static void ChangeDictionary(INotificationService notification) { PatriciaTrie translationTrie; string currentKey = ""; if (NinjaTranslateMain.nextKeyToUse.Equals("quickchangeKey")) { translationTrie = NinjaTranslateMain.LoadTranslationTree(NinjaTranslateMain.quickChangeKey); currentKey = NinjaTranslateMain.quickChangeKey; NinjaTranslateMain.nextKeyToUse = "currentKey"; } else { translationTrie = NinjaTranslateMain.LoadTranslationTree(NinjaTranslateMain.currentFileKey); NinjaTranslateMain.nextKeyToUse = "quickchangeKey"; currentKey = NinjaTranslateMain.currentFileKey; } NinjaTranslateMain.translationCenter.SetTranslationTree(translationTrie); if (notification != null) { notification.Notify("New Dictionary: " + currentKey); } }
static void Main() { //Initiate update process //deactivated for now, though it does work! //NinjaTranslateMain.Update(Config.GetValue("version"), Config.GetValue("updateStep")); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); //load windows MainWindow mainWindow = new MainWindow(); NotificationForm notificationForm = new NotificationForm(); //load config values LoadConfigFiles(mainWindow); //load tree PatriciaTrie translationTree = LoadTranslationTree(currentFileKey); //TODO normalizer is used for input and parsing -> surely no problem when we finally add filters Normalizer normalizer = new Normalizer(); //initiate translation center translationCenter = new TranslationCenter(); translationCenter.SetFilter(normalizer); translationCenter.SetTranslationTree(translationTree); //initiate notification service CustomNotification notification = new CustomNotification(); notification.setHeight(Int32.Parse(Config.GetValue("windowHeight"))); notification.setWidth(Int32.Parse(Config.GetValue("windowWidth"))); notification.SetForm(notificationForm); //initiate sources to be translated from SystemSource systemSource = new SystemSource(); int clipboardAccessTimer = 500; int.TryParse(Config.GetValue("clipboardAccessTimer"), out clipboardAccessTimer); systemSource.SetClipboardAccessTimer(clipboardAccessTimer); systemSource.SetTranslationService(translationCenter); systemSource.SetNotificationService(notification); InputForm inputSource = new InputForm(); inputSource.SetTranslationService(translationCenter); inputSource.SetNotificationService(notification); //register hooks KeyboardHook markerHook = new KeyboardHook(); KeyboardHook inputHook = new KeyboardHook(); KeyboardHook dictionaryHook = new KeyboardHook(); try { // register the control + alt + N combination as hot key to translate current selection. markerHook.KeyPressed += new EventHandler <KeyPressedEventArgs>(delegate(object sender, KeyPressedEventArgs e) { systemSource.TriggerTranslation(true); }); markerHook.RegisterHotKey((ModifierKeys)2 | (ModifierKeys)1, Keys.N); // register the control + alt + B combination as hot key to open up input formular. inputHook.KeyPressed += new EventHandler <KeyPressedEventArgs>(delegate(object sender, KeyPressedEventArgs e) { inputSource.TriggerTranslation(true); }); inputHook.RegisterHotKey((ModifierKeys)2 | (ModifierKeys)1, Keys.B); //register the control + alt + V combination to trigger a switch of the chosen dictionary dictionaryHook.KeyPressed += new EventHandler <KeyPressedEventArgs>(delegate(object sender, KeyPressedEventArgs e) { //reload in case user has added a dict NinjaTranslateMain.rawFiles = Config.GetMultiValue("path"); NinjaTranslateMain.quickChangeKey = Config.GetValue("quickchangeKey"); NinjaTranslateMain.currentFileKey = Config.GetValue("currentKey"); NinjaTranslateMain.ChangeDictionary(notification); }); dictionaryHook.RegisterHotKey((ModifierKeys)2 | (ModifierKeys)1, Keys.V); } catch (InvalidOperationException e) { System.Windows.Forms.MessageBox.Show("NinjaTranslate couldn't register the necessary hotkeys. It seems like another program uses them. Try to close them :)", "NinjaTranslate found an error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //check if construction went well or if window is marked as indisposed if (!mainWindow.IsDisposed) { Application.Run(mainWindow); } GC.KeepAlive(markerHook); GC.KeepAlive(dictionaryHook); GC.KeepAlive(inputHook); }