Skip to content

Commit 6987240

Browse files
committed
save search options
1 parent 56c1e7d commit 6987240

16 files changed

Lines changed: 245 additions & 65 deletions

File tree

Modules/XamlEditor/ViewModels/EditorControlViewModel.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class EditorControlViewModel : BindableBase
1717
{
1818
private string _fileGuid = null;
1919
private bool _isReseting = false;
20+
private bool _canSyncSearchConfig = false;
2021

2122
private XsdParser _xsdParser = null;
2223
private TextEditorEx _textEditor = null;
@@ -228,6 +229,52 @@ public Func<string, string, string, List<string>> GenerateCompletionDataFunc
228229
}
229230
}
230231

232+
#region Search
233+
234+
private bool _isMatchCase;
235+
public bool IsMatchCase
236+
{
237+
get { return _isMatchCase; }
238+
set
239+
{
240+
if(_isMatchCase == value)
241+
return;
242+
243+
SetProperty(ref _isMatchCase, value);
244+
ApplySearchConfig();
245+
}
246+
}
247+
248+
private bool _isWholeWords;
249+
public bool IsWholeWords
250+
{
251+
get { return _isWholeWords; }
252+
set
253+
{
254+
if(_isWholeWords == value)
255+
return;
256+
257+
SetProperty(ref _isWholeWords, value);
258+
ApplySearchConfig();
259+
}
260+
}
261+
262+
private bool _useRegex;
263+
public bool UseRegex
264+
{
265+
get { return _useRegex; }
266+
set
267+
{
268+
if(_useRegex == value)
269+
return;
270+
271+
SetProperty(ref _useRegex, value);
272+
ApplySearchConfig();
273+
}
274+
}
275+
276+
#endregion
277+
231278
#region Command
232279

233280
private bool CanSave(bool? alreadySelectPath)
@@ -298,6 +345,12 @@ private void OnEditorConfig(EditorConfig config)
298345

299346
AutoCompile = config.AutoCompile;
300347
AutoCompileDelay = config.AutoCompileDelay;
348+
349+
IsMatchCase = config.IsMatchCase;
350+
IsWholeWords = config.IsWholeWords;
351+
UseRegex = config.UseRegex;
352+
353+
_canSyncSearchConfig = true;
301354
}
302355

303356
private void OnLoadText(TabInfo tabInfo)
@@ -357,6 +410,19 @@ private void InitCodeCompletionParser()
357410

358411
Task.Run(() => IsCodeCompletion = _xsdParser.TryParse());
359412
}
413+
414+
private void ApplySearchConfig()
415+
{
416+
if (_eventAggregator != null && _canSyncSearchConfig)
417+
{
418+
_eventAggregator.GetEvent<SearchConfigEvents>().Publish(new SearchConfig
419+
{
420+
IsMatchCase = IsMatchCase,
421+
IsWholeWords = IsWholeWords,
422+
UseRegex = UseRegex,
423+
});
424+
}
425+
}
360426

361427
#endregion
362428
}

Modules/XamlEditor/Views/EditorControl.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
<UserControl x:Class="XamlEditor.Views.EditorControl"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
64
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
75
xmlns:prism="http://prismlibrary.com/"
86
xmlns:themes="clr-namespace:XamlTheme;assembly=XamlTheme"
97
xmlns:controls="clr-namespace:XamlTheme.Controls;assembly=XamlTheme"
10-
prism:ViewModelLocator.AutoWireViewModel="True"
11-
mc:Ignorable="d"
12-
d:DesignHeight="300" d:DesignWidth="300">
8+
prism:ViewModelLocator.AutoWireViewModel="True">
139
<Grid Background="White">
1410
<controls:TextEditorEx Margin="6,0,0,0"
11+
IsMatchCase="{Binding IsMatchCase, Mode=TwoWay}"
12+
IsWholeWords="{Binding IsWholeWords, Mode=TwoWay}"
13+
UseRegex="{Binding UseRegex, Mode=TwoWay}"
1514
IsCodeCompletion="{Binding IsCodeCompletion}"
1615
IsReadOnly="{Binding IsReadOnly}"
1716
LineNumber="{Binding CaretLine, Mode=TwoWay}"

XamlService/Events/ConfigEvents.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
namespace XamlService.Events
55
{
66
public class ConfigEvents : PubSubEvent<EditorConfig> {}
7+
public class SearchConfigEvents : PubSubEvent<SearchConfig> {}
78
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11

22
namespace XamlService.Payloads
33
{
4-
public class EditorConfig
4+
public class SearchConfig
5+
{
6+
public bool IsMatchCase { get; set; }
7+
public bool IsWholeWords { get; set; }
8+
public bool UseRegex { get; set; }
9+
}
10+
11+
public class EditorConfig : SearchConfig
512
{
613
public string FontFamily { get; set; }
714
public double FontSize { get; set; }
@@ -10,6 +17,6 @@ public class EditorConfig
1017
public bool ShowLineNumber { get; set; }
1118

1219
public bool AutoCompile { get; set; }
13-
public double AutoCompileDelay { get; set; }
20+
public double AutoCompileDelay { get; set; }
1421
}
1522
}

XamlTheme/Controls/TextEditorEx.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,54 @@ private static void OnLineNumberPropertyChanged(DependencyObject d, DependencyPr
115115
ctrl._partTextEditor.TextArea.Caret.Line = line;
116116
}
117117

118+
public static readonly DependencyProperty IsMatchCaseProperty = DependencyProperty.Register("IsMatchCase", typeof(bool), _typeofSelf, new PropertyMetadata(OnIsMatchCasePropertyChanged));
119+
public bool IsMatchCase
120+
{
121+
get { return (bool)GetValue(IsMatchCaseProperty); }
122+
set { SetValue(IsMatchCaseProperty, value); }
123+
}
124+
125+
private static void OnIsMatchCasePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
126+
{
127+
var ctrl = d as TextEditorEx;
128+
var isMatchCase = (bool)e.NewValue;
129+
130+
if(ctrl._searchPanel != null)
131+
ctrl._searchPanel.MatchCase = isMatchCase;
132+
}
133+
134+
public static readonly DependencyProperty IsWholeWordsProperty = DependencyProperty.Register("IsWholeWords", typeof(bool), _typeofSelf, new PropertyMetadata(OnIsWholeWordsPropertyChanged));
135+
public bool IsWholeWords
136+
{
137+
get { return (bool)GetValue(IsWholeWordsProperty); }
138+
set { SetValue(IsWholeWordsProperty, value); }
139+
}
140+
141+
private static void OnIsWholeWordsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
142+
{
143+
var ctrl = d as TextEditorEx;
144+
var isWholeWords = (bool)e.NewValue;
145+
146+
if(ctrl._searchPanel != null)
147+
ctrl._searchPanel.WholeWords = isWholeWords;
148+
}
149+
150+
public static readonly DependencyProperty UseRegexProperty = DependencyProperty.Register("UseRegex", typeof(bool), _typeofSelf, new PropertyMetadata(OnUseRegexPropertyChanged));
151+
public bool UseRegex
152+
{
153+
get { return (bool)GetValue(UseRegexProperty); }
154+
set { SetValue(UseRegexProperty, value); }
155+
}
156+
157+
private static void OnUseRegexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
158+
{
159+
var ctrl = d as TextEditorEx;
160+
var useRegex = (bool)e.NewValue;
161+
162+
if(ctrl._searchPanel != null)
163+
ctrl._searchPanel.UseRegex = useRegex;
164+
}
165+
118166
public static readonly DependencyProperty IsModifiedProperty = TextEditor.IsModifiedProperty.AddOwner(_typeofSelf);
119167
public bool IsModified
120168
{
@@ -208,7 +256,10 @@ public override void OnApplyTemplate()
208256
base.OnApplyTemplate();
209257

210258
if (_searchPanel != null)
211-
_searchPanel.Uninstall();
259+
{
260+
_searchPanel.SearchOptionsChanged -= _searchPanel_SearchOptionsChanged;
261+
_searchPanel.Uninstall();
262+
}
212263

213264
if (_partTextEditor != null)
214265
{
@@ -235,8 +286,17 @@ public override void OnApplyTemplate()
235286
_partTextEditor.TextArea.SelectionForeground = null;
236287

237288
_searchPanel = SearchPanel.Install(_partTextEditor.TextArea);
238-
_searchPanel.MarkerBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F6B94D"));
239289
}
290+
291+
if(_searchPanel != null)
292+
{
293+
IsMatchCase = _searchPanel.MatchCase;
294+
IsWholeWords = _searchPanel.WholeWords;
295+
UseRegex = _searchPanel.UseRegex;
296+
297+
_searchPanel.MarkerBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F6B94D"));
298+
_searchPanel.SearchOptionsChanged += _searchPanel_SearchOptionsChanged;
299+
}
240300
}
241301

242302
#endregion
@@ -249,6 +309,13 @@ private void _timer_Tick(object sender, EventArgs e)
249309
RaiseEvent(new RoutedEventArgs(DelayArrivedEvent));
250310
}
251311

312+
private void _searchPanel_SearchOptionsChanged(object sender, SearchOptionsChangedEventArgs e)
313+
{
314+
IsMatchCase = e.MatchCase;
315+
IsWholeWords = e.WholeWords;
316+
UseRegex = e.UseRegex;
317+
}
318+
252319
private void _partTextEditor_TextChanged(object sender, EventArgs e)
253320
{
254321
RefreshFoldings();

XamlTheme/Controls/UserWindow.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,39 @@ public bool HideOriginalTitle
9494
set { SetValue(HideOriginalTitleProperty, value); }
9595
}
9696

97-
public static readonly DependencyProperty TitleBarFontSizeProperty = DependencyProperty.Register("TitleBarFontSize", typeof(double), _typeofSelf, new PropertyMetadata(14d));
98-
public double TitleBarFontSize
97+
public static readonly DependencyProperty CaptionFontSizeProperty = DependencyProperty.Register("CaptionFontSize", typeof(double), _typeofSelf, new PropertyMetadata(14d));
98+
public double CaptionFontSize
9999
{
100-
get { return (double)GetValue(TitleBarFontSizeProperty); }
101-
set { SetValue(TitleBarFontSizeProperty, value); }
100+
get { return (double)GetValue(CaptionFontSizeProperty); }
101+
set { SetValue(CaptionFontSizeProperty, value); }
102+
}
103+
104+
public static readonly DependencyProperty CaptionHeightProperty = DependencyProperty.Register("CaptionHeight", typeof(double), _typeofSelf, new PropertyMetadata(30d));
105+
public double CaptionHeight
106+
{
107+
get { return (double)GetValue(CaptionHeightProperty); }
108+
set { SetValue(CaptionHeightProperty, value); }
102109
}
103110

104-
public static readonly DependencyProperty TitleBarBackgroundProperty = DependencyProperty.Register("TitleBarBackground", typeof(Brush), _typeofSelf);
105-
public Brush TitleBarBackground
111+
public static readonly DependencyProperty CaptionBackgroundProperty = DependencyProperty.Register("CaptionBackground", typeof(Brush), _typeofSelf);
112+
public Brush CaptionBackground
106113
{
107-
get { return (Brush)GetValue(TitleBarBackgroundProperty); }
108-
set { SetValue(TitleBarBackgroundProperty, value); }
114+
get { return (Brush)GetValue(CaptionBackgroundProperty); }
115+
set { SetValue(CaptionBackgroundProperty, value); }
109116
}
110117

111-
public static readonly DependencyProperty TitleBarForegroundProperty = DependencyProperty.Register("TitleBarForeground", typeof(Brush), _typeofSelf);
112-
public Brush TitleBarForeground
118+
public static readonly DependencyProperty CaptionForegroundProperty = DependencyProperty.Register("CaptionForeground", typeof(Brush), _typeofSelf);
119+
public Brush CaptionForeground
113120
{
114-
get { return (Brush)GetValue(TitleBarForegroundProperty); }
115-
set { SetValue(TitleBarForegroundProperty, value); }
121+
get { return (Brush)GetValue(CaptionForegroundProperty); }
122+
set { SetValue(CaptionForegroundProperty, value); }
116123
}
117124

118-
public static readonly DependencyProperty TitleBarContentProperty = DependencyProperty.Register("TitleBarContent", typeof(object), _typeofSelf);
119-
public object TitleBarContent
125+
public static readonly DependencyProperty CaptionContentProperty = DependencyProperty.Register("CaptionContent", typeof(object), _typeofSelf);
126+
public object CaptionContent
120127
{
121-
get { return (object)GetValue(TitleBarContentProperty); }
122-
set { SetValue(TitleBarContentProperty, value); }
128+
get { return (object)GetValue(CaptionContentProperty); }
129+
set { SetValue(CaptionContentProperty, value); }
123130
}
124131

125132
#endregion

XamlTheme/Styles/CodeCompletionStyle.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:cc="clr-namespace:ICSharpCode.AvalonEdit.CodeCompletion;assembly=ICSharpCode.AvalonEdit"
4-
xmlns:themes="clr-namespace:XamlTheme"
4+
xmlns:shell="clr-namespace:Microsoft.Windows.Shell"
55
xmlns:controls="clr-namespace:XamlTheme.Controls">
66

77
<Style TargetType="{x:Type controls:CompletionWindowEx}">
8-
<Setter Property="WindowChrome.WindowChrome">
8+
<Setter Property="shell:WindowChrome.WindowChrome">
99
<Setter.Value>
10-
<WindowChrome CornerRadius="0" GlassFrameThickness="0"/>
10+
<shell:WindowChrome CaptionHeight="0" GlassFrameThickness="0,0,0,1"/>
1111
</Setter.Value>
1212
</Setter>
1313
</Style>

XamlTheme/Styles/UserWindowStyle.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
TargetType="{x:Type controls:UserWindow}">
99
<Setter Property="shell:WindowChrome.WindowChrome">
1010
<Setter.Value>
11-
<shell:WindowChrome CaptionHeight="30" ResizeBorderThickness="4" GlassFrameThickness="0,0,0,1"/>
11+
<shell:WindowChrome ResizeBorderThickness="4" GlassFrameThickness="0,0,0,1"
12+
CaptionHeight="{Binding CaptionHeight, RelativeSource={RelativeSource AncestorType=controls:UserWindow}}"/>
1213
</Setter.Value>
1314
</Setter>
1415
<Setter Property="BorderThickness" Value="0"/>
@@ -19,8 +20,8 @@
1920
<Setter Property="Background" Value="#EFEFF2"/>
2021
<Setter Property="FontSize" Value="13"/>
2122
<Setter Property="FontFamily" Value="Arial,SimSun"/>
22-
<Setter Property="TitleBarForeground" Value="#141414"/>
23-
<Setter Property="TitleBarBackground" Value="#EFEFF2"/>
23+
<Setter Property="CaptionForeground" Value="#141414"/>
24+
<Setter Property="CaptionBackground" Value="#EFEFF2"/>
2425
<Setter Property="ResizeMode" Value="CanResize"/>
2526
<Setter Property="Template">
2627
<Setter.Value>
@@ -32,19 +33,19 @@
3233
UseLayoutRounding="True">
3334
<Grid x:Name="LayoutRoot">
3435
<Grid.RowDefinitions>
35-
<RowDefinition Height="30"/>
36+
<RowDefinition Height="auto"/>
3637
<RowDefinition Height="*"/>
3738
</Grid.RowDefinitions>
38-
<Grid Grid.Row="0" Background="{TemplateBinding TitleBarBackground}">
39+
<Grid Grid.Row="0" Background="{TemplateBinding CaptionBackground}" Height="{TemplateBinding CaptionHeight}">
3940
<Grid.ColumnDefinitions>
4041
<ColumnDefinition Width="auto"/>
4142
<ColumnDefinition Width="auto"/>
4243
<ColumnDefinition Width="*"/>
4344
<ColumnDefinition Width="auto"/>
4445
</Grid.ColumnDefinitions>
4546
<Image Grid.Column="0" Source="{TemplateBinding Icon}" VerticalAlignment="Center" shell:WindowChrome.IsHitTestVisibleInChrome="False"/>
46-
<TextBlock x:Name="TitleTextBlock" Grid.Column="1" Margin="5,0,0,0" Text="{TemplateBinding Title}" FontSize="{TemplateBinding TitleBarFontSize}" FontWeight="Medium" VerticalAlignment="Center" Foreground="{TemplateBinding TitleBarForeground}" TextTrimming="CharacterEllipsis" shell:WindowChrome.IsHitTestVisibleInChrome="False"/>
47-
<ContentPresenter Grid.Column="2" ContentSource="TitleBarContent" shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
47+
<TextBlock x:Name="TitleTextBlock" Grid.Column="1" Margin="5,0,0,0" Text="{TemplateBinding Title}" FontSize="{TemplateBinding CaptionFontSize}" FontWeight="Medium" VerticalAlignment="Center" Foreground="{TemplateBinding CaptionForeground}" TextTrimming="CharacterEllipsis" shell:WindowChrome.IsHitTestVisibleInChrome="False"/>
48+
<ContentPresenter Grid.Column="2" ContentSource="CaptionContent" shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
4849
<StackPanel Grid.Column="3" Orientation="Horizontal" shell:WindowChrome.IsHitTestVisibleInChrome="True">
4950
<Button x:Name="MiniBtn" Style="{DynamicResource {x:Static themes:ResourceKeys.TitlebarButtonStyleKey}}" Width="37" Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" VerticalContentAlignment="Center" Padding="0,5,0,0" >
5051
<Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}" VerticalAlignment="Center" HorizontalAlignment="Center"

XamlViewer/App.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ protected override void OnInitialized()
9595
ShowLineNumber = appData.Config.ShowLineNumber,
9696

9797
AutoCompile = appData.Config.AutoCompile,
98-
AutoCompileDelay = appData.Config.AutoCompileDelay
98+
AutoCompileDelay = appData.Config.AutoCompileDelay,
99+
100+
IsMatchCase = appData.Config.IsMatchCase,
101+
IsWholeWords = appData.Config.IsWholeWords,
102+
UseRegex = appData.Config.UseRegex
99103
});
100104
}
101105
}

XamlViewer/Dialogs/DialogWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Style="{StaticResource {x:Static themes:ResourceKeys.NormalUserWindowStyleKey}}"
88
SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False"
99
prism:Dialog.WindowStartupLocation="CenterScreen"
10-
Title="XAML Viewer" Background="White" MinWidth="350" TitleBarFontSize="13"/>
10+
Title="XAML Viewer" Background="White" MinWidth="350" CaptionFontSize="13" CaptionHeight="27"/>

0 commit comments

Comments
 (0)