Skip to content

Commit

Permalink
Merge pull request #28 from mantasjasikenas/dev
Browse files Browse the repository at this point in the history
Release v1.1.8
  • Loading branch information
mantasjasikenas authored Sep 12, 2024
2 parents 2179e4f + 04533ba commit 9e9852a
Show file tree
Hide file tree
Showing 22 changed files with 426 additions and 194 deletions.
47 changes: 46 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,52 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- Add quotes escaping
## [1.1.8] - 2024-09-xx

- Add autocomplete support for commands with arguments
- After typing the full shortcut, for example `q dev`, pressing `Ctr+Tab` (autocomplete) will replace current query with
the
shortcut path
- Alias support for shortcuts. Add `Alias` field in the shortcut JSON file. Provide the alias name. Example:

```json
{
"Type": "Directory",
"Path": "C:\\Users\\tutta\\Storage\\Dev",
"Key": "dev",
"Alias": ["development", "devs"]
}
```
- Show associated icons for shortcuts in the search results
- New plugin icon
- Customizable icons for shortcuts. In order to use custom icons, add `Icon` field in the shortcut JSON file.
Provide the full path to the icon file. Example:

```json
{
"Type": "Directory",
"Path": "C:\\Users\\tutta\\Storage\\Dev",
"Key": "dev",
"Icon": "C:\\Users\\tutta\\Storage\\Dev\\Projects\\ShortcutPlugin\\Flow.Launcher.Plugin.ShortcutPlugin\\Images\\discord-mark-white.png"
}
```

## [1.1.7] - 2024-06-21

- New backup command with subcommands.
- Added copy result title and subtitle options in the context menu
- Fix issue with cmd arguments quotes
- Support for VS Code and VS Code - Insiders in context menu for folders
- Help command with documentation, issues links and developer Discord username

## [1.1.6] - 2024-05-08

- Improved possible shortcuts fuzzy search. Now fuzzy search is case insensitive.
- Version command to see the current plugin version.
- Fix the disappearing config file after updating the plugin using default shortcuts and variables paths. This should
start working updating from **v1.1.6** to future releases.
- Changed default shortcuts and variable paths.
- Reset button in the settings panel to set default settings values.

## [1.1.5] - 2024-04-05

Expand Down
56 changes: 46 additions & 10 deletions Flow.Launcher.Plugin.ShortcutPlugin/ContextMenu.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Windows;
using Flow.Launcher.Plugin.ShortcutPlugin.Extensions;
using Flow.Launcher.Plugin.ShortcutPlugin.Models.Shortcuts;
using Flow.Launcher.Plugin.ShortcutPlugin.Services.Interfaces;
Expand All @@ -15,16 +13,19 @@ namespace Flow.Launcher.Plugin.ShortcutPlugin;
internal class ContextMenu : IContextMenu
{
private readonly IVariablesService _variablesService;
private readonly PluginInitContext _context;

public ContextMenu(IVariablesService variablesService)
public ContextMenu(IVariablesService variablesService, PluginInitContext context)
{
_variablesService = variablesService;
_context = context;
}

public List<Result> LoadContextMenus(Result selectedResult)
{
var contextMenu = new List<Result>();

AddShortcutDetails(selectedResult, contextMenu);
AddCopyTitleAndSubtitle(selectedResult, contextMenu);

if (selectedResult.ContextData is not Shortcut shortcut)
Expand All @@ -45,18 +46,53 @@ public List<Result> LoadContextMenus(Result selectedResult)
return contextMenu;
}

private static void AddCopyTitleAndSubtitle(Result selectedResult, List<Result> contextMenu)
private void AddShortcutDetails(Result selectedResult, List<Result> contextMenu)
{
if (selectedResult.ContextData is not Shortcut shortcut)
{
return;
}

contextMenu.Add(ResultExtensions.Result(
"Key",
shortcut.Key,
() => { _context.API.CopyToClipboard(shortcut.Key, showDefaultNotification: false); }
));

if (shortcut.Alias is {Count: > 0})
{
contextMenu.Add(ResultExtensions.Result(
"Alias",
string.Join(", ", shortcut.Alias),
() =>
{
_context.API.CopyToClipboard(string.Join(", ", shortcut.Alias), showDefaultNotification: false);
}
));
}

if (!string.IsNullOrEmpty(shortcut.Description))
{
contextMenu.Add(ResultExtensions.Result(
"Description",
shortcut.Description,
() => { _context.API.CopyToClipboard(shortcut.Description, showDefaultNotification: false); }
));
}
}

private void AddCopyTitleAndSubtitle(Result selectedResult, List<Result> contextMenu)
{
var copyTitle = ResultExtensions.Result(
"Copy result title",
selectedResult.Title,
action: () => { Clipboard.SetText(selectedResult.Title); },
action: () => { _context.API.CopyToClipboard(selectedResult.Title, showDefaultNotification: false); },
iconPath: Icons.Copy
);
var copySubTitle = ResultExtensions.Result(
"Copy result subtitle",
selectedResult.SubTitle,
action: () => { Clipboard.SetText(selectedResult.SubTitle); },
action: () => { _context.API.CopyToClipboard(selectedResult.SubTitle, showDefaultNotification: false); },
iconPath: Icons.Copy
);

Expand Down Expand Up @@ -106,13 +142,13 @@ private void GetFileShortcutContextMenu(ICollection<Result> contextMenu, FileSho

contextMenu.Add(ResultExtensions.Result(
"Copy path",
action: () => { Clipboard.SetText(filePath); },
action: () => { _context.API.CopyToClipboard(filePath, showDefaultNotification: false); },
iconPath: Icons.Copy
));

contextMenu.Add(ResultExtensions.Result(
"Copy file",
action: () => { Clipboard.SetFileDropList(new StringCollection {filePath}); },
action: () => { _context.API.CopyToClipboard(filePath, true, false); },
iconPath: Icons.Copy
));
}
Expand Down Expand Up @@ -180,12 +216,12 @@ private void GetDirectoryContextMenu(ICollection<Result> contextMenu, DirectoryS
};
Process.Start(processStartInfo);
},
iconPath: Icons.PowerShell
iconPath: Icons.PowerShellBlack
));

contextMenu.Add(ResultExtensions.Result(
"Copy path",
action: () => { Clipboard.SetText(directoryPath); },
action: () => { _context.API.CopyToClipboard(directoryPath, showDefaultNotification: false); },
iconPath: Icons.Copy
));

Expand Down
10 changes: 0 additions & 10 deletions Flow.Launcher.Plugin.ShortcutPlugin/Extensions/ResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ public static List<Result> EmptyResult(string title, string subtitle = "")
return SingleResult(title, subtitle);
}

/*public static List<Result> InitializedResult()
{
return SingleResult(Resources.ShortcutsManager_Init_Plugin_initialized);
}*/

/*public static List<Result> NotImplementedResult()
{
return SingleResult("Not implemented yet", "Please wait for the next release");
}*/

public static List<Result> SingleResult(
string title,
string subtitle = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.4"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Flow.Launcher.Plugin" Version="4.3.0" />
<PackageReference Include="Flow.Launcher.Plugin" Version="4.4.0" />
<PackageReference Include="FuzzySharp" Version="2.0.2"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
</ItemGroup>
Expand Down
Binary file modified Flow.Launcher.Plugin.ShortcutPlugin/Images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

36 changes: 13 additions & 23 deletions Flow.Launcher.Plugin.ShortcutPlugin/Models/Shortcuts/Shortcut.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin.ShortcutPlugin.Utilities;

namespace Flow.Launcher.Plugin.ShortcutPlugin.Models.Shortcuts;

Expand All @@ -10,49 +10,39 @@ namespace Flow.Launcher.Plugin.ShortcutPlugin.Models.Shortcuts;
[JsonDerivedType(typeof(FileShortcut), nameof(ShortcutType.File))]
[JsonDerivedType(typeof(ShellShortcut), nameof(ShortcutType.Shell))]
[JsonDerivedType(typeof(GroupShortcut), nameof(ShortcutType.Group))]
[JsonDerivedType(typeof(PluginShortcut), nameof(ShortcutType.Plugin))]
public abstract class Shortcut : ICloneable
{
public string Key { get; set; }

public List<string> Alias { get; set; }

public string Description { get; set; }

public string Icon { get; set; }

public string GetDerivedType()
{
return this switch
{
FileShortcut => "File",
DirectoryShortcut => "Directory",
UrlShortcut => "Url",
PluginShortcut => "Plugin",
GroupShortcut => "Group",
ShellShortcut => "Shell",
_ => "Unspecified shortcut type"
};
}

public string GetIcon()
public string GetTitle()
{
return this switch
{
FileShortcut => Icons.File,
DirectoryShortcut => Icons.Folder,
UrlShortcut => Icons.Link,
ShellShortcut => Icons.Terminal,
PluginShortcut => Icons.Logo,
GroupShortcut => Icons.TabGroup,
_ => Icons.Logo
};
return $"{Key}{GetAlias()}";
}

public ShortcutType GetShortcutType() => this switch
private string GetAlias()
{
FileShortcut => ShortcutType.File,
DirectoryShortcut => ShortcutType.Directory,
UrlShortcut => ShortcutType.Url,
ShellShortcut => ShortcutType.Shell,
PluginShortcut => ShortcutType.Plugin,
GroupShortcut => ShortcutType.Group,
_ => ShortcutType.Unspecified
};
// Alternative symbols: ⨯ ⇒ ⪢ ⌗
return Alias is {Count: > 0} ? $"{string.Join("", Alias)}" : string.Empty;
}


public abstract object Clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ public List<Result> ResolveCommand(List<string> arguments, Query query)
return ShowAvailableCommands(query.ActionKeyword);
}

var key = arguments[0];
var argsWithoutKey = arguments.Skip(1).ToList();

// In case this is a shortcut command, let's open shortcut
if (_shortcutsRepository.GetShortcuts(arguments[0]) is not null)
if (_shortcutsRepository.GetShortcuts(key) is not null)
{
return _shortcutsService.OpenShortcuts(arguments[0], arguments.Skip(1).ToList()); // Skips shortcut name
return _shortcutsService.OpenShortcuts(key, argsWithoutKey);
}

// If command was not found
if (!_commands.TryGetValue(arguments[0], out var command))
if (!_commands.TryGetValue(key, out var command))
{
// Show possible shortcuts
var possibleShortcuts = _shortcutsRepository
.GetPossibleShortcuts(arguments[0])
.Select(s =>
_shortcutsService.OpenShortcut(s, arguments.Skip(1).ToList())
.First()
);
.GetPossibleShortcuts(key)
.SelectMany(s => _shortcutsService.OpenShortcut(s, argsWithoutKey));

// Return possible command matches
var possibleCommands = GetPossibleCommands(arguments[0], query.ActionKeyword);
var possibleCommands = GetPossibleCommands(key, query.ActionKeyword);

var possibleResults = possibleShortcuts.Concat(possibleCommands).ToList();

return possibleResults.Count != 0
return possibleResults.Any()
? possibleResults
: ResultExtensions.SingleResult(
"Invalid input",
Expand Down Expand Up @@ -95,21 +95,22 @@ public List<Result> ResolveCommand(List<string> arguments, Query query)
}

// If command has more arguments
if (executor.Arguments.Count != 0)
if (executor.Arguments.Any())
{
// Can't check because Flow Launcher trims the query
/* if (!query.EndsWith(" "))
/*if (!query.RawQuery.EndsWith(" "))
{
return ResultExtensions.SingleResult(executor.ResponseInfo.Item1, executor.ResponseInfo.Item2);
} */
}*/

return executor
.Arguments.Cast<Argument>()
.Select(a =>
ResultExtensions.Result(
a.ResponseInfo.Item1,
a.ResponseInfo.Item2,
() => { _context.API.ChangeQuery($"{a.Key} "); }
() => { _context.API.ChangeQuery($"{query.ActionKeyword} {a.ResponseInfo.Item1}"); },
hideAfterAction: false
)
)
.ToList();
Expand Down
Loading

0 comments on commit 9e9852a

Please sign in to comment.