2014-04-13 15:38:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using System.IO;
|
2014-04-13 15:38:12 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
2015-01-03 15:20:34 +08:00
|
|
|
|
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;
|
2015-01-03 15:20:34 +08:00
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2015-01-05 22:41:17 +08:00
|
|
|
|
namespace Wox.Plugin.Folder
|
|
|
|
|
{
|
2014-06-30 21:31:13 +08:00
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
public partial class FileSystemSettings
|
2015-01-05 22:41:17 +08:00
|
|
|
|
{
|
2015-02-04 23:16:41 +08:00
|
|
|
|
private IPublicAPI woxAPI;
|
2016-03-28 10:09:57 +08:00
|
|
|
|
private FolderStorage _settings;
|
2015-01-07 18:59:55 +08:00
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
public FileSystemSettings(IPublicAPI woxAPI, FolderStorage settings)
|
2015-01-05 22:41:17 +08:00
|
|
|
|
{
|
2015-02-04 23:16:41 +08:00
|
|
|
|
this.woxAPI = woxAPI;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
InitializeComponent();
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings = settings;
|
|
|
|
|
lbxFolders.ItemsSource = _settings.FolderLinks;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2015-01-05 22:41:17 +08:00
|
|
|
|
private void btnDelete_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2014-04-13 15:38:12 +08:00
|
|
|
|
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);
|
2015-01-09 10:23:48 +08:00
|
|
|
|
|
|
|
|
|
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.FolderLinks.Remove(selectedFolder);
|
2015-01-09 10:23:48 +08:00
|
|
|
|
lbxFolders.Items.Refresh();
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.Save();
|
2015-01-09 10:23:48 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
}
|
|
|
|
|
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);
|
2014-04-13 15:38:12 +08:00
|
|
|
|
}
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
|
|
|
|
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var selectedFolder = lbxFolders.SelectedItem as FolderLink;
|
|
|
|
|
if (selectedFolder != null)
|
|
|
|
|
{
|
2015-01-03 15:20:34 +08:00
|
|
|
|
var folderBrowserDialog = new FolderBrowserDialog();
|
2014-04-13 15:38:12 +08:00
|
|
|
|
folderBrowserDialog.SelectedPath = selectedFolder.Path;
|
2015-01-03 15:20:34 +08:00
|
|
|
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
2014-04-13 15:38:12 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
var link = _settings.FolderLinks.First(x => x.Path == selectedFolder.Path);
|
2014-04-13 15:38:12 +08:00
|
|
|
|
link.Path = folderBrowserDialog.SelectedPath;
|
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.Save();
|
2014-04-13 15:38:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2014-04-13 15:38:12 +08:00
|
|
|
|
}
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2015-01-05 22:41:17 +08:00
|
|
|
|
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)
|
2015-01-05 22:41:17 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
var newFolder = new FolderLink
|
2015-01-05 22:41:17 +08:00
|
|
|
|
{
|
|
|
|
|
Path = folderBrowserDialog.SelectedPath
|
|
|
|
|
};
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
if (_settings.FolderLinks == null)
|
2015-01-05 22:41:17 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.FolderLinks = new List<FolderLink>();
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.FolderLinks.Add(newFolder);
|
|
|
|
|
_settings.Save();
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
|
2015-01-05 22:41:17 +08:00
|
|
|
|
lbxFolders.Items.Refresh();
|
|
|
|
|
}
|
2015-01-09 10:23:48 +08:00
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
private void lbxFolders_Drop(object sender, DragEventArgs e)
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2015-01-09 10:23:48 +08:00
|
|
|
|
|
|
|
|
|
if (files != null && files.Count() > 0)
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
if (_settings.FolderLinks == null)
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.FolderLinks = new List<FolderLink>();
|
2015-01-09 10:23:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string s in files)
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
if (Directory.Exists(s))
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
var newFolder = new FolderLink
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
|
|
|
|
Path = s
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.FolderLinks.Add(newFolder);
|
|
|
|
|
_settings.Save();
|
2015-01-09 10:23:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lbxFolders.Items.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
private void lbxFolders_DragEnter(object sender, DragEventArgs e)
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
2015-01-09 10:23:48 +08:00
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
e.Effects = DragDropEffects.Link;
|
2015-01-09 10:23:48 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
e.Effects = DragDropEffects.None;
|
2015-01-09 10:23:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-05 22:41:17 +08:00
|
|
|
|
}
|
2014-04-13 15:38:12 +08:00
|
|
|
|
}
|