From 999b09dbf0abeab19eba3a67093d76ce088318a6 Mon Sep 17 00:00:00 2001 From: Jamie Sharpe Date: Sun, 9 Aug 2020 10:23:46 +0100 Subject: [PATCH 1/3] Added display path options to folder listing module. --- ShareX.IndexerLib/IndexerHtml.cs | 20 +++++++++++++++++--- ShareX.IndexerLib/IndexerSettings.cs | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ShareX.IndexerLib/IndexerHtml.cs b/ShareX.IndexerLib/IndexerHtml.cs index 6748d11b7..081516d54 100644 --- a/ShareX.IndexerLib/IndexerHtml.cs +++ b/ShareX.IndexerLib/IndexerHtml.cs @@ -34,6 +34,7 @@ namespace ShareX.IndexerLib public class IndexerHtml : Indexer { protected StringBuilder sbContent = new StringBuilder(); + protected int prePathTrim = 0; public IndexerHtml(IndexerSettings indexerSettings) : base(indexerSettings) { @@ -52,6 +53,8 @@ public override string Index(string folderPath) sbHtmlIndex.AppendLine(HtmlHelper.EndTag("head")); sbHtmlIndex.AppendLine(HtmlHelper.StartTag("body")); + prePathTrim = folderPath.LastIndexOf(@"\"); + FolderInfo folderInfo = GetFolderInfo(folderPath); folderInfo.Update(); @@ -107,7 +110,7 @@ private string GetFolderNameRow(FolderInfo dir, int level) if (dir.TotalFileCount > 0) { - folderNameRow += dir.TotalFileCount + " file" + (dir.TotalFileCount > 1 ? "s" : ""); + folderNameRow += dir.TotalFileCount.ToString("n0") + " file" + (dir.TotalFileCount > 1 ? "s" : ""); } if (dir.TotalFolderCount > 0) @@ -117,16 +120,27 @@ private string GetFolderNameRow(FolderInfo dir, int level) folderNameRow += ", "; } - folderNameRow += dir.TotalFolderCount + " folder" + (dir.TotalFolderCount > 1 ? "s" : ""); + folderNameRow += dir.TotalFolderCount.ToString("n0") + " folder" + (dir.TotalFolderCount > 1 ? "s" : ""); } folderNameRow += ")"; folderNameRow = " " + HtmlHelper.Tag("span", folderNameRow, "", "class=\"FolderInfo\""); } + string pathTitle = ""; + + if (settings.DisplayPath) + { + pathTitle = settings.DisplayPathLimited ? dir.FolderPath.Substring(prePathTrim) : dir.FolderPath; + } + else + { + pathTitle = dir.FolderName; + } + int heading = (level + 1).Clamp(1, 6); - return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(dir.FolderName) + folderNameRow + HtmlHelper.EndTag("h" + heading); + return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(pathTitle) + folderNameRow + HtmlHelper.EndTag("h" + heading); } private string GetFileNameRow(FileInfo fi, int level) diff --git a/ShareX.IndexerLib/IndexerSettings.cs b/ShareX.IndexerLib/IndexerSettings.cs index deb7d0b97..c8538dbdc 100644 --- a/ShareX.IndexerLib/IndexerSettings.cs +++ b/ShareX.IndexerLib/IndexerSettings.cs @@ -59,6 +59,12 @@ public class IndexerSettings [Category("Indexer / HTML"), DefaultValue(false), Description("Use custom Cascading Style Sheet file.")] public bool UseCustomCSSFile { get; set; } + [Category("Indexer / HTML"), DefaultValue(false), Description("Display the path for each subfolder.")] + public bool DisplayPath { get; set; } + + [Category("Indexer / HTML"), DefaultValue(false), Description("Limit the display path to the selected root folder. Must have DisplayPath enabled.")] + public bool DisplayPathLimited { get; set; } + [Category("Indexer / HTML"), DefaultValue(""), Description("Custom Cascading Style Sheet file path."), Editor(typeof(CssFileNameEditor), typeof(UITypeEditor))] public string CustomCSSFilePath { get; set; } From b24065d8004b8b3d0646dd2cd4d9ab0fcbb2b1a7 Mon Sep 17 00:00:00 2001 From: Jamie Sharpe Date: Sun, 9 Aug 2020 12:45:45 +0100 Subject: [PATCH 2/3] Fixed additional path separator bug in Directory Indexer. --- ShareX.IndexerLib/IndexerHtml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ShareX.IndexerLib/IndexerHtml.cs b/ShareX.IndexerLib/IndexerHtml.cs index 081516d54..720982547 100644 --- a/ShareX.IndexerLib/IndexerHtml.cs +++ b/ShareX.IndexerLib/IndexerHtml.cs @@ -53,6 +53,7 @@ public override string Index(string folderPath) sbHtmlIndex.AppendLine(HtmlHelper.EndTag("head")); sbHtmlIndex.AppendLine(HtmlHelper.StartTag("body")); + folderPath = Path.GetFullPath(folderPath).TrimEnd('\\'); prePathTrim = folderPath.LastIndexOf(@"\"); FolderInfo folderInfo = GetFolderInfo(folderPath); From 8824835cff17af69dc483c7b7a1d5dc21fa2e3cc Mon Sep 17 00:00:00 2001 From: Jamie Sharpe Date: Sun, 9 Aug 2020 12:57:55 +0100 Subject: [PATCH 3/3] Removed prepended path separator from root folder in Directory Indexer module. --- ShareX.IndexerLib/IndexerHtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShareX.IndexerLib/IndexerHtml.cs b/ShareX.IndexerLib/IndexerHtml.cs index 720982547..d6df433c4 100644 --- a/ShareX.IndexerLib/IndexerHtml.cs +++ b/ShareX.IndexerLib/IndexerHtml.cs @@ -54,7 +54,7 @@ public override string Index(string folderPath) sbHtmlIndex.AppendLine(HtmlHelper.StartTag("body")); folderPath = Path.GetFullPath(folderPath).TrimEnd('\\'); - prePathTrim = folderPath.LastIndexOf(@"\"); + prePathTrim = folderPath.LastIndexOf(@"\") + 1; FolderInfo folderInfo = GetFolderInfo(folderPath); folderInfo.Update();