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