From a491d1295283e1bbc23cf5841be428b510190db3 Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Fri, 28 Jan 2011 23:39:53 +0200 Subject: [PATCH] Lock view contents when debugger starts and refresh icon since we don't support EnC (yet). --- .../Scripting/Test/Utils/MockTextEditor.cs | 2 + .../WixBinding/Test/Utils/MockTextEditor.cs | 2 + .../Test/Utils/MockWorkbenchWindow.cs | 4 ++ .../Debugger.AddIn/Service/WindowsDebugger.cs | 61 ++++++++++++++++--- .../XmlEditor/Test/Utils/MockTextEditor.cs | 2 + .../AvalonEdit/AvalonEditTextEditorAdapter.cs | 5 ++ .../Base/Project/Src/Editor/ITextEditor.cs | 2 + .../Base/Project/Src/Gui/IWorkbenchWindow.cs | 5 ++ .../Layouts/AvalonWorkbenchWindow.cs | 2 +- 9 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs b/src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs index c69ccde533..f2e513d1b3 100644 --- a/src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs +++ b/src/AddIns/BackendBindings/Scripting/Test/Utils/MockTextEditor.cs @@ -62,6 +62,8 @@ namespace ICSharpCode.Scripting.Tests.Utils } } + public bool IsReadOnly { get; set; } + public int SelectionLength { get; set; } public string SelectedText { get; set; } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs index 127885a93a..329d192e11 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs @@ -110,6 +110,8 @@ namespace WixBinding.Tests.Utils } } + public bool IsReadOnly { get; set; } + public FileName FileName { get { throw new NotImplementedException(); diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs index 60eef0e0cd..c014f61b48 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockWorkbenchWindow.cs @@ -69,6 +69,10 @@ namespace WixBinding.Tests.Utils get { return selectWindowMethodCalled; } } + public void UpdateActiveViewContent() + { + } + public event EventHandler ActiveViewContentChanged; protected virtual void OnActiveViewContentChanged(EventArgs e) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs index 4ad8e6875a..521b111a85 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs @@ -22,6 +22,8 @@ using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Visitors; using ICSharpCode.SharpDevelop.Bookmarks; using ICSharpCode.SharpDevelop.Debugging; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui.OptionPanels; using ICSharpCode.SharpDevelop.Project; @@ -142,12 +144,12 @@ namespace ICSharpCode.SharpDevelop.Services if (FileUtility.IsUrl(processStartInfo.FileName)) { var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject; - var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); + var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); if (!CheckWebProjectStartInfo(project, options)) return; System.Diagnostics.Process defaultAppProcess = null; - if (options.Data.WebServer != WebServer.None) { + if (options.Data.WebServer != WebServer.None) { string processName = WebProjectService.WorkerProcessName; // try find the worker process directly or using the process monitor callback @@ -294,7 +296,7 @@ namespace ICSharpCode.SharpDevelop.Services { if (FileUtility.IsUrl(processStartInfo.FileName)) { var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject; - var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); + var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name); if (!CheckWebProjectStartInfo(project, options)) return; @@ -764,16 +766,59 @@ namespace ICSharpCode.SharpDevelop.Services if (debugger.Processes.Count == 1) { if (DebugStarted != null) { DebugStarted(this, EventArgs.Empty); + SetActiveViewsReadonly(true); } } e.Item.LogMessage += LogMessage; } + void SetActiveViewsReadonly(bool readOnly) + { + // TODO: don't forget about EnC + //if (DebuggingOptions.Instance.EnableEditAndContinue) + // return; + + if (WorkbenchSingleton.Workbench == null) + return; + + if (WorkbenchSingleton.Workbench.WorkbenchWindowCollection.Count > 0) { + foreach(var window in WorkbenchSingleton.Workbench.WorkbenchWindowCollection) { + foreach (var content in window.ViewContents) { + if (content is ITextEditorProvider) { + ((ITextEditorProvider)content).TextEditor.IsReadOnly = readOnly; + } + } + + // refresh tab icon + window.UpdateActiveViewContent(); + } + } + + // make readonly the newly opened views + if (readOnly) + WorkbenchSingleton.Workbench.ViewOpened += OnViewOpened; + else + WorkbenchSingleton.Workbench.ViewOpened -= OnViewOpened; + } + + void OnViewOpened(object sender, ViewContentEventArgs e) + { + if (!IsDebugging) + return; + + // TODO: don't forget about EnC + //if (!DebuggingOptions.Instance.EnableEditAndContinue) + if (e.Content is ITextEditorProvider) { + ((ITextEditorProvider)e.Content).TextEditor.IsReadOnly = true; + } + } + void debugger_ProcessExited(object sender, CollectionItemEventArgs e) { if (debugger.Processes.Count == 0) { if (DebugStopped != null) { DebugStopped(this, e); + SetActiveViewsReadonly(false); } SelectProcess(null); } else { @@ -886,7 +931,7 @@ namespace ICSharpCode.SharpDevelop.Services } void process_Modules_Added(object sender, CollectionItemEventArgs e) - { + { if (ProjectService.OpenSolution == null || ProjectService.OpenSolution.Projects == null || ProjectService.OpenSolution.Projects.Count() == 0) @@ -894,9 +939,9 @@ namespace ICSharpCode.SharpDevelop.Services if (e == null || e.Item == null) return; - ProjectService.OpenSolution.Projects - .Where(p => e.Item.Name.IndexOf(p.Name) >= 0) - .ForEach(p => e.Item.LoadSymbolsFromDisk(new []{ Path.GetDirectoryName(p.OutputAssemblyFullPath) })); - } + ProjectService.OpenSolution.Projects + .Where(p => e.Item.Name.IndexOf(p.Name) >= 0) + .ForEach(p => e.Item.LoadSymbolsFromDisk(new []{ Path.GetDirectoryName(p.OutputAssemblyFullPath) })); + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs index d7ce998abc..80e35cf7a4 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextEditor.cs @@ -95,6 +95,8 @@ namespace XmlEditor.Tests.Utils } } + public bool IsReadOnly { get; set; } + public FileName FileName { get { return fileName; } set { fileName = value; } diff --git a/src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs b/src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs index f32b382d75..7e13ec945b 100755 --- a/src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs +++ b/src/Main/Base/Project/Src/Editor/AvalonEdit/AvalonEditTextEditorAdapter.cs @@ -26,6 +26,11 @@ namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit readonly TextEditor textEditor; AvalonEditDocumentAdapter document; + public bool IsReadOnly { + get { return textEditor.IsReadOnly; } + set { textEditor.IsReadOnly = value; } + } + public TextEditor TextEditor { get { return textEditor; } } diff --git a/src/Main/Base/Project/Src/Editor/ITextEditor.cs b/src/Main/Base/Project/Src/Editor/ITextEditor.cs index 56060b949a..fb74738621 100644 --- a/src/Main/Base/Project/Src/Editor/ITextEditor.cs +++ b/src/Main/Base/Project/Src/Editor/ITextEditor.cs @@ -24,6 +24,8 @@ namespace ICSharpCode.SharpDevelop.Editor /// public interface ITextEditor : IServiceProvider { + bool IsReadOnly { get; set; } + /// /// Gets the primary view if split-view is active. /// If split-view is disabled, the current ITextEditor instance is returned. diff --git a/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs b/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs index 3218d98a35..dcccb79756 100644 --- a/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs +++ b/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs @@ -76,5 +76,10 @@ namespace ICSharpCode.SharpDevelop.Gui /// Is called when the title of this window has changed. /// event EventHandler TitleChanged; + + /// + /// Updates the content. + /// + void UpdateActiveViewContent(); } } diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs index 29fac481f0..2049ce1e61 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs @@ -137,7 +137,7 @@ namespace ICSharpCode.SharpDevelop.Gui IViewContent oldActiveViewContent; - void UpdateActiveViewContent() + public void UpdateActiveViewContent() { UpdateTitleAndInfoTip();