| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- /*************************************************************************************
- Extended WPF Toolkit
- Copyright (C) 2007-2013 Xceed Software Inc.
- This program is provided to you under the terms of the Microsoft Public
- License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
- For more features, controls, and fast professional support,
- pick up the Plus Edition at http://xceed.com/wpf_toolkit
- Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
- ***********************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using Xceed.Wpf.AvalonDock.Layout;
- using System.Windows.Input;
- using Xceed.Wpf.AvalonDock.Commands;
- using System.ComponentModel;
- using System.Windows.Data;
- using System.Windows.Media;
- using System.Windows.Controls;
- namespace Xceed.Wpf.AvalonDock.Controls
- {
- public abstract class LayoutItem : FrameworkElement
- {
- static LayoutItem()
- {
- ToolTipProperty.OverrideMetadata(typeof(LayoutItem), new FrameworkPropertyMetadata(null, (s, e) => OnToolTipChanged(s,e)));
- VisibilityProperty.OverrideMetadata(typeof(LayoutItem), new FrameworkPropertyMetadata(Visibility.Visible, (s,e) => OnVisibilityChanged(s, e)));
- }
- internal LayoutItem()
- {
- }
- internal virtual void Attach(LayoutContent model)
- {
- LayoutElement = model;
- Model = model.Content;
- InitDefaultCommands();
- LayoutElement.IsSelectedChanged+=new EventHandler(LayoutElement_IsSelectedChanged);
- LayoutElement.IsActiveChanged+=new EventHandler(LayoutElement_IsActiveChanged);
- DataContext = this;
- System.Diagnostics.Trace.WriteLine( string.Format( "Attach({0})", LayoutElement.Title ) );
- }
- void LayoutElement_IsActiveChanged(object sender, EventArgs e)
- {
- if (_isActiveReentrantFlag.CanEnter)
- {
- using (_isActiveReentrantFlag.Enter())
- {
- var bnd = BindingOperations.GetBinding(this, IsActiveProperty);
- IsActive = LayoutElement.IsActive;
- var bnd2 = BindingOperations.GetBinding(this, IsActiveProperty);
- }
- }
- }
- void LayoutElement_IsSelectedChanged(object sender, EventArgs e)
- {
- if (_isSelectedReentrantFlag.CanEnter)
- {
- using (_isSelectedReentrantFlag.Enter())
- {
- IsSelected = LayoutElement.IsSelected;
- }
- }
- }
- internal virtual void Detach()
- {
- System.Diagnostics.Trace.WriteLine( string.Format( "Detach({0})", LayoutElement.Title ) );
- LayoutElement.IsSelectedChanged -= new EventHandler(LayoutElement_IsSelectedChanged);
- LayoutElement.IsActiveChanged -= new EventHandler(LayoutElement_IsActiveChanged);
- LayoutElement = null;
- Model = null;
- }
- public LayoutContent LayoutElement
- {
- get;
- private set;
- }
- public object Model
- {
- get;
- private set;
- }
- ICommand _defaultCloseCommand;
- ICommand _defaultFloatCommand;
- ICommand _defaultDockAsDocumentCommand;
- ICommand _defaultCloseAllButThisCommand;
- ICommand _defaultActivateCommand;
- ICommand _defaultNewVerticalTabGroupCommand;
- ICommand _defaultNewHorizontalTabGroupCommand;
- ICommand _defaultMoveToNextTabGroupCommand;
- ICommand _defaultMoveToPreviousTabGroupCommand;
- protected virtual void InitDefaultCommands()
- {
- _defaultCloseCommand = new RelayCommand((p) => ExecuteCloseCommand(p), (p) => CanExecuteCloseCommand(p));
- _defaultFloatCommand = new RelayCommand((p) => ExecuteFloatCommand(p), (p) => CanExecuteFloatCommand(p));
- _defaultDockAsDocumentCommand = new RelayCommand((p) => ExecuteDockAsDocumentCommand(p), (p) => CanExecuteDockAsDocumentCommand(p));
- _defaultCloseAllButThisCommand = new RelayCommand((p) => ExecuteCloseAllButThisCommand(p), (p) => CanExecuteCloseAllButThisCommand(p));
- _defaultActivateCommand = new RelayCommand((p) => ExecuteActivateCommand(p), (p) => CanExecuteActivateCommand(p));
- _defaultNewVerticalTabGroupCommand = new RelayCommand((p) => ExecuteNewVerticalTabGroupCommand(p), (p) => CanExecuteNewVerticalTabGroupCommand(p));
- _defaultNewHorizontalTabGroupCommand = new RelayCommand((p) => ExecuteNewHorizontalTabGroupCommand(p), (p) => CanExecuteNewHorizontalTabGroupCommand(p));
- _defaultMoveToNextTabGroupCommand = new RelayCommand((p) => ExecuteMoveToNextTabGroupCommand(p), (p) => CanExecuteMoveToNextTabGroupCommand(p));
- _defaultMoveToPreviousTabGroupCommand = new RelayCommand((p) => ExecuteMoveToPreviousTabGroupCommand(p), (p) => CanExecuteMoveToPreviousTabGroupCommand(p));
- }
- protected virtual void ClearDefaultBindings()
- {
- if (CloseCommand == _defaultCloseCommand)
- BindingOperations.ClearBinding(this, CloseCommandProperty);
- if (FloatCommand == _defaultFloatCommand)
- BindingOperations.ClearBinding(this, FloatCommandProperty);
- if (DockAsDocumentCommand == _defaultDockAsDocumentCommand)
- BindingOperations.ClearBinding(this, DockAsDocumentCommandProperty);
- if (CloseAllButThisCommand == _defaultCloseAllButThisCommand)
- BindingOperations.ClearBinding(this, CloseAllButThisCommandProperty);
- if (ActivateCommand == _defaultActivateCommand)
- BindingOperations.ClearBinding(this, ActivateCommandProperty);
- if (NewVerticalTabGroupCommand == _defaultNewVerticalTabGroupCommand)
- BindingOperations.ClearBinding(this, NewVerticalTabGroupCommandProperty);
- if (NewHorizontalTabGroupCommand == _defaultNewHorizontalTabGroupCommand)
- BindingOperations.ClearBinding(this, NewHorizontalTabGroupCommandProperty);
- if (MoveToNextTabGroupCommand == _defaultMoveToNextTabGroupCommand)
- BindingOperations.ClearBinding(this, MoveToNextTabGroupCommandProperty);
- if (MoveToPreviousTabGroupCommand == _defaultMoveToPreviousTabGroupCommand)
- BindingOperations.ClearBinding(this, MoveToPreviousTabGroupCommandProperty);
- }
- protected virtual void SetDefaultBindings()
- {
- if (CloseCommand == null)
- CloseCommand = _defaultCloseCommand;
- if (FloatCommand == null)
- FloatCommand = _defaultFloatCommand;
- if (DockAsDocumentCommand == null)
- DockAsDocumentCommand = _defaultDockAsDocumentCommand;
- if (CloseAllButThisCommand == null)
- CloseAllButThisCommand = _defaultCloseAllButThisCommand;
- if (ActivateCommand == null)
- ActivateCommand = _defaultActivateCommand;
- if (NewVerticalTabGroupCommand == null)
- NewVerticalTabGroupCommand = _defaultNewVerticalTabGroupCommand;
- if (NewHorizontalTabGroupCommand == null)
- NewHorizontalTabGroupCommand = _defaultNewHorizontalTabGroupCommand;
- if (MoveToNextTabGroupCommand == null)
- MoveToNextTabGroupCommand = _defaultMoveToNextTabGroupCommand;
- if (MoveToPreviousTabGroupCommand == null)
- MoveToPreviousTabGroupCommand = _defaultMoveToPreviousTabGroupCommand;
- IsSelected = LayoutElement.IsSelected;
- IsActive = LayoutElement.IsActive;
- }
- internal void _ClearDefaultBindings()
- {
- ClearDefaultBindings();
- }
- internal void _SetDefaultBindings()
- {
- SetDefaultBindings();
- }
- ContentPresenter _view = null;
- public ContentPresenter View
- {
- get
- {
- if (_view == null)
- {
- _view = new ContentPresenter();
- _view.SetBinding(ContentPresenter.ContentProperty, new Binding("Content") { Source = LayoutElement });
- _view.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding("LayoutItemTemplate") { Source = LayoutElement.Root.Manager});
- _view.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, new Binding("LayoutItemTemplateSelector") { Source = LayoutElement.Root.Manager });
- LayoutElement.Root.Manager.InternalAddLogicalChild(_view);
- }
- return _view;
- }
- }
- #region Title
- /// <summary>
- /// Title Dependency Property
- /// </summary>
- public static readonly DependencyProperty TitleProperty =
- DependencyProperty.Register("Title", typeof(string), typeof(LayoutItem),
- new FrameworkPropertyMetadata((string)null,
- new PropertyChangedCallback(OnTitleChanged)));
- /// <summary>
- /// Gets or sets the Title property. This dependency property
- /// indicates the title of the element.
- /// </summary>
- public string Title
- {
- get { return (string)GetValue(TitleProperty); }
- set { SetValue(TitleProperty, value); }
- }
- /// <summary>
- /// Handles changes to the Title property.
- /// </summary>
- private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnTitleChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the Title property.
- /// </summary>
- protected virtual void OnTitleChanged(DependencyPropertyChangedEventArgs e)
- {
- if (LayoutElement != null)
- LayoutElement.Title = (string)e.NewValue;
- }
- #endregion
- #region ToolTip
- private static void OnToolTipChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)s).OnToolTipChanged();
- }
- private void OnToolTipChanged()
- {
- if (LayoutElement != null)
- LayoutElement.ToolTip = ToolTip;
- }
- #endregion
- #region IconSource
- /// <summary>
- /// IconSource Dependency Property
- /// </summary>
- public static readonly DependencyProperty IconSourceProperty =
- DependencyProperty.Register("IconSource", typeof(ImageSource), typeof(LayoutItem),
- new FrameworkPropertyMetadata((ImageSource)null,
- new PropertyChangedCallback(OnIconSourceChanged)));
- /// <summary>
- /// Gets or sets the IconSource property. This dependency property
- /// indicates icon associated with the item.
- /// </summary>
- public ImageSource IconSource
- {
- get { return (ImageSource)GetValue(IconSourceProperty); }
- set { SetValue(IconSourceProperty, value); }
- }
- /// <summary>
- /// Handles changes to the IconSource property.
- /// </summary>
- private static void OnIconSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnIconSourceChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the IconSource property.
- /// </summary>
- protected virtual void OnIconSourceChanged(DependencyPropertyChangedEventArgs e)
- {
- if (LayoutElement != null)
- LayoutElement.IconSource = IconSource;
- }
- #endregion
- #region Visibility
- private static void OnVisibilityChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)s).OnVisibilityChanged();
- }
- protected virtual void OnVisibilityChanged()
- {
- if (LayoutElement != null &&
- Visibility == System.Windows.Visibility.Collapsed)
- LayoutElement.Close();
- }
- #endregion
- #region ContentId
- /// <summary>
- /// ContentId Dependency Property
- /// </summary>
- public static readonly DependencyProperty ContentIdProperty =
- DependencyProperty.Register("ContentId", typeof(string), typeof(LayoutItem),
- new FrameworkPropertyMetadata((string)null,
- new PropertyChangedCallback(OnContentIdChanged)));
- /// <summary>
- /// Gets or sets the ContentId property. This dependency property
- /// indicates the content id used to retrive content when deserializing layouts.
- /// </summary>
- public string ContentId
- {
- get { return (string)GetValue(ContentIdProperty); }
- set { SetValue(ContentIdProperty, value); }
- }
- /// <summary>
- /// Handles changes to the ContentId property.
- /// </summary>
- private static void OnContentIdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnContentIdChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the ContentId property.
- /// </summary>
- protected virtual void OnContentIdChanged(DependencyPropertyChangedEventArgs e)
- {
- if (LayoutElement != null)
- LayoutElement.ContentId = (string)e.NewValue;
- }
- #endregion
- #region IsSelected
- ReentrantFlag _isSelectedReentrantFlag = new ReentrantFlag();
- /// <summary>
- /// IsSelected Dependency Property
- /// </summary>
- public static readonly DependencyProperty IsSelectedProperty =
- DependencyProperty.Register("IsSelected", typeof(bool), typeof(LayoutItem),
- new FrameworkPropertyMetadata((bool)false,
- new PropertyChangedCallback(OnIsSelectedChanged)));
- /// <summary>
- /// Gets or sets the IsSelected property. This dependency property
- /// indicates if the item is selected inside its container.
- /// </summary>
- public bool IsSelected
- {
- get { return (bool)GetValue(IsSelectedProperty); }
- set { SetValue(IsSelectedProperty, value); }
- }
- /// <summary>
- /// Handles changes to the IsSelected property.
- /// </summary>
- private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnIsSelectedChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the IsSelected property.
- /// </summary>
- protected virtual void OnIsSelectedChanged(DependencyPropertyChangedEventArgs e)
- {
- if (_isSelectedReentrantFlag.CanEnter)
- {
- using (_isSelectedReentrantFlag.Enter())
- {
- if (LayoutElement != null)
- LayoutElement.IsSelected = (bool)e.NewValue;
- }
- }
- }
- #endregion
- #region IsActive
- ReentrantFlag _isActiveReentrantFlag = new ReentrantFlag();
- /// <summary>
- /// IsActive Dependency Property
- /// </summary>
- public static readonly DependencyProperty IsActiveProperty =
- DependencyProperty.Register("IsActive", typeof(bool), typeof(LayoutItem),
- new FrameworkPropertyMetadata((bool)false,
- new PropertyChangedCallback(OnIsActiveChanged)));
- /// <summary>
- /// Gets or sets the IsActive property. This dependency property
- /// indicates if the item is active in the UI.
- /// </summary>
- public bool IsActive
- {
- get { return (bool)GetValue(IsActiveProperty); }
- set { SetValue(IsActiveProperty, value); }
- }
- /// <summary>
- /// Handles changes to the IsActive property.
- /// </summary>
- private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnIsActiveChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the IsActive property.
- /// </summary>
- protected virtual void OnIsActiveChanged(DependencyPropertyChangedEventArgs e)
- {
- if (_isActiveReentrantFlag.CanEnter)
- {
- using (_isActiveReentrantFlag.Enter())
- {
- if (LayoutElement != null)
- LayoutElement.IsActive = (bool)e.NewValue;
- }
- }
- }
- #endregion
- #region CanClose
- /// <summary>
- /// CanClose Dependency Property
- /// </summary>
- public static readonly DependencyProperty CanCloseProperty =
- DependencyProperty.Register("CanClose", typeof(bool), typeof(LayoutItem),
- new FrameworkPropertyMetadata((bool)true,
- new PropertyChangedCallback(OnCanCloseChanged)));
- /// <summary>
- /// Gets or sets the CanClose property. This dependency property
- /// indicates if the item can be closed.
- /// </summary>
- public bool CanClose
- {
- get { return (bool)GetValue(CanCloseProperty); }
- set { SetValue(CanCloseProperty, value); }
- }
- /// <summary>
- /// Handles changes to the CanClose property.
- /// </summary>
- private static void OnCanCloseChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnCanCloseChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the CanClose property.
- /// </summary>
- protected virtual void OnCanCloseChanged(DependencyPropertyChangedEventArgs e)
- {
- if (LayoutElement != null)
- LayoutElement.CanClose = (bool)e.NewValue;
- }
- #endregion
- #region CanFloat
- /// <summary>
- /// CanFloat Dependency Property
- /// </summary>
- public static readonly DependencyProperty CanFloatProperty =
- DependencyProperty.Register("CanFloat", typeof(bool), typeof(LayoutItem),
- new FrameworkPropertyMetadata((bool)true,
- new PropertyChangedCallback(OnCanFloatChanged)));
- /// <summary>
- /// Gets or sets the CanFloat property. This dependency property
- /// indicates if user can move the layout element dragging it to another position.
- /// </summary>
- public bool CanFloat
- {
- get { return (bool)GetValue(CanFloatProperty); }
- set { SetValue(CanFloatProperty, value); }
- }
- /// <summary>
- /// Handles changes to the CanFloat property.
- /// </summary>
- private static void OnCanFloatChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnCanFloatChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the CanFloat property.
- /// </summary>
- protected virtual void OnCanFloatChanged(DependencyPropertyChangedEventArgs e)
- {
- if (LayoutElement != null)
- LayoutElement.CanFloat = (bool)e.NewValue;
- }
- #endregion
- #region CloseCommand
- /// <summary>
- /// CloseCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty CloseCommandProperty =
- DependencyProperty.Register("CloseCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnCloseCommandChanged),
- new CoerceValueCallback(CoerceCloseCommandValue)));
- /// <summary>
- /// Gets or sets the CloseCommand property. This dependency property
- /// indicates the command to execute when user click the document close button.
- /// </summary>
- public ICommand CloseCommand
- {
- get { return (ICommand)GetValue(CloseCommandProperty); }
- set { SetValue(CloseCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the CloseCommand property.
- /// </summary>
- private static void OnCloseCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnCloseCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the CloseCommand property.
- /// </summary>
- protected virtual void OnCloseCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the CloseCommand value.
- /// </summary>
- private static object CoerceCloseCommandValue(DependencyObject d, object value)
- {
- return value;
- }
- private bool CanExecuteCloseCommand(object parameter)
- {
- #if DEBUG
- if( LayoutElement != null )
- System.Diagnostics.Trace.WriteLine( string.Format( "CanExecuteCloseCommand({0}) = {1}", LayoutElement.Title, LayoutElement.CanClose ) );
- #endif
- return LayoutElement != null && LayoutElement.CanClose;
- }
- private void ExecuteCloseCommand(object parameter)
- {
- Close();
- }
- protected abstract void Close();
- #endregion
- #region FloatCommand
- /// <summary>
- /// FloatCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty FloatCommandProperty =
- DependencyProperty.Register("FloatCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnFloatCommandChanged),
- new CoerceValueCallback(CoerceFloatCommandValue)));
- /// <summary>
- /// Gets or sets the FloatCommand property. This dependency property
- /// indicates the command to execute when user click the float button.
- /// </summary>
- /// <remarks>By default this command move the anchorable inside new floating window.</remarks>
- public ICommand FloatCommand
- {
- get { return (ICommand)GetValue(FloatCommandProperty); }
- set { SetValue(FloatCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the FloatCommand property.
- /// </summary>
- private static void OnFloatCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnFloatCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the FloatCommand property.
- /// </summary>
- protected virtual void OnFloatCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the FloatCommand value.
- /// </summary>
- private static object CoerceFloatCommandValue(DependencyObject d, object value)
- {
- return value;
- }
- private bool CanExecuteFloatCommand(object anchorable)
- {
- return LayoutElement != null && LayoutElement.CanFloat && LayoutElement.FindParent<LayoutFloatingWindow>() == null;
- }
- private void ExecuteFloatCommand(object parameter)
- {
- LayoutElement.Root.Manager._ExecuteFloatCommand(LayoutElement);
- }
- protected virtual void Float()
- {
- }
- #endregion
- #region DockAsDocumentCommand
- /// <summary>
- /// DockAsDocumentCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty DockAsDocumentCommandProperty =
- DependencyProperty.Register("DockAsDocumentCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnDockAsDocumentCommandChanged),
- new CoerceValueCallback(CoerceDockAsDocumentCommandValue)));
- /// <summary>
- /// Gets or sets the DockAsDocumentCommand property. This dependency property
- /// indicates the command to execute when user click the DockAsDocument button.
- /// </summary>
- /// <remarks>By default this command move the anchorable inside the last focused document pane.</remarks>
- public ICommand DockAsDocumentCommand
- {
- get { return (ICommand)GetValue(DockAsDocumentCommandProperty); }
- set { SetValue(DockAsDocumentCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the DockAsDocumentCommand property.
- /// </summary>
- private static void OnDockAsDocumentCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnDockAsDocumentCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the DockAsDocumentCommand property.
- /// </summary>
- protected virtual void OnDockAsDocumentCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the DockAsDocumentCommand value.
- /// </summary>
- private static object CoerceDockAsDocumentCommandValue(DependencyObject d, object value)
- {
- return value;
- }
- private bool CanExecuteDockAsDocumentCommand(object parameter)
- {
- return LayoutElement != null && LayoutElement.FindParent<LayoutDocumentPane>() == null;
- }
- private void ExecuteDockAsDocumentCommand(object parameter)
- {
- LayoutElement.Root.Manager._ExecuteDockAsDocumentCommand(LayoutElement);
- }
- #endregion
- #region CloseAllButThisCommand
- /// <summary>
- /// CloseAllButThisCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty CloseAllButThisCommandProperty =
- DependencyProperty.Register("CloseAllButThisCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnCloseAllButThisCommandChanged),
- new CoerceValueCallback(CoerceCloseAllButThisCommandValue)));
- /// <summary>
- /// Gets or sets the CloseAllButThisCommand property. This dependency property
- /// indicates the 'Close All But This' command.
- /// </summary>
- public ICommand CloseAllButThisCommand
- {
- get { return (ICommand)GetValue(CloseAllButThisCommandProperty); }
- set { SetValue(CloseAllButThisCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the CloseAllButThisCommand property.
- /// </summary>
- private static void OnCloseAllButThisCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnCloseAllButThisCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the CloseAllButThisCommand property.
- /// </summary>
- protected virtual void OnCloseAllButThisCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the CloseAllButThisCommand value.
- /// </summary>
- private static object CoerceCloseAllButThisCommandValue(DependencyObject d, object value)
- {
- return value;
- }
- private bool CanExecuteCloseAllButThisCommand(object parameter)
- {
- if (LayoutElement == null)
- return false;
- var root = LayoutElement.Root;
- if (root == null)
- return false;
- return LayoutElement.Root.Manager.Layout.
- Descendents().OfType<LayoutContent>().Where(d => d != LayoutElement && (d.Parent is LayoutDocumentPane || d.Parent is LayoutDocumentFloatingWindow)).Any();
- }
- private void ExecuteCloseAllButThisCommand(object parameter)
- {
- LayoutElement.Root.Manager._ExecuteCloseAllButThisCommand(LayoutElement);
- }
- #endregion
- #region ActivateCommand
- /// <summary>
- /// ActivateCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty ActivateCommandProperty =
- DependencyProperty.Register("ActivateCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata(null,
- new PropertyChangedCallback(OnActivateCommandChanged),
- new CoerceValueCallback(CoerceActivateCommandValue)));
- /// <summary>
- /// Gets or sets the ActivateCommand property. This dependency property
- /// indicates the command to execute when user wants to activate a content (either a Document or an Anchorable).
- /// </summary>
- public ICommand ActivateCommand
- {
- get { return (ICommand)GetValue(ActivateCommandProperty); }
- set { SetValue(ActivateCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the ActivateCommand property.
- /// </summary>
- private static void OnActivateCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnActivateCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the ActivateCommand property.
- /// </summary>
- protected virtual void OnActivateCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- /// <summary>
- /// Coerces the ActivateCommand value.
- /// </summary>
- private static object CoerceActivateCommandValue(DependencyObject d, object value)
- {
- return value;
- }
- private bool CanExecuteActivateCommand(object parameter)
- {
- return LayoutElement != null;
- }
- private void ExecuteActivateCommand(object parameter)
- {
- LayoutElement.Root.Manager._ExecuteContentActivateCommand(LayoutElement);
- }
- #endregion
- #region NewVerticalTabGroupCommand
- /// <summary>
- /// NewVerticalTabGroupCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty NewVerticalTabGroupCommandProperty =
- DependencyProperty.Register("NewVerticalTabGroupCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata((ICommand)null,
- new PropertyChangedCallback(OnNewVerticalTabGroupCommandChanged)));
- /// <summary>
- /// Gets or sets the NewVerticalTabGroupCommand property. This dependency property
- /// indicates the new vertical tab group command.
- /// </summary>
- public ICommand NewVerticalTabGroupCommand
- {
- get { return (ICommand)GetValue(NewVerticalTabGroupCommandProperty); }
- set { SetValue(NewVerticalTabGroupCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the NewVerticalTabGroupCommand property.
- /// </summary>
- private static void OnNewVerticalTabGroupCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnNewVerticalTabGroupCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the NewVerticalTabGroupCommand property.
- /// </summary>
- protected virtual void OnNewVerticalTabGroupCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- private bool CanExecuteNewVerticalTabGroupCommand(object parameter)
- {
- if (LayoutElement == null)
- return false;
- var parentDocumentGroup = LayoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = LayoutElement.Parent as LayoutDocumentPane;
- return ((parentDocumentGroup == null ||
- parentDocumentGroup.ChildrenCount == 1 ||
- parentDocumentGroup.Root.Manager.AllowMixedOrientation ||
- parentDocumentGroup.Orientation == System.Windows.Controls.Orientation.Horizontal) &&
- parentDocumentPane != null &&
- parentDocumentPane.ChildrenCount > 1);
- }
- private void ExecuteNewVerticalTabGroupCommand(object parameter)
- {
- var layoutElement = LayoutElement;
- var parentDocumentGroup = layoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = layoutElement.Parent as LayoutDocumentPane;
- if (parentDocumentGroup == null)
- {
- var grandParent = parentDocumentPane.Parent as ILayoutContainer;
- parentDocumentGroup = new LayoutDocumentPaneGroup() { Orientation = System.Windows.Controls.Orientation.Horizontal };
- grandParent.ReplaceChild(parentDocumentPane, parentDocumentGroup);
- parentDocumentGroup.Children.Add(parentDocumentPane);
- }
- parentDocumentGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
- int indexOfParentPane = parentDocumentGroup.IndexOfChild(parentDocumentPane);
- parentDocumentGroup.InsertChildAt(indexOfParentPane + 1, new LayoutDocumentPane(layoutElement));
- layoutElement.IsActive = true;
- layoutElement.Root.CollectGarbage();
- }
- #endregion
- #region NewHorizontalTabGroupCommand
- /// <summary>
- /// NewHorizontalTabGroupCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty NewHorizontalTabGroupCommandProperty =
- DependencyProperty.Register("NewHorizontalTabGroupCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata((ICommand)null,
- new PropertyChangedCallback(OnNewHorizontalTabGroupCommandChanged)));
- /// <summary>
- /// Gets or sets the NewHorizontalTabGroupCommand property. This dependency property
- /// indicates the new horizontal tab group command.
- /// </summary>
- public ICommand NewHorizontalTabGroupCommand
- {
- get { return (ICommand)GetValue(NewHorizontalTabGroupCommandProperty); }
- set { SetValue(NewHorizontalTabGroupCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the NewHorizontalTabGroupCommand property.
- /// </summary>
- private static void OnNewHorizontalTabGroupCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnNewHorizontalTabGroupCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the NewHorizontalTabGroupCommand property.
- /// </summary>
- protected virtual void OnNewHorizontalTabGroupCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- private bool CanExecuteNewHorizontalTabGroupCommand(object parameter)
- {
- if (LayoutElement == null)
- return false;
- var parentDocumentGroup = LayoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = LayoutElement.Parent as LayoutDocumentPane;
- return ((parentDocumentGroup == null ||
- parentDocumentGroup.ChildrenCount == 1 ||
- parentDocumentGroup.Root.Manager.AllowMixedOrientation ||
- parentDocumentGroup.Orientation == System.Windows.Controls.Orientation.Vertical) &&
- parentDocumentPane != null &&
- parentDocumentPane.ChildrenCount > 1);
- }
- private void ExecuteNewHorizontalTabGroupCommand(object parameter)
- {
- var layoutElement = LayoutElement;
- var parentDocumentGroup = layoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = layoutElement.Parent as LayoutDocumentPane;
- if (parentDocumentGroup == null)
- {
- var grandParent = parentDocumentPane.Parent as ILayoutContainer;
- parentDocumentGroup = new LayoutDocumentPaneGroup() { Orientation = System.Windows.Controls.Orientation.Vertical };
- grandParent.ReplaceChild(parentDocumentPane, parentDocumentGroup);
- parentDocumentGroup.Children.Add(parentDocumentPane);
- }
- parentDocumentGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
- int indexOfParentPane = parentDocumentGroup.IndexOfChild(parentDocumentPane);
- parentDocumentGroup.InsertChildAt(indexOfParentPane + 1, new LayoutDocumentPane(layoutElement));
- layoutElement.IsActive = true;
- layoutElement.Root.CollectGarbage();
- }
- #endregion
- #region MoveToNextTabGroupCommand
- /// <summary>
- /// MoveToNextTabGroupCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty MoveToNextTabGroupCommandProperty =
- DependencyProperty.Register("MoveToNextTabGroupCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata((ICommand)null,
- new PropertyChangedCallback(OnMoveToNextTabGroupCommandChanged)));
- /// <summary>
- /// Gets or sets the MoveToNextTabGroupCommand property. This dependency property
- /// indicates move to next tab group command.
- /// </summary>
- public ICommand MoveToNextTabGroupCommand
- {
- get { return (ICommand)GetValue(MoveToNextTabGroupCommandProperty); }
- set { SetValue(MoveToNextTabGroupCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the MoveToNextTabGroupCommand property.
- /// </summary>
- private static void OnMoveToNextTabGroupCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnMoveToNextTabGroupCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the MoveToNextTabGroupCommand property.
- /// </summary>
- protected virtual void OnMoveToNextTabGroupCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- private bool CanExecuteMoveToNextTabGroupCommand(object parameter)
- {
- if (LayoutElement == null)
- return false;
- var parentDocumentGroup = LayoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = LayoutElement.Parent as LayoutDocumentPane;
- return (parentDocumentGroup != null &&
- parentDocumentPane != null &&
- parentDocumentGroup.ChildrenCount > 1 &&
- parentDocumentGroup.IndexOfChild(parentDocumentPane) < parentDocumentGroup.ChildrenCount - 1 &&
- parentDocumentGroup.Children[parentDocumentGroup.IndexOfChild(parentDocumentPane) + 1] is LayoutDocumentPane);
- }
- private void ExecuteMoveToNextTabGroupCommand(object parameter)
- {
- var layoutElement = LayoutElement;
- var parentDocumentGroup = layoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = layoutElement.Parent as LayoutDocumentPane;
- int indexOfParentPane = parentDocumentGroup.IndexOfChild(parentDocumentPane);
- var nextDocumentPane = parentDocumentGroup.Children[indexOfParentPane + 1] as LayoutDocumentPane;
- nextDocumentPane.InsertChildAt(0, layoutElement);
- layoutElement.IsActive = true;
- layoutElement.Root.CollectGarbage();
- }
- #endregion
- #region MoveToPreviousTabGroupCommand
- /// <summary>
- /// MoveToPreviousTabGroupCommand Dependency Property
- /// </summary>
- public static readonly DependencyProperty MoveToPreviousTabGroupCommandProperty =
- DependencyProperty.Register("MoveToPreviousTabGroupCommand", typeof(ICommand), typeof(LayoutItem),
- new FrameworkPropertyMetadata((ICommand)null,
- new PropertyChangedCallback(OnMoveToPreviousTabGroupCommandChanged)));
- /// <summary>
- /// Gets or sets the MoveToPreviousTabGroupCommand property. This dependency property
- /// indicates move to rpevious tab group command.
- /// </summary>
- public ICommand MoveToPreviousTabGroupCommand
- {
- get { return (ICommand)GetValue(MoveToPreviousTabGroupCommandProperty); }
- set { SetValue(MoveToPreviousTabGroupCommandProperty, value); }
- }
- /// <summary>
- /// Handles changes to the MoveToPreviousTabGroupCommand property.
- /// </summary>
- private static void OnMoveToPreviousTabGroupCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((LayoutItem)d).OnMoveToPreviousTabGroupCommandChanged(e);
- }
- /// <summary>
- /// Provides derived classes an opportunity to handle changes to the MoveToPreviousTabGroupCommand property.
- /// </summary>
- protected virtual void OnMoveToPreviousTabGroupCommandChanged(DependencyPropertyChangedEventArgs e)
- {
- }
- private bool CanExecuteMoveToPreviousTabGroupCommand(object parameter)
- {
- if (LayoutElement == null)
- return false;
- var parentDocumentGroup = LayoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = LayoutElement.Parent as LayoutDocumentPane;
- return (parentDocumentGroup != null &&
- parentDocumentPane != null &&
- parentDocumentGroup.ChildrenCount > 1 &&
- parentDocumentGroup.IndexOfChild(parentDocumentPane) > 0 &&
- parentDocumentGroup.Children[parentDocumentGroup.IndexOfChild(parentDocumentPane) - 1] is LayoutDocumentPane);
- }
- private void ExecuteMoveToPreviousTabGroupCommand(object parameter)
- {
- var layoutElement = LayoutElement;
- var parentDocumentGroup = layoutElement.FindParent<LayoutDocumentPaneGroup>();
- var parentDocumentPane = layoutElement.Parent as LayoutDocumentPane;
- int indexOfParentPane = parentDocumentGroup.IndexOfChild(parentDocumentPane);
- var nextDocumentPane = parentDocumentGroup.Children[indexOfParentPane - 1] as LayoutDocumentPane;
- nextDocumentPane.InsertChildAt(0, layoutElement);
- layoutElement.IsActive = true;
- layoutElement.Root.CollectGarbage();
- }
- #endregion
- }
- }
|