Added display path options to folder listing module.

This commit is contained in:
Jamie Sharpe 2020-08-09 10:23:46 +01:00
parent b45751f264
commit 999b09dbf0
2 changed files with 23 additions and 3 deletions

View file

@ -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)

View file

@ -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; }