public LocalWordsProjectPlugin(Project project)
        {
            // Save the variables so we can access them later.
            Project = project;

            // Create the collections we'll use.
            CaseInsensitiveDictionary = new HashSet<string>();
            CaseSensitiveDictionary = new HashSet<string>();

            // Load in the initial settings.
            ReadSettings();
        }
        public ImmediateCorrectionProjectPlugin(
			ImmediateCorrectionPlugin plugin,
			Project project)
        {
            // Save the various properties we need for the controller.
            Plugin = plugin;
            Project = project;

            // Set up the substitions from the configuration settings.
            Substitutions = new List<RegisteredSubstitution>();
            RetrieveSettings();
        }
        public ProjectLineBuffer(
			Project project,
			EditorView editorView)
        {
            // Save the parameters as member fields for later.
            this.project = project;
            this.editorView = editorView;

            // Pull out some common elements.
            blocks = this.project.Blocks;
            commands = project.Commands;

            // Hook up the events.
            editorView.Controller.PopulateContextMenu += OnPopulateContextMenu;
            blocks.BlockTextChanged += OnBlockTextChanged;
            blocks.TextSpansChanged += OnTextSpansChanged;
            blocks.BlockTypeChanged += OnBlockTypeChanged;
        }
 public ImmediateBlockTypesProjectPlugin(Project project)
 {
     Project = project;
 }
        /// <summary>
        /// Configures the environment to load the plugin manager and verify we
        /// have access to our plugin and projectPlugin.
        /// </summary>
        private void SetupPlugin(
			out ProjectBlockCollection blocks,
			out BlockCommandSupervisor commands,
			out PluginSupervisor plugins,
			out FilesystemPersistenceProjectPlugin projectPlugin)
        {
            // Start getting us a simple plugin manager.
            var persistencePlugin = new PersistenceFrameworkPlugin();
            var filesystemPlugin = new FilesystemPersistencePlugin();
            var spellingPlugin = new SpellingFrameworkPlugin();
            var nhunspellPlugin = new HunspellSpellingPlugin();
            var localWordsPlugin = new LocalWordsPlugin();
            var immediateCorrectionPlugin = new ImmediateCorrectionPlugin();
            var immediateBlockTypesPlugin = new ImmediateBlockTypesPlugin();
            var blockStructurePlugin = new BlockStructurePlugin();

            var pluginManager = new PluginManager(
                persistencePlugin,
                filesystemPlugin,
                spellingPlugin,
                nhunspellPlugin,
                localWordsPlugin,
                immediateCorrectionPlugin,
                immediateBlockTypesPlugin,
                blockStructurePlugin);

            PluginManager.Instance = pluginManager;
            PersistenceManager.Instance = new PersistenceManager(persistencePlugin);

            // Create a project and pull out the useful properties we'll use to
            // make changes.
            var project = new Project();

            blocks = project.Blocks;
            commands = project.Commands;
            plugins = project.Plugins;

            // Load in the plugins we'll be using in these tests.
            foreach (IPlugin plugin in pluginManager.Plugins)
            {
                plugins.Add(plugin.Key);
            }

            // Set up the local words lookup.
            var localWordsProjectPlugin =
                (LocalWordsProjectPlugin) plugins["Local Words"];

            localWordsProjectPlugin.ReadSettings();
            localWordsProjectPlugin.CaseInsensitiveDictionary.Add("teig");
            localWordsProjectPlugin.CaseSensitiveDictionary.Add("Moonfire");
            localWordsProjectPlugin.WriteSettings();

            // Set up the immediate correction plugin.
            var immediateCorrectionProjectPlugin =
                (ImmediateCorrectionProjectPlugin) plugins["Immediate Correction"];

            immediateCorrectionProjectPlugin.AddSubstitution(
                "Grey", "Gray", SubstitutionOptions.WholeWord);
            immediateCorrectionProjectPlugin.AddSubstitution(
                "GWG", "Great Waryoni Garèo", SubstitutionOptions.None);
            immediateCorrectionProjectPlugin.AddSubstitution(
                "GWB", "Great Waryoni Bob", SubstitutionOptions.None);

            // Set up the immediate block types.
            var immediateBlockTypesProjectPlugin =
                (ImmediateBlockTypesProjectPlugin) plugins["Immediate Block Types"];

            foreach (BlockType blockType in project.BlockTypes.BlockTypes.Values)
            {
                string prefix = string.Format("{0}: ", blockType.Name);

                immediateBlockTypesProjectPlugin.Settings.Replacements[prefix] =
                    blockType.Name;
            }

            // Pull out the projectPlugin for the correction and cast it (since we know
            // what type it is).
            ProjectPluginController pluginController = plugins.Controllers[1];
            projectPlugin =
                (FilesystemPersistenceProjectPlugin) pluginController.ProjectPlugin;
        }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     return new SpellingFrameworkProjectPlugin();
 }
        public void InitializePluginFramework(
			Project project,
			IEnumerable<IProjectPlugin> controllers)
        {
            foreach (IProjectPlugin controller in controllers)
            {
                HandleAddedController(project, controller);
            }
        }
        /// <summary>
        /// Configures the environment to load the plugin manager and verify we
        /// have access to our plugin and projectPlugin.
        /// </summary>
        private void SetupPlugin(
			out BlockCommandContext context,
			out ProjectBlockCollection blocks,
			out BlockCommandSupervisor commands,
			out PluginSupervisor plugins,
			out SpellEngineSpellingProjectPlugin projectPlugin)
        {
            // Start getting us a simple plugin manager.
            var spelling = new SpellingFrameworkPlugin();
            var nhunspell = new HunspellSpellingPlugin();
            var pluginManager = new PluginManager(spelling, nhunspell);

            PluginManager.Instance = pluginManager;

            // Create a project and pull out the useful properties we'll use to
            // make changes.
            var project = new Project();

            context = new BlockCommandContext(project);
            blocks = project.Blocks;
            commands = project.Commands;
            plugins = project.Plugins;

            // Load in the immediate correction editor.
            if (!plugins.Add("Spelling Framework"))
            {
                // We couldn't load it for some reason.
                throw new ApplicationException("Cannot load 'Spelling' plugin.");
            }

            if (!plugins.Add("NHunspell"))
            {
                // We couldn't load it for some reason.
                throw new ApplicationException("Cannot load 'NHunspell' plugin.");
            }

            // Pull out the projectPlugin for the correction and cast it (since we know
            // what type it is).
            ProjectPluginController pluginController = plugins.Controllers[1];
            projectPlugin =
                (SpellEngineSpellingProjectPlugin) pluginController.ProjectPlugin;
        }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     return projectPlugin;
 }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     var controller = new ImmediateCorrectionProjectPlugin(this, project);
     return controller;
 }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     var projectPlugin = new BlockStructureProjectPlugin();
     return projectPlugin;
 }
        /// <summary>
        /// Raises the project is unloaded.
        /// </summary>
        /// <param name="project">The project.</param>
        protected void RaiseProjectUnloaded(Project project)
        {
            EventHandler<ProjectEventArgs> listeners = ProjectUnloaded;

            if (listeners != null)
            {
                var args = new ProjectEventArgs(project);
                listeners(this, args);
            }
        }
        /// <summary>
        /// Sets the project and fires the various events 
        /// </summary>
        /// <param name="project">The project.</param>
        public void SetProject(Project project)
        {
            // If the project is identical to the currently loaded one, we
            // don't have to do anything nor do we want events loaded.
            if (project == Project)
            {
                return;
            }

            // If we already had a project loaded, we need to unload it
            // so the various listeners can handle the unloading (and
            // interrupt it).
            if (Project != null)
            {
                // Disconnect the project from the manager.
                Project unloadedProject = Project;
                Project = null;

                // Raise the associated event.
                RaiseProjectUnloaded(unloadedProject);
            }

            // If we have a new project, then load it and raise the appropriate
            // event.
            if (project != null)
            {
                // Set the new project in the manager.
                Project = project;

                // Raise the loaded event to listeners.
                RaiseProjectLoaded(project);
            }
        }
        /// <summary>
        /// Configures the environment to load the plugin manager and verify we
        /// have access to the ImmediateCorrectionPlugin.
        /// </summary>
        private void SetupCorrectionPlugin(
			out BlockCommandContext context,
			out ProjectBlockCollection blocks,
			out BlockCommandSupervisor commands,
			out ImmediateCorrectionProjectPlugin projectPlugin)
        {
            // Start getting us a simple plugin manager.
            var plugin = new ImmediateCorrectionPlugin();
            var pluginManager = new PluginManager(plugin);

            PluginManager.Instance = pluginManager;

            // Create a project and pull out the useful properties we'll use to
            // make changes.
            var project = new Project();

            context = new BlockCommandContext(project);
            blocks = project.Blocks;
            commands = project.Commands;

            // Load in the immediate correction editor.
            if (!project.Plugins.Add("Immediate Correction"))
            {
                // We couldn't load it for some reason.
                throw new ApplicationException("Cannot load immediate correction plugin");
            }

            // Pull out the controller for the correction and cast it (since we know
            // what type it is).
            ProjectPluginController pluginController = project.Plugins.Controllers[0];
            projectPlugin =
                (ImmediateCorrectionProjectPlugin) pluginController.ProjectPlugin;
        }
        /// <summary>
        /// Configures the environment to load the plugin manager and verify we
        /// have access to the ImmediateCorrectionPlugin.
        /// </summary>
        private void SetupPlugin(
			out ProjectBlockCollection blocks,
			out BlockCommandSupervisor commands,
			out WordCounterProjectPlugin projectPlugin)
        {
            // Start getting us a simple plugin manager.
            var plugin = new WordCounterPlugin();
            var pluginManager = new PluginManager(plugin);

            PluginManager.Instance = pluginManager;

            // Create a project and pull out the useful properties we'll use to
            // make changes.
            var project = new Project();

            blocks = project.Blocks;
            commands = project.Commands;

            // Load in the immediate correction editor.
            if (!project.Plugins.Add("Word Counter"))
            {
                // We couldn't load it for some reason.
                throw new ApplicationException("Cannot load word counter plugin.");
            }

            // Pull out the controller for the correction and cast it (since we know
            // what type it is).
            ProjectPluginController pluginController = project.Plugins.Controllers[0];
            projectPlugin = (WordCounterProjectPlugin) pluginController.ProjectPlugin;

            // Set up logging for the controller.
            WordCounterProjectPlugin.Logger = Console.WriteLine;
        }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     return new WordCounterProjectPlugin();
 }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     return new LocalWordsProjectPlugin(project);
 }
        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;
            }
        }
Ejemplo n.º 19
0
        private void OnProjectMenuNewItem(
			object sender,
			EventArgs e)
        {
            // We need an open file dialog box and use that to select the project.
            var dialog = new FileChooserDialog(
                "Choose Author Intrusion Project",
                this,
                FileChooserAction.Save,
                "Cancel",
                ResponseType.Cancel,
                "Save",
                ResponseType.Accept);

            // Set up the filter on the dialog.
            var filter = new FileFilter
            {
                Name = "Project Files"
            };
            filter.AddMimeType("binary/x-author-intrusion");
            filter.AddPattern("*.aiproj");
            dialog.AddFilter(filter);

            // Show the dialog and process the results.
            try
            {
                // Show the dialog and get the button the user selected.
                int results = dialog.Run();

                // If the user accepted a file, then use that to open the file.
                if (results != (int) ResponseType.Accept)
                {
                    return;
                }

                // Create a project and (for now) add in every plugin.
                var project = new Project();

                foreach (IPlugin plugin in project.Plugins.PluginManager.Plugins)
                {
                    project.Plugins.Add(plugin.Key);
                }

                // Save the project to the given file.
                var file = new FileInfo(dialog.Filename);
                var savePlugin =
                    (FilesystemPersistenceProjectPlugin)
                        project.Plugins["Filesystem Persistence"];

                savePlugin.Settings.SetIndividualDirectoryLayout();
                savePlugin.Settings.ProjectDirectory = file.Directory.FullName;
                savePlugin.Save(file.Directory);

                // Set the project to the new plugin.
                string newProjectFilename = System.IO.Path.Combine(
                    file.Directory.FullName, "Project.aiproj");
                var projectFile = new FileInfo(newProjectFilename);
                projectManager.OpenProject(projectFile);
            }
            finally
            {
                // Destroy the dialog the box.
                dialog.Destroy();
            }
        }
 public IProjectPlugin GetProjectPlugin(Project project)
 {
     return new ImmediateBlockTypesProjectPlugin(project);
 }