Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace Flow.Launcher.Plugin.Shell.Converters;

public class LeaveShellOpenOrCloseShellAfterPressEnabledConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (
values.Length != 2 ||
values[0] is not bool closeShellAfterPressOrLeaveShellOpen ||
values[1] is not Shell shell
)
return Binding.DoNothing;

return (!closeShellAfterPressOrLeaveShellOpen) && shell != Shell.RunCommand;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
10 changes: 9 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin.Shell.Views;
using WindowsInput;
using WindowsInput.Native;
using Control = System.Windows.Controls.Control;
Expand Down Expand Up @@ -45,14 +46,14 @@
string basedir = null;
string dir = null;
string excmd = Environment.ExpandEnvironmentVariables(cmd);
if (Directory.Exists(excmd) && (cmd.EndsWith('/') || cmd.EndsWith('\\')))

Check warning on line 49 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
{
basedir = excmd;

Check warning on line 51 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
dir = cmd;
}
else if (Directory.Exists(Path.GetDirectoryName(excmd) ?? string.Empty))

Check warning on line 54 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
{
basedir = Path.GetDirectoryName(excmd);

Check warning on line 56 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
var dirName = Path.GetDirectoryName(cmd);
dir = (dirName.EndsWith('/') || dirName.EndsWith('\\')) ? dirName : cmd[..(dirName.Length + 1)];
}
Expand Down Expand Up @@ -128,7 +129,7 @@
return ret;
}).Where(o => o != null);

if (_settings.ShowOnlyMostUsedCMDs)

Check warning on line 132 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`CMDs` is not a recognized word. (unrecognized-spelling)
return [.. history.Take(_settings.ShowOnlyMostUsedCMDsNumber)];

return [.. history];
Expand Down Expand Up @@ -271,7 +272,7 @@
}
else
{
info.FileName = "pwsh.exe";

Check warning on line 275 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`pwsh` is not a recognized word. (unrecognized-spelling)
}
if (_settings.LeaveShellOpen)
{
Expand Down Expand Up @@ -383,15 +384,22 @@
Context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
context.API.RegisterGlobalKeyboardCallback(API_GlobalKeyboardEvent);
// Since the old Settings class set default value of ShowOnlyMostUsedCMDsNumber to 0 which is a wrong value,
// we need to fix it here to make sure the default value is 5
// todo: remove this code block after release v2.2.0
if (_settings.ShowOnlyMostUsedCMDsNumber == 0)
{
_settings.ShowOnlyMostUsedCMDsNumber = 5;
}
}

bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
private bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)
{
if (!Context.CurrentPluginMetadata.Disabled && _settings.ReplaceWinR)
{
if (keyevent == (int)KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
{
_winRStroked = true;

Check warning on line 402 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`RStroked` is not a recognized word. (unrecognized-spelling)
OnWinRPressed();
return false;
}
Expand Down
123 changes: 114 additions & 9 deletions Plugins/Flow.Launcher.Plugin.Shell/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,121 @@
using System.Collections.Generic;
using Flow.Launcher.Localization.Attributes;

namespace Flow.Launcher.Plugin.Shell
{
public class Settings
public class Settings : BaseModel
{
public Shell Shell { get; set; } = Shell.Cmd;
private Shell _shell = Shell.Cmd;
public Shell Shell
{
get => _shell;
set
{
if (_shell != value)
{
_shell = value;
OnPropertyChanged();
}
}
}

public bool ReplaceWinR { get; set; } = false;
private bool _replaceWinR = false;
public bool ReplaceWinR
{
get => _replaceWinR;
set
{
if (_replaceWinR != value)
{
_replaceWinR = value;
OnPropertyChanged();
}
}
}

public bool CloseShellAfterPress { get; set; } = false;
private bool _closeShellAfterPress = false;
public bool CloseShellAfterPress
{
get => _closeShellAfterPress;
set
{
if (_closeShellAfterPress != value)
{
_closeShellAfterPress = value;
OnPropertyChanged();
}
}
}

public bool LeaveShellOpen { get; set; }
private bool _leaveShellOpen;
public bool LeaveShellOpen
{
get => _leaveShellOpen;
set
{
if (_leaveShellOpen != value)
{
_leaveShellOpen = value;
OnPropertyChanged();
}
}
}

public bool RunAsAdministrator { get; set; } = true;
private bool _runAsAdministrator = true;
public bool RunAsAdministrator
{
get => _runAsAdministrator;
set
{
if (_runAsAdministrator != value)
{
_runAsAdministrator = value;
OnPropertyChanged();
}
}
}

public bool UseWindowsTerminal { get; set; } = false;
private bool _useWindowsTerminal = false;
public bool UseWindowsTerminal
{
get => _useWindowsTerminal;
set
{
if (_useWindowsTerminal != value)
{
_useWindowsTerminal = value;
OnPropertyChanged();
}
}
}

public bool ShowOnlyMostUsedCMDs { get; set; }
private bool _showOnlyMostUsedCMDs;
public bool ShowOnlyMostUsedCMDs
{
get => _showOnlyMostUsedCMDs;
set
{
if (_showOnlyMostUsedCMDs != value)
{
_showOnlyMostUsedCMDs = value;
OnPropertyChanged();
}
}
}

public int ShowOnlyMostUsedCMDsNumber { get; set; }
private int _showOnlyMostUsedCMDsNumber = 5;
public int ShowOnlyMostUsedCMDsNumber
{
get => _showOnlyMostUsedCMDsNumber;
set
{
if (_showOnlyMostUsedCMDsNumber != value)
{
_showOnlyMostUsedCMDsNumber = value;
OnPropertyChanged();
}
}
}

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

Expand All @@ -31,11 +128,19 @@ public void AddCmdHistory(string cmdName)
}
}

[EnumLocalize]
public enum Shell
{
[EnumLocalizeValue("CMD")]
Cmd = 0,

[EnumLocalizeValue("PowerShell")]
Powershell = 1,

[EnumLocalizeValue("RunCommand")]
RunCommand = 2,

[EnumLocalizeValue("Pwsh")]
Pwsh = 3,
}
}
142 changes: 0 additions & 142 deletions Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs

This file was deleted.

Loading
Loading