Ejemplo n.º 1
0
        void CreateSelectedItemsContextMenu()
        {
            _selectedItemsContextMenu = new ContextMenu(
                ClientID + "scm",
                Controller.CurrentUICulture.TextInfo.IsRightToLeft,
                RenderContextMenuPopupItem,
                Controller.DynamicMenuStyle,
                Controller.DynamicMenuItemStyle,
                Controller.DynamicHoverStyle);

            // Root
            MenuItem root = new MenuItem();
            root.Text = "_contextMenu";
            root.NavigateUrl = "javascript: return;";
            _selectedItemsContextMenu.Items.Add(root);

            string clientClickFunction = "javascript:" + FileManagerController.ClientScriptObjectNamePrefix + Controller.ClientID + ".On{0}(" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ", '{1}');return false;";

            StringBuilder sbCommands = new StringBuilder();

            for (int i = 0; i < FileTypes.Count; i++)
            {
                FileType ft = FileTypes[i];
                for (int j = 0; j < ft.Commands.Count; j++)
                {
                    FileManagerCommand command = ft.Commands[j];
                    MenuItem itemCommand = new MenuItem();
                    itemCommand.Text = command.Name;
                    itemCommand.Value = i + "_" + j;
                    itemCommand.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.ExecuteCommand, "0:" + j);
                    itemCommand.ImageUrl = command.SmallImageUrl;
                    root.ChildItems.Add(itemCommand);

                    sbCommands.AppendLine(ClientID + "_SetCommandVisible('" + ClientID + "CMD" + i + "_" + j + "', (" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".SelectedItems.length==1) && (" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".SelectedItems[0].FileType==" + i + "));");
                }
            }

            MenuItem itemOpen = new MenuItem();
            itemOpen.Text = GetResourceString("Open", "Open");
            itemOpen.Value = "Open";
            itemOpen.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.ExecuteCommand, "0:-1");
            root.ChildItems.Add(itemOpen);

            MenuItem itemDownload = new MenuItem();
            itemDownload.Text = GetResourceString("Download", "Download");
            itemDownload.Value = "Download";
            itemDownload.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.ExecuteCommand, "0:-2");
            root.ChildItems.Add(itemDownload);
            sbCommands.AppendLine(ClientID + "_SetCommandVisible('" + ClientID + "CMDDownload', (" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".SelectedItems.length==1) && (" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".SelectedItems[0].FileType!=-2));");

            root.ChildItems.Add(new MenuItem("__separator__", "__separator__", null, "javascript: return;"));

            // Copy to
            MenuItem itemCopyTo = new MenuItem();
            itemCopyTo.Text = GetResourceString("Copy", "Copy");
            itemCopyTo.Value = "Copy";
            itemCopyTo.ImageUrl = Controller.GetToolbarImage(ToolbarImages.Copy);
            itemCopyTo.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.SelectedItemsCopyTo, "");
            itemCopyTo.Enabled = !ReadOnly;
            root.ChildItems.Add(itemCopyTo);

            // Move to
            MenuItem itemMoveTo = new MenuItem();
            itemMoveTo.Text = GetResourceString("Move", "Move");
            itemMoveTo.Value = "Move";
            itemMoveTo.ImageUrl = Controller.GetToolbarImage(ToolbarImages.Move);
            itemMoveTo.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.SelectedItemsMoveTo, "");
            itemMoveTo.Enabled = !ReadOnly && AllowDelete;
            root.ChildItems.Add(itemMoveTo);

            root.ChildItems.Add(new MenuItem("__separator__", "__separator__", null, "javascript: return;"));

            // Delete
            MenuItem itemDelete = new MenuItem();
            itemDelete.Text = GetResourceString("Delete", "Delete");
            itemDelete.Value = "Delete";
            itemDelete.ImageUrl = Controller.GetToolbarImage(ToolbarImages.Delete);
            itemDelete.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.SelectedItemsDelete, "");
            itemDelete.Enabled = !ReadOnly && AllowDelete;
            root.ChildItems.Add(itemDelete);

            // Rename
            MenuItem itemRename = new MenuItem();
            itemRename.Text = GetResourceString("Rename", "Rename");
            itemRename.Value = "Rename";
            itemRename.ImageUrl = Controller.GetToolbarImage(ToolbarImages.Rename);
            itemRename.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.Rename, "");
            itemRename.Enabled = !ReadOnly && AllowDelete;
            root.ChildItems.Add(itemRename);

            // client script
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("function " + ClientID + "_ShowSelectedItemsContextMenu(x,y) {");
            sb.Append(sbCommands.ToString());
            sb.AppendLine("var node = WebForm_GetElementById('" + _selectedItemsContextMenu.ClientID + "')");
            sb.AppendLine("WebForm_SetElementX(node, x)");
            sb.AppendLine("WebForm_SetElementY(node, y)");
            sb.AppendLine("IZWebFileManager_ShowElement('" + _selectedItemsContextMenu.ClientID + "_0');");
            sb.AppendLine("}");
            sb.AppendLine("function " + ClientID + "_SetCommandVisible(command, value) {");
            sb.AppendLine("var node = WebForm_GetElementById(command);");
            sb.AppendLine("var row = node.parentNode;");
            sb.AppendLine("if (value) {");
            sb.AppendLine("row.style.visibility = \"visible\";");
            sb.AppendLine("row.style.display = \"block\";");
            sb.AppendLine("row.style.position = \"static\";");
            //sb.AppendLine ("row.parentNode.parentNode.style.height = \"auto\";");
            sb.AppendLine("} else {");
            sb.AppendLine("row.style.visibility = \"hidden\";");
            sb.AppendLine("row.style.display = \"none\";");
            sb.AppendLine("row.style.position = \"absolute\";");
            //sb.AppendLine ("row.parentNode.parentNode.style.height = \"0px\";");
            sb.AppendLine("}");
            sb.AppendLine("}");
            Page.ClientScript.RegisterClientScriptBlock(typeof(FileView), ClientID + "_ShowSelectedItemsContextMenu", sb.ToString(), true);
        }
Ejemplo n.º 2
0
        void CreateContextMenu()
        {
            _contextMenu = new ContextMenu(
                ClientID + "cm",
                Controller.CurrentUICulture.TextInfo.IsRightToLeft,
                RenderContextMenuPopupItem,
                Controller.DynamicMenuStyle,
                Controller.DynamicMenuItemStyle,
                Controller.DynamicHoverStyle);

            // Root
            MenuItem root = new MenuItem();
            root.Text = "_contextMenu";
            root.NavigateUrl = "javascript: return;";
            _contextMenu.Items.Add(root);

            string clientClickFunction = "javascript:" + FileManagerController.ClientScriptObjectNamePrefix + Controller.ClientID + ".On{0}(" + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ", '{1}');return false;";

            // View
            MenuItem itemView = new MenuItem();
            itemView.Text = GetResourceString("View", "View");
            itemView.Value = "View";
            itemView.NavigateUrl = "javascript: return;";
            root.ChildItems.Add(itemView);

            // Icons
            MenuItem itemViewIcons = new MenuItem();
            itemViewIcons.Text = GetResourceString("Icons", "Icons");
            itemViewIcons.Value = "Icons";
            itemViewIcons.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewChangeView, FileViewRenderMode.Icons);
            itemView.ChildItems.Add(itemViewIcons);

            // Details
            MenuItem itemViewDetails = new MenuItem();
            itemViewDetails.Text = GetResourceString("Details", "Details");
            itemViewDetails.Value = "Details";
            itemViewDetails.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewChangeView, FileViewRenderMode.Details);
            itemView.ChildItems.Add(itemViewDetails);

            // Thumbnails
            MenuItem itemViewThumbnails = new MenuItem();
            itemViewThumbnails.Text = GetResourceString("Thumbnails", "Thumbnails");
            itemViewThumbnails.Value = "Thumbnails";
            itemViewThumbnails.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewChangeView, FileViewRenderMode.Thumbnails);
            itemView.ChildItems.Add(itemViewThumbnails);

            root.ChildItems.Add(new MenuItem("__separator__", "__separator__", null, "javascript: return;"));

            // Arrange Icons By
            MenuItem itemArrangeIconsBy = new MenuItem();
            itemArrangeIconsBy.Text = GetResourceString("Arrange_Icons_By", "Arrange Icons By");
            itemArrangeIconsBy.Value = "Arrange_Icons_By";
            itemArrangeIconsBy.NavigateUrl = "javascript: return;";
            root.ChildItems.Add(itemArrangeIconsBy);

            // Name
            MenuItem itemArrangeIconsByName = new MenuItem();
            itemArrangeIconsByName.Text = GetResourceString("Name", "Name");
            itemArrangeIconsByName.Value = "Name";
            itemArrangeIconsByName.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewSort, SortMode.Name);
            itemArrangeIconsBy.ChildItems.Add(itemArrangeIconsByName);

            // Size
            MenuItem itemArrangeIconsBySize = new MenuItem();
            itemArrangeIconsBySize.Text = GetResourceString("Size", "Size");
            itemArrangeIconsBySize.Value = "Size";
            itemArrangeIconsBySize.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewSort, SortMode.Size);
            itemArrangeIconsBy.ChildItems.Add(itemArrangeIconsBySize);

            // Type
            MenuItem itemArrangeIconsByType = new MenuItem();
            itemArrangeIconsByType.Text = GetResourceString("Type", "Type");
            itemArrangeIconsByType.Value = "Type";
            itemArrangeIconsByType.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewSort, SortMode.Type);
            itemArrangeIconsBy.ChildItems.Add(itemArrangeIconsByType);

            // Modified
            MenuItem itemArrangeIconsByModified = new MenuItem();
            itemArrangeIconsByModified.Text = GetResourceString("Date_Modified", "Date Modified");
            itemArrangeIconsByModified.Value = "Modified";
            itemArrangeIconsByModified.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.FileViewSort, SortMode.Modified);
            itemArrangeIconsBy.ChildItems.Add(itemArrangeIconsByModified);

            // Refresh
            MenuItem itemRefresh = new MenuItem();
            itemRefresh.Text = Controller.GetResourceString("Refresh", "Refresh");
            itemRefresh.Value = "Refresh";
            itemRefresh.ImageUrl = Controller.GetToolbarImage(ToolbarImages.Refresh);
            itemRefresh.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.Refresh, "");
            root.ChildItems.Add(itemRefresh);

            root.ChildItems.Add(new MenuItem("__separator__", "__separator__", null, "javascript: return;"));

            // New
            MenuItem itemNew = new MenuItem();
            itemNew.Text = GetResourceString("Create", "New");
            itemNew.Value = "Create";
            itemNew.NavigateUrl = "javascript: return;";
            itemNew.Enabled = !ReadOnly;
            root.ChildItems.Add(itemNew);

            if (!ReadOnly)
            {
                // New Folder
                MenuItem itemFolder = new MenuItem();
                itemFolder.Text = GetResourceString("New_Folder", "Folder");
                itemFolder.Value = "New_Folder";
                itemFolder.ImageUrl = Controller.GetFolderSmallImage();
                itemFolder.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.NewFolder, "");
                itemNew.ChildItems.Add(itemFolder);

                itemNew.ChildItems.Add(new MenuItem("__separator__", "__separator__", null, "javascript: return;"));

                for (int i = 0; i < Templates.Count; i++)
                {
                    NewDocumentTemplate template = Templates[i];
                    MenuItem item = new MenuItem();
                    item.Text = template.Name;
                    item.Value = "Template" + i;
                    if (template.SmallImageUrl.Length > 0)
                        item.ImageUrl = ResolveUrl(template.SmallImageUrl);
                    else if (template.MasterFileUrl.Length > 0)
                        item.ImageUrl = Controller.GetFileSmallImage(new FileInfo(Page.MapPath(template.MasterFileUrl)));
                    else
                        item.ImageUrl = Controller.GetFileSmallImage();
                    item.NavigateUrl = String.Format(clientClickFunction, FileManagerCommands.NewDocument, Templates.IndexOf(template));
                    itemNew.ChildItems.Add(item);
                }
            }

            // client script
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("function " + ClientID + "_ShowContextMenu(x,y) {");

            sb.AppendLine("var bulletImgSrc = '" + Page.ClientScript.GetWebResourceUrl(typeof(FileManagerController), "IZ.WebFileManager.resources.Bullet.gif") + "';");
            sb.AppendLine("var emptyImgSrc = '" + Page.ClientScript.GetWebResourceUrl(typeof(FileManagerController), "IZ.WebFileManager.resources.Empty.gif") + "';");

            sb.AppendLine("var nameImg = WebForm_GetElementById('" + ClientID + "CMIMGName');");
            sb.AppendLine("var sizeImg = WebForm_GetElementById('" + ClientID + "CMIMGSize');");
            sb.AppendLine("var typeImg = WebForm_GetElementById('" + ClientID + "CMIMGType');");
            sb.AppendLine("var modifiedImg = WebForm_GetElementById('" + ClientID + "CMIMGModified');");
            sb.AppendLine("var iconsImg = WebForm_GetElementById('" + ClientID + "CMIMGIcons');");
            sb.AppendLine("var detailsImg = WebForm_GetElementById('" + ClientID + "CMIMGDetails');");
            sb.AppendLine("var thumbnailsImg = WebForm_GetElementById('" + ClientID + "CMIMGThumbnails');");

            sb.AppendLine("nameImg.src = emptyImgSrc;");
            sb.AppendLine("sizeImg.src = emptyImgSrc;");
            sb.AppendLine("typeImg.src = emptyImgSrc;");
            sb.AppendLine("modifiedImg.src = emptyImgSrc;");
            sb.AppendLine("iconsImg.src = emptyImgSrc;");
            sb.AppendLine("detailsImg.src = emptyImgSrc;");
            sb.AppendLine("thumbnailsImg.src = emptyImgSrc;");

            sb.AppendLine("var sort = " + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".GetSort();");
            sb.AppendLine("switch(sort) {");
            sb.AppendLine("case '" + SortMode.Name + "':");
            sb.AppendLine("nameImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("case '" + SortMode.Type + "':");
            sb.AppendLine("typeImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("case '" + SortMode.Size + "':");
            sb.AppendLine("sizeImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("case '" + SortMode.Modified + "':");
            sb.AppendLine("modifiedImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("}");

            sb.AppendLine("var view = " + FileManagerController.ClientScriptObjectNamePrefix + ClientID + ".GetView();");
            sb.AppendLine("switch(view) {");
            sb.AppendLine("case '" + FileViewRenderMode.Icons + "':");
            sb.AppendLine("iconsImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("case '" + FileViewRenderMode.Details + "':");
            sb.AppendLine("detailsImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("case '" + FileViewRenderMode.Thumbnails + "':");
            sb.AppendLine("thumbnailsImg.src = bulletImgSrc;");
            sb.AppendLine("break;");
            sb.AppendLine("}");

            sb.AppendLine("var node = WebForm_GetElementById('" + _contextMenu.ClientID + "')");
            sb.AppendLine("WebForm_SetElementX(node, x)");
            sb.AppendLine("WebForm_SetElementY(node, y)");
            sb.AppendLine("IZWebFileManager_ShowElement('" + _contextMenu.ClientID + "_0');");
            sb.AppendLine("}");
            Page.ClientScript.RegisterClientScriptBlock(typeof(FileView), ClientID + "_ShowContextMenu", sb.ToString(), true);
        }