public ChangeBlockTypeCommand(
			BlockKey blockKey,
			BlockType blockType)
            : base(blockKey)
        {
            BlockType = blockType;
        }
예제 #2
0
        /// <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 override void Do(
			BlockCommandContext context,
			Block block)
        {
            // We need to keep track of the previous block type so we can change
            // it back with Undo.
            previousBlockType = block.BlockType;

            // Set the block type.
            block.SetBlockType(BlockType);

            // Save the position from this command.
            if (UpdateTextPosition.HasFlag(DoTypes.Do))
            {
                context.Position = new BlockPosition(BlockKey, 0);
            }
        }
예제 #4
0
        /// <summary>
        /// Sets the type of the block and fires the events to update the internal
        /// structure. If the block type is identical, no events are fired.
        /// </summary>
        /// <param name="newBlockType">New type of the block.</param>
        public void SetBlockType(BlockType newBlockType)
        {
            // Make sure we have a sane state.
            if (newBlockType == null)
            {
                throw new ArgumentNullException("newBlockType");
            }

            if (Blocks.Project != newBlockType.Supervisor.Project)
            {
                throw new InvalidOperationException(
                    "Cannot assign a block type with a different Project than the block's Project.");
            }

            // We only do things if we are changing the block type.
            bool changed = blockType != newBlockType;

            if (changed)
            {
                // Assign the new block type.
                BlockType oldBlockType = blockType;

                blockType = newBlockType;

                // Raise an event that the block type had changed. This is done
                // before the plugins are called because they may make additional
                // changes and we want to avoid recursion.
                Project.Blocks.RaiseBlockTypeChanged(this, oldBlockType);
            }
        }
        public void ChangeBlockType(
			Block block,
			BlockType oldBlockType)
        {
            // We need a write lock on the blocks while we make this change.
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                // Report what we're doing if we have logging on.
                Log("ChangeBlockType: {0}: Old Type {1}", block, oldBlockType);

                //// Figure out the deltas for this block.
                //var deltas = new Dictionary<HierarchicalPath, int>();
                //deltas[WordCounterPathUtility.GetPath(oldBlockType)] = -1;
                //deltas[WordCounterPathUtility.GetPath(block.BlockType)] = 1;

                //// Update the parent types.
                //UpdateDeltas(block, deltas);
                //UpdateDeltas(block.Project, deltas);
            }
        }
        /// <summary>
        /// Raises an event that a block's type had changed.
        /// </summary>
        /// <param name="block"></param>
        /// <param name="oldBlockType"></param>
        public void RaiseBlockTypeChanged(
			Block block,
			BlockType oldBlockType)
        {
            EventHandler<BlockEventArgs> listeners = BlockTypeChanged;

            if (listeners != null)
            {
                var args = new BlockEventArgs(block);
                listeners(this, args);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlockTypeSupervisor"/> class.
        /// </summary>
        /// <param name="project">The project.</param>
        public BlockTypeSupervisor(Project project)
        {
            // Save the project so we can associated the Supervisor with its project.
            Project = project;

            // Create the standard project block types.
            var paragraph = new BlockType(this)
            {
                Name = ParagraphName,
                IsSystem = true,
                IsStructural = false,
            };

            var story = new BlockType(this)
            {
                Name = StoryName,
                IsSystem = true,
                IsStructural = true,
            };
            var book = new BlockType(this)
            {
                Name = BookName,
                IsSystem = true,
                IsStructural = true,
            };
            var chapter = new BlockType(this)
            {
                Name = ChapterName,
                IsSystem = true,
                IsStructural = true,
            };

            var scene = new BlockType(this)
            {
                Name = SceneName,
                IsSystem = true,
                IsStructural = true,
            };

            var epigraph = new BlockType(this)
            {
                Name = EpigraphName,
                IsSystem = true,
                IsStructural = true,
            };
            var attribution = new BlockType(this)
            {
                Name = EpigraphAttributionName,
                IsSystem = true,
                IsStructural = true,
            };

            // Initialize the collection of block types.
            BlockTypes = new Dictionary<string, BlockType>();
            BlockTypes[ParagraphName] = paragraph;
            BlockTypes[StoryName] = story;
            BlockTypes[BookName] = book;
            BlockTypes[ChapterName] = chapter;
            BlockTypes[SceneName] = scene;
            BlockTypes[EpigraphName] = epigraph;
            BlockTypes[EpigraphAttributionName] = attribution;
        }
        /// <summary>
        /// Adds the specified block type to the collection.
        /// </summary>
        /// <param name="blockTypeName">Name of the block type.</param>
        /// <param name="isStructural">if set to <c>true</c> [is structural].</param>
        /// <param name="isSystem">if set to <c>true</c> [is system].</param>
        public void Add(
			string blockTypeName,
			bool isStructural,
			bool isSystem = false)
        {
            var blockType = new BlockType(this)
            {
                Name = blockTypeName,
                IsStructural = isStructural,
                IsSystem = isSystem
            };

            BlockTypes.Add(blockTypeName, blockType);
        }
 /// <summary>
 /// Gets the child structure associated with a given block type.
 /// </summary>
 /// <param name="blockType">Type of the block.</param>
 /// <returns>A child structure of the given type.</returns>
 /// <exception cref="System.IndexOutOfRangeException">Cannot find child block type:  + blockType</exception>
 public BlockStructure GetChildStructure(BlockType blockType)
 {
     foreach (BlockStructure childStructure in
         ChildStructures.Where(
             childStructure => childStructure.BlockType == blockType))
     {
         return childStructure;
     }
     throw new IndexOutOfRangeException(
         "Cannot find child block type: " + blockType);
 }
 /// <summary>
 /// Determines whether this instance contains a child structure of the given block type.
 /// </summary>
 /// <param name="blockType">Type of the block.</param>
 /// <returns>
 ///   <c>true</c> if [contains child structure] [the specified block type]; otherwise, <c>false</c>.
 /// </returns>
 public bool ContainsChildStructure(BlockType blockType)
 {
     return
         ChildStructures.Any(childStructure => childStructure.BlockType == blockType);
 }