Exemplo n.º 1
0
        private void SetApplicationHelpState()
        {
            if (String.IsNullOrEmpty(_profile.HelpFileName) ||
                String.IsNullOrEmpty(_profile.HelpFileTitle))
            {
                return;
            }

            ToolStripMenuItem helpMenuHelp =
                MenuTools.CreateMenuItem(
                    Constants.UI_HELP_MENU_HELP,
                    _profile.HelpFileTitle, null,
                    _profile.HelpShortcutKeys, null,
                    UI_HELP_MENU_HELP_Click, true);

            if (_profile.HelpMenuImage != null)
            {
                helpMenuHelp.Image = _profile.HelpMenuImage;
                helpMenuHelp.ImageTransparentColor = Color.Fuchsia;
            }

            UI_HELP_MENU.DropDownItems.Insert(0, helpMenuHelp);

            string helpFilePath = Path.Combine(
                _applicationManager.QuickSharpHome,
                _profile.HelpFileName);

            if (!File.Exists(helpFilePath))
            {
                helpMenuHelp.Enabled = false;
            }
        }
Exemplo n.º 2
0
        private void UpdateToolbarItems()
        {
            foreach (DockedToolStrip toolStrip in _dockedToolStrips.Values)
            {
                /*
                 * Go through each button in the toolbars and add a
                 * separator after every item with the 'IncludeSeparator'
                 * flag set.
                 */

                for (int i = 0; i < toolStrip.ToolStrip.Items.Count; i++)
                {
                    ToolStripItem item = toolStrip.ToolStrip.Items[i];

                    ToolStripItemTag tag = item.Tag as ToolStripItemTag;
                    if (tag != null && tag.IncludeSeparator)
                    {
                        ToolStripSeparator sep =
                            MenuTools.CreateSeparator(item.Name + "_SEP");

                        /*
                         * Toolbar separator occurs before the button.
                         */

                        int j = toolStrip.ToolStrip.Items.IndexOf(item);
                        if (j != -1)
                        {
                            toolStrip.ToolStrip.Items.Insert(j, sep);
                            i++;  // increment i to skip button
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void CreateMainToolbar()
        {
            _mainToolStrip      = new ToolStrip();
            _mainToolStrip.Name = Constants.MAIN_TOOLBAR_NAME;
            _mainToolStrip.Text = Resources.MainToolbarText;

            UI_TOOLBAR_NEW = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_NEW, Resources.MainToolbarNew,
                Resources.New, UI_TOOLBAR_NEW_Click);

            UI_TOOLBAR_OPEN = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_OPEN, Resources.MainToolbarOpen,
                Resources.Open, UI_TOOLBAR_OPEN_Click);

            UI_TOOLBAR_SAVE = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_SAVE, Resources.MainToolbarSave,
                Resources.Save, UI_TOOLBAR_SAVE_Click);

            UI_TOOLBAR_SAVE_ALL = MenuTools.CreateToolbarButton(
                Constants.UI_TOOLBAR_SAVE_ALL, Resources.MainToolbarSaveAll,
                Resources.SaveAll, UI_TOOLBAR_SAVE_ALL_Click);

            UI_TOOLBAR_SAVE.Enabled     = false;
            UI_TOOLBAR_SAVE_ALL.Enabled = false;

            _mainToolStrip.Items.AddRange(new ToolStripItem[] {
                UI_TOOLBAR_NEW, UI_TOOLBAR_OPEN,
                UI_TOOLBAR_SAVE, UI_TOOLBAR_SAVE_ALL
            });

            AddDockedToolStrip(_mainToolStrip, 0, 0);
        }
Exemplo n.º 4
0
        private void UpdateMenuDropDownItems(ToolStripMenuItem menu)
        {
            for (int i = 0; i < menu.DropDownItems.Count; i++)
            {
                ToolStripItem item = menu.DropDownItems[i];

                ToolStripItemTag tag = item.Tag as ToolStripItemTag;
                if (tag != null && tag.IncludeSeparator)
                {
                    ToolStripSeparator sep =
                        MenuTools.CreateSeparator(item.Name + "_SEP");

                    int j = menu.DropDownItems.IndexOf(item);

                    /*
                     * Menu separator occurs after the menu.
                     */

                    if (j != -1)
                    {
                        menu.DropDownItems.Insert(j + 1, sep);
                        i++; // increment i to skip new item
                    }
                }

                /*
                 * If the item is a menu recurse into any submenus.
                 */

                if (item is ToolStripMenuItem)
                {
                    ToolStripMenuItem menuItem = item as ToolStripMenuItem;

                    if (menuItem.DropDownItems.Count > 0)
                    {
                        UpdateMenuDropDownItems(menuItem);
                    }
                }
            }

            /*
             * The rule is that evey menu item group should end on a
             * separator. In some cases this will mean the last item
             * is a separator so we go through each menu and remove them.
             */

            int count = menu.DropDownItems.Count;

            if (count > 0)
            {
                ToolStripItem lastItem = menu.DropDownItems[count - 1];
                if (lastItem is ToolStripSeparator)
                {
                    menu.DropDownItems.RemoveAt(count - 1);
                }
            }
        }
Exemplo n.º 5
0
        private void LoadMultipleToolStrips()
        {
            /*
             * Update the toolbar menu for multi-item operation.
             */

            UI_VIEW_MENU.DropDownOpening +=
                new EventHandler(UI_VIEW_MENU_DropDownOpeningMulti);

            UI_VIEW_MENU_TOOLBAR.Text = Resources.MainViewMenuToolbarMulti;

            UI_VIEW_MENU_TOOLBAR.DropDownOpening +=
                new EventHandler(UI_VIEW_MENU_TOOLBAR_DropDownOpening);

            /*
             * Create a list of toolStrips and sort into column hint order.
             */

            List <DockedToolStrip> list =
                _dockedToolStrips.Values.ToList <DockedToolStrip>();

            int rowMax = list.Max(n => n.RowHint);

            list.Sort(CompareByColHint);

            /*
             * Add the toolStrips to the toolStripPanel and create the
             * entries for the main toolbar menu. Build up the toolbars
             * a row at a time.
             */

            for (int r = 0; r <= rowMax; r++)
            {
                foreach (DockedToolStrip toolStrip in list)
                {
                    if (toolStrip.RowHint != r)
                    {
                        continue;
                    }

                    _mainToolStripPanel.Join(
                        toolStrip.ToolStrip, toolStrip.RowHint);

                    ToolStripMenuItem toolStripMenu = MenuTools.CreateMenuItem(
                        Constants.UI_VIEW_MENU_TOOLBAR + toolStrip.Name,
                        toolStrip.Text, null, Keys.None, null,
                        UI_VIEW_MENU_TOOLBAR_ITEM_Click);

                    toolStripMenu.Tag = toolStrip.Name;

                    UI_VIEW_MENU_TOOLBAR.DropDownItems.Add(toolStripMenu);
                }
            }
        }
Exemplo n.º 6
0
        private void SetUpdateCheckState()
        {
            if (String.IsNullOrEmpty(_profile.UpdateCheckURL))
            {
                return;
            }

            ToolStripMenuItem helpMenuUpdateCheck =
                MenuTools.CreateMenuItem(
                    Constants.UI_HELP_MENU_UPDATE_CHECK,
                    Resources.MainHelpMenuCheckForUpdates,
                    null, Keys.None, null,
                    UI_HELP_MENU_CHECK_FOR_UPDATES_Click, true);

            int i = UI_HELP_MENU.DropDownItems.IndexOf(UI_HELP_MENU_ABOUT);

            if (i != -1)
            {
                UI_HELP_MENU.DropDownItems.Insert(i, helpMenuUpdateCheck);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create the main form.
        /// </summary>
        public MainForm()
        {
            _applicationManager          = ApplicationManager.GetInstance();
            _applicationManager.MainForm = this;

            /*
             * Get the ClientProfile.
             */

            _profile = _applicationManager.ClientProfile;

            if (_profile == null)
            {
                throw new Exception(Resources.NullClientProfileMessage);
            }

            /*
             * Register the default persistence provider and
             * create the settings persistence manager.
             */

            _applicationManager.RegisterPersistenceProvider(
                Constants.REGISTRY_PERSISTENCE_PROVIDER,
                RegistryPersistenceManager.GetInstance);

            _persistenceManager = _applicationManager.
                                  GetPersistenceManager(Constants.MODULE_NAME);

            /*
             * Set default form providers.
             */

            if (_profile.UpdateCheckFormFactory == null)
            {
                _profile.UpdateCheckFormFactory = delegate
                { return(new UpdateCheckForm()); }
            }
            ;

            if (_profile.AboutBoxFactory == null)
            {
                _profile.AboutBoxFactory = delegate
                { return(new AboutForm()); }
            }
            ;

            /*
             * Get any command line flags and values.
             */

            foreach (string arg in _profile.CommandLineArgs)
            {
                if (arg[0] != '/' && arg[0] != '-')
                {
                    continue;
                }
                if (arg.Length < 2)
                {
                    continue;
                }
                _applicationManager.AddCommandLineSwitch(arg.Substring(1));
            }

            /*
             * Determine if documents should be opened by the Windows shell
             * and if "no handler" messages should be shown.
             */

            _allowShellOpen = _persistenceManager.ReadBoolean(
                Constants.KEY_DOCUMENT_ALLOW_SHELL_OPEN, true);

            _showNoHandlerMessage = _persistenceManager.ReadBoolean(
                Constants.KEY_DOCUMENT_SHOW_NO_HANDLER_MESSAGE, true);

            _showDocumentChangeStatusMessage = _persistenceManager.ReadBoolean(
                Constants.KEY_SHOW_DOCUMENT_PATH, false);

            /*
             * Set up the MRU documents list.
             */

            _recentlyUsedDocuments = _persistenceManager.ReadStrings(
                Constants.KEY_MRU_DOCUMENTS_LIST);

            // Trim down to size if too big
            while (_recentlyUsedDocuments.Count > _profile.MRUDocumentListMax)
            {
                _recentlyUsedDocuments.RemoveAt(0);
            }

            /*
             * Optionally allow the documents open at the end of the last
             * session to be restored.
             */

            if (_persistenceManager.ReadBoolean(
                    Constants.KEY_DOCUMENT_RESTORE_LAST_SESSION, false))
            {
                _restoreDocumentsFromLastSession = true;
            }

            /*
             * Optionally reset the window configuration.
             */

            if (_applicationManager.HaveCommandLineSwitch(Resources.SwitchClean) &&
                _applicationManager.HaveDockPanelConfig)
            {
                File.Delete(_applicationManager.DockPanelConfigFile);
            }

            /*
             * Initialize the form.
             */

            InitializeComponent();

            /*
             * Add the Help and UpdateCheck menu items if needed.
             * Do this here to avoid adding the menu items after the
             * plugins and confusing their menu placement strategies.
             */

            SetApplicationHelpState();
            SetUpdateCheckState();

            /*
             * Prepare the main toolbar. Create the main toolbar
             * before the plugins so items can be added if required.
             */

            CreateMainToolbar();

            /*
             * Load the available plugins.
             */

            _pluginManager = PluginManager.GetInstance();
            _pluginManager.LoadPlugins();
            _pluginManager.RegisterPlugins();
            _pluginManager.ActivatePlugins(this);

            /*
             * Load the toolbars and setup the menu.
             */

            LoadDockedToolStrips();

            /*
             * Enable the document management UI if documents and document
             * handlers have been registered.
             */

            UI_FILE_MENU_NEW.Enabled = UI_TOOLBAR_NEW.Enabled = false;

            if (_applicationManager.NewDocumentType != null &&
                _applicationManager.NewDocumentHandler != null)
            {
                UI_FILE_MENU_NEW.Enabled = UI_TOOLBAR_NEW.Enabled = true;
            }

            UI_FILE_MENU_OPEN.Enabled = UI_TOOLBAR_OPEN.Enabled = false;

            if (_applicationManager.OpenDocumentHandlers.Count > 0)
            {
                UI_FILE_MENU_OPEN.Enabled = UI_TOOLBAR_OPEN.Enabled = true;
            }

            /*
             * Optionally display the current document path on the status bar
             * for 3 seconds whenever the it changes.
             */

            if (_showDocumentChangeStatusMessage)
            {
                ClientWindow.ActiveDocumentChanged += delegate
                {
                    Document doc = ClientWindow.ActiveDocument as Document;

                    if (doc != null && doc.FilePath != null)
                    {
                        SetStatusBarMessage(doc.FilePath, 5);
                    }
                    else
                    {
                        SetStatusBarMessage(String.Empty);
                    }
                };
            }

            /*
             * Set the theme.
             */

            // Register the default 'do nothing' theme.
            _applicationManager.RegisterThemeProvider(
                new DefaultTheme());

            // Register the built in Visual Studio 2008 theme.
            if (!_profile.HaveFlag(ClientFlags.CoreDisableVisualStudio2008Theme))
            {
                _applicationManager.RegisterThemeProvider(
                    new VS2008Theme());
            }

            // Register the built in Visual Studio 2010 themes.
            if (!_profile.HaveFlag(ClientFlags.CoreDisableVisualStudio2010Theme))
            {
                _applicationManager.RegisterThemeProvider(
                    new VS2010ThemeBasic());
                _applicationManager.RegisterThemeProvider(
                    new VS2010ThemeEnhanced());
            }

            // Set the currently selected theme, use VS2010 for
            // initially selected theme. If this isn't available
            // SelectTheme will bump it down to the default.
            _applicationManager.SelectedTheme =
                _persistenceManager.ReadString(
                    Constants.KEY_SELECTED_THEME,
                    Constants.VS2010_ENHANCED_THEME_ID);

            IQuickSharpTheme provider =
                _applicationManager.GetSelectedThemeProvider();

            if (provider != null)
            {
                provider.ApplyTheme();
            }

            if (_profile.ThemeFlags != null &&
                _profile.ThemeFlags.MenuForeColor != Color.Empty)
            {
                MenuTools.MenuStripItemsSetForeColor(MainMenu,
                                                     _profile.ThemeFlags.MenuForeColor,
                                                     _profile.ThemeFlags.MenuHideImages);
            }

            // Send notification that the theme has been activated.
            if (ThemeActivated != null)
            {
                ThemeActivated();
            }

            /*
             * Set or restore the layout of the main form.
             */

            SetMainFormState();
            UpdateMenuItems();
            UpdateToolbarItems();

            /*
             * Register the option pages. (This needs to be after
             * the plugins and default themes are loaded/registered.)
             */

            _applicationManager.RegisterOptionsPageFactory(
                delegate { return(new GeneralOptionsPage()); });

            /*
             * Restore the document state after the window is loaded
             * otherwise the drop-down window list doesn't get shown.
             */

            Load += delegate
            {
                /*
                 * Restore the saved dockpanel state.
                 */

                SetDockPanelState();

                /*
                 * Allow plugins to set default window states
                 * if not restored from the saved config.
                 */

                if (DockPanelPostLoad != null)
                {
                    DockPanelPostLoad();
                }

                /*
                 * Load documents from the command line.
                 */

                LoadDocuments();
            };
        }