-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUserControl1.xaml.cs
More file actions
executable file
·118 lines (108 loc) · 3.41 KB
/
Copy pathUserControl1.xaml.cs
File metadata and controls
executable file
·118 lines (108 loc) · 3.41 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
115
116
117
118
using Plugin;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
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.Navigation;
namespace CustomCommandPlugin
{
/// <summary>
/// UserControl1.xaml 的交互逻辑
/// </summary>
public partial class UserControl1 : UserControl
{
private ObservableCollection<Item> items;
CustomCommandExecutor E;
public UserControl1(ObservableCollection<Item> items,CustomCommandExecutor e)
{
InitializeComponent();
this.Loaded += UserControl1_Loaded;
this.items = items;
E = e;
}
void UserControl1_Loaded(object sender, EventArgs e)
{
load();
lv.ItemsSource = items;
}
private void load()
{
try
{
string path = Path.Combine(System.Environment.GetEnvironmentVariable("appdata"), "PocketDesktop");
string cfgPath = Path.Combine(path, "CustomCommand.cfg");
if (File.Exists(cfgPath))
{
items.Clear();
using (StreamReader sr = new StreamReader(cfgPath))
{
while (!sr.EndOfStream)
{
string s = sr.ReadLine();
Item i = Item.Parse(s);
if (i != null)
items.Add(i);
}
}
}
}
catch (Exception)
{
throw;
}
}
private void save()
{
try
{
string path = Path.Combine(System.Environment.GetEnvironmentVariable("appdata"), "PocketDesktop");
string cfgPath = Path.Combine(path, "CustomCommand.cfg");
using (StreamWriter sw = new StreamWriter(cfgPath))
{
foreach (Item i in items)
{
sw.WriteLine(i.ToString());
}
}
}
catch (Exception)
{
throw;
}
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
if(string.IsNullOrEmpty(tbCmd.Text)||string.IsNullOrEmpty(tbParm.Text))
{
return;
}
Item i=new Item();
i.Cmd = tbCmd.Text;
i.Action = (Action)cbAction.SelectedIndex;
i.Parameter = tbParm.Text;
items.Add(i);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
save();
E.SetCommandText();
tbTz.Visibility=Visibility.Visible;
}
private void btnDel_Click(object sender, RoutedEventArgs e)
{
if (lv.SelectedIndex >= 0)
{
items.RemoveAt(lv.SelectedIndex);
}
}
}
}