Skip to content

Commit 423621d

Browse files
committed
Update keyword changing logic
1 parent beaa2ff commit 423621d

8 files changed

Lines changed: 33 additions & 38 deletions

File tree

Flow.Launcher.Plugin.OneNote/Keywords.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,15 @@ public class Keywords
1616
}
1717

1818
[JsonConverter(typeof(KeywordJsonConverter))]
19-
public class Keyword : BaseModel
19+
public class Keyword
2020
{
21-
public Keyword(string value)
22-
{
23-
Value = value;
24-
}
21+
public Keyword(string value) => Value = value;
2522
public string Value { get; private set; }
2623

27-
public void ChangeKeyword(string newValue)
28-
{
29-
Value = newValue;
30-
OnPropertyChanged(nameof(Value));
31-
}
24+
public void ChangeKeyword(string newValue) => Value = newValue;
3225

3326
public int Length => Value.Length;
34-
public static implicit operator string(Keyword keyword) => keyword.Value;
27+
public static implicit operator string(Keyword keyword) => keyword.Value;
3528
public override string ToString() => Value;
3629
}
3730

Flow.Launcher.Plugin.OneNote/Search/NotebookExplorer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ private List<Result> Explorer(string search, IOneNoteItem? parent, IEnumerable<I
112112
case null:
113113
results.Add(resultCreator.CreateNewNotebookResult(search));
114114
break;
115-
case INotebookOrSectionGroup p:
116-
results.Add(resultCreator.CreateNewSectionResult(search, p));
117-
results.Add(resultCreator.CreateNewSectionGroupResult(search, p));
115+
case INotebookOrSectionGroup x:
116+
results.Add(resultCreator.CreateNewSectionResult(search, x));
117+
results.Add(resultCreator.CreateNewSectionGroupResult(search, x));
118118
break;
119119
case OneNoteSection section:
120120
if (!section.Locked)

Flow.Launcher.Plugin.OneNote/UI/RelayCommand.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ public RelayCommand(Action<T?> execute, Predicate<T?>? canExecute = null)
4747
this.execute = execute;
4848
this.canExecute = canExecute;
4949
}
50-
51-
public bool CanExecute(T? parameter) => canExecute?.Invoke(parameter) != false;
52-
public void Execute(T? parameter) => execute(parameter);
5350

54-
public bool CanExecute(object? parameter) => CanExecute((T?)parameter);
55-
public void Execute(object? parameter) => Execute((T?)parameter);
51+
public bool CanExecute(object? parameter) => canExecute?.Invoke((T?)parameter) != false;
52+
public void Execute(object? parameter) => execute.Invoke((T?)parameter);
5653
}
5754
}

Flow.Launcher.Plugin.OneNote/UI/ViewModels/ChangeKeywordViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ private bool CanChangeKeyword(string? newKeyword)
4343
}
4444

4545
newKeyword = newKeyword.Trim();
46-
if (SelectedKeyword.Keyword == newKeyword)
46+
if (SelectedKeyword.Value == newKeyword)
4747
{
4848
ErrorMessage = "The new keyword is the same as the old keyword.";
4949
return false;
5050
}
5151

52-
KeywordViewModel? alreadySetKeyword = keywords.FirstOrDefault(k => k.Keyword == newKeyword);
52+
KeywordViewModel? alreadySetKeyword = keywords.FirstOrDefault(k => k.Value == newKeyword);
5353
if (alreadySetKeyword != null)
5454
{
5555
ErrorMessage = $"The new keyword is already set for {alreadySetKeyword.Name}.";
@@ -62,7 +62,7 @@ private bool CanChangeKeyword(string? newKeyword)
6262

6363
private void ChangeKeyword(string newKeyword)
6464
{
65-
SelectedKeyword.Keyword.ChangeKeyword(newKeyword.Trim());
65+
SelectedKeyword.Value = newKeyword.Trim();
6666
context.API.SaveSettingJsonStorage<Settings>();
6767
context.API.ReQuery();
6868
closeAction.Invoke();
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
namespace Flow.Launcher.Plugin.OneNote.UI.ViewModels
22
{
3-
public class KeywordViewModel : BaseModel
3+
public class KeywordViewModel : Model
44
{
5+
private readonly Keyword keyword;
56
public KeywordViewModel(string keywordName, Keyword keyword)
67
{
78
Name = keywordName;
8-
Keyword = keyword;
9-
keyword.PropertyChanged += (_, args) =>
10-
{
11-
if (args.PropertyName == nameof(Keyword.Value))
12-
{
13-
OnPropertyChanged(nameof(Keyword));
14-
}
15-
};
9+
this.keyword = keyword;
1610
}
1711
public string Name { get; }
18-
public Keyword Keyword { get; }
12+
13+
public string Value
14+
{
15+
get => keyword.Value;
16+
set
17+
{
18+
keyword.ChangeKeyword(value);
19+
OnPropertyChanged();
20+
}
21+
}
1922
}
2023
}

Flow.Launcher.Plugin.OneNote/UI/ViewModels/SettingsViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public SettingsViewModel(PluginInitContext context, Settings settings, IconProvi
1818
{
1919
this.iconProvider = iconProvider;
2020
Settings = settings;
21-
Keywords = settings.Keywords
21+
Keywords = settings.Keywords //Order is the order they are written in Keywords.cs
2222
.GetType()
2323
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
2424
.Select(p => new KeywordViewModel(p.Name.Humanize(LetterCasing.Title), (Keyword)p.GetValue(settings.Keywords)!))
@@ -60,6 +60,8 @@ public SettingsViewModel(PluginInitContext context, Settings settings, IconProvi
6060
public ICommand ClearCachedIconsCommand { get; }
6161
public Settings Settings { get; }
6262
public KeywordViewModel[] Keywords { get; }
63+
public KeywordViewModel NotebookExplorerKeyword => Keywords[0];
64+
public KeywordViewModel RecentPagesKeyword => Keywords[1];
6365
public IconThemeViewModel[] IconThemes { get; }
6466
public string CachedIconsFileSize => iconProvider.GeneratedImagesDirectoryInfo.EnumerateFiles()
6567
.Select(file => file.Length)

Flow.Launcher.Plugin.OneNote/UI/Views/ChangeKeywordWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
FontSize="14"
118118
FontWeight="SemiBold"
119119
Foreground="{DynamicResource Color05B}"
120-
Text="{Binding SelectedKeyword.Keyword}" />
120+
Text="{Binding SelectedKeyword.Value}" />
121121
</StackPanel>
122122
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
123123
<TextBlock

Flow.Launcher.Plugin.OneNote/UI/Views/SettingsView.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<ItemsControl Style="{StaticResource SettingGrid}">
3737
<StackPanel Style="{StaticResource TextPanel}">
3838
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Show recycle bin" />
39-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding Keywords[0].Keyword, StringFormat='When using &quot;{0}&quot; show items that are in the recycle bin'}" />
39+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding NotebookExplorerKeyword.Value, StringFormat='When using &quot;{0}&quot; show items that are in the recycle bin'}" />
4040
</StackPanel>
4141
<ui:ToggleSwitch
4242
Grid.Column="2"
@@ -52,7 +52,7 @@
5252
<ItemsControl Style="{StaticResource SettingGrid}">
5353
<StackPanel Style="{StaticResource TextPanel}">
5454
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Show encrypted sections" />
55-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding Keywords[0].Keyword, StringFormat='When using &quot;{0}&quot; show encrypted sections, if the section has been unlocked, allow temporary access.'}" />
55+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding NotebookExplorerKeyword.Value, StringFormat='When using &quot;{0}&quot; show encrypted sections, if the section has been unlocked, allow temporary access.'}" />
5656
</StackPanel>
5757
<ui:ToggleSwitch
5858
Grid.Column="2"
@@ -164,7 +164,7 @@
164164
<ItemsControl Style="{StaticResource SettingGrid}">
165165
<StackPanel Style="{StaticResource TextPanel}">
166166
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="Default number of recent pages" />
167-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding Keywords[1].Keyword, StringFormat='The initial number of recent pages to show when using &quot;{0}&quot;'}" />
167+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{Binding RecentPagesKeyword.Value, StringFormat='The initial number of recent pages to show when using &quot;{0}&quot;'}" />
168168
</StackPanel>
169169
<ComboBox
170170
Grid.Column="2"
@@ -262,7 +262,7 @@
262262
Header="Keyword">
263263
<GridViewColumn.CellTemplate>
264264
<DataTemplate DataType="{x:Type vm:KeywordViewModel}">
265-
<TextBlock Width="{Binding Width, ElementName=KeywordColumn}" Text="{Binding Keyword}">
265+
<TextBlock Width="{Binding Width, ElementName=KeywordColumn}" Text="{Binding Value}">
266266
<TextBlock.InputBindings>
267267
<ui:StaticResource ResourceKey="DoubleClickEdit" />
268268
</TextBlock.InputBindings>

0 commit comments

Comments
 (0)