From: <mar...@us...> - 2006-08-01 00:40:40
|
Revision: 696 Author: marisademeglio Date: 2006-07-31 16:03:29 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/urakawa/?rev=696&view=rev Log Message: ----------- Added command handlers and undo functionality for move up/move down Modified Paths: -------------- trunk/urakawa/application/Obi/Obi/Events/Node/AddedSectionNodeEventArgs.cs trunk/urakawa/application/Obi/Obi/Events/Node/NodeEventArgs.cs trunk/urakawa/application/Obi/Obi/Obi.csproj trunk/urakawa/application/Obi/Obi/Project.cs trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.Designer.cs trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs Modified: trunk/urakawa/application/Obi/Obi/Events/Node/AddedSectionNodeEventArgs.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/Events/Node/AddedSectionNodeEventArgs.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/Events/Node/AddedSectionNodeEventArgs.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -7,6 +7,7 @@ namespace Obi.Events.Node { public delegate void AddedSectionNodeHandler(object sender, AddedSectionNodeEventArgs e); + public delegate void UndidMoveNodeHandler(object sender, AddedSectionNodeEventArgs e); /// <summary> /// A section node was added. Modified: trunk/urakawa/application/Obi/Obi/Events/Node/NodeEventArgs.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/Events/Node/NodeEventArgs.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/Events/Node/NodeEventArgs.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -13,6 +13,7 @@ public delegate void RequestToDeleteNodeHandler(object sender, NodeEventArgs e); public delegate void RequestToMoveNodeUpHandler(object sender, NodeEventArgs e); public delegate void RequestToMoveNodeDownHandler(object sender, NodeEventArgs e); + public delegate void RequestToUndoMoveNodeHandler(object sender, NodeEventArgs e); public delegate void IncreasedNodeLevelHandler(object sender, NodeEventArgs e); public delegate void DecreasedNodeLevelHandler(object sender, NodeEventArgs e); Modified: trunk/urakawa/application/Obi/Obi/Obi.csproj =================================================================== --- trunk/urakawa/application/Obi/Obi/Obi.csproj 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/Obi.csproj 2006-07-31 23:03:29 UTC (rev 696) @@ -72,6 +72,8 @@ <Compile Include="Commands\CommandManager.cs" /> <Compile Include="Commands\TOC\AddSection.cs" /> <Compile Include="Commands\TOC\DeleteSection.cs" /> + <Compile Include="Commands\TOC\MoveSectionDown.cs" /> + <Compile Include="Commands\TOC\MoveSectionUp.cs" /> <Compile Include="Commands\TOC\Rename.cs" /> <Compile Include="DescendantsVisitor.cs" /> <Compile Include="Dialogs\EditSimpleMetadata.cs"> Modified: trunk/urakawa/application/Obi/Obi/Project.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/Project.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/Project.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -49,8 +49,13 @@ public event Events.Node.MovedNodeDownHandler MovedNodeDown; // a node was moved down in the presentation public event Events.Node.IncreasedNodeLevelHandler IncreasedNodeLevel; //a node's level was increased in the presentation public event Events.Node.DecreasedNodeLevelHandler DecreasedNodeLevel; //a node's level was decreased in the presentation - public event Events.Node.ImportedAssetHandler ImportedAsset; // an asset was imported into the project + public event Events.Node.UndidMoveNodeHandler UndidMoveNode; //a node was restored to its previous location + + //marisa: TESTING + private Obi.Commands.TOC.MoveSectionUp mLastMoveSectionUpCommand; + //marisa: TESTING + private Obi.Commands.TOC.MoveSectionDown mLastMoveSectionDownCommand; /// <summary> /// This flag is set to true if the project contains modifications that have not been saved. @@ -489,16 +494,36 @@ /// </summary> public void MoveNodeUp(object origin, CoreNode node) { - //a facade API function could do this for us + Commands.TOC.MoveSectionUp command = null; + + //marisa: TESTING + mLastMoveSectionUpCommand = null; + + if (origin != this) + { + CoreNode parent = (CoreNode)node.getParent(); + NodePositionVisitor visitor = new NodePositionVisitor(node); + getPresentation().getRootNode().acceptDepthFirst(visitor); + //we need to save the state of the node before it is moved + command = new Commands.TOC.MoveSectionUp + (this, node, parent, parent.indexOf(node), visitor.Position); + } + bool succeeded = ExecuteMoveNodeUp(node); + if (succeeded) { + //marisa: TESTING + mLastMoveSectionUpCommand = command; + MovedNodeUp(this, new Events.Node.NodeEventArgs(origin, node)); mUnsaved = true; StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); + if (command != null) CommandCreated(this, new Events.Project.CommandCreatedEventArgs(command)); } } + //a facade API function could do this for us private bool ExecuteMoveNodeUp(CoreNode node) { CoreNode newParent = null; @@ -543,15 +568,65 @@ MoveNodeUp(sender, e.Node); } + /// <summary> + /// reposition the node at the index under its given parent + /// </summary> + /// <param name="node"></param> + /// <param name="parent"></param> + /// <param name="index"></param> + /// <param name="position"></param> + public void UndoMoveNode(CoreNode node, CoreNode parent, int index, int position) + { + if (node.getParent() != null) node.detach(); + parent.insert(node, index); + + UndidMoveNode(this, new Events.Node.AddedSectionNodeEventArgs(this, node, index, position)); + mUnsaved = true; + StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); +} + + //marisa: TESTING + public void TestUndoMoveNode(object sender, Events.Node.NodeEventArgs e) + { + if (mLastMoveSectionUpCommand != null) + { + mLastMoveSectionUpCommand.Undo(); + mLastMoveSectionUpCommand = null; + + } + else if (mLastMoveSectionDownCommand != null) + { + mLastMoveSectionDownCommand.Undo(); + } + } + public void MoveNodeDown(object origin, CoreNode node) { + Commands.TOC.MoveSectionDown command = null; + //marisa: TESTING + mLastMoveSectionDownCommand = null; + + if (origin != this) + { + CoreNode parent = (CoreNode)node.getParent(); + NodePositionVisitor visitor = new NodePositionVisitor(node); + getPresentation().getRootNode().acceptDepthFirst(visitor); + //we need to save the state of the node before it is moved + command = new Commands.TOC.MoveSectionDown + (this, node, parent, parent.indexOf(node), visitor.Position); + } + //a facade API function could do this for us bool succeeded = ExecuteMoveNodeDown(node); if (succeeded) { + //marisa: TESTING + mLastMoveSectionDownCommand = command; + MovedNodeDown(this, new Events.Node.NodeEventArgs(origin, node)); mUnsaved = true; StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); + if (command != null) CommandCreated(this, new Events.Project.CommandCreatedEventArgs(command)); } } Modified: trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -56,13 +56,13 @@ mTOCPanel.RequestToDeleteSection -= new Events.Node.RequestToDeleteNodeHandler(mProject.RemoveNodeRequested); mProject.DeletedNode -= new Events.Node.DeletedNodeHandler(mTOCPanel.SyncDeletedNode); - - //comment: this used to say += but I think it was a typo - //reply: yes it was. -= is the way to go. mProject.DeletedNode -= new Events.Node.DeletedNodeHandler(mStripManagerPanel.SyncDeletedNode); mStripManagerPanel.ImportPhrase -= new Events.Strip.RequestToImportAssetHandler(mProject.ImportPhraseRequested); mProject.ImportedAsset -= new Events.Node.ImportedAssetHandler(mStripManagerPanel.SyncImportedAsset); + + //marisa: TESTING only + mTOCPanel.RequestToUndoMoveNode -= new Events.Node.RequestToUndoMoveNodeHandler(mProject.TestUndoMoveNode); } // Set up the handlers for the new project if (value != null) @@ -98,6 +98,9 @@ mStripManagerPanel.ImportPhrase += new Events.Strip.RequestToImportAssetHandler(value.ImportPhraseRequested); value.ImportedAsset += new Events.Node.ImportedAssetHandler(mStripManagerPanel.SyncImportedAsset); + + //marisa: TESTING only + mTOCPanel.RequestToUndoMoveNode += new Events.Node.RequestToUndoMoveNodeHandler(value.TestUndoMoveNode); } mProject = value; mSplitContainer.Visible = mProject != null; Modified: trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.Designer.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.Designer.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.Designer.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -33,15 +33,16 @@ this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.addSectionAtSameLevelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addSubSectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.deleteSectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.testShallowDeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.editLabelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.moveUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.moveDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.increaseLevelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.decreaseLevelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.editLabelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteSectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.testShallowDeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.testUndoMoveNodeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -70,84 +71,92 @@ this.moveUpToolStripMenuItem, this.moveDownToolStripMenuItem, this.increaseLevelToolStripMenuItem, - this.decreaseLevelToolStripMenuItem}); + this.decreaseLevelToolStripMenuItem, + this.testUndoMoveNodeToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(167, 236); + this.contextMenuStrip1.Size = new System.Drawing.Size(179, 258); this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); // // addSectionAtSameLevelToolStripMenuItem // this.addSectionAtSameLevelToolStripMenuItem.Name = "addSectionAtSameLevelToolStripMenuItem"; - this.addSectionAtSameLevelToolStripMenuItem.Size = new System.Drawing.Size(166, 22); + this.addSectionAtSameLevelToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.addSectionAtSameLevelToolStripMenuItem.Text = "&Add section"; this.addSectionAtSameLevelToolStripMenuItem.Click += new System.EventHandler(this.addSectionAtSameLevelToolStripMenuItem_Click); // // addSubSectionToolStripMenuItem // this.addSubSectionToolStripMenuItem.Name = "addSubSectionToolStripMenuItem"; - this.addSubSectionToolStripMenuItem.Size = new System.Drawing.Size(166, 22); + this.addSubSectionToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.addSubSectionToolStripMenuItem.Text = "Add &sub-section"; this.addSubSectionToolStripMenuItem.Click += new System.EventHandler(this.addSubSectionToolStripMenuItem_Click); // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(175, 6); + // + // deleteSectionToolStripMenuItem + // + this.deleteSectionToolStripMenuItem.Name = "deleteSectionToolStripMenuItem"; + this.deleteSectionToolStripMenuItem.Size = new System.Drawing.Size(178, 22); + this.deleteSectionToolStripMenuItem.Text = "&Delete section"; + this.deleteSectionToolStripMenuItem.Click += new System.EventHandler(this.deleteSectionToolStripMenuItem_Click); + // + // testShallowDeleteToolStripMenuItem + // + this.testShallowDeleteToolStripMenuItem.Name = "testShallowDeleteToolStripMenuItem"; + this.testShallowDeleteToolStripMenuItem.Size = new System.Drawing.Size(178, 22); + this.testShallowDeleteToolStripMenuItem.Text = "Test shallow delete"; + this.testShallowDeleteToolStripMenuItem.Click += new System.EventHandler(this.testShallowDeleteToolStripMenuItem_Click); + // + // editLabelToolStripMenuItem + // + this.editLabelToolStripMenuItem.Name = "editLabelToolStripMenuItem"; + this.editLabelToolStripMenuItem.Size = new System.Drawing.Size(178, 22); + this.editLabelToolStripMenuItem.Text = "Rena&me"; + this.editLabelToolStripMenuItem.Click += new System.EventHandler(this.editLabelToolStripMenuItem_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(175, 6); + // // moveUpToolStripMenuItem // this.moveUpToolStripMenuItem.Name = "moveUpToolStripMenuItem"; - this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.moveUpToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.moveUpToolStripMenuItem.Text = "Move up"; this.moveUpToolStripMenuItem.Click += new System.EventHandler(this.moveUpToolStripMenuItem_Click); // // moveDownToolStripMenuItem // this.moveDownToolStripMenuItem.Name = "moveDownToolStripMenuItem"; - this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.moveDownToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.moveDownToolStripMenuItem.Text = "Move down"; this.moveDownToolStripMenuItem.Click += new System.EventHandler(this.moveDownToolStripMenuItem_Click); // // increaseLevelToolStripMenuItem // this.increaseLevelToolStripMenuItem.Name = "increaseLevelToolStripMenuItem"; - this.increaseLevelToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.increaseLevelToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.increaseLevelToolStripMenuItem.Text = "Increase level"; this.increaseLevelToolStripMenuItem.Click += new System.EventHandler(this.increaseLevelToolStripMenuItem_Click); // // decreaseLevelToolStripMenuItem // this.decreaseLevelToolStripMenuItem.Name = "decreaseLevelToolStripMenuItem"; - this.decreaseLevelToolStripMenuItem.Size = new System.Drawing.Size(206, 22); + this.decreaseLevelToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.decreaseLevelToolStripMenuItem.Text = "Decrease level"; this.decreaseLevelToolStripMenuItem.Click += new System.EventHandler(this.decreaseLevelToolStripMenuItem_Click); // - // editLabelToolStripMenuItem + // testUndoMoveNodeToolStripMenuItem // - this.editLabelToolStripMenuItem.Name = "editLabelToolStripMenuItem"; - this.editLabelToolStripMenuItem.Size = new System.Drawing.Size(196, 22); - this.editLabelToolStripMenuItem.Text = "Rena&me"; - this.editLabelToolStripMenuItem.Click += new System.EventHandler(this.editLabelToolStripMenuItem_Click); + this.testUndoMoveNodeToolStripMenuItem.Name = "testUndoMoveNodeToolStripMenuItem"; + this.testUndoMoveNodeToolStripMenuItem.Size = new System.Drawing.Size(178, 22); + this.testUndoMoveNodeToolStripMenuItem.Text = "Test undo move node"; + this.testUndoMoveNodeToolStripMenuItem.Click += new System.EventHandler(this.testUndoMoveNodeToolStripMenuItem_Click); // - // deleteSectionToolStripMenuItem - // - this.deleteSectionToolStripMenuItem.Name = "deleteSectionToolStripMenuItem"; - this.deleteSectionToolStripMenuItem.Size = new System.Drawing.Size(206, 22); - this.deleteSectionToolStripMenuItem.Text = "&Delete section"; - this.deleteSectionToolStripMenuItem.Click += new System.EventHandler(this.deleteSectionToolStripMenuItem_Click); - // - // testShallowDeleteToolStripMenuItem - // - this.testShallowDeleteToolStripMenuItem.Name = "testShallowDeleteToolStripMenuItem"; - this.testShallowDeleteToolStripMenuItem.Size = new System.Drawing.Size(206, 22); - this.testShallowDeleteToolStripMenuItem.Text = "Test shallow delete"; - this.testShallowDeleteToolStripMenuItem.Click += new System.EventHandler(this.testShallowDeleteToolStripMenuItem_Click); - // - // toolStripSeparator1 - // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(193, 6); - // - // toolStripSeparator2 - // - this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(193, 6); - // // TOCPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -175,5 +184,6 @@ private System.Windows.Forms.ToolStripMenuItem testShallowDeleteToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem testUndoMoveNodeToolStripMenuItem; } } Modified: trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs 2006-07-31 17:12:46 UTC (rev 695) +++ trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs 2006-07-31 23:03:29 UTC (rev 696) @@ -26,6 +26,7 @@ public event Events.Node.RequestToMoveNodeUpHandler RequestToMoveSectionUp; public event Events.Node.RequestToRenameNodeHandler RequestToRenameSection; public event Events.Node.RequestToDeleteNodeHandler RequestToDeleteSection; + public event Events.Node.RequestToUndoMoveNodeHandler RequestToUndoMoveNode; /// <summary> /// Test whether a node is currently selected or not. @@ -705,6 +706,11 @@ } } + private void testUndoMoveNodeToolStripMenuItem_Click(object sender, EventArgs e) + { + RequestToUndoMoveNode(this, new Events.Node.NodeEventArgs(this, GetSelectedSection())); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |