コード例 #1
0
ファイル: ICommandService.cs プロジェクト: vincenthamm/ATF
 /// <summary>
 /// Registers a menu for the application</summary>
 /// <param name="commandService">Command service</param>
 /// <param name="menuTag">Menu's unique ID</param>
 /// <param name="menuText">Menu text</param>
 /// <param name="description">Menu description</param>
 /// <returns>MenuInfo object describing menu</returns>
 public static MenuInfo RegisterMenu(
     this ICommandService commandService, object menuTag, string menuText, string description)
 {
     MenuInfo info = new MenuInfo(menuTag, menuText, description);
     commandService.RegisterMenu(info);
     return info;
 }
コード例 #2
0
ファイル: CommandService.cs プロジェクト: Joxx0r/ATF
        protected override sealed void RegisterMenuInfo(MenuInfo info)
        {
            base.RegisterMenuInfo(info);

            // Add an IToolBar to composition
            if (m_composer != null)
                ExportMenuModel(info);
        }
コード例 #3
0
ファイル: CommandServiceBase.cs プロジェクト: Optis-World/ATF
        /// <summary>
        /// Registers menu info</summary>
        /// <param name="info">MenuInfo to register</param>
        /// <remarks>Adds this MenuInfo object to m_menus field and creates a tool strip for it.
        /// WARNING: This virtual method is called within the constructor. ONLY
        /// CLASSES THAT DIRECTLY DERIVE FROM COMMANDSERVICEBASE SHOULD OVERRIDE IT
        /// AND SHOULD DO SO USING THE 'SEALED' KEYWORD.</remarks>
        protected virtual void RegisterMenuInfo(MenuInfo info)
        {
            MenuInfo addedInfo = GetMenuInfo(info.MenuTag);

            if (addedInfo != null)
            {
                throw new InvalidOperationException("Menu object '" + info.MenuTag + "' was already added");
            }

            if (info.MenuTag is StandardMenu)
            {
                m_menus.Add(info);
            }
            else
            {
                m_menus.Insert(m_menus.Count - 2, info); // insert custom menus before Window, Help
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets command path string for given command</summary>
        /// <param name="commandInfo">CommandInfo for command</param>
        /// <returns>String representing command path in menu hierarchy</returns>
        public string GetCommandPath(CommandInfo commandInfo)
        {
            string result = commandInfo.MenuText;

            MenuInfo menuInfo = GetMenuInfo(commandInfo.MenuTag);

            if (menuInfo == null)
            {
                menuInfo = GetContextMenuInfo(commandInfo.MenuTag);
            }

            if (menuInfo != null)
            {
                result = menuInfo.MenuText + "/" + result;
            }

            return(result);
        }
コード例 #5
0
ファイル: MenuInfos.cs プロジェクト: zparr/ATF
        /// <summary>
        /// Sets ToolStrip for MenuInfo</summary>
        /// <param name="menuInfo">ToolStrip for MenuInfo</param>
        /// <param name="toolStrip">ToolStrip to set</param>
        /// <param name="commandService">Command service</param>
        public static void SetToolStrip(this MenuInfo menuInfo, ToolStrip toolStrip, CommandService commandService)
        {
            if (menuInfo.CommandService != null && menuInfo.CommandService != commandService)
            {
                throw new NullReferenceException("MenuInfo has already been registered to a CommandService, and it is not the one specified.");
            }

            if (toolStrip == null)
            {
                throw new InvalidTransactionException("ToolStrip cannot be null");
            }

            if (commandService == null)
            {
                throw new InvalidTransactionException("CommandService cannot be null");
            }

            commandService.SetMenuToolStrip(menuInfo, toolStrip);
        }
コード例 #6
0
ファイル: MenuInfos.cs プロジェクト: zparr/ATF
        /// <summary>
        /// Obtains ToolStrip for MenuInfo</summary>
        /// <param name="menuInfo">MenuInfo</param>
        /// <returns>ToolStrip for MenuInfo</returns>
        public static ToolStrip GetToolStrip(this MenuInfo menuInfo)
        {
            if (menuInfo.CommandService == null)
            {
                throw new NullReferenceException("MenuInfo has not been registered to a CommandService.");
            }

            CommandService commandService = (CommandService)menuInfo.CommandService;

            if (commandService == null)
            {
                throw new InvalidTransactionException("MenuInfo was registered to an ICommandService, but not specifically to Sce.Atf.Applications.CommandService.");
            }

            ToolStrip toolStrip = commandService.GetMenuToolStrip(menuInfo);

            if (toolStrip == null)
            {
                throw new InvalidTransactionException("The MenuInfo specified has no ToolStrip associated with it, which should have been set up in (or before) CommandService.RegisterMenuInfo()");
            }

            return(toolStrip);
        }
コード例 #7
0
ファイル: CommandService.cs プロジェクト: Joxx0r/ATF
 public MenuToolBarModel(MenuInfo menuInfo)
 {
     MenuInfo = menuInfo;
 }
コード例 #8
0
ファイル: CommandService.cs プロジェクト: Joxx0r/ATF
 private void ExportMenuModel(MenuInfo menuInfo)
 {
     // Add toolbar/menu model
     var model = new MenuToolBarModel(menuInfo);
     model.ComposablePart = m_composer.AddPart(model);
 }
コード例 #9
0
ファイル: CommandServiceBase.cs プロジェクト: Optis-World/ATF
 /// <summary>
 /// Registers the menu for the application and gives it a tool strip</summary>
 /// <param name="menuInfo">Menu description; standard menus are defined as static members
 /// of the MenuInfo class</param>
 public void RegisterMenu(MenuInfo menuInfo)
 {
     RegisterMenuInfo(menuInfo);
 }
コード例 #10
0
ファイル: CommandServiceBase.cs プロジェクト: Optis-World/ATF
 /// <summary>
 /// Decrements the count of commands associated with the specified MenuInfo</summary>
 /// <param name="menuInfo">MenuInfo for menu's command count to decrement</param>
 protected virtual void DecrementMenuCommandCount(MenuInfo menuInfo)
 {
     menuInfo.Commands--;
 }
コード例 #11
0
ファイル: LuaIntellisense.cs プロジェクト: arsaccol/SLED
        public void Initialize()
        {
            m_broker = LuaTextEditorFactory.CreateOrGetBroker();
            m_broker.UseNavigationBar = false;
            m_broker.CustomScriptRegistrationHandler = CustomScriptRegistrationHandler;
            m_broker.OpenAndSelectHandler = CustomOpenAndSelectHandler;
            m_broker.Status.Changed += BrokerStatusChanged;

            m_statusService = SledServiceInstance.TryGet<IStatusService>();
            m_gotoService = SledServiceInstance.Get<ISledGotoService>();

            var projectService = SledServiceInstance.Get<ISledProjectService>();
            projectService.Created += ProjectServiceCreated;
            projectService.Opened += ProjectServiceOpened;
            projectService.FileOpened += ProjectServiceFileOpened;
            projectService.FileClosing += ProjectServiceFileClosing;
            projectService.Closed += ProjectServiceClosed;

            m_documentService = SledServiceInstance.Get<ISledDocumentService>();

            // Register the toolbar menu
            var menuInfo = new MenuInfo(Menu.LuaIntellisense, "Lua Intelliense", "Lua Intelliense Menu");
            m_commandService.RegisterMenu(menuInfo);

            // Register the commands
            m_commandService.RegisterCommand(
                Command.GotoDefinition,
                Menu.LuaIntellisense,
                null,
                "Goto &Definition",
                "Jumps to the definition of the selected variable",
                Atf.Input.Keys.Alt | Atf.Input.Keys.G,
                null,
                CommandVisibility.Menu,
                this);

            m_commandService.RegisterCommand(
                Command.GotoReference,
                Menu.LuaIntellisense,
                null,
                "Goto &References",
                "Jumps to the references of the selected variable",
                Atf.Input.Keys.Alt | Atf.Input.Keys.R,
                null,
                CommandVisibility.Menu,
                this);

            //m_commandService.RegisterCommand(
            //    Command.RenameVariable,
            //    Menu.LuaIntellisense,
            //    Group.LuaIntellisense,
            //    "Rename variable",
            //    "Renames selected variable",
            //    Atf.Input.Keys.Shift | Atf.Input.Keys.Alt | Atf.Input.Keys.R,
            //    null,
            //    CommandVisibility.Menu,
            //    this);

            m_commandService.RegisterCommand(
                Command.MoveToPreviousPosition,
                Menu.LuaIntellisense,
                Group.LuaIntellisense,
                "&Previous visited location",
                "Moves the caret to the previous visited location",
                Atf.Input.Keys.Alt | Atf.Input.Keys.Left,
                null,
                CommandVisibility.Menu,
                this);

            m_commandService.RegisterCommand(
                Command.MoveToNextPosition,
                Menu.LuaIntellisense,
                Group.LuaIntellisense,
                "&Next visited location",
                "Moves the caret to the next visited location",
                Atf.Input.Keys.Alt | Atf.Input.Keys.Right,
                null,
                CommandVisibility.Menu,
                this);
        }
コード例 #12
0
 /// <summary>
 /// Decrements the count of commands associated with the specified MenuInfo</summary>
 /// <param name="menuInfo">MenuInfo whose command count is decremented</param>
 protected override void DecrementMenuCommandCount(MenuInfo menuInfo)
 {
     base.DecrementMenuCommandCount(menuInfo);
     if (menuInfo.Commands == 0)
         m_menuToolStripItems[menuInfo].Visible = false;
 }
コード例 #13
0
        /// <summary>
        /// Adds this MenuInfo object to m_menus field and creates a ToolStrip for it</summary>
        /// <param name="info">MenuInfo object to add</param>
        sealed protected override void RegisterMenuInfo(MenuInfo info)
        {
            base.RegisterMenuInfo(info);

            // If it wasn't already done, create a WinForms ToolStrip for this MenuInfo
            ToolStrip toolStrip;
            if (m_menuToolStrips.TryGetValue(info, out toolStrip) == false)
            {
                toolStrip = new ToolStripEx();
                toolStrip.MouseHover += ToolStripOnMouseHover;
                m_menuToolStrips.Add(info, toolStrip);
            }

            // build toolbar corresponding to menu
            {
                string str = info.MenuText.Replace("&", "");
                str = str.Replace(";", "");
                toolStrip.Name = str + "_toolbar";
                toolStrip.AllowItemReorder = true; // magic, to enable customization with Alt key
            }

            // build menu
            ToolStripMenuItem menuItem = new ToolStripMenuItem(info.MenuText);
            menuItem.Visible = false;
            menuItem.Name = info.MenuText + "_menu";
            menuItem.Tag = info.MenuTag;
            m_menuToolStripItems.Add(info, menuItem);
            
            // Associate the registered MenuInfo with this CommandService.  Only can be registered once.
            info.CommandService = this;
        }
コード例 #14
0
        /// <summary>
        /// Sets the WinForms ToolStrip for a given MenuInfo instance. Prevents RegisterMenuInfo()
        /// from creating one for it.</summary>
        /// <param name="info">MenuInfo</param>
        /// <param name="toolStrip">ToolStrip</param>
        public void SetMenuToolStrip(MenuInfo info, ToolStrip toolStrip)
        {
            if (info == null)
                throw new NullReferenceException("MenuInfo argument cannot be null");

            if (toolStrip == null)
                throw new NullReferenceException("ToolStrip argument cannot be null");

            m_menuToolStrips.Add(info, toolStrip);
        }
コード例 #15
0
        /// <summary>
        /// Gets the WinForms ToolStrip for a given MenuInfo instance</summary>
        /// <param name="info">MenuInfo instance</param>
        /// <returns>WinForms ToolStrip for given MenuInfo instance</returns>
        public ToolStrip GetMenuToolStrip(MenuInfo info)
        {
            if (info == null)
                throw new NullReferenceException("MenuInfo argument cannot be null");

            return m_menuToolStrips[info];
        }
コード例 #16
0
ファイル: CommandService.cs プロジェクト: zparr/ATF
        /// <summary>
        /// Populates menu control and toolbar with all registered menus and commands</summary>
        public void BuildDefaultMenusAndToolbars()
        {
            // try to get toolstrip container for toolbars
            if (m_toolStripContainer == null)
            {
                foreach (Control control in m_mainForm.Controls)
                {
                    m_toolStripContainer = control as ToolStripContainer;
                    if (m_toolStripContainer != null)
                    {
                        break;
                    }
                }
            }

            // build menus (but not their contents)
            m_mainMenuStrip.SuspendLayout();
            m_mainMenuStrip.Items.Clear();

            foreach (MenuInfo menuInfo in m_menus)
            {
                ToolStripMenuItem menuItem = m_menuToolStripItems[menuInfo];
                menuItem.DropDownItems.Add("Dummy"); // to trigger drop down
                // we will build the menu just-in-time, when its drop down is opening
                menuItem.DropDownOpening += menuItem_DropDownOpening;
                // we will clear the menu when it's closed
                menuItem.DropDownClosed += menuItem_DropDownClosed;
                m_mainMenuStrip.Items.Add(menuItem);
            }

            m_mainMenuStrip.ResumeLayout();
            m_mainMenuStrip.PerformLayout();

            // build toolbars
            var toolStrips = new List <ToolStrip>();

            for (int i = m_menus.Count - 1; i >= 0; i--)
            {
                MenuInfo menuInfo  = m_menus[i];
                var      toolStrip = menuInfo.GetToolStrip();
                toolStrips.Add(toolStrip);

                foreach (CommandInfo commandInfo in m_commands)
                {
                    if (TagsEqual(menuInfo.MenuTag, commandInfo.MenuTag))
                    {
                        if ((commandInfo.Visibility & CommandVisibility.Toolbar) != 0 &&
                            GetClient(commandInfo.CommandTag) != null)
                        {
                            var btn = commandInfo.GetButton();
                            if (commandInfo.CheckOnClick)
                            {
                                btn.CheckOnClick = true;
                                commandInfo.GetMenuItem().CheckOnClick = true;
                                btn.CheckedChanged += SynchronizeCheckedState;
                                commandInfo.GetMenuItem().CheckedChanged += SynchronizeCheckedState;
                            }
                            toolStrip.Items.Add(btn);
                        }
                    }
                }

                toolStrip.Dock = DockStyle.None;
                AddCustomizationDropDown(toolStrip);
                toolStrip.Visible = (toolStrip.Items.Count > 1);
            }

            if (m_toolStripContainer != null)
            {
                m_toolStripContainer.TopToolStripPanel.Controls.AddRange(toolStrips.ToArray());
                m_toolStripContainer.TopToolStripPanel.Controls.Add(m_mainMenuStrip);
            }
            else
            {
                m_mainForm.Controls.Add(m_mainMenuStrip);
            }
        }