/// <summary> /// Opens the font editor dialog for the selected font in the list /// </summary> private void EditFont() { //Create new instance of Font Editor form. var f = new frmEdit(XFont.Load(((XItem)listFonts.SelectedItem).FileName), false); //Store current keyboard state var o = Program.kManager.Mode; if (o != KeyboardMode.Enabled) //If current state is enabled, temporarily disable it. { Logger.Notify("KManager temporarily switched the keyboard mode for the application to work correctly. ", MessageKind.Info); Program.kManager.Mode = KeyboardMode.Enabled; /////NOTE///// /// This application cannot recieve any keyboard input as long as the keyboardmode is set to intercept! /////////////// } f.ShowDialog(); //Restore keyboard state. if (o != KeyboardMode.Enabled) { Logger.Notify("KManager restored the keyboard mode to " + (o == KeyboardMode.Intercept ? "intercept keys." : " disabled. "), MessageKind.Info); } Program.kManager.Mode = o; //Reload font (if specified) if (Program.fManager.CurrentFont != null) { Program.fManager.CurrentFont = XFont.Load(Program.fManager.CurrentFont.File()); } }
/// <summary> /// Initializes the Font, Keyboard, Config and Notification manager. /// </summary> public static void Initiate() { //Subscribe to Application shutdown event. App.Current.Exit += (xx, ee) => { Log($"Program.Exit({ee.ApplicationExitCode}): Application shutdown was requested. Unregistering keyboard hook..."); kManager.Unregister(); Log($"Program.Exit({ee.ApplicationExitCode}): Saving settings..."); SaveSettings(); Log($"Program.Exit({ee.ApplicationExitCode}): Closing logger. Good bye!"); WriteHeader(); Save(); NotificationManager.NotifyIcon.Visible = false; }; //Initialize logger. Logger.Init(); //Write new heading in the log file. WriteHeader(); Log("Program.Initiate()..."); Log("Program.Initiate(): Instantiating FontManager..."); fManager = new FontManager(new XSerializer()); Log("Program.Initiate(): Instantiating NotificationManager..."); NotificationManager.Initiate(); Log("Program.Initiate(): Instantiating ConfigManager..."); cManager = new ConfigManager("config.cfg", new BSerializer(), true); //Using BinarySerializer because the class contains complicated data objects. //Set up Keyboard Manager. Log("Program.Initiate(): Instantiating Keyboad Manager..."); kManager = new KManager(); //Register to low level keyboard hook kManager.Register(); //Subscribe to input event from KManager. kManager.KeyIntercept += Key_Intercepted; //Load settings. Log("Program.Initiate(): Loading last configuration..."); cManager.AutoSave = cManager.Get <bool>(ConfigKeys.Autosave); //Load recent font. string lastFont = cManager.Get <string>(ConfigKeys.LastFont); if (string.IsNullOrEmpty(lastFont) == false && System.IO.File.Exists(lastFont)) { Log("Program.Initiate(): Loading recent font: " + lastFont); fManager.CurrentFont = XFont.Load(lastFont); } //Set keyboard state to last recent state kManager.KeyboardState = cManager.Get <KeyboardState>(ConfigKeys.KeyboardState); //Set beep on keyboard block to last setting. kManager.Beep = cManager.Get <bool>(ConfigKeys.InputBlockBeep); Log("Program.Initiate(): Setting up global error handlers..."); //Subscribe to Global Exception Handlers. (in case there are un-expected errors) AppDomain.CurrentDomain.FirstChanceException += (oo, ee) => { Log($"A first chance of exception was detected on the object of type: {oo.GetType()}. Exception: {ee.Exception}", MessagePriority.Low, MessageKind.Warning); }; AppDomain.CurrentDomain.UnhandledException += (oo, ee) => { Log($"An unhandled error occured in the application on an object of type {oo.GetType()}. {(ee.IsTerminating ? "The application must be terminated in order to avoid any miss-behaviour or data loss. ":"The application can continue however, it is recommended to close the application and start again. ")} Exception: {ee.ExceptionObject as Exception}", MessagePriority.High, MessageKind.Error); }; }
/// <summary> /// Initializes the Font, Keyboard, Config and Notification manager. /// </summary> public static void Initiate() { //Subscribe to Application shutdown event. App.Current.Exit += (xx, ee) => { Log($"Application shutdown was requested. Unregistering keyboard hook..."); kManager.Unregister(); Log($"Saving settings..."); SaveSettings(); Log($"Closing logger. Good bye!"); Logger.Save(); //Save the log file NotificationManager.NotifyIcon.Visible = false; }; //Subscribe to Global Exception Handlers. (in case there are un-expected runtime errors) AppDomain.CurrentDomain.FirstChanceException += (oo, ee) => { Log($"A first chance of exception was detected on the object of type: {oo.GetType()}. Exception: {ee.Exception}", MessagePriority.Low, MessageKind.Warning); }; AppDomain.CurrentDomain.UnhandledException += (oo, ee) => { Log($"An unhandled error occured in the application on an object of type {oo.GetType()}. {(ee.IsTerminating ? "The application must be terminated in order to avoid any miss-behaviour or data loss. " : "The application can continue however, it is recommended to close the application and start again. ")} Exception: {ee.ExceptionObject as Exception}", MessagePriority.High, MessageKind.Error); }; //Initialize logger. Logger.Init(); Log("Initializing FontManager..."); fManager = new FontManager(); Log("Instializing NotificationManager..."); NotificationManager.Initiate(); Log("Initializing XConfig..."); //Set up Keyboard Manager. Log("Initializing KeyboadManager..."); kManager = new KManager(); //Register to low level keyboard hook kManager.Register(); //Subscribe to input event from KManager. kManager.KeyIntercept += Key_Intercepted; kManager.KeyForward += KManager_KeyForward; //Load settings. Log("Loading last configuration..."); //Load recent font. string lastFont = XKeyboard.Properties.Settings.Default.lastFont; if (string.IsNullOrEmpty(lastFont) == false && System.IO.File.Exists(lastFont)) { Log("Loading font: " + lastFont); fManager.CurrentFont = XFont.Load(lastFont); } //Set keyboard state to last recent state kManager.Mode = (KeyboardMode)Properties.Settings.Default.lastState; //Set beep on keyboard block to last setting. kManager.Beep = Properties.Settings.Default.beepOnBlock; }