LayoutDocument.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Globalization;
  15. namespace Xceed.Wpf.AvalonDock.Layout
  16. {
  17. [Serializable]
  18. public class LayoutDocument : LayoutContent
  19. {
  20. public bool IsVisible
  21. {
  22. get { return true; }
  23. }
  24. #region Description
  25. private string _description = null;
  26. public string Description
  27. {
  28. get { return _description; }
  29. set
  30. {
  31. if (_description != value)
  32. {
  33. _description = value;
  34. RaisePropertyChanged("Description");
  35. }
  36. }
  37. }
  38. #endregion
  39. public override void WriteXml(System.Xml.XmlWriter writer)
  40. {
  41. base.WriteXml(writer);
  42. if (!string.IsNullOrWhiteSpace(Description))
  43. writer.WriteAttributeString("Description", Description);
  44. }
  45. public override void ReadXml(System.Xml.XmlReader reader)
  46. {
  47. if (reader.MoveToAttribute("Description"))
  48. Description = reader.Value;
  49. base.ReadXml(reader);
  50. }
  51. public override void Close()
  52. {
  53. var dockingManager = this.Root.Manager;
  54. if( ( this.Root != null ) && ( this.Root.Manager != null ) )
  55. dockingManager._ExecuteCloseCommand( this );
  56. }
  57. #if TRACE
  58. public override void ConsoleDump(int tab)
  59. {
  60. System.Diagnostics.Trace.Write( new string( ' ', tab * 4 ) );
  61. System.Diagnostics.Trace.WriteLine( "Document()" );
  62. }
  63. #endif
  64. protected override void InternalDock()
  65. {
  66. var root = Root as LayoutRoot;
  67. LayoutDocumentPane documentPane = null;
  68. if (root.LastFocusedDocument != null &&
  69. root.LastFocusedDocument != this)
  70. {
  71. documentPane = root.LastFocusedDocument.Parent as LayoutDocumentPane;
  72. }
  73. if (documentPane == null)
  74. {
  75. documentPane = root.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
  76. }
  77. bool added = false;
  78. if (root.Manager.LayoutUpdateStrategy != null)
  79. {
  80. added = root.Manager.LayoutUpdateStrategy.BeforeInsertDocument(root, this, documentPane);
  81. }
  82. if (!added)
  83. {
  84. if (documentPane == null)
  85. throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");
  86. documentPane.Children.Add(this);
  87. added = true;
  88. }
  89. if (root.Manager.LayoutUpdateStrategy != null)
  90. {
  91. root.Manager.LayoutUpdateStrategy.AfterInsertDocument(root, this);
  92. }
  93. base.InternalDock();
  94. }
  95. }
  96. }