-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 064d638. We will use the folder plugin to better mimic the way the start menu and run prompt deal with directories
- Loading branch information
1 parent
845c6be
commit 1ddd94b
Showing
20 changed files
with
887 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/modules/launcher/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using Wox.Infrastructure.Logger; | ||
using Wox.Infrastructure.Image; | ||
using Wox.Plugin.SharedCommands; | ||
|
||
namespace Wox.Plugin.Folder | ||
{ | ||
internal class ContextMenuLoader : IContextMenu | ||
{ | ||
private readonly PluginInitContext _context; | ||
|
||
public ContextMenuLoader(PluginInitContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult) | ||
{ | ||
var contextMenus = new List<ContextMenuResult>(); | ||
if (selectedResult.ContextData is SearchResult record) | ||
{ | ||
if (record.Type == ResultType.File) | ||
{ | ||
contextMenus.Add(CreateOpenContainingFolderResult(record)); | ||
} | ||
|
||
var icoPath = (record.Type == ResultType.File) ? Main.FileImagePath : Main.FolderImagePath; | ||
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder"; | ||
contextMenus.Add(new ContextMenuResult | ||
{ | ||
Title = "Copy path", | ||
Glyph = "\xE8C8", | ||
FontFamily = "Segoe MDL2 Assets", | ||
SubTitle = $"Copy the current {fileOrFolder} path to clipboard", | ||
AcceleratorKey = "C", | ||
AcceleratorModifiers = "Control", | ||
Action = (context) => | ||
{ | ||
try | ||
{ | ||
Clipboard.SetText(record.FullPath); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
var message = "Fail to set text in clipboard"; | ||
LogException(message, e); | ||
_context.API.ShowMsg(message); | ||
return false; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return contextMenus; | ||
} | ||
|
||
private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record) | ||
{ | ||
return new ContextMenuResult | ||
{ | ||
Title = "Open containing folder", | ||
Glyph = "\xE838", | ||
FontFamily = "Segoe MDL2 Assets", | ||
AcceleratorKey = "E", | ||
AcceleratorModifiers = "Control,Shift", | ||
Action = _ => | ||
{ | ||
try | ||
{ | ||
Process.Start("explorer.exe", $" /select,\"{record.FullPath}\""); | ||
} | ||
catch(Exception e) | ||
{ | ||
var message = $"Fail to open file at {record.FullPath}"; | ||
LogException(message, e); | ||
_context.API.ShowMsg(message); | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
|
||
private Result CreateOpenWithEditorResult(SearchResult record) | ||
{ | ||
string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor | ||
|
||
var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath); | ||
return new Result | ||
{ | ||
Title = name, | ||
Action = _ => | ||
{ | ||
try | ||
{ | ||
Process.Start(editorPath, record.FullPath); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
var message = $"Fail to editor for file at {record.FullPath}"; | ||
LogException(message, e); | ||
_context.API.ShowMsg(message); | ||
return false; | ||
} | ||
}, | ||
IcoPath = editorPath | ||
}; | ||
} | ||
|
||
public void LogException(string message, Exception e) | ||
{ | ||
Log.Exception($"|Wox.Plugin.Folder.ContextMenu|{message}", e); | ||
} | ||
|
||
private bool CanRunAsDifferentUser(string path) | ||
{ | ||
switch(Path.GetExtension(path)) | ||
{ | ||
case ".exe": | ||
case ".bat": | ||
return true; | ||
|
||
default: | ||
return false; | ||
|
||
} | ||
} | ||
} | ||
|
||
public class SearchResult | ||
{ | ||
public string FullPath { get; set; } | ||
public ResultType Type { get; set; } | ||
} | ||
|
||
public enum ResultType | ||
{ | ||
Volume, | ||
Folder, | ||
File | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/modules/launcher/Plugins/Wox.Plugin.Folder/FolderLink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
|
||
namespace Wox.Plugin.Folder | ||
{ | ||
[JsonObject(MemberSerialization.OptIn)] | ||
public class FolderLink | ||
{ | ||
[JsonProperty] | ||
public string Path { get; set; } | ||
|
||
public string Nickname => | ||
Path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None) | ||
.Last() | ||
+ " (" + System.IO.Path.GetDirectoryName(Path) + ")"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/modules/launcher/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<UserControl x:Class="Wox.Plugin.Folder.FileSystemSettings" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" d:DesignWidth="500"> | ||
<Grid Margin="10"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="50"/> | ||
</Grid.RowDefinitions> | ||
<ListView x:Name="lbxFolders" Grid.Row="0" AllowDrop="True" | ||
Drop="lbxFolders_Drop" | ||
DragEnter="lbxFolders_DragEnter"> | ||
<ListView.View> | ||
<GridView> | ||
<GridViewColumn Header="{DynamicResource wox_plugin_folder_folder_path}" Width="180"> | ||
<GridViewColumn.CellTemplate> | ||
<DataTemplate> | ||
<TextBlock Text="{Binding Path}"/> | ||
</DataTemplate> | ||
</GridViewColumn.CellTemplate> | ||
</GridViewColumn> | ||
</GridView> | ||
</ListView.View> | ||
</ListView> | ||
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal"> | ||
<Button x:Name="btnDelete" Click="btnDelete_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_delete}"/> | ||
<Button x:Name="btnEdit" Click="btnEdit_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_edit}"/> | ||
<Button x:Name="btnAdd" Click="btnAdd_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_add}"/> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
130 changes: 130 additions & 0 deletions
130
src/modules/launcher/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Windows.Forms; | ||
using DataFormats = System.Windows.DataFormats; | ||
using DragDropEffects = System.Windows.DragDropEffects; | ||
using DragEventArgs = System.Windows.DragEventArgs; | ||
using MessageBox = System.Windows.MessageBox; | ||
|
||
namespace Wox.Plugin.Folder | ||
{ | ||
|
||
public partial class FileSystemSettings | ||
{ | ||
private IPublicAPI woxAPI; | ||
private Settings _settings; | ||
|
||
public FileSystemSettings(IPublicAPI woxAPI, Settings settings) | ||
{ | ||
this.woxAPI = woxAPI; | ||
InitializeComponent(); | ||
_settings = settings; | ||
lbxFolders.ItemsSource = _settings.FolderLinks; | ||
} | ||
|
||
private void btnDelete_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var selectedFolder = lbxFolders.SelectedItem as FolderLink; | ||
if (selectedFolder != null) | ||
{ | ||
string msg = string.Format(woxAPI.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path); | ||
|
||
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) | ||
{ | ||
_settings.FolderLinks.Remove(selectedFolder); | ||
lbxFolders.Items.Refresh(); | ||
} | ||
} | ||
else | ||
{ | ||
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning"); | ||
MessageBox.Show(warning); | ||
} | ||
} | ||
|
||
private void btnEdit_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var selectedFolder = lbxFolders.SelectedItem as FolderLink; | ||
if (selectedFolder != null) | ||
{ | ||
var folderBrowserDialog = new FolderBrowserDialog(); | ||
folderBrowserDialog.SelectedPath = selectedFolder.Path; | ||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK) | ||
{ | ||
var link = _settings.FolderLinks.First(x => x.Path == selectedFolder.Path); | ||
link.Path = folderBrowserDialog.SelectedPath; | ||
} | ||
|
||
lbxFolders.Items.Refresh(); | ||
} | ||
else | ||
{ | ||
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning"); | ||
MessageBox.Show(warning); | ||
} | ||
} | ||
|
||
private void btnAdd_Click(object sender, RoutedEventArgs e) | ||
{ | ||
var folderBrowserDialog = new FolderBrowserDialog(); | ||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK) | ||
{ | ||
var newFolder = new FolderLink | ||
{ | ||
Path = folderBrowserDialog.SelectedPath | ||
}; | ||
|
||
if (_settings.FolderLinks == null) | ||
{ | ||
_settings.FolderLinks = new List<FolderLink>(); | ||
} | ||
|
||
_settings.FolderLinks.Add(newFolder); | ||
} | ||
|
||
lbxFolders.Items.Refresh(); | ||
} | ||
|
||
private void lbxFolders_Drop(object sender, DragEventArgs e) | ||
{ | ||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); | ||
|
||
if (files != null && files.Count() > 0) | ||
{ | ||
if (_settings.FolderLinks == null) | ||
{ | ||
_settings.FolderLinks = new List<FolderLink>(); | ||
} | ||
|
||
foreach (string s in files) | ||
{ | ||
if (Directory.Exists(s)) | ||
{ | ||
var newFolder = new FolderLink | ||
{ | ||
Path = s | ||
}; | ||
|
||
_settings.FolderLinks.Add(newFolder); | ||
} | ||
|
||
lbxFolders.Items.Refresh(); | ||
} | ||
} | ||
} | ||
|
||
private void lbxFolders_DragEnter(object sender, DragEventArgs e) | ||
{ | ||
if (e.Data.GetDataPresent(DataFormats.FileDrop)) | ||
{ | ||
e.Effects = DragDropEffects.Link; | ||
} | ||
else | ||
{ | ||
e.Effects = DragDropEffects.None; | ||
} | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.3 KB
src/modules/launcher/Plugins/Wox.Plugin.Folder/Images/deletefilefolder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.