public static void GetCounts( IProjectPlugin project, Block block, out int count, out int wordCount, out int characterCount, out int nonWhitespaceCount) { // Make sure we have a sane state. if (project == null) { throw new ArgumentNullException("project"); } if (block == null) { throw new ArgumentNullException("block"); } // Figure out the root path for the various components. HierarchicalPath rootPath = GetPluginRootPath(project); count = GetCount(block, rootPath, "Total/" + CountType); wordCount = GetCount(block, rootPath, "Total/" + WordCountType); characterCount = GetCount(block, rootPath, "Total/" + CharacterCountType); nonWhitespaceCount = GetCount( block, rootPath, "Total/" + NonWhitespaceCountType); }
public static void GetCounts( IProjectPlugin project, Block block, out int count, out int wordCount, out int characterCount, out int nonWhitespaceCount) { // Make sure we have a sane state. if (project == null) { throw new ArgumentNullException("project"); } if (block == null) { throw new ArgumentNullException("block"); } // Figure out the root path for the various components. HierarchicalPath rootPath = GetPluginRootPath(project); count = GetCount(block, rootPath, "Total/" + CountType); wordCount = GetCount(block, rootPath, "Total/" + WordCountType); characterCount = GetCount(block, rootPath, "Total/" + CharacterCountType); nonWhitespaceCount = GetCount( block, rootPath, "Total/" + NonWhitespaceCountType); }
private void LoadCorePlugin(IProjectPlugin plugin) { try { plugin.Launch(project); } catch (Exception ex) { MessageBox.Show(ex.Message, Strings.GetString("unknown_error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Removes all the text spans of a given controller. /// </summary> /// <param name="controller">The controller to remove the spans for.</param> public void Remove(IProjectPlugin controller) { var removeSpans = new HashSet <TextSpan>(); foreach (TextSpan textSpan in this.Where(textSpan => textSpan.Controller == controller)) { removeSpans.Add(textSpan); } foreach (TextSpan textSpan in removeSpans) { Remove(textSpan); } }
public void HandleRemovedController( Project project, IProjectPlugin controller) { var spellingController = controller as ISpellingProjectPlugin; if (spellingController != null) { // Update the collections. SpellingControllers.Remove(spellingController); // Inject some additional linkage into the controller. spellingController.BlockAnalyzer = null; } }
/// <summary> /// Gets the deltas as a dictionary of key and deltas for the block. /// </summary> /// <param name="project">The project.</param> /// <param name="block">The block.</param> /// <param name="wordDelta">The word delta.</param> /// <param name="characterDelta">The character delta.</param> /// <param name="nonWhitespaceDelta">The non whitespace delta.</param> /// <returns> /// A dictionary of paths and deltas. /// </returns> public static Dictionary <HierarchicalPath, int> GetDeltas( IProjectPlugin project, Block block, int delta, int wordDelta, int characterDelta, int nonWhitespaceDelta) { // Make sure we have a sane arguments. if (project == null) { throw new ArgumentNullException("project"); } if (block == null) { throw new ArgumentNullException("block"); } // Create the dictionary and figure out the top-level elements. var deltas = new Dictionary <HierarchicalPath, int>(); HierarchicalPath rootPath = GetPluginRootPath(project); // Add in the path for the totals. var totalPath = new HierarchicalPath("Total", rootPath); AddDeltas( deltas, totalPath, delta, wordDelta, characterDelta, nonWhitespaceDelta); // Add in a block-type specific path along with a counter. string relativeBlockPath = "Block Types/" + block.BlockType.Name; var blockPath = new HierarchicalPath(relativeBlockPath, rootPath); AddDeltas( deltas, blockPath, delta, wordDelta, characterDelta, nonWhitespaceDelta); // Return the resulting delta. return(deltas); }
private void LoadPlugin(Assembly assembly) { try { foreach (Type type in assembly.GetTypes()) { if (type.GetInterface("IProjectPlugin") != null) { IProjectPlugin plugin = (IProjectPlugin)Activator.CreateInstance(type); projectPlugins.Add(plugin); } else if (type.GetInterface("IDiagramPlugin") != null) { IDiagramPlugin plugin = (IDiagramPlugin)Activator.CreateInstance(type); diagramPlugins.Add(plugin); } } } catch (Exception ex) { MessageBox.Show(Strings.GetString("error_could_not_load_plugins", ex.Message)); } }
/// <summary> /// Gets the deltas as a dictionary of key and deltas for the block. /// </summary> /// <param name="project">The project.</param> /// <param name="block">The block.</param> /// <param name="wordDelta">The word delta.</param> /// <param name="characterDelta">The character delta.</param> /// <param name="nonWhitespaceDelta">The non whitespace delta.</param> /// <returns> /// A dictionary of paths and deltas. /// </returns> public static Dictionary<HierarchicalPath, int> GetDeltas( IProjectPlugin project, Block block, int delta, int wordDelta, int characterDelta, int nonWhitespaceDelta) { // Make sure we have a sane arguments. if (project == null) { throw new ArgumentNullException("project"); } if (block == null) { throw new ArgumentNullException("block"); } // Create the dictionary and figure out the top-level elements. var deltas = new Dictionary<HierarchicalPath, int>(); HierarchicalPath rootPath = GetPluginRootPath(project); // Add in the path for the totals. var totalPath = new HierarchicalPath("Total", rootPath); AddDeltas( deltas, totalPath, delta, wordDelta, characterDelta, nonWhitespaceDelta); // Add in a block-type specific path along with a counter. string relativeBlockPath = "Block Types/" + block.BlockType.Name; var blockPath = new HierarchicalPath(relativeBlockPath, rootPath); AddDeltas( deltas, blockPath, delta, wordDelta, characterDelta, nonWhitespaceDelta); // Return the resulting delta. return deltas; }
private static HierarchicalPath GetPluginRootPath(IProjectPlugin project) { return(new HierarchicalPath("/Plugins/" + project.Key)); }
private void LoadPlugins() { try { string pluginsPath = Path.Combine(Application.StartupPath, "plugins"); if (!Directory.Exists(pluginsPath)) { return; } DirectoryInfo directory = new DirectoryInfo(pluginsPath); foreach (FileInfo file in directory.GetFiles("*.dll")) { Assembly assembly = Assembly.LoadFile(file.FullName); LoadPlugin(assembly); } } catch (Exception ex) { MessageBox.Show(Strings.GetString("error_could_not_load_plugins", ex.Message)); } if (projectPlugins.Count > 0 || diagramPlugins.Count > 0) { mnuPlugins.Visible = true; foreach (IProjectPlugin plugin in projectPlugins) { ToolStripMenuItem menu = new ToolStripMenuItem(); menu.Text = plugin.MenuText; menu.Tag = plugin; menu.Click += new EventHandler(delegate { try { IProjectPlugin taggedPlugin = menu.Tag as IProjectPlugin; if (taggedPlugin != null) { taggedPlugin.Launch(project); } } catch (Exception ex) { MessageBox.Show(ex.Message, Strings.GetString("unknown_error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }); mnuPlugins.DropDownItems.Add(menu); } foreach (IDiagramPlugin plugin in diagramPlugins) { ToolStripMenuItem menu = new ToolStripMenuItem(); menu.Text = plugin.MenuText; menu.Tag = plugin; menu.Click += new EventHandler(delegate { try { IDiagramPlugin taggedPlugin = menu.Tag as IDiagramPlugin; if (taggedPlugin != null) { taggedPlugin.Launch(diagram); } } catch (Exception ex) { MessageBox.Show(ex.Message, Strings.GetString("unknown_error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }); mnuPlugins.DropDownItems.Add(menu); } } }
private static HierarchicalPath GetPluginRootPath(IProjectPlugin project) { return new HierarchicalPath("/Plugins/" + project.Key); }
/// <summary> /// Adds the specified plugin by name from the PluginManager and sets up the /// elements inside the project. /// </summary> /// <param name="pluginName">Name of the plugin.</param> /// <returns></returns> public bool Add(string pluginName) { // Look up the plugin from the plugin manager. IProjectPluginProviderPlugin plugin; if (!PluginManager.TryGetProjectPlugin(pluginName, out plugin)) { // We couldn't find the plugin inside the manager. return(false); } // If the plugin doesn't allow duplicates, then check to see if we // already have a configuration object associated with this plugin. if (!plugin.AllowMultiple && Contains(pluginName)) { // We can't add a new one since we already have one. return(false); } // We can add this plugin to the project (either as a duplicate or // as the first). In all cases, we get a flyweight wrapper around the // plugin and add it to the ordered list of project-specific plugins. var projectPlugin = new ProjectPluginController(this, plugin); // See if this is a plugin framework controller. If it is, we all // it to connect to any existing plugins. IProjectPlugin pluginController = projectPlugin.ProjectPlugin; var frameworkController = pluginController as IFrameworkProjectPlugin; if (frameworkController != null) { var pluginControllers = new List <IProjectPlugin>(); foreach (ProjectPluginController currentPlugin in Controllers) { pluginControllers.Add(currentPlugin.ProjectPlugin); } frameworkController.InitializePluginFramework(Project, pluginControllers); } // Go through the list of existing plugin frameworks and see if they want to // add this one to their internal management. foreach (ProjectPluginController controller in Controllers) { frameworkController = controller.ProjectPlugin as IFrameworkProjectPlugin; if (frameworkController != null) { frameworkController.HandleAddedController(Project, pluginController); } } // Add the controllers to the list. Controllers.Add(projectPlugin); // Because we've made changes to the plugin, we need to sort and reorder it. // This also creates some of the specialized lists required for handling // immediate editors (auto-correct). UpdatePlugins(); // We were successful in adding the plugin. return(true); }
public void HandleRemovedController( Project project, IProjectPlugin controller) { var spellingController = controller as ISpellingProjectPlugin; if (spellingController != null) { // Update the collections. SpellingControllers.Remove(spellingController); // Inject some additional linkage into the controller. spellingController.BlockAnalyzer = null; } }