Exemple #1
0
        /// <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;
        }
        /// <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>
        /// Creates a project with a set number of lines and gives them a state that
        /// can easily be tested for.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="blocks">The block collection in the project.</param>
        /// <param name="blockTypes">The block types supervisor for the project.</param>
        /// <param name="commands">The commands supervisor for the project.</param>
        /// <param name="lineCount">The number of blocks to insert into the projects.</param>
        protected void SetupMultilineTest(
            out BlockCommandContext context,
            out ProjectBlockCollection blocks,
            out BlockTypeSupervisor blockTypes,
            out BlockCommandSupervisor commands,
            int lineCount = 4)
        {
            // Everything is based on the project.
            var project = new Project();

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

            // Insert the bulk of the lines.
            InsertLines(project, lineCount);

            // Go through and set up the block types for these elements.
            project.Blocks[0].SetBlockType(blockTypes.Chapter);

            for (int index = 1;
                 index < project.Blocks.Count;
                 index++)
            {
                project.Blocks[index].SetBlockType(blockTypes.Scene);
            }
        }
        protected void SetupComplexMultilineTest(
			out ProjectBlockCollection blocks,
			out BlockTypeSupervisor blockTypes,
			out BlockCommandSupervisor commands,
			int lineCount = 10)
        {
            // Everything is based on the project.
            var project = new Project();

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

            // Set up the structure and insert the lines.
            SetupComplexMultilineTest(project, lineCount);
        }
        protected void SetupComplexMultilineTest(
            out ProjectBlockCollection blocks,
            out BlockTypeSupervisor blockTypes,
            out BlockCommandSupervisor commands,
            int lineCount = 10)
        {
            // Everything is based on the project.
            var project = new Project();

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

            // Set up the structure and insert the lines.
            SetupComplexMultilineTest(project, lineCount);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        public Project(
            ProjectProcessingState initialProcessingState =
            ProjectProcessingState.Interactive)
        {
            // Set up the initial states.
            ProcessingState = initialProcessingState;

            // We need the settings set up first since it may contribute
            // to the loading of other components of the project.
            Settings   = new ProjectSettings();
            Properties = new PropertiesDictionary();
            BlockTypes = new BlockTypeSupervisor(this);
            Blocks     = new ProjectBlockCollection(this);
            Commands   = new BlockCommandSupervisor(this);
            Plugins    = new PluginSupervisor(this);
            Macros     = new ProjectMacros();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        public Project(
			ProjectProcessingState initialProcessingState =
				ProjectProcessingState.Interactive)
        {
            // Set up the initial states.
            ProcessingState = initialProcessingState;

            // We need the settings set up first since it may contribute
            // to the loading of other components of the project.
            Settings = new ProjectSettings();
            Properties = new PropertiesDictionary();
            BlockTypes = new BlockTypeSupervisor(this);
            Blocks = new ProjectBlockCollection(this);
            Commands = new BlockCommandSupervisor(this);
            Plugins = new PluginSupervisor(this);
            Macros = new ProjectMacros();
        }
Exemple #8
0
        /// <summary>
        /// Gets the editor actions associated with the given TextSpan.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="textSpan">The text span.</param>
        /// <returns>
        /// A list of editor actions associated with this span.
        /// </returns>
        /// <remarks>
        /// This will be called within a read-only lock.
        /// </remarks>
        public IList <IEditorAction> GetEditorActions(
            Block block,
            TextSpan textSpan)
        {
            // We only get to this point if we have a misspelled word.
            string word = textSpan.GetText(block.Text);

            // Get the suggestions for the word.
            IList <SpellingSuggestion> suggestions = GetSuggestions(word);

            // Go through the suggestions and create an editor action for each one.
            // These will already be ordered coming out of the GetSuggestions()
            // method.
            BlockCommandSupervisor commands = block.Project.Commands;
            var actions = new List <IEditorAction>(suggestions.Count);

            foreach (SpellingSuggestion suggestion in suggestions)
            {
                // Figure out the operation we'll be using to implement the change.
                var command =
                    new ReplaceTextCommand(
                        new BlockPosition(block.BlockKey, textSpan.StartTextIndex),
                        textSpan.Length,
                        suggestion.Suggestion);

                // Create the suggestion action, along with the replacement command.
                var action =
                    new EditorAction(
                        string.Format("Change to \"{0}\"", suggestion.Suggestion),
                        new HierarchicalPath("/Plugins/Spelling/Change"),
                        context => commands.Do(command, context));

                actions.Add(action);
            }

            // Add the additional editor actions from the plugins.
            foreach (ISpellingProjectPlugin controller in SpellingControllers)
            {
                IEnumerable <IEditorAction> additionalActions =
                    controller.GetAdditionalEditorActions(word);
                actions.AddRange(additionalActions);
            }

            // Return all the change actions.
            return(actions);
        }
        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;
        }
        /// <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;
        }
        /// <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 pluginManager = new PluginManager(persistencePlugin, filesystemPlugin);

            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.
            plugins.Add("Persistence Framework");
            plugins.Add("Filesystem Persistence");
            plugins.Add("Spelling Framework");
            plugins.Add("NHunspell");
            plugins.Add("Local Words");
            plugins.Add("Immediate Correction");

            // 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;
        }
        /// <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;
        }
        /// <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;
        }
        /// <summary>
        /// Creates a project with a set number of lines and gives them a state that
        /// can easily be tested for.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="blocks">The block collection in the project.</param>
        /// <param name="blockTypes">The block types supervisor for the project.</param>
        /// <param name="commands">The commands supervisor for the project.</param>
        /// <param name="lineCount">The number of blocks to insert into the projects.</param>
        protected void SetupMultilineTest(
			out BlockCommandContext context,
			out ProjectBlockCollection blocks,
			out BlockTypeSupervisor blockTypes,
			out BlockCommandSupervisor commands,
			int lineCount = 4)
        {
            // Everything is based on the project.
            var project = new Project();

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

            // Insert the bulk of the lines.
            InsertLines(project, lineCount);

            // Go through and set up the block types for these elements.
            project.Blocks[0].SetBlockType(blockTypes.Chapter);

            for (int index = 1;
                index < project.Blocks.Count;
                index++)
            {
                project.Blocks[index].SetBlockType(blockTypes.Scene);
            }
        }
        /// <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 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;
        }
Exemple #17
0
        /// <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;
        }
        /// <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 pluginManager = new PluginManager(persistencePlugin, filesystemPlugin);

            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.
            plugins.Add("Persistence Framework");
            plugins.Add("Filesystem Persistence");
            plugins.Add("Spelling Framework");
            plugins.Add("NHunspell");
            plugins.Add("Local Words");
            plugins.Add("Immediate Correction");

            // 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;
        }