public static void GetBeginAndEndCharacterIndices( this SingleLineTextRange range, ProjectBlockCollection blocks, out int blockIndex, out int sourceBegin, out int sourceEnd, out string text) { using (blocks.AcquireLock(RequestLock.Read)) { // Start by getting the block based on the index. Block block; blockIndex = range.LinePosition.GetLineIndex(blocks.Count); using ( blocks.AcquireBlockLock( RequestLock.Read, RequestLock.Read, blockIndex, out block)) { // Get the text and calculate the character indicies. text = block.Text; range.GetBeginAndEndCharacterIndices(text, out sourceBegin, out sourceEnd); } } }
public void Register(ProjectBlockCollection ownerCollection) { //ownerCollection.ItemsAdded += OnItemsAdded; //ownerCollection.ItemsRemoved += OnItemsRemoved; //ownerCollection.ItemRemovedAt += OnItemRemovedAt; //ownerCollection.ItemInserted += OnItemInserted; //ownerCollection.CollectionCleared += OnCollectionCleared; //ownerCollection.CollectionChanged += OnCollectionChanged; }
public static void GetBeginAndEndCharacterIndices( this SingleLineTextRange range, ProjectBlockCollection blocks, out int blockIndex, out int sourceBegin, out int sourceEnd) { string text; GetBeginAndEndCharacterIndices( range, blocks, out blockIndex, out sourceBegin, out sourceEnd, out text); }
/// <summary> /// Initializes a new instance of the <see cref="Block" /> class. /// </summary> /// <param name="blocks">The ownerCollection.</param> /// <param name="initialBlockType">Initial type of the block.</param> /// <param name="text">The text.</param> public Block( ProjectBlockCollection blocks, BlockType initialBlockType, string text = "") { BlockKey = BlockKey.GetNext(); Blocks = blocks; blockType = initialBlockType; this.text = text; Properties = new PropertiesDictionary(); TextSpans = new TextSpanCollection(); accessLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); previouslyAnalyzedPlugins = new HashSet<IBlockAnalyzerProjectPlugin>(); }
/// <summary> /// Initializes a new instance of the <see cref="Block" /> class. /// </summary> /// <param name="blocks">The ownerCollection.</param> /// <param name="initialBlockType">Initial type of the block.</param> /// <param name="text">The text.</param> public Block( ProjectBlockCollection blocks, BlockType initialBlockType, string text = "") { BlockKey = BlockKey.GetNext(); Blocks = blocks; blockType = initialBlockType; this.text = text; Properties = new PropertiesDictionary(); TextSpans = new TextSpanCollection(); accessLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); previouslyAnalyzedPlugins = new HashSet <IBlockAnalyzerProjectPlugin>(); }
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(); }
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> /// 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 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 Block(ProjectBlockCollection blocks) : this(blocks, blocks.Project.BlockTypes.Paragraph, string.Empty) { }
/// <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> /// Initializes a new instance of the <see cref="SplitBlockCommand"/> class. /// </summary> /// <param name="position">The position to break the paragraph.</param> public SplitBlockCommand( ProjectBlockCollection blocks, BlockPosition position) : base(position, "\n") { }
/// <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 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 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; }