private void createOrderSql(PNTreeItem node) { try { foreach (var pti in node.Items.OfType <PNTreeItem>()) { createOrderSql(pti); } var pnm = node.Tag as PNMenu; if (pnm == null) { return; } var sb = new StringBuilder("UPDATE MENUS_ORDER SET ORDER_NEW = "); sb.Append(node.Index); sb.Append(" WHERE CONTEXT_NAME = '"); sb.Append(pnm.ContextName); sb.Append("' AND MENU_NAME = '"); sb.Append(pnm.Name); sb.Append("'"); _OrderSql.Add(sb.ToString()); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void loadGroups(PNGroup gr, PNTreeItem item, string captionShow, string captionHide) { try { var ti = new PNTreeItem("submnu", gr.Name, gr.ID.ToString(CultureInfo.InvariantCulture)) { IsExpanded = true }; ti.Items.Add(new PNTreeItem("mnu", captionShow, gr.ID.ToString(CultureInfo.InvariantCulture) + "_show")); ti.Items.Add(new PNTreeItem("mnu", captionHide, gr.ID.ToString(CultureInfo.InvariantCulture) + "_hide")); if (item == null) { _ItemsGroup.Add(ti); } else { item.Items.Add(ti); } foreach (PNGroup g in gr.Subgroups) { loadGroups(g, ti, captionShow, captionHide); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void loadGroup(PNGroup pgroup, PNTreeItem item) { try { var ti = new PNTreeItem(pgroup.Image, pgroup.Name, pgroup) { IsExpanded = true }; foreach (var sg in pgroup.Subgroups) { loadGroup(sg, ti); } if (item == null) { _Items.Add(ti); } else { item.Items.Add(ti); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private static void expandTreeItem(PNTreeItem item) { foreach (var it in item.Items.OfType <PNTreeItem>()) { expandTreeItem(it); } item.IsExpanded = true; }
private void resetChecks(PNTreeItem item) { try { foreach (PNTreeItem n in item.Items) { resetChecks(n); } item.IsChecked = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void loadMenus(PNMenu mnu, PNTreeItem item, MenuType type) { try { //PNStrings.MENU_SEPARATOR_STRING var treeItem = mnu.Text != PNStrings.MENU_SEPARATOR_STRING ? new PNTreeItem("mnu", mnu.Text, mnu, mnu.Name, PNStatic.HiddenMenus.Where(m => m.Type == type).All(m => m.Name != mnu.Name)) { IsExpanded = true } : new PNTreeItem("mnu", mnu.Text, mnu, mnu.Name); treeItem.TreeViewItemCheckChanged += treeItem_TreeViewItemCheckChanged; foreach (var sg in mnu.Items) { loadMenus(sg, treeItem, type); } if (item == null) { switch (type) { case MenuType.Main: _ItemsMain.Add(treeItem); break; case MenuType.Note: _ItemsNote.Add(treeItem); break; case MenuType.Edit: _ItemsEdit.Add(treeItem); break; case MenuType.ControlPanel: _ItemsCP.Add(treeItem); break; } } else { item.Items.Add(treeItem); } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal WndNewGroup(PNGroup group, PNTreeItem treeItem) : this() { if (group != null) { m_Group = (PNGroup)group.Clone(); m_Mode = AddEditMode.Edit; } else { m_Group = new PNGroup { IsDefaultImage = true }; } _TreeItem = treeItem; }
private void setButtonsEnabled(PNTreeItem node) { try { if (node.Image.Equals(_ImageSubmenu)) { //cmdAddHK.IsEnabled = false; //cmdEditHK.IsEnabled = false; cmdDeleteHK.IsEnabled = false; txtHotKey.Visibility = Visibility.Hidden; } else { var name = (string)node.Tag; PNHotKey hk = null; switch (tabHK.SelectedIndex) { case 0: hk = m_KeysMain.FirstOrDefault(h => h.MenuName == name); break; case 1: hk = m_KeysNote.FirstOrDefault(h => h.MenuName == name); break; case 2: hk = m_KeysEdit.FirstOrDefault(h => h.MenuName == name); break; case 3: hk = m_KeysGroups.FirstOrDefault(h => h.MenuName == name); break; } if (hk == null) { return; } cmdDeleteHK.IsEnabled = hk.VK != 0; txtHotKey.Visibility = Visibility.Visible; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void saveUncheckedNodes(PNTreeItem item) { try { foreach (var n in item.Items.OfType <PNTreeItem>()) { saveUncheckedNodes(n); } if (item.IsChecked != null && !item.IsChecked.Value) { _UncheckedNodes.Add(item.Key); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void restoreUncheckedNodes(PNTreeItem item) { try { foreach (var pti in item.Items.OfType <PNTreeItem>()) { restoreUncheckedNodes(pti); } if (_UncheckedNodes.Any(s => s == item.Key)) { item.IsChecked = false; return; } item.IsChecked = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void enableUpDown(PNTreeItem item) { try { if (item == null) { cmdUp.IsEnabled = cmdDown.IsEnabled = false; } else { var index = item.Index; cmdUp.IsEnabled = index > 0; var parent = ItemsControl.ItemsControlFromItemContainer(item); cmdDown.IsEnabled = index < parent.Items.Count - 1; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void fillNodesList(PNTreeItem item, List <string> listNames, List <string> listHidden) { try { foreach (var pti in item.Items.OfType <PNTreeItem>()) { fillNodesList(pti, listNames, listHidden); } listNames.Add(item.Key); if (listHidden == null) { return; } if (!item.IsChecked.HasValue || !item.IsChecked.Value) { listHidden.Add(item.Key); } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal GroupChangedEventArgs(PNGroup group, AddEditMode mode, PNTreeItem treeItem) { Group = group; Mode = mode; TreeItem = treeItem; }
private void cmdDeleteHK_Click(object sender, RoutedEventArgs e) { try { var message = PNLang.Instance.GetMessageText("delete_hot_keys", "Delete selected hot keys combination?"); if (PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } PNHotKey hk = null; PNTreeItem tvi = null; switch (tabHK.SelectedIndex) { case 0: tvi = tvwHKMain.SelectedItem as PNTreeItem; if (tvi == null) { break; } hk = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 1: tvi = tvwHKNote.SelectedItem as PNTreeItem; if (tvi == null) { break; } hk = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 2: tvi = tvwHKEdit.SelectedItem as PNTreeItem; if (tvi == null) { break; } hk = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; case 3: tvi = tvwHKGroups.SelectedItem as PNTreeItem; if (tvi == null) { break; } hk = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag); setButtonsEnabled(tvi); break; } if (hk == null) { return; } var defKey = _DefKeys.FirstOrDefault(dk => dk.Id == hk.ID); if (defKey != null) { _DefKeys.Remove(defKey); } hk.Clear(); txtHotKey.Text = ""; setButtonsEnabled(tvi); if (txtHotKey.IsFocused) { PNStatic.SendKey(Key.Tab); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void loadMenus(PNMenu mnu, PNTreeItem item, HotkeyType type) { try { if (mnu.Text == PNStrings.MENU_SEPARATOR_STRING) { return; } switch (mnu.Name) { case "": case "mnuSave": case "mnuPrint": case "mnuGroups": case "mnuRemoveFromFavorites": case "mnuRemovePassword": case "mnuUnpin": case "mnuUndo": case "mnuRedo": case "mnuCut": case "mnuCopy": case "mnuPaste": case "mnuFind": case "mnuFindNext": case "mnuReplace": case "mnuSearchWeb": case "mnuSelectAll": case "mnuShowByTag": case "mnuHideByTag": case "mnuFont": case "mnuFontSize": case "mnuFontColor": case "mnuBold": case "mnuItalic": case "mnuUnderline": case "mnuStrikethrough": case "mnuHighlight": case "mnuAlignLeft": case "mnuAlignCenter": case "mnuAlignRight": case "mnuPostOn": case "mnuPostNote": case "mnuReplacePost": case "mnuInsertPost": case "mnuRun": return; } var ti = new PNTreeItem(mnu.Items.Any() ? "submnu" : "mnu", mnu.Text, mnu.Name) { IsExpanded = true }; foreach (var sg in mnu.Items) { loadMenus(sg, ti, type); } if (item == null) { switch (type) { case HotkeyType.Main: _ItemsMain.Add(ti); break; case HotkeyType.Note: _ItemsNote.Add(ti); break; case HotkeyType.Edit: _ItemsEdit.Add(ti); break; case HotkeyType.Group: _ItemsGroup.Add(ti); break; } } else { item.Items.Add(ti); } } 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); } }
private void findInNoteAtLeastOneWord(PNote note, string searchString, System.Windows.Forms.RichTextBoxFinds options, ref int count) { try { var foundTitle = false; PNRichEditBox edit; var strings = searchString.Split(' '); var counter = 0; var key = PNNotesOperations.GetNoteImage(note); var tn = new PNTreeItem(key, note.Name, note.ID); switch (_Scope) { case SearchScope.Titles: if (!strings.Any(s => note.Name.Contains(s))) { return; } count++; _FoundItems.Add(tn); return; case SearchScope.TextAndTitles: if (strings.Any(s => note.Name.Contains(s))) { count++; foundTitle = true; } break; } if (note.Visible) { edit = note.Dialog.Edit; } else { var path = Path.Combine(PNPaths.Instance.DataDir, note.ID + PNStrings.NOTE_EXTENSION); _HiddenEdit.Size = note.EditSize; PNNotesOperations.LoadNoteFile(_HiddenEdit, path); edit = _HiddenEdit; } var stop = edit.TextLength; foreach (var s in strings) { var start = 0; var index = edit.Find(s, start, options); if (index <= -1) { continue; } counter++; var current = 0; while (index > -1 && current <= index) { count++; current = index; var line = edit.GetLineFromCharIndex(index); var col = index - edit.GetFirstCharIndexFromLine(line); var t = new PNTreeItem("searchloc", s + " (" + _Line + " " + (line + 1).ToString(CultureInfo.InvariantCulture) + ", " + _Column + " " + (col + 1).ToString(CultureInfo.InvariantCulture) + ")", new[] { index, s.Length }); tn.Items.Add(t); if (s.Length > 1) { start = index + s.Length - 1; } else { start = index + s.Length; } if (start >= stop) { break; } index = edit.Find(s, start, options); } } if (counter > 0 || foundTitle) { if (_Scope == SearchScope.TextAndTitles) { if (counter > 0 && foundTitle) { tn.Text += @" " + _TextAndTitle; } else if (counter > 0) { tn.Text += @" " + _TextOnly; } else { tn.Text += @" " + _TitleOnly; } } _FoundItems.Add(tn); return; } count = 0; } catch (Exception ex) { PNStatic.LogException(ex); } }