提交记录修改Core/Models/Config/ConfigAttribute.cs+3 −0看文件
修改Core/Models/Config/Link/LinkModel.cs+2 −2看文件
修改Core/Servicers/Instances/AppConfig.cs+33 −0看文件
修改UI/Controls/SettingPanel/SettingPanel.cs+111 −0看文件
修改UI/Controls/SettingPanel/SettingPanelMultiItem.cs+33 −1看文件
| @@ -21,10 +21,13 @@ namespace Core.Models.Config | ||
| 21 | 21 | public string Group; |
| 22 | 22 | public int Index; |
| 23 | 23 | public bool IsName; |
| 24 | 新增: public string Placeholder; | |
| 25 | 新增: public bool IsCanRepeat; | |
| 24 | 26 | public ConfigAttribute() |
| 25 | 27 | { |
| 26 | 28 | ToggleTrueText = "开"; |
| 27 | 29 | ToggleFalseText = "关"; |
| 30 | 新增: IsCanRepeat = true; | |
| 28 | 31 | Index = 0; |
| 29 | 32 | IsName = false; |
| 30 | 33 | } |
| @@ -11,12 +11,12 @@ namespace Core.Models.Config.Link | ||
| 11 | 11 | /// <summary> |
| 12 | 12 | /// 关联名称 |
| 13 | 13 | /// </summary> |
| 14 | 删除: [Config(Name = "关联名称", Description = "设置一个名称用于识别该关联的目的", IsName = true)] | |
| 14 | 新增: [Config(Name = "关联名称", Description = "设置一个名称用于识别该关联的目的", IsName = true, IsCanRepeat = false)] | |
| 15 | 15 | public string Name { get; set; } = "新的关联"; |
| 16 | 16 | /// <summary> |
| 17 | 17 | /// 关联进程列表 |
| 18 | 18 | /// </summary> |
| 19 | 删除: [Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此")] | |
| 19 | 新增: [Config(Name = "关联进程", Description = "将需要关联的进程名称(不带.exe)添加到此", IsCanRepeat = false)] | |
| 20 | 20 | public List<string> ProcessList { get; set; } = new List<string>(); |
| 21 | 21 | } |
| 22 | 22 | } |
| @@ -5,8 +5,10 @@ using Core.Servicers.Interfaces; | ||
| 5 | 5 | using Newtonsoft.Json; |
| 6 | 6 | using System; |
| 7 | 7 | using System.Collections.Generic; |
| 8 | 新增:using System.Diagnostics; | |
| 8 | 9 | using System.IO; |
| 9 | 10 | using System.Linq; |
| 11 | 新增:using System.Reflection; | |
| 10 | 12 | using System.Text; |
| 11 | 13 | using System.Threading.Tasks; |
| 12 | 14 | |
| @@ -45,6 +47,8 @@ namespace Core.Servicers.Instances | ||
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | CopyToOldConfig(); |
| 50 | 新增: | |
| 51 | 新增: CheckOption(config); | |
| 48 | 52 | } |
| 49 | 53 | catch (JsonSerializationException ex) |
| 50 | 54 | { |
| @@ -82,6 +86,9 @@ namespace Core.Servicers.Instances | ||
| 82 | 86 | |
| 83 | 87 | config.General = new GeneralModel(); |
| 84 | 88 | config.General.IsStartatboot = false; |
| 89 | 新增: | |
| 90 | 新增: config.Behavior = new BehaviorModel(); | |
| 91 | 新增: config.Behavior.IgnoreProcessList.Add("Test"); | |
| 85 | 92 | } |
| 86 | 93 | |
| 87 | 94 | public ConfigModel GetConfig() |
| @@ -111,5 +118,31 @@ namespace Core.Servicers.Instances | ||
| 111 | 118 | Logger.Error(ex.Message); |
| 112 | 119 | } |
| 113 | 120 | } |
| 121 | 新增: | |
| 122 | 新增: private void CheckOption(object obj) | |
| 123 | 新增: { | |
| 124 | 新增: System.Reflection.PropertyInfo[] properties = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); | |
| 125 | 新增: | |
| 126 | 新增: foreach (System.Reflection.PropertyInfo item in properties) | |
| 127 | 新增: { | |
| 128 | 新增: string name = item.Name; | |
| 129 | 新增: object value = item.GetValue(obj, null); | |
| 130 | 新增: if (value == null) | |
| 131 | 新增: { | |
| 132 | 新增: //配置项不存在时创建 | |
| 133 | 新增: Type[] types = new Type[0]; | |
| 134 | 新增: object[] objs = new object[0]; | |
| 135 | 新增: | |
| 136 | 新增: ConstructorInfo ctor = item.PropertyType.GetConstructor(types); | |
| 137 | 新增: if (ctor != null) | |
| 138 | 新增: { | |
| 139 | 新增: object instance = ctor.Invoke(objs); | |
| 140 | 新增: item.SetValue(obj, instance); | |
| 141 | 新增: } | |
| 142 | 新增: } | |
| 143 | 新增: | |
| 144 | 新增: Debug.WriteLine(string.Format("{0}:{1},", name, value)); | |
| 145 | 新增: } | |
| 146 | 新增: } | |
| 114 | 147 | } |
| 115 | 148 | } |
| @@ -11,6 +11,8 @@ using System.Threading.Tasks; | ||
| 11 | 11 | using System.Windows; |
| 12 | 12 | using System.Windows.Controls; |
| 13 | 13 | using System.Windows.Media; |
| 14 | 新增:using UI.Controls.Input; | |
| 15 | 新增:using UI.Controls.List; | |
| 14 | 16 | |
| 15 | 17 | namespace UI.Controls.SettingPanel |
| 16 | 18 | { |
| @@ -39,9 +41,11 @@ namespace UI.Controls.SettingPanel | ||
| 39 | 41 | private object configData; |
| 40 | 42 | private readonly string nosetGroupKey = "noset_group"; |
| 41 | 43 | private Dictionary<string, List<Config>> configList; |
| 44 | 新增: public Dictionary<string, List<string>> SettingData { get; set; } | |
| 42 | 45 | public SettingPanel() |
| 43 | 46 | { |
| 44 | 47 | DefaultStyleKey = typeof(SettingPanel); |
| 48 | 新增: SettingData = new Dictionary<string, List<string>>(); | |
| 45 | 49 | } |
| 46 | 50 | public override void OnApplyTemplate() |
| 47 | 51 | { |
| @@ -141,6 +145,7 @@ namespace UI.Controls.SettingPanel | ||
| 141 | 145 | var panel = new SettingPanelMultiItem(); |
| 142 | 146 | panel.Data = data; |
| 143 | 147 | panel.Tag = id; |
| 148 | 新增: panel.SettingData = SettingData; | |
| 144 | 149 | panel.DataChanged += (e, c) => |
| 145 | 150 | { |
| 146 | 151 | int pid = (int)panel.Tag; |
| @@ -299,6 +304,10 @@ namespace UI.Controls.SettingPanel | ||
| 299 | 304 | { |
| 300 | 305 | uIElement = RenderBooleanConfigControl(attribute, pi); |
| 301 | 306 | } |
| 307 | 新增: else if (pi.PropertyType == typeof(List<string>)) | |
| 308 | 新增: { | |
| 309 | 新增: uIElement = RenderListStringConfigControl(attribute, pi); | |
| 310 | 新增: } | |
| 302 | 311 | |
| 303 | 312 | return uIElement; |
| 304 | 313 | } |
| @@ -322,5 +331,107 @@ namespace UI.Controls.SettingPanel | ||
| 322 | 331 | |
| 323 | 332 | return item; |
| 324 | 333 | } |
| 334 | 新增: | |
| 335 | 新增: private UIElement RenderListStringConfigControl(ConfigAttribute configAttribute, PropertyInfo pi) | |
| 336 | 新增: { | |
| 337 | 新增: var list = pi.GetValue(Data) as List<string>; | |
| 338 | 新增: | |
| 339 | 新增: var listControl = new BaseList(); | |
| 340 | 新增: listControl.MaxHeight = 200; | |
| 341 | 新增: listControl.Loaded += (sender, args) => | |
| 342 | 新增: { | |
| 343 | 新增: listControl.Items.CollectionChanged += (o, e) => | |
| 344 | 新增: { | |
| 345 | 新增: var newData = new List<string>(); | |
| 346 | 新增: foreach (var item in listControl.Items) | |
| 347 | 新增: { | |
| 348 | 新增: newData.Add(item.ToString()); | |
| 349 | 新增: } | |
| 350 | 新增: pi.SetValue(configData, newData); | |
| 351 | 新增: Data = configData; | |
| 352 | 新增: }; | |
| 353 | 新增: }; | |
| 354 | 新增: listControl.Margin = new Thickness(15, 0, 15, 10); | |
| 355 | 新增: | |
| 356 | 新增: if (list != null) | |
| 357 | 新增: { | |
| 358 | 新增: foreach (string item in list) | |
| 359 | 新增: { | |
| 360 | 新增: listControl.Items.Add(item); | |
| 361 | 新增: } | |
| 362 | 新增: } | |
| 363 | 新增: else | |
| 364 | 新增: { | |
| 365 | 新增: list = new List<string>(); | |
| 366 | 新增: } | |
| 367 | 新增: var contextMenu = new ContextMenu(); | |
| 368 | 新增: | |
| 369 | 新增: var contextMenuItemDel = new MenuItem(); | |
| 370 | 新增: contextMenuItemDel.Header = "移除"; | |
| 371 | 新增: contextMenuItemDel.Click += (e, c) => | |
| 372 | 新增: { | |
| 373 | 新增: listControl.Items.Remove(listControl.SelectedItem); | |
| 374 | 新增: }; | |
| 375 | 新增: contextMenu.Items.Add(contextMenuItemDel); | |
| 376 | 新增: listControl.ContextMenu = contextMenu; | |
| 377 | 新增: | |
| 378 | 新增: | |
| 379 | 新增: // 添加输入框 | |
| 380 | 新增: var addInputBox = new InputBox(); | |
| 381 | 新增: addInputBox.Placeholder = configAttribute.Placeholder; | |
| 382 | 新增: addInputBox.Margin = new Thickness(0, 0, 10, 0); | |
| 383 | 新增: | |
| 384 | 新增: var addBtn = new Button.Button(); | |
| 385 | 新增: //addBtn.Margin = new Thickness(15, 0, 15, 10); | |
| 386 | 新增: addBtn.Content = "添加"; | |
| 387 | 新增: | |
| 388 | 新增: addBtn.Click += (e, c) => | |
| 389 | 新增: { | |
| 390 | 新增: if (addInputBox.Text == String.Empty || list.Contains(addInputBox.Text)) | |
| 391 | 新增: { | |
| 392 | 新增: addInputBox.Error = configAttribute.Name + (addInputBox.Text == String.Empty ? "不能为空" : "已存在"); | |
| 393 | 新增: addInputBox.ShowError(); | |
| 394 | 新增: return; | |
| 395 | 新增: } | |
| 396 | 新增: //list.Add(addInputBox.Text); | |
| 397 | 新增: listControl.Items.Add(addInputBox.Text); | |
| 398 | 新增: addInputBox.Text = String.Empty; | |
| 399 | 新增: | |
| 400 | 新增: | |
| 401 | 新增: | |
| 402 | 新增: }; | |
| 403 | 新增: pi.SetValue(configData, list); | |
| 404 | 新增: | |
| 405 | 新增: var inputPanel = new Grid(); | |
| 406 | 新增: inputPanel.ColumnDefinitions.Add( | |
| 407 | 新增: new ColumnDefinition() | |
| 408 | 新增: { | |
| 409 | 新增: Width = new GridLength(10, GridUnitType.Star) | |
| 410 | 新增: }); | |
| 411 | 新增: inputPanel.ColumnDefinitions.Add( | |
| 412 | 新增: new ColumnDefinition() | |
| 413 | 新增: { | |
| 414 | 新增: Width = new GridLength(2, GridUnitType.Star) | |
| 415 | 新增: }); | |
| 416 | 新增: inputPanel.Margin = new Thickness(15, 10, 15, 10); | |
| 417 | 新增: Grid.SetColumn(addInputBox, 0); | |
| 418 | 新增: Grid.SetColumn(addBtn, 1); | |
| 419 | 新增: inputPanel.Children.Add(addInputBox); | |
| 420 | 新增: inputPanel.Children.Add(addBtn); | |
| 421 | 新增: | |
| 422 | 新增: | |
| 423 | 新增: // 标题和说明 | |
| 424 | 新增: | |
| 425 | 新增: var description = new TextBlock(); | |
| 426 | 新增: description.Text = configAttribute.Description; | |
| 427 | 新增: description.Margin = new Thickness(10, 10, 10, 0); | |
| 428 | 新增: description.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#989CA1")); | |
| 429 | 新增: var container = new StackPanel(); | |
| 430 | 新增: | |
| 431 | 新增: container.Children.Add(description); | |
| 432 | 新增: container.Children.Add(inputPanel); | |
| 433 | 新增: container.Children.Add(listControl); | |
| 434 | 新增: return container; | |
| 435 | 新增: } | |
| 325 | 436 | } |
| 326 | 437 | } |
| @@ -8,6 +8,7 @@ using System.Diagnostics; | ||
| 8 | 8 | using System.Linq; |
| 9 | 9 | using System.Reflection; |
| 10 | 10 | using System.Text; |
| 11 | 新增:using System.Text.RegularExpressions; | |
| 11 | 12 | using System.Threading.Tasks; |
| 12 | 13 | using System.Windows; |
| 13 | 14 | using System.Windows.Controls; |
| @@ -19,6 +20,11 @@ namespace UI.Controls.SettingPanel | ||
| 19 | 20 | { |
| 20 | 21 | public class SettingPanelMultiItem : Control |
| 21 | 22 | { |
| 23 | 新增: /// <summary> | |
| 24 | 新增: /// 所有设置数据 | |
| 25 | 新增: /// </summary> | |
| 26 | 新增: public Dictionary<string, List<string>> SettingData { get { return (Dictionary<string, List<string>>)GetValue(SettingDataProperty); } set { SetValue(SettingDataProperty, value); } } | |
| 27 | 新增: public static readonly DependencyProperty SettingDataProperty = DependencyProperty.Register("SettingData", typeof(Dictionary<string, List<string>>), typeof(SettingPanelMultiItem)); | |
| 22 | 28 | public bool Fold { get { return (bool)GetValue(FoldProperty); } set { SetValue(FoldProperty, value); } } |
| 23 | 29 | public static readonly DependencyProperty FoldProperty = DependencyProperty.Register("Fold", typeof(bool), typeof(SettingPanelMultiItem), new PropertyMetadata(false)); |
| 24 | 30 | |
| @@ -39,6 +45,11 @@ namespace UI.Controls.SettingPanel | ||
| 39 | 45 | public SettingPanelMultiItem() |
| 40 | 46 | { |
| 41 | 47 | DefaultStyleKey = typeof(SettingPanelMultiItem); |
| 48 | 新增: | |
| 49 | 新增: if (SettingData == null) | |
| 50 | 新增: { | |
| 51 | 新增: SettingData = new Dictionary<string, List<string>>(); | |
| 52 | 新增: } | |
| 42 | 53 | } |
| 43 | 54 | public override void OnApplyTemplate() |
| 44 | 55 | { |
| @@ -113,6 +124,15 @@ namespace UI.Controls.SettingPanel | ||
| 113 | 124 | |
| 114 | 125 | var list = pi.GetValue(Data) as List<string>; |
| 115 | 126 | |
| 127 | 新增: if (SettingData.ContainsKey(pi.Name)) | |
| 128 | 新增: { | |
| 129 | 新增: SettingData[pi.Name] = SettingData[pi.Name].Concat(list).ToList(); | |
| 130 | 新增: } | |
| 131 | 新增: else | |
| 132 | 新增: { | |
| 133 | 新增: SettingData.Add(pi.Name, list); | |
| 134 | 新增: } | |
| 135 | 新增: | |
| 116 | 136 | var listControl = new BaseList(); |
| 117 | 137 | |
| 118 | 138 | listControl.Loaded += (sender, args) => |
| @@ -175,10 +195,21 @@ namespace UI.Controls.SettingPanel | ||
| 175 | 195 | |
| 176 | 196 | addBtn.Click += (e, c) => |
| 177 | 197 | { |
| 198 | 新增: addInputBox.Error = attribute.Name + (addInputBox.Text == String.Empty ? "不能为空" : "已存在"); | |
| 199 | 新增: | |
| 178 | 200 | if (addInputBox.Text == String.Empty || list.Contains(addInputBox.Text)) |
| 179 | 201 | { |
| 202 | 新增: addInputBox.ShowError(); | |
| 180 | 203 | return; |
| 181 | 204 | } |
| 205 | 新增: | |
| 206 | 新增: // 判断重复 | |
| 207 | 新增: if (!attribute.IsCanRepeat && SettingData[pi.Name].Contains(addInputBox.Text)) | |
| 208 | 新增: { | |
| 209 | 新增: addInputBox.ShowError(); | |
| 210 | 新增: return; | |
| 211 | 新增: } | |
| 212 | 新增: | |
| 182 | 213 | //list.Add(addInputBox.Text); |
| 183 | 214 | listControl.Items.Add(addInputBox.Text); |
| 184 | 215 | addInputBox.Text = String.Empty; |
| @@ -211,9 +242,10 @@ namespace UI.Controls.SettingPanel | ||
| 211 | 242 | } |
| 212 | 243 | private void RenderTextBox(ConfigAttribute attribute, PropertyInfo pi) |
| 213 | 244 | { |
| 245 | 新增: string value = (string)pi.GetValue(Data); | |
| 214 | 246 | |
| 215 | 247 | var textBox = new InputBox(); |
| 216 | 删除: textBox.Text = (string)pi.GetValue(Data); | |
| 248 | 新增: textBox.Text = value; | |
| 217 | 249 | textBox.Placeholder = attribute.Name; |
| 218 | 250 | textBox.Width = 125; |
| 219 | 251 | textBox.LostFocus += (e, c) => |

