diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs index 5662c0672f..49fef4fef3 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs @@ -47,6 +47,11 @@ namespace CSharpBinding.Refactoring get { return description; } } + public string GetDisplayName(EditorRefactoringContext context) + { + return DisplayName; + } + public void Execute(EditorRefactoringContext context) { SD.AnalyticsMonitor.TrackFeature(provider.ID); diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs index 00ce53d9f7..6966d54b38 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs @@ -41,7 +41,30 @@ namespace CSharpBinding.Refactoring return false; return identifier.Parent is TypeDeclaration || identifier.Parent is DelegateDeclaration; } - + + public override string DisplayName + { + get { + return "Move type to file"; + } + } + + public override string GetDisplayName(EditorRefactoringContext context) + { + CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation; + if (parseInformation != null) { + SyntaxTree st = parseInformation.SyntaxTree; + Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier); + if (identifier == null) + return DisplayName; + + return StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}", + new StringTagPair("FileName", MakeValidFileName(identifier.Name))); + } + + return DisplayName; + } + public override async void Execute(EditorRefactoringContext context) { SyntaxTree st = await context.GetSyntaxTreeAsync().ConfigureAwait(false); @@ -131,9 +154,5 @@ namespace CSharpBinding.Refactoring return name.RemoveAny(Path.GetInvalidFileNameChars()) + ".cs"; return name + ".cs"; } - - public override string DisplayName { - get { return "Move type to file"; } - } } } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs index e800c08362..e7a6637e16 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs @@ -52,13 +52,29 @@ namespace CSharpBinding.Refactoring } } - public override string DisplayName { + public override string DisplayName + { get { - // TODO Use the string from resource file! But this needs to become GetDisplayName(context) first. return "Rename file to match type name"; } } + public override string GetDisplayName(EditorRefactoringContext context) + { + CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation; + if (parseInformation != null) { + SyntaxTree st = parseInformation.SyntaxTree; + Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier); + if (identifier == null) + return DisplayName; + + return StringParser.Parse("${res:SharpDevelop.Refactoring.RenameFileTo}", + new StringTagPair("FileName", MakeValidFileName(identifier.Name))); + } + + return DisplayName; + } + string MakeValidFileName(string name) { if (name == null) diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs index a4e06f6bec..dc5244a52a 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs @@ -3,19 +3,10 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; -using System.Runtime.Remoting.Lifetime; -using System.Threading; using ICSharpCode.NRefactory; -using ICSharpCode.NRefactory.CSharp.Resolver; -using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem.Implementation; -using ICSharpCode.NRefactory.Xml; -using ICSharpCode.SharpDevelop.Parser; -using ICSharpCode.XmlEditor; namespace ICSharpCode.XamlBinding { @@ -37,12 +28,7 @@ namespace ICSharpCode.XamlBinding { string prefix, memberName; string name = ParseName(expression, out prefix, out memberName); - string namespaceUrl; - - if (prefix == "") - namespaceUrl = context.ActiveElement.Namespace; - else - namespaceUrl = context.ActiveElement.ResolvePrefix(prefix); + string namespaceUrl = context.ActiveElement.LookupNamespace(prefix); if (string.IsNullOrEmpty(memberName)) { IType type = ResolveType(namespaceUrl, context.ActiveElement.LocalName); IMember member = type.GetMembers(m => m.Name == name).FirstOrDefault(); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs index efc98ac504..2f4ddbcf4f 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlUnresolvedFile.cs @@ -111,14 +111,17 @@ namespace ICSharpCode.XamlBinding public static ITypeReference CreateTypeReference(string @namespace, string localName) { - if (@namespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase)) { + if (@namespace == null) + return new UnknownType(null, localName); + if (@namespace.StartsWith("clr-namespace:", StringComparison.OrdinalIgnoreCase)) return CreateClrNamespaceTypeReference(@namespace.Substring("clr-namespace:".Length), localName); - } return new XamlTypeReference(@namespace, localName); } public static ITypeReference CreateClrNamespaceTypeReference(string @namespace, string localName) { + if (@namespace == null) + return new UnknownType(null, localName); int assemblyNameIndex = @namespace.IndexOf(";assembly=", StringComparison.OrdinalIgnoreCase); IAssemblyReference asm = DefaultAssemblyReference.CurrentAssembly; if (assemblyNameIndex > -1) { diff --git a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin index c7143dbb8d..4d7ad92c6b 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin +++ b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin @@ -68,6 +68,15 @@ + + + + + + + + + + diff --git a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj index ab07982060..711a36f285 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj +++ b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj @@ -111,6 +111,7 @@ Code + @@ -138,6 +139,9 @@ EditBreakpointScriptWindow.xaml Code + + ExecuteProcessWindow.xaml + @@ -311,6 +315,7 @@ + diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs index 8192c68cbf..0b50c9ee59 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs @@ -69,6 +69,16 @@ namespace ICSharpCode.SharpDevelop.Services set { PS.Set("Debugger.PauseOnHandledExceptions", value); } } + public bool AskForArguments { + get { return PS.Get("Debugger.AskForArguments", false); } + set { PS.Set("Debugger.AskForArguments", value); } + } + + public bool BreakAtBeginning { + get { return PS.Get("Debugger.BreakAtBeginning", false); } + set { PS.Set("Debugger.BreakAtBeginning", value); } + } + public ShowIntegersAs ShowIntegersAs { get { return PS.Get("Debugger.ShowIntegersAs", ShowIntegersAs.Decimal); } set { PS.Set("Debugger.ShowIntegersAs", value); } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml index 5cc4caef34..7134b3fa66 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml @@ -34,5 +34,13 @@ IsChecked="{sd:OptionBinding debugger:DebuggingOptions.SuppressNGENOptimization}" /> + + + + + + \ No newline at end of file diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/ClassBrowserSupport.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/ClassBrowserSupport.cs new file mode 100644 index 0000000000..d4b76afdaf --- /dev/null +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/ClassBrowserSupport.cs @@ -0,0 +1,149 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.IO; +using Debugger; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Dom.ClassBrowser; +using System.Linq; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + /// + /// Description of ClassBrowserSupport. + /// + public static class ClassBrowserSupport + { + public static void Attach(Debugger.Process process) + { + var classBrowser = SD.GetService(); + classBrowser.SpecialNodes.Add(new DebuggerProcessTreeNode(process)); + } + + public static void Detach(Debugger.Process process) + { + var classBrowser = SD.GetService(); + var nodes = classBrowser.SpecialNodes + .Where(n => n.Model == process) + .ToArray(); + foreach (var node in nodes) { + classBrowser.SpecialNodes.Remove(node); + } + } + } + + class DebuggerTreeNodesFactory : ITreeNodeFactory + { + public Type GetSupportedType(object model) + { + if (model is Debugger.Process) + return typeof(Debugger.Process); + if (model is Debugger.Module) + return typeof(Debugger.Module); + return null; + } + + public ICSharpCode.TreeView.SharpTreeNode CreateTreeNode(object model) + { + if (model is Debugger.Process) + return new DebuggerProcessTreeNode((Debugger.Process)model); + if (model is Debugger.Module) + return new DebuggerModuleTreeNode((Debugger.Module)model); + return null; + } + } + + class DebuggerProcessTreeNode : ModelCollectionTreeNode + { + Debugger.Process process; + IMutableModelCollection modules; + + public DebuggerProcessTreeNode(Debugger.Process process) + { + if (process == null) + throw new ArgumentNullException("process"); + this.process = process; + this.modules = new SimpleModelCollection(this.process.Modules); + this.process.ModuleLoaded += ModuleLoaded; + this.process.ModuleUnloaded += ModuleUnloaded; + } + + void ModuleLoaded(object sender, ModuleEventArgs e) + { + modules.Add(e.Module); + } + + void ModuleUnloaded(object sender, ModuleEventArgs e) + { + modules.Remove(e.Module); + } + + protected override object GetModel() + { + return process; + } + + protected override IModelCollection ModelChildren { + get { + return modules; + } + } + + protected override System.Collections.Generic.IComparer NodeComparer { + get { + return NodeTextComparer; + } + } + + public override object Text { + get { + return Path.GetFileName(process.Filename); + } + } + + public override object Icon { + get { + return IconService.GetImageSource("Icons.16x16.Debug.Start"); + } + } + } + + class DebuggerModuleTreeNode : AssemblyTreeNode + { + Debugger.Module module; + + public DebuggerModuleTreeNode(Module module) + : base(CreateAssemblyModel(module)) + { + if (module == null) + throw new ArgumentNullException("module"); + this.module = module; + } + + public override object Icon { + get { + return IconService.GetImageSource("PadIcons.LoadedModules"); + } + } + + public override object Text { + get { + return module.Name; + } + } + + static IAssemblyModel CreateAssemblyModel(Module module) + { + // references?? + IEntityModelContext context = new AssemblyEntityModelContext(module.Assembly.UnresolvedAssembly); + IAssemblyModel model = SD.GetRequiredService().CreateAssemblyModel(context); + if (model is IUpdateableAssemblyModel) { + ((IUpdateableAssemblyModel)model).Update(EmptyList.Instance, module.Assembly.TopLevelTypeDefinitions.SelectMany(td => td.Parts).ToList()); + } + return model; + } + } +} diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/DebuggerCommands.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/DebuggerCommands.cs index 87f76cf11e..76b61a22a7 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/DebuggerCommands.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/DebuggerCommands.cs @@ -3,11 +3,14 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Debugging; using ICSharpCode.SharpDevelop.Editor; +using Microsoft.Win32; using ICSharpCode.SharpDevelop.Services; namespace Debugger.AddIn @@ -28,7 +31,7 @@ namespace Debugger.AddIn public override void Run() { ITextEditor textEditor = SD.GetActiveViewContentService(); - + if (textEditor == null || DebuggerService.CurrentDebugger == null) return; @@ -97,4 +100,41 @@ namespace Debugger.AddIn return BreakpointUtil.BreakpointsOnCaret.Any(); } } + + public class DebugExecutableMenuCommand : AbstractMenuCommand + { + public override void Run() + { + if (DebuggingOptions.Instance.AskForArguments) { + var window = new ExecuteProcessWindow { Owner = SD.Workbench.MainWindow }; + if (window.ShowDialog() == true) { + string fileName = window.SelectedExecutable; + + // execute the process + StartExecutable(fileName, window.WorkingDirectory, window.Arguments); + } + } else { + OpenFileDialog dialog = new OpenFileDialog() { + Filter = ".NET Executable (*.exe) | *.exe", + RestoreDirectory = true, + DefaultExt = "exe" + }; + if (dialog.ShowDialog() == true) { + string fileName = dialog.FileName; + // execute the process + StartExecutable(fileName); + } + } + } + + void StartExecutable(string fileName, string workingDirectory = null, string arguments = null) + { + DebuggerService.CurrentDebugger.BreakAtBeginning = DebuggingOptions.Instance.BreakAtBeginning; + DebuggerService.CurrentDebugger.Start(new ProcessStartInfo { + FileName = fileName, + WorkingDirectory = workingDirectory ?? Path.GetDirectoryName(fileName), + Arguments = arguments + }); + } + } } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/ExecuteProcessWindow.xaml b/src/AddIns/Debugger/Debugger.AddIn/Service/ExecuteProcessWindow.xaml new file mode 100644 index 0000000000..e3e510fcc0 --- /dev/null +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/ExecuteProcessWindow.xaml @@ -0,0 +1,113 @@ + + + + + + + +