Skip to content

Commit dbf0807

Browse files
Code Quality: Add IsExecutable check for SearchAction (#17646)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent 7c2e9c8 commit dbf0807

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Files.App/Actions/Global/SearchAction.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,35 @@ public HotKey SecondHotKey
2323
public RichGlyph Glyph
2424
=> new(themedIconStyle: "App.ThemedIcons.Omnibar.Search");
2525

26+
public bool IsExecutable
27+
=> context.ShellPage is not null;
28+
2629
public SearchAction()
2730
{
2831
context = Ioc.Default.GetRequiredService<IContentPageContext>();
32+
33+
context.PropertyChanged += Context_PropertyChanged;
2934
}
3035

3136
public Task ExecuteAsync(object? parameter = null)
3237
{
33-
context.ShellPage!.ToolbarViewModel.SwitchToSearchMode();
38+
// Check if ShellPage is available before executing the action
39+
if (context.ShellPage is null)
40+
return Task.CompletedTask;
41+
42+
context.ShellPage.ToolbarViewModel.SwitchToSearchMode();
3443

3544
return Task.CompletedTask;
3645
}
46+
47+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
48+
{
49+
switch (e.PropertyName)
50+
{
51+
case nameof(IContentPageContext.ShellPage):
52+
OnPropertyChanged(nameof(IsExecutable));
53+
break;
54+
}
55+
}
3756
}
3857
}

0 commit comments

Comments
 (0)