public static ReferenceManager GetInstance() { if (_singleton == null) { _singleton = new ReferenceManager(); } return(_singleton); }
public CreateReferenceDatabaseForm() { InitializeComponent(); Text = ApplicationManager.GetInstance(). ClientProfile.ClientTitle; Shown += new EventHandler( CreateReferenceDatabaseForm_Shown); _referenceManager = ReferenceManager.GetInstance(); }
private void ActivatePlugin() { ApplicationManager applicationManager = ApplicationManager.GetInstance(); applicationManager.RegisterOptionsPageFactory( delegate { return(new CodeAssistOptionsPage()); }); /* * Create and load the reference database file: either * empty or populated if autopopulate is enabled. */ ReferenceManager.GetInstance().CreateReferenceDatabaseFile(); }
public CodeAssistOptionsPage() { Name = Constants.UI_OPTIONS_CODE_ASSIST_PAGE; PageText = Resources.OptionsPageText; GroupText = Resources.OptionsGroupText; _settingsManager = SettingsManager.GetInstance(); _referenceManager = ReferenceManager.GetInstance(); _referenceGroupBox = new GroupBox(); _manageNamespacesButton = new Button(); _reloadNamespacesButton = new Button(); Controls.Add(_referenceGroupBox); ApplicationManager applicationManager = ApplicationManager.GetInstance(); _disableColorization = applicationManager.ClientProfile.HaveFlag( ClientFlags.CodeAssistDotNetDisableColorization); bool enableReload = !applicationManager.ClientProfile.HaveFlag( ClientFlags.CodeAssistDotNetDisableReloadDatabase); if (!_disableColorization) { _colorizeGroupBox = new GroupBox(); _colorizeTypesCheckBox = new CheckBox(); _colorizeVariablesCheckBox = new CheckBox(); _colorizeOnActivateCheckBox = new CheckBox(); _colorizeOnLookupCheckBox = new CheckBox(); Controls.Add(_colorizeGroupBox); } #region Form Layout _referenceGroupBox.Controls.Add(_manageNamespacesButton); if (enableReload) { _referenceGroupBox.Controls.Add(_reloadNamespacesButton); } _referenceGroupBox.Location = new Point(0, 0); _referenceGroupBox.Name = m_referenceGroupBox; _referenceGroupBox.TabIndex = 0; _referenceGroupBox.TabStop = false; _referenceGroupBox.Text = Resources.OptionsReferenceGroupBox; _referenceGroupBox.Size = new Size(430, 100); _manageNamespacesButton.Name = m_manageNamespacesButton; _manageNamespacesButton.Size = new Size(98, 23); _manageNamespacesButton.TabIndex = 1; _manageNamespacesButton.Text = Resources.OptionsManageNamespacesButton; _manageNamespacesButton.UseVisualStyleBackColor = true; if (enableReload) { _manageNamespacesButton.Location = new Point(111, 40); } else { _manageNamespacesButton.Location = new Point(166, 40); } if (enableReload) { _reloadNamespacesButton.Name = m_reloadNamespacesButton; _reloadNamespacesButton.Size = new Size(98, 23); _reloadNamespacesButton.TabIndex = 2; _reloadNamespacesButton.Text = Resources.OptionsReloadNamespacesButton; _reloadNamespacesButton.UseVisualStyleBackColor = true; _reloadNamespacesButton.Location = new Point(221, 40); } if (!_disableColorization) { _colorizeGroupBox.Controls.Add(_colorizeTypesCheckBox); _colorizeGroupBox.Controls.Add(_colorizeVariablesCheckBox); _colorizeGroupBox.Controls.Add(_colorizeOnActivateCheckBox); _colorizeGroupBox.Controls.Add(_colorizeOnLookupCheckBox); _colorizeGroupBox.Location = new Point(0, 110); _colorizeGroupBox.Name = m_colorizeGroupBox; _colorizeGroupBox.Size = new Size(430, 140); _colorizeGroupBox.TabIndex = 3; _colorizeGroupBox.TabStop = false; _colorizeGroupBox.Text = Resources.OptionsColorizeGroupBox; _colorizeTypesCheckBox.AutoSize = true; _colorizeTypesCheckBox.Location = new Point(19, 31); _colorizeTypesCheckBox.Name = m_colorizeTypesCheckBox; _colorizeTypesCheckBox.TabIndex = 4; _colorizeTypesCheckBox.Text = Resources.OptionsColorizeTypes; _colorizeTypesCheckBox.UseVisualStyleBackColor = true; _colorizeVariablesCheckBox.AutoSize = true; _colorizeVariablesCheckBox.Location = new Point(19, 54); _colorizeVariablesCheckBox.Name = m_colorizeVariablesCheckBox; _colorizeVariablesCheckBox.TabIndex = 5; _colorizeVariablesCheckBox.Text = Resources.OptionsColorizeVariables; _colorizeVariablesCheckBox.UseVisualStyleBackColor = true; _colorizeOnActivateCheckBox.AutoSize = true; _colorizeOnActivateCheckBox.Location = new Point(19, 77); _colorizeOnActivateCheckBox.Name = m_colorizeOnActivateCheckBox; _colorizeOnActivateCheckBox.TabIndex = 6; _colorizeOnActivateCheckBox.Text = Resources.OptionsColorizeOnActivate; _colorizeOnActivateCheckBox.UseVisualStyleBackColor = true; _colorizeOnLookupCheckBox.AutoSize = true; _colorizeOnLookupCheckBox.Location = new Point(19, 100); _colorizeOnLookupCheckBox.Name = m_colorizeOnLookupCheckBox; _colorizeOnLookupCheckBox.TabIndex = 7; _colorizeOnLookupCheckBox.Text = Resources.OptionsColorizeOnLookup; _colorizeOnLookupCheckBox.UseVisualStyleBackColor = true; } #endregion _manageNamespacesButton.Click += new EventHandler(ManageNamespacesButton_Click); if (enableReload) { _reloadNamespacesButton.Click += new EventHandler(reloadNamespacesButton_Click); } if (!_disableColorization) { _colorizeTypesCheckBox.Checked = _settingsManager.ColorizeTypes; _colorizeVariablesCheckBox.Checked = _settingsManager.ColorizeVariables; _colorizeOnActivateCheckBox.Checked = _settingsManager.ColorizeOnActivate; _colorizeOnLookupCheckBox.Checked = _settingsManager.ColorizeOnLookup; } /* * Copy the reference database to allow chnages to be * abandoned on exit if required. Not a full copy as * we're not copying the lists but as these won't change * we can just copy them as references. */ _activeNamespaces = new ReferenceDatabase(); _inactiveNamespaces = new ReferenceDatabase(); foreach (ReferenceNamespace ns in _referenceManager.ActiveNamespaces.Values) { _activeNamespaces[ns.Name] = ns; } foreach (ReferenceNamespace ns in _referenceManager.InactiveNamespaces.Values) { _inactiveNamespaces[ns.Name] = ns; } }
public override void Save() { /* * Save the registry settings. */ if (!_disableColorization) { _settingsManager.ColorizeTypes = _colorizeTypesCheckBox.Checked; _settingsManager.ColorizeVariables = _colorizeVariablesCheckBox.Checked; _settingsManager.ColorizeOnActivate = _colorizeOnActivateCheckBox.Checked; _settingsManager.ColorizeOnLookup = _colorizeOnLookupCheckBox.Checked; _settingsManager.Save(); } /* * Write the reference database if it has been updated. */ if (_activeNamespaces == null || _inactiveNamespaces == null) { return; } /* * Sanitize the lists first. */ /* * Make sure we don't have any namespaces without assemblies. * (Not sure if that could happen but better safe than sorry.) */ Dictionary <string, ReferenceNamespace> cleanActiveNamespaces = new Dictionary <string, ReferenceNamespace>(); foreach (string key in _activeNamespaces.Keys) { if (_activeNamespaces[key].AssemblyList.Count > 0) { cleanActiveNamespaces[key] = _activeNamespaces[key]; } } /* * Check for any empty namespaces and also dump any '@' * referenced assemblies so they don't build up. */ ReferenceDatabase cleanInactiveNamespaces = new ReferenceDatabase(); foreach (string key in _inactiveNamespaces.Keys) { ReferenceNamespace ns = new ReferenceNamespace(key); foreach (string s in _inactiveNamespaces[key].AssemblyList) { if (!s.StartsWith("@")) { ns.AddAssembly(s); } } if (ns.AssemblyList.Count > 0) { cleanInactiveNamespaces[ns.Name] = ns; } } /* * Write the data to the database file. */ string path = _referenceManager.ReferenceDatabasePath; StreamWriter sw = null; try { sw = new StreamWriter(path); foreach (string key in cleanActiveNamespaces.Keys) { sw.WriteLine("+" + key); foreach (string assmembly in cleanActiveNamespaces[key].AssemblyList) { sw.WriteLine(assmembly); } } foreach (string key in cleanInactiveNamespaces.Keys) { sw.WriteLine("-" + key); foreach (string assmembly in cleanInactiveNamespaces[key].AssemblyList) { sw.WriteLine(assmembly); } } } catch (Exception ex) { MessageBox.Show(String.Format("{0}:\r\n{1}", Resources.CreateDbErrorMessage, ex.Message), Resources.CreateDbErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sw != null) { sw.Close(); } } /* * Reread the database. */ ReferenceManager.GetInstance().LoadReferenceDatabaseFromFile(); }