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 static void prepareSubitem(IEnumerable <Tuple <string, string, int> > tableList, MenuItem parentItem, PNMenu parentPNItem, string context) { try { if (!parentItem.HasItems) { return; } var arr = parentItem.Items.Cast <Control>().ToArray(); var enumerable = tableList as Tuple <string, string, int>[] ?? tableList.ToArray(); var tuples = tableList as Tuple <string, string, int>[] ?? enumerable.ToArray(); var topItems = tuples.Where(tp => tp.Item2 == parentItem.Name).OrderBy(tp => tp.Item3); foreach (var tp in topItems) { var si = arr.FirstOrDefault(a => a.Name == tp.Item1); if (si == null) { continue; } if (si.GetType() != typeof(MenuItem) && si.GetType() != typeof(Separator)) { continue; } var pmi = new PNMenu(si.Name, si.GetType() == typeof(MenuItem) ? ((MenuItem)si).Header.ToString() : PNStrings.MENU_SEPARATOR_STRING, parentPNItem.Name, context); parentPNItem.Items.Add(pmi); var psi = si as MenuItem; if (psi != null) { prepareSubitem(enumerable, psi, pmi, context); } } } 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); } }
internal static void PrepareDefaultMenuStrip(ContextMenu source, MenuType type, bool forCurrent) { try { List <PNMenu> menuItems; if (forCurrent) { switch (type) { case MenuType.Main: menuItems = CurrentMainMenus; break; case MenuType.Edit: menuItems = CurrentEditMenus; break; case MenuType.Note: menuItems = CurrentNoteMenus; break; case MenuType.ControlPanel: menuItems = CurrentCPMenus; break; default: return; } } else { switch (type) { case MenuType.Main: menuItems = DefaultMainMenus; break; case MenuType.Edit: menuItems = DefaultEditMenus; break; case MenuType.Note: menuItems = DefaultNoteMenus; break; case MenuType.ControlPanel: menuItems = DefaultCPMenus; break; default: return; } } menuItems.Clear(); var arr = source.Items.Cast <Control>().ToArray(); var tableList = new List <Tuple <string, string, int> >(); using (var oData = new SQLiteDataObject(PNData.ConnectionString)) { var sb = new StringBuilder("SELECT MENU_NAME, "); sb.Append(forCurrent ? "ORDER_NEW" : "ORDER_ORIGINAL"); sb.Append(", IFNULL(PARENT_NAME, '') AS PARENT_NAME FROM MENUS_ORDER WHERE CONTEXT_NAME = '"); sb.Append(source.Name); sb.Append("' ORDER BY "); sb.Append(forCurrent ? "ORDER_NEW" : "ORDER_ORIGINAL"); using (var t = oData.FillDataTable(sb.ToString())) { if (forCurrent) { tableList.AddRange(from DataRow r in t.Rows select Tuple.Create(Convert.ToString(r["MENU_NAME"]), Convert.ToString(r["PARENT_NAME"]), Convert.ToInt32(r["ORDER_NEW"]))); } else { tableList.AddRange(from DataRow r in t.Rows select Tuple.Create(Convert.ToString(r["MENU_NAME"]), Convert.ToString(r["PARENT_NAME"]), Convert.ToInt32(r["ORDER_ORIGINAL"]))); } var topItems = tableList.Where(tp => tp.Item2 == ""); foreach (var tp in topItems) { var si = arr.FirstOrDefault(a => a.Name == tp.Item1); if (si == null) { continue; } var pmi = new PNMenu(si.Name, si.GetType() == typeof(MenuItem) ?((MenuItem)si).Header.ToString() : PNStrings.MENU_SEPARATOR_STRING, "", source.Name); menuItems.Add(pmi); var psi = si as MenuItem; if (psi != null) { prepareSubitem(tableList, psi, pmi, source.Name); } } } } } catch (Exception ex) { PNStatic.LogException(ex); } }