PowerToys/Plugins/Wox.Plugin.Folder/FolderPluginSettings.xaml.cs

136 lines
4.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2016-01-07 05:34:42 +08:00
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
2016-01-07 05:34:42 +08:00
using DataFormats = System.Windows.DataFormats;
using DragDropEffects = System.Windows.DragDropEffects;
using DragEventArgs = System.Windows.DragEventArgs;
using MessageBox = System.Windows.MessageBox;
namespace Wox.Plugin.Folder
{
2014-06-30 21:31:13 +08:00
public partial class FileSystemSettings
{
2015-02-04 23:16:41 +08:00
private IPublicAPI woxAPI;
private FolderStorage _settings;
2015-01-07 18:59:55 +08:00
public FileSystemSettings(IPublicAPI woxAPI, FolderStorage settings)
{
2015-02-04 23:16:41 +08:00
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)
{
2015-02-04 23:16:41 +08:00
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();
_settings.Save();
}
}
else
{
2015-02-04 23:16:41 +08:00
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
2015-01-07 18:59:55 +08:00
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;
_settings.Save();
}
lbxFolders.Items.Refresh();
}
else
{
2015-02-04 23:16:41 +08:00
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
2015-01-07 18:59:55 +08:00
MessageBox.Show(warning);
}
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
2016-01-07 05:34:42 +08:00
var folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
2016-01-07 05:34:42 +08:00
var newFolder = new FolderLink
{
Path = folderBrowserDialog.SelectedPath
};
if (_settings.FolderLinks == null)
{
_settings.FolderLinks = new List<FolderLink>();
}
_settings.FolderLinks.Add(newFolder);
_settings.Save();
}
lbxFolders.Items.Refresh();
}
2016-01-07 05:34:42 +08:00
private void lbxFolders_Drop(object sender, DragEventArgs e)
{
2016-01-07 05:34:42 +08:00
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)
{
2016-01-07 05:34:42 +08:00
if (Directory.Exists(s))
{
2016-01-07 05:34:42 +08:00
var newFolder = new FolderLink
{
Path = s
};
_settings.FolderLinks.Add(newFolder);
_settings.Save();
}
lbxFolders.Items.Refresh();
}
}
}
2016-01-07 05:34:42 +08:00
private void lbxFolders_DragEnter(object sender, DragEventArgs e)
{
2016-01-07 05:34:42 +08:00
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
2016-01-07 05:34:42 +08:00
e.Effects = DragDropEffects.Link;
}
else
{
2016-01-07 05:34:42 +08:00
e.Effects = DragDropEffects.None;
}
}
}
}