protected override void DoRecursivelyResolve(Dictionary <string, DataDefinition> local, Dictionary <string, DataDefinition> global, Dictionary <string, Dictionary <string, DataDefinition> > referenceableDefinitions) { if (DefKey != null) { var key = DefKey.ToLower(); Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key)) { defs = local; } else if (global.ContainsKey(key)) { defs = global; } if (defs != null) { var def = defs[key] as ReferenceDefinition; Keys = def.Keys; ListCollectionView lcv = new ListCollectionView(Keys); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2")); ItemsSource = lcv; } else { throw new Exception("Failed to find key " + DefKey + "!"); } } foreach (var key in Keys) { Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key.Item1.ToLower())) { defs = local; } else if (global.ContainsKey(key.Item1.ToLower())) { defs = global; } if (defs != null) { var def = defs[key.Item1.ToLower()]; if (def is GraphNodeDefinition) { Definitions[key.Item1] = def as GraphNodeDefinition; } else if (key.Item1 != "---") { throw new Exception("Tried to add definition of type " + def.GetType() + " (key = " + key.Item1 + ") to graph reference!"); } } else { throw new Exception("Failed to find key " + key.Item1 + "!"); } } if (Keys.Count == 0) { Keys.Add(new Tuple <string, string>("---", "---")); ListCollectionView lcv = new ListCollectionView(Keys); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2")); ItemsSource = lcv; Definitions["---"] = new GraphStructDefinition(); } }
protected override void DoRecursivelyResolve(Dictionary <string, DataDefinition> local, Dictionary <string, DataDefinition> global, Dictionary <string, Dictionary <string, DataDefinition> > referenceableDefinitions) { if (DefKey != null) { var key = DefKey.ToLower(); Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key)) { defs = local; } else if (global.ContainsKey(key)) { defs = global; } if (defs != null) { var def = defs[key] as ReferenceDefinition; foreach (var keydef in def.Keys) { var childDef = def.Definitions[keydef.Item1]; childDef.RecursivelyResolve(local, global, referenceableDefinitions); var keyframeDef = new KeyframeDefinition(); keyframeDef.CreateFrom(childDef); KeyframeDefinitions.Add(keyframeDef); Keys.Add(new Tuple <KeyframeDefinition, string>(keyframeDef, keydef.Item2)); } } else { throw new Exception("Failed to find key " + DefKey + "!"); } } foreach (var key in DefKeys) { Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key.Item1.ToLower())) { defs = local; } else if (global.ContainsKey(key.Item1.ToLower())) { defs = global; } if (defs != null) { var childDef = defs[key.Item1.ToLower()]; childDef.RecursivelyResolve(local, global, referenceableDefinitions); var keyframeDef = new KeyframeDefinition(); keyframeDef.CreateFrom(childDef); KeyframeDefinitions.Add(keyframeDef); Keys.Add(new Tuple <KeyframeDefinition, string>(keyframeDef, key.Item2)); } else if (key.Item1 != "---") { throw new Exception("Failed to find key " + key.Item1 + "!"); } } foreach (var def in KeyframeDefinitions) { def.RecursivelyResolve(local, global, referenceableDefinitions); } }
public override void RecursivelyResolve(Dictionary <string, DataDefinition> local, Dictionary <string, DataDefinition> global, Dictionary <string, Dictionary <string, DataDefinition> > referenceableDefinitions) { if (DefKey != null) { var key = DefKey.ToLower(); Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key)) { defs = local; } else if (global.ContainsKey(key)) { defs = global; } if (defs != null) { var def = defs[key] as ReferenceDefinition; Keys = def.Keys; ListCollectionView lcv = new ListCollectionView(Keys); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2")); ItemsSource = lcv; } else { Message.Show("Failed to find key " + DefKey + "!", "Reference Resolve Failed", "Ok"); } } foreach (var key in Keys) { Dictionary <string, DataDefinition> defs = null; if (local.ContainsKey(key.Item1.ToLower())) { defs = local; } else if (global.ContainsKey(key.Item1.ToLower())) { defs = global; } if (defs != null) { Definitions[key.Item1] = defs[key.Item1.ToLower()]; } else if (key.Item1 != "---") { Message.Show("Failed to find key " + key.Item1 + "!", "Reference Resolve Failed", "Ok"); } } if (Keys.Count == 0) { Keys.Add(new Tuple <string, string>("---", "---")); ListCollectionView lcv = new ListCollectionView(Keys); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Item2")); ItemsSource = lcv; Definitions["---"] = new DummyDefinition(); } }
private void txtHotKey_PreviewKeyDown(object sender, KeyEventArgs e) { try { var check = false; var modString = ""; var keyString = ""; var hk = new PNHotKey { Modifiers = HotkeysStatic.GetModifiers(ref modString), VK = HotkeysStatic.GetKey(ref keyString), Shortcut = modString + keyString }; if (hk.Modifiers == HotkeyModifiers.MOD_NONE) { if (hk.VK >= HotkeysStatic.VK_F1 && hk.VK <= HotkeysStatic.VK_F24) { check = true; } } else { if (hk.VK > 0) { check = true; } } if (!check) { return; } string message, caption; if (PNStrings.RestrictedHotkeys.Contains(hk.Shortcut) || PNStatic.HotKeysEdit.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || PNStatic.HotKeysGroups.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || PNStatic.HotKeysNote.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || hk.Modifiers == HotkeyModifiers.MOD_SHIFT && (hk.VK >= HotkeysStatic.VK_A && hk.VK <= HotkeysStatic.VK_Z)) { message = hk.Shortcut + '\n'; message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered."); message += '\n'; message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please."); caption = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys"); PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation); e.Handled = true; return; } if (HotkeysStatic.RegisterHK(_HwndSource.Handle, hk)) { HotkeysStatic.UnregisterHK(_HwndSource.Handle, hk.ID); } else { message = hk.Shortcut + '\n'; message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered."); message += '\n'; message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please."); caption = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys"); PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation); e.Handled = true; return; } PNTreeItem tvi = null; PNHotKey hkCurrent = null; switch (tabHK.SelectedIndex) { case 0: tvi = tvwHKMain.SelectedItem as PNTreeItem; if (tvi == null) { break; } hkCurrent = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 1: tvi = tvwHKNote.SelectedItem as PNTreeItem; if (tvi == null) { break; } hkCurrent = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 2: tvi = tvwHKEdit.SelectedItem as PNTreeItem; if (tvi == null) { break; } hkCurrent = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 3: tvi = tvwHKGroups.SelectedItem as PNTreeItem; if (tvi == null) { break; } hkCurrent = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; } if (hkCurrent != null) { hkCurrent.Modifiers = hk.Modifiers; hkCurrent.Shortcut = hk.Shortcut; hkCurrent.VK = hk.VK; setButtonsEnabled(tvi); txtHotKey.Text = hk.Shortcut; var defKey = new DefKey(hkCurrent.ID, hkCurrent.Type, hkCurrent.MenuName) { Icon = isHotkeyInDatabase( tabHK.SelectedIndex == 0 ? PNStatic.HotKeysMain : (tabHK.SelectedIndex == 1 ? PNStatic.HotKeysNote : (tabHK.SelectedIndex == 2 ? PNStatic.HotKeysEdit : PNStatic.HotKeysGroups)), hk) ? (BitmapSource)TryFindResource("check") : null, MenuRange = tabHK.SelectedIndex == 0 ? tbpHKMain.Header.ToString() : (tabHK.SelectedIndex == 1 ? tbpHKNote.Header.ToString() : (tabHK.SelectedIndex == 2 ? tbpHKEdit.Header.ToString() : tbpHKGroups.Header.ToString())), MenuText = tabHK.SelectedIndex < 3 ? PNLang.Instance.GetMenuText( tabHK.SelectedIndex == 0 ? "main_menu" : (tabHK.SelectedIndex == 1 ? "note_menu" : "edit_menu"), hkCurrent.MenuName, hkCurrent.MenuName) : hkCurrent.MenuName, Shortcut = hkCurrent.Shortcut }; if (tabHK.SelectedIndex == 3) { var arr = hkCurrent.MenuName.Split('_'); if (arr.Length == 2) { var gr = PNStatic.Groups.GetGroupByID(Convert.ToInt32(arr[0])); if (gr != null) { var defCap = arr[1] == "show" ? PNLang.Instance.GetCaptionText("show_group", "Show group") : PNLang.Instance.GetCaptionText("hide_group", "Hide group"); defKey.MenuText = gr.Name + "/" + defCap; } } } //remove existing key var existingKey = _DefKeys.FirstOrDefault(k => k.Id == defKey.Id); if (existingKey != null) { _DefKeys.Remove(existingKey); } _DefKeys.Add(defKey); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void txtHotKey_PreviewKeyDown(object sender, KeyEventArgs e) { try { var check = false; var modString = ""; var keyString = ""; var hk = new PNHotKey { Modifiers = HotkeysStatic.GetModifiers(ref modString), VK = HotkeysStatic.GetKey(ref keyString), Shortcut = modString + keyString }; if (hk.Modifiers == HotkeyModifiers.MOD_NONE) { if (hk.VK >= HotkeysStatic.VK_F1 && hk.VK <= HotkeysStatic.VK_F24) { check = true; } } else { if (hk.VK > 0) { check = true; } } if (!check) { return; } string message, caption; if (PNStrings.RestrictedHotkeys.Contains(hk.Shortcut) || PNStatic.HotKeysEdit.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || PNStatic.HotKeysGroups.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || PNStatic.HotKeysNote.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) || hk.Modifiers == HotkeyModifiers.MOD_SHIFT && (hk.VK >= HotkeysStatic.VK_A && hk.VK <= HotkeysStatic.VK_Z)) { message = hk.Shortcut + '\n'; message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered."); message += '\n'; message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please."); caption = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys"); PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation); e.Handled = true; return; } if (HotkeysStatic.RegisterHK(_HwndSource.Handle, hk)) { HotkeysStatic.UnregisterHK(_HwndSource.Handle, hk.ID); } else { message = hk.Shortcut + '\n'; message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered."); message += '\n'; message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please."); caption = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys"); PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation); e.Handled = true; return; } PNTreeItem tvi = null; PNHotKey hkCurrent = null; switch (tabHK.SelectedIndex) { case 0: tvi = tvwHKMain.SelectedItem as PNTreeItem; if (tvi == null) break; hkCurrent = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 1: tvi = tvwHKNote.SelectedItem as PNTreeItem; if (tvi == null) break; hkCurrent = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 2: tvi = tvwHKEdit.SelectedItem as PNTreeItem; if (tvi == null) break; hkCurrent = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 3: tvi = tvwHKGroups.SelectedItem as PNTreeItem; if (tvi == null) break; hkCurrent = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; } if (hkCurrent != null) { hkCurrent.Modifiers = hk.Modifiers; hkCurrent.Shortcut = hk.Shortcut; hkCurrent.VK = hk.VK; setButtonsEnabled(tvi); txtHotKey.Text = hk.Shortcut; var defKey = new DefKey(hkCurrent.ID, hkCurrent.Type, hkCurrent.MenuName) { Icon = isHotkeyInDatabase( tabHK.SelectedIndex == 0 ? PNStatic.HotKeysMain : (tabHK.SelectedIndex == 1 ? PNStatic.HotKeysNote : (tabHK.SelectedIndex == 2 ? PNStatic.HotKeysEdit : PNStatic.HotKeysGroups)), hk) ? (BitmapSource)TryFindResource("check") : null, MenuRange = tabHK.SelectedIndex == 0 ? tbpHKMain.Header.ToString() : (tabHK.SelectedIndex == 1 ? tbpHKNote.Header.ToString() : (tabHK.SelectedIndex == 2 ? tbpHKEdit.Header.ToString() : tbpHKGroups.Header.ToString())), MenuText = tabHK.SelectedIndex < 3 ? PNLang.Instance.GetMenuText( tabHK.SelectedIndex == 0 ? "main_menu" : (tabHK.SelectedIndex == 1 ? "note_menu" : "edit_menu"), hkCurrent.MenuName, hkCurrent.MenuName) : hkCurrent.MenuName, Shortcut = hkCurrent.Shortcut }; if (tabHK.SelectedIndex == 3) { var arr = hkCurrent.MenuName.Split('_'); if (arr.Length == 2) { var gr = PNStatic.Groups.GetGroupByID(Convert.ToInt32(arr[0])); if (gr != null) { var defCap = arr[1] == "show" ? PNLang.Instance.GetCaptionText("show_group", "Show group") : PNLang.Instance.GetCaptionText("hide_group", "Hide group"); defKey.MenuText = gr.Name + "/" + defCap; } } } //remove existing key var existingKey = _DefKeys.FirstOrDefault(k => k.Id == defKey.Id); if (existingKey != null) _DefKeys.Remove(existingKey); _DefKeys.Add(defKey); } } catch (Exception ex) { PNStatic.LogException(ex); } }