-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
203 lines (189 loc) · 6.7 KB
/
MainWindow.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Threading;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
namespace notebook
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public int saveojbk = 0;
public string SaveFillPath;
public MainWindow()
{
InitializeComponent();
TeboxSeleTimer();
TextCache();
}
public void TeboxSeleTimer()
{
/*
^ Timer set
*/
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(TextboxSelect);
dispatcherTimer.IsEnabled = true;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
public void TextCache()
{
/*
^ Timer set
*/
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(TextboxerrorCache);
dispatcherTimer.IsEnabled = true;
dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
dispatcherTimer.Start();
}
public void TextboxerrorCache(object sender, EventArgs e)
{
/*
*Textbox SelectionStart
*/
var thispath = System.Environment.CurrentDirectory; ;
Console.WriteLine(thispath.ToString());
if (System.IO.Directory.Exists(thispath.ToString() + "\\Cache") == false)//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(thispath + "\\Cache");
}
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(thispath+ "\\Cache\\thispath.Cache", lines, Encoding.UTF8);
}
public void TextboxSelect(object sender, EventArgs e)
{
/*
*Textbox SelectionStart
*/
try { Console.WriteLine(TextBox_Edit.SelectionStart.ToString()); } catch { }
}
private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
{
/*
^ this Move
*/
try { this.DragMove(); } catch { }
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
System.Windows.Rect r = new System.Windows.Rect(e.NewSize);
RectangleGeometry gm = new RectangleGeometry(r,6,5);
((UIElement)sender).Clip = gm;
}
private void TextBox_Edit_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void TextBox_Edit_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.S)
{
if (saveojbk != 0)
{
Console.WriteLine("Yes!");
saveojbk = 1;
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(SaveFillPath, lines, Encoding.UTF8);
}
else
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
if (saveFileDialog.ShowDialog() == true)
{
saveojbk = 1;
Console.WriteLine("You File Yes!");
SaveFillPath = saveFileDialog.FileName;
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(SaveFillPath, lines, Encoding.UTF8);
}
else
{
MessageBox.Show("Sorry You in File error");
}
}
}
}
private void menuOpen_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
if (openFileDialog.FileName != null)
{
SaveFillPath = openFileDialog.FileName;
saveojbk = 1;
string openstrfile = System.IO.File.ReadAllText(SaveFillPath, Encoding.UTF8);
TextBox_Edit.Text = openstrfile;
}
else { Console.WriteLine("error null"); }
}
else
{
Console.WriteLine("error");
}
}
private void MenuItem_Click_saver(object sender, RoutedEventArgs e)
{
if (saveojbk != 0)
{
Console.WriteLine("Yes!");
saveojbk = 1;
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(SaveFillPath, lines, Encoding.UTF8);
}
else
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
if (saveFileDialog.ShowDialog() == true)
{
saveojbk = 1;
Console.WriteLine("You File Yes!");
SaveFillPath = saveFileDialog.FileName;
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(SaveFillPath, lines, Encoding.UTF8);
}
else
{
MessageBox.Show("Sorry You in File error");
}
}
}
private void MenuItem_Click_saver_as(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
if (saveFileDialog.ShowDialog() == true)
{
Console.WriteLine("You File Yes!");
SaveFillPath = saveFileDialog.FileName;
string lines = TextBox_Edit.Text;
System.IO.File.WriteAllText(SaveFillPath, lines, Encoding.UTF8);
}
else {
Console.WriteLine("error null");
}
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Hide();
System.Environment.Exit(0);
}
private void Minimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
}
}