From: <mar...@us...> - 2006-07-25 21:17:32
|
Revision: 657 Author: marisademeglio Date: 2006-07-25 14:04:11 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/urakawa/?rev=657&view=rev Log Message: ----------- Added move section up and move section down functionality for TOC panel and core tree. If you move a section, the change shows up in the tree view and core tree (XUK file), but not in the strip view (yet) Modified Paths: -------------- trunk/urakawa/application/Obi/Obi/Events/Sync/DeletedNodeEventArgs.cs trunk/urakawa/application/Obi/Obi/Obi.csproj trunk/urakawa/application/Obi/Obi/ObiForm.Designer.cs trunk/urakawa/application/Obi/Obi/ObiForm.cs trunk/urakawa/application/Obi/Obi/Project.cs trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs trunk/urakawa/application/Obi/Obi/UserControls/StripManagerPanel.cs trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs Modified: trunk/urakawa/application/Obi/Obi/Events/Sync/DeletedNodeEventArgs.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/Events/Sync/DeletedNodeEventArgs.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/Events/Sync/DeletedNodeEventArgs.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -7,6 +7,7 @@ namespace Obi.Events.Sync { public delegate void DeletedNodeHandler(object sender, DeletedNodeEventArgs e); + public delegate void ShallowDeletedNodeHandler(object sender, DeletedNodeEventArgs e); class DeletedNodeEventArgs : EventArgs { Modified: trunk/urakawa/application/Obi/Obi/Obi.csproj =================================================================== --- trunk/urakawa/application/Obi/Obi/Obi.csproj 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/Obi.csproj 2006-07-25 21:04:11 UTC (rev 657) @@ -96,22 +96,15 @@ <DependentUpon>UserProfile.cs</DependentUpon> </Compile> <Compile Include="Events\Node\DeleteSectionEventArgs.cs" /> - <Compile Include="Events\Node\ExpandViewToAllDepthsEventArgs.cs" /> - <Compile Include="Events\Node\AddChildSectionEventArgs.cs" /> - <Compile Include="Events\Node\AddSiblingSectionEventArgs.cs" /> - <Compile Include="Events\Node\BeginEditingSectionHeadingLabelEventArgs.cs" /> - <Compile Include="Events\Node\DecreaseSectionLevelEventArgs.cs" /> - <Compile Include="Events\Node\IncreaseSectionLevelEventArgs.cs" /> - <Compile Include="Events\Node\LimitViewToSectionDepthEventArgs.cs" /> - <Compile Include="Events\Node\MoveSectionDownEventArgs.cs" /> - <Compile Include="Events\Node\MoveSectionUpEventArgs.cs" /> + <Compile Include="Events\Node\AddSectionEventArgs.cs" /> + <Compile Include="Events\Node\ChangeSectionLevelEventArgs.cs" /> + <Compile Include="Events\Node\MoveSectionEventArgs.cs" /> <Compile Include="Events\Node\RenameSectionEventArgs.cs" /> <Compile Include="Events\Project\StateChangedEventArgs.cs" /> <Compile Include="Events\Strip\SelectedEventArgs.cs" /> - <Compile Include="Events\Sync\AddedChildNodeEventArgs.cs" /> <Compile Include="Events\Sync\AddedSectionNodeEventArgs.cs" /> - <Compile Include="Events\Sync\AddedSiblingNodeEventArgs.cs" /> <Compile Include="Events\Sync\DeletedNodeEventArgs.cs" /> + <Compile Include="Events\Sync\MovedNodeEventArgs.cs" /> <Compile Include="Events\Sync\RenamedNodeEventArgs.cs" /> <Compile Include="Localizer.cs" /> <Compile Include="messages.Designer.cs"> Modified: trunk/urakawa/application/Obi/Obi/ObiForm.Designer.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/ObiForm.Designer.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/ObiForm.Designer.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -54,13 +54,14 @@ this.mDeleteSectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mStripsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mAddStripToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.renameStripToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.userSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.preferencesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.mProjectPanel = new Obi.UserControls.ProjectPanel(); - this.renameStripToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mMoveSectionUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -93,20 +94,20 @@ this.toolStripSeparator3, this.exitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(36, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20); this.fileToolStripMenuItem.Text = "&File"; // // mNewProjectToolStripMenuItem // this.mNewProjectToolStripMenuItem.Name = "mNewProjectToolStripMenuItem"; - this.mNewProjectToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mNewProjectToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mNewProjectToolStripMenuItem.Text = "&New project"; this.mNewProjectToolStripMenuItem.Click += new System.EventHandler(this.mNewProjectToolStripMenuItem_Click); // // mOpenProjectToolStripMenuItem // this.mOpenProjectToolStripMenuItem.Name = "mOpenProjectToolStripMenuItem"; - this.mOpenProjectToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mOpenProjectToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mOpenProjectToolStripMenuItem.Text = "&Open project"; this.mOpenProjectToolStripMenuItem.Click += new System.EventHandler(this.mOpenProjectToolStripMenuItem_Click); // @@ -116,64 +117,64 @@ this.openrecentSeparator, this.mClearListToolStripMenuItem}); this.mOpenRecentProjectToolStripMenuItem.Name = "mOpenRecentProjectToolStripMenuItem"; - this.mOpenRecentProjectToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mOpenRecentProjectToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mOpenRecentProjectToolStripMenuItem.Text = "Open &recent project"; // // openrecentSeparator // this.openrecentSeparator.Name = "openrecentSeparator"; - this.openrecentSeparator.Size = new System.Drawing.Size(114, 6); + this.openrecentSeparator.Size = new System.Drawing.Size(112, 6); // // mClearListToolStripMenuItem // this.mClearListToolStripMenuItem.Name = "mClearListToolStripMenuItem"; - this.mClearListToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.mClearListToolStripMenuItem.Size = new System.Drawing.Size(115, 22); this.mClearListToolStripMenuItem.Text = "&Clear list"; this.mClearListToolStripMenuItem.Click += new System.EventHandler(this.mClearListToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(168, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(170, 6); // // mSaveProjectToolStripMenuItem // this.mSaveProjectToolStripMenuItem.Name = "mSaveProjectToolStripMenuItem"; this.mSaveProjectToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.mSaveProjectToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mSaveProjectToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mSaveProjectToolStripMenuItem.Text = "&Save project"; this.mSaveProjectToolStripMenuItem.Click += new System.EventHandler(this.mSaveProjectToolStripMenuItem_Click); // // mSaveProjectasToolStripMenuItem // this.mSaveProjectasToolStripMenuItem.Name = "mSaveProjectasToolStripMenuItem"; - this.mSaveProjectasToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mSaveProjectasToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mSaveProjectasToolStripMenuItem.Text = "Save project &as"; this.mSaveProjectasToolStripMenuItem.Click += new System.EventHandler(this.mSaveProjectasToolStripMenuItem_Click); // // mDiscardChangesToolStripMenuItem // this.mDiscardChangesToolStripMenuItem.Name = "mDiscardChangesToolStripMenuItem"; - this.mDiscardChangesToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mDiscardChangesToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mDiscardChangesToolStripMenuItem.Text = "&Discard changes"; this.mDiscardChangesToolStripMenuItem.Click += new System.EventHandler(this.mDiscardChangesToolStripMenuItem_Click); // // mCloseProjectToolStripMenuItem // this.mCloseProjectToolStripMenuItem.Name = "mCloseProjectToolStripMenuItem"; - this.mCloseProjectToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.mCloseProjectToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.mCloseProjectToolStripMenuItem.Text = "&Close project"; this.mCloseProjectToolStripMenuItem.Click += new System.EventHandler(this.mCloseProjectToolStripMenuItem_Click); // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(168, 6); + this.toolStripSeparator3.Size = new System.Drawing.Size(170, 6); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(171, 22); + this.exitToolStripMenuItem.Size = new System.Drawing.Size(173, 22); this.exitToolStripMenuItem.Text = "E&xit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // @@ -208,7 +209,8 @@ this.mAddSectionAtSameLevelToolStripMenuItem, this.mAddsubsectionToolStripMenuItem, this.mRenameSectionToolStripMenuItem, - this.mDeleteSectionToolStripMenuItem}); + this.mDeleteSectionToolStripMenuItem, + this.mMoveSectionUpToolStripMenuItem}); this.mTocToolStripMenuItem.Name = "mTocToolStripMenuItem"; this.mTocToolStripMenuItem.Size = new System.Drawing.Size(40, 20); this.mTocToolStripMenuItem.Text = "TO&C"; @@ -216,37 +218,37 @@ // mShowhideTableOfCOntentsToolStripMenuItem // this.mShowhideTableOfCOntentsToolStripMenuItem.Name = "mShowhideTableOfCOntentsToolStripMenuItem"; - this.mShowhideTableOfCOntentsToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.mShowhideTableOfCOntentsToolStripMenuItem.Size = new System.Drawing.Size(196, 22); this.mShowhideTableOfCOntentsToolStripMenuItem.Text = "Show &table of contents "; this.mShowhideTableOfCOntentsToolStripMenuItem.Click += new System.EventHandler(this.mShowhideTableOfContentsToolStripMenuItem_Click); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(201, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(193, 6); // // mAddSectionAtSameLevelToolStripMenuItem // this.mAddSectionAtSameLevelToolStripMenuItem.Name = "mAddSectionAtSameLevelToolStripMenuItem"; - this.mAddSectionAtSameLevelToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.mAddSectionAtSameLevelToolStripMenuItem.Size = new System.Drawing.Size(196, 22); this.mAddSectionAtSameLevelToolStripMenuItem.Text = "&Add section at same level"; // // mAddsubsectionToolStripMenuItem // this.mAddsubsectionToolStripMenuItem.Name = "mAddsubsectionToolStripMenuItem"; - this.mAddsubsectionToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.mAddsubsectionToolStripMenuItem.Size = new System.Drawing.Size(196, 22); this.mAddsubsectionToolStripMenuItem.Text = "Add &sub-section"; // // mRenameSectionToolStripMenuItem // this.mRenameSectionToolStripMenuItem.Name = "mRenameSectionToolStripMenuItem"; - this.mRenameSectionToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.mRenameSectionToolStripMenuItem.Size = new System.Drawing.Size(196, 22); this.mRenameSectionToolStripMenuItem.Text = "&Rename section"; // // mDeleteSectionToolStripMenuItem // this.mDeleteSectionToolStripMenuItem.Name = "mDeleteSectionToolStripMenuItem"; - this.mDeleteSectionToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.mDeleteSectionToolStripMenuItem.Size = new System.Drawing.Size(196, 22); this.mDeleteSectionToolStripMenuItem.Text = "&Delete section"; // // mStripsToolStripMenuItem @@ -255,35 +257,41 @@ this.mAddStripToolStripMenuItem, this.renameStripToolStripMenuItem}); this.mStripsToolStripMenuItem.Name = "mStripsToolStripMenuItem"; - this.mStripsToolStripMenuItem.Size = new System.Drawing.Size(47, 20); + this.mStripsToolStripMenuItem.Size = new System.Drawing.Size(46, 20); this.mStripsToolStripMenuItem.Text = "Strips"; // // mAddStripToolStripMenuItem // this.mAddStripToolStripMenuItem.Name = "mAddStripToolStripMenuItem"; - this.mAddStripToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.mAddStripToolStripMenuItem.Size = new System.Drawing.Size(137, 22); this.mAddStripToolStripMenuItem.Text = "&Add strip"; // + // renameStripToolStripMenuItem + // + this.renameStripToolStripMenuItem.Name = "renameStripToolStripMenuItem"; + this.renameStripToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.renameStripToolStripMenuItem.Text = "&Rename strip"; + // // toolsToolStripMenuItem // this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.userSettingsToolStripMenuItem, this.preferencesToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; - this.toolsToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.toolsToolStripMenuItem.Size = new System.Drawing.Size(44, 20); this.toolsToolStripMenuItem.Text = "&Tools"; // // userSettingsToolStripMenuItem // this.userSettingsToolStripMenuItem.Name = "userSettingsToolStripMenuItem"; - this.userSettingsToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.userSettingsToolStripMenuItem.Size = new System.Drawing.Size(132, 22); this.userSettingsToolStripMenuItem.Text = "&User profile"; this.userSettingsToolStripMenuItem.Click += new System.EventHandler(this.userSettingsToolStripMenuItem_Click); // // preferencesToolStripMenuItem // this.preferencesToolStripMenuItem.Name = "preferencesToolStripMenuItem"; - this.preferencesToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.preferencesToolStripMenuItem.Size = new System.Drawing.Size(132, 22); this.preferencesToolStripMenuItem.Text = "&Preferences"; this.preferencesToolStripMenuItem.Click += new System.EventHandler(this.preferencesToolStripMenuItem_Click); // @@ -291,7 +299,7 @@ // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 480); + this.statusStrip1.Location = new System.Drawing.Point(0, 522); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.ManagerRenderMode; this.statusStrip1.Size = new System.Drawing.Size(775, 22); @@ -310,24 +318,24 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.mProjectPanel.BackColor = System.Drawing.Color.White; - this.mProjectPanel.Location = new System.Drawing.Point(4, 27); + this.mProjectPanel.Location = new System.Drawing.Point(4, 29); this.mProjectPanel.Name = "mProjectPanel"; this.mProjectPanel.Project = null; - this.mProjectPanel.Size = new System.Drawing.Size(767, 450); + this.mProjectPanel.Size = new System.Drawing.Size(767, 488); this.mProjectPanel.TabIndex = 4; // - // renameStripToolStripMenuItem + // moveSectionupToolStripMenuItem // - this.renameStripToolStripMenuItem.Name = "renameStripToolStripMenuItem"; - this.renameStripToolStripMenuItem.Size = new System.Drawing.Size(152, 22); - this.renameStripToolStripMenuItem.Text = "&Rename strip"; + this.mMoveSectionUpToolStripMenuItem.Name = "mMoveSectionUpToolStripMenuItem"; + this.mMoveSectionUpToolStripMenuItem.Size = new System.Drawing.Size(196, 22); + this.mMoveSectionUpToolStripMenuItem.Text = "Move section &up"; // // ObiForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(775, 502); + this.ClientSize = new System.Drawing.Size(775, 544); this.Controls.Add(this.mProjectPanel); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.menuStrip1); @@ -380,6 +388,7 @@ private System.Windows.Forms.ToolStripMenuItem mRenameSectionToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem mAddStripToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem renameStripToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mMoveSectionUpToolStripMenuItem; } Modified: trunk/urakawa/application/Obi/Obi/ObiForm.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/ObiForm.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/ObiForm.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -313,6 +313,8 @@ new EventHandler(mProjectPanel.TOCPanel.editLabelToolStripMenuItem_Click); mDeleteSectionToolStripMenuItem.Click += new EventHandler(mProjectPanel.TOCPanel.deleteSectionToolStripMenuItem_Click); + mMoveSectionUpToolStripMenuItem.Click += + new EventHandler(mProjectPanel.TOCPanel.moveUpToolStripMenuItem_Click); mProjectPanel.StripManager.SelectedStrip += new Events.Strip.SelectedHandler(StripManager_Selected); mAddStripToolStripMenuItem.Click += @@ -576,5 +578,7 @@ { toolStripStatusLabel1.Text = Localizer.Message("ready"); } + + } } \ No newline at end of file Modified: trunk/urakawa/application/Obi/Obi/Project.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/Project.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/Project.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -36,11 +36,10 @@ public event Events.Project.StateChangedHandler StateChanged; // the state of the project changed (modified, saved...) public event Events.Sync.AddedSectionNodeHandler AddedSectionNode; // a section node was added to the TOC - public event Events.Sync.AddedChildNodeHandler AddedChildNode; // a new child node was added to the presentation - public event Events.Sync.AddedSiblingNodeHandler AddedSiblingNode; // a new sibling node was added to the presentation public event Events.Sync.DeletedNodeHandler DeletedNode; // a node was deleted from the presentation public event Events.Sync.RenamedNodeHandler RenamedNode; // a node was renamed in the presentation - + public event Events.Sync.MovedNodeUpHandler MovedNodeUp; // a node was moved up in the presentation + public event Events.Sync.MovedNodeDownHandler MovedNodeDown; // a node was moved down in the presentation /// <summary> /// This flag is set to true if the project contains modifications that have not been saved. /// </summary> @@ -351,7 +350,7 @@ StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); } - public void CreateSiblingSectionRequested(object sender, Events.Node.AddSiblingSectionEventArgs e) + public void CreateSiblingSectionRequested(object sender, Events.Node.AddSectionEventArgs e) { System.Diagnostics.Debug.WriteLine("create sibling request from " + sender.ToString() + " with hash: " + sender.GetHashCode()); CreateSiblingSection(sender, e.ContextNode); @@ -372,7 +371,7 @@ StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); } - public void CreateChildSectionRequested(object sender, Events.Node.AddChildSectionEventArgs e) + public void CreateChildSectionRequested(object sender, Events.Node.AddSectionEventArgs e) { CreateChildSection(sender, e.ContextNode); } @@ -414,16 +413,116 @@ /// </summary> public void MoveNodeUp(object origin, CoreNode node) { - // doesn't do much yet - mUnsaved = true; - StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); + //a facade API function could do this for us + bool moveUpSucceeded = ExecuteMoveNodeUpLogic(node); + if (moveUpSucceeded) + { + MovedNodeUp(this, new Events.Sync.MovedNodeEventArgs(origin, node)); + mUnsaved = true; + StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); + } } - public void MoveNodeUpRequested(object sender, Events.Node.MoveSectionUpEventArgs e) + private bool ExecuteMoveNodeUpLogic(CoreNode node) { - MoveNodeUp(sender, e.ContextNode); + CoreNode newParent = null; + int newIndex = 0; + + int currentIndex = ((CoreNode)node.getParent()).indexOf(node); + + //if it is the first node in its list + //change its level and move it to be the previous sibling of its parent + if (currentIndex == 0) + { + //it will be a sibling of its parent (soon to be former parent) + if (node.getParent().getParent() != null) + { + newParent = (CoreNode)node.getParent().getParent(); + + newIndex = newParent.indexOf((CoreNode)node.getParent()); + + } + } + else + { + //keep our current parent + newParent = (CoreNode)node.getParent(); + newIndex = currentIndex - 1; + } + + if (newParent != null) + { + CoreNode movedNode = (CoreNode)node.detach(); + newParent.insert(movedNode, newIndex); + return true; + } + else + { + return false; + } + } + + public void MoveNodeUpRequested(object sender, Events.Node.MoveSectionEventArgs e) + { + MoveNodeUp(sender, e.Node); } + public void MoveNodeDown(object origin, CoreNode node) + { + //a facade API function could do this for us + bool moveDownSucceeded = ExecuteMoveNodeDownLogic(node); + if (moveDownSucceeded) + { + MovedNodeDown(this, new Events.Sync.MovedNodeEventArgs(origin, node)); + mUnsaved = true; + StateChanged(this, new Events.Project.StateChangedEventArgs(Events.Project.StateChange.Modified)); + } + } + + private bool ExecuteMoveNodeDownLogic(CoreNode node) + { + CoreNode newParent = null; + int newIndex = 0; + + int currentIndex = ((CoreNode)node.getParent()).indexOf(node); + + //if it is the last node in its list + //change its level and move it to be the next sibling of its parent + if (currentIndex == node.getParent().getChildCount() - 1) + { + //it will be a sibling of its parent (soon to be former parent) + if (node.getParent().getParent() != null) + { + newParent = (CoreNode)node.getParent().getParent(); + + newIndex = newParent.indexOf((CoreNode)node.getParent()) + 1; + + } + } + else + { + //keep our current parent + newParent = (CoreNode)node.getParent(); + newIndex = currentIndex + 1; + } + + if (newParent != null) + { + CoreNode movedNode = (CoreNode)node.detach(); + newParent.insert(movedNode, newIndex); + return true; + } + else + { + return false; + } + } + + public void MoveNodeDownRequested(object sender, Events.Node.MoveSectionEventArgs e) + { + MoveNodeDown(sender, e.Node); + } + /// <summary> /// Change the text label of a node. /// </summary> @@ -440,6 +539,7 @@ RenameNode(sender, e.Node, e.Label); } + #endregion /// <summary> Modified: trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/UserControls/ProjectPanel.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -42,7 +42,11 @@ //mProject.AddedChildNode -= new Events.Sync.AddedChildNodeHandler(mStripManagerPanel.SyncAddedChildNode); mTOCPanel.MoveSectionUp -= new Events.Node.MoveSectionUpHandler(mProject.MoveNodeUpRequested); + mProject.MovedNodeUp -= new Events.Sync.MovedNodeUpHandler(mTOCPanel.SyncMovedNodeUp); + mTOCPanel.MoveSectionDown -= new Events.Node.MoveSectionDownHandler(mProject.MoveNodeDownRequested); + mProject.MovedNodeDown -= new Events.Sync.MovedNodeDownHandler(mTOCPanel.SyncMovedNodeDown); + mTOCPanel.RenameSection -= new Events.Node.RenameSectionHandler(mProject.RenameNodeRequested); mStripManagerPanel.RenameSection -= new Events.Node.RenameSectionHandler(mProject.RenameNodeRequested); mProject.RenamedNode -= new Events.Sync.RenamedNodeHandler(mTOCPanel.SyncRenamedNode); @@ -50,7 +54,9 @@ mTOCPanel.DeleteSection -= new Events.Node.DeleteSectionHandler(mProject.RemoveNodeRequested); mProject.DeletedNode -= new Events.Sync.DeletedNodeHandler(mTOCPanel.SyncDeletedNode); - mProject.DeletedNode += new Events.Sync.DeletedNodeHandler(mStripManagerPanel.SyncDeletedNode); + + //comment: this used to say += but I think it was a typo + mProject.DeletedNode -= new Events.Sync.DeletedNodeHandler(mStripManagerPanel.SyncDeletedNode); } // Set up the handlers for the new project if (value != null) @@ -58,9 +64,6 @@ mTOCPanel.AddSiblingSection += new Events.Node.AddSiblingSectionHandler(value.CreateSiblingSectionRequested); mStripManagerPanel.AddSiblingSection += new Events.Node.AddSiblingSectionHandler(value.CreateSiblingSectionRequested); - //value.AddedSiblingNode += new Events.Sync.AddedSiblingNodeHandler(mTOCPanel.SyncAddedSiblingNode); - //value.AddedSiblingNode += new Events.Sync.AddedSiblingNodeHandler(mStripManagerPanel.SyncAddedSiblingNode); - value.AddedSectionNode += new Events.Sync.AddedSectionNodeHandler(mTOCPanel.SyncAddedSectionNode); value.AddedSectionNode += new Events.Sync.AddedSectionNodeHandler(mStripManagerPanel.SyncAddedSectionNode); @@ -69,7 +72,11 @@ //value.AddedChildNode += new Events.Sync.AddedChildNodeHandler(mStripManagerPanel.SyncAddedChildNode); mTOCPanel.MoveSectionUp += new Events.Node.MoveSectionUpHandler(value.MoveNodeUpRequested); + value.MovedNodeUp += new Events.Sync.MovedNodeUpHandler(mTOCPanel.SyncMovedNodeUp); + mTOCPanel.MoveSectionDown += new Events.Node.MoveSectionDownHandler(value.MoveNodeDownRequested); + value.MovedNodeDown += new Events.Sync.MovedNodeDownHandler(mTOCPanel.SyncMovedNodeDown); + mTOCPanel.RenameSection += new Events.Node.RenameSectionHandler(value.RenameNodeRequested); mStripManagerPanel.RenameSection += new Events.Node.RenameSectionHandler(value.RenameNodeRequested); value.RenamedNode += new Events.Sync.RenamedNodeHandler(mTOCPanel.SyncRenamedNode); Modified: trunk/urakawa/application/Obi/Obi/UserControls/StripManagerPanel.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/StripManagerPanel.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/UserControls/StripManagerPanel.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -104,7 +104,7 @@ AddStripFromNode(e.Node, e.Position, e.Origin == this); } - internal void SyncAddedSiblingNode(object sender, Events.Sync.AddedSiblingNodeEventArgs e) + /* internal void SyncAddedSiblingNode(object sender, Events.Sync.AddedSiblingNodeEventArgs e) { AddStripFromNode(e.Node, e.Position, e.Origin == this); } @@ -112,7 +112,7 @@ internal void SyncAddedChildNode(object sender, Events.Sync.AddedChildNodeEventArgs e) { AddStripFromNode(e.Node, e.Position, e.Origin == this); - } + }*/ private void AddStripFromNode(CoreNode node, int position, bool rename) { @@ -161,7 +161,7 @@ internal void addStripToolStripMenuItem_Click(object sender, EventArgs e) { - AddSiblingSection(this, new Events.Node.AddSiblingSectionEventArgs(mSelectedNode)); + AddSiblingSection(this, new Events.Node.AddSectionEventArgs(mSelectedNode)); } internal void renameStripToolStripMenuItem_Click(object sender, EventArgs e) Modified: trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs =================================================================== --- trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs 2006-07-25 14:39:02 UTC (rev 656) +++ trunk/urakawa/application/Obi/Obi/UserControls/TOCPanel.cs 2006-07-25 21:04:11 UTC (rev 657) @@ -21,15 +21,13 @@ { public event Events.Node.AddSiblingSectionHandler AddSiblingSection; public event Events.Node.AddChildSectionHandler AddChildSection; - public event Events.Node.BeginEditingSectionHeadingLabelHandler BeginEditingLabel; public event Events.Node.DecreaseSectionLevelHandler DecreaseSectionLevel; public event Events.Node.IncreaseSectionLevelHandler IncreaseSectionLevel; - public event Events.Node.LimitViewToSectionDepthHandler LimitDepthOfView; public event Events.Node.MoveSectionDownHandler MoveSectionDown; public event Events.Node.MoveSectionUpHandler MoveSectionUp; public event Events.Node.RenameSectionHandler RenameSection; public event Events.Node.DeleteSectionHandler DeleteSection; - + /// <summary> /// Test whether a node is currently selected or not. /// </summary> @@ -88,7 +86,7 @@ System.Windows.Forms.TreeNode newTreeNode; if (node.getParent().getParent() != null) { - System.Windows.Forms.TreeNode parentTreeNode = findTreeNodeFromCoreNode((CoreNode)node.getParent()); + System.Windows.Forms.TreeNode parentTreeNode = FindTreeNodeFromCoreNode((CoreNode)node.getParent()); newTreeNode = parentTreeNode.Nodes.Add(node.GetHashCode().ToString(), label); } else @@ -120,115 +118,6 @@ InitializeComponent(); } - - - - - /* - * you might move left if you go up and down - * you won't move right - */ - public void MoveCurrentSectionUp() - { - System.Windows.Forms.TreeNode selected = this.tocTree.SelectedNode; - System.Windows.Forms.TreeNode clone = (System.Windows.Forms.TreeNode) - selected.Clone(); - System.Windows.Forms.TreeNodeCollection siblingCollection = null; - - - if (selected.Parent != null) - { - siblingCollection = selected.Parent.Nodes; - } - else - { - siblingCollection = tocTree.Nodes; - } - - //it is the first node in its list - //change its level and move it to be the previous sibling of its parent - if (selected.Index == 0) - { - if (selected.Parent != null) - { - //it will be a sibling of its parent (soon to be former parent) - if (selected.Parent.Parent != null) - { - siblingCollection = selected.Parent.Parent.Nodes; - } - //it is moving to the outermost level - else - { - siblingCollection = tocTree.Nodes; - } - } - //else it has index = 0 and no parent - //so it's the first node in the tree and can't move up - } - - if (siblingCollection != null) - { - //insert the clone at one above the node to be moved - siblingCollection.Insert(selected.Index - 1, clone); - - //remove the node which was just moved - selected.Remove(); - - tocTree.SelectedNode = clone; - - clone.Expand(); - } - - } - - public void MoveCurrentSectionDown() - { - System.Windows.Forms.TreeNode selected = this.tocTree.SelectedNode; - System.Windows.Forms.TreeNode clone = (System.Windows.Forms.TreeNode) - selected.Clone(); - System.Windows.Forms.TreeNodeCollection siblingCollection = null; - - //get the set of sibling nodes that surround the selected node - if (selected.Parent != null) - { - siblingCollection = selected.Parent.Nodes; - } - else - { - siblingCollection = tocTree.Nodes; - } - - //if this is the last node in its collection - if (selected.Index >= siblingCollection.Count - 1) - { - if (selected.Parent != null) - { - //move it out a level - if (selected.Parent.Parent != null) - { - siblingCollection = selected.Parent.Parent.Nodes; - } - else - { - siblingCollection = tocTree.Nodes; - } - } - } - - if (siblingCollection != null) - { - //insert the clone at one above the node to be moved - siblingCollection.Insert(selected.Index + 2, clone); - - //remove the node which was just moved - selected.Remove(); - - tocTree.SelectedNode = clone; - - clone.Expand(); - } - } - //always allowed until level 1 public void DecreaseCurrentSectionLevel() { @@ -268,7 +157,7 @@ /// <returns>true or false, depending on if the selection was successful</returns> public bool SetSelectedSection(CoreNode node) { - System.Windows.Forms.TreeNode sel = findTreeNodeFromCoreNode(node); + System.Windows.Forms.TreeNode sel = FindTreeNodeFromCoreNode(node); if (sel != null) { @@ -281,6 +170,7 @@ } } + #region context menu handlers /* * *************************************** * These functions "...ToolStripMenuItem_Click" are triggered @@ -297,7 +187,7 @@ System.Diagnostics.Debug.WriteLine("TOC panel click!\n"); AddSiblingSection(this, - new Events.Node.AddSiblingSectionEventArgs(GetSelectedSection())); + new Events.Node.AddSectionEventArgs(GetSelectedSection())); } /// <summary> @@ -306,7 +196,7 @@ internal void addSubSectionToolStripMenuItem_Click(object sender, EventArgs e) { AddChildSection(this, - new Events.Node.AddChildSectionEventArgs(GetSelectedSection())); + new Events.Node.AddSectionEventArgs(GetSelectedSection())); } /// <summary> @@ -315,7 +205,7 @@ internal void moveUpToolStripMenuItem_Click(object sender, EventArgs e) { MoveSectionUp(this, - new Events.Node.MoveSectionUpEventArgs(GetSelectedSection())); + new Events.Node.MoveSectionEventArgs(GetSelectedSection())); } /// <summary> @@ -335,13 +225,13 @@ internal void moveDownToolStripMenuItem_Click(object sender, EventArgs e) { MoveSectionDown(this, - new Events.Node.MoveSectionDownEventArgs(GetSelectedSection())); + new Events.Node.MoveSectionEventArgs(GetSelectedSection())); } internal void increaseLevelToolStripMenuItem_Click(object sender, EventArgs e) { IncreaseSectionLevel(this, - new Events.Node.IncreaseSectionLevelEventArgs(GetSelectedSection())); + new Events.Node.ChangeSectionLevelEventArgs(GetSelectedSection())); } internal void decreaseLevelToolStripMenuItem_Click(object sender, EventArgs e) @@ -350,8 +240,9 @@ sel.BeginEdit(); DecreaseSectionLevel(this, - new Events.Node.DecreaseSectionLevelEventArgs(GetSelectedSection())); + new Events.Node.ChangeSectionLevelEventArgs(GetSelectedSection())); } + #endregion /// <summary> /// The user has edited a label in the tree, so an event is raised to rename the node. @@ -378,85 +269,7 @@ } } - /// <summary> - /// helper function to get a channel based on its name - /// </summary> - /// <param name="node">the node (points to its own presentation)</param> - /// <param name="channelName">the channel name</param> - /// <returns></returns> - private Channel GetChannelByName(CoreNode node, string channelName) - { - ChannelsProperty channelsProp = (ChannelsProperty)node.getProperty(typeof(ChannelsProperty)); - Channel foundChannel = null; - IList channelsList = channelsProp.getListOfUsedChannels(); - - for (int i = 0; i < channelsList.Count; i++) - { - string name = ((IChannel)channelsList[i]).getName(); - if (name == channelName) - { - foundChannel = (Channel)channelsList[i]; - break; - } - } - - return foundChannel; - } - - /// <summary> - /// A helper function to get the <see cref="System.Windows.Forms.TreeNode"/>, given a - /// <see cref="CoreNode"/>. - /// The <see cref="TOCPanel"/> puts the value of <see cref="CoreNode.GetHashCode()"/> - /// into the <see cref="System.Windows.Forms.TreeNode"/> as a key value when it adds a - /// new node to the tree. This function searches the tree view based on key values, and - /// assumes that when they were generated, they came from <see cref="CoreNode.GetHashCode()"/>. - /// </summary> - /// <param name="node"></param> - /// <returns></returns> - private System.Windows.Forms.TreeNode findTreeNodeFromCoreNode(CoreNode node) - { - System.Windows.Forms.TreeNode foundNode = FindTreeNodeWithoutLabel(node); - if (foundNode.Text != Project.GetTextMedia(node).getText()) - { - throw new Exception(String.Format("Found tree node matching core node #{0} but labels mismatch (wanted \"{1}\" but got \"{2}\").", - node.GetHashCode(), Project.GetTextMedia(node).getText(), foundNode.Text)); - } - return foundNode; - } - - /// <summary> - /// Find a tree node for a core node, regardless of its label (used by rename.) - /// </summary> - /// <param name="node">The node to find.</param> - /// <returns>The corresponding tree node.</returns> - private System.Windows.Forms.TreeNode FindTreeNodeWithoutLabel(CoreNode node) - { - System.Windows.Forms.TreeNode foundNode = null; - System.Windows.Forms.TreeNode[] treeNodes - = tocTree.Nodes.Find(node.GetHashCode().ToString(), true); - //(please try to enjoy this long comment:) - //since a key isn't unique and we get a list back from Nodes.Find, - //try to be as sure as possible that it's the same node - //however, this is questionably valuable as it will get more complicated - //as text support improves and as multiple labels are supported on TOC items - for (int i = 0; i < treeNodes.GetLength(0); i++) - { - //check the tag field only - if (treeNodes[i].Tag == node) - { - foundNode = treeNodes[i]; - break; - } - } - // The node must be found, so raise an exception if it couldn't - if (foundNode == null) - { - throw new Exception(String.Format("Could not find tree node matching core node #{0} with label \"{1}\".", - node.GetHashCode(), Project.GetTextMedia(node).getText())); - } - return foundNode; - } - + //trying to figure out which event to call when the tree gets right-clicked //it's really annoying to not have the node get selected when you right click it //because then, menu actions are applied to whichever node *is* selected @@ -469,13 +282,28 @@ #region Sync event handlers + /// <summary> + /// Add a section to the tree view. If we were the ones to request its addition, + /// also start editing its label right now. + /// + /// The new heading has already been created as a <see cref="CoreNode"/>. + /// It is in its correct place in the core tree. + /// Now we need to add it as a <see cref="System.Windows.Forms.TreeNode"/> so + /// it shows up in the tree view. Internally, the new <see cref="System.Windows.Forms.TreeNode"/> + /// is given the key of its <see cref="CoreNode"/> object's hash code. + /// This makes it faster to find a <see cref="System.Windows.Forms.TreeNode"/> + /// based on a given <see cref="CoreNode"/>. + /// </summary> + /// <param name="sender">The sender of this event notification</param> + /// <param name="e"><see cref="e.Node"/> is the new heading to add to the tree</param> + internal void SyncAddedSectionNode(object sender, Events.Sync.AddedSectionNodeEventArgs e) { System.Windows.Forms.TreeNode newTreeNode; string label = Project.GetTextMedia(e.Node).getText(); if (e.Node.getParent().getParent() != null) { - System.Windows.Forms.TreeNode relTreeNode = findTreeNodeFromCoreNode((CoreNode)e.Node.getParent()); + System.Windows.Forms.TreeNode relTreeNode = FindTreeNodeFromCoreNode((CoreNode)e.Node.getParent()); newTreeNode = relTreeNode.Nodes.Insert(e.Index, e.Node.GetHashCode().ToString(), label); } else @@ -494,132 +322,246 @@ } /// <summary> - /// Show the child node that was added in the tree (if it is a section.) - /// If we were the ones to request its addition, also start editing its label right now. - /// - /// The new heading has already been created as a <see cref="CoreNode"/>. It is in its correct - /// place in the core tree. - /// Now we need to add it as a <see cref="System.Windows.Forms.TreeNode"/> so it shows up in the tree view. - /// Internally, the new <see cref="System.Windows.Forms.TreeNode"/> - /// is given the key of its <see cref="CoreNode"/> object's hash code. - /// This makes it faster to find a <see cref="System.Windows.Forms.TreeNode"/> - /// based on a given <see cref="CoreNode"/>. - /// If the relative node is null, then the new node is created as a child of the - /// presentation root. + /// Change the label of the tree view node. + /// This is in response to external renames (i.e. those not originating from within the tree view itself) /// </summary> /// <param name="sender">The sender of this event notification</param> - /// <param name="e"><see cref="e.Node"/> is the new heading to add to the tree</param> - internal void SyncAddedChildNode(object sender, Events.Sync.AddedChildNodeEventArgs e) + /// <param name="e"><see cref="e.Node"/> is the tree node being renamed.</param> + internal void SyncRenamedNode(object sender, Events.Sync.RenamedNodeEventArgs e) { - - System.Windows.Forms.TreeNode newTreeNode; - string label = Project.GetTextMedia(e.Node).getText(); + if (e.Origin != this) + { + System.Windows.Forms.TreeNode treeNode = FindTreeNodeWithoutLabel(e.Node); + treeNode.Text = e.Label; + } + } - System.Diagnostics.Debug.WriteLine("TocPanel: SyncAddedChildNode -- " + label); + /// <summary> + /// Remove a node from the tree view. + /// This will remove the whole subtree. + /// </summary> + /// <param name="sender">The sender of this event notification</param> + /// <param name="e"><see cref="e.Node"/> is the node to be removed.</param> + internal void SyncDeletedNode(object sender, Events.Sync.DeletedNodeEventArgs e) + { + if (e.Node != null) + { + System.Windows.Forms.TreeNode treeNode = FindTreeNodeFromCoreNode(e.Node); + treeNode.Remove(); + } + } - if (e.Node.getParent().getParent() != null) + /// <summary> + /// This function deletes a node and promotes its children to be one level shallower + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + internal void SyncShallowDeletedNode(object sender, Events.Sync.DeletedNodeEventArgs e) + { + } + + /// <summary> + /// Move a tree node up + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + internal void SyncMovedNodeUp(object sender, Events.Sync.MovedNodeEventArgs e) + { + System.Windows.Forms.TreeNode selected = FindTreeNodeFromCoreNode(e.Node); + + System.Windows.Forms.TreeNode clone = (System.Windows.Forms.TreeNode)selected.Clone(); + System.Windows.Forms.TreeNodeCollection siblingCollection = null; + + int newIndex = 0; + + if (selected.Parent != null) { - System.Windows.Forms.TreeNode relTreeNode = findTreeNodeFromCoreNode((CoreNode)e.Node.getParent()); - newTreeNode = relTreeNode.Nodes.Add(e.Node.GetHashCode().ToString(), label); + siblingCollection = selected.Parent.Nodes; } else { - newTreeNode = tocTree.Nodes.Add(e.Node.GetHashCode().ToString(), label); + siblingCollection = tocTree.Nodes; } - newTreeNode.Tag = e.Node; - newTreeNode.ExpandAll(); - newTreeNode.EnsureVisible(); - tocTree.SelectedNode = newTreeNode; - //start editing if the request to add a node happened in the tree view - if (e.Origin.Equals(this)) + //it is the first node in its list + //change its level and move it to be the previous sibling of its parent + if (selected.Index == 0) { - newTreeNode.BeginEdit(); + if (selected.Parent != null) + { + newIndex = selected.Parent.Index; + + //it will be a sibling of its parent (soon to be former parent) + if (selected.Parent.Parent != null) + { + siblingCollection = selected.Parent.Parent.Nodes; + } + //it is moving to the outermost level + else + { + siblingCollection = tocTree.Nodes; + } + } + //else it has index = 0 and no parent + //so it's the first node in the tree and can't move up } + else + { + newIndex = selected.Index - 1; + } + + if (siblingCollection != null) + { + //insert the clone at one above the node to be moved + siblingCollection.Insert(newIndex, clone); + + //remove the node which was just moved + selected.Remove(); + + tocTree.SelectedNode = clone; + + clone.Expand(); + } + } - /// <summary> - /// Add a new heading as an immediate sibling of the relative node. - /// If we were the ones to request its addition, also start editing its label right now. - /// - /// The new heading has already been created as a <see cref="CoreNode"/>. Now we - /// need to add it as a <see cref="System.Windows.Forms.TreeNode"/>. - /// Internally, the new <see cref="System.Windows.Forms.TreeNode"/> - /// is given the key of its <see cref="CoreNode"/> object's hash code. - /// This makes it faster to find a <see cref="System.Windows.Forms.TreeNode"/> - /// based on a given <see cref="CoreNode"/>. - /// A <see cref="CoreNode"/> can always be found from a <see cref="System.Windows.Forms.TreeNode"/> - /// because the <see cref="System.Windows.Forms.TreeNode.Tag"/> field contains a reference to the <see cref="CoreNode"/> - /// </summary> - /// <param name="sender">The sender of this event notification</param> - /// <param name="e"><see cref="e.Node"/> is the new heading to add to the tree, and - /// <see cref="e.ContextNode"/> is the relative sibling node.</param> - /// <remarks>We don't actually need a context node parameter since the core node is already - /// in the correct place in its tree. However, having the parameter doesn't hurt.</remarks> - internal void SyncAddedSiblingNode(object sender, Events.Sync.AddedSiblingNodeEventArgs e) + internal void SyncMovedNodeDown(object sender, Events.Sync.MovedNodeEventArgs e) { - - System.Windows.Forms.TreeNode relTreeNode = findTreeNodeFromCoreNode(e.ContextNode); - string label = Project.GetTextMedia(e.Node).getText(); + System.Windows.Forms.TreeNode selected = FindTreeNodeFromCoreNode(e.Node); + System.Windows.Forms.TreeNode clone = (System.Windows.Forms.TreeNode) + selected.Clone(); + System.Windows.Forms.TreeNodeCollection siblingCollection = null; - System.Diagnostics.Debug.WriteLine("TocPanel: SyncAddedSiblingNode -- " + label); + int newIndex = 0; - //add as a sibling - System.Windows.Forms.TreeNodeCollection siblingCollection = null; - if (relTreeNode.Parent != null) + //get the set of sibling nodes that surround the selected node + if (selected.Parent != null) { - siblingCollection = relTreeNode.Parent.Nodes; + siblingCollection = selected.Parent.Nodes; } else { siblingCollection = tocTree.Nodes; } - System.Windows.Forms.TreeNode newTreeNode = - siblingCollection.Insert - (relTreeNode.Index + 1, e.Node.GetHashCode().ToString(), label); - newTreeNode.Tag = e.Node; - newTreeNode.ExpandAll(); - newTreeNode.EnsureVisible(); - tocTree.SelectedNode = newTreeNode; - //start editing if the request to add a node happened in the tree view - if (e.Origin.Equals(this)) + //if this is the last node in its collection + if (selected.Index >= siblingCollection.Count - 1) { - newTreeNode.BeginEdit(); + if (selected.Parent != null) + { + newIndex = selected.Parent.Index + 1; + + //move it out a level + if (selected.Parent.Parent != null) + { + siblingCollection = selected.Parent.Parent.Nodes; + } + else + { + siblingCollection = tocTree.Nodes; + } + } } + else + { + newIndex = selected.Index + 2; + } + + if (siblingCollection != null) + { + //insert the clone at one above the node to be moved + siblingCollection.Insert(newIndex, clone); + + //remove the node which was just moved + selected.Remove(); + + tocTree.SelectedNode = clone; + + clone.Expand(); + } } + #endregion + + #region helper functions /// <summary> - /// Change the label of the tree view node. - /// This is in response to external renames (i.e. those not originating from within the tree view itself) + /// helper function to get a channel based on its name /// </summary> - /// <param name="sender">The sender of this event notification</param> - /// <param name="e"><see cref="e.Node"/> is the tree node being renamed.</param> - internal void SyncRenamedNode(object sender, Events.Sync.RenamedNodeEventArgs e) + /// <param name="node">the node (points to its own presentation)</param> + /// <param name="channelName">the channel name</param> + /// <returns></returns> + private Channel GetChannelByName(CoreNode node, string channelName) { - if (e.Origin != this) + ChannelsProperty channelsProp = (ChannelsProperty)node.getProperty(typeof(ChannelsProperty)); + Channel foundChannel = null; + IList channelsList = channelsProp.getListOfUsedChannels(); + + for (int i = 0; i < channelsList.Count; i++) { - System.Windows.Forms.TreeNode treeNode = FindTreeNodeWithoutLabel(e.Node); - treeNode.Text = e.Label; + string name = ((IChannel)channelsList[i]).getName(); + if (name == channelName) + { + foundChannel = (Channel)channelsList[i]; + break; + } } + + return foundChannel; } /// <summary> - /// Remove a node from the tree view. - /// This will remove the whole subtree. + /// A helper function to get the <see cref="System.Windows.Forms.TreeNode"/>, given a + /// <see cref="CoreNode"/>. + /// The <see cref="TOCPanel"/> puts the value of <see cref="CoreNode.GetHashCode()"/> + /// into the <see cref="System.Windows.Forms.TreeNode"/> as a key value when it adds a + /// new node to the tree. This function searches the tree view based on key values, and + /// assumes that when they were generated, they came from <see cref="CoreNode.GetHashCode()"/>. /// </summary> - /// <param name="sender">The sender of this event notification</param> - /// <param name="e"><see cref="e.Node"/> is the node to be removed.</param> - internal void SyncDeletedNode(object sender, Events.Sync.DeletedNodeEventArgs e) + /// <param name="node"></param> + /// <returns></returns> + private System.Windows.Forms.TreeNode FindTreeN... [truncated message content] |