forked from changbowen/DesktopNote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win_Options.xaml.cs
144 lines (125 loc) · 5.55 KB
/
Win_Options.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
//using System.Windows.Data;
using System.Windows.Documents;
//using System.Windows.Input;
using System.Windows.Media;
//using System.Windows.Media.Imaging;
//using System.Windows.Shapes;
namespace DesktopNote
{
public partial class Win_Options : RoundedWindow
{
public readonly MainWindow MainWin;
private readonly RichTextBox RTB_Main;
private string assname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
public Win_Options(MainWindow mainwin)
{
InitializeComponent();
Owner = mainwin;
MainWin = mainwin;
RTB_Main = MainWin.RTB_Main;
App.OptionsWindow = this;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
App.OptionsWindow = null;
}
private void CB_AutoStart_Click(object sender, RoutedEventArgs e)
{
var run = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (CB_AutoStart.IsChecked == true)
run.SetValue(assname, System.Reflection.Assembly.GetExecutingAssembly().Location, Microsoft.Win32.RegistryValueKind.String);
else
run.DeleteValue(assname, false);
}
private void CB_AutoDock_Click(object sender, RoutedEventArgs e)
{
if (CB_AutoDock.IsChecked == true)
{
MainWin.CurrentSetting.AutoDock = true;
MainWin.DockToSide(true);
}
else
{
MainWin.CurrentSetting.AutoDock = false;
MainWin.UnDock();
MainWin.Topmost = false;
}
}
private void Button_ResetFormats_Click(object sender, RoutedEventArgs e)
{
//clear custom formats
var tr = new TextRange(RTB_Main.Document.ContentStart, RTB_Main.Document.ContentEnd);
tr.ClearAllProperties();
//reset global font size
RTB_Main.FontSize = MainWin.FontSize;
//resetting paper color should be processed with Reset Settings
//var cp = (Color)ColorConverter.ConvertFromString((string)MainWin.CurrentSetting.Properties["PaperColor"].DefaultValue);
//MainWin.CurrentSetting.PaperColor = cp;
//Rec_BG.Fill = new SolidColorBrush(cp);
}
private async void Button_ResetSet_Click(object sender, RoutedEventArgs e)
{
//create default setting with current note path
await FadeOut(true);
var newSetting = new Setting(Setting.NoteFlag.Existing | Setting.NoteFlag.IgnoreSettingsFromFile,
path: MainWin.CurrentSetting.Doc_Location);
MainWin.Close();
new MainWindow(newSetting).Show();
//var optwin = new Win_Options(win);
//optwin.Show();
}
private void Button_About_Click(object sender, RoutedEventArgs e)
{
Close();
System.Threading.Tasks.Task.Run(delegate
{
if (Helpers.MsgBox(body: string.Format((string)App.Res["msgbox_about"], System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()),
button: MessageBoxButton.OKCancel,
image: MessageBoxImage.Information) == MessageBoxResult.OK)
System.Diagnostics.Process.Start("https://github.com/changbowen/DesktopNote");
});
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//check auto dock
if (MainWin.CurrentSetting.AutoDock == true) CB_AutoDock.IsChecked = true;
//check auto start
var run = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
string run_value = (string)run.GetValue(assname);
if (!string.IsNullOrEmpty(run_value))
{//update the exe location if Run contains assname.
CB_AutoStart.IsChecked = true;
if (run_value != System.Reflection.Assembly.GetExecutingAssembly().Location)
run.SetValue(assname, System.Reflection.Assembly.GetExecutingAssembly().Location, Microsoft.Win32.RegistryValueKind.String);
}
//set path
TB_SavePath.Text = MainWin.CurrentSetting.Doc_Location;
TB_SavePathTxt.Text = MainWin.CurrentSetting.Bak_Location;
}
private void TB_SavePath_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var path = Helpers.OpenFileDialog(this, true, MainWin.CurrentSetting.Doc_Location);
if (path == null) return;
MainWin.CurrentSetting.Doc_Location = path;
TB_SavePath.Text = path;
TB_SavePathTxt.Text = MainWin.CurrentSetting.Bak_Location;
}
//private void TB_SavePathTxt_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
//{
// var path = Helpers.OpenFileDialog(this, true, MainWin.CurrentSetting.Bak_Location, "DesktopNote Text Content|*.txt");
// if (path == null) return;
// MainWin.CurrentSetting.Bak_Location = path;
// TB_SavePathTxt.Text = path;
//}
}
}