From 467dcdd3a4724ad17bc0f907582535de8257e7c2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 5 Feb 2007 15:27:22 +0000 Subject: [PATCH] Worked on SD2-1234 - added support for view contents that are not editing a file (e.g. project options). git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2365 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/CSharpCompletionBinding.cs | 4 +- .../Project/Src/DesignerViewContent.cs | 60 +++---- .../Src/Services/WorkflowSideTabService.cs | 2 +- .../Forms.TextEditor/SQLTextEditorControl.cs | 2 +- .../SubversionAddIn/Project/Src/SvnClient.cs | 2 +- .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Project/Src/Commands/AutostartCommands.cs | 7 +- .../Base/Project/Src/Commands/EditCommands.cs | 2 +- .../Base/Project/Src/Commands/FileCommands.cs | 30 +++- .../Project/Src/Commands/FileMenuCommands.cs | 2 +- .../Src/Commands/FileTabStripCommands.cs | 14 +- .../Base/Project/Src/Commands/HelpCommands.cs | 4 +- .../Project/Src/Commands/ToolsCommands.cs | 4 +- .../Project/Src/Gui/AbstractViewContent.cs | 20 ++- .../Src/Gui/AbstractViewContentWithoutFile.cs | 16 +- .../ContentInterfaces/ICustomizedCommands.cs | 6 + .../Project/Src/Gui/Dialogs/NewFileDialog.cs | 2 +- .../Src/Gui/Dialogs/NewProjectDialog.cs | 2 +- .../OptionPanels/EditTemplateDialog.cs | 2 +- .../Src/Gui/Dialogs/ProjectOptionsView.cs | 6 +- .../Project/Src/Gui/Dialogs/TabbedOptions.cs | 2 +- .../Src/Gui/Dialogs/TreeViewOptions.cs | 2 +- .../Src/Gui/Dialogs/WordCountDialog.cs | 2 +- src/Main/Base/Project/Src/Gui/IViewContent.cs | 7 +- src/Main/Base/Project/Src/Gui/IWorkbench.cs | 17 +- .../Base/Project/Src/Gui/IWorkbenchLayout.cs | 4 - .../Base/Project/Src/Gui/IWorkbenchWindow.cs | 13 +- .../Project/Src/Gui/Pads/TaskList/TaskView.cs | 2 +- .../Src/Gui/Workbench/DefaultWorkbench.cs | 164 +++++++----------- .../Workbench/Layouts/SdiWorkspaceLayout.cs | 13 +- .../Workbench/Layouts/SdiWorkspaceWindow.cs | 38 ++-- .../Src/Gui/Workbench/SingleInstanceHelper.cs | 92 ++++++++++ .../Project/Src/Gui/WorkbenchSingleton.cs | 11 ++ .../Project/Src/Services/File/FileService.cs | 16 +- .../Project/Src/Services/File/OpenedFile.cs | 4 +- .../Project/Src/Services/File/RecentOpen.cs | 2 +- .../Base/Project/Src/Services/HelpProvider.cs | 6 +- .../ParserService/ParseProjectContent.cs | 2 +- .../Src/TextEditor/Commands/FormatCommands.cs | 2 +- .../AttributesDataProvider.cs | 2 +- .../Gui/Editor/SharpDevelopTextAreaControl.cs | 4 +- .../Engine/SearchReplaceManager.cs | 2 +- .../Project/Src/CSharp/ExpressionFinder.cs | 6 +- .../Project/Src/ExpressionContext.cs | 11 +- .../Src/Implementations/SystemTypes.cs | 4 + src/Main/StartUp/Project/SharpDevelopMain.cs | 2 +- src/Tools/Tools.build | 22 +-- 47 files changed, 395 insertions(+), 245 deletions(-) create mode 100644 src/Main/Base/Project/Src/Gui/Workbench/SingleInstanceHelper.cs diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs index 61c0692949..c08f67b52a 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpCompletionBinding.cs @@ -43,10 +43,10 @@ namespace CSharpBinding context = ExpressionContext.Default; break; case "using": - context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.GetClass("System.IDisposable", 0), false); + context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.SystemTypes.IDisposable, false); break; case "catch": - context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.GetClass("System.Exception", 0), false); + context = ExpressionContext.TypeDerivingFrom(ParserService.CurrentProjectContent.SystemTypes.Exception, false); break; case "foreach": case "typeof": diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs index e4e09dcf59..890b821d31 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs @@ -96,13 +96,6 @@ namespace ICSharpCode.FormsDesigner this.textAreaControlProvider = viewContent as ITextEditorControlProvider; } - /*public override void SwitchedTo() - { - if (IsFormsDesignerVisible) { - AddSideBars(); - } - }*/ - void LoadDesigner() { LoggingService.Info("Form Designer: BEGIN INITIALIZE"); @@ -307,35 +300,27 @@ namespace ICSharpCode.FormsDesigner return generator.GetCompatibleMethods(edesc); } - #warning Code temporarily disabled after IViewContent changes - /*public override void Selected() + /* + protected override void OnViewActivated(EventArgs e) { - PropertyPad.PropertyValueChanged += PropertyValueChanged; - Reload(); + LoggingService.Info("Designer.OnViewActived 1"); + base.OnViewActivated(e); // calls Load() if required + LoggingService.Info("Designer.OnViewActived 2"); + IsFormsDesignerVisible = true; AddSideBars(); + PropertyPad.PropertyValueChanged += PropertyValueChanged; SetActiveSideTab(); UpdatePropertyPad(); - }*/ - - public override void Dispose() - { - disposing = true; - base.Dispose(); - } - - protected override void LoadFromPrimary() - { - Reload(); + LoggingService.Info("Designer.OnViewActived 3"); } + */ - protected override void SaveToPrimary() - { - MergeFormChanges(); - } - - /*public override void Deselecting() + /* + protected override void OnViewDeactivated(EventArgs e) { + LoggingService.Info("Designer.OnViewDeactivated"); + // can happen if form designer is disposed and then deselected if (!IsFormsDesignerVisible) return; @@ -360,7 +345,24 @@ namespace ICSharpCode.FormsDesigner } UnloadDesigner(); LoggingService.Info("Unloading form designer finished"); - }*/ + } + */ + + public override void Dispose() + { + disposing = true; + base.Dispose(); + } + + protected override void LoadFromPrimary() + { + Reload(); + } + + protected override void SaveToPrimary() + { + MergeFormChanges(); + } void SelectionChangedHandler(object sender, EventArgs args) { diff --git a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/WorkflowSideTabService.cs b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/WorkflowSideTabService.cs index 1c6a6ea870..fcedb605fc 100644 --- a/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/WorkflowSideTabService.cs +++ b/src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Services/WorkflowSideTabService.cs @@ -113,7 +113,7 @@ namespace WorkflowDesigner } // Attach the handlers. - viewContent.ViewActivated += ViewContentActivatedEventHandler; + viewContent.SwitchedTo += ViewContentActivatedEventHandler; viewContent.Disposed += ViewContentDisposedEventHandler; ViewCount++; diff --git a/src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms.TextEditor/SQLTextEditorControl.cs b/src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms.TextEditor/SQLTextEditorControl.cs index 3b162cd3ff..46b4df503c 100644 --- a/src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms.TextEditor/SQLTextEditorControl.cs +++ b/src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms.TextEditor/SQLTextEditorControl.cs @@ -61,7 +61,7 @@ namespace SharpDbTools.Forms.TextEditor if (next == '.') { ICompletionDataProvider completionDataProvider = new TestCodeCompletionProvider(); // TODO: create a simple provider that just returns a couple of strings codeCompletionWindow = - CodeCompletionWindow.ShowCompletionWindow((Form)WorkbenchSingleton.Workbench, + CodeCompletionWindow.ShowCompletionWindow(WorkbenchSingleton.MainForm, this, this.FileName, completionDataProvider, next); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); diff --git a/src/AddIns/Misc/SubversionAddIn/Project/Src/SvnClient.cs b/src/AddIns/Misc/SubversionAddIn/Project/Src/SvnClient.cs index 8ab9f1e724..0c3df9086c 100644 --- a/src/AddIns/Misc/SubversionAddIn/Project/Src/SvnClient.cs +++ b/src/AddIns/Misc/SubversionAddIn/Project/Src/SvnClient.cs @@ -190,7 +190,7 @@ namespace ICSharpCode.Svn thread.Name = "SvnOperation"; thread.IsBackground = true; inOperationForm = new InOperationDialog(operationName, thread); - inOperationForm.Owner = (Form)WorkbenchSingleton.Workbench; + inOperationForm.Owner = WorkbenchSingleton.MainForm; inOperationForm.Show(); thread.Start(); } diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 078ce24821..740e7f5d1f 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -65,6 +65,7 @@ AddNewConfigurationDialog.cs + diff --git a/src/Main/Base/Project/Src/Commands/AutostartCommands.cs b/src/Main/Base/Project/Src/Commands/AutostartCommands.cs index aa7418c2a3..38f018fd7c 100644 --- a/src/Main/Base/Project/Src/Commands/AutostartCommands.cs +++ b/src/Main/Base/Project/Src/Commands/AutostartCommands.cs @@ -77,8 +77,7 @@ namespace ICSharpCode.SharpDevelop.Commands public void Run(IList fileList) { - Form f = (Form)WorkbenchSingleton.Workbench; - f.Show(); + //WorkbenchSingleton.MainForm.Show(); bool didLoadCombineOrFile = false; @@ -110,13 +109,13 @@ namespace ICSharpCode.SharpDevelop.Commands } } - f.Focus(); // windows.forms focus workaround + //WorkbenchSingleton.MainForm.Focus(); // windows.forms focus workaround ParserService.StartParserThread(); // finally run the workbench window ... Application.AddMessageFilter(new FormKeyHandler()); - Application.Run(f); + Application.Run(WorkbenchSingleton.MainForm); // save the workbench memento in the ide properties try { diff --git a/src/Main/Base/Project/Src/Commands/EditCommands.cs b/src/Main/Base/Project/Src/Commands/EditCommands.cs index e3bb787d77..b88ba129d8 100644 --- a/src/Main/Base/Project/Src/Commands/EditCommands.cs +++ b/src/Main/Base/Project/Src/Commands/EditCommands.cs @@ -214,7 +214,7 @@ namespace ICSharpCode.SharpDevelop.Commands public override void Run() { using (WordCountDialog wcd = new WordCountDialog()) { - wcd.Owner = (Form)WorkbenchSingleton.Workbench; + wcd.Owner = WorkbenchSingleton.MainForm; wcd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); } } diff --git a/src/Main/Base/Project/Src/Commands/FileCommands.cs b/src/Main/Base/Project/Src/Commands/FileCommands.cs index 99a7c3ce3f..be07c344cb 100644 --- a/src/Main/Base/Project/Src/Commands/FileCommands.cs +++ b/src/Main/Base/Project/Src/Commands/FileCommands.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.SharpDevelop.Commands } } using (NewFileDialog nfd = new NewFileDialog(null)) { - nfd.Owner = (Form)WorkbenchSingleton.Workbench; + nfd.Owner = WorkbenchSingleton.MainForm; nfd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); } } @@ -54,8 +54,17 @@ namespace ICSharpCode.SharpDevelop.Commands { public override void Run() { - IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; + Save(WorkbenchSingleton.Workbench.ActiveViewContent); + } + + internal static void Save(IViewContent content) + { if (content != null) { + if (content is ICustomizedCommands) { + if (((ICustomizedCommands)content).SaveCommand()) { + return; + } + } if (content.IsViewOnly) { return; } @@ -111,14 +120,18 @@ namespace ICSharpCode.SharpDevelop.Commands { public override void Run() { - // save the primary file only - IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; + Save(WorkbenchSingleton.Workbench.ActiveViewContent); + } + + internal static void Save(IViewContent content) + { if (content != null && !content.IsViewOnly) { if (content is ICustomizedCommands) { if (((ICustomizedCommands)content).SaveAsCommand()) { return; } } + // save the primary file only if (content.PrimaryFile != null) { Save(content.PrimaryFile); } @@ -160,6 +173,11 @@ namespace ICSharpCode.SharpDevelop.Commands { public static void SaveAll() { + foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { + if (content is ICustomizedCommands && content.IsDirty) { + ((ICustomizedCommands)content).SaveCommand(); + } + } foreach (OpenedFile file in FileService.OpenedFiles) { if (file.IsDirty) { SaveFile.Save(file); @@ -220,7 +238,7 @@ namespace ICSharpCode.SharpDevelop.Commands { public override void Run() { - ((Form)WorkbenchSingleton.Workbench).Close(); + WorkbenchSingleton.MainForm.Close(); } } @@ -259,7 +277,7 @@ namespace ICSharpCode.SharpDevelop.Commands using (PrintDocument pdoc = printable.PrintDocument) { if (pdoc != null) { PrintPreviewDialog ppd = new PrintPreviewDialog(); - ppd.Owner = (Form)WorkbenchSingleton.Workbench; + ppd.Owner = WorkbenchSingleton.MainForm; ppd.TopMost = true; ppd.Document = pdoc; ppd.Show(); diff --git a/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs b/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs index 95be2323ce..be1826f3d9 100644 --- a/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs +++ b/src/Main/Base/Project/Src/Commands/FileMenuCommands.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands using (NewProjectDialog npdlg = new NewProjectDialog(true)) { - npdlg.Owner = (Form)WorkbenchSingleton.Workbench; + npdlg.Owner = WorkbenchSingleton.MainForm; npdlg.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); } } diff --git a/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs b/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs index ba14cbe603..ebf370f254 100644 --- a/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs +++ b/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs @@ -46,12 +46,7 @@ namespace ICSharpCode.SharpDevelop.Commands.TabStrip { IWorkbenchWindow window = Owner as IWorkbenchWindow; if (window != null) { - if (window.ActiveViewContent.IsViewOnly) { - return; - } - foreach (OpenedFile file in window.ActiveViewContent.Files) { - SaveFile.Save(file); - } + SaveFile.Save(window.ActiveViewContent); } } } @@ -63,12 +58,7 @@ namespace ICSharpCode.SharpDevelop.Commands.TabStrip IWorkbenchWindow window = Owner as IWorkbenchWindow; if (window != null) { - if (window.ActiveViewContent.IsViewOnly) { - return; - } - foreach (OpenedFile file in window.ActiveViewContent.Files) { - SaveFileAs.Save(file); - } + SaveFileAs.Save(window.ActiveViewContent); } } } diff --git a/src/Main/Base/Project/Src/Commands/HelpCommands.cs b/src/Main/Base/Project/Src/Commands/HelpCommands.cs index e430deb591..eda93b089f 100644 --- a/src/Main/Base/Project/Src/Commands/HelpCommands.cs +++ b/src/Main/Base/Project/Src/Commands/HelpCommands.cs @@ -63,8 +63,8 @@ namespace ICSharpCode.SharpDevelop.Commands public override void Run() { using (CommonAboutDialog ad = new CommonAboutDialog()) { - ad.Owner = (Form)WorkbenchSingleton.Workbench; - ad.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); + ad.Owner = WorkbenchSingleton.MainForm; + ad.ShowDialog(WorkbenchSingleton.MainForm); } } } diff --git a/src/Main/Base/Project/Src/Commands/ToolsCommands.cs b/src/Main/Base/Project/Src/Commands/ToolsCommands.cs index af66af2a16..4b3392cb70 100644 --- a/src/Main/Base/Project/Src/Commands/ToolsCommands.cs +++ b/src/Main/Base/Project/Src/Commands/ToolsCommands.cs @@ -32,8 +32,8 @@ namespace ICSharpCode.SharpDevelop.Commands AddInTree.GetTreeNode("/SharpDevelop/Dialogs/OptionsDialog"))) { optionsDialog.FormBorderStyle = FormBorderStyle.FixedDialog; - optionsDialog.Owner = (Form)WorkbenchSingleton.Workbench; - optionsDialog.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); + optionsDialog.Owner = WorkbenchSingleton.MainForm; + optionsDialog.ShowDialog(WorkbenchSingleton.MainForm); } } } diff --git a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs index fc8de2bb60..f95a9fc624 100644 --- a/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/AbstractViewContent.cs @@ -34,18 +34,26 @@ namespace ICSharpCode.SharpDevelop.Gui this.Files.Add(file); } - public event EventHandler ViewActivated; + public event EventHandler SwitchedTo; - protected virtual void OnViewActivated(EventArgs e) + /// + /// Is called when the window is switched to. + /// -> Inside the tab (on SelectedIndexChanged of the tab control) + /// -> Inside the workbench (focus change in the docking library). + /// + /// You must call base.OnViewActivated if you override this method, otherwise the + /// event will not fire and will not work correctly. + /// + protected virtual void OnSwitchedTo(EventArgs e) { - if (ViewActivated != null) { - ViewActivated(this, e); + if (SwitchedTo != null) { + SwitchedTo(this, e); } } - public void SwitchedTo() + void IViewContent.OnSwitchedTo() { - OnViewActivated(EventArgs.Empty); + OnSwitchedTo(EventArgs.Empty); } public abstract Control Control { diff --git a/src/Main/Base/Project/Src/Gui/AbstractViewContentWithoutFile.cs b/src/Main/Base/Project/Src/Gui/AbstractViewContentWithoutFile.cs index 2dbff00d29..a36508a004 100644 --- a/src/Main/Base/Project/Src/Gui/AbstractViewContentWithoutFile.cs +++ b/src/Main/Base/Project/Src/Gui/AbstractViewContentWithoutFile.cs @@ -12,14 +12,14 @@ namespace ICSharpCode.SharpDevelop.Gui /// /// Base class for view contents that are not based on a file. /// - public abstract class AbstractViewContentWithoutFile : AbstractViewContent + public abstract class AbstractViewContentWithoutFile : AbstractViewContent, ICustomizedCommands { public override bool IsViewOnly { get { return false; } } [Obsolete("AbstractViewContentWithoutFile.PrimaryFile is always null")] - public override OpenedFile PrimaryFile { get { return null; } } + public sealed override OpenedFile PrimaryFile { get { return null; } } [Obsolete("This method is not supported on an AbstractViewContentWithoutFile")] public sealed override void Load(OpenedFile file, System.IO.Stream stream) @@ -42,5 +42,17 @@ namespace ICSharpCode.SharpDevelop.Gui /// Save the view content. /// public abstract void Save(); + + bool ICustomizedCommands.SaveCommand() + { + Save(); + return true; + } + + bool ICustomizedCommands.SaveAsCommand() + { + Save(); + return true; + } } } diff --git a/src/Main/Base/Project/Src/Gui/ContentInterfaces/ICustomizedCommands.cs b/src/Main/Base/Project/Src/Gui/ContentInterfaces/ICustomizedCommands.cs index 8ce3220dd0..dcc4f7b774 100644 --- a/src/Main/Base/Project/Src/Gui/ContentInterfaces/ICustomizedCommands.cs +++ b/src/Main/Base/Project/Src/Gui/ContentInterfaces/ICustomizedCommands.cs @@ -10,9 +10,15 @@ using System; namespace ICSharpCode.SharpDevelop.Gui { /// + /// Allows a IViewContent to handle the save command on its own instead of using OpenedFile. /// public interface ICustomizedCommands { + /// + /// Returns true, if the save command is handled, false otherwise + /// + bool SaveCommand(); + /// /// Returns true, if the save as command is handled, false otherwise /// diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs index 6bf755cd37..226be235a6 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs @@ -606,7 +606,7 @@ namespace ICSharpCode.SharpDevelop.Gui tooltip.SetToolTip(ControlDictionary["largeIconsRadioButton"], StringParser.Parse("${res:Global.LargeIconToolTip}")); tooltip.SetToolTip(ControlDictionary["smallIconsRadioButton"], StringParser.Parse("${res:Global.SmallIconToolTip}")); tooltip.Active = true; - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; StartPosition = FormStartPosition.CenterParent; Icon = null; diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs index b4f6b68771..166b88af9a 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs @@ -398,7 +398,7 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs tooltip.SetToolTip(ControlDictionary["largeIconsRadioButton"], StringParser.Parse("${res:Global.LargeIconToolTip}")); tooltip.SetToolTip(ControlDictionary["smallIconsRadioButton"], StringParser.Parse("${res:Global.SmallIconToolTip}")); tooltip.Active = true; - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; StartPosition = FormStartPosition.CenterParent; Icon = null; diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs index f9e382d8c3..9efc62846c 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/EditTemplateDialog.cs @@ -45,7 +45,7 @@ namespace ICSharpCode.SharpDevelop.Gui ControlDictionary["okButton"].Click += new EventHandler(AcceptEvent); - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; Icon = null; } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs b/src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs index ebd38c0685..b1dd1f4cf8 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/ProjectOptionsView.cs @@ -38,15 +38,13 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs public ProjectOptionsView(AddInTreeNode node, IProject project) { - this.project = project; + this.project = project; + this.TitleName = project.Name; // tabControl.Alignment = TabAlignment.Left; tabControl.HandleCreated += TabControlHandleCreated; AddOptionPanels(node.BuildChildItems(this)); - - this.AutomaticallyRegisterViewOnFiles = false; - this.Files.Add(FileService.AttachToOpenedFile(project.FileName, this)); } void TabControlHandleCreated(object sender, EventArgs e) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs index 7b2ab04968..c931aa488e 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/TabbedOptions.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.SharpDevelop.Gui this.Text = dialogName; ControlDictionary["okButton"].Click += new EventHandler(AcceptEvent); Icon = null; - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; AddOptionPanels(node.BuildChildItems(this)); } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptions.cs b/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptions.cs index cf74d51022..81b9e5564b 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptions.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptions.cs @@ -225,7 +225,7 @@ namespace ICSharpCode.SharpDevelop.Gui protected void InitializeComponent() { - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.TreeViewOptionsDialog.xfrm")); diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/WordCountDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/WordCountDialog.cs index 41a43f432a..39aba8a2a1 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/WordCountDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/WordCountDialog.cs @@ -231,7 +231,7 @@ namespace ICSharpCode.SharpDevelop.Gui ((ListView)ControlDictionary["resultListView"]).ColumnClick += new ColumnClickEventHandler(SortEvt); Icon = IconService.GetIcon("Icons.16x16.FindIcon"); - Owner = (Form)WorkbenchSingleton.Workbench; + Owner = WorkbenchSingleton.MainForm; ((ComboBox)ControlDictionary["locationComboBox"]).Items.Add(StringParser.Parse("${res:Global.Location.currentfile}")); ((ComboBox)ControlDictionary["locationComboBox"]).Items.Add(StringParser.Parse("${res:Global.Location.allopenfiles}")); diff --git a/src/Main/Base/Project/Src/Gui/IViewContent.cs b/src/Main/Base/Project/Src/Gui/IViewContent.cs index 19fb6b7da7..6f7966c3c4 100644 --- a/src/Main/Base/Project/Src/Gui/IViewContent.cs +++ b/src/Main/Base/Project/Src/Gui/IViewContent.cs @@ -65,11 +65,14 @@ namespace ICSharpCode.SharpDevelop.Gui } /// + /// Used internally. /// Is called when the window is switched to. /// -> Inside the tab (on SelectedIndexChanged of the tab control) /// -> Inside the workbench (focus change in the docking library). /// - void SwitchedTo(); + void OnSwitchedTo(); + + event EventHandler SwitchedTo; /// /// Reinitializes the content. (Re-initializes all add-in tree stuff) @@ -131,8 +134,6 @@ namespace ICSharpCode.SharpDevelop.Gui /// INavigationPoint BuildNavPoint(); - event EventHandler ViewActivated; - bool IsDisposed { get; } event EventHandler Disposed; diff --git a/src/Main/Base/Project/Src/Gui/IWorkbench.cs b/src/Main/Base/Project/Src/Gui/IWorkbench.cs index 4ac346ab3e..105b3371bf 100644 --- a/src/Main/Base/Project/Src/Gui/IWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/IWorkbench.cs @@ -52,6 +52,12 @@ namespace ICSharpCode.SharpDevelop.Gui get; } + /// + /// Is called, when the workbench window which the user has into + /// the foreground (e.g. editable) changed to a new one. + /// + event EventHandler ActiveWorkbenchWindowChanged; + /// /// The active view content inside the active workbench window. /// @@ -59,6 +65,11 @@ namespace ICSharpCode.SharpDevelop.Gui get; } + /// + /// Is called, when the active view content has changed. + /// + event EventHandler ActiveViewContentChanged; + /// /// The active content. This can be either a IViewContent or a IPadContent, depending on /// where the focus currently is. @@ -130,11 +141,5 @@ namespace ICSharpCode.SharpDevelop.Gui /// Is called, when a workbench view was closed /// event ViewContentEventHandler ViewClosed; - - /// - /// Is called, when the workbench window which the user has into - /// the foreground (e.g. editable) changed to a new one. - /// - event EventHandler ActiveWorkbenchWindowChanged; } } diff --git a/src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs b/src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs index b13b649472..44f459d457 100644 --- a/src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs +++ b/src/Main/Base/Project/Src/Gui/IWorkbenchLayout.cs @@ -88,9 +88,5 @@ namespace ICSharpCode.SharpDevelop.Gui /// the foreground (e.g. editable) changed to a new one. /// event EventHandler ActiveWorkbenchWindowChanged; - - // only needed in the workspace window when the 'secondary view content' changed - // it is somewhat like 'active workbench window changed' - void OnActiveWorkbenchWindowChanged(EventArgs e); } } diff --git a/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs b/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs index e095ee867c..bf9a48b8b9 100644 --- a/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs +++ b/src/Main/Base/Project/Src/Gui/IWorkbenchWindow.cs @@ -38,6 +38,11 @@ namespace ICSharpCode.SharpDevelop.Gui set; } + /// + /// Is raised when the ActiveViewContent property has changed. + /// + event EventHandler ActiveViewContentChanged; + /// /// Gets the list of view contents displayed in this window /// @@ -66,9 +71,15 @@ namespace ICSharpCode.SharpDevelop.Gui void RedrawContent(); /// - /// Only for internal use. + /// Used internally: + /// This method is called by the workbench to notify the window that is was selected. /// void OnWindowSelected(EventArgs e); + + /// + /// Used internally: + /// This method is called by the workbench to notify the window that is was deselected. + /// void OnWindowDeselected(EventArgs e); /// diff --git a/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskView.cs b/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskView.cs index 0000bf87ba..01d40b5aa8 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskView.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskView.cs @@ -18,7 +18,7 @@ using System.Windows.Forms; using ICSharpCode.Core; -namespace ICSharpCode.SharpDevelop +namespace ICSharpCode.SharpDevelop.Gui { public enum TaskViewCols : int { Icon = 0, diff --git a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs index 66428edd35..5d242219d2 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs @@ -24,7 +24,7 @@ namespace ICSharpCode.SharpDevelop.Gui /// /// This is the Workspace with a multiple document interface. /// - public class DefaultWorkbench : Form, IWorkbench + sealed class DefaultWorkbench : Form, IWorkbench { readonly static string mainMenuPath = "/SharpDevelop/Workbench/MainMenu"; readonly static string viewContentPath = "/SharpDevelop/Workbench/Pads"; @@ -99,6 +99,7 @@ namespace ICSharpCode.SharpDevelop.Gui value.Attach(this); layout = value; layout.ActiveWorkbenchWindowChanged += OnActiveWindowChanged; + OnActiveWindowChanged(null, null); } } @@ -129,31 +130,78 @@ namespace ICSharpCode.SharpDevelop.Gui } } + void OnActiveWindowChanged(object sender, EventArgs e) + { + if (closeAll) return; + + if (layout == null) { + this.ActiveWorkbenchWindow = null; + } else { + this.ActiveWorkbenchWindow = layout.ActiveWorkbenchwindow; + } + } + + IWorkbenchWindow activeWorkbenchWindow; + public IWorkbenchWindow ActiveWorkbenchWindow { get { - #if DEBUG - WorkbenchSingleton.AssertMainThread(); - #endif - if (layout == null) { - return null; + WorkbenchSingleton.DebugAssertMainThread(); + return activeWorkbenchWindow; + } + private set { + if (activeWorkbenchWindow != value) { + if (activeWorkbenchWindow != null) { + activeWorkbenchWindow.ActiveViewContentChanged -= OnWorkbenchActiveViewContentChanged; + } + activeWorkbenchWindow = value; + if (activeWorkbenchWindow != null) { + activeWorkbenchWindow.ActiveViewContentChanged += OnWorkbenchActiveViewContentChanged; + } + OnWorkbenchActiveViewContentChanged(null, null); + if (ActiveWorkbenchWindowChanged != null) { + ActiveWorkbenchWindowChanged(this, EventArgs.Empty); + } } - return layout.ActiveWorkbenchwindow; } } + void OnWorkbenchActiveViewContentChanged(object sender, EventArgs e) + { + // update ActiveViewContent + IWorkbenchWindow window = this.ActiveWorkbenchWindow; + if (window != null) + this.ActiveViewContent = window.ActiveViewContent; + else + this.ActiveViewContent = null; + } + + public event EventHandler ActiveWorkbenchWindowChanged; + + IViewContent activeViewContent; + /// /// The active view content inside the active workbench window. /// public IViewContent ActiveViewContent { - get{ - IWorkbenchWindow window = this.ActiveWorkbenchWindow; - if (window != null) - return window.ActiveViewContent; - else - return null; + get { + WorkbenchSingleton.DebugAssertMainThread(); + return activeViewContent; + } + private set { + if (activeViewContent != value) { + activeViewContent = value; + if (ActiveViewContentChanged != null) { + ActiveViewContentChanged(this, EventArgs.Empty); + } + } } } + /// + /// Is called, when the active view content has changed. + /// + public event EventHandler ActiveViewContentChanged; + public object ActiveContent { get { if (layout == null) { @@ -173,7 +221,6 @@ namespace ICSharpCode.SharpDevelop.Gui AllowDrop = true; } - #region Single instance code protected override void WndProc(ref Message m) { if (!SingleInstanceHelper.PreFilterMessage(ref m)) { @@ -181,80 +228,6 @@ namespace ICSharpCode.SharpDevelop.Gui } } - public static class SingleInstanceHelper - { - const int WM_USER = 0x400; - const int CUSTOM_MESSAGE = WM_USER + 2; - const int RESULT_FILES_HANDLED = 2; - const int RESULT_PROJECT_IS_OPEN = 3; - - [System.Runtime.InteropServices.DllImport("user32.dll")] - static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); - - [System.Runtime.InteropServices.DllImport("user32.dll")] - static extern IntPtr SetForegroundWindow(IntPtr hWnd); - - public static bool OpenFilesInPreviousInstance(string[] fileList) - { - LoggingService.Info("Trying to pass arguments to previous instance..."); - int currentProcessId = Process.GetCurrentProcess().Id; - string currentFile = Assembly.GetEntryAssembly().Location; - int number = new Random().Next(); - string fileName = Path.Combine(Path.GetTempPath(), "sd" + number + ".tmp"); - try { - File.WriteAllLines(fileName, fileList); - List alternatives = new List(); - foreach (Process p in Process.GetProcessesByName("SharpDevelop")) { - if (p.Id == currentProcessId) continue; - - if (FileUtility.IsEqualFileName(currentFile, p.MainModule.FileName)) { - IntPtr hWnd = p.MainWindowHandle; - if (hWnd != IntPtr.Zero) { - long result = SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), IntPtr.Zero).ToInt64(); - if (result == RESULT_FILES_HANDLED) { - return true; - } else if (result == RESULT_PROJECT_IS_OPEN) { - alternatives.Add(hWnd); - } - } - } - } - foreach (IntPtr hWnd in alternatives) { - if (SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), new IntPtr(1)).ToInt64()== RESULT_FILES_HANDLED) { - return true; - } - } - return false; - } finally { - File.Delete(fileName); - } - } - - internal static bool PreFilterMessage(ref Message m) - { - if (m.Msg != CUSTOM_MESSAGE) - return false; - long fileNumber = m.WParam.ToInt64(); - long openEvenIfProjectIsOpened = m.LParam.ToInt64(); - LoggingService.Info("Receiving custom message..."); - if (openEvenIfProjectIsOpened == 0 && ProjectService.OpenSolution != null) { - m.Result = new IntPtr(RESULT_PROJECT_IS_OPEN); - } else { - m.Result = new IntPtr(RESULT_FILES_HANDLED); - try { - WorkbenchSingleton.SafeThreadAsyncCall(delegate { SetForegroundWindow(WorkbenchSingleton.MainForm.Handle) ; }); - foreach (string file in File.ReadAllLines(Path.Combine(Path.GetTempPath(), "sd" + fileNumber + ".tmp"))) { - WorkbenchSingleton.SafeThreadAsyncCall(delegate(string openFileName) { FileService.OpenFile(openFileName); }, file); - } - } catch (Exception ex) { - LoggingService.Warn(ex); - } - } - return true; - } - } - #endregion - System.Windows.Forms.Timer toolbarUpdateTimer; public void InitializeWorkspace() @@ -321,7 +294,7 @@ namespace ICSharpCode.SharpDevelop.Gui } } - public virtual void ShowView(IViewContent content) + public void ShowView(IViewContent content) { System.Diagnostics.Debug.Assert(layout != null); viewContentCollection.Add(content); @@ -341,7 +314,7 @@ namespace ICSharpCode.SharpDevelop.Gui OnViewOpened(new ViewContentEventArgs(content)); } - public virtual void ShowPad(PadDescriptor content) + public void ShowPad(PadDescriptor content) { PadContentCollection.Add(content); @@ -560,12 +533,6 @@ namespace ICSharpCode.SharpDevelop.Gui StatusBarService.SetMessage("${res:MainWindow.StatusBar.ReadyMessage}"); } - void OnActiveWindowChanged(object sender, EventArgs e) - { - if (!closeAll && ActiveWorkbenchWindowChanged != null) { - ActiveWorkbenchWindowChanged(this, e); - } - } // public ToolStripManager ToolStripManager = new ToolStripManager(); public MenuStrip TopMenu = null; public ToolStrip[] ToolBars = null; @@ -675,14 +642,14 @@ namespace ICSharpCode.SharpDevelop.Gui } } - protected virtual void OnViewOpened(ViewContentEventArgs e) + void OnViewOpened(ViewContentEventArgs e) { if (ViewOpened != null) { ViewOpened(this, e); } } - protected virtual void OnViewClosed(ViewContentEventArgs e) + void OnViewClosed(ViewContentEventArgs e) { if (ViewClosed != null) { ViewClosed(this, e); @@ -691,7 +658,6 @@ namespace ICSharpCode.SharpDevelop.Gui public event ViewContentEventHandler ViewOpened; public event ViewContentEventHandler ViewClosed; - public event EventHandler ActiveWorkbenchWindowChanged; protected override void OnActivated(EventArgs e) { diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs index a3fd4037ad..f62182509d 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs @@ -20,7 +20,7 @@ namespace ICSharpCode.SharpDevelop.Gui /// /// This is the a Workspace with a single document interface. /// - public class SdiWorkbenchLayout : IWorkbenchLayout + internal sealed class SdiWorkbenchLayout : IWorkbenchLayout { DefaultWorkbench wbForm; @@ -604,7 +604,8 @@ namespace ICSharpCode.SharpDevelop.Gui } IWorkbenchWindow oldSelectedWindow = null; - public virtual void OnActiveWorkbenchWindowChanged(EventArgs e) + + internal void OnActiveWorkbenchWindowChanged(EventArgs e) { IWorkbenchWindow newWindow = this.ActiveWorkbenchwindow; if (newWindow == null || newWindow.ActiveViewContent != null) { @@ -618,13 +619,13 @@ namespace ICSharpCode.SharpDevelop.Gui } else { //LoggingService.Debug("ignore window change to disposed window"); } - if (oldSelectedWindow != null) { + if (oldSelectedWindow != null && oldSelectedWindow.ActiveViewContent != null) { oldSelectedWindow.OnWindowDeselected(EventArgs.Empty); } oldSelectedWindow = newWindow; - if (oldSelectedWindow != null && oldSelectedWindow.ActiveViewContent != null && oldSelectedWindow.ActiveViewContent.Control != null) { - oldSelectedWindow.OnWindowSelected(EventArgs.Empty); - oldSelectedWindow.ActiveViewContent.SwitchedTo(); + if (newWindow != null && newWindow.ActiveViewContent != null) { + newWindow.ActiveViewContent.OnSwitchedTo(); + newWindow.OnWindowSelected(EventArgs.Empty); } } diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs index 1423d3ccbb..31c3964364 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceWindow.cs @@ -18,7 +18,7 @@ using WeifenLuo.WinFormsUI; namespace ICSharpCode.SharpDevelop.Gui { - public class SdiWorkspaceWindow : DockContent, IWorkbenchWindow, IOwnerState + internal sealed class SdiWorkspaceWindow : DockContent, IWorkbenchWindow, IOwnerState { readonly static string contextMenuPath = "/SharpDevelop/Workbench/OpenFileTab/ContextMenu"; @@ -82,6 +82,20 @@ namespace ICSharpCode.SharpDevelop.Gui } } + public event EventHandler ActiveViewContentChanged; + + IViewContent oldActiveViewContent; + + void UpdateActiveViewContent() + { + UpdateTitle(); + IViewContent newActiveViewContent = this.ActiveViewContent; + if (oldActiveViewContent != newActiveViewContent && ActiveViewContentChanged != null) { + ActiveViewContentChanged(this, EventArgs.Empty); + } + oldActiveViewContent = newActiveViewContent; + } + sealed class ViewContentCollection : Collection { readonly SdiWorkspaceWindow window; @@ -99,6 +113,7 @@ namespace ICSharpCode.SharpDevelop.Gui base.ClearItems(); window.ClearContent(); + window.UpdateActiveViewContent(); } protected override void InsertItem(int index, IViewContent item) @@ -131,7 +146,7 @@ namespace ICSharpCode.SharpDevelop.Gui window.viewTabControl.TabPages.Insert(index, newPage); } } - window.UpdateTitle(); + window.UpdateActiveViewContent(); } protected override void RemoveItem(int index) @@ -148,7 +163,7 @@ namespace ICSharpCode.SharpDevelop.Gui } else { window.viewTabControl.TabPages.RemoveAt(index); } - window.UpdateTitle(); + window.UpdateActiveViewContent(); } protected override void SetItem(int index, IViewContent item) @@ -169,7 +184,7 @@ namespace ICSharpCode.SharpDevelop.Gui page.Controls.Add(item.Control); page.Text = StringParser.Parse(item.TabPageText); } - window.UpdateTitle(); + window.UpdateActiveViewContent(); } } @@ -230,7 +245,8 @@ namespace ICSharpCode.SharpDevelop.Gui this.Controls.Add(viewTabControl); viewTabControl.SelectedIndexChanged += delegate { - this.ActiveViewContent.SwitchedTo(); + this.ActiveViewContent.OnSwitchedTo(); + UpdateActiveViewContent(); }; } } @@ -341,7 +357,7 @@ namespace ICSharpCode.SharpDevelop.Gui return true; } - public virtual void RedrawContent() + public void RedrawContent() { RefreshTabPageTexts(); } @@ -356,12 +372,11 @@ namespace ICSharpCode.SharpDevelop.Gui } } - protected virtual void OnTitleChanged(EventArgs e) + void OnTitleChanged(EventArgs e) { if (TitleChanged != null) { TitleChanged(this, e); } - WorkbenchSingleton.Workbench.WorkbenchLayout.OnActiveWorkbenchWindowChanged(EventArgs.Empty); } protected override void OnClosing(System.ComponentModel.CancelEventArgs e) @@ -369,7 +384,7 @@ namespace ICSharpCode.SharpDevelop.Gui e.Cancel = !CloseWindow(false); } - protected virtual void OnCloseEvent(EventArgs e) + void OnCloseEvent(EventArgs e) { OnWindowDeselected(e); if (CloseEvent != null) { @@ -377,13 +392,14 @@ namespace ICSharpCode.SharpDevelop.Gui } } - public virtual void OnWindowSelected(EventArgs e) + public void OnWindowSelected(EventArgs e) { if (WindowSelected != null) { WindowSelected(this, e); } } - public virtual void OnWindowDeselected(EventArgs e) + + public void OnWindowDeselected(EventArgs e) { if (WindowDeselected != null) { WindowDeselected(this, e); diff --git a/src/Main/Base/Project/Src/Gui/Workbench/SingleInstanceHelper.cs b/src/Main/Base/Project/Src/Gui/Workbench/SingleInstanceHelper.cs new file mode 100644 index 0000000000..ee76a6ab39 --- /dev/null +++ b/src/Main/Base/Project/Src/Gui/Workbench/SingleInstanceHelper.cs @@ -0,0 +1,92 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Windows.Forms; + +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Project; + +namespace ICSharpCode.SharpDevelop.Gui +{ + public static class SingleInstanceHelper + { + const int WM_USER = 0x400; + const int CUSTOM_MESSAGE = WM_USER + 2; + const int RESULT_FILES_HANDLED = 2; + const int RESULT_PROJECT_IS_OPEN = 3; + + [System.Runtime.InteropServices.DllImport("user32.dll")] + static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); + + [System.Runtime.InteropServices.DllImport("user32.dll")] + static extern IntPtr SetForegroundWindow(IntPtr hWnd); + + public static bool OpenFilesInPreviousInstance(string[] fileList) + { + LoggingService.Debug("Trying to pass arguments to previous instance..."); + int currentProcessId = Process.GetCurrentProcess().Id; + string currentFile = Assembly.GetEntryAssembly().Location; + int number = new Random().Next(); + string fileName = Path.Combine(Path.GetTempPath(), "sd" + number + ".tmp"); + try { + File.WriteAllLines(fileName, fileList); + List alternatives = new List(); + foreach (Process p in Process.GetProcessesByName("SharpDevelop")) { + if (p.Id == currentProcessId) continue; + + if (FileUtility.IsEqualFileName(currentFile, p.MainModule.FileName)) { + IntPtr hWnd = p.MainWindowHandle; + if (hWnd != IntPtr.Zero) { + long result = SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), IntPtr.Zero).ToInt64(); + if (result == RESULT_FILES_HANDLED) { + return true; + } else if (result == RESULT_PROJECT_IS_OPEN) { + alternatives.Add(hWnd); + } + } + } + } + foreach (IntPtr hWnd in alternatives) { + if (SendMessage(hWnd, CUSTOM_MESSAGE, new IntPtr(number), new IntPtr(1)).ToInt64() == RESULT_FILES_HANDLED) { + return true; + } + } + return false; + } finally { + File.Delete(fileName); + } + } + + internal static bool PreFilterMessage(ref Message m) + { + if (m.Msg != CUSTOM_MESSAGE) + return false; + long fileNumber = m.WParam.ToInt64(); + long openEvenIfProjectIsOpened = m.LParam.ToInt64(); + LoggingService.Debug("Receiving custom message..."); + if (openEvenIfProjectIsOpened == 0 && ProjectService.OpenSolution != null) { + m.Result = new IntPtr(RESULT_PROJECT_IS_OPEN); + } else { + m.Result = new IntPtr(RESULT_FILES_HANDLED); + try { + WorkbenchSingleton.SafeThreadAsyncCall(delegate { SetForegroundWindow(WorkbenchSingleton.MainForm.Handle) ; }); + foreach (string file in File.ReadAllLines(Path.Combine(Path.GetTempPath(), "sd" + fileNumber + ".tmp"))) { + WorkbenchSingleton.SafeThreadAsyncCall(delegate(string openFileName) { FileService.OpenFile(openFileName); }, file); + } + } catch (Exception ex) { + LoggingService.Warn(ex); + } + } + return true; + } + } +} diff --git a/src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs b/src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs index e7fb88a815..a372d11f58 100644 --- a/src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs +++ b/src/Main/Base/Project/Src/Gui/WorkbenchSingleton.cs @@ -6,6 +6,7 @@ // using System; +using System.Diagnostics; using System.Windows.Forms; using ICSharpCode.Core; @@ -130,6 +131,16 @@ namespace ICSharpCode.SharpDevelop.Gui } } + /// + /// Throws an exception if the current thread is not the main thread. + /// For performance reasons, the thread check is only done in debug builds. + /// + [Conditional("DEBUG")] + internal static void DebugAssertMainThread() + { + AssertMainThread(); + } + /// /// Throws an exception if the current thread is not the main thread. /// diff --git a/src/Main/Base/Project/Src/Services/File/FileService.cs b/src/Main/Base/Project/Src/Services/File/FileService.cs index 13ef57a759..ea68fcfd09 100644 --- a/src/Main/Base/Project/Src/Services/File/FileService.cs +++ b/src/Main/Base/Project/Src/Services/File/FileService.cs @@ -45,6 +45,7 @@ namespace ICSharpCode.SharpDevelop PropertyService.Set("RecentOpen", recentOpen.ToProperties()); } ProjectService.SolutionLoaded -= ProjectServiceSolutionLoaded; + ParserService.LoadSolutionProjectsThreadEnded -= ParserServiceLoadSolutionProjectsThreadEnded; serviceInitialized = false; } @@ -52,6 +53,7 @@ namespace ICSharpCode.SharpDevelop { if (!serviceInitialized) { ProjectService.SolutionLoaded += ProjectServiceSolutionLoaded; + ParserService.LoadSolutionProjectsThreadEnded += ParserServiceLoadSolutionProjectsThreadEnded; serviceInitialized = true; } } @@ -182,6 +184,16 @@ namespace ICSharpCode.SharpDevelop } } + static void ParserServiceLoadSolutionProjectsThreadEnded(object sender, EventArgs e) + { + WorkbenchSingleton.SafeThreadAsyncCall( + delegate { + foreach (IViewContent content in Linq.ToArray(WorkbenchSingleton.Workbench.ViewContentCollection)) { + DisplayBindingService.AttachSubWindows(content, true); + } + }); + } + public static bool IsOpen(string fileName) { return GetOpenFile(fileName) != null; @@ -372,7 +384,7 @@ namespace ICSharpCode.SharpDevelop } /// - /// Creates a FolderBrowserDialog that will initially select the + /// Creates a FolderBrowserDialog that will initially select the /// specified folder. If the folder does not exist then the default /// behaviour of the FolderBrowserDialog is used where it selects the /// desktop folder. @@ -389,7 +401,7 @@ namespace ICSharpCode.SharpDevelop } /// - /// Creates a FolderBrowserDialog that will initially select the + /// Creates a FolderBrowserDialog that will initially select the /// desktop folder. /// public static FolderBrowserDialog CreateFolderBrowserDialog(string description) diff --git a/src/Main/Base/Project/Src/Services/File/OpenedFile.cs b/src/Main/Base/Project/Src/Services/File/OpenedFile.cs index 633cdfa4e4..702452e09f 100644 --- a/src/Main/Base/Project/Src/Services/File/OpenedFile.cs +++ b/src/Main/Base/Project/Src/Services/File/OpenedFile.cs @@ -191,7 +191,7 @@ namespace ICSharpCode.SharpDevelop registeredViews.Add(view); - view.ViewActivated += SwitchedToView; + view.SwitchedTo += SwitchedToView; #if DEBUG view.Disposed += ViewDisposed; #endif @@ -203,7 +203,7 @@ namespace ICSharpCode.SharpDevelop throw new ArgumentNullException("view"); Debug.Assert(registeredViews.Contains(view)); - view.ViewActivated -= SwitchedToView; + view.SwitchedTo -= SwitchedToView; #if DEBUG view.Disposed -= ViewDisposed; #endif diff --git a/src/Main/Base/Project/Src/Services/File/RecentOpen.cs b/src/Main/Base/Project/Src/Services/File/RecentOpen.cs index af0d3065c9..fc2adc9dc4 100644 --- a/src/Main/Base/Project/Src/Services/File/RecentOpen.cs +++ b/src/Main/Base/Project/Src/Services/File/RecentOpen.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop /// it checks, if the files exists at every creation, and if not it doesn't list them in the /// recent files, and they'll not be saved during the next option save. /// - public class RecentOpen + public sealed class RecentOpen { /// /// This variable is the maximal length of lastfile/lastopen entries diff --git a/src/Main/Base/Project/Src/Services/HelpProvider.cs b/src/Main/Base/Project/Src/Services/HelpProvider.cs index d0c122cae5..eb923d6d1b 100644 --- a/src/Main/Base/Project/Src/Services/HelpProvider.cs +++ b/src/Main/Base/Project/Src/Services/HelpProvider.cs @@ -6,7 +6,7 @@ // using System; -using System.Collections; +using System.Collections.Generic; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Dom; @@ -14,9 +14,9 @@ namespace ICSharpCode.SharpDevelop { public class HelpProvider { - public static ArrayList GetProviders() + public static List GetProviders() { - return AddInTree.BuildItems("/SharpDevelop/Services/HelpProvider", null, false); + return AddInTree.BuildItems("/SharpDevelop/Services/HelpProvider", null, false); } public static void ShowHelp(IClass c) diff --git a/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs b/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs index 9cddb19e2c..e26aec6b08 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs @@ -13,7 +13,7 @@ using ICSharpCode.SharpDevelop.Project; namespace ICSharpCode.SharpDevelop { - public class ParseProjectContent : DefaultProjectContent + public sealed class ParseProjectContent : DefaultProjectContent { internal static ParseProjectContent CreateUninitalized(IProject project) { diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/FormatCommands.cs b/src/Main/Base/Project/Src/TextEditor/Commands/FormatCommands.cs index fb69d09e07..5844419a80 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/FormatCommands.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/FormatCommands.cs @@ -232,7 +232,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands } using (SortOptionsDialog sortOptionsDialog = new SortOptionsDialog()) { - sortOptionsDialog.Owner = (Form)WorkbenchSingleton.Workbench; + sortOptionsDialog.Owner = WorkbenchSingleton.MainForm; if (sortOptionsDialog.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) { TextArea textarea = ((ITextEditorControlProvider)viewContent).TextEditorControl.ActiveTextAreaControl.TextArea; textarea.BeginUpdate(); diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AttributesDataProvider.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AttributesDataProvider.cs index 2f271a3757..b7fa34f974 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AttributesDataProvider.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/CompletionWindow/AttributesDataProvider.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor public class AttributesDataProvider : CtrlSpaceCompletionDataProvider { public AttributesDataProvider(IProjectContent pc) - : this(ExpressionContext.TypeDerivingFrom(pc.GetClass("System.Attribute", 0), true)) + : this(ExpressionContext.TypeDerivingFrom(pc.SystemTypes.Attribute, true)) { } diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs index ecef57199e..b28d141eb4 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextAreaControl.cs @@ -316,7 +316,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor public void ShowInsightWindow(IInsightDataProvider insightDataProvider) { if (insightWindow == null || insightWindow.IsDisposed) { - insightWindow = new InsightWindow(((Form)WorkbenchSingleton.Workbench), this); + insightWindow = new InsightWindow(WorkbenchSingleton.MainForm, this); insightWindow.Closed += new EventHandler(CloseInsightWindow); } insightWindow.AddInsightDataProvider(insightDataProvider, this.FileName); @@ -331,7 +331,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor public void ShowCompletionWindow(ICompletionDataProvider completionDataProvider, char ch) { - codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow((Form)WorkbenchSingleton.Workbench, this, this.FileName, completionDataProvider, ch); + codeCompletionWindow = CodeCompletionWindow.ShowCompletionWindow(WorkbenchSingleton.MainForm, this, this.FileName, completionDataProvider, ch); if (codeCompletionWindow != null) { codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs index 39d1eed6b5..b115b98e53 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs @@ -362,7 +362,7 @@ namespace SearchAndReplace static void ShowNotFoundMessage(IProgressMonitor monitor) { if (monitor != null) monitor.ShowingDialog = true; - MessageBox.Show((Form)WorkbenchSingleton.Workbench, + MessageBox.Show(WorkbenchSingleton.MainForm, ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound"), ResourceService.GetString("Dialog.NewProject.SearchReplace.SearchStringNotFound.Title"), MessageBoxButtons.OK, diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs index 4b14bd6040..f045990654 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs @@ -76,7 +76,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp IReturnType t = finder.SearchType(nonGenericClassName, typeParameterCount); IClass c = (t != null) ? t.GetUnderlyingClass() : null; if (c != null) { - ExpressionContext context = ExpressionContext.TypeDerivingFrom(c, true); + ExpressionContext context = ExpressionContext.TypeDerivingFrom(t, true); if (context.ShowEntry(c)) { if (genericPart != null) { DefaultClass genericClass = new DefaultClass(c.CompilationUnit, c.ClassType, c.Modifiers, c.Region, c.DeclaringType); @@ -94,7 +94,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp } else { UnGet(); if (ReadIdentifier(GetNextNonWhiteSpace()) == "throw") { - return ExpressionContext.TypeDerivingFrom(HostCallback.GetCurrentProjectContent().GetClass("System.Exception", 0), true); + return ExpressionContext.TypeDerivingFrom(HostCallback.GetCurrentProjectContent().SystemTypes.Exception, true); } } return ExpressionContext.ObjectCreation; @@ -201,7 +201,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp /// /// Gets the position in the source string (after filtering out comments) - /// where the beginning of last expression was found. + /// where the beginning of last expression was found. /// public int LastExpressionStartPosition { get { diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs index 772bd6597f..3113461089 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs @@ -93,16 +93,16 @@ namespace ICSharpCode.SharpDevelop.Dom /// object creation. public static ExpressionContext GetAttribute(IProjectContent projectContent) { - return new TypeExpressionContext(projectContent.GetClass("System.Attribute", 0), false, true); + return new TypeExpressionContext(projectContent.SystemTypes.Attribute, false, true); } /// Context expects a type name which has special base type /// The class the expression must derive from. /// Specifies whether classes must be constructable. /// catch(*expr* ...), using(*expr* ...), throw new *** - public static ExpressionContext TypeDerivingFrom(IClass baseClass, bool isObjectCreation) + public static ExpressionContext TypeDerivingFrom(IReturnType baseType, bool isObjectCreation) { - return new TypeExpressionContext(baseClass, isObjectCreation, false); + return new TypeExpressionContext(baseType, isObjectCreation, false); } /// Context expects an interface @@ -163,9 +163,10 @@ namespace ICSharpCode.SharpDevelop.Dom IClass baseClass; bool isObjectCreation; - public TypeExpressionContext(IClass baseClass, bool isObjectCreation, bool readOnly) + public TypeExpressionContext(IReturnType baseType, bool isObjectCreation, bool readOnly) { - this.baseClass = baseClass; + if (baseType != null) + baseClass = baseType.GetUnderlyingClass(); this.isObjectCreation = isObjectCreation; this.readOnly = readOnly; } diff --git a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SystemTypes.cs b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SystemTypes.cs index 7b0aa2e709..91e97e055f 100644 --- a/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SystemTypes.cs +++ b/src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Implementations/SystemTypes.cs @@ -26,8 +26,10 @@ namespace ICSharpCode.SharpDevelop.Dom public readonly IReturnType Attribute; public readonly IReturnType Type; + public readonly IReturnType Exception; public readonly IReturnType AsyncCallback; public readonly IReturnType IAsyncResult; + public readonly IReturnType IDisposable; IProjectContent pc; @@ -47,8 +49,10 @@ namespace ICSharpCode.SharpDevelop.Dom Attribute = CreateFromName("System.Attribute"); Type = CreateFromName("System.Type"); + Exception = CreateFromName("System.Exception"); AsyncCallback = CreateFromName("System.AsyncCallback"); IAsyncResult = CreateFromName("System.IAsyncResult"); + IAsyncResult = CreateFromName("System.IDisposable"); } IReturnType CreateFromName(string name) diff --git a/src/Main/StartUp/Project/SharpDevelopMain.cs b/src/Main/StartUp/Project/SharpDevelopMain.cs index 7a5aa9a272..5913404284 100644 --- a/src/Main/StartUp/Project/SharpDevelopMain.cs +++ b/src/Main/StartUp/Project/SharpDevelopMain.cs @@ -155,7 +155,7 @@ namespace ICSharpCode.SharpDevelop return false; } } - return DefaultWorkbench.SingleInstanceHelper.OpenFilesInPreviousInstance(fileList); + return SingleInstanceHelper.OpenFilesInPreviousInstance(fileList); } catch (Exception ex) { LoggingService.Error(ex); return false; diff --git a/src/Tools/Tools.build b/src/Tools/Tools.build index e4aea6c9ed..b4208c12f8 100644 --- a/src/Tools/Tools.build +++ b/src/Tools/Tools.build @@ -13,17 +13,17 @@ - - - - - - - - - - - + + + + + + + + + + +