mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
查找与替换完成
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
@@ -576,6 +577,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showSearch;
|
||||
public bool ShowSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showSearch;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _showSearch, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _searchText;
|
||||
public string SearchText
|
||||
{
|
||||
@@ -589,6 +603,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private string _replaceText;
|
||||
public string ReplaceText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _replaceText;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _replaceText, value);
|
||||
}
|
||||
}
|
||||
|
||||
private string _searchInfo;
|
||||
public string SearchInfo
|
||||
{
|
||||
@@ -602,6 +629,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _searchCaseMatch;
|
||||
public bool SearchCaseMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _searchCaseMatch;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _searchCaseMatch, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _searchWholeWordMatch;
|
||||
public bool SearchWholeWordMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _searchWholeWordMatch;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _searchWholeWordMatch, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected ObservableCollection<CinchMenuItem> menuOptions;
|
||||
public IEnumerable<CinchMenuItem> MenuOptions
|
||||
{
|
||||
@@ -1028,6 +1081,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _showSearchCommand;
|
||||
public ICommand ShowSearchCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._showSearchCommand ?? (this._showSearchCommand = new SimpleCommand(ExecuteEnable, this.ExecutedShowSearchCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _closeSearchCommand;
|
||||
public ICommand CloseSearchCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._closeSearchCommand ?? (this._closeSearchCommand = new SimpleCommand(ExecuteEnable, this.ExecutedCloseSearchCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _searchDownCommand;
|
||||
public ICommand SearchDownCommand
|
||||
{
|
||||
@@ -1045,6 +1116,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return this._searchUpCommand ?? (this._searchUpCommand = new SimpleCommand(ExecuteEnable, this.ExecutedSearchUpCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _replaceCommand;
|
||||
public ICommand ReplaceCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._replaceCommand ?? (this._replaceCommand = new SimpleCommand(ExecuteEnable, this.ExecutedSearchReplaceCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _replaceAllCommand;
|
||||
public ICommand ReplaceAllCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._replaceAllCommand ?? (this._replaceAllCommand = new SimpleCommand(ExecuteEnable, this.ExecutedSearchReplaceAllCommand));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ctor和初始化
|
||||
@@ -1499,6 +1588,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Dictionary<SelectableDesignerItemViewModelBase, bool> infos = selectedItems.ToDictionary(p => p, p => p.IsSelected);
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
ClearSelectedItems();
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
item.IsSelected = true;
|
||||
@@ -3002,6 +3092,31 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
UngroupCommand.Execute(null);
|
||||
return true;
|
||||
}
|
||||
else if (DiagramOption.ShortcutOption.Search(e))
|
||||
{
|
||||
ShowSearchCommand.Execute(null);
|
||||
return true;
|
||||
}
|
||||
else if (DiagramOption.ShortcutOption.SearchDown(e))
|
||||
{
|
||||
SearchDownCommand.Execute(SearchText);
|
||||
return true;
|
||||
}
|
||||
else if (DiagramOption.ShortcutOption.SearchUp(e))
|
||||
{
|
||||
SearchUpCommand.Execute(SearchText);
|
||||
return true;
|
||||
}
|
||||
else if (DiagramOption.ShortcutOption.Replace(e))
|
||||
{
|
||||
ReplaceCommand.Execute(new object[] { SearchText, ReplaceText });
|
||||
return true;
|
||||
}
|
||||
else if (DiagramOption.ShortcutOption.ReplaceAll(e))
|
||||
{
|
||||
ReplaceAllCommand.Execute(new object[] { SearchText, ReplaceText });
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -3034,12 +3149,23 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
private void ExecutedShowSearchCommand(object parameter)
|
||||
{
|
||||
ShowSearch = true;
|
||||
}
|
||||
|
||||
private void ExecutedCloseSearchCommand(object parameter)
|
||||
{
|
||||
ShowSearch = false;
|
||||
}
|
||||
|
||||
private void ExecutedSearchUpCommand(object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
var selecteddesign = SelectedItem as DesignerItemViewModelBase;
|
||||
var searchitems = Items.OfType<DesignerItemViewModelBase>().Where(p => p.Text?.Contains(obj.ToString()) == true).ToList();
|
||||
var selecteddesign = SelectedItem as SelectableDesignerItemViewModelBase;
|
||||
|
||||
var searchitems = Items.OfType<SelectableDesignerItemViewModelBase>().Where(p => SearchMatch(p.Text, obj.ToString()) == true).ToList();
|
||||
if (searchitems.Count > 0)
|
||||
{
|
||||
int selectindex = 0;
|
||||
@@ -3079,8 +3205,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (!string.IsNullOrEmpty(obj?.ToString()))
|
||||
{
|
||||
var selecteddesign = SelectedItem as DesignerItemViewModelBase;
|
||||
var searchitems = Items.OfType<DesignerItemViewModelBase>().Where(p => p.Text?.Contains(obj.ToString()) == true).ToList();
|
||||
var selecteddesign = SelectedItem as SelectableDesignerItemViewModelBase;
|
||||
var searchitems = Items.OfType<SelectableDesignerItemViewModelBase>().Where(p => SearchMatch(p.Text, obj.ToString()) == true).ToList();
|
||||
if (searchitems.Count > 0)
|
||||
{
|
||||
int selectindex = 0;
|
||||
@@ -3115,6 +3241,85 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SearchInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
private bool SearchMatch(string input, string searchtext)
|
||||
{
|
||||
if (input == null || searchtext == null)
|
||||
return false;
|
||||
|
||||
if (SearchCaseMatch == true && SearchWholeWordMatch == true)
|
||||
{
|
||||
return input == searchtext;
|
||||
}
|
||||
else if (SearchCaseMatch == true && SearchWholeWordMatch == false)
|
||||
{
|
||||
return input.Contains(searchtext);
|
||||
}
|
||||
else if (SearchCaseMatch == false && SearchWholeWordMatch == true)
|
||||
{
|
||||
return input.ToLower() == searchtext.ToLower();
|
||||
}
|
||||
else
|
||||
{
|
||||
return input.ToLower().Contains(searchtext.ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
private string ReplaceSearch(string input, string searchtext, string replcetext)
|
||||
{
|
||||
if (SearchCaseMatch == true)
|
||||
{
|
||||
return input.Replace(searchtext, replcetext);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Regex.Replace(input, searchtext, replcetext, RegexOptions.IgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecutedSearchReplaceCommand(object obj)
|
||||
{
|
||||
if (obj is object[] array && array.Length == 2)
|
||||
{
|
||||
var items = SelectedItems.Where(p => SearchMatch(p.Text, array[0]?.ToString()) == true).ToList();
|
||||
Dictionary<SelectableDesignerItemViewModelBase, string> infos = items.ToDictionary(p => p, p => p.Text);
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.Text = ReplaceSearch(item.Text, array[0]?.ToString(), array[1]?.ToString());
|
||||
}
|
||||
},
|
||||
() => {
|
||||
foreach (var item in infos)
|
||||
{
|
||||
item.Key.Text = item.Value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecutedSearchReplaceAllCommand(object obj)
|
||||
{
|
||||
if (obj is object[] array && array.Length == 2)
|
||||
{
|
||||
var items = Items.Where(p => SearchMatch(p.Text, array[0]?.ToString()) == true).ToList();
|
||||
Dictionary<SelectableDesignerItemViewModelBase, string> infos = items.ToDictionary(p => p, p => p.Text);
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.Text = ReplaceSearch(item.Text, array[0]?.ToString(), array[1]?.ToString());
|
||||
}
|
||||
},
|
||||
() => {
|
||||
foreach (var item in infos)
|
||||
{
|
||||
item.Key.Text = item.Value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user