PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 6ms RepoModel.GetById 34ms 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
 17using System;
 18using System.Collections.Generic;
 19using System.Text;
 20using System.Web.UI;
 21using System.Collections;
 22using System.Web.UI.WebControls;
 23using System.Collections.ObjectModel;
 24using System.ComponentModel;
 25using System.Diagnostics.CodeAnalysis;
 26using System.Drawing.Design;
 27using System.Web;
 28
 29namespace IZ.WebFileManager
 30{
 31	public sealed class RootDirectory : IStateManager
 32	{
 33		readonly StateBag bag = new StateBag ();
 34
 35		[DefaultValue ("~/")]
 36		public string DirectoryPath {
 37			get { return bag ["DirectoryPath"] == null ? "~/" : (string) bag ["DirectoryPath"]; }
 38			set { bag ["DirectoryPath"] = value; }
 39		}
 40
 41		/// <summary>
 42		/// Gets or sets the number of levels that are expanded in the folder tree when a FileManager control is displayed for the first time. 
 43		/// </summary>
 44		/// <value>
 45		/// The depth to display in the folder tree when the FileManager is initially displayed. The default is -1, which displays all the nodes.
 46		/// </value>
 47		[DefaultValue (1)]
 48		public int ExpandDepth {
 49			get { return bag ["ExpandDepth"] == null ? 1 : (int) bag ["ExpandDepth"]; }
 50			set { bag ["ExpandDepth"] = value; }
 51		}
 52
 53		[SuppressMessage ("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
 54		[Editor ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (UITypeEditor))]
 55		[DefaultValue ("")]
 56		[UrlProperty]
 57		[Bindable (true)]
 58		public string SmallImageUrl {
 59			get { return bag ["SmallIconUrl"] == null ? String.Empty : (string) bag ["SmallIconUrl"]; }
 60			set { bag ["SmallIconUrl"] = value; }
 61		}
 62
 63		[SuppressMessage ("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
 64		[Editor ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof (UITypeEditor))]
 65		[DefaultValue ("")]
 66		[UrlProperty]
 67		[Bindable (true)]
 68		public string LargeImageUrl {
 69			get { return bag ["LargeIconUrl"] == null ? String.Empty : (string) bag ["LargeIconUrl"]; }
 70			set { bag ["LargeIconUrl"] = value; }
 71		}
 72
 73		/// <summary>
 74		/// Gets or sets the text displayed for the node in the folder tree of FileManager control.
 75		/// </summary>
 76		[DefaultValue ("")]
 77		public string Text {
 78			get { return (string) bag ["Text"] ?? String.Empty; }
 79			set {
 80				// validate value must be valid file/folder name 
 81				if (!FileManagerController.Validate (value))
 82					throw new ArgumentException (String.Format ("'{0}' is not a valid value for RootDirectory.Text, It cannot contain any of the following characters: \\/:*?\"<>|", value));
 83				bag ["Text"] = value;
 84			}
 85		}
 86
 87		internal string TextInternal {
 88			get {
 89				if (String.IsNullOrEmpty (Text))
 90					return VirtualPathUtility.GetFileName (DirectoryPath);
 91				return Text;
 92			}
 93		}
 94
 95		[DefaultValue (true)]
 96		public bool ShowRootIndex {
 97			get { return bag ["ShowRootIndex"] == null ? true : (bool) bag ["ShowRootIndex"]; }
 98			set {
 99				bag ["ShowRootIndex"] = value;
100			}
101		}
102
103		/// <summary>
104		/// Overridden
105		/// </summary>
106		/// <returns></returns>
107		public override string ToString () {
108			return DirectoryPath;
109		}
110
111		#region IStateManager Members
112
113		bool IStateManager.IsTrackingViewState {
114			get { return ((IStateManager) bag).IsTrackingViewState; }
115		}
116
117		void IStateManager.LoadViewState (object state) {
118			((IStateManager) bag).LoadViewState (state);
119		}
120
121		object IStateManager.SaveViewState () {
122			return ((IStateManager) bag).SaveViewState ();
123		}
124
125		void IStateManager.TrackViewState () {
126			((IStateManager) bag).TrackViewState ();
127		}
128
129		#endregion
130
131		internal void SetDirty () {
132			bag.SetDirty (true);
133		}
134	}
135}