/// <summary>
        /// Registers a theme provider. The provider ID is the registration
        /// key: if a provider with the same key has already been registered
        /// it will be replaced with the new provider.
        /// </summary>
        /// <param name="provider">A theme provider (implements IThemeProvider).</param>
        public void RegisterThemeProvider(IQuickSharpTheme provider)
        {
            string id = provider.GetID();

            if (String.IsNullOrEmpty(id))
            {
                throw new Exception("Theme provider has invalid ID: "
                                    + provider.GetName());
            }

            // Overwrite existing provider if key exists.
            _themeProviders[id] = provider;
        }
Beispiel #2
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();
            };
        }