PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/IZWebFileManager/RootDirectory.cs

http://izwebfilemanager.googlecode.com/
C# | 135 lines | 89 code | 17 blank | 29 comment | 7 complexity | 2e2fe0f0fc5d01e0376b5263cf528afa MD5 | raw file
  1. // Copyright (C) 2006 Igor Zelmanovich <izwebfilemanager@gmail.com>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Text;
  19. using System.Web.UI;
  20. using System.Collections;
  21. using System.Web.UI.WebControls;
  22. using System.Collections.ObjectModel;
  23. using System.ComponentModel;
  24. using System.Diagnostics.CodeAnalysis;
  25. using System.Drawing.Design;
  26. using System.Web;
  27. namespace IZ.WebFileManager
  28. {
  29. public sealed class RootDirectory : IStateManager
  30. {
  31. readonly StateBag bag = new StateBag ();
  32. [DefaultValue ("~/")]
  33. public string DirectoryPath {
  34. get { return bag ["DirectoryPath"] == null ? "~/" : (string) bag ["DirectoryPath"]; }
  35. set { bag ["DirectoryPath"] = value; }
  36. }
  37. /// <summary>
  38. /// Gets or sets the number of levels that are expanded in the folder tree when a FileManager control is displayed for the first time.
  39. /// </summary>
  40. /// <value>
  41. /// The depth to display in the folder tree when the FileManager is initially displayed. The default is -1, which displays all the nodes.
  42. /// </value>
  43. [DefaultValue (1)]
  44. public int ExpandDepth {
  45. get { return bag ["ExpandDepth"] == null ? 1 : (int) bag ["ExpandDepth"]; }
  46. set { bag ["ExpandDepth"] = value; }
  47. }
  48. [SuppressMessage ("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
  49. [Editor ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (UITypeEditor))]
  50. [DefaultValue ("")]
  51. [UrlProperty]
  52. [Bindable (true)]
  53. public string SmallImageUrl {
  54. get { return bag ["SmallIconUrl"] == null ? String.Empty : (string) bag ["SmallIconUrl"]; }
  55. set { bag ["SmallIconUrl"] = value; }
  56. }
  57. [SuppressMessage ("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
  58. [Editor ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (UITypeEditor))]
  59. [DefaultValue ("")]
  60. [UrlProperty]
  61. [Bindable (true)]
  62. public string LargeImageUrl {
  63. get { return bag ["LargeIconUrl"] == null ? String.Empty : (string) bag ["LargeIconUrl"]; }
  64. set { bag ["LargeIconUrl"] = value; }
  65. }
  66. /// <summary>
  67. /// Gets or sets the text displayed for the node in the folder tree of FileManager control.
  68. /// </summary>
  69. [DefaultValue ("")]
  70. public string Text {
  71. get { return (string) bag ["Text"] ?? String.Empty; }
  72. set {
  73. // validate value must be valid file/folder name
  74. if (!FileManagerController.Validate (value))
  75. throw new ArgumentException (String.Format ("'{0}' is not a valid value for RootDirectory.Text, It cannot contain any of the following characters: \\/:*?\"<>|", value));
  76. bag ["Text"] = value;
  77. }
  78. }
  79. internal string TextInternal {
  80. get {
  81. if (String.IsNullOrEmpty (Text))
  82. return VirtualPathUtility.GetFileName (DirectoryPath);
  83. return Text;
  84. }
  85. }
  86. [DefaultValue (true)]
  87. public bool ShowRootIndex {
  88. get { return bag ["ShowRootIndex"] == null ? true : (bool) bag ["ShowRootIndex"]; }
  89. set {
  90. bag ["ShowRootIndex"] = value;
  91. }
  92. }
  93. /// <summary>
  94. /// Overridden
  95. /// </summary>
  96. /// <returns></returns>
  97. public override string ToString () {
  98. return DirectoryPath;
  99. }
  100. #region IStateManager Members
  101. bool IStateManager.IsTrackingViewState {
  102. get { return ((IStateManager) bag).IsTrackingViewState; }
  103. }
  104. void IStateManager.LoadViewState (object state) {
  105. ((IStateManager) bag).LoadViewState (state);
  106. }
  107. object IStateManager.SaveViewState () {
  108. return ((IStateManager) bag).SaveViewState ();
  109. }
  110. void IStateManager.TrackViewState () {
  111. ((IStateManager) bag).TrackViewState ();
  112. }
  113. #endregion
  114. internal void SetDirty () {
  115. bag.SetDirty (true);
  116. }
  117. }
  118. }