Пример #1
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();
            };
        }
Пример #2
0
        /// <summary>
        /// Copy the files in the named content folder to the user data folder.
        /// </summary>
        /// <param name="contentName">The name of the content folder to deploy.
        /// </param>
        public static void DeployContent(string contentName)
        {
            ApplicationManager applicationManager =
                ApplicationManager.GetInstance();

            /*
             * Check content hasn't been deployed already.
             */

            IPersistenceManager persistenceManager =
                applicationManager.GetPersistenceManager(contentName);

            bool contentDeployed = persistenceManager.ReadBoolean(
                Constants.KEY_USER_CONTENT_DEPLOYED, false);

            if (contentDeployed)
            {
                return;
            }

            /*
             * Check we have content to deploy.
             */

            string contentRoot = Path.Combine(
                Constants.USER_CONTENT_FOLDER, contentName);

            contentRoot = Path.Combine(
                applicationManager.QuickSharpHome, contentRoot);

            if (!Directory.Exists(contentRoot))
            {
                return;
            }

            int contentRootLength = contentRoot.Length;

            /*
             * Copy the content to the user home directory.
             * Just ignore any errors - there's nothing the end user
             * can do and any message is likely to be confusing.
             */

            string targetRoot = applicationManager.QuickSharpUserHome;

            string[] folders = Directory.GetDirectories(
                contentRoot, "*.*", SearchOption.AllDirectories);

            foreach (string folder in folders)
            {
                try
                {
                    string targetPath = Path.Combine(targetRoot,
                                                     folder.Substring(contentRootLength + 1));

                    Directory.CreateDirectory(targetPath);
                }
                catch
                {
                }
            }

            string[] files = Directory.GetFiles(
                contentRoot, "*.*", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                try
                {
                    string targetPath = Path.Combine(targetRoot,
                                                     file.Substring(contentRootLength + 1));

                    File.Copy(file, targetPath);
                }
                catch
                {
                }
            }

            /*
             * Register that we've done it.
             */

            persistenceManager.WriteBoolean(
                Constants.KEY_USER_CONTENT_DEPLOYED, true);
        }
Пример #3
0
        /// <summary>
        /// Initialize a new instance of the GeneralOptionsPage.
        /// </summary>
        public GeneralOptionsPage()
        {
            _applicationManager = ApplicationManager.GetInstance();
            _persistenceManager = _applicationManager.
                                  GetPersistenceManager(Constants.MODULE_NAME);

            Name      = Constants.UI_OPTIONS_PAGE_GENERAL;
            PageText  = Resources.OptionsPageTextGeneral;
            GroupText = Resources.OptionsGroupText;

            _documentsGroupBox          = new GroupBox();
            _restoreLastSessionCheckBox = new CheckBox();
            _showNoHandlerCheckBox      = new CheckBox();
            _allowShellOpenCheckBox     = new CheckBox();
            _showDocumentPathCheckBox   = new CheckBox();
            _themeGroupBox        = new GroupBox();
            _themeComboBox        = new ComboBox();
            _restartRequiredLabel = new Label();

            #region Form Layout

            _documentsGroupBox.Controls.Add(_restoreLastSessionCheckBox);
            _documentsGroupBox.Controls.Add(_showNoHandlerCheckBox);
            _documentsGroupBox.Controls.Add(_allowShellOpenCheckBox);
            _documentsGroupBox.Controls.Add(_showDocumentPathCheckBox);
            _documentsGroupBox.Location = new Point(0, 0);
            _documentsGroupBox.Name     = m_documentGroupBox;
            _documentsGroupBox.TabIndex = 0;
            _documentsGroupBox.TabStop  = false;
            _documentsGroupBox.Text     = Resources.OptionsDocumentsGroupBox;
            _documentsGroupBox.Size     = new Size(430, 137);

            _restoreLastSessionCheckBox.AutoSize = true;
            _restoreLastSessionCheckBox.Location = new Point(19, 22);
            _restoreLastSessionCheckBox.Name     = m_restoreLastSessionCheckBox;
            _restoreLastSessionCheckBox.TabIndex = 1;
            _restoreLastSessionCheckBox.Text     = Resources.OptionsRestoreLastSession;

            _showNoHandlerCheckBox.AutoSize = true;
            _showNoHandlerCheckBox.Location = new Point(19, 45);
            _showNoHandlerCheckBox.Name     = m_showNoHandlerCheckBox;
            _showNoHandlerCheckBox.TabIndex = 2;
            _showNoHandlerCheckBox.Text     = Resources.OptionsShowNoHandler;

            _allowShellOpenCheckBox.AutoSize = true;
            _allowShellOpenCheckBox.Location = new Point(19, 68);
            _allowShellOpenCheckBox.Name     = m_allowShellOpenCheckBox;
            _allowShellOpenCheckBox.TabIndex = 3;
            _allowShellOpenCheckBox.Text     = Resources.OptionsAllowShellOpen;

            _showDocumentPathCheckBox.AutoSize = true;
            _showDocumentPathCheckBox.Location = new Point(19, 91);
            _showDocumentPathCheckBox.Name     = m_showDocumentPathCheckBox;
            _showDocumentPathCheckBox.TabIndex = 4;
            _showDocumentPathCheckBox.Text     = Resources.OptionsShowDocumentPath;

            _themeGroupBox.Location = new Point(0, 144);
            _themeGroupBox.Name     = m_themeGroupBox;
            _themeGroupBox.TabIndex = 5;
            _themeGroupBox.TabStop  = false;
            _themeGroupBox.Text     = Resources.OptionsThemeGroupBox;
            _themeGroupBox.Size     = new Size(430, 78);
            _themeGroupBox.Controls.Add(_themeComboBox);

            _themeComboBox.Location      = new Point(19, 31);
            _themeComboBox.Name          = m_themeComboBox;
            _themeComboBox.TabIndex      = 6;
            _themeComboBox.Size          = new Size(392, 21);
            _themeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            _themeComboBox.DisplayMember = "Name";

            _restartRequiredLabel.AutoSize = true;
            _restartRequiredLabel.Location = new System.Drawing.Point(0, 230);
            _restartRequiredLabel.Name     = m_restartRequiredLabel;
            _restartRequiredLabel.Text     = Resources.OptionsRestartRequired;
            _restartRequiredLabel.TabIndex = 7;

            Controls.Add(_documentsGroupBox);
            Controls.Add(_themeGroupBox);
            Controls.Add(_restartRequiredLabel);

            #endregion

            _restoreLastSessionCheckBox.Checked =
                _persistenceManager.ReadBoolean(
                    Constants.KEY_DOCUMENT_RESTORE_LAST_SESSION, false);

            _showNoHandlerCheckBox.Checked =
                _persistenceManager.ReadBoolean(
                    Constants.KEY_DOCUMENT_SHOW_NO_HANDLER_MESSAGE, true);

            _allowShellOpenCheckBox.Checked =
                _persistenceManager.ReadBoolean(
                    Constants.KEY_DOCUMENT_ALLOW_SHELL_OPEN, true);

            _showDocumentPathCheckBox.Checked =
                _persistenceManager.ReadBoolean(
                    Constants.KEY_SHOW_DOCUMENT_PATH, false);

            string savedTheme = _persistenceManager.ReadString(
                Constants.KEY_SELECTED_THEME,
                _applicationManager.SelectedTheme);

            // Is the theme still available?
            if (_applicationManager.GetThemeProvider(savedTheme) == null)
            {
                savedTheme = Constants.DEFAULT_THEME_ID;
            }

            List <StringMap> themes =
                _applicationManager.ThemeProviderMap;

            foreach (StringMap map in themes)
            {
                _themeComboBox.Items.Add(map);

                if (map.Value == savedTheme)
                {
                    _themeComboBox.SelectedItem = map;
                }
            }
        }