private IEnumerable <Element> GetSharedCodeElements(SearchToken searchToken)
        {
            var result = new List <Element>();

            foreach (SharedFile sharedFile in PageTemplateFacade.GetSharedFiles())
            {
                string relativeFilePath = sharedFile.RelativeFilePath;

                string fullPath    = relativeFilePath.StartsWith("~") ? PathUtil.Resolve(relativeFilePath) : relativeFilePath;
                var    websiteFile = new WebsiteFile(fullPath);

                Element element = new Element(_context.CreateElementHandle(new SharedCodeFileEntityToken(relativeFilePath)))
                {
                    VisualData = new ElementVisualizedData()
                    {
                        Label       = websiteFile.FileName,
                        ToolTip     = websiteFile.FileName,
                        HasChildren = false,
                        Icon        = FileElementProvider.WebsiteFileIcon(websiteFile.MimeType),
                        OpenedIcon  = FileElementProvider.WebsiteFileIcon(websiteFile.MimeType)
                    }
                };

                element.PropertyBag.Add("Uri", PathUtil.GetWebsitePath(websiteFile.FullPath));
                element.PropertyBag.Add("ElementType", websiteFile.MimeType);

                // Adding "Edit" action for text-editable files
                if (sharedFile.DefaultEditAction && MimeTypeInfo.IsTextFile(websiteFile.MimeType))
                {
                    element.AddWorkflowAction(
                        "Composite.Plugins.Elements.ElementProviders.PageTemplateElementProvider.EditSharedCodeFileWorkflow",
                        new[] { PermissionType.Edit },
                        new ActionVisualizedData
                    {
                        Label          = GetResourceString("EditSharedCodeFile.Label"),
                        ToolTip        = GetResourceString("EditSharedCodeFile.ToolTip"),
                        Icon           = CommonCommandIcons.Edit,
                        Disabled       = websiteFile.IsReadOnly,
                        ActionLocation = new ActionLocation
                        {
                            ActionType  = ActionType.Edit,
                            IsInFolder  = false,
                            IsInToolbar = true,
                            ActionGroup = EditCodeFileActionGroup
                        }
                    });
                }

                var customActions = sharedFile.GetActions();
                foreach (var action in customActions)
                {
                    element.AddAction(action);
                }

                result.Add(element);
            }

            return(result);
        }
예제 #2
0
        private static bool IsEditActionAllowed(WebsiteEntity websiteEntity)
        {
            if (websiteEntity is WebsiteFile)
            {
                WebsiteFile websiteFile = websiteEntity as WebsiteFile;

                return(MimeTypeInfo.IsTextFile(websiteFile.MimeType));
            }

            if (websiteEntity is WebsiteFolder)
            {
                return(false);
            }

            throw new NotImplementedException();
        }
예제 #3
0
        private bool FilePreviewable(FileInfo fileInfo)
        {
            if (string.IsNullOrEmpty(fileInfo.Extension))
            {
                return(false);
            }

            string mimeType = MimeTypeInfo.GetCanonicalFromExtension(fileInfo.Extension);

            if (string.IsNullOrEmpty(mimeType))
            {
                return(false);
            }

            return(MimeTypeInfo.IsBrowserPreviewableFile(mimeType) ||
                   (MimeTypeInfo.IsTextFile(mimeType) && fileInfo.Length < 1 << 20 /* 1 MB */));
        }
        private bool FilePreviewable(FileInfo fileInfo)
        {
            if (string.IsNullOrEmpty(fileInfo.Extension))
            {
                return(false);
            }

            string mimeType = MimeTypeInfo.GetCanonicalFromExtension(fileInfo.Extension);

            if (string.IsNullOrEmpty(mimeType))
            {
                return(false);
            }

            return(MimeTypeInfo.IsBrowserPreviewableFile(mimeType) ||
                   (MimeTypeInfo.IsTextFile(mimeType) && fileInfo.Length < 1 << 20 /* 1 MB */) ||
                   fileInfo.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase));
        }