mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Move some user settings to its own dll (cmd,folder plugin and etc)
This commit is contained in:
@@ -2,13 +2,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using WindowsInput;
|
||||
using WindowsInput.Native;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
public class CMD : IPlugin, ISettingProvider
|
||||
{
|
||||
private readonly GlobalHotkey globalHotkey = new GlobalHotkey();
|
||||
private PluginInitContext context;
|
||||
private bool WinRStroked;
|
||||
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@@ -166,6 +173,33 @@ namespace Wox.Plugin.CMD
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||
}
|
||||
|
||||
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
||||
{
|
||||
if (CMDStorage.Instance.ReplaceWinR)
|
||||
{
|
||||
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
|
||||
{
|
||||
WinRStroked = true;
|
||||
OnWinRPressed();
|
||||
return false;
|
||||
}
|
||||
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
|
||||
{
|
||||
WinRStroked = false;
|
||||
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnWinRPressed()
|
||||
{
|
||||
context.API.ShowApp();
|
||||
context.API.ChangeQuery(">");
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
@@ -13,30 +12,30 @@ namespace Wox.Plugin.CMD
|
||||
|
||||
private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
|
||||
{
|
||||
cbReplaceWinR.IsChecked = UserSettingStorage.Instance.ReplaceWinR;
|
||||
cbLeaveCmdOpen.IsChecked = UserSettingStorage.Instance.LeaveCmdOpen;
|
||||
cbReplaceWinR.IsChecked = CMDStorage.Instance.ReplaceWinR;
|
||||
cbLeaveCmdOpen.IsChecked = CMDStorage.Instance.LeaveCmdOpen;
|
||||
|
||||
cbLeaveCmdOpen.Checked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.LeaveCmdOpen = true;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.LeaveCmdOpen = true;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
|
||||
cbLeaveCmdOpen.Unchecked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.LeaveCmdOpen = false;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.LeaveCmdOpen = false;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
|
||||
cbReplaceWinR.Checked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.ReplaceWinR = true;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.ReplaceWinR = true;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
cbReplaceWinR.Unchecked += (o, e) =>
|
||||
{
|
||||
UserSettingStorage.Instance.ReplaceWinR = false;
|
||||
UserSettingStorage.Instance.Save();
|
||||
CMDStorage.Instance.ReplaceWinR = false;
|
||||
CMDStorage.Instance.Save();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using System.IO;
|
||||
|
||||
namespace Wox.Plugin.CMD
|
||||
{
|
||||
public class CMDStorage : JsonStrorage<CMDStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
public bool ReplaceWinR { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public bool LeaveCmdOpen { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public Dictionary<string, int> CMDHistory = new Dictionary<string, int>();
|
||||
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "CMDHistory"; }
|
||||
}
|
||||
|
||||
protected override CMDStorage LoadDefault()
|
||||
{
|
||||
ReplaceWinR = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void AddCmdHistory(string cmdName)
|
||||
{
|
||||
if (CMDHistory.ContainsKey(cmdName))
|
||||
|
||||
@@ -44,11 +44,15 @@
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="WindowsInput">
|
||||
<HintPath>..\..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CMD.cs" />
|
||||
|
||||
18
Plugins/Wox.Plugin.Folder/FolderLink.cs
Normal file
18
Plugins/Wox.Plugin.Folder/FolderLink.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Plugin.Folder
|
||||
{
|
||||
[Serializable]
|
||||
public class FolderLink
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Path { get; set; }
|
||||
|
||||
public string Nickname
|
||||
{
|
||||
get { return Path.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None).Last(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
|
||||
namespace Wox.Plugin.Folder
|
||||
@@ -24,10 +23,10 @@ namespace Wox.Plugin.Folder
|
||||
this.context = context;
|
||||
this.context.API.BackKeyDownEvent += ApiBackKeyDownEvent;
|
||||
InitialDriverList();
|
||||
if (UserSettingStorage.Instance.FolderLinks == null)
|
||||
if (FolderStorage.Instance.FolderLinks == null)
|
||||
{
|
||||
UserSettingStorage.Instance.FolderLinks = new List<FolderLink>();
|
||||
UserSettingStorage.Instance.Save();
|
||||
FolderStorage.Instance.FolderLinks = new List<FolderLink>();
|
||||
FolderStorage.Instance.Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +55,7 @@ namespace Wox.Plugin.Folder
|
||||
if(string.IsNullOrEmpty(query.RawQuery)) return new List<Result>();
|
||||
string input = query.RawQuery.ToLower();
|
||||
|
||||
List<FolderLink> userFolderLinks = UserSettingStorage.Instance.FolderLinks.Where(
|
||||
List<FolderLink> userFolderLinks = FolderStorage.Instance.FolderLinks.Where(
|
||||
x => x.Nickname.StartsWith(input, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
List<Result> results =
|
||||
userFolderLinks.Select(
|
||||
|
||||
@@ -2,33 +2,36 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using UserControl = System.Windows.Controls.UserControl;
|
||||
|
||||
namespace Wox.Plugin.Folder {
|
||||
namespace Wox.Plugin.Folder
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for FileSystemSettings.xaml
|
||||
/// </summary>
|
||||
public partial class FileSystemSettings : UserControl {
|
||||
public FileSystemSettings() {
|
||||
InitializeComponent();
|
||||
lbxFolders.ItemsSource = UserSettingStorage.Instance.FolderLinks;
|
||||
}
|
||||
/// <summary>
|
||||
/// Interaction logic for FileSystemSettings.xaml
|
||||
/// </summary>
|
||||
public partial class FileSystemSettings : UserControl
|
||||
{
|
||||
public FileSystemSettings()
|
||||
{
|
||||
InitializeComponent();
|
||||
lbxFolders.ItemsSource = FolderStorage.Instance.FolderLinks;
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, RoutedEventArgs e) {
|
||||
private void btnDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedFolder = lbxFolders.SelectedItem as FolderLink;
|
||||
if (selectedFolder != null)
|
||||
{
|
||||
UserSettingStorage.Instance.FolderLinks.Remove(selectedFolder);
|
||||
FolderStorage.Instance.FolderLinks.Remove(selectedFolder);
|
||||
lbxFolders.Items.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a folder link!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -39,10 +42,10 @@ namespace Wox.Plugin.Folder {
|
||||
folderBrowserDialog.SelectedPath = selectedFolder.Path;
|
||||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var link = UserSettingStorage.Instance.FolderLinks.First(x => x.Path == selectedFolder.Path);
|
||||
var link = FolderStorage.Instance.FolderLinks.First(x => x.Path == selectedFolder.Path);
|
||||
link.Path = folderBrowserDialog.SelectedPath;
|
||||
|
||||
UserSettingStorage.Instance.Save();
|
||||
FolderStorage.Instance.Save();
|
||||
}
|
||||
|
||||
lbxFolders.Items.Refresh();
|
||||
@@ -51,24 +54,28 @@ namespace Wox.Plugin.Folder {
|
||||
{
|
||||
MessageBox.Show("Please select a folder link!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e) {
|
||||
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
|
||||
var newFolder = new FolderLink() {
|
||||
Path = folderBrowserDialog.SelectedPath
|
||||
};
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
var newFolder = new FolderLink()
|
||||
{
|
||||
Path = folderBrowserDialog.SelectedPath
|
||||
};
|
||||
|
||||
if (UserSettingStorage.Instance.FolderLinks == null) {
|
||||
UserSettingStorage.Instance.FolderLinks = new List<FolderLink>();
|
||||
}
|
||||
if (FolderStorage.Instance.FolderLinks == null)
|
||||
{
|
||||
FolderStorage.Instance.FolderLinks = new List<FolderLink>();
|
||||
}
|
||||
|
||||
UserSettingStorage.Instance.FolderLinks.Add(newFolder);
|
||||
UserSettingStorage.Instance.Save();
|
||||
}
|
||||
FolderStorage.Instance.FolderLinks.Add(newFolder);
|
||||
FolderStorage.Instance.Save();
|
||||
}
|
||||
|
||||
lbxFolders.Items.Refresh();
|
||||
}
|
||||
}
|
||||
lbxFolders.Items.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
Plugins/Wox.Plugin.Folder/FolderStorage.cs
Normal file
26
Plugins/Wox.Plugin.Folder/FolderStorage.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using System.IO;
|
||||
|
||||
namespace Wox.Plugin.Folder
|
||||
{
|
||||
public class FolderStorage : JsonStrorage<FolderStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<FolderLink> FolderLinks { get; set; }
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "setting"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
@@ -48,10 +52,12 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FolderLink.cs" />
|
||||
<Compile Include="FolderPlugin.cs" />
|
||||
<Compile Include="FolderPluginSettings.xaml.cs">
|
||||
<DependentUpon>FolderPluginSettings.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FolderStorage.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.3" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="6.0.7" targetFramework="net35" />
|
||||
</packages>
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Core.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.PluginIndicator
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.5\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net35" />
|
||||
<package id="Newtonsoft.Json" version="6.0.7" targetFramework="net35" />
|
||||
</packages>
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Wox.Plugin.Program
|
||||
}
|
||||
|
||||
watchedPath.Add(path);
|
||||
foreach (string fileType in UserSettingStorage.Instance.ProgramSuffixes.Split(';'))
|
||||
foreach (string fileType in ProgramStorage.Instance.ProgramSuffixes.Split(';'))
|
||||
{
|
||||
FileSystemWatcher watcher = new FileSystemWatcher
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
@@ -9,6 +11,11 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
public List<Program> Programs = new List<Program>();
|
||||
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "ProgramIndexCache"; }
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
@@ -19,7 +18,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
programSourceView.ItemsSource = UserSettingStorage.Instance.ProgramSources;
|
||||
programSourceView.ItemsSource = ProgramStorage.Instance.ProgramSources;
|
||||
}
|
||||
|
||||
private void ReIndexing()
|
||||
@@ -40,13 +39,13 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
string path = folderBrowserDialog.SelectedPath;
|
||||
|
||||
UserSettingStorage.Instance.ProgramSources.Add(new ProgramSource()
|
||||
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
|
||||
{
|
||||
Location = path,
|
||||
Type = "FileSystemProgramSource",
|
||||
Enabled = true
|
||||
});
|
||||
UserSettingStorage.Instance.Save();
|
||||
ProgramStorage.Instance.Save();
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
@@ -59,8 +58,8 @@ namespace Wox.Plugin.Program
|
||||
if (MessageBox.Show("Are your sure to delete " + selectedProgramSource.Location, "Delete ProgramSource",
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
UserSettingStorage.Instance.ProgramSources.Remove(selectedProgramSource);
|
||||
UserSettingStorage.Instance.Save();
|
||||
ProgramStorage.Instance.ProgramSources.Remove(selectedProgramSource);
|
||||
ProgramStorage.Instance.Save();
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,7 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
string path = folderBrowserDialog.SelectedPath;
|
||||
selectedProgramSource.Location = path;
|
||||
UserSettingStorage.Instance.Save();
|
||||
ProgramStorage.Instance.Save();
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
|
||||
20
Plugins/Wox.Plugin.Program/ProgramSource.cs
Normal file
20
Plugins/Wox.Plugin.Program/ProgramSource.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
[Serializable]
|
||||
public class ProgramSource
|
||||
{
|
||||
public string Location { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int BonusPoints { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public Dictionary<string, string> Meta { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (this.Type ?? "") + ":" + this.Location ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Log = Wox.Infrastructure.Logger.Log;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
@@ -39,7 +38,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
if (UserSettingStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
{
|
||||
Program p = CreateEntry(file);
|
||||
list.Add(p);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
|
||||
44
Plugins/Wox.Plugin.Program/ProgramStorage.cs
Normal file
44
Plugins/Wox.Plugin.Program/ProgramStorage.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
public class ProgramStorage : JsonStrorage<ProgramStorage>
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<ProgramSource> ProgramSources { get; set; }
|
||||
|
||||
[JsonProperty]
|
||||
public string ProgramSuffixes { get; set; }
|
||||
|
||||
protected override string ConfigFolder
|
||||
{
|
||||
get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
|
||||
}
|
||||
|
||||
protected override ProgramStorage LoadDefault()
|
||||
{
|
||||
ProgramSources = new List<ProgramSource>();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override void OnAfterLoad(ProgramStorage storage)
|
||||
{
|
||||
if (string.IsNullOrEmpty(storage.ProgramSuffixes))
|
||||
{
|
||||
storage.ProgramSuffixes = "lnk;exe;appref-ms;bat";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string ConfigName
|
||||
{
|
||||
get { return "setting"; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Windows;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
@@ -12,7 +11,7 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
tbSuffixes.Text = UserSettingStorage.Instance.ProgramSuffixes;
|
||||
tbSuffixes.Text = ProgramStorage.Instance.ProgramSuffixes;
|
||||
}
|
||||
|
||||
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
@@ -23,7 +22,7 @@ namespace Wox.Plugin.Program
|
||||
return;
|
||||
}
|
||||
|
||||
UserSettingStorage.Instance.ProgramSuffixes = tbSuffixes.Text;
|
||||
ProgramStorage.Instance.ProgramSuffixes = tbSuffixes.Text;
|
||||
MessageBox.Show("Sucessfully update file suffixes");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Plugin.Program.ProgramSources;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
@@ -90,10 +89,10 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
List<ProgramSource> programSources = new List<ProgramSource>();
|
||||
programSources.AddRange(LoadDeaultProgramSources());
|
||||
if (UserSettingStorage.Instance.ProgramSources != null &&
|
||||
UserSettingStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
|
||||
if (ProgramStorage.Instance.ProgramSources != null &&
|
||||
ProgramStorage.Instance.ProgramSources.Count(o => o.Enabled) > 0)
|
||||
{
|
||||
programSources.AddRange(UserSettingStorage.Instance.ProgramSources.Where(o => o.Enabled));
|
||||
programSources.AddRange(ProgramStorage.Instance.ProgramSources.Where(o => o.Enabled));
|
||||
}
|
||||
|
||||
sources.Clear();
|
||||
|
||||
@@ -59,10 +59,12 @@
|
||||
<Compile Include="ProgramSetting.xaml.cs">
|
||||
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ProgramSource.cs" />
|
||||
<Compile Include="ProgramSources\AppPathsProgramSource.cs" />
|
||||
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
|
||||
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />
|
||||
<Compile Include="ProgramSources\UserStartMenuProgramSource.cs" />
|
||||
<Compile Include="ProgramStorage.cs" />
|
||||
<Compile Include="ProgramSuffixes.xaml.cs">
|
||||
<DependentUpon>ProgramSuffixes.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Http;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
@@ -14,7 +15,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
|
||||
public override List<string> GetSuggestions(string query)
|
||||
{
|
||||
var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), "GB2312");
|
||||
var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), HttpProxy.Instance, "GB2312");
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
|
||||
Match match = reg.Match(result);
|
||||
@@ -23,9 +24,9 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
JContainer json = null;
|
||||
try
|
||||
{
|
||||
json =JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer;
|
||||
json = JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer;
|
||||
}
|
||||
catch{}
|
||||
catch { }
|
||||
|
||||
if (json != null)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Infrastructure.Http;
|
||||
|
||||
namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
@@ -11,7 +12,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources
|
||||
{
|
||||
public override List<string> GetSuggestions(string query)
|
||||
{
|
||||
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query));
|
||||
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query),HttpProxy.Instance);
|
||||
if (string.IsNullOrEmpty(result)) return new List<string>();
|
||||
|
||||
try
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Core.UserSettings;
|
||||
using Wox.Plugin.WebSearch.SuggestionSources;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
@@ -15,7 +15,7 @@ namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
|
||||
Infrastructure.Storage.UserSettings.WebSearch webSearch =
|
||||
Core.UserSettings.WebSearch webSearch =
|
||||
UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.ActionName && o.Enabled);
|
||||
|
||||
if (webSearch != null)
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Core.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace Wox.Plugin.WebSearch
|
||||
private string defaultWebSearchImageDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\websearch");
|
||||
private WebSearchesSetting settingWindow;
|
||||
private bool update;
|
||||
private Infrastructure.Storage.UserSettings.WebSearch updateWebSearch;
|
||||
private Core.UserSettings.WebSearch updateWebSearch;
|
||||
|
||||
public WebSearchSetting(WebSearchesSetting settingWidow)
|
||||
{
|
||||
@@ -22,7 +22,7 @@ namespace Wox.Plugin.WebSearch
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void UpdateItem(Infrastructure.Storage.UserSettings.WebSearch webSearch)
|
||||
public void UpdateItem(Core.UserSettings.WebSearch webSearch)
|
||||
{
|
||||
updateWebSearch = UserSettingStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch);
|
||||
if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url))
|
||||
@@ -89,7 +89,7 @@ namespace Wox.Plugin.WebSearch
|
||||
MessageBox.Show("ActionWord has existed, please input a new one.");
|
||||
return;
|
||||
}
|
||||
UserSettingStorage.Instance.WebSearches.Add(new Infrastructure.Storage.UserSettings.WebSearch()
|
||||
UserSettingStorage.Instance.WebSearches.Add(new Core.UserSettings.WebSearch()
|
||||
{
|
||||
ActionWord = action,
|
||||
Enabled = cbEnable.IsChecked ?? false,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
using Wox.Core.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
@@ -54,7 +54,7 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Infrastructure.Storage.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Infrastructure.Storage.UserSettings.WebSearch;
|
||||
Core.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Core.UserSettings.WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
if (MessageBox.Show("Are your sure to delete " + selectedWebSearch.Title, "Delete WebSearch",
|
||||
@@ -72,7 +72,7 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Infrastructure.Storage.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Infrastructure.Storage.UserSettings.WebSearch;
|
||||
Core.UserSettings.WebSearch selectedWebSearch = webSearchView.SelectedItem as Core.UserSettings.WebSearch;
|
||||
if (selectedWebSearch != null)
|
||||
{
|
||||
WebSearchSetting webSearch = new WebSearchSetting(this);
|
||||
|
||||
@@ -77,6 +77,10 @@
|
||||
<WCFMetadata Include="Service References\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Wox.Core\Wox.Core.csproj">
|
||||
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
|
||||
<Name>Wox.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
|
||||
Reference in New Issue
Block a user