From a98624fe08750215f270579aec99ed769a2f4fb7 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 13 Apr 2009 12:07:36 +0000 Subject: [PATCH] Updated UI Added context menu to RingDiagramControl git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3988 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Misc/Profiler/Frontend/AddIn/AddIn.csproj | 2 +- .../AddIn/Src/Commands/CopySelectedData.cs | 8 +-- .../AddIn/Src/Commands/CopyStacktrace.cs | 8 +-- .../AddIn/Src/Commands/FindCallsOfSelected.cs | 7 +-- .../AddIn/Src/Commands/GoToDefinition.cs | 11 +--- .../AddIn/Src/Commands/ProfileExecutable.cs | 2 +- .../AddIn/Src/Commands/ProfileProject.cs | 2 +- .../AddIn/Src/Commands/ProfilerMenuCommand.cs | 61 +++++++++++++++++++ .../Frontend/AddIn/Src/Commands/SetAsRoot.cs | 11 ++-- .../AddIn/Src/Commands/ShowFunctions.cs | 16 ++--- .../AddIn/Src/Views/ProfilerView.xaml.cs | 15 +++-- .../Profiler/Frontend/Controls/QueryView.xaml | 6 +- .../Frontend/Controls/QueryView.xaml.cs | 16 +++-- .../Frontend/Controls/RingDiagramControl.cs | 2 + .../Misc/Profiler/Frontend/Gui/Window1.xaml | 2 +- 15 files changed, 115 insertions(+), 54 deletions(-) create mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfilerMenuCommand.cs diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj index 07ae87a857..6f0c5a3f66 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj @@ -94,7 +94,7 @@ - + ProfileExecutableForm.xaml diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopySelectedData.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopySelectedData.cs index 23d5e7e241..6209ca52a8 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopySelectedData.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopySelectedData.cs @@ -21,20 +21,20 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of CopySelectedData /// - public class CopySelectedData : AbstractMenuCommand + public class CopySelectedData : ProfilerMenuCommand { /// /// Starts the command /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); - ProfilerView parent = (((((QueryView)Owner).Parent as TabItem).Parent as TabControl).Parent as Grid).Parent as ProfilerView; + var list = GetSelectedItems(); - if (list.Count > 0) { + if (list.FirstOrDefault() != null) { StringBuilder builder = new StringBuilder(); foreach (CallTreeNodeViewModel node in list) { + if (node != null) builder.AppendLine(new string('\t', node.Level) + node.Name + "\t" + node.CallCount + "\t" + node.TimeSpent + "\t" + node.TimePercentageOfParentAsText); } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopyStacktrace.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopyStacktrace.cs index 3b1afa3240..edb099e9fa 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopyStacktrace.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/CopyStacktrace.cs @@ -7,9 +7,10 @@ using System; using System.Collections.Generic; -using System.Text; using System.Linq; +using System.Text; using System.Windows.Forms; +using System.Windows.Shapes; using ICSharpCode.Core; using ICSharpCode.Profiler.Controls; @@ -19,15 +20,14 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of CopyStacktrace /// - public class CopyStacktrace : AbstractMenuCommand + public class CopyStacktrace : ProfilerMenuCommand { /// /// Starts the command /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); - CallTreeNodeViewModel selectedItem = (list.Count > 0) ? list[0] as CallTreeNodeViewModel : null; + var selectedItem = GetSelectedItems().FirstOrDefault(); if (selectedItem != null) { StringBuilder data = new StringBuilder(); diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/FindCallsOfSelected.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/FindCallsOfSelected.cs index a481f677f5..21befa5451 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/FindCallsOfSelected.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/FindCallsOfSelected.cs @@ -23,15 +23,14 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of FindCallsOfSelected /// - public class FindCallsOfSelected : AbstractMenuCommand + public class FindCallsOfSelected : ProfilerMenuCommand { /// /// Starts the command /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); - ProfilerView parent = (((((QueryView)Owner).Parent as TabItem).Parent as TabControl).Parent as Grid).Parent as ProfilerView; + var list = GetSelectedItems().ToList(); if (list.Count > 0) { var items = from item in list select item.Node; @@ -47,7 +46,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands string header = "Results"; - parent.CreateTab(header, "from c in Calls where " + string.Join(" || ", parts.ToArray()) + " select c"); + Parent.CreateTab(header, "from c in Calls where " + string.Join(" || ", parts.ToArray()) + " select c"); } } } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/GoToDefinition.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/GoToDefinition.cs index 5765b31434..faf9f82c6e 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/GoToDefinition.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/GoToDefinition.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of GoToDefinition /// - public class GoToDefinition : AbstractMenuCommand + public class GoToDefinition : ProfilerMenuCommand { IAmbience ambience = new CSharpAmbience(); @@ -31,12 +31,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); - - if (list.Count == 0) - return; - - CallTreeNodeViewModel selectedItem = list.First(); + var selectedItem = GetSelectedItems().FirstOrDefault(); if (selectedItem != null) { IClass c = GetClassFromName(selectedItem.FullyQualifiedClassName); @@ -44,7 +39,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands { IMember member = GetMemberFromName(c, selectedItem.MethodName, selectedItem.Parameters); if (member != null) { - IViewContent view = FileService.JumpToFilePosition(c.CompilationUnit.FileName, member.BodyRegion.BeginLine, member.BodyRegion.BeginColumn); + IViewContent view = FileService.JumpToFilePosition(c.CompilationUnit.FileName, member.BodyRegion.BeginLine - 1, member.BodyRegion.BeginColumn - 1); } } } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileExecutable.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileExecutable.cs index 1f13bf432e..eaccea7dd2 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileExecutable.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileExecutable.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of RunExecutable /// - public class ProfileExecutable : AbstractMenuCommand + public class ProfileExecutable : ProfilerMenuCommand { /// /// Starts the command diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs index c93dd07543..28a37e3cf2 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfileProject.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of RunProject /// - public class ProfileProject : AbstractMenuCommand + public class ProfileProject : ProfilerMenuCommand { /// /// Starts the command diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfilerMenuCommand.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfilerMenuCommand.cs new file mode 100644 index 0000000000..38c0980739 --- /dev/null +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ProfilerMenuCommand.cs @@ -0,0 +1,61 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Shapes; + +using ICSharpCode.Core; +using ICSharpCode.Profiler.AddIn.Views; +using ICSharpCode.Profiler.Controls; + +namespace ICSharpCode.Profiler.AddIn.Commands +{ + /// + /// Description of ProfilerMenuCommand. + /// + public abstract class ProfilerMenuCommand : AbstractMenuCommand + { + public abstract override void Run(); + + protected virtual IEnumerable GetSelectedItems() + { + if (Owner is Shape) + yield return (Owner as Shape).Tag as CallTreeNodeViewModel; + else { + var fe = TryToFindParent(typeof(QueryView)) as QueryView; + + if (fe != null) { + foreach (var item in fe.SelectedItems) + yield return item; + } + } + } + + protected virtual ProfilerView Parent { + get { + return TryToFindParent(typeof(ProfilerView)) as ProfilerView; + } + } + + FrameworkElement TryToFindParent(Type type) + { + FrameworkElement start = Owner as FrameworkElement; + + if (start == null) + return null; + + while (start != null && !start.GetType().Equals(type)) + start = start.Parent as FrameworkElement; + + return start; + } + } +} diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/SetAsRoot.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/SetAsRoot.cs index 6f0e08a166..2572f364f4 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/SetAsRoot.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/SetAsRoot.cs @@ -23,19 +23,16 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of SetAsRoot /// - public class SetAsRoot : AbstractMenuCommand + public class SetAsRoot : ProfilerMenuCommand { /// /// Starts the command /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); - ProfilerView parent = (((((QueryView)Owner).Parent as TabItem).Parent as TabControl).Parent as Grid).Parent as ProfilerView; + var items = GetSelectedItems().Where(item => item != null && item.Node != null).Select(i => i.Node); - if (list.Count > 0) { - var items = from item in list select item.Node; - + if (items.FirstOrDefault() != null) { List parts = new List(); int? nameId = items.First().NameMapping.Id; // use nullable int to represent non assigned nameId @@ -51,7 +48,7 @@ namespace ICSharpCode.Profiler.AddIn.Commands if (nameId == null) header = "Merged Nodes"; - parent.CreateTab(header, "Merge(" + string.Join(",", parts.ToArray()) + ")"); + Parent.CreateTab(header, "Merge(" + string.Join(",", parts.ToArray()) + ")"); } } } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ShowFunctions.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ShowFunctions.cs index 07e33c38b2..ea2b8fd116 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ShowFunctions.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Commands/ShowFunctions.cs @@ -21,24 +21,18 @@ namespace ICSharpCode.Profiler.AddIn.Commands /// /// Description of ShowFunctions /// - public class ShowFunctions : AbstractMenuCommand + public class ShowFunctions : ProfilerMenuCommand { /// /// Starts the command /// public override void Run() { - IList list = ((QueryView)Owner).SelectedItems.ToList(); + var selectedItem = GetSelectedItems().FirstOrDefault(); - if (list.Count == 0) - return; - - CallTreeNodeViewModel selectedItem = list.First(); - - if (selectedItem != null) { - ProfilerView parent = (((((QueryView)Owner).Parent as TabItem).Parent as TabControl).Parent as Grid).Parent as ProfilerView; - parent.CreateTab("All functions for " + selectedItem.GetSignature(), "from f in Functions where f.Signature == \"" + selectedItem.GetSignature() + "\" select f"); - } + if (selectedItem != null) + Parent.CreateTab("All functions for " + selectedItem.GetSignature(), + "from f in Functions where f.Signature == \"" + selectedItem.GetSignature() + "\" select f"); } } } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs index 5c8b6fa454..7267439e08 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Shapes; using System.Windows.Threading; using ICSharpCode.Core.Presentation; @@ -34,10 +35,14 @@ namespace ICSharpCode.Profiler.AddIn.Views foreach (TabItem item in this.tabView.Items) { if (item.Content != null) { - ((QueryView)item.Content).Reporter = new ErrorReporter(UpdateErrorList); - ((QueryView)item.Content).Provider = provider; - ((QueryView)item.Content).SetRange(this.timeLine.SelectedStartIndex, this.timeLine.SelectedEndIndex); - ((QueryView)item.Content).TreeViewContextMenu = MenuService.CreateContextMenu(item.Content, "/AddIns/Profiler/QueryView/ContextMenu"); + QueryView view = item.Content as QueryView; + view.Reporter = new ErrorReporter(UpdateErrorList); + view.Provider = provider; + view.SetRange(this.timeLine.SelectedStartIndex, this.timeLine.SelectedEndIndex); + view.ContextMenuOpening += delegate(object sender, ContextMenuEventArgs e) { + object source = (e.OriginalSource is Shape) ? e.OriginalSource : view; + MenuService.CreateContextMenu(source, "/AddIns/Profiler/QueryView/ContextMenu").IsOpen = true; + }; } } @@ -168,7 +173,7 @@ namespace ICSharpCode.Profiler.AddIn.Views view.CurrentQuery = query; view.ShowQueryItems = true; - view.TreeViewContextMenu = MenuService.CreateContextMenu(view, "/AddIns/Profiler/QueryView/ContextMenu"); + //view.TreeViewContextMenu = ; view.CurrentQueryChanged += delegate { ViewCurrentQueryChanged(header, view); }; diff --git a/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml b/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml index a6d06f7264..adc437ca03 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml +++ b/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml @@ -83,21 +83,21 @@ - + - + - + diff --git a/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml.cs index a9ded74af5..7d5464c8e1 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml.cs +++ b/src/AddIns/Misc/Profiler/Frontend/Controls/QueryView.xaml.cs @@ -41,7 +41,6 @@ namespace ICSharpCode.Profiler.Controls bool isDirty; - public string View { get; set; } public ErrorReporter Reporter { get; set; } public event EventHandler CurrentQueryChanged; @@ -91,8 +90,13 @@ namespace ICSharpCode.Profiler.Controls this.DataContext = this; this.task = new SingleTask(this.Dispatcher); this.treeView.SizeChanged += delegate(object sender, SizeChangedEventArgs e) { - if (e.NewSize.Width > 0 && e.PreviousSize.Width > 0 && (nameColumn.Width + (e.NewSize.Width - e.PreviousSize.Width)) > 0) { - nameColumn.Width += (e.NewSize.Width - e.PreviousSize.Width); + if (e.NewSize.Width > 0 && e.PreviousSize.Width > 0 && + (nameColumn.Width + (e.NewSize.Width - e.PreviousSize.Width)) > 0) { + if ((nameColumn.Width + (e.NewSize.Width - e.PreviousSize.Width)) >= + (e.NewSize.Width - this.callCountColumn.Width - this.percentColumn.Width - this.timeSpentColumn.Width)) + this.nameColumn.Width = e.NewSize.Width - this.callCountColumn.Width - this.percentColumn.Width - this.timeSpentColumn.Width - 25; + else + nameColumn.Width += (e.NewSize.Width - e.PreviousSize.Width); } }; } @@ -159,6 +163,10 @@ namespace ICSharpCode.Profiler.Controls list => LoadCompleted(list, layer, ad), delegate { layer.Remove(ad); }); } + + public RingDiagramControl RingDiagram { + get { return ringDiagram; } + } static HierarchyList LoadWorker(ProfilingDataProvider provider, QueryCompiler compiler, int rangeStart, int rangeEnd) { @@ -212,7 +220,7 @@ namespace ICSharpCode.Profiler.Controls public ContextMenu TreeViewContextMenu { get { return this.treeView.ContextMenu; } - set { this.treeView.ContextMenu = value; } + set { this.treeView.ContextMenu = this.ringDiagram.ContextMenu = value; } } } } \ No newline at end of file diff --git a/src/AddIns/Misc/Profiler/Frontend/Controls/RingDiagramControl.cs b/src/AddIns/Misc/Profiler/Frontend/Controls/RingDiagramControl.cs index d3e6af00c9..2ad431a03c 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Controls/RingDiagramControl.cs +++ b/src/AddIns/Misc/Profiler/Frontend/Controls/RingDiagramControl.cs @@ -74,6 +74,7 @@ namespace ICSharpCode.Profiler.Controls ell.Fill = Brushes.Gray; ell.Stroke = Brushes.Black; ell.ToolTip = item.CreateToolTip(); + ell.Tag = item; ell.MouseLeftButtonDown += (sender, e) => { @@ -154,6 +155,7 @@ namespace ICSharpCode.Profiler.Controls p.VerticalAlignment = VerticalAlignment.Center; p.HorizontalAlignment = HorizontalAlignment.Center; p.Tag = node; + //p.ContextMenu = this.ContextMenu.; p.MouseLeftButtonDown += new MouseButtonEventHandler( delegate(object sender, MouseButtonEventArgs e) { diff --git a/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml b/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml index 07f2e8e202..65df80713d 100644 --- a/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml +++ b/src/AddIns/Misc/Profiler/Frontend/Gui/Window1.xaml @@ -18,7 +18,7 @@ - +