Beispiel #1
0
        /// <summary>
        /// An INIReader that reads lines from a streams file
        /// adding sections and key=value pairs to a context menu
        /// as submenus and clickable items.
        /// </summary>
        public StreamsFileReader()
        {
            file = null;
            menu = null;
            onClick = null;

            currentMenuItems = null;
            seenSubmenues = new Dictionary<String, MenuItem>();

            currentLineNumber = 0;
            currentLine = String.Empty;
        }
Beispiel #2
0
        /// <summary>
        /// Read a streams file adding submenus items to a context menu.
        /// </summary>
        /// <param name="file">Streams file to read lines from.</param>
        /// <param name="menu">Target context menu.</param>
        /// <param name="onClick">Click event to attach to menu items.</param>
        public void Read(StreamsFile file, ContextMenu menu, EventHandler onClick)
        {
            this.file = file;
            this.menu = menu;
            this.onClick = onClick;

            // start at root:
            currentMenuItems = menu.MenuItems;

            try
            {
                foreach (String line in file.ReadLines())
                {
                    currentLineNumber++;
                    currentLine = line;
                    ReadLine(line);
                }
            }
            finally
            {
                ResetState();
            }
        }
Beispiel #3
0
        public void MenuItemCollection_Insert_IListInvoke_Success()
        {
            var   menu       = new SubMenu(new MenuItem[0]);
            IList collection = new Menu.MenuItemCollection(menu);

            var menuItem1 = new MenuItem("text1");

            collection.Insert(0, menuItem1);
            Assert.Same(menuItem1, Assert.Single(collection));
            Assert.Equal(menu, menuItem1.Parent);
            Assert.Equal(0, menuItem1.Index);

            var menuItem2 = new MenuItem("text1");

            collection.Insert(0, menuItem2);
            Assert.Equal(2, collection.Count);
            Assert.Same(menuItem2, collection[0]);
            Assert.Same(menuItem1, collection[1]);
            Assert.Equal(menu, menuItem1.Parent);
            Assert.Equal(1, menuItem1.Index);
            Assert.Equal(menu, menuItem2.Parent);
            Assert.Equal(0, menuItem2.Index);
        }
Beispiel #4
0
        public void MenuItemCollection_Add_IndexMenuItem_Success()
        {
            var menu       = new SubMenu(new MenuItem[0]);
            var collection = new Menu.MenuItemCollection(menu);

            var menuItem1 = new MenuItem("text1");

            Assert.Equal(0, collection.Add(0, menuItem1));
            Assert.Same(menuItem1, Assert.Single(collection));
            Assert.Equal(menu, menuItem1.Parent);
            Assert.Equal(0, menuItem1.Index);

            var menuItem2 = new MenuItem("text1");

            Assert.Equal(0, collection.Add(0, menuItem2));
            Assert.Equal(2, collection.Count);
            Assert.Same(menuItem2, collection[0]);
            Assert.Same(menuItem1, collection[1]);
            Assert.Equal(menu, menuItem1.Parent);
            Assert.Equal(1, menuItem1.Index);
            Assert.Equal(menu, menuItem2.Parent);
            Assert.Equal(0, menuItem2.Index);
        }
Beispiel #5
0
        /* ****************************************************
         *	I need a search function to modify a NiceMenu item
         *  at runtime
         * ****************************************************/
        public NiceMenu SearchNiceMenuItem(string NiceMenuText, int nNo)
        {
            contModify = 0;
            int nCount =1;
            repeat:
                IList myMenuList = new Menu.MenuItemCollection(myModifyNiceMenu[contModify]);
            foreach (NiceMenu myMenuItem in myMenuList)
            {
                // ---------------------------------------
                if (myMenuItem.Text == NiceMenuText)
                {
                    if((nCount-1) == nNo)
                        return myMenuItem;

                    nCount++;

                }
                // ---------------------------------------
                if (myMenuItem.IsParent == true)
                {
                    IList myMenuList2 = new Menu.MenuItemCollection(myMenuItem);
                    foreach (NiceMenu myMenuItem2 in myMenuList2)
                    {
                        // --------------------------------
                        if (myMenuItem2.Text == NiceMenuText)
                        {
                            if(nCount == nNo)
                                return myMenuItem2;

                            nCount++;
                            contModify++;

                        }
                    }
                }
            }
            contModify++;
            goto repeat;
        }
Beispiel #6
0
 /* ****************************************************
  *	I need a search function to modify a NiceMenu item
  *  at runtime (for Context menu)
  * ****************************************************/
 public NiceMenu SearchContextNiceMenuItem(string ContextNiceMenuText)
 {
     contModifyContext = 0;
     repeat:
     // ---------------------------------------
         if (myModifyContextNiceMenu[contModifyContext].Text
             == ContextNiceMenuText)
         {
             return myModifyContextNiceMenu[contModifyContext];
         }
     // --------------------------------------------
     IList myMenuList = new Menu.MenuItemCollection(myModifyContextNiceMenu[contModifyContext]);
     foreach (NiceMenu myMenuItem in myMenuList)
     {
         if (myMenuItem.Text == ContextNiceMenuText)
         {
             contModifyContext++;
             return myMenuItem;
         }
     }
     contModifyContext++;
     goto repeat;
 }
Beispiel #7
0
 /// <summary>
 /// On an empty line, go back to the menu root.
 /// </summary>
 protected override void OnEmpty()
 {
     currentMenuItems = menu.MenuItems;
 }
Beispiel #8
0
        public DynamicMenuBuilder(MainMenu aMainMenu, MenuItem aParent, MenuItem aBefore, MenuItem aAfter)
        {
            if (aParent != null)
              {
            mParent = aParent;
            mParentItems = aParent.MenuItems;
              }
              else
            mParentItems = aMainMenu.MenuItems;

              // XXX we do jack shit to handle this at the moment. TBD.
              mBefore = aBefore;
              mAfter = aAfter;

              ResetInsertionPoint();

              InitializeComponent();
        }
Beispiel #9
0
        /* ****************************************************
         *	With the context menu I need the yourClickFunction
         *	because also the main menu shall be clickable !
         * ****************************************************/
        private void BuildMenuTree(IList myMenu, ContextMenu parentMenu, NiceMenuClickEvent yourClickFunction)
        {
            int numOldMenu = myMenu.Count;

            foreach (MenuItem myMenuItem in myMenu)
            {
                // Declaration
                NiceMenu newMainMenu;

                string IndexImage = "";
                bool AddMenuImage = false;

                /* If in the first two characters of the menu item text
                 * there is a number I set AddMenuImage = true and the
                 * IndexImage to get the icon in the image list control. */
                if (myMenuItem.Text.Length > 2)
                {
                    IndexImage = myMenuItem.Text.Substring(0,2);
                    if (Char.IsNumber(IndexImage,1) == true)
                    {
                        AddMenuImage = true;
                        // I have to delete first two characters
                        myMenuItem.Text = myMenuItem.Text.Substring(2);
                    }
                }
                if (AddMenuImage == true)
                    newMainMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut, MenuImages.Images[Convert.ToInt32(IndexImage)]);
                else
                    newMainMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut);

                parentMenu.MenuItems.Add(newMainMenu);

                if (myModifyContextNiceMenu[contModifyContext] == null)
                {
                    myModifyContextNiceMenu[contModifyContext] = newMainMenu;
                    contModifyContext ++;
                }

                if (myMenuItem.IsParent == true)
                {
                    IList mySubMenu = new Menu.MenuItemCollection(myMenuItem);
                    BuildMenuTree(mySubMenu, newMainMenu, yourClickFunction);
                }
            }
            // Now I have to delete the old menus
            for (int i=0;i<numOldMenu;i++)
            {   parentMenu.MenuItems.RemoveAt(0);   }
        }
Beispiel #10
0
        /* ***********************************************************
         *		BuildMenuTree (IList myMenu, MenuItem parentMenu)
         * -----------------------------------------------------------
         *		build the new submenu item
         * ***********************************************************/
        private void BuildMenuTree(IList myMenu, MenuItem parentMenu, NiceMenuClickEvent yourClickFunction)
        {
            foreach (MenuItem myMenuItem in myMenu)
            {
                // Declaration
                NiceMenu newSubMenu;

                string IndexImage = "";
                bool AddMenuImage = false;

                /* If in the first two characters of the menu item text
                 * there is a number I set AddMenuImage = true and the
                 * IndexImage to get the icon in the image list control. */
                if (myMenuItem.Text.Length > 2)
                {
                    IndexImage = myMenuItem.Text.Substring(0,2);
                    if (Char.IsNumber(IndexImage,1) == true)
                    {
                        AddMenuImage = true;
                        // I have to delete first two characters
                        myMenuItem.Text = myMenuItem.Text.Substring(2);
                    }
                }
                if (AddMenuImage == true)
                    newSubMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut, MenuImages.Images[Convert.ToInt32(IndexImage)]);
                else
                    newSubMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut);
                // I add the new menu item to its parent
                parentMenu.MenuItems.Add(newSubMenu);
                // Checked
                if (myMenuItem.Checked == true) newSubMenu.Checked = true;
                // RadioCheck
                if (myMenuItem.RadioCheck == true)
                    if (myMenuItem.Checked == true) newSubMenu.RadioCheck = true;
                // DefaultItem
                if (myMenuItem.DefaultItem == true) newSubMenu.DefaultItem = true;
                // Enabled
                if (myMenuItem.Enabled == false) newSubMenu.Enabled = false;
                // If this menu item contains child menu items
                if (myMenuItem.IsParent == true)
                {
                    IList mySubMenu = new Menu.MenuItemCollection(myMenuItem);
                    BuildMenuTree(mySubMenu, newSubMenu, yourClickFunction);
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// On a new section, go back to the menu root.
 /// </summary>
 protected override void OnSection(String section)
 {
     currentMenuItems = menu.MenuItems;
 }
Beispiel #12
0
        public void MenuItemCollection_IndexOf_IListInvoke_ReturnsExpected(Menu menu, MenuItem value, int expected)
        {
            IList collection = new Menu.MenuItemCollection(menu);

            Assert.Equal(expected, collection.IndexOf(value));
        }
Beispiel #13
0
        public void MenuItemCollection_Contains_IListInvoke_ReturnsExpected(Menu menu, MenuItem value, bool expected)
        {
            IList collection = new Menu.MenuItemCollection(menu);

            Assert.Equal(expected, collection.Contains(value));
        }
 private void SetupContextMenu()
 {
     this.rclick = new System.Windows.Forms.ContextMenu();
     Menu.MenuItemCollection items = new Menu.MenuItemCollection(rclick);
     this.rclick.MenuItems.Add(new MenuItem("Copy color to clipboard"));
     this.rclick.MenuItems[0].Enabled = false;
     this.rclick.MenuItems.Add(new MenuItem("...as R,G,B", this.CopyRGB));
     this.rclick.MenuItems.Add(new MenuItem("...as #HEX", this.CopyHex));
 }
Beispiel #15
0
 public NiceMenu SearchNiceMenuItem(string NiceMenuText)
 {
     contModify = 0;
     repeat:
     IList myMenuList = new Menu.MenuItemCollection(myModifyNiceMenu[contModify]);
     foreach (NiceMenu myMenuItem in myMenuList)
     {
         // ---------------------------------------
         if (myMenuItem.Text == NiceMenuText)
         {
             return myMenuItem;
         }
         // ---------------------------------------
         if (myMenuItem.IsParent == true)
         {
             IList myMenuList2 = new Menu.MenuItemCollection(myMenuItem);
             foreach (NiceMenu myMenuItem2 in myMenuList2)
             {
                 // --------------------------------
                 if (myMenuItem2.Text == NiceMenuText)
                 {
                     contModify++;
                     return myMenuItem2;
                 }
             }
         }
     }
     contModify++;
     goto repeat;
 }
Beispiel #16
0
 /// <summary>
 /// this function will update your Context Menu.
 /// </summary>
 public void UpdateMenu(ContextMenu yourOldMenu, NiceMenuClickEvent yourClickFunction)
 {
     IList myMenuList = new Menu.MenuItemCollection(yourOldMenu);
     BuildMenuTree(myMenuList, yourOldMenu, yourClickFunction);
 }
Beispiel #17
0
        /// <summary>
        /// Add subsections as submenus and descend into them.
        /// </summary>
        protected override void OnSubSection(String subsection, String path)
        {
            MenuItem submenu;
            seenSubmenues.TryGetValue(path, out submenu);

            // not seen, create and add to the current menu
            // otherwise it's a duplicate and has already been added:
            if (submenu == null)
            {
                submenu = new MenuItem(subsection);
                seenSubmenues.Add(path, submenu);
                currentMenuItems.Add(submenu);
            }

            currentMenuItems = submenu.MenuItems;
        }
Beispiel #18
0
        /* ***********************************************************
         *	BuildMenuTree (IList myMenu, MainMenu parentMenu)
         *  BuildMenuTree (IList myMenu, ContextMenu parentMenu, NiceMenuClickEvent yourClickFunction)
         * -----------------------------------------------------------
         *  build the new main menus and delete the old ones
         * ***********************************************************/
        private void BuildMenuTree(IList myMenu, MainMenu parentMenu, NiceMenuClickEvent yourClickFunction)
        {
            int numOldMenu = myMenu.Count;

            foreach (MenuItem myMenuItem in myMenu)
            {
                NiceMenu newMainMenu = new NiceMenu(myMenuItem.Text);
                parentMenu.MenuItems.Add(newMainMenu);

                if (myModifyNiceMenu[contModify] == null)
                {
                    myModifyNiceMenu[contModify] = newMainMenu;
                    contModify ++;
                }

                if (myMenuItem.IsParent == true)
                {
                    IList mySubMenu = new Menu.MenuItemCollection(myMenuItem);
                    BuildMenuTree(mySubMenu, newMainMenu, yourClickFunction);
                }
            }
            // Now I have to delete the old menus
            for (int i=0;i<numOldMenu;i++)
            {   parentMenu.MenuItems.RemoveAt(0);   }
        }
Beispiel #19
0
        /// <summary>
        /// Clear internal state.
        /// </summary>
        private void ResetState()
        {
            file = null;
            menu = null;
            onClick = null;

            currentMenuItems = null;
            seenSubmenues.Clear();

            currentLineNumber = 0;
            currentLine = String.Empty;
        }
Beispiel #20
0
 private void m_CreateMenuInfo(Menu owner)
 {
     m_Language = m_GetLanguageFromCulture(HathiForm.preferences.GetString("Language"));
     m_ShowAllLanguage = HathiForm.preferences.GetBool("ShowAllLanguages",true);
     m_Owner = owner;
     Actions=new Hashtable();
     MenuItems=new Menu.MenuItemCollection(owner);
     MenuItem menu;
     try
     {
     ShowAllLanguageMenuItem = new MenuItem(HathiForm.Globalization["LBL_SHOW_ALL_LANGUAGES"],new EventHandler(ShowAllLanguageMenuItem_Click));
     ShowAllLanguageMenuItem.DefaultItem = true;
     ShowAllLanguageMenuItem.Checked = m_ShowAllLanguage;
     MenuItems.Add(ShowAllLanguageMenuItem);
     menu=new MenuItem("-");
     MenuItems.Add(menu);
     XmlDocument doc = new XmlDocument();
     doc.Load(Application.StartupPath + Path.DirectorySeparatorChar + "webSearchs.xml");
     XmlNodeList nodes = doc.DocumentElement["Searchs"].ChildNodes;
     foreach (XmlElement el in nodes)
     {
         if (el.Name=="Search")
         {
             if ((el.Attributes.Count>2) &&
                     (el.Attributes["SiteName"].InnerText!="")&&
                     (el.Attributes["URL"].InnerText!="")&&
                     (el.Attributes["Language"].InnerText!=""))
             {
                 String NodeLanguage = el.Attributes["Language"].InnerText;
                 if (!m_ShowAllLanguage && NodeLanguage!=m_Language && NodeLanguage!="All")
                 {
                     m_DisplayBar = false;
                 }
                 else
                 {
                     m_DisplayBar = true;
                     menu=new MenuItem(el.Attributes["SiteName"].InnerText+"\t("+el.Attributes["Language"].InnerText+")",new EventHandler(OnItemClicked));
                     MenuItems.Add(menu);
                     Actions.Add(menu,el.Attributes["URL"].InnerText);
                 }
             } else if (m_DisplayBar && el.Attributes["SiteName"].InnerText=="-")
             {
                 menu=new MenuItem("-");
                 MenuItems.Add(menu);
             }
         }
     }
     if (MenuItems[MenuItems.Count-1].Text=="-") MenuItems.RemoveAt(MenuItems.Count-1);
     }
     catch (Exception e)
     {
     Debug.WriteLine(e.ToString());
     }
 }
Beispiel #21
0
        public DynamicMenuBuilder(MainMenu aMainMenu, MenuItem aParent)
        {
            if (aParent != null)
              {
            mParent = aParent;
            mParentItems = aParent.MenuItems;
              }
              else
            mParentItems = aMainMenu.MenuItems;

              InitializeComponent();
        }