Example #1
0
        /// <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);
        }
		/// <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;
		}