Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

storing & reading global hotkeys (it's still hard coded though)... fi…

…rst step in making it customizable
  • Loading branch information...
commit a5675a764388c08b2cb1c68c5f005ef1b50bd571 1 parent 0a7b1dc
@srushti authored
View
11 Azazel/AppFinder.cs
@@ -35,13 +35,8 @@ public class AppFinder {
}
private Folders LoadFoldersToParse() {
- return PersistanceHelper.LoadOrSaveAndLoad<Folders>(xstream, Paths.Instance.Folders, () => File.Contents(Paths.Instance.Folders),
- StoreDefaultFolders,
- "Because of some error (probably connected with plugins) all the folders you have added have been lost!! You will have to add them again!!");
- }
-
- private void StoreDefaultFolders() {
- File.WriteAllText(Paths.Instance.Folders, xstream.ToXml(new Folders(Folders.QuickLaunch, Folders.StartMenu, Folders.AllUsersStartMenu)));
+ return PersistanceHelper.LoadOrSaveAndLoad(xstream, Paths.Instance.Folders,
+ new Folders(Folders.QuickLaunch, Folders.StartMenu, Folders.AllUsersStartMenu));
}
public Launchables FindFiles(string searchString) {
@@ -68,7 +63,7 @@ public class AppFinder {
}
public void AddFolder(LaunchablePlugins launchablePlugins) {
- var folders = LoadFoldersToParse();
+ Folders folders = LoadFoldersToParse();
var dialog = new FolderBrowserDialog {SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal)};
if (dialog.ShowDialog() == DialogResult.OK) folders.Add(new Folder(dialog.SelectedPath));
File.WriteAllText(Paths.Instance.Folders, xstream.ToXml(folders));
View
12 Azazel/AppSettings.cs
@@ -1,9 +1,15 @@
-using System.Windows.Forms;
using Azazel.KeyHookup;
namespace Azazel {
public class AppSettings {
- public readonly Hotkey DisplayHotKey = new Hotkey(Modifiers.Windows, Keys.Space);
- public readonly Hotkey KillHotkey = new Hotkey(Modifiers.Shift | Modifiers.Alt | Modifiers.Control, Keys.F4);
+ public readonly Hotkey DisplayHotKey;
+ public readonly Hotkey KillHotKey;
+
+ public AppSettings() {}
+
+ public AppSettings(Hotkey displayHotKey, Hotkey killHotKey) {
+ DisplayHotKey = displayHotKey;
+ KillHotKey = killHotKey;
+ }
}
}
View
4 Azazel/FileSystem/Paths.cs
@@ -26,6 +26,10 @@ public class Paths {
get { return AppDataFile("exception.txt"); }
}
+ public string AppSettings {
+ get { return AppDataFile("AppSettings.xml"); }
+ }
+
private static string AppDataFile(string fileName) {
return Combine(Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Azazel", fileName));
}
View
12 Azazel/FileSystem/PersistanceHelper.cs
@@ -4,11 +4,11 @@
namespace Azazel.FileSystem {
public static class PersistanceHelper {
- public static T LoadOrSaveAndLoad<T>(XStream xStream, string filePath, LoadFile loadFile, VoidDelegate defaultSave, string messageBoxText) {
+ public static T LoadOrSaveAndLoad<T>(XStream xStream, string filePath, T defaultObject) {
if (!File.Exists(filePath))
- defaultSave();
+ Save(filePath, xStream, defaultObject);
try {
- return (T) xStream.FromXml(loadFile().Trim());
+ return (T) xStream.FromXml(((LoadFile) (() => File.Contents(filePath)))().Trim());
}
catch (Exception e) {
LogManager.WriteLog(e);
@@ -16,14 +16,14 @@ public static class PersistanceHelper {
File.WriteAllText(
file.FullName + DateTime.Now.ToString().Replace("/", "").Replace("\\", "").Replace(" ", "").Replace(":", "") + file.Extension,
File.Contents(filePath));
- defaultSave();
+ Save(filePath, xStream, defaultObject);
return (T) xStream.FromXml(File.Contents(filePath).Trim());
}
}
- public static void Save<T>(XStream xStream, File file, T t) {
+ public static void Save<T>(string path, XStream xStream, T t) {
try {
- file.WriteAllText(xStream.ToXml(t));
+ File.WriteAllText(path, xStream.ToXml(t));
}
catch (Exception e) {
LogManager.WriteLog(e);
View
10 Azazel/History.cs
@@ -14,12 +14,7 @@ public class History {
public History(File historyFile, XStream xstream) {
this.historyFile = historyFile;
this.xstream = xstream;
- dictionary = PersistanceHelper.LoadOrSaveAndLoad<Dictionary<string, Launchable>>(xstream, Paths.Instance.History, LoadHistory, StoreHistory,
- "Because of some error (probably connected with plugins) all your history has been lost!!");
- }
-
- protected virtual string LoadHistory() {
- return File.Contents(Paths.Instance.History);
+ dictionary = PersistanceHelper.LoadOrSaveAndLoad(xstream, Paths.Instance.History, dictionary);
}
public Launchable this[string input] {
@@ -28,8 +23,7 @@ public class History {
}
protected virtual void StoreHistory() {
- PersistanceHelper.Save(xstream, historyFile, dictionary);
- historyFile.WriteAllText(xstream.ToXml(dictionary));
+ PersistanceHelper.Save(historyFile.FullName, xstream, dictionary);
}
public void Add(string input, Launchable launchable) {
View
111 Azazel/MainWindowCommand.cs
@@ -1,54 +1,59 @@
-using System.Windows;
-using Azazel.KeyHookup;
-using Azazel.PluggingIn;
-
-namespace Azazel {
- public class MainWindowCommand {
- private readonly VoidDelegate killApplication;
- private readonly Hotkey displayHotkey;
- private readonly Hotkey killHotkey;
- private WPFHotkeyManager hotkeyManager;
- private readonly MainWindowController controller;
- private MainWindow window;
-
- public MainWindowCommand(VoidDelegate killApplication, AppSettings settings) {
- var selfPlugin = new SelfPlugin();
- var loader = new PluginLoader(selfPlugin);
- controller = new MainWindowController(loader.LaunchablePlugins, loader.CharacterPlugins, loader.LaunchableHandlers, selfPlugin);
- this.killApplication = killApplication;
- displayHotkey = settings.DisplayHotKey;
- killHotkey = settings.KillHotkey;
- }
-
- public void Execute() {
- window = new MainWindow(controller);
- window.Show();
- window.Activate();
- RegisterEvents();
- }
-
- public void Collapse() {
- window.Collapse();
- }
-
- private void RegisterEvents() {
- hotkeyManager = new WPFHotkeyManager(window);
- hotkeyManager.Register(displayHotkey);
- hotkeyManager.Register(killHotkey);
- hotkeyManager.HotkeyPressed += (window1, hotkey) => HandleHotkey(hotkey);
- }
-
- private void HandleHotkey(Hotkey hotkey) {
- if (window.Visibility != Visibility.Visible) {
- window.Close();
- hotkeyManager.Unregister(displayHotkey);
- hotkeyManager.Unregister(killHotkey);
- if (hotkey.Equals(displayHotkey)) Execute();
- else if (hotkey.Equals(killHotkey)) killApplication();
- }
- if (hotkey.Equals(displayHotkey)) window.Activate();
- }
- }
-
- public delegate void VoidDelegate();
+using System.Windows;
+using System.Windows.Forms;
+using Azazel.FileSystem;
+using Azazel.KeyHookup;
+using Azazel.PluggingIn;
+
+namespace Azazel {
+ public class MainWindowCommand {
+ private readonly VoidDelegate killApplication;
+ private readonly Hotkey displayHotkey;
+ private readonly Hotkey killHotkey;
+ private WPFHotkeyManager hotkeyManager;
+ private readonly MainWindowController controller;
+ private MainWindow window;
+
+ public MainWindowCommand(VoidDelegate killApplication, AppSettings settings) {
+ var selfPlugin = new SelfPlugin();
+ var loader = new PluginLoader(selfPlugin);
+ PersistanceHelper.LoadOrSaveAndLoad(selfPlugin.XStream, Paths.Instance.AppSettings,
+ new AppSettings(new Hotkey(Modifiers.Alt, Keys.F2),
+ new Hotkey(Modifiers.Alt | Modifiers.Control | Modifiers.Shift, Keys.F4)));
+ controller = new MainWindowController(loader.LaunchablePlugins, loader.CharacterPlugins, loader.LaunchableHandlers, selfPlugin);
+ this.killApplication = killApplication;
+ displayHotkey = settings.DisplayHotKey;
+ killHotkey = settings.KillHotKey;
+ }
+
+ public void Execute() {
+ window = new MainWindow(controller);
+ window.Show();
+ window.Activate();
+ RegisterEvents();
+ }
+
+ public void Collapse() {
+ window.Collapse();
+ }
+
+ private void RegisterEvents() {
+ hotkeyManager = new WPFHotkeyManager(window);
+ hotkeyManager.Register(displayHotkey);
+ hotkeyManager.Register(killHotkey);
+ hotkeyManager.HotkeyPressed += (window1, hotkey) => HandleHotkey(hotkey);
+ }
+
+ private void HandleHotkey(Hotkey hotkey) {
+ if (window.Visibility != Visibility.Visible) {
+ window.Close();
+ hotkeyManager.Unregister(displayHotkey);
+ hotkeyManager.Unregister(killHotkey);
+ if (hotkey.Equals(displayHotkey)) Execute();
+ else if (hotkey.Equals(killHotkey)) killApplication();
+ }
+ if (hotkey.Equals(displayHotkey)) window.Activate();
+ }
+ }
+
+ public delegate void VoidDelegate();
}
View
4 Azazel/PluggingIn/KeyboardShortcut.xaml.cs
@@ -7,6 +7,8 @@
namespace Azazel.PluggingIn {
public partial class KeyboardShortcut {
+ private Hotkey newHotkey;
+
public KeyboardShortcut() {
InitializeComponent();
HookEvents();
@@ -32,7 +34,7 @@ public partial class KeyboardShortcut {
!new List<Key> {Key.LeftAlt, Key.LeftCtrl, Key.LeftShift, Key.RightAlt, Key.RightCtrl, Key.RightShift, Key.LWin, Key.RWin, Key.System}.
Contains(key)) {
currentlySelected.Content = keyboardCombo.ToString();
- var newHotkey = new Hotkey(modifiers, (Keys) Enum.Parse(typeof (Keys), key.ToString()));
+ newHotkey = new Hotkey(modifiers, (Keys) Enum.Parse(typeof (Keys), key.ToString()));
}
}
}
View
5 AzazelTests/HistoryTest.cs
@@ -2,7 +2,6 @@
using Azazel.FileSystem;
using NUnit.Framework;
using Rhino.Mocks;
-using xstream;
namespace Azazel {
[TestFixture]
@@ -45,10 +44,6 @@ public class HistoryTest {
}
public class HistoryStub : History {
- protected override string LoadHistory() {
- return new XStream().ToXml(this);
- }
-
protected override void StoreHistory() {}
}
}
View
BIN  lib/XStream.dll
Binary file not shown
View
BIN  lib/XStream.pdb
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.