Skip to content

Commit

Permalink
[PowerToys Run] Implemented Setting to Clear Search Query when PowerT…
Browse files Browse the repository at this point in the history
…oys Run is Launched (#4995)

* Implemented Clear Input On Launch

* Move logic to seperate command on viewmodel

* Added Settings Sync
Moved logic from OnDeactivated to OnActivated

* Complete after testing

Co-authored-by: Roy <royvou@hotmailcom>
  • Loading branch information
royvou and Roy committed Jul 15, 2020
1 parent f59abe2 commit 78946c1
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class PowerLauncherProperties

public bool ignore_hotkeys_in_fullscreen { get; set; }

public bool clear_input_on_launch { get; set; }

public PowerLauncherProperties()
{
open_powerlauncher = new HotkeySettings();
Expand All @@ -35,6 +37,7 @@ public PowerLauncherProperties()
search_result_preference = "most_recently_used";
search_type_preference = "application_name";
ignore_hotkeys_in_fullscreen = false;
clear_input_on_launch = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@
<data name="PowerLauncher_IgnoreHotkeysInFullScreen.Content" xml:space="preserve">
<value>Ignore hotkeys in fullscreen mode</value>
</data>
<data name="PowerLauncher_ClearInputOnLaunch.Content" xml:space="preserve">
<value>Clear the previous query on launch</value>
</data>
<data name="KeyboardManager_KeysMappingLayoutRightHeader.Text" xml:space="preserve">
<value>To:</value>
<comment>Keyboard Manager mapping keys view right header</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,38 @@ public bool OverrideWinSKey
}
}

public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.properties.ignore_hotkeys_in_fullscreen;
}

set
{
if (settings.properties.ignore_hotkeys_in_fullscreen != value)
{
settings.properties.ignore_hotkeys_in_fullscreen = value;
UpdateSettings();
}
}
public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.properties.ignore_hotkeys_in_fullscreen;
}

set
{
if (settings.properties.ignore_hotkeys_in_fullscreen != value)
{
settings.properties.ignore_hotkeys_in_fullscreen = value;
UpdateSettings();
}
}
}

public bool ClearInputOnLaunch
{
get
{
return settings.properties.clear_input_on_launch;
}

set
{
if (settings.properties.clear_input_on_launch != value)
{
settings.properties.clear_input_on_launch = value;
UpdateSettings();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.IgnoreHotkeysInFullScreen}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher}"
/>

<CheckBox x:Uid="PowerLauncher_ClearInputOnLaunch"
Margin="{StaticResource SmallTopMargin}"
IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.ClearInputOnLaunch}"
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.EnablePowerLauncher}"
/>
</StackPanel>
<StackPanel
x:Name="SidePanel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,7 @@ public void Override_ShouldUpdateOverrides()
Assert.IsTrue(mockSettings.properties.override_win_r_key);
Assert.IsFalse(mockSettings.properties.override_win_s_key);
}


}
}
1 change: 1 addition & 0 deletions src/modules/launcher/PowerLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Closing="OnClosing"
Background="Transparent"
LocationChanged="OnLocationChanged"
Activated="OnActivated"
Deactivated="OnDeactivated"
IsVisibleChanged="OnVisibilityChanged"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Expand Down
10 changes: 9 additions & 1 deletion src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,17 @@ private void InitializePosition()
_settings.WindowLeft = Left;
}

private void OnActivated(object sender, EventArgs e)
{
if (_settings.ClearInputOnLaunch)
{
_viewModel.ClearQueryCommand.Execute(null);
}
}

private void OnDeactivated(object sender, EventArgs e)
{
if (_settings.HideWhenDeactivated)
if (_settings.HideWhenDeactivated)
{
//(this.FindResource("OutroStoryboard") as Storyboard).Begin();
Hide();
Expand Down
5 changes: 5 additions & 0 deletions src/modules/launcher/PowerLauncher/SettingsWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public void OverloadSettings()
{
_settings.IgnoreHotkeysOnFullscreen = overloadSettings.properties.ignore_hotkeys_in_fullscreen;
}

if (_settings.ClearInputOnLaunch != overloadSettings.properties.clear_input_on_launch)
{
_settings.ClearInputOnLaunch = overloadSettings.properties.clear_input_on_launch;
}
}
// the settings application can hold a lock on the settings.json file which will result in a IOException.
// This should be changed to properly synch with the settings app instead of retrying.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public bool HideNotifyIcon
}
public bool LeaveCmdOpen { get; set; }
public bool HideWhenDeactivated { get; set; } = true;
public bool ClearInputOnLaunch { get; set; } = false;

public bool RememberLastLaunchLocation { get; set; }
public bool IgnoreHotkeysOnFullscreen { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions src/modules/launcher/Wox/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ private void InitializeKeyCommands()
SelectedResults = Results;
}
});

ClearQueryCommand = new RelayCommand(_ =>
{
if(!string.IsNullOrEmpty(QueryText))
{
ChangeQueryText(string.Empty,true);
//Push Event to UI SystemQuery has changed
OnPropertyChanged(nameof(SystemQueryText));
}
});
}

#endregion
Expand Down Expand Up @@ -342,6 +352,8 @@ private ResultsViewModel SelectedResults
public ICommand LoadContextMenuCommand { get; set; }
public ICommand LoadHistoryCommand { get; set; }
public ICommand OpenResultCommand { get; set; }
public ICommand ClearQueryCommand { get; set; }


#endregion

Expand Down

0 comments on commit 78946c1

Please sign in to comment.