From 6a23e5ae9b388f285c769152f7c31b4136dc7aab Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 3 Sep 2019 14:10:37 +0200 Subject: [PATCH] work on docking ui --- ILSpy/Analyzers/AnalyzerTreeView.cs | 2 +- ILSpy/Controls/DockedPane.cs | 76 ----------------------- ILSpy/DebugSteps.xaml.cs | 2 +- ILSpy/Docking/DockingHelper.cs | 27 +++++++++ ILSpy/Docking/PanePosition.cs | 8 +++ ILSpy/ILSpy.csproj | 3 +- ILSpy/MainWindow.xaml | 41 ++----------- ILSpy/MainWindow.xaml.cs | 93 ++++++++--------------------- ILSpy/Search/SearchPane.cs | 2 +- ILSpy/themes/generic.xaml | 91 +--------------------------- 10 files changed, 69 insertions(+), 276 deletions(-) delete mode 100644 ILSpy/Controls/DockedPane.cs create mode 100644 ILSpy/Docking/DockingHelper.cs create mode 100644 ILSpy/Docking/PanePosition.cs diff --git a/ILSpy/Analyzers/AnalyzerTreeView.cs b/ILSpy/Analyzers/AnalyzerTreeView.cs index 54256935e..13b29bd3f 100644 --- a/ILSpy/Analyzers/AnalyzerTreeView.cs +++ b/ILSpy/Analyzers/AnalyzerTreeView.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.Analyzers public void Show() { if (!IsVisible) - MainWindow.Instance.ShowInBottomPane("Analyzer", this); + MainWindow.Instance.ShowInNewPane("Analyzer", this, PanePosition.Bottom); } public void Show(AnalyzerTreeNode node) diff --git a/ILSpy/Controls/DockedPane.cs b/ILSpy/Controls/DockedPane.cs deleted file mode 100644 index 6f370ce95..000000000 --- a/ILSpy/Controls/DockedPane.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; - -namespace ICSharpCode.ILSpy.Controls -{ - class DockedPane : Control - { - static DockedPane() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(DockedPane), new FrameworkPropertyMetadata(typeof(DockedPane))); - } - - public static readonly DependencyProperty TitleProperty = - DependencyProperty.Register("Title", typeof(string), typeof(DockedPane)); - - public string Title { - get { return (string)GetValue(TitleProperty); } - set { SetValue(TitleProperty, value); } - } - - public static readonly DependencyProperty ContentProperty = - DependencyProperty.Register("Content", typeof(object), typeof(DockedPane)); - - public object Content { - get { return GetValue(ContentProperty); } - set { SetValue(ContentProperty, value); } - } - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - Button closeButton = (Button)this.Template.FindName("PART_Close", this); - if (closeButton != null) { - closeButton.Click += closeButton_Click; - } - } - - void closeButton_Click(object sender, RoutedEventArgs e) - { - if (CloseButtonClicked != null) - CloseButtonClicked(this, e); - } - - public event EventHandler CloseButtonClicked; - - protected override void OnKeyDown(KeyEventArgs e) - { - base.OnKeyDown(e); - if (e.Key == Key.F4 && e.KeyboardDevice.Modifiers == ModifierKeys.Control || e.Key == Key.Escape) { - if (CloseButtonClicked != null) - CloseButtonClicked(this, e); - e.Handled = true; - } - } - } -} diff --git a/ILSpy/DebugSteps.xaml.cs b/ILSpy/DebugSteps.xaml.cs index 131530740..ba13f1d84 100644 --- a/ILSpy/DebugSteps.xaml.cs +++ b/ILSpy/DebugSteps.xaml.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.ILSpy public static void Show() { - MainWindow.Instance.ShowInTopPane(Properties.Resources.DebugSteps, new DebugSteps()); + MainWindow.Instance.ShowInNewPane(Properties.Resources.DebugSteps, new DebugSteps(), PanePosition.Top); } void IPane.Closed() diff --git a/ILSpy/Docking/DockingHelper.cs b/ILSpy/Docking/DockingHelper.cs new file mode 100644 index 000000000..449d703b6 --- /dev/null +++ b/ILSpy/Docking/DockingHelper.cs @@ -0,0 +1,27 @@ +using System.Windows; +using System.Windows.Controls; +using Xceed.Wpf.AvalonDock.Layout; + +namespace ICSharpCode.ILSpy.Docking +{ + public static class DockingHelper + { + public static void DockHorizontal(LayoutContent layoutContent, ILayoutElement paneRelativeTo, GridLength dockHeight, bool dockBefore = false) + { + if (paneRelativeTo is ILayoutDocumentPane parentDocumentPane) { + var parentDocumentGroup = paneRelativeTo.FindParent(); + if (parentDocumentGroup == null) { + var grandParent = parentDocumentPane.Parent as ILayoutContainer; + parentDocumentGroup = new LayoutDocumentPaneGroup() { Orientation = System.Windows.Controls.Orientation.Vertical }; + grandParent.ReplaceChild(paneRelativeTo, parentDocumentGroup); + parentDocumentGroup.Children.Add(parentDocumentPane); + } + parentDocumentGroup.Orientation = System.Windows.Controls.Orientation.Vertical; + int indexOfParentPane = parentDocumentGroup.IndexOfChild(parentDocumentPane); + parentDocumentGroup.InsertChildAt(dockBefore ? indexOfParentPane : indexOfParentPane + 1, new LayoutDocumentPane(layoutContent) { DockHeight = dockHeight }); + layoutContent.IsActive = true; + layoutContent.Root.CollectGarbage(); + } + } + } +} diff --git a/ILSpy/Docking/PanePosition.cs b/ILSpy/Docking/PanePosition.cs new file mode 100644 index 000000000..d0ff28370 --- /dev/null +++ b/ILSpy/Docking/PanePosition.cs @@ -0,0 +1,8 @@ +namespace ICSharpCode.ILSpy +{ + public enum PanePosition + { + Top, + Bottom + } +} diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 3ddf7448a..6c58619d0 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -124,7 +124,6 @@ ResourceObjectTable.xaml - @@ -138,6 +137,7 @@ DebugSteps.xaml + @@ -164,6 +164,7 @@ + True True diff --git a/ILSpy/MainWindow.xaml b/ILSpy/MainWindow.xaml index 5bd6722b1..75ef145a4 100644 --- a/ILSpy/MainWindow.xaml +++ b/ILSpy/MainWindow.xaml @@ -115,7 +115,7 @@ - + @@ -131,20 +131,18 @@ - + - + - - @@ -156,39 +154,8 @@ - - - - - - - - - + diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 9df0fc9e2..5f564205b 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -44,6 +44,7 @@ using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.TreeView; using Microsoft.Win32; using OSVersionHelper; +using Xceed.Wpf.AvalonDock.Layout; namespace ICSharpCode.ILSpy { @@ -1025,10 +1026,10 @@ namespace ICSharpCode.ILSpy sessionSettings.WindowBounds = this.RestoreBounds; //todo //sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value); - if (topPane.Visibility == Visibility.Visible) - sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value); - if (bottomPane.Visibility == Visibility.Visible) - sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); + //if (topPane.Visibility == Visibility.Visible) + // sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value); + //if (bottomPane.Visibility == Visibility.Visible) + // sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); sessionSettings.Save(); } @@ -1072,73 +1073,27 @@ namespace ICSharpCode.ILSpy pane1Row.Height = new GridLength(pane1Height.Value / totalHeight, GridUnitType.Star); pane2Row.Height = new GridLength(pane2Height.Value / totalHeight, GridUnitType.Star); - } - - public void ShowInTopPane(string title, object content) - { - topPaneRow.MinHeight = 100; - if (sessionSettings.TopPaneSplitterPosition > 0 && sessionSettings.TopPaneSplitterPosition < 1) { - //Ensure all 3 blocks are in fair conditions - NormalizePaneRowHeightValues(bottomPaneRow, textViewRow); - - textViewRow.Height = new GridLength(1 - sessionSettings.TopPaneSplitterPosition, GridUnitType.Star); - topPaneRow.Height = new GridLength(sessionSettings.TopPaneSplitterPosition, GridUnitType.Star); - } - topPane.Title = title; - if (topPane.Content != content) { - IPane pane = topPane.Content as IPane; - if (pane != null) - pane.Closed(); - topPane.Content = content; - } - topPane.Visibility = Visibility.Visible; - } + } - void TopPane_CloseButtonClicked(object sender, EventArgs e) + public void ShowInNewPane(string title, object content, PanePosition panePosition) { - sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value); - topPaneRow.MinHeight = 0; - topPaneRow.Height = new GridLength(0); - topPane.Visibility = Visibility.Collapsed; - - IPane pane = topPane.Content as IPane; - topPane.Content = null; - if (pane != null) - pane.Closed(); - } - - public void ShowInBottomPane(string title, object content) - { - bottomPaneRow.MinHeight = 100; - if (sessionSettings.BottomPaneSplitterPosition > 0 && sessionSettings.BottomPaneSplitterPosition < 1) { - //Ensure all 3 blocks are in fair conditions - NormalizePaneRowHeightValues(topPaneRow, textViewRow); - - textViewRow.Height = new GridLength(1 - sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star); - bottomPaneRow.Height = new GridLength(sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star); - } - bottomPane.Title = title; - if (bottomPane.Content != content) { - IPane pane = bottomPane.Content as IPane; - if (pane != null) - pane.Closed(); - bottomPane.Content = content; - } - bottomPane.Visibility = Visibility.Visible; - } - - void BottomPane_CloseButtonClicked(object sender, EventArgs e) - { - sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); - bottomPaneRow.MinHeight = 0; - bottomPaneRow.Height = new GridLength(0); - bottomPane.Visibility = Visibility.Collapsed; - - IPane pane = bottomPane.Content as IPane; - bottomPane.Content = null; - if (pane != null) - pane.Closed(); - } + var layoutAnchorable = new LayoutAnchorable() { Title = title, Content = content }; + var documentPane = this.DockManager.Layout.Descendents().OfType().FirstOrDefault(); + Docking.DockingHelper.DockHorizontal(layoutAnchorable, documentPane, new GridLength(100), panePosition == PanePosition.Top); + } + + //void BottomPane_CloseButtonClicked(object sender, EventArgs e) + //{ + // sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value); + // bottomPaneRow.MinHeight = 0; + // bottomPaneRow.Height = new GridLength(0); + // bottomPane.Visibility = Visibility.Collapsed; + + // IPane pane = bottomPane.Content as IPane; + // bottomPane.Content = null; + // if (pane != null) + // pane.Closed(); + //} #endregion public void UnselectAll() diff --git a/ILSpy/Search/SearchPane.cs b/ILSpy/Search/SearchPane.cs index f911fd3a6..f1394239e 100644 --- a/ILSpy/Search/SearchPane.cs +++ b/ILSpy/Search/SearchPane.cs @@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy public void Show() { if (!IsVisible) { - MainWindow.Instance.ShowInTopPane(Properties.Resources.SearchPane_Search, this); + MainWindow.Instance.ShowInNewPane(Properties.Resources.SearchPane_Search, this, PanePosition.Top); if (runSearchOnNextShow) { runSearchOnNextShow = false; StartSearch(this.SearchTerm); diff --git a/ILSpy/themes/generic.xaml b/ILSpy/themes/generic.xaml index a72a988d5..8bb3384fa 100644 --- a/ILSpy/themes/generic.xaml +++ b/ILSpy/themes/generic.xaml @@ -10,7 +10,7 @@ Displays an up arrow or down arrow in the column header when the grid is sorted using that column. --> - + @@ -26,93 +26,4 @@ Data = "M 5,5 L 10,10 L 15,5 L 5,5"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file