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 resetChecks(PNTreeItem item) { try { foreach (PNTreeItem n in item.Items) { resetChecks(n); } item.IsChecked = true; } 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); } }
private void deleteGroupOnDrop(PNGroup pnGroup, PNTreeItem itemToDelete = null) { try { var message = PNLang.Instance.GetMessageText("delete_group_warning", "Are you sure you want to delete this group - " + PNStrings.PLACEHOLDER1 + " - and all included subgroups and notes?"); message = message.Replace(PNStrings.PLACEHOLDER1, pnGroup.Name); if (PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) return; var groupsIds = new List<int>(); var notesIds = new List<string>(); deleteGroup(pnGroup, groupsIds, notesIds); var parent = PNStatic.Groups.GetGroupByID(pnGroup.ParentID); if (parent != null) { parent.Subgroups.RemoveAll(g => g.ID == pnGroup.ID); } PNStatic.Groups.RemoveAll(g => g.ID == pnGroup.ID); if (groupsIds.Count > 0) { PNData.DeleteGroups(groupsIds); } foreach (var id in notesIds) { var note = PNStatic.Notes.Note(id); deleteNote(note, note.FromDB ? NoteDeleteType.Bin : NoteDeleteType.Complete); } if (itemToDelete == null) return; if (itemToDelete.ItemParent == null) { _PGroups.Remove(itemToDelete); } else { itemToDelete.ItemParent.Items.Remove(itemToDelete); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void addGroupToTree(PNGroup group, PNTreeItem node) { try { var temp = (PNGroup)group.Clone(); group.CopyTo(temp); var n = new PNTreeItem(temp.Image, temp.Name, temp); if (node == null) { tvwGroups.Items.Add(n); } else { node.Items.Add(n); } foreach (var g in group.Subgroups.OrderBy(gr => gr.Name)) { addGroupToTree(g, n); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void checkAndApplyGroupChanges(PNTreeItem node, List<int> changedSkins) { try { var gr = node.Tag as PNGroup; if (gr == null) return; var rg = PNStatic.Groups.GetGroupByID(gr.ID); if (rg != null) { if (gr != rg) { if (gr.Skin.SkinName != rg.Skin.SkinName) { changedSkins.Add(gr.ID); } gr.CopyTo(rg); PNData.SaveGroupChanges(rg); } foreach (var n in node.Items.OfType<PNTreeItem>()) { checkAndApplyGroupChanges(n, changedSkins); } } else { if (gr.ID != (int)SpecialGroups.Docking) return; if (gr == PNStatic.Docking) return; changedSkins.Add((int)SpecialGroups.Docking); gr.CopyTo(PNStatic.Docking); PNData.SaveGroupChanges(PNStatic.Docking); } } 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 (pgroup.ID == m_GroupID) { ti.IsSelected = true; } else if (pgroup.ID == 0 && m_GroupID == -1) { ti.IsSelected = true; } if (item == null) _Items.Add(ti); else item.Items.Add(ti); } catch (Exception ex) { PNStatic.LogException(ex); } }
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 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 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); } }
public PNTreeItem Clone() { PNTreeItem pti; if (PNUtils.GetIsResourceImage(this)) { var arr = _Image.Source.ToString().Split(new[] { @"/" }, StringSplitOptions.RemoveEmptyEntries); pti = new PNTreeItem(Path.GetFileNameWithoutExtension(arr[arr.Length - 1]), Text, Tag, Key, IsChecked.HasValue && IsChecked.Value) { IsExpanded = IsExpanded, IsEnabled = IsEnabled, IsSelected = IsSelected }; PNUtils.SetIsResourceImage(pti, true); } else { pti = new PNTreeItem(Image, Text, Tag, Key, IsChecked.HasValue && IsChecked.Value) { IsExpanded = IsExpanded, IsEnabled = IsEnabled, IsSelected = IsSelected }; } foreach (var p in Items.OfType<PNTreeItem>()) { pti.Items.Add(p.Clone()); } return pti; }
private void loadGroups(PNGroup group, PNTreeItem local, bool byUser = false) { try { int count; switch (group.ID) { case (int)SpecialGroups.AllGroups: count = PNStatic.Notes.Count(nt => nt.GroupID != (int)SpecialGroups.RecycleBin); break; case (int)SpecialGroups.Favorites: count = PNStatic.Notes.Count(nt => nt.Favorite && nt.GroupID != (int)SpecialGroups.RecycleBin); break; case (int)SpecialGroups.Backup: var di = new DirectoryInfo(PNPaths.Instance.BackupDir); var fis = di.GetFiles("*" + PNStrings.NOTE_BACK_EXTENSION); count = fis.Count( f => PNStatic.Notes.Any( n => n.ID == Path.GetFileNameWithoutExtension(f.Name) .Substring(0, Path.GetFileNameWithoutExtension(f.Name).IndexOf('_')))); break; default: count = PNStatic.Notes.Count(nt => nt.GroupID == group.ID); break; } PNTreeItem pnTreeItem; if (group.IsDefaultImage) { pnTreeItem = group.PasswordString == "" ? new PNTreeItem(group.ImageName, group.Name + " (" + count + ")", group) { IsExpanded = true } : new PNTreeItem(group.ImageName, group.Name + " (" + count + ") ***", group) { IsExpanded = true }; } else { pnTreeItem = group.PasswordString == "" ? new PNTreeItem(group.Image, group.Name + " (" + count + ")", group) { IsExpanded = true } : new PNTreeItem(group.Image, group.Name + " (" + count + ") ***", group) { IsExpanded = true }; } foreach (var chg in group.Subgroups.OrderBy(g => g.Name)) { loadGroups(chg, pnTreeItem); } if (local == null) { _PGroups.Add(pnTreeItem); } else { if (!byUser) { local.Items.Add(pnTreeItem); } else { insertGroup(group, local, pnTreeItem); } } if (group.ID == PNStatic.Settings.Config.CPLastGroup) pnTreeItem.IsSelected = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private bool setSelectedSubGroup(PNTreeItem item) { try { var gr = item.Tag as PNGroup; if (gr != null && gr.ID == PNStatic.Settings.Config.CPLastGroup) { item.IsSelected = true; return true; } return item.Items.OfType<PNTreeItem>().Any(setSelectedSubGroup); } catch (Exception ex) { PNStatic.LogException(ex); return false; } }
private void groupsActionPasswordRemove() { try { _LastTreeItem = _RightSelectedItem ?? tvwGroups.SelectedItem as PNTreeItem; if (_LastTreeItem == null) return; var gr = _RightSelectedItem != null ? _RightSelectedItem.Tag as PNGroup : getSelectedGroup(); if (gr == null) return; var text = " [" + PNLang.Instance.GetCaptionText("group", "Group") + " \"" + gr.Name + "\"]"; var pwrdDelete = new WndPasswordDelete(PasswordDlgMode.DeleteGroup, text, gr.PasswordString) { Owner = this }; pwrdDelete.PasswordDeleted += pwrdDelete_PasswordDeleted; _SelectedGroup = gr.ID; var showDialog = pwrdDelete.ShowDialog(); if (showDialog == null || !showDialog.Value) { pwrdDelete.PasswordDeleted -= pwrdDelete_PasswordDeleted; } } catch (Exception ex) { PNStatic.LogException(ex); } finally { _LastTreeItem = null; _SelectedGroup = 0; } }
private bool changeNodeText(PNTreeItem node, int groupId) { try { var png = node.Tag as PNGroup; if (png == null) return false; if (png.ID == groupId) { var count = PNStatic.Notes.Count(n => n.GroupID == groupId); node.Text = png.Name; node.Text += @" (" + count + @")"; if (png.PasswordString.Trim().Length > 0) { node.Text += @" ***"; } return true; } if (png.ID == (int)SpecialGroups.AllGroups) { var count = PNStatic.Notes.Count(n => n.GroupID != (int)SpecialGroups.RecycleBin); node.Text = png.Name + @" (" + count + @")"; } return node.Items.OfType<PNTreeItem>().Any(n => changeNodeText(n, groupId)); } catch (Exception ex) { PNStatic.LogException(ex); return false; } }
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 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); } }
internal GroupChangedEventArgs(PNGroup group, AddEditMode mode, PNTreeItem treeItem) { Group = group; Mode = mode; TreeItem = treeItem; }
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); } }
private void setDefaultSkin(PNTreeItem node, string path) { try { foreach (var n in node.Items.OfType<PNTreeItem>()) { setDefaultSkin(n, path); } var gr = node.Tag as PNGroup; if (gr == null || gr.Skin.SkinName != PNSkinDetails.NO_SKIN) return; gr.Skin.SkinName = Path.GetFileNameWithoutExtension(path); PNSkinsOperations.LoadSkin(path, gr.Skin); } 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 cleanUpGroups(PNTreeItem node) { try { var group = node.Tag as PNGroup; if (group != null) { group.Dispose(); } foreach (var n in node.Items.OfType<PNTreeItem>()) { cleanUpGroups(n); } } 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); } }
private void fillGroups(bool firstTime = true) { try { _GroupsList.Clear(); var imageC = TryFindResource("contact") as BitmapImage;// new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "contact.png")); var imageG = TryFindResource("group") as BitmapImage;// new BitmapImage(new Uri(PNStrings.RESOURCE_PREFIX + "group.png")); var itNone = new PNTreeItem(imageG, PNLang.Instance.GetCaptionText("no_cont_group", PNStrings.NO_GROUP), -1); foreach (var cn in _Contacts.Where(c => c.GroupID == -1)) { itNone.Items.Add(new PNTreeItem(imageC, cn.Name, null)); } _GroupsList.Add(itNone); foreach (var gc in _Groups) { var id = gc.ID; var it = new PNTreeItem(imageG, gc.Name, id); foreach (var cn in _Contacts.Where(c => c.GroupID == id)) { it.Items.Add(new PNTreeItem(imageC, cn.Name, null)); } _GroupsList.Add(it); } if (firstTime) tvwContactsGroups.ItemsSource = _GroupsList; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void insertGroup(PNGroup group, PNTreeItem parentItem, PNTreeItem insertedItem) { try { var inserted = false; for (var i = 0; i < parentItem.Items.Count; i++) { var pni = parentItem.Items[i] as PNTreeItem; if (pni == null) continue; var gr = pni.Tag as PNGroup; if (gr == null) continue; if (string.CompareOrdinal(gr.Name, group.Name) > 0) { parentItem.Items.Insert(i, insertedItem); inserted = true; break; } } if (!inserted) { parentItem.Items.Add(insertedItem); } } catch (Exception ex) { PNStatic.LogException(ex); } }