diff options
author | Pavlos Touboulidis <pavlos256@gmail.com> | 2011-11-27 04:53:09 +0400 |
---|---|---|
committer | Pavlos Touboulidis <pavlos256@gmail.com> | 2011-11-27 04:53:09 +0400 |
commit | 1ca7e9ed13c19ed486a935520108ea97b78af67b (patch) | |
tree | ce02149243c28c29ef549ed6704202b2ee975577 | |
parent | 41eb50f540d83e9b275f6e0d2086087d4b9d64fb (diff) |
Fixed 'Bug 627 - When renaming a file, only select the name and not the extension'
3 files changed, 47 insertions, 1 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs index 4278258cde..5220e7fd4d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs @@ -211,6 +211,7 @@ namespace MonoDevelop.Ide.Gui.Components } text_render.Ypad = 0; IdeApp.Preferences.CustomPadFontChanged += CustomFontPropertyChanged;; + text_render.EditingStarted += HandleEditingStarted; text_render.Edited += HandleOnEdit; text_render.EditingCanceled += HandleOnEditCancelled; @@ -1171,19 +1172,52 @@ namespace MonoDevelop.Ide.Gui.Components node.ExpandToNode (); //make sure the parent of the node that is being edited is expanded - store.SetValue (iter, ExtensibleTreeView.TextColumn, node.NodeName); + string nodeName = node.NodeName; + store.SetValue (iter, ExtensibleTreeView.TextColumn, nodeName); + // Get and validate the initial text selection + int nameLength = nodeName != null ? nodeName.Length : 0, + selectionStart = 0, selectionLength = nameLength; + foreach (NodeBuilder b in node.NodeBuilderChain) { + try { + NodeCommandHandler handler = b.CommandHandler; + handler.SetCurrentNode(node); + handler.OnRenameStarting(ref selectionStart, ref selectionLength); + } catch (Exception ex) { + LoggingService.LogError (ex.ToString ()); + } + } + if (selectionStart < 0 || selectionStart >= nameLength) + selectionStart = 0; + if (selectionStart + selectionLength > nameLength) + selectionLength = nameLength - selectionStart; + // This will apply the selection as soon as possible + GLib.Idle.Add (() => { + var editable = currentLabelEditable; + if (editable == null) + return false; + + editable.SelectRegion (selectionStart, selectionStart + selectionLength); + return false; + }); text_render.Editable = true; tree.SetCursor (store.GetPath (iter), complete_column, true); editingText = true; } + Gtk.Editable currentLabelEditable; + void HandleEditingStarted (object o, Gtk.EditingStartedArgs e) + { + currentLabelEditable = e.Editable as Gtk.Entry; + } + void HandleOnEdit (object o, Gtk.EditedArgs e) { try { editingText = false; text_render.Editable = false; + currentLabelEditable = null; Gtk.TreeIter iter; if (!store.GetIterFromString (out iter, e.Path)) @@ -1227,6 +1261,7 @@ namespace MonoDevelop.Ide.Gui.Components { editingText = false; text_render.Editable = false; + currentLabelEditable = null; TreeNodeNavigator node = (TreeNodeNavigator) GetSelectedNode (); if (node == null) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs index 9e7efa2362..bf5ad2227a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs @@ -86,6 +86,10 @@ namespace MonoDevelop.Ide.Gui.Components get { return tree; } } + public virtual void OnRenameStarting (ref int selectionStart, ref int selectionLength) + { + } + public virtual void RenameItem (string newName) { } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs index 81010e6413..d1ee44287a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs @@ -137,6 +137,13 @@ namespace MonoDevelop.Ide.Gui.Pads.ProjectPad public class ProjectFileNodeCommandHandler: NodeCommandHandler { + public override void OnRenameStarting (ref int selectionStart, ref int selectionLength) + { + string name = CurrentNode.NodeName; + selectionStart = 0; + selectionLength = Path.GetFileNameWithoutExtension(name).Length; + } + public override void RenameItem (string newName) { ProjectFile file = (ProjectFile) CurrentNode.DataItem; |