Permalink
Browse files

set Content to null if closed, added hide events

  • Loading branch information...
1 parent b6205d7 commit f710bbc943f207716e8bb371c4c51824873edcf3 @IsNull committed Jul 30, 2011
@@ -75,6 +75,7 @@ public class AvalonWorkBenchService : IWorkBenchService
dockableContent.HideOnClose = false;
dockableContent.Closing += (s, e) => viewModel.OnRequestClose();
+ viewModel.IsOnWorkspace = true;
dockableContent.ShowAsDialoge(DockManager);
}
@@ -92,6 +93,7 @@ public class AvalonWorkBenchService : IWorkBenchService
var content = SetupFloatingContent(viewModel, sizeToContent, windowSize);
content.ShowAsFloatingWindow(DockManager, false);
+ viewModel.IsOnWorkspace = true;
}
/// <summary>
@@ -106,6 +108,7 @@ public class AvalonWorkBenchService : IWorkBenchService
var content = SetupFloatingContent(viewModel, sizeToContent, windowSize);
content.ShowAsUndockableFloatingWindow(DockManager);
+ viewModel.IsOnWorkspace = true;
}
@@ -131,6 +134,7 @@ public class AvalonWorkBenchService : IWorkBenchService
if (windowSize.HasValue) {
dockableContent.FloatingWindowSize = windowSize.Value;
}
+ viewModel.IsOnWorkspace = true;
var ret = dockableContent.ShowAsDialoge(DockManager);
return ret;
@@ -142,13 +146,15 @@ public class AvalonWorkBenchService : IWorkBenchService
throw new ArgumentNullException("viewModel");
var dockableContent = SetUpDockableContent(viewModel);
dockableContent.Show(DockManager);
+ viewModel.IsOnWorkspace = true;
}
public void ShowDockedDocument(WorkspaceViewModel viewModel) {
if(viewModel == null)
throw new ArgumentNullException("viewModel");
var dockableContent = SetUpDockableContent(viewModel);
dockableContent.ShowAsDocument(DockManager);
+ viewModel.IsOnWorkspace = true;
}
#endregion
@@ -178,6 +184,7 @@ public class AvalonWorkBenchService : IWorkBenchService
dc.FloatingWindowSizeToContent = SizeToContent.WidthAndHeight;
dc.HideOnClose = false;
dc.Closing += (s, e) => vm.OnRequestClose();
+ vm.IsOnWorkspace = true;
dc.ShowAsDialoge(DockManager);
return vm.DialogeResult;
@@ -202,8 +209,9 @@ public class AvalonWorkBenchService : IWorkBenchService
dc.FloatingWindowSizeToContent = SizeToContent.WidthAndHeight;
dc.HideOnClose = false;
dc.Closing += (s, e) => vm.OnRequestClose();
+ vm.IsOnWorkspace = true;
dc.ShowAsDialoge(DockManager);
-
+
return vm.DialogeResult;
}
@@ -242,9 +250,10 @@ public class AvalonWorkBenchService : IWorkBenchService
/// <param name="display">True means show, false hides the Loader</param>
public void LoaderView(bool display) {
+ LoaderViewModel vm = null;
if (_dcLoaderView == null && display) {
var loaderView = new LoadingAnimation() { Width = 100, Height = 100 };
- var vm = new LoaderViewModel();
+ vm = new LoaderViewModel();
_dcLoaderView = CreateDockableContent(loaderView, vm);
_dcLoaderView.DockableStyle = DockableStyle.Floating;
_dcLoaderView.FloatingWindowSizeToContent = SizeToContent.WidthAndHeight;
@@ -254,6 +263,8 @@ public class AvalonWorkBenchService : IWorkBenchService
if (display) {
_dcLoaderView.ShowAsFloatingWindow(DockManager, false);
+ if(vm != null)
+ vm.IsOnWorkspace = true;
} else {
if (_dcLoaderView != null)
_dcLoaderView.Close();
@@ -341,16 +352,69 @@ public class AvalonWorkBenchService : IWorkBenchService
dockableContent = CreateDockableContent(view, viewModel);
return dockableContent;
}
-
+
DockableContent CreateDockableContent(DependencyObject view, WorkspaceViewModel viewModel) {
var dockableContent = new DockableContent();
+ dockableContent.HideOnClose = false;
//bind title to WorkspaceViewModel.DisplayName
dockableContent.SetBinding(DockableContent.TitleProperty, new System.Windows.Data.Binding("DisplayName"));
+
dockableContent.Content = view;
dockableContent.DataContext = viewModel;
- viewModel.RequestClose += (s, e) => CloseParent(view, viewModel);
+
+ viewModel.RequestClose += (s, e) => {
+ CloseParent(view, viewModel);
+ };
+
+ viewModel.RequestFocus += (s, e) => {
+ dockableContent.Focus();
+ };
+
+
+ dockableContent.Hiding += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.OnClosing(e);
+ };
+
+ dockableContent.Hidden += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.OnClosed();
+ };
+
+ dockableContent.Closing += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.OnClosing(e);
+ };
+
+ dockableContent.Closing += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.OnClosed();
+ };
+
+
+ dockableContent.Closed += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.IsOnWorkspace = false;
+ };
+
+ dockableContent.GotFocus += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.HasFocus = true;
+ };
+ dockableContent.LostFocus += (s, e) => {
+ var content = s as DockableContent;
+ var vm = content.DataContext as WorkspaceViewModel;
+ vm.HasFocus = false;
+ };
+
return dockableContent;
}
@@ -7,6 +7,7 @@
using Archimedes.Patterns.WPF.Commands;
using System.Linq.Expressions;
using System.Windows.Markup;
+using System.ComponentModel;
namespace Archimedes.Patterns.WPF.ViewModels
{
@@ -22,6 +23,8 @@ public abstract class WorkspaceViewModel : ViewModelBase
RelayCommand _closeCommand;
RelayCommand _focusCommand;
+ bool _hasFocus = false;
+ bool _isOnWorkspace = false;
#endregion // Fields
@@ -37,6 +40,21 @@ public abstract class WorkspaceViewModel : ViewModelBase
/// </summary>
public event EventHandler RequestFocus;
+ /// <summary>
+ /// Raised when the focus of this Workspace Element has changed
+ /// </summary>
+ public event EventHandler HasFocusChanged;
+
+ /// <summary>
+ /// Raised when the IsOnWorkspace Property has changed
+ /// </summary>
+ public event EventHandler IsOnWorkspaceChanged;
+
+
+ /// <summary>
+ /// Raised when this Element is about to close itself
+ /// </summary>
+ public event EventHandler<CancelEventArgs> Closing;
#endregion
@@ -59,6 +77,28 @@ public abstract class WorkspaceViewModel : ViewModelBase
get { return DefaultLanguage; }
}
+ /// <summary>
+ /// Gets/Sets if this Elemnt has currently focus
+ /// </summary>
+ public bool HasFocus {
+ get { return _hasFocus; }
+ set {
+ _hasFocus = value;
+ OnHasFocusChanged();
+ }
+ }
+
+ /// <summary>
+ /// Gets/Sets if this Element currently is on the Workspace
+ /// </summary>
+ public bool IsOnWorkspace {
+ get { return _isOnWorkspace; }
+ set {
+ _isOnWorkspace = value;
+ OnIsOnWorkspaceChanged();
+ }
+ }
+
#region Close Command
/// <summary>
@@ -93,12 +133,36 @@ public abstract class WorkspaceViewModel : ViewModelBase
#region Event Invokers
- public void OnRequestClose() {
+ /// <summary>
+ /// Occurs when this Element is about to close
+ /// </summary>
+ /// <param name="e"></param>
+ public virtual void OnClosing(CancelEventArgs e) {
+ if(Closing != null && !e.Cancel)
+ Closing(this, e);
+ }
+
+ public virtual void OnClosed() {
+
+ }
+
+
+ protected virtual void OnIsOnWorkspaceChanged() {
+ if(IsOnWorkspaceChanged != null)
+ IsOnWorkspaceChanged(this, EventArgs.Empty);
+ }
+
+ protected virtual void OnHasFocusChanged() {
+ if(HasFocusChanged != null)
+ HasFocusChanged(this, EventArgs.Empty);
+ }
+
+ public virtual void OnRequestClose() {
if (RequestClose != null)
RequestClose(this, EventArgs.Empty);
}
- void OnRequestFocus() {
+ protected virtual void OnRequestFocus() {
if (RequestFocus != null)
RequestFocus(this, EventArgs.Empty);
}
@@ -223,6 +223,23 @@ internal class DockableContentStateAndPosition
/// </summary>
public class DockableContent : ManagedContent
{
+
+ #region Events
+
+ /// <summary>
+ /// Raised when this DockableContent was hidden
+ /// </summary>
+ public event EventHandler Hidden;
+
+
+ /// <summary>
+ /// Raised when this DockableContent is about to hide itself
+ /// </summary>
+ public event EventHandler<CancelEventArgs> Hiding;
+
+
+ #endregion
+
static DockableContent()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DockableContent), new FrameworkPropertyMetadata(typeof(DockableContent)));
@@ -676,8 +693,14 @@ public override bool Hide()
{
if (!CanExecuteCommand(ManagedContentCommands.Hide))
return false;
+ var e = new CancelEventArgs();
+ this.OnHiding(e);
+
+ if(e.Cancel)
+ return false;
Manager.Hide(this);
+ this.OnHidden();
return true;
}
@@ -738,7 +761,8 @@ internal virtual bool CloseOrHide(bool force)
ContainerPane.RemoveContent(
ContainerPane.Items.IndexOf(this));
}
-
+ this.Content = null;
+
OnClosed();
//Close here ThemeDictionaryExtension floatingwindow...
@@ -748,6 +772,24 @@ internal virtual bool CloseOrHide(bool force)
}
/// <summary>
+ /// Ovveride this method to handle <see cref="DocumentContent.OnHiding"/> event.
+ /// </summary>
+ protected virtual void OnHiding(CancelEventArgs e) {
+ if(Hiding != null && !e.Cancel) {
+ Hiding(this, e);
+ }
+ }
+
+ /// <summary>
+ /// Ovveride this method to handle <see cref="DocumentContent.OnHidden"/> event.
+ /// </summary>
+ protected virtual void OnHidden() {
+ if(Hidden != null)
+ Hidden(this, EventArgs.Empty);
+ }
+
+
+ /// <summary>
/// Slides out this content to a border of the containing docking manager
/// </summary>
public void ToggleAutoHide()

0 comments on commit f710bbc

Please sign in to comment.