Skip to content

Commit 7f0851b

Browse files
authored
Merge pull request #4023 from Flow-Launcher/shell_setting_panel_enhancement
Refactor ShellSettings with Binding & Fix IsEnabled logic
2 parents 5b6ea73 + 652ec40 commit 7f0851b

File tree

7 files changed

+284
-167
lines changed

7 files changed

+284
-167
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
5+
namespace Flow.Launcher.Plugin.Shell.Converters;
6+
7+
public class LeaveShellOpenOrCloseShellAfterPressEnabledConverter : IMultiValueConverter
8+
{
9+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
10+
{
11+
if (
12+
values.Length != 2 ||
13+
values[0] is not bool closeShellAfterPressOrLeaveShellOpen ||
14+
values[1] is not Shell shell
15+
)
16+
return Binding.DoNothing;
17+
18+
return (!closeShellAfterPressOrLeaveShellOpen) && shell != Shell.RunCommand;
19+
}
20+
21+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
}

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Threading.Tasks;
88
using Flow.Launcher.Plugin.SharedCommands;
9+
using Flow.Launcher.Plugin.Shell.Views;
910
using WindowsInput;
1011
using WindowsInput.Native;
1112
using Control = System.Windows.Controls.Control;
@@ -383,9 +384,16 @@ public void Init(PluginInitContext context)
383384
Context = context;
384385
_settings = context.API.LoadSettingJsonStorage<Settings>();
385386
context.API.RegisterGlobalKeyboardCallback(API_GlobalKeyboardEvent);
387+
// Since the old Settings class set default value of ShowOnlyMostUsedCMDsNumber to 0 which is a wrong value,
388+
// we need to fix it here to make sure the default value is 5
389+
// todo: remove this code block after release v2.2.0
390+
if (_settings.ShowOnlyMostUsedCMDsNumber == 0)
391+
{
392+
_settings.ShowOnlyMostUsedCMDsNumber = 5;
393+
}
386394
}
387395

388-
bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
396+
private bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
389397
{
390398
if (!Context.CurrentPluginMetadata.Disabled && _settings.ReplaceWinR)
391399
{
Lines changed: 114 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,121 @@
11
using System.Collections.Generic;
2+
using Flow.Launcher.Localization.Attributes;
23

34
namespace Flow.Launcher.Plugin.Shell
45
{
5-
public class Settings
6+
public class Settings : BaseModel
67
{
7-
public Shell Shell { get; set; } = Shell.Cmd;
8+
private Shell _shell = Shell.Cmd;
9+
public Shell Shell
10+
{
11+
get => _shell;
12+
set
13+
{
14+
if (_shell != value)
15+
{
16+
_shell = value;
17+
OnPropertyChanged();
18+
}
19+
}
20+
}
821

9-
public bool ReplaceWinR { get; set; } = false;
22+
private bool _replaceWinR = false;
23+
public bool ReplaceWinR
24+
{
25+
get => _replaceWinR;
26+
set
27+
{
28+
if (_replaceWinR != value)
29+
{
30+
_replaceWinR = value;
31+
OnPropertyChanged();
32+
}
33+
}
34+
}
1035

11-
public bool CloseShellAfterPress { get; set; } = false;
36+
private bool _closeShellAfterPress = false;
37+
public bool CloseShellAfterPress
38+
{
39+
get => _closeShellAfterPress;
40+
set
41+
{
42+
if (_closeShellAfterPress != value)
43+
{
44+
_closeShellAfterPress = value;
45+
OnPropertyChanged();
46+
}
47+
}
48+
}
1249

13-
public bool LeaveShellOpen { get; set; }
50+
private bool _leaveShellOpen;
51+
public bool LeaveShellOpen
52+
{
53+
get => _leaveShellOpen;
54+
set
55+
{
56+
if (_leaveShellOpen != value)
57+
{
58+
_leaveShellOpen = value;
59+
OnPropertyChanged();
60+
}
61+
}
62+
}
1463

15-
public bool RunAsAdministrator { get; set; } = true;
64+
private bool _runAsAdministrator = true;
65+
public bool RunAsAdministrator
66+
{
67+
get => _runAsAdministrator;
68+
set
69+
{
70+
if (_runAsAdministrator != value)
71+
{
72+
_runAsAdministrator = value;
73+
OnPropertyChanged();
74+
}
75+
}
76+
}
1677

17-
public bool UseWindowsTerminal { get; set; } = false;
78+
private bool _useWindowsTerminal = false;
79+
public bool UseWindowsTerminal
80+
{
81+
get => _useWindowsTerminal;
82+
set
83+
{
84+
if (_useWindowsTerminal != value)
85+
{
86+
_useWindowsTerminal = value;
87+
OnPropertyChanged();
88+
}
89+
}
90+
}
1891

19-
public bool ShowOnlyMostUsedCMDs { get; set; }
92+
private bool _showOnlyMostUsedCMDs;
93+
public bool ShowOnlyMostUsedCMDs
94+
{
95+
get => _showOnlyMostUsedCMDs;
96+
set
97+
{
98+
if (_showOnlyMostUsedCMDs != value)
99+
{
100+
_showOnlyMostUsedCMDs = value;
101+
OnPropertyChanged();
102+
}
103+
}
104+
}
20105

21-
public int ShowOnlyMostUsedCMDsNumber { get; set; }
106+
private int _showOnlyMostUsedCMDsNumber = 5;
107+
public int ShowOnlyMostUsedCMDsNumber
108+
{
109+
get => _showOnlyMostUsedCMDsNumber;
110+
set
111+
{
112+
if (_showOnlyMostUsedCMDsNumber != value)
113+
{
114+
_showOnlyMostUsedCMDsNumber = value;
115+
OnPropertyChanged();
116+
}
117+
}
118+
}
22119

23120
public Dictionary<string, int> CommandHistory { get; set; } = [];
24121

@@ -31,11 +128,19 @@ public void AddCmdHistory(string cmdName)
31128
}
32129
}
33130

131+
[EnumLocalize]
34132
public enum Shell
35133
{
134+
[EnumLocalizeValue("CMD")]
36135
Cmd = 0,
136+
137+
[EnumLocalizeValue("PowerShell")]
37138
Powershell = 1,
139+
140+
[EnumLocalizeValue("RunCommand")]
38141
RunCommand = 2,
142+
143+
[EnumLocalizeValue("Pwsh")]
39144
Pwsh = 3,
40145
}
41146
}

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)