Browse Source

Fixed SD2-661: Project browser cannot be navigated with keyboard

Fixed SD2-578: Changing the "Name" property in the designer does not change the form class name

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1054 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
fdad3d05d5
  1. 6
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs
  2. 25
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs
  3. 21
      src/Main/Base/Project/Src/Gui/Components/ExtTreeView/ExtTreeView.cs
  4. 71
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs
  5. 14
      src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs
  6. 2
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs

6
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs

@ -153,6 +153,12 @@ namespace ICSharpCode.FormsDesigner
throw new InvalidOperationException("InitializeComponent method not found in framework-generated CodeDom."); throw new InvalidOperationException("InitializeComponent method not found in framework-generated CodeDom.");
} }
if (formClass.Name != this.formClass.Name) {
LoggingService.Info("Renaming form to " + formClass.Name);
ICSharpCode.SharpDevelop.DefaultEditor.Commands.ClassBookmarkMenuBuilder.RenameClass(this.formClass, formClass.Name);
Reparse();
}
// generate file and get initialize components string // generate file and get initialize components string
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
CodeDOMGenerator domGenerator = new CodeDOMGenerator(this.CodeDomProvider, tabs + '\t'); CodeDOMGenerator domGenerator = new CodeDOMGenerator(this.CodeDomProvider, tabs + '\t');

25
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DocumentFactory.cs

@ -24,14 +24,25 @@ namespace ICSharpCode.TextEditor.Document
public IDocument CreateDocument() public IDocument CreateDocument()
{ {
DefaultDocument doc = new DefaultDocument(); DefaultDocument doc = new DefaultDocument();
doc.TextBufferStrategy = new GapTextBufferStrategy(); doc.TextBufferStrategy = new GapTextBufferStrategy();
doc.FormattingStrategy = new DefaultFormattingStrategy(); doc.FormattingStrategy = new DefaultFormattingStrategy();
doc.LineManager = new DefaultLineManager(doc, null); doc.LineManager = new DefaultLineManager(doc, null);
doc.FoldingManager = new FoldingManager(doc, doc.LineManager); doc.FoldingManager = new FoldingManager(doc, doc.LineManager);
doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy(); doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy();
doc.MarkerStrategy = new MarkerStrategy(doc); doc.MarkerStrategy = new MarkerStrategy(doc);
doc.BookmarkManager = new BookmarkManager(doc, doc.LineManager); doc.BookmarkManager = new BookmarkManager(doc, doc.LineManager);
doc.CustomLineManager = new CustomLineManager(doc.LineManager); doc.CustomLineManager = new CustomLineManager(doc.LineManager);
return doc;
}
/// <summary>
/// Creates a new document and loads the given file
/// </summary>
public IDocument CreateFromTextBuffer(ITextBufferStrategy textBuffer)
{
DefaultDocument doc = (DefaultDocument)CreateDocument();
doc.TextContent = textBuffer.GetText(0, textBuffer.Length);
doc.TextBufferStrategy = textBuffer;
return doc; return doc;
} }

21
src/Main/Base/Project/Src/Gui/Components/ExtTreeView/ExtTreeView.cs

@ -132,13 +132,6 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
void ActivateSelectedItem()
{
ExtTreeNode node = SelectedNode as ExtTreeNode;
if (node != null) {
node.ActivateItem();
}
}
#region label editing #region label editing
public void StartLabelEdit(ExtTreeNode node) public void StartLabelEdit(ExtTreeNode node)
@ -226,15 +219,21 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
base.OnKeyPress(e); base.OnKeyPress(e);
if (e.KeyChar == '\r') { if (e.KeyChar == '\r') {
ActivateSelectedItem(); ExtTreeNode node = SelectedNode as ExtTreeNode;
if (node != null) {
node.ActivateItem();
}
e.Handled = true; e.Handled = true;
} }
} }
protected override void OnDoubleClick(EventArgs e) protected override void OnMouseDoubleClick(MouseEventArgs e)
{ {
base.OnDoubleClick(e); base.OnMouseDoubleClick(e);
ActivateSelectedItem(); ExtTreeNode node = GetNodeAt(e.Location) as ExtTreeNode;
if (node != null) {
node.ActivateItem();
}
} }
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)

71
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs

@ -111,7 +111,7 @@ namespace ICSharpCode.SharpDevelop.Project
ViewSolution(((AbstractProjectBrowserTreeNode)treeView.Nodes[0]).Solution); ViewSolution(((AbstractProjectBrowserTreeNode)treeView.Nodes[0]).Solution);
} }
} }
FileNode FindFileNode(TreeNodeCollection nodes, string fileName) FileNode FindFileNode(TreeNodeCollection nodes, string fileName)
{ {
FileNode fn; FileNode fn;
@ -143,7 +143,7 @@ namespace ICSharpCode.SharpDevelop.Project
// stores the fileName of the last selected target so // stores the fileName of the last selected target so
// that we can select it again on opening a folder // that we can select it again on opening a folder
string lastSelectionTarget; string lastSelectionTarget;
/// <summary> /// <summary>
/// Selects the deepest node open on the path to a particular file. /// Selects the deepest node open on the path to a particular file.
/// </summary> /// </summary>
@ -170,7 +170,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
#region SelectDeepestOpenNode internals #region SelectDeepestOpenNode internals
// //
// SolutionNode RootSolutionNode { // SolutionNode RootSolutionNode {
// get { // get {
// if (treeView.Nodes != null && treeView.Nodes.Count>0) { // if (treeView.Nodes != null && treeView.Nodes.Count>0) {
@ -179,38 +179,46 @@ namespace ICSharpCode.SharpDevelop.Project
// return null; // return null;
// } // }
// } // }
// //
void SelectDeepestOpenNodeForPath(string fileName) void SelectDeepestOpenNodeForPath(string fileName)
{ {
LoggingService.DebugFormatted("Selecting Deepest for '{0}'", fileName); TreeNode node = FindDeepestOpenNodeForPath(fileName);
if (node != null) {
treeView.SelectedNode = node;
}
}
TreeNode FindDeepestOpenNodeForPath(string fileName)
{
LoggingService.DebugFormatted("Finding Deepest for '{0}'", fileName);
Solution solution = ProjectService.OpenSolution; Solution solution = ProjectService.OpenSolution;
if (solution == null) { if (solution == null) {
return; return null;
} }
IProject project = solution.FindProjectContainingFile(fileName); IProject project = solution.FindProjectContainingFile(fileName);
if (project == null) { if (project == null) {
LoggingService.Debug("no IProject found"); LoggingService.Debug("no IProject found");
return; return null;
} }
string relativePath = String.Empty; string relativePath = String.Empty;
TreeNode targetNode = FindProjectNode(project); TreeNode targetNode = FindProjectNode(project);
if (targetNode == null) { if (targetNode == null) {
// our project node is not yet created, // our project node is not yet created,
// so start at the root and work down. // so start at the root and work down.
if (treeView.Nodes == null || treeView.Nodes.Count<1) { if (treeView.Nodes == null || treeView.Nodes.Count<1) {
// the treeView is not yet prepared to assist in this request. // the treeView is not yet prepared to assist in this request.
return; return null;
} else { } else {
targetNode = treeView.Nodes[0]; targetNode = treeView.Nodes[0];
if (fileName.StartsWith(solution.Directory)) { if (fileName.StartsWith(solution.Directory)) {
relativePath = fileName.Replace(solution.Directory, ""); relativePath = fileName.Replace(solution.Directory, "");
} }
} }
} else { } else {
@ -228,8 +236,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (t != targetNode) { if (t != targetNode) {
// project node is instantiated but not visible // project node is instantiated but not visible
// so select the most visible parent node. // so select the most visible parent node.
treeView.SelectedNode = t; return t;
return;
} else { } else {
// project node is instantiated and visible // project node is instantiated and visible
@ -243,9 +250,8 @@ namespace ICSharpCode.SharpDevelop.Project
if (!targetNode.IsExpanded) { if (!targetNode.IsExpanded) {
// the targetNode is not expanded so it's as deep as we can go // the targetNode is not expanded so it's as deep as we can go
treeView.SelectedNode = targetNode;
LoggingService.DebugFormatted("target node '{0};{1}' is not expanded.", targetNode, targetNode.Text); LoggingService.DebugFormatted("target node '{0};{1}' is not expanded.", targetNode, targetNode.Text);
return; return targetNode;
} }
LoggingService.Debug("entering depth loop..."); LoggingService.Debug("entering depth loop...");
@ -258,6 +264,10 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Debug("-- looking for: "+target); LoggingService.Debug("-- looking for: "+target);
nextNode = null; nextNode = null;
foreach (TreeNode node in targetNode.Nodes) { foreach (TreeNode node in targetNode.Nodes) {
if (node == null) {
// can happen when the node is currently expanding
continue;
}
if (node.Text == target) { if (node.Text == target) {
nextNode = node; nextNode = node;
break; break;
@ -270,7 +280,7 @@ namespace ICSharpCode.SharpDevelop.Project
targetNode = nextNode; targetNode = nextNode;
} }
} }
treeView.SelectedNode = targetNode; return targetNode;
} }
ProjectNode FindProjectNode(IProject project) ProjectNode FindProjectNode(IProject project)
@ -296,17 +306,17 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
pn = FindProjectNodeByName(node.Nodes, projectName); pn = FindProjectNodeByName(node.Nodes, projectName);
if (pn != null) if (pn != null)
return pn; return pn;
} }
return null; return null;
} }
// TODO: remove this debug code // TODO: remove this debug code
// void LogTreeViewPaths(TreeNodeCollection nodes, int depth) // void LogTreeViewPaths(TreeNodeCollection nodes, int depth)
// { // {
// System.Text.StringBuilder sb = null; // System.Text.StringBuilder sb = null;
// //
// foreach (TreeNode node in nodes) { // foreach (TreeNode node in nodes) {
// sb = new System.Text.StringBuilder(); // sb = new System.Text.StringBuilder();
// for(int i = 0; i<depth; i++) { // for(int i = 0; i<depth; i++) {
@ -348,15 +358,24 @@ namespace ICSharpCode.SharpDevelop.Project
} }
void TreeViewAfterExpand(object sender, TreeViewEventArgs e) void TreeViewAfterExpand(object sender, TreeViewEventArgs e)
{ // attempt to restore the last selection if its path has been reexpanded {
// attempt to restore the last selection if its path has been reexpanded
if (lastSelectionTarget != null) { if (lastSelectionTarget != null) {
SelectFile(lastSelectionTarget); TreeNode node = FindDeepestOpenNodeForPath(lastSelectionTarget);
while (node != null) {
if (node.Parent == e.Node) {
treeView.SelectedNode = node;
break;
} else {
node = node.Parent;
}
}
} }
} }
void TreeViewBeforeSelect(object sender, TreeViewCancelEventArgs e) void TreeViewBeforeSelect(object sender, TreeViewCancelEventArgs e)
{ // set current project & current combine {
// set current project & current combine
AbstractProjectBrowserTreeNode node = e.Node as AbstractProjectBrowserTreeNode; AbstractProjectBrowserTreeNode node = e.Node as AbstractProjectBrowserTreeNode;
if (node == null) { if (node == null) {
return; return;

14
src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs

@ -138,10 +138,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{ {
MenuCommand item = (MenuCommand)sender; MenuCommand item = (MenuCommand)sender;
IClass c = (IClass)item.Tag; IClass c = (IClass)item.Tag;
c = c.DefaultReturnType.GetUnderlyingClass(); // get compound class if class is partial
string newName = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:SharpDevelop.Refactoring.RenameClassText}", c.Name); string newName = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:SharpDevelop.Refactoring.RenameClassText}", c.Name);
if (!FindReferencesAndRenameHelper.CheckName(newName, c.Name)) return; if (!FindReferencesAndRenameHelper.CheckName(newName, c.Name)) return;
RenameClass(c, newName);
}
public static void RenameClass(IClass c, string newName)
{
c = c.DefaultReturnType.GetUnderlyingClass(); // get compound class if class is partial
List<Reference> list = RefactoringService.FindReferences(c, null); List<Reference> list = RefactoringService.FindReferences(c, null);
if (list == null) return; if (list == null) return;
@ -160,12 +166,12 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
FindReferencesAndRenameHelper.RenameReferences(list, newName); FindReferencesAndRenameHelper.RenameReferences(list, newName);
} }
void AddDeclarationAsReference(List<Reference> list, string fileName, DomRegion region, string name) static void AddDeclarationAsReference(List<Reference> list, string fileName, DomRegion region, string name)
{ {
if (fileName == null) if (fileName == null)
return; return;
ProvidedDocumentInformation documentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(fileName); ProvidedDocumentInformation documentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(fileName);
int offset = documentInformation.Document.PositionToOffset(new Point(region.BeginColumn - 1, region.BeginLine - 1)); int offset = documentInformation.CreateDocument().PositionToOffset(new Point(region.BeginColumn - 1, region.BeginLine - 1));
string text = documentInformation.TextBuffer.GetText(offset, Math.Min(name.Length + 30, documentInformation.TextBuffer.Length - offset - 1)); string text = documentInformation.TextBuffer.GetText(offset, Math.Min(name.Length + 30, documentInformation.TextBuffer.Length - offset - 1));
int offsetChange = text.IndexOf(name); int offsetChange = text.IndexOf(name);
if (offsetChange < 0) if (offsetChange < 0)
@ -178,7 +184,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
list.Add(new Reference(fileName, offset, name.Length, name, null)); list.Add(new Reference(fileName, offset, name.Length, name, null));
} }
List<IClass> GetClassParts(IClass c) static List<IClass> GetClassParts(IClass c)
{ {
List<IClass> list; List<IClass> list;
CompoundClass cc = c as CompoundClass; CompoundClass cc = c as CompoundClass;

2
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/DocumentIterator/ProvidedDocumentInformation.cs

@ -88,7 +88,7 @@ namespace SearchAndReplace
if (document != null) { if (document != null) {
return document; return document;
} }
return new DocumentFactory().CreateFromFile(fileName); return new DocumentFactory().CreateFromTextBuffer(textBuffer);
} }
public ProvidedDocumentInformation(IDocument document, string fileName, int currentOffset) public ProvidedDocumentInformation(IDocument document, string fileName, int currentOffset)

Loading…
Cancel
Save