Browse Source

Implemented "rename" refactoring.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@150 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
869779a47c
  1. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 53
      src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs
  3. 0
      src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs
  4. 9
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  5. 36
      src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs
  6. 1
      src/Main/Core/Project/ICSharpCode.Core.csproj
  7. 151
      src/Main/Core/Project/Src/Services/MessageService/InputBox.cs
  8. 10
      src/Main/Core/Project/Src/Services/MessageService/MessageService.cs

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -425,7 +425,7 @@
<Compile Include="Src\Gui\Pads\ErrorList\ErrorList.cs" /> <Compile Include="Src\Gui\Pads\ErrorList\ErrorList.cs" />
<Compile Include="Src\Gui\Pads\ErrorList\ErrorListToolbarCommands.cs" /> <Compile Include="Src\Gui\Pads\ErrorList\ErrorListToolbarCommands.cs" />
<Compile Include="Src\Gui\Pads\CompilerMessageView\CompulerMessageViewToolbarCommands.cs" /> <Compile Include="Src\Gui\Pads\CompilerMessageView\CompulerMessageViewToolbarCommands.cs" />
<Compile Include="Src\Services\ParserService\CaseSensitiveProjectContent.cs" /> <Compile Include="Src\Services\ParserService\DefaultProjectContent.cs" />
<Compile Include="Src\Services\ParserService\IProjectContent.cs" /> <Compile Include="Src\Services\ParserService\IProjectContent.cs" />
<Compile Include="Src\Gui\Pads\ClassBrowser\ClassBrowser.cs" /> <Compile Include="Src\Gui\Pads\ClassBrowser\ClassBrowser.cs" />
<Compile Include="Src\Gui\Pads\ClassBrowser\ClassBrowserToolbarCommands.cs" /> <Compile Include="Src\Gui\Pads\ClassBrowser\ClassBrowserToolbarCommands.cs" />

53
src/Main/Base/Project/Src/Commands/ClassMemberMenuBuilder.cs

@ -75,11 +75,62 @@ namespace ICSharpCode.SharpDevelop.Commands
} }
} }
private struct Modification {
public IDocument Document;
public int Offset;
public int LengthDifference;
public Modification(IDocument Document, int Offset, int LengthDifference)
{
this.Document = Document;
this.Offset = Offset;
this.LengthDifference = LengthDifference;
}
}
void Rename(object sender, EventArgs e) void Rename(object sender, EventArgs e)
{ {
MenuCommand item = (MenuCommand)sender; MenuCommand item = (MenuCommand)sender;
IMember member = (IMember)item.Tag; IMember member = (IMember)item.Tag;
MessageService.ShowMessage("Not implemented."); string newName = MessageService.ShowInputBox("Rename", "Enter the new name of the member", member.Name);
if (newName == null || newName.Length == 0) return;
List<Reference> list = RefactoringService.FindReferences(member, null);
if (list == null) return;
List<IViewContent> modifiedContents = new List<IViewContent>();
List<Modification> modifications = new List<Modification>();
foreach (Reference r in list) {
FileService.OpenFile(r.FileName);
IViewContent viewContent = FileService.GetOpenFile(r.FileName).ViewContent;
if (!modifiedContents.Contains(viewContent)) {
modifiedContents.Add(viewContent);
}
ITextEditorControlProvider p = viewContent as ITextEditorControlProvider;
if (p != null) {
IDocument doc = p.TextEditorControl.Document;
int offset = r.Offset;
foreach (Modification m in modifications) {
if (m.Document != doc) continue;
if (m.Offset < offset) offset += m.LengthDifference;
}
int lengthDifference = newName.Length - r.Length;
doc.Replace(offset, r.Length, newName);
if (lengthDifference != 0) {
for (int i = 0; i < modifications.Count; ++i) {
Modification m = modifications[i];
if (m.Document != doc) continue;
if (m.Offset > offset) {
m.Offset += lengthDifference;
modifications[i] = m; // Modification is a value type
}
}
modifications.Add(new Modification(doc, offset, lengthDifference));
}
}
}
foreach (IViewContent viewContent in modifiedContents) {
ParserService.ParseViewContent(viewContent);
}
} }
void FindOverrides(object sender, EventArgs e) void FindOverrides(object sender, EventArgs e)

0
src/Main/Base/Project/Src/Services/ParserService/CaseSensitiveProjectContent.cs → src/Main/Base/Project/Src/Services/ParserService/DefaultProjectContent.cs

9
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -248,6 +248,15 @@ namespace ICSharpCode.Core
} }
} }
public static void ParseViewContent(IViewContent viewContent)
{
string text = ((IEditable)viewContent).Text;
ParseInformation parseInformation = ParseFile(viewContent.FileName, text, !viewContent.IsUntitled, true);
if (parseInformation != null && viewContent is IParseInformationListener) {
((IParseInformationListener)viewContent).ParseInformationUpdated(parseInformation);
}
}
public static event ParserUpdateStepEventHandler ParserUpdateStepFinished; public static event ParserUpdateStepEventHandler ParserUpdateStepFinished;
static void OnParserUpdateStepFinished(ParserUpdateStepEventArgs e) static void OnParserUpdateStepFinished(ParserUpdateStepEventArgs e)

36
src/Main/Base/Project/Src/Services/ProjectService/ParseableFileContentEnumerator.cs

@ -11,6 +11,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project namespace ICSharpCode.SharpDevelop.Project
{ {
@ -76,11 +77,14 @@ namespace ICSharpCode.SharpDevelop.Project
string GetParseableFileContent(IProject project, string fileName) string GetParseableFileContent(IProject project, string fileName)
{ {
//Console.WriteLine("Reading {0} from disk", fileName);
// Loading the source files is done asynchronously: // Loading the source files is done asynchronously:
// While one file is parsed, the next is already loaded from disk. // While one file is parsed, the next is already loaded from disk.
string res = project.GetParseableFileContent(fileName); string res = project.GetParseableFileContent(fileName);
if (res != null) if (res != null)
return res; return res;
// load file // load file
using (StreamReader r = new StreamReader(fileName, getParseableContentEncoding)) { using (StreamReader r = new StreamReader(fileName, getParseableContentEncoding)) {
return r.ReadToEnd(); return r.ReadToEnd();
@ -110,18 +114,38 @@ namespace ICSharpCode.SharpDevelop.Project
if (item == null) return false; if (item == null) return false;
if (item.ItemType != ItemType.Compile) if (item.ItemType != ItemType.Compile)
return MoveNext(); return MoveNext();
string fileName = item.FileName;
string fileContent; string fileContent;
if (res != null) if (res != null) {
fileContent = pcd.EndInvoke(res); fileContent = pcd.EndInvoke(res);
else } else {
fileContent = GetParseableFileContent(item.Project, fileName); fileContent = GetFileContent(item);
if (nextItem != null && nextItem.ItemType == ItemType.Compile) }
if (nextItem != null && nextItem.ItemType == ItemType.Compile && CanReadAsync(nextItem))
res = pcd.BeginInvoke(nextItem.Project, nextItem.FileName, null, null); res = pcd.BeginInvoke(nextItem.Project, nextItem.FileName, null, null);
else else
res = null; res = null;
current = new KeyValuePair<string, string>(fileName, fileContent); current = new KeyValuePair<string, string>(item.FileName, fileContent);
return true; return true;
} }
string GetFileContent(ProjectItem item)
{
string fileName = item.FileName;
IWorkbenchWindow window = FileService.GetOpenFile(fileName);
if (window != null) {
IViewContent viewContent = window.ViewContent;
IEditable editable = viewContent as IEditable;
if (editable != null) {
//Console.WriteLine("Reading {0} from editable", fileName);
return editable.Text;
}
}
return GetParseableFileContent(item.Project, fileName);
}
bool CanReadAsync(ProjectItem item)
{
return !FileService.IsOpen(item.FileName);
}
} }
} }

1
src/Main/Core/Project/ICSharpCode.Core.csproj

@ -123,6 +123,7 @@
<Compile Include="Src\Util\AbstractCommand.cs" /> <Compile Include="Src\Util\AbstractCommand.cs" />
<Compile Include="Src\Util\ICommand.cs" /> <Compile Include="Src\Util\ICommand.cs" />
<Compile Include="Src\Util\RightToLeftConverter.cs" /> <Compile Include="Src\Util\RightToLeftConverter.cs" />
<Compile Include="Src\Services\MessageService\InputBox.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project> </Project>

151
src/Main/Core/Project/Src/Services/MessageService/InputBox.cs

@ -0,0 +1,151 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version value="$version"/>
// </file>
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ICSharpCode.Core
{
/// <summary>
/// Description of InputBox.
/// </summary>
internal class InputBox : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.TextBox textBox;
private System.Windows.Forms.Button acceptButton;
public InputBox(string text, string caption, string defaultValue)
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
text = StringParser.Parse(text);
this.Text = StringParser.Parse(caption);
acceptButton.Text = StringParser.Parse("${res:Global.OKButtonText}");
cancelButton.Text = StringParser.Parse("${res:Global.CancelButtonText}");
Size size;
using (Graphics g = this.CreateGraphics()) {
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
SizeF sizeF = g.MeasureString(text, label.Font, screen.Width - 20);
size = sizeF.ToSize();
size.Width += 4;
}
if (size.Width < 200)
size.Width = 200;
Size clientSize = this.ClientSize;
clientSize.Width += size.Width - label.Width;
clientSize.Height += size.Height - label.Height;
this.ClientSize = clientSize;
label.Text = text;
textBox.Text = defaultValue;
this.DialogResult = DialogResult.Cancel;
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.acceptButton = new System.Windows.Forms.Button();
this.textBox = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.Button();
this.label = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// acceptButton
//
this.acceptButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.acceptButton.Location = new System.Drawing.Point(176, 114);
this.acceptButton.Name = "acceptButton";
this.acceptButton.TabIndex = 2;
this.acceptButton.Text = "OK";
this.acceptButton.Click += new System.EventHandler(this.AcceptButtonClick);
//
// textBox
//
this.textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox.Location = new System.Drawing.Point(8, 86);
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(318, 20);
this.textBox.TabIndex = 1;
this.textBox.Text = "";
//
// cancelButton
//
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cancelButton.Location = new System.Drawing.Point(256, 114);
this.cancelButton.Name = "cancelButton";
this.cancelButton.TabIndex = 3;
this.cancelButton.Text = "Cancel";
this.cancelButton.Click += new System.EventHandler(this.CancelButtonClick);
//
// label
//
this.label.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label.Location = new System.Drawing.Point(8, 8);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(328, 74);
this.label.TabIndex = 0;
this.label.UseMnemonic = false;
//
// InputBox
//
this.AcceptButton = this.acceptButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(338, 144);
this.Controls.Add(this.textBox);
this.Controls.Add(this.label);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.acceptButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputBox";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "InputBox";
this.ResumeLayout(false);
}
#endregion
void CancelButtonClick(object sender, System.EventArgs e)
{
result = null;
this.Close();
}
void AcceptButtonClick(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
result = textBox.Text;
this.Close();
}
string result;
public string Result {
get {
return result;
}
}
}
}

10
src/Main/Core/Project/Src/Services/MessageService/MessageService.cs

@ -115,12 +115,20 @@ namespace ICSharpCode.Core
return messageBox.Result; return messageBox.Result;
} }
} }
public static int ShowCustomDialog(string caption, string dialogText, params string[] buttontexts) public static int ShowCustomDialog(string caption, string dialogText, params string[] buttontexts)
{ {
return ShowCustomDialog(caption, dialogText, -1, -1, buttontexts); return ShowCustomDialog(caption, dialogText, -1, -1, buttontexts);
} }
public static string ShowInputBox(string caption, string dialogText, string defaultValue)
{
using (InputBox inputBox = new InputBox(dialogText, caption, defaultValue)) {
inputBox.ShowDialog(MessageService.MainForm);
return inputBox.Result;
}
}
public static void ShowMessage(string message) public static void ShowMessage(string message)
{ {
ShowMessage(message, "SharpDevelop"); ShowMessage(message, "SharpDevelop");

Loading…
Cancel
Save