From d1c8b7b8488f7f023abd1626ac1cf51ade2e8d78 Mon Sep 17 00:00:00 2001 From: Christopher Brown Date: Thu, 14 Feb 2019 14:30:51 +0000 Subject: [PATCH] Navigator window now allows for zero open documents. --- .../Controls/NavigatorWindow.cs | 165 +++++++++--------- 1 file changed, 86 insertions(+), 79 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.AvalonDock/Controls/NavigatorWindow.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.AvalonDock/Controls/NavigatorWindow.cs index 9c2ea878..9d839124 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.AvalonDock/Controls/NavigatorWindow.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.AvalonDock/Controls/NavigatorWindow.cs @@ -244,85 +244,92 @@ namespace Xceed.Wpf.AvalonDock.Controls _documentListBox = this.GetTemplateChild( PART_DocumentListBox ) as ListBox; } - protected override void OnPreviewKeyDown( System.Windows.Input.KeyEventArgs e ) - { - bool shouldHandle = false; - - // Press Tab to switch Selected LayoutContent. - if( e.Key == System.Windows.Input.Key.Tab) - { - // Selecting LayoutDocuments - if( _isSelectingDocument ) - { - if( this.SelectedDocument != null ) - { - // Jump to next LayoutDocument - var docIndex = this.Documents.IndexOf( this.SelectedDocument ); - if( docIndex < (this.Documents.Length - 1) ) - { - this.SelectNextDocument(); - shouldHandle = true; - } - // Jump to first LayoutAnchorable - else if( this.Anchorables.Count() > 0 ) - { - _isSelectingDocument = false; - this.InternalSetSelectedDocument( null ); - this.InternalSetSelectedAnchorable( this.Anchorables.First() ); - shouldHandle = true; - } - } - // There is no SelectedDocument, select the first one. - else - { - if( this.Documents.Length > 0 ) - { - this.InternalSetSelectedDocument( this.Documents[ 0 ] ); - shouldHandle = true; - } - } - } - // Selecting LayoutAnchorables - else - { - if( this.SelectedAnchorable != null ) - { - // Jump to next LayoutAnchorable - var anchorableIndex = this.Anchorables.ToArray().IndexOf( this.SelectedAnchorable ); - if( anchorableIndex < (this.Anchorables.Count() - 1) ) - { - this.SelectNextAnchorable(); - shouldHandle = true; - } - // Jump to first LayoutDocument - else if( this.Documents.Length > 0 ) - { - _isSelectingDocument = true; - this.InternalSetSelectedAnchorable( null ); - this.InternalSetSelectedDocument( this.Documents[ 0 ] ); - shouldHandle = true; - } - } - // There is no SelectedAnchorable, select the first one. - else - { - if( this.Anchorables.Count() > 0 ) - { - this.InternalSetSelectedAnchorable( this.Anchorables.ToArray()[ 0 ] ); - shouldHandle = true; - } - } - } - } - - if( shouldHandle ) - { - e.Handled = true; - } - base.OnPreviewKeyDown( e ); - } - - protected override void OnPreviewKeyUp( System.Windows.Input.KeyEventArgs e ) + protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e) + { + bool shouldHandle = false; + + // Press Tab to switch Selected LayoutContent. + if (e.Key == System.Windows.Input.Key.Tab) + { + // Selecting LayoutDocuments + if (_isSelectingDocument) + { + if (this.SelectedDocument != null) + { + // Jump to next LayoutDocument + var docIndex = this.Documents.IndexOf(this.SelectedDocument); + if (docIndex < (this.Documents.Length - 1)) + { + this.SelectNextDocument(); + shouldHandle = true; + } + // Jump to first LayoutAnchorable + else if (this.Anchorables.Count() > 0) + { + _isSelectingDocument = false; + this.InternalSetSelectedDocument(null); + this.InternalSetSelectedAnchorable(this.Anchorables.First()); + shouldHandle = true; + } + } + // There is no SelectedDocument, select the first one. + else + { + if (this.Documents.Length > 0) + { + this.InternalSetSelectedDocument(this.Documents[0]); + shouldHandle = true; + } + } + } + // Selecting LayoutAnchorables + else + { + if (this.SelectedAnchorable != null) + { + // Jump to next LayoutAnchorable + var anchorableIndex = this.Anchorables.ToArray() + .IndexOf(this.SelectedAnchorable); + if (anchorableIndex < (this.Anchorables.Count() - 1)) + { + this.SelectNextAnchorable(); + shouldHandle = true; + } + // Jump to first LayoutDocument + else if (this.Documents.Length > 0) + { + _isSelectingDocument = true; + this.InternalSetSelectedAnchorable(null); + this.InternalSetSelectedDocument(this.Documents[0]); + shouldHandle = true; + } + else if (!this.Documents.Any() && this.Anchorables.Any()) + { + this.InternalSetSelectedAnchorable(this.Anchorables.ToArray()[0]); + shouldHandle = true; + } + } + // There is no SelectedAnchorable, select the first one. + else + { + if (this.Anchorables.Count() > 0) + { + this.InternalSetSelectedAnchorable(this.Anchorables.ToArray()[0]); + shouldHandle = true; + } + } + } + } + + if (shouldHandle) + { + e.Handled = true; + } + + base.OnPreviewKeyDown(e); + } + + protected override void OnPreviewKeyUp( System.Windows.Input.KeyEventArgs e ) { if( e.Key != System.Windows.Input.Key.Tab ) {