/// ------------------------------------------------------------------------------------ /// <summary> /// Called from the TMAdapter when one of the view menu items is clicked. /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnSideBarViewTabItemMenuHandler(object args) { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null) { return(false); } SBTabItemProperties tabProps = itemProps.Tag as SBTabItemProperties; if (tabProps == null) { return(false); } string tabName = tabProps.OwningTabName; string itemName = tabProps.Name; SetCurrentTabItem(tabName, itemName, true); if (!((ButtonItem)m_navPane.Items[tabName]).Checked) { SetCurrentTab(tabName, true); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Tells the side bar adapter to setup it's menus so they show up on the application's /// view menu. This method should be called after all the tabs and tab items have been /// created. /// </summary> /// <param name="menuAdapter">Menu adapter used by the application.</param> /// <param name="insertBeforeItem">Name of the menu item before which the sidebar /// menus will be added.</param> /// ------------------------------------------------------------------------------------ public void SetupViewMenuForSideBarTabs(ITMAdapter adapter, string insertBeforeItem) { Debug.Assert(adapter != null); adapter.MessageMediator.AddColleague(this); foreach (SideBarTab tab in m_navPane.Items) { // Add the menu for the view tab. TMItemProperties props = tab.MenuItemProperties; props.Message = "SideBarViewTabMenuHandler"; adapter.AddMenuItem(props, null, insertBeforeItem); // Add menus for the view tab items. foreach (TMItemProperties itemProps in tab.SubMenuItemProperties) { itemProps.Text = itemProps.Text.Replace(Environment.NewLine, " "); itemProps.Message = "SideBarViewTabItemMenuHandler"; adapter.AddMenuItem(itemProps, tab.MenuItemProperties.Name, null); } // Add the menu item for the view tab's configure menu. SBTabProperties tabProps = tab.Properties; props = new TMItemProperties(); props.Name = tab.Name + "Config"; props.Text = tabProps.ConfigureMenuText; props.Message = tabProps.ConfigureMessage; props.BeginGroup = true; props.Tag = tabProps; adapter.AddMenuItem(props, tab.MenuItemProperties.Name, null); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Called from the TMAdapter when one of the view menu items needs to be updated. /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnUpdateSideBarViewTabItemMenuHandler(object args) { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null) { return(false); } SBTabItemProperties tabProps = itemProps.Tag as SBTabItemProperties; if (tabProps == null) { return(false); } SideBarTab tab = m_navPane.Items[tabProps.OwningTabName] as SideBarTab; if (tab == null) { return(false); } itemProps.Checked = (tab == CurrentTab && tab.CurrentItemProps.Name == itemProps.Name); itemProps.Update = true; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Called from the TMAdapter when one of the view menus needs to be updated. /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnUpdateSideBarViewTabMenuHandler(object args) { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null) { return(false); } itemProps.Update = true; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Called from the TMAdapter when one of the view menus needs to be updated. /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnUpdateSideBarViewTabMenuHandler(object args) { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null) { return(false); } itemProps.Enabled = m_navPane.Items[itemProps.Name].Enabled; itemProps.Update = true; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Called from the TMAdapter when one of the view menu items is clicked. /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnSideBarViewTabItemMenuHandler(object args) { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null) { return(false); } SBTabItemProperties tabProps = itemProps.Tag as SBTabItemProperties; if (tabProps == null) { return(false); } string tabName = tabProps.OwningTabName; string itemName = tabProps.Name; SetCurrentTabItem(tabName, itemName, true); return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected void GetWindowIndex(ToolStripItem item, TMItemProperties itemProps) { itemProps.Tag = (m_htWndListIndices[item] != null ? (int)m_htWndListIndices[item] : -1); }
private List<string> MakeSpellCheckMenuOptions(Point mousePos, RootSite rootsite, ITMAdapter tmAdapter, string menuName, string addToDictMenuName, string changeMultipleMenuName, string insertBeforeMenuName) { int hvoObj, tag, wsAlt, wsText; string word; ISpellEngine dict; bool nonSpellingError; ICollection<SpellCorrectMenuItem> suggestions = SpellCheckHelper.GetSuggestions(mousePos, rootsite, out hvoObj, out tag, out wsAlt, out wsText, out word, out dict, out nonSpellingError); IVwRootBox rootb = rootsite.RootBox; // These two menu items are disabled for non-spelling errors. In addition, for addToDict, we need // to set the tag to an AddToDictMenuItem which can actually do the work. UpdateItemProps(tmAdapter, addToDictMenuName, nonSpellingError, new AddToDictMenuItem(dict, word, rootb, hvoObj, tag, wsAlt, wsText, RootSiteStrings.ksAddToDictionary, Cache)); // any non-null value of tag will indicate the item should be enabled, tested in TeMainWnd.UpdateSpellingMenus. UpdateItemProps(tmAdapter, changeMultipleMenuName, nonSpellingError, "ok to change"); if (suggestions == null) return null; // Make the menu options. List<string> menuItemNames = new List<string>(); TMItemProperties itemProps; if (suggestions.Count == 0) { itemProps = new TMItemProperties(); itemProps.Name = "noSpellingSuggestion"; itemProps.Text = RootSiteStrings.ksNoSuggestions; itemProps.Enabled = false; menuItemNames.Add(itemProps.Name); tmAdapter.AddContextMenuItem(itemProps, menuName, insertBeforeMenuName); } int cSuggestions = 0; string additionalSuggestionsMenuName = "additionalSpellSuggestion"; foreach (SpellCorrectMenuItem scmi in suggestions) { itemProps = new TMItemProperties(); itemProps.Name = "spellSuggestion" + scmi.Text; itemProps.Text = scmi.Text; itemProps.Message = "SpellingSuggestionChosen"; itemProps.CommandId = "CmdSpellingSuggestionChosen"; itemProps.Tag = scmi; itemProps.Font = (wsText == 0) ? null : GetFontForNormalStyle(wsText, rootb.Stylesheet, rootb.DataAccess.WritingSystemFactory); if (cSuggestions++ == kMaxSpellingSuggestionsInRootMenu) { TMItemProperties tmpItemProps = new TMItemProperties(); tmpItemProps.Name = additionalSuggestionsMenuName; tmpItemProps.Text = RootSiteStrings.ksAdditionalSuggestions; menuItemNames.Add(tmpItemProps.Name); tmAdapter.AddContextMenuItem(tmpItemProps, menuName, insertBeforeMenuName); insertBeforeMenuName = null; } if (insertBeforeMenuName != null) { menuItemNames.Add(itemProps.Name); tmAdapter.AddContextMenuItem(itemProps, menuName, insertBeforeMenuName); } else { tmAdapter.AddContextMenuItem(itemProps, menuName, additionalSuggestionsMenuName, null); } } return menuItemNames; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method initializes a toolbar or menu item's properties. /// </summary> /// <param name="node"></param> /// <param name="item">Item to be initialized.</param> /// <param name="name"></param> /// <param name="isMenuItem"></param> /// ------------------------------------------------------------------------------------ private void InitItem(XmlNode node, ToolStripItem item, string name, bool isMenuItem) { string commandid = GetAttributeValue(node, "commandid"); item.Tag = commandid; item.Name = name; item.AccessibleName = name; TMItemProperties itemProps = new TMItemProperties(); itemProps.ParentForm = m_parentForm; itemProps.Name = name; itemProps.CommandId = commandid; itemProps.Enabled = true; itemProps.Visible = GetBoolFromAttribute(node, "visible", true); itemProps.BeginGroup = GetBoolFromAttribute(node, "begingroup", false); CommandInfo cmdInfo; if (m_commandInfo.TryGetValue(commandid, out cmdInfo)) { itemProps.Text = cmdInfo.Text; itemProps.Category = cmdInfo.Category; itemProps.Tooltip = cmdInfo.ToolTip; itemProps.Image = cmdInfo.Image; if (cmdInfo.ShortcutKey != Keys.None && isMenuItem && item is ToolStripMenuItem) ((ToolStripMenuItem)item).ShortcutKeys = cmdInfo.ShortcutKey; } if (GetBoolFromAttribute(node, "toolbarlist")) m_toolbarListItem = (item as ToolStripMenuItem); if (GetBoolFromAttribute(node, "windowlist")) m_windowListItem = (item as ToolStripMenuItem); if (GetBoolFromAttribute(node, "morewindowsitem")) m_moreWindowItem = (item as ToolStripMenuItem); ToolStripComboBox cboItem = item as ToolStripComboBox; if (cboItem != null) { cboItem.AccessibleRole = AccessibleRole.ComboBox; itemProps.Control = cboItem.ComboBox; } // Let the application have a stab at initializing the item. if (InitializeItem != null) InitializeItem(ref itemProps); // Save all initializatons by updating the item. itemProps.Update = true; SetItemProps(item, itemProps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is like choosing the Window/New Window menu item. /// </summary> /// ------------------------------------------------------------------------------------ public void CreateNewWindowCopy() { TMItemProperties itemProps = new TMItemProperties(); itemProps.ParentForm = this; OnNewWindow(itemProps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the items in the Items collection for a ComboBoxItem type toolbar item. /// </summary> /// <param name="item">The combo box item whose Items collection is be updated.</param> /// <param name="itemProps">The TMItemProperties containing the new property /// values for the toolbar item.</param> /// ------------------------------------------------------------------------------------ private void SetComboItemSpecificProperties(ComboBoxItem item, TMItemProperties itemProps) { if (item == null) return; // First check if the lists are the same. If they are we don't want to // go to the trouble of rebuilding the list, especially since that will // cause unnecessary flicker. if (itemProps.List != null && itemProps.List.Count == item.Items.Count) { bool fAreSame = true; for (int i = 0; i < item.Items.Count || !fAreSame; i++) fAreSame = (item.Items[i] == itemProps.List[i]); if (fAreSame) return; } item.Items.Clear(); // If there are item's in the list then upate the combobox item's // collection of items. if (itemProps.List != null && itemProps.List.Count > 0) { for (int i = 0; i < itemProps.List.Count; i++) item.Items.Add(itemProps.List[i]); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets some of a menu/toolbar item's properties. Note: if the Update property in the /// TMItemProperties object hasn't been set to true, no updating will occur. Items that /// can be set are: Text, Category, Tooltip, Enabled, Visible, BeginGroup, Checked, /// Image, List, Tag, and CommandId; /// </summary> /// <param name="item">The item whose properties are being updated.</param> /// <param name="itemProps">The TMItemProperties containing the new property /// values for the toolbar item.</param> /// ------------------------------------------------------------------------------------ private void SetItemProps(ToolStripItem item, TMItemProperties itemProps) { if (item == null || !itemProps.Update) return; if (item.Tag as string != itemProps.CommandId) { item.Tag = itemProps.CommandId; // Since we just changed the command ID, we should change the item's // image if it's a button item and the image isn't already being // specified in the item properties. if (itemProps.Image == null && item is ToolStripItem) { CommandInfo cmdInfo = GetCommandInfo(item); if (cmdInfo != null && cmdInfo.Image != null) item.Image = cmdInfo.Image; } } m_htItemTags[item] = itemProps.Tag; // Update all the changed fields only if necessary. if (item.Text != itemProps.Text) item.Text = itemProps.Text; if (itemProps.Font != null) item.Font = itemProps.Font; if (item.ToolTipText != itemProps.Tooltip) item.ToolTipText = itemProps.Tooltip; if (item.Enabled != itemProps.Enabled) item.Enabled = itemProps.Enabled; if (item.Visible != itemProps.Visible) item.Visible = itemProps.Visible; if (item.Image != itemProps.Image) item.Image = itemProps.Image; ToolStripItemExtender.SetBeginGroup(item, itemProps.BeginGroup); if (item is ToolStripButton && ((ToolStripButton)item).Checked != itemProps.Checked) ((ToolStripButton)item).Checked = itemProps.Checked; else if (item is ToolStripMenuItem && ((ToolStripMenuItem)item).Checked != itemProps.Checked) ((ToolStripMenuItem)item).Checked = itemProps.Checked; else if (item is CheckableSplitButton && ((CheckableSplitButton)item).Checked != itemProps.Checked) ((CheckableSplitButton)item).Checked = itemProps.Checked; if (item is ToolStripComboBox) SetComboItemSpecificProperties(item as ToolStripComboBox, itemProps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Display current book name in "First" and "Last" menus /// </summary> /// <param name="itemProps">The "first" or "Last" menu item</param> /// <param name="selLimitType">Determines whether the current book will be based /// on the top or the bottom of the current selection</param> /// ------------------------------------------------------------------------------------ private bool UpdateGoToFirstLast(TMItemProperties itemProps, SelectionHelper.SelLimitType selLimitType) { try { if (itemProps == null || ActiveEditingHelper == null || itemProps.ParentForm != this) return false; itemProps.Enabled = (m_bookFilter.BookCount > 0 && ActiveEditingHelper.CurrentSelection != null && ActiveEditingHelper.CurrentSelection.LevelInfo.Length > 0); string bookName = ActiveEditingHelper.CurrentBook(selLimitType); itemProps.Text = string.Format(itemProps.OriginalText, (bookName != null) ? bookName : string.Empty); itemProps.Update = true; return true; } catch { #if DEBUG throw; #else return false; // just ignore in release builds #endif } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new submenu item to the menu specified by parentItemName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new submenu item is added to the end of parentItemName's menu collection. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="parentItemName">Name of the menu item that will be added to.</param> /// <param name="insertBeforeItem">Name of the submenu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddMenuItem(TMItemProperties itemProps, string parentItemName, string insertBeforeItem) { // Check if the specified command Id is in our dictionary of commands. // If not, we need to add one for this item. if (!m_commandInfo.ContainsKey(itemProps.CommandId)) { // If there is no command Id, then assign a unique one. if (string.IsNullOrEmpty(itemProps.CommandId)) itemProps.CommandId = Guid.NewGuid().ToString(); CommandInfo ci = new CommandInfo(); ci.Image = itemProps.Image; ci.Message = itemProps.Message; ci.Text = itemProps.Text; ci.ToolTip = itemProps.Tooltip; ci.Category = itemProps.Category; m_commandInfo[itemProps.CommandId] = ci; } ToolStripMenuItem item = ToolStripItemExtender.CreateMenuItem(); item.Name = itemProps.Name; item.Tag = itemProps.CommandId; item.Click += HandleItemClicks; item.DropDown.Opening += HandleMenuOpening; item.DropDown.Opened += HandleMenuOpened; itemProps.Update = true; SetItemProps(item, itemProps); m_tmItems[item.Name] = item; // If an item to insert before isn't specified, then add the item to the // specified parent item. Otherwise, insert before "insertBeforeItem". if (insertBeforeItem == null || insertBeforeItem.Trim() == string.Empty) AddMenuItem(item, parentItemName); else InsertMenuItem(item, insertBeforeItem); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new menu item to a context menu specified by contextMenuName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new menu item is added to the end of parentItemName's menu collection. This /// overload allows new menu items to be added as submenus to menus at the top level /// of the context menu. The parentMenuName can be the name of a menu item at any /// level within the hierarchy of the menus on the context menu. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="contextMenuName">Name of the context menu to which the item is added. /// </param> /// <param name="parentMenuName">Name of the menu item in the context menu under which /// the new item is added.</param> /// <param name="insertBeforeItem">Name of the context menu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddContextMenuItem(TMItemProperties itemProps, string contextMenuName, string parentMenuName, string insertBeforeItem) { // First, make sure we can find the context menu to which the item will be added. ContextMenuStrip cmnu; if (!m_contextMenus.TryGetValue(contextMenuName, out cmnu)) return; object parentMenu = cmnu; // If the context menu name and the parent menu name are the same, then the new // item will be added to the context menu strip. Otherwise, it will be added to // a sub menu item that's already on the context menu strip. if (contextMenuName != parentMenuName) { // Get the menu under which the new menu item will be added. ToolStripItem[] items = cmnu.Items.Find(parentMenuName, true); Debug.Assert(items.Length == 1); Debug.Assert(items[0] is ToolStripDropDownItem); parentMenu = items[0]; } // Make the new item and set its properties. ToolStripMenuItem item = ToolStripItemExtender.CreateMenuItem(); item.Name = itemProps.Name; item.AccessibleName = itemProps.Name; item.Click += HandleItemClicks; item.DropDown.Opening += HandleMenuOpening; item.DropDown.Opened += HandleMenuOpened; itemProps.Update = true; SetItemProps(item, itemProps); m_tmItems[item.Name] = item; // If an item to insert before isn't specified, then add the item to the // parent item specified. Otherwise, insert before "insertBeforeItem". if (insertBeforeItem == null || insertBeforeItem.Trim() == string.Empty) { if (parentMenu == cmnu) cmnu.Items.Add(item); else ((ToolStripDropDownItem)parentMenu).DropDownItems.Add(item); return; } ToolStripItem beforeItem; if (m_tmItems.TryGetValue(insertBeforeItem, out beforeItem)) ToolStripItemExtender.InsertItemBefore(beforeItem, item); else { Debug.Fail("Failure trying to insert '" + item.Name + "' before '" + insertBeforeItem + "'."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add filters to the side bar /// </summary> /// ------------------------------------------------------------------------------------ protected virtual void AddFilters() { // Add defined filters to the filters submenu if (TMAdapter == null) return; foreach (ICmFilter filter in m_cache.LangProject.FiltersOC) { // only use filters that are defined for this application if (filter.App != TeApp.AppGuid) continue; switch (filter.ClassId) { case ScrBookTags.kClassId: { string filterName = string.Format( TeResourceHelper.GetResourceString("kstidFilterNameTemplate"), filter.Name); TMItemProperties itemProps = new TMItemProperties(); itemProps.Text = filterName; // setup the event handler for book filters itemProps.CommandId = "CmdBookFilterDlg"; TMAdapter.AddMenuItem(itemProps, "mnuFilters", null); break; } default: // ENHANCE: if other types of filters are needed, add handlers here break; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new menu item to a context menu specified by contextMenuName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new menu item is added to the end of parentItemName's menu collection. This /// overload allows new menu items to be added as submenus to menus at the top level /// of the context menu. The parentMenuName can be the name of a menu item at any /// level within the hierarchy of the menus on the context menu. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="contextMenuName">Name of the context menu to which the item is added. /// </param> /// <param name="parentMenuName">Name of the menu item in the context menu under which /// the new item is added.</param> /// <param name="insertBeforeItem">Name of the context menu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddContextMenuItem(TMItemProperties itemProps, string contextMenuName, string parentMenuName, string insertBeforeItem) { ButtonItem contextMenu = null; // First, make sure we can find the context menu to which the item will be added. int i = m_dnbMngr.ContextMenus.IndexOf(contextMenuName); if (i >= 0) contextMenu = m_dnbMngr.ContextMenus[i] as ButtonItem; if (i < 0 || contextMenu == null) return; SilButtonItem item = new SilButtonItem(); item.Name = itemProps.Name; itemProps.Update = true; SetItemProps(item, itemProps); // Get the menu under which the new menu item will be added. ButtonItem parentMenu = FindSubMenu(contextMenu, parentMenuName); Debug.Assert(parentMenu != null); if (parentMenu == null) return; // If an item to insert before isn't specified, then add the item to the item to the // parent item specified. Otherwise, insert before "insertBeforeItem". if (insertBeforeItem == null || insertBeforeItem.Trim() == string.Empty) parentMenu.SubItems.Add(item); else { i = parentMenu.SubItems.IndexOf(insertBeforeItem); if (i >= 0) parentMenu.SubItems.Insert(i, item); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Populate the InsertBook menus with the book names from the database. /// </summary> /// ------------------------------------------------------------------------------------ public void InitializeInsertBookMenus() { CheckDisposed(); TMItemProperties itemProps; for (int bookNum = 1; bookNum <= 66; bookNum++) { string bookName = ScriptureServices.GetUiBookName(bookNum); itemProps = new TMItemProperties(); itemProps.Text = bookName; itemProps.Name = "mnu" + bookName; itemProps.CommandId = "CmdInsertBook"; itemProps.Tag = bookNum; // Add books to the menu off the Insert main menu. (Matthew is 40); TMAdapter.AddMenuItem(itemProps, (bookNum < 40 ? "mnuOldTestament" : "mnuNewTestament"), null); // Add books to the context menu that pops-up by clicking the // Books button on the empty scripture dialog. (Matthew is 40); itemProps.Name = "c" + itemProps.Name; TMAdapter.AddContextMenuItem(itemProps, "cmnuInsertBooks", (bookNum < 40 ? "cmnuOldTestament" : "cmnuNewTestament"), null); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Helper method to determine if the spelling menu items should be visible. /// </summary> /// ------------------------------------------------------------------------------------ private bool UpdateSpellingMenus(TMItemProperties itemProps) { if (itemProps == null || EditingHelper == null) return false; itemProps.Update = true; // Strictly itemProps must be an AddToDictMenuItem for AddToDictionary. // For ChangeMultipleOccurrences, we just set it to something to indicate that the // command should be enabled. itemProps.Enabled = (itemProps.Tag != null); itemProps.Visible = ActiveEditingHelper.SpellCheckingStatus == RootSiteEditingHelper.SpellCheckStatus.Enabled; return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Populate the Insert Note menu with subitems for each type of note the user is /// allowed to create. /// </summary> /// <param name="args"></param> /// ------------------------------------------------------------------------------------ public bool OnUpdateInsertNoteParent(object args) { CheckDisposed(); try { TMItemProperties itemProps = args as TMItemProperties; if (itemProps == null || itemProps.ParentForm != this) return false; itemProps.Update = true; itemProps.Enabled = false; if (ActiveEditingHelper == null || ActiveEditingHelper.CurrentSelection == null || ActiveEditingHelper.CurrentSelection.LevelInfo.Length == 0) { return true; } ScrReference scrRef = ActiveEditingHelper.CurrentStartRef; // Don't allow inserting a note when the selection is not // in a valid book (e.g. when a picture is selected). if (scrRef == null || scrRef.Book <= 0) return true; bool fSubMenuAdded = false; TMAdapter.RemoveMenuSubItems("mnuInsertNote"); foreach (ICmAnnotationDefn subdfn in m_lp.ScriptureAnnotationDfns) { if (subdfn.UserCanCreate) { TMItemProperties noteItemProps = new TMItemProperties(); noteItemProps.Text = subdfn.Name.UserDefaultWritingSystem.Text; noteItemProps.Name = "mnu" + noteItemProps.Text.Replace(" ", string.Empty); noteItemProps.Enabled = true; noteItemProps.Visible = true; noteItemProps.CommandId = "CmdInsertNote"; noteItemProps.Tag = subdfn; TMAdapter.AddMenuItem(noteItemProps, "mnuInsertNote", null); fSubMenuAdded = true; // ENHANCE: Might need to create cascading submenus ad nauseum if the // subdefinitions have further subdefinitions. } } itemProps.Enabled = fSubMenuAdded; return true; } catch { #if DEBUG throw; #else return false; // just ignore in release builds #endif } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads a TMItemProperties object with several properties from a toolbar item. /// </summary> /// <param name="item">The item whose properties are being stored.</param> /// <returns>The properties of a menu or toolbar item.</returns> /// ------------------------------------------------------------------------------------ private TMItemProperties GetItemProps(ToolStripItem item) { TMItemProperties itemProps = new TMItemProperties(); // Set default values. itemProps.Update = false; itemProps.Name = string.Empty; itemProps.Text = string.Empty; itemProps.OriginalText = string.Empty; itemProps.Font = null; itemProps.Category = string.Empty; itemProps.Tooltip = string.Empty; itemProps.Enabled = false; itemProps.Visible = false; itemProps.Checked = false; itemProps.Image = null; itemProps.CommandId = null; itemProps.Control = null; itemProps.List = null; itemProps.ParentForm = m_parentForm; if (item == null) return itemProps; itemProps.Name = item.Name; itemProps.Text = item.Text; itemProps.CommandId = item.Tag as string; itemProps.Enabled = item.Enabled; itemProps.Visible = item.Visible; itemProps.IsDisplayed = item.Visible; itemProps.Image = item.Image; itemProps.Font = item.Font; itemProps.Tooltip = item.ToolTipText; itemProps.Tag = m_htItemTags[item]; itemProps.BeginGroup = ToolStripItemExtender.GetBeginGroup(item); CommandInfo cmdInfo = GetCommandInfo(item); if (cmdInfo != null) { if (cmdInfo.Message != null) itemProps.Message = cmdInfo.Message; if (cmdInfo.Text != null) itemProps.OriginalText = cmdInfo.Text; } if (item is ToolStripButton) itemProps.Checked = ((ToolStripButton)item).Checked; else if (item is ToolStripMenuItem) itemProps.Checked = ((ToolStripMenuItem)item).Checked; else if (item is CheckableSplitButton) itemProps.Checked = ((CheckableSplitButton)item).Checked; else if (item is ToolStripComboBox) { ToolStripComboBox cboItem = item as ToolStripComboBox; itemProps.Control = cboItem.ComboBox; if (cboItem.Items.Count > 0) { // Get all the combo items and save in the List property. itemProps.List = new ArrayList(); for (int i = 0; i < cboItem.Items.Count; i++) itemProps.List.Add(cboItem.Items[i]); } } else if (item is ToolStripControlHost) itemProps.Control = ((ToolStripControlHost)item).Control; //REVIEW: should this return null if item is null? return itemProps; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new submenu item to the menu specified by parentItemName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new submenu item is added to the end of parentItemName's menu collection. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="parentItemName">Name of the menu item that will be added to.</param> /// <param name="insertBeforeItem">Name of the submenu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddMenuItem(TMItemProperties itemProps, string parentItemName, string insertBeforeItem) { SilButtonItem item = new SilButtonItem(); item.Name = itemProps.Name; itemProps.Update = true; SetItemProps(item, itemProps); // If an item to insert before isn't specified, then add the item to the item to the // parent item specified. Otherwise, insert before "insertBeforeItem". if (insertBeforeItem == null || insertBeforeItem.Trim() == string.Empty) AddMenuItem(item, parentItemName); else InsertMenuItem(item, insertBeforeItem, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets some of a toolbar item's properties. Note: if the Update property in the /// TMItemProperties object hasn't been set to true, no updating will occur. /// </summary> /// <param name="name">Name of item whose properties are being updated.</param> /// <param name="itemProps">The TMItemProperties containing the new property /// values for the toolbar item.</param> /// ------------------------------------------------------------------------------------ public void SetItemProperties(string name, TMItemProperties itemProps) { ToolStripItem item; if (m_tmItems.TryGetValue(name, out item)) SetItemProps(item, itemProps); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Dispose managed resources here. if (m_mainWnd != null) m_mainWnd.Dispose(); if (m_dummyItemProps != null) m_dummyItemProps.ParentForm = null; } // Dispose unmanaged resources here, whether disposing is true or false. m_mainWnd = null; m_dummyItemProps = null; // TMItemProperties should implement IDisposable. base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the items in the Items collection for a ComboBoxItem type toolbar item. /// </summary> /// <param name="item">The combo box item whose Items collection is be updated.</param> /// <param name="itemProps">The TMItemProperties containing the new property /// values for the toolbar item.</param> /// ------------------------------------------------------------------------------------ private void SetComboItemSpecificProperties(ToolStripComboBox cbo, TMItemProperties itemProps) { // First check if the lists are the same. If they are we don't want to // go to the trouble of rebuilding the list, especially since that will // cause unnecessary flicker. int maxStringLength = 0; int factor = 6; if (itemProps.List != null && itemProps.List.Count == cbo.Items.Count) { bool fAreSame = true; for (int i = 0; i < cbo.Items.Count || !fAreSame; i++) { if (cbo.Items[i].ToString().Length > maxStringLength) { maxStringLength = cbo.Items[i].ToString().Length; } fAreSame = (cbo.Items[i] == itemProps.List[i]); } if (maxStringLength > 0 && cbo.DropDownWidth < maxStringLength * factor) cbo.DropDownWidth = maxStringLength * factor; if (fAreSame) return; } cbo.Items.Clear(); // If there are item's in the list then upate the combobox item's // collection of items. if (itemProps.List != null && itemProps.List.Count > 0) { for (int i = 0; i < itemProps.List.Count; i++) cbo.Items.Add(itemProps.List[i]); } //Set the DropDownWidth of the combo box so that is is wide enough to show //the text of all items in the list. maxStringLength = 0; for (int i = 0; i < cbo.Items.Count; i++) { if (cbo.Items[i].ToString().Length > maxStringLength) { maxStringLength = cbo.Items[i].ToString().Length; } } if (maxStringLength > 0 && cbo.DropDownWidth < maxStringLength * factor) cbo.DropDownWidth = maxStringLength * factor; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the enabled status of sub items in the GoTo menus. /// </summary> /// <param name="itemProps">The item props.</param> /// <param name="fSelectionRequired">if set to <c>true</c> selection is required in /// order for this command to be enabled.</param> /// <returns>true if handled</returns> /// ------------------------------------------------------------------------------------ public bool UpdateGoToSubItems(TMItemProperties itemProps, bool fSelectionRequired) { try { if (itemProps == null) return false; itemProps.Update = true; if (m_bookFilter.BookCount > 0 && ActiveEditingHelper != null) { if (fSelectionRequired) { itemProps.Enabled = ActiveEditingHelper.CurrentSelection != null && ActiveEditingHelper.CurrentSelection.LevelInfo.Length > 0; } else itemProps.Enabled = true; } else itemProps.Enabled = false; return true; } catch { #if DEBUG throw; #else return false; // just ignore in release builds #endif } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a new menu item to a context menu specified by contextMenuName and inserts it /// before the item specified by insertBeforeItem. If insertBeforeItem is null, then /// the new menu item is added to the end of parentItemName's menu collection. /// </summary> /// <param name="itemProps">Properties of the new menu item.</param> /// <param name="contextMenuName">Name of the context menu to which the item is added. /// </param> /// <param name="insertBeforeItem">Name of the context menu item before which the new /// menu item will be added.</param> /// ------------------------------------------------------------------------------------ public void AddContextMenuItem(TMItemProperties itemProps, string contextMenuName, string insertBeforeItem) { AddContextMenuItem(itemProps, contextMenuName, contextMenuName, insertBeforeItem); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates any of the Edit/Find,replace menu items based on the selected view /// </summary> /// <param name="itemProps">The item props.</param> /// ------------------------------------------------------------------------------------ private bool UpdateFindReplaceMenuItem(TMItemProperties itemProps) { if (itemProps != null) { itemProps.Update = true; itemProps.Enabled = false; } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the specified Keys is a shortcut for a toolbar or menu item. /// </summary> /// <param name="key">The key.</param> /// <param name="isItemEnabled"><c>true</c> when the specified key is a shortcut key /// and its associated toolbar or menu item is enabled.</param> /// <returns> /// <c>true</c> if the specified key is a shortcut for a toolbar or menu item; /// otherwise, <c>false</c>. /// </returns> /// ------------------------------------------------------------------------------------ public bool IsShortcutKey(Keys key, ref bool isItemEnabled) { isItemEnabled = false; foreach (CommandInfo cmdInfo in m_commandInfo.Values) { if (cmdInfo.ShortcutKey == key) { // Call update method (e.g. OnUpdateEditCopy). If that method doesn't exist or // if all update methods return false, we check for the existence of the // command handler. TMItemProperties itemProps = new TMItemProperties(); itemProps.Message = cmdInfo.Message; itemProps.ParentForm = m_parentForm; itemProps.Text = cmdInfo.Text; m_msgMediator.SendMessage("Update" + cmdInfo.Message, itemProps); isItemEnabled = itemProps.Enabled; return true; } } return false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine whether or not the specified context menu is visible for the specified /// check. /// </summary> /// ------------------------------------------------------------------------------------ protected bool UpdateCheckContextMenu(TMItemProperties itemProps, Guid checkId) { if (itemProps == null) return false; ScrChkTreeNode node = m_availableChecksTree.SelectedNode as ScrChkTreeNode; itemProps.Visible = (node != null && node.ScrCheck.CheckId == checkId); itemProps.Enabled = true; itemProps.Update = true; return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the tool strip button with the specified item properties. The msgId is used /// for the name and the button's click event uses that name as the message to send. /// </summary> /// ------------------------------------------------------------------------------------ private void AddToolStripButton(TMItemProperties itemProps, string msgId) { if (itemProps == null) return; AddToolStripButton(0, itemProps.Image, itemProps.Tooltip); m_ToolStrip.Items[0].Name = msgId; m_ToolStrip.Items[0].Tag = itemProps; if (m_tmAdapter.MessageMediator != null) { m_ToolStrip.Items[0].Click += delegate(object sender, EventArgs e) { ToolStripButton button = sender as ToolStripButton; if (button != null && button.Tag is TMItemProperties) m_tmAdapter.MessageMediator.SendMessage(button.Name, button.Tag); }; } }
public override void FixtureSetup() { CheckDisposed(); base.FixtureSetup(); m_dummyItemProps = new TMItemProperties(); Debug.Assert(m_mainWnd == null, "m_mainWnd is not null."); //if (m_mainWnd != null) // m_mainWnd.Dispose(); m_mainWnd = new InvisibleTeMainWnd(); m_dummyItemProps.ParentForm = m_mainWnd; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine if the given menu item should be enabled, based on whether there is a /// valid view and constructed rootbox. /// </summary> /// <param name="itemProps">The menu item properties</param> /// <returns><c>true</c> if a valid menu item</returns> /// ------------------------------------------------------------------------------------ private bool UpdateMenuRequiringValidView(TMItemProperties itemProps) { if (itemProps == null) return false; RootSite rs = ActiveView as RootSite; bool enable = (rs != null && rs.RootBox != null); if (itemProps.Enabled != enable) { itemProps.Update = true; itemProps.Enabled = enable; } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public void UpdateZoom() { TMItemProperties itemProps = new TMItemProperties(); base.OnUpdateViewZoom(itemProps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the properties for a ButtonItem type toolbar button. /// </summary> /// <param name="item">The item whose properties are being updated.</param> /// <param name="itemProps">The TMItemProperties containing the new property /// values for the toolbar item.</param> /// ------------------------------------------------------------------------------------ private void SetButtonItemSpecificProperties(ButtonItem item, TMItemProperties itemProps) { if (item == null) return; if (item.Checked != itemProps.Checked) item.Checked = itemProps.Checked; if (itemProps.Image != item.Image && itemProps.Image != null) item.Image = itemProps.Image; }