提交记录修改Core/Models/Config/BehaviorModel.cs+1 −1看文件
修改Core/Models/Config/ConfigAttribute.cs+2 −0看文件
修改UI/Controls/SettingPanel/SettingPanel.cs+104 −58看文件
| @@ -11,7 +11,7 @@ namespace Core.Models.Config | ||
| 11 | 11 | /// </summary> |
| 12 | 12 | public class BehaviorModel |
| 13 | 13 | { |
| 14 | 删除: [Config(Name = "忽略进程", Description = "忽略的进程将不进行时长统计", Group = "忽略进程", Placeholder ="进程名,不需要输入.exe")] | |
| 14 | 新增: [Config(IsCanImportExport = true, Name = "忽略进程", Description = "忽略的进程将不进行时长统计", Group = "忽略进程", Placeholder = "进程名,不需要输入.exe")] | |
| 15 | 15 | /// <summary> |
| 16 | 16 | /// 忽略的进程列表 |
| 17 | 17 | /// </summary> |
| @@ -23,6 +23,7 @@ namespace Core.Models.Config | ||
| 23 | 23 | public bool IsName; |
| 24 | 24 | public string Placeholder; |
| 25 | 25 | public bool IsCanRepeat; |
| 26 | 新增: public bool IsCanImportExport; | |
| 26 | 27 | public ConfigAttribute() |
| 27 | 28 | { |
| 28 | 29 | ToggleTrueText = "开"; |
| @@ -30,6 +31,7 @@ namespace Core.Models.Config | ||
| 30 | 31 | IsCanRepeat = true; |
| 31 | 32 | Index = 0; |
| 32 | 33 | IsName = false; |
| 34 | 新增: IsCanImportExport = false; | |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | |
| @@ -1,4 +1,5 @@ | ||
| 1 | 删除:using Core.Models.Config; | |
| 1 | 新增:using Core.Librarys; | |
| 2 | 新增:using Core.Models.Config; | |
| 2 | 3 | using Newtonsoft.Json; |
| 3 | 4 | using System; |
| 4 | 5 | using System.Collections; |
| @@ -13,6 +14,7 @@ using System.Threading.Tasks; | ||
| 13 | 14 | using System.Windows; |
| 14 | 15 | using System.Windows.Controls; |
| 15 | 16 | using System.Windows.Media; |
| 17 | 新增:using UI.Controls.Button; | |
| 16 | 18 | using UI.Controls.Input; |
| 17 | 19 | using UI.Controls.List; |
| 18 | 20 | |
| @@ -406,63 +408,98 @@ namespace UI.Controls.SettingPanel | ||
| 406 | 408 | }; |
| 407 | 409 | pi.SetValue(configData, list); |
| 408 | 410 | |
| 409 | 删除: //导入 | |
| 410 | 删除: var importBtn = new Button.Button(); | |
| 411 | 删除: importBtn.Content = "导入"; | |
| 412 | 删除: importBtn.Click += (e, c) => | |
| 413 | 删除: { | |
| 414 | 删除: Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); | |
| 415 | 删除: ofd.Title = "选择文件"; | |
| 416 | 删除: ofd.Filter = "json(*.json)|*.json"; | |
| 417 | 删除: ofd.FileName = "TaiProcessIgnoreExport"; | |
| 411 | 新增: IconButton moreActionBtn = new IconButton(); | |
| 412 | 新增: moreActionBtn.VerticalAlignment = VerticalAlignment.Center; | |
| 413 | 新增: moreActionBtn.HorizontalAlignment = HorizontalAlignment.Right; | |
| 414 | 新增: moreActionBtn.Margin = new Thickness(0, 5, 5, 0); | |
| 415 | 新增: moreActionBtn.Icon = Base.IconTypes.More; | |
| 416 | 新增: | |
| 417 | 新增: var moreActionMenu = new ContextMenu(); | |
| 418 | 418 | |
| 419 | 删除: ofd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;//指定启动路径 | |
| 419 | 新增: moreActionBtn.MouseLeftButtonUp += (e, c) => | |
| 420 | 新增: { | |
| 421 | 新增: moreActionMenu.IsOpen = true; | |
| 422 | 新增: }; | |
| 423 | 新增: bool isHasMoreAction = false; | |
| 424 | 新增: if (configAttribute.IsCanImportExport) | |
| 425 | 新增: { | |
| 426 | 新增: // 允许导入导出 | |
| 427 | 新增: isHasMoreAction = true; | |
| 420 | 428 | |
| 421 | 删除: bool? result = ofd.ShowDialog(); | |
| 422 | 删除: if (result == true) | |
| 429 | 新增: // 导入操作 | |
| 430 | 新增: var importMenuItem = new MenuItem(); | |
| 431 | 新增: importMenuItem.Header = "导入"; | |
| 432 | 新增: importMenuItem.Click += (e, c) => | |
| 423 | 433 | { |
| 424 | 删除: | |
| 425 | 删除: BehaviorModel bm = JsonConvert.DeserializeObject<BehaviorModel>(File.ReadAllText(ofd.FileName)); | |
| 426 | 删除: if (bm == null) | |
| 427 | 删除: { | |
| 428 | 删除: MessageBox.Show("文件格式有误或者数据为空,请选择有效的导出文件。"); | |
| 429 | 删除: } | |
| 430 | 删除: else | |
| 434 | 新增: Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); | |
| 435 | 新增: ofd.Title = "选择文件"; | |
| 436 | 新增: ofd.Filter = "json(*.json)|*.json"; | |
| 437 | 新增: ofd.FileName = configAttribute.Name; | |
| 438 | 新增: | |
| 439 | 新增: bool? result = ofd.ShowDialog(); | |
| 440 | 新增: if (result == true) | |
| 431 | 441 | { |
| 432 | 删除: if (MessageBox.Show("导入将覆盖现有设置,确定吗?", "注意", MessageBoxButton.OKCancel) == MessageBoxResult.OK) | |
| 442 | 新增: try | |
| 433 | 443 | { |
| 434 | 删除: pi.SetValue(configData, bm.IgnoreProcessList); | |
| 435 | 删除: listControl.Items.Clear(); | |
| 436 | 删除: foreach (string p in bm.IgnoreProcessList) | |
| 444 | 新增: List<string> data = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(ofd.FileName)); | |
| 445 | 新增: if (data == null) | |
| 446 | 新增: { | |
| 447 | 新增: MessageBox.Show("文件格式有误或者数据为空,请选择有效的导出文件。"); | |
| 448 | 新增: } | |
| 449 | 新增: else | |
| 437 | 450 | { |
| 438 | 删除: listControl.Items.Add(p); | |
| 451 | 新增: if (MessageBox.Show("导入将覆盖现有配置,确定吗?", "注意", MessageBoxButton.OKCancel) == MessageBoxResult.OK) | |
| 452 | 新增: { | |
| 453 | 新增: pi.SetValue(configData, data); | |
| 454 | 新增: listControl.Items.Clear(); | |
| 455 | 新增: foreach (string item in data) | |
| 456 | 新增: { | |
| 457 | 新增: listControl.Items.Add(item); | |
| 458 | 新增: } | |
| 459 | 新增: MessageBox.Show("导入完成!", "提示"); | |
| 460 | 新增: } | |
| 439 | 461 | } |
| 462 | 新增: }catch (Exception ex) | |
| 463 | 新增: { | |
| 464 | 新增: Logger.Error($"导入配置“{configAttribute.Name}”时失败:{ex.Message}"); | |
| 465 | 新增: MessageBox.Show("导入失败!", "提示"); | |
| 440 | 466 | } |
| 441 | 467 | } |
| 442 | 删除: } | |
| 443 | 468 | |
| 444 | 删除: }; | |
| 469 | 新增: }; | |
| 445 | 470 | |
| 446 | 删除: //导出 | |
| 447 | 删除: var exportBtn = new Button.Button(); | |
| 448 | 删除: exportBtn.Content = "导出"; | |
| 449 | 删除: exportBtn.Click += (e, c) => | |
| 450 | 删除: { | |
| 451 | 删除: Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); | |
| 452 | 删除: sfd.Title = "选择文件"; | |
| 453 | 删除: sfd.Filter = "json(*.json)|*.json"; | |
| 454 | 删除: sfd.FileName = "TaiProcessIgnoreExport"; | |
| 471 | 新增: // 导出操作 | |
| 472 | 新增: var exportMenuItem = new MenuItem(); | |
| 473 | 新增: exportMenuItem.Header = "导出"; | |
| 474 | 新增: exportMenuItem.Click += (e, c) => | |
| 475 | 新增: { | |
| 476 | 新增: try | |
| 477 | 新增: { | |
| 478 | 新增: Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); | |
| 479 | 新增: sfd.Title = "选择文件"; | |
| 480 | 新增: sfd.Filter = "json(*.json)|*.json"; | |
| 481 | 新增: sfd.FileName = configAttribute.Name + "导出配置"; | |
| 455 | 482 | |
| 456 | 删除: sfd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;//指定启动路径 | |
| 483 | 新增: bool? result = sfd.ShowDialog(); | |
| 484 | 新增: if (result == true) | |
| 485 | 新增: { | |
| 486 | 新增: File.WriteAllText(sfd.FileName, JsonConvert.SerializeObject(listControl.Items)); | |
| 487 | 新增: MessageBox.Show("导出完成", "提示"); | |
| 488 | 新增: } | |
| 489 | 新增: } | |
| 490 | 新增: catch (Exception ex) | |
| 491 | 新增: { | |
| 492 | 新增: Logger.Error($"导出配置“{configAttribute.Name}”时失败:{ex.Message}"); | |
| 493 | 新增: MessageBox.Show("导出失败!", "提示"); | |
| 494 | 新增: } | |
| 457 | 495 | |
| 458 | 删除: bool? result = sfd.ShowDialog(); | |
| 459 | 删除: if (result == true) | |
| 460 | 删除: { | |
| 461 | 删除: File.WriteAllText(sfd.FileName, JsonConvert.SerializeObject(configData)); | |
| 496 | 新增: }; | |
| 462 | 497 | |
| 463 | 删除: } | |
| 464 | 498 | |
| 465 | 删除: }; | |
| 499 | 新增: moreActionMenu.Items.Add(importMenuItem); | |
| 500 | 新增: moreActionMenu.Items.Add(exportMenuItem); | |
| 501 | 新增: } | |
| 502 | 新增: | |
| 466 | 503 | |
| 467 | 504 | var inputPanel = new Grid(); |
| 468 | 505 | inputPanel.ColumnDefinitions.Add( |
| @@ -475,25 +512,13 @@ namespace UI.Controls.SettingPanel | ||
| 475 | 512 | { |
| 476 | 513 | Width = new GridLength(2, GridUnitType.Star) |
| 477 | 514 | }); |
| 478 | 删除: inputPanel.ColumnDefinitions.Add( | |
| 479 | 删除: new ColumnDefinition() | |
| 480 | 删除: { | |
| 481 | 删除: Width = new GridLength(2, GridUnitType.Star) | |
| 482 | 删除: }); | |
| 483 | 删除: inputPanel.ColumnDefinitions.Add( | |
| 484 | 删除: new ColumnDefinition() | |
| 485 | 删除: { | |
| 486 | 删除: Width = new GridLength(2, GridUnitType.Star) | |
| 487 | 删除: }); | |
| 515 | 新增: | |
| 488 | 516 | inputPanel.Margin = new Thickness(15, 10, 15, 10); |
| 489 | 517 | Grid.SetColumn(addInputBox, 0); |
| 490 | 518 | Grid.SetColumn(addBtn, 1); |
| 491 | 删除: Grid.SetColumn(importBtn, 2); | |
| 492 | 删除: Grid.SetColumn(exportBtn, 3); | |
| 519 | 新增: | |
| 493 | 520 | inputPanel.Children.Add(addInputBox); |
| 494 | 521 | inputPanel.Children.Add(addBtn); |
| 495 | 删除: inputPanel.Children.Add(importBtn); | |
| 496 | 删除: inputPanel.Children.Add(exportBtn); | |
| 497 | 522 | |
| 498 | 523 | // 标题和说明 |
| 499 | 524 | |
| @@ -503,7 +528,28 @@ namespace UI.Controls.SettingPanel | ||
| 503 | 528 | description.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#989CA1")); |
| 504 | 529 | var container = new StackPanel(); |
| 505 | 530 | |
| 506 | 删除: container.Children.Add(description); | |
| 531 | 新增: var head = new Grid(); | |
| 532 | 新增: head.ColumnDefinitions.Add( | |
| 533 | 新增: new ColumnDefinition() | |
| 534 | 新增: { | |
| 535 | 新增: Width = new GridLength(10, GridUnitType.Star) | |
| 536 | 新增: }); | |
| 537 | 新增: head.ColumnDefinitions.Add( | |
| 538 | 新增: new ColumnDefinition() | |
| 539 | 新增: { | |
| 540 | 新增: Width = new GridLength(2, GridUnitType.Star) | |
| 541 | 新增: }); | |
| 542 | 新增: Grid.SetColumn(description, 0); | |
| 543 | 新增: head.Children.Add(description); | |
| 544 | 新增: | |
| 545 | 新增: // 更多操作按钮 | |
| 546 | 新增: if (isHasMoreAction) | |
| 547 | 新增: { | |
| 548 | 新增: Grid.SetColumn(moreActionBtn, 1); | |
| 549 | 新增: head.Children.Add(moreActionBtn); | |
| 550 | 新增: } | |
| 551 | 新增: | |
| 552 | 新增: container.Children.Add(head); | |
| 507 | 553 | container.Children.Add(inputPanel); |
| 508 | 554 | container.Children.Add(listControl); |
| 509 | 555 | return container; |

