PageRenderTime 78ms CodeModel.GetById 35ms app.highlight 6ms RepoModel.GetById 35ms app.codeStats 0ms

/IZWebFileManager/Components/FileViewRender.cs

http://izwebfilemanager.googlecode.com/
C# | 103 lines | 71 code | 10 blank | 22 comment | 6 complexity | fcc2079b89884f6f2b7c49646219ebb3 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.Web.UI.WebControls;
 22using System.IO;
 23using System.Web;
 24
 25namespace IZ.WebFileManager.Components
 26{
 27	abstract class FileViewRender
 28	{
 29		//protected SortMode sort;
 30		//protected SortDirection sortDirection;
 31		protected FileManagerController controller;
 32		protected FileView fileView;
 33
 34		protected FileViewRender (FileView fileView) {
 35			this.fileView = fileView;
 36			this.controller = fileView.Controller;
 37			//this.sort = fileView.Sort;
 38			//this.sortDirection = fileView.SortDirection;
 39		}
 40
 41
 42		internal virtual void RenderBeginList (HtmlTextWriter output) {
 43		}
 44		internal virtual void RenderEndList (HtmlTextWriter output) {
 45		}
 46
 47		internal virtual void RenderBeginGroup (HtmlTextWriter output, GroupInfo group) {
 48			output.AddStyleAttribute ("clear", "both");
 49			output.AddStyleAttribute (HtmlTextWriterStyle.Width, "100%");
 50			output.RenderBeginTag (HtmlTextWriterTag.Div);
 51			output.Write (HttpUtility.HtmlEncode (group.Name));
 52			output.RenderEndTag ();
 53		}
 54		internal virtual void RenderEndGroup (HtmlTextWriter output, GroupInfo group) {
 55		}
 56
 57		//internal virtual void RenderUpDirectory(HtmlTextWriter output, System.IO.DirectoryInfo dir)
 58		//{
 59		//}
 60		internal virtual void RenderItem (HtmlTextWriter output, FileViewItem item) {
 61		}
 62		internal static FileViewRender GetRender (FileView fileView) {
 63			switch (fileView.View) {
 64			case FileViewRenderMode.Details:
 65				return new FileViewDetailsRender (fileView);
 66			case FileViewRenderMode.Icons:
 67				return new FileViewIconsRender (fileView);
 68			case FileViewRenderMode.Thumbnails:
 69				if (fileView.Controller.SupportThumbnails)
 70					return new FileViewThumbnailsRender (fileView);
 71				return new FileViewIconsRender (fileView);
 72			default:
 73				return new FileViewDetailsRender (fileView);
 74			}
 75		}
 76
 77		protected void RenderItemName (HtmlTextWriter output, FileViewItem item) {
 78			if (fileView.UseLinkToOpenItem) {
 79				string href = item.IsDirectory ?
 80					"javascript:WFM_" + fileView.Controller.ClientID + ".OnExecuteCommand(WFM_" + fileView.ClientID + ",\'0:0\')" :
 81					(VirtualPathUtility.AppendTrailingSlash (fileView.CurrentDirectory.VirtualPath) + item.FileSystemInfo.Name);
 82				if (!item.IsDirectory && !String.IsNullOrEmpty (fileView.LinkToOpenItemTarget))
 83					output.AddAttribute (HtmlTextWriterAttribute.Target, fileView.LinkToOpenItemTarget);
 84				output.AddAttribute (HtmlTextWriterAttribute.Href, href, true);
 85				output.AddAttribute (HtmlTextWriterAttribute.Class, fileView.LinkToOpenItemClass);
 86				output.RenderBeginTag (HtmlTextWriterTag.A);
 87				output.Write (HttpUtility.HtmlEncode (item.Name));
 88				output.RenderEndTag ();
 89			}
 90			else {
 91				output.Write (HttpUtility.HtmlEncode (item.Name));
 92			}
 93		}
 94	}
 95
 96	public enum FileViewRenderMode
 97	{
 98		Icons,
 99		Details,
100		Thumbnails
101	}
102
103}