-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScriptChange.xaml.cs
More file actions
114 lines (97 loc) · 3.46 KB
/
ScriptChange.xaml.cs
File metadata and controls
114 lines (97 loc) · 3.46 KB
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
using System.Diagnostics;
using System.Windows.Documents;
using System.Windows.Input;
using Microsoft.Win32;
namespace WindowUI;
public partial class ScriptChange
{
private string _currentFilePath = string.Empty; //文件路径
private string fileContent = string.Empty;
public ScriptChange()
{
InitializeComponent();
}
private void ExitWindow(object sender, RoutedEventArgs e)
{
//退出窗口
Close();
}
private void SelectFile(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filter = "Script文件 | *.txt"
};
if (openFileDialog.ShowDialog() == true)
{
_currentFilePath = openFileDialog.FileName;
ScriptName.Text = _currentFilePath; //设置文件路径到 TextBox
using (var reader = new StreamReader(_currentFilePath, true))
{
fileContent = reader.ReadToEnd();
}
var paragraph = new Paragraph();
// 创建并添加文本
paragraph.Inlines.Add(new Run(fileContent));
// 清空富文本框并插入新的段落
Script.Document.Blocks.Clear();
Script.Document.Blocks.Add(paragraph);
}
}
private void SaveFile(object sender, RoutedEventArgs e)
{
if (_currentFilePath == "") return;
// 保存富文本框内的内容到桌面
var savePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\转换后脚本.txt";
using (var writer = new StreamWriter(savePath))
{
writer.Write(new TextRange(Script.Document.ContentStart, Script.Document.ContentEnd).Text);
}
Message.ShowSnack();
}
private void Image_MouseEnter_Save(object sender, MouseEventArgs e)
{
var savePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\转换后脚本.txt";
using (var writer = new StreamWriter(savePath))
{
writer.Write(new TextRange(Script.Document.ContentStart, Script.Document.ContentEnd).Text);
}
Message.ShowSnack();
}
private void Image_MouseDown_Open(object sender, MouseButtonEventArgs e)
{
var openFileDialog = new OpenFileDialog
{
Filter = "Script文件 | *.txt"
};
if (openFileDialog.ShowDialog() == true)
{
_currentFilePath = openFileDialog.FileName;
ScriptName.Text = _currentFilePath; //设置文件路径到 TextBox
using (var reader = new StreamReader(_currentFilePath, true))
{
fileContent = reader.ReadToEnd();
}
var paragraph = new Paragraph();
//创建并添加文本
paragraph.Inlines.Add(new Run(fileContent));
//清空富文本框并插入新的段落
Script.Document.Blocks.Clear();
Script.Document.Blocks.Add(paragraph);
}
}
private void Image_MouseDown_OpenScript(object sender, MouseButtonEventArgs e)
{
var savePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\转换后脚本.txt";
//打开文件路径
if (savePath != null)
{
var processStartInfo = new ProcessStartInfo
{
FileName = savePath,
UseShellExecute = true
};
Process.Start(processStartInfo);
}
}
}