Browse Source

Fixed SD2-1461 (Exception when renaming form) and other issues with renaming forms.

With the new view content system we must not switch views during a save operation.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3556 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 18 years ago
parent
commit
22b9e89c87
  1. 5
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs
  2. 10
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs
  3. 7
      src/Main/Base/Project/Src/Gui/IWorkbench.cs
  4. 4
      src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs
  5. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs
  6. 11
      src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs
  7. 30
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs
  8. 7
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs
  9. 5
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/SimpleWorkbenchLayout.cs
  10. 32
      src/Main/Base/Project/Src/Services/File/FileService.cs
  11. 52
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

5
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs

@ -94,6 +94,11 @@ namespace PythonBinding.Tests.Utils @@ -94,6 +94,11 @@ namespace PythonBinding.Tests.Utils
throw new NotImplementedException();
}
public void ShowView(IViewContent content, bool switchToOpenedView)
{
throw new NotImplementedException();
}
public void ShowPad(PadDescriptor content)
{
throw new NotImplementedException();

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

@ -192,7 +192,15 @@ namespace ICSharpCode.FormsDesigner @@ -192,7 +192,15 @@ namespace ICSharpCode.FormsDesigner
if (formClass.Name != this.formClass.Name) {
LoggingService.Info("Renaming form to " + formClass.Name);
ICSharpCode.SharpDevelop.Refactoring.FindReferencesAndRenameHelper.RenameClass(this.formClass, formClass.Name);
Dictionary<string, IDocument> providedFileDocuments = new Dictionary<string, IDocument>();
providedFileDocuments.Add(this.ViewContent.DesignerCodeFile.FileName, this.ViewContent.DesignerCodeFileDocument);
if (!this.ViewContent.PrimaryFile.Equals(this.ViewContent.DesignerCodeFile)) {
System.Diagnostics.Debug.Assert(!this.ViewContent.DesignerCodeFileDocument.Equals(this.ViewContent.PrimaryFileDocument));
providedFileDocuments.Add(this.ViewContent.PrimaryFileName, this.ViewContent.PrimaryFileDocument);
}
ICSharpCode.SharpDevelop.Refactoring.FindReferencesAndRenameHelper.RenameClass(this.formClass, formClass.Name, providedFileDocuments);
this.ViewContent.DesignerCodeFile.MakeDirty();
this.ViewContent.PrimaryFile.MakeDirty();
Reparse();
}

7
src/Main/Base/Project/Src/Gui/IWorkbench.cs

@ -117,10 +117,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -117,10 +117,15 @@ namespace ICSharpCode.SharpDevelop.Gui
void Initialize();
/// <summary>
/// Inserts a new <see cref="IViewContent"/> object in the workspace.
/// Inserts a new <see cref="IViewContent"/> object in the workspace and switches to the new view.
/// </summary>
void ShowView(IViewContent content);
/// <summary>
/// Inserts a new <see cref="IViewContent"/> object in the workspace.
/// </summary>
void ShowView(IViewContent content, bool switchToOpenedView);
/// <summary>
/// Inserts a new <see cref="IPadContent"/> object in the workspace.
/// </summary>

4
src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs

@ -75,9 +75,9 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -75,9 +75,9 @@ namespace ICSharpCode.SharpDevelop.Gui
void RedrawAllComponents();
/// <summary>
/// Shows a new <see cref="IViewContent"/>.
/// Shows a new <see cref="IViewContent"/> and optionally switches to it.
/// </summary>
IWorkbenchWindow ShowView(IViewContent content);
IWorkbenchWindow ShowView(IViewContent content, bool switchToOpenedView);
void LoadConfiguration();

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/DefaultFileNodeCommands.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -77,7 +77,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
int defaultCodonIndex = codons.IndexOf(DisplayBindingService.GetDefaultCodonPerFileName(fileName));
using (OpenWithDialog dlg = new OpenWithDialog(codons, defaultCodonIndex, Path.GetExtension(fileName))) {
if (dlg.ShowDialog(WorkbenchSingleton.MainForm) == DialogResult.OK) {
FileUtility.ObservedLoad(new FileService.LoadFileWrapper(dlg.SelectedBinding.Binding).Invoke, fileName);
FileUtility.ObservedLoad(new FileService.LoadFileWrapper(dlg.SelectedBinding.Binding, true).Invoke, fileName);
}
}
}

11
src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs

@ -323,6 +323,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -323,6 +323,11 @@ namespace ICSharpCode.SharpDevelop.Gui
}
public void ShowView(IViewContent content)
{
this.ShowView(content, true);
}
public void ShowView(IViewContent content, bool switchToOpenedView)
{
System.Diagnostics.Debug.Assert(layout != null);
primaryViewContentCollection.Add(content);
@ -337,8 +342,10 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -337,8 +342,10 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
layout.ShowView(content);
content.WorkbenchWindow.SelectWindow();
layout.ShowView(content, switchToOpenedView);
if (switchToOpenedView) {
content.WorkbenchWindow.SelectWindow();
}
OnViewOpened(new ViewContentEventArgs(content));
}

30
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ICSharpCode.Core;
@ -181,7 +182,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -181,7 +182,7 @@ namespace ICSharpCode.SharpDevelop.Gui
void ShowViewContents()
{
foreach (IViewContent content in WorkbenchSingleton.Workbench.PrimaryViewContents) {
ShowView(content);
ShowView(content, true);
}
}
@ -548,12 +549,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -548,12 +549,16 @@ namespace ICSharpCode.SharpDevelop.Gui
ActiveMdiChanged(this, null);
}
public IWorkbenchWindow ShowView(IViewContent content)
public IWorkbenchWindow ShowView(IViewContent content, bool switchToOpenedView)
{
if (content.WorkbenchWindow is SdiWorkspaceWindow) {
SdiWorkspaceWindow oldSdiWindow = (SdiWorkspaceWindow)content.WorkbenchWindow;
if (!oldSdiWindow.IsDisposed) {
oldSdiWindow.Show(dockPanel);
if (switchToOpenedView) {
oldSdiWindow.Show(dockPanel);
} else {
this.AddWindowToDockPanelWithoutSwitching(oldSdiWindow);
}
return oldSdiWindow;
}
}
@ -563,12 +568,29 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -563,12 +568,29 @@ namespace ICSharpCode.SharpDevelop.Gui
sdiWorkspaceWindow.ViewContents.AddRange(content.SecondaryViewContents);
sdiWorkspaceWindow.CloseEvent += new EventHandler(CloseWindowEvent);
if (dockPanel != null) {
sdiWorkspaceWindow.Show(dockPanel);
if (switchToOpenedView) {
sdiWorkspaceWindow.Show(dockPanel);
} else {
this.AddWindowToDockPanelWithoutSwitching(sdiWorkspaceWindow);
}
}
return sdiWorkspaceWindow;
}
void AddWindowToDockPanelWithoutSwitching(SdiWorkspaceWindow sdiWorkspaceWindow)
{
sdiWorkspaceWindow.DockPanel = dockPanel;
SdiWorkspaceWindow otherWindow = dockPanel.ActiveContent as SdiWorkspaceWindow;
if (otherWindow == null) {
otherWindow = dockPanel.Contents.OfType<SdiWorkspaceWindow>().FirstOrDefault(c => c.Pane != null);
}
if (otherWindow != null) {
sdiWorkspaceWindow.Pane = otherWindow.Pane;
}
sdiWorkspaceWindow.DockState = DockState.Document;
}
void ActiveMdiChanged(object sender, EventArgs e)
{
OnActiveWorkbenchWindowChanged(e);

7
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs

@ -285,6 +285,13 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -285,6 +285,13 @@ namespace ICSharpCode.SharpDevelop.Gui
void UpdateTitle()
{
IViewContent content = ActiveViewContent;
if (content == null && this.ViewContents.Count > 0) {
// This can happen when the window is inactive and
// no tab page of the viewTabControl is selected
// (viewTabControl.SelectedIndex == -1)
// but we have multiple ViewContents.
content = this.ViewContents[0];
}
if (content != null) {
base.ToolTipText = content.PrimaryFileName;

5
src/Main/Base/Project/Src/Gui/Workbench/Layouts/SimpleWorkbenchLayout.cs

@ -140,11 +140,14 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -140,11 +140,14 @@ namespace ICSharpCode.SharpDevelop.Gui
{
}
public IWorkbenchWindow ShowView(IViewContent content)
public IWorkbenchWindow ShowView(IViewContent content, bool switchToOpenedView)
{
SimpleDocumentTab sdt = new SimpleDocumentTab();
sdt.window.ViewContents.Add(content);
documentTabs.TabPages.Add(sdt);
if (switchToOpenedView) {
documentTabs.SelectedTab = sdt;
}
return sdt.window;
}

32
src/Main/Base/Project/Src/Services/File/FileService.cs

@ -173,11 +173,13 @@ namespace ICSharpCode.SharpDevelop @@ -173,11 +173,13 @@ namespace ICSharpCode.SharpDevelop
internal sealed class LoadFileWrapper
{
IDisplayBinding binding;
readonly IDisplayBinding binding;
readonly bool switchToOpenedView;
public LoadFileWrapper(IDisplayBinding binding)
public LoadFileWrapper(IDisplayBinding binding, bool switchToOpenedView)
{
this.binding = binding;
this.switchToOpenedView = switchToOpenedView;
}
public void Invoke(string fileName)
@ -186,7 +188,7 @@ namespace ICSharpCode.SharpDevelop @@ -186,7 +188,7 @@ namespace ICSharpCode.SharpDevelop
IViewContent newContent = binding.CreateContentForFile(file);
if (newContent != null) {
DisplayBindingService.AttachSubWindows(newContent, false);
WorkbenchSingleton.Workbench.ShowView(newContent);
WorkbenchSingleton.Workbench.ShowView(newContent, switchToOpenedView);
}
file.CloseIfAllViewsClosed();
}
@ -207,21 +209,41 @@ namespace ICSharpCode.SharpDevelop @@ -207,21 +209,41 @@ namespace ICSharpCode.SharpDevelop
return GetOpenFile(fileName) != null;
}
/// <summary>
/// Opens a view content for the specified file and switches to the opened view
/// or switches to and returns the existing view content for the file if it is already open.
/// </summary>
/// <param name="fileName">The name of the file to open.</param>
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
public static IViewContent OpenFile(string fileName)
{
return OpenFile(fileName, true);
}
/// <summary>
/// Opens a view content for the specified file
/// or returns the existing view content for the file if it is already open.
/// </summary>
/// <param name="fileName">The name of the file to open.</param>
/// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
public static IViewContent OpenFile(string fileName, bool switchToOpenedView)
{
fileName = FileUtility.NormalizePath(fileName);
LoggingService.Info("Open file " + fileName);
IViewContent viewContent = GetOpenFile(fileName);
if (viewContent != null) {
viewContent.WorkbenchWindow.SelectWindow();
if (switchToOpenedView) {
viewContent.WorkbenchWindow.SelectWindow();
}
return viewContent;
}
IDisplayBinding binding = DisplayBindingService.GetBindingPerFileName(fileName);
if (binding != null) {
if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding).Invoke), fileName) == FileOperationResult.OK) {
if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) {
FileService.RecentOpen.AddLastFile(fileName);
}
} else {

52
src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

@ -13,7 +13,6 @@ using System.Text; @@ -13,7 +13,6 @@ using System.Text;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.TextEditor;
@ -132,6 +131,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -132,6 +131,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
public static void RenameClass(IClass c, string newName)
{
RenameClass(c, newName, null);
}
public static void RenameClass(IClass c, string newName, IDictionary<string, ICSharpCode.TextEditor.Document.IDocument> providedFileDocuments)
{
c = c.GetCompoundClass(); // get compound class if class is partial
@ -150,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -150,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
}
FindReferencesAndRenameHelper.RenameReferences(list, newName);
FindReferencesAndRenameHelper.RenameReferences(list, newName, providedFileDocuments);
}
static IList<IClass> GetClassParts(IClass c)
@ -367,28 +371,42 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -367,28 +371,42 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public static void RenameReferences(List<Reference> list, string newName)
{
List<IViewContent> modifiedContents = new List<IViewContent>();
RenameReferences(list, newName, null);
}
public static void RenameReferences(List<Reference> list, string newName, IDictionary<string, ICSharpCode.TextEditor.Document.IDocument> providedFileDocuments)
{
Dictionary<ICSharpCode.TextEditor.Document.IDocument, IViewContent> modifiedDocuments = new Dictionary<ICSharpCode.TextEditor.Document.IDocument, IViewContent>();
List<Modification> modifications = new List<Modification>();
foreach (Reference r in list) {
IViewContent viewContent = FileService.OpenFile(r.FileName);
ITextEditorControlProvider p = viewContent as ITextEditorControlProvider;
ICSharpCode.TextEditor.Document.IDocument document;
IViewContent viewContent;
if (!modifiedContents.Contains(viewContent)) {
modifiedContents.Add(viewContent);
if (p != null)
p.TextEditorControl.Document.UndoStack.StartUndoGroup();
if (providedFileDocuments == null || !providedFileDocuments.TryGetValue(FileUtility.NormalizePath(r.FileName), out document)) {
viewContent = FileService.OpenFile(r.FileName, false);
ITextEditorControlProvider p = viewContent as ITextEditorControlProvider;
document = (p == null) ? null : p.TextEditorControl.Document;
} else {
viewContent = null;
}
if (p != null) {
ModifyDocument(modifications, p.TextEditorControl.Document, r.Offset, r.Length, newName);
if (document == null) {
LoggingService.Warn("RenameReferences: Could not get document for file '" + r.FileName + "'");
continue;
}
if (!modifiedDocuments.ContainsKey(document)) {
modifiedDocuments.Add(document, viewContent);
document.UndoStack.StartUndoGroup();
}
}
foreach (IViewContent viewContent in modifiedContents) {
ITextEditorControlProvider p = viewContent as ITextEditorControlProvider;
if (p != null)
p.TextEditorControl.Document.UndoStack.EndUndoGroup();
ParserService.ParseViewContent(viewContent);
ModifyDocument(modifications, document, r.Offset, r.Length, newName);
}
foreach (KeyValuePair<ICSharpCode.TextEditor.Document.IDocument, IViewContent> entry in modifiedDocuments) {
entry.Key.UndoStack.EndUndoGroup();
if (entry.Value != null) {
ParserService.ParseViewContent(entry.Value);
}
}
}

Loading…
Cancel
Save