From 4de3bec866cf840da5f0969d4bbd470557b033cb Mon Sep 17 00:00:00 2001 From: TfT Hacker Date: Fri, 18 Nov 2022 14:28:05 +0100 Subject: [PATCH] Added maxFileCountToDisplay --- .gitignore | 4 ++- src/main.ts | 2 ++ src/ui/components/uic-ref--parent.ts | 4 +-- src/ui/components/uic-ref-area.ts | 17 ++++++++-- src/ui/settingsTab.ts | 49 +++++++++++++++++++--------- 5 files changed, 56 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 3e19c6a..c333062 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # vscode .vscode +TODONOTES.md # Intellij *.iml @@ -29,4 +30,5 @@ build .Spotlight-V100 .Trashes ehthumbs.db -Thumbs.db \ No newline at end of file +Thumbs.db + diff --git a/src/main.ts b/src/main.ts index 55f5337..013ef46 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ import { SettingsTab, Settings, DEFAULT_SETTINGS} from "./ui/settingsTab"; import SnwAPI from "./snwApi"; import { setPluginVariableForUIC } from "./ui/components/uic-ref--parent"; import PluginCommands from "./pluginCommands"; +import { setPluginVariableUIC_RefArea } from "./ui/components/uic-ref-area"; export default class SNWPlugin extends Plugin { @@ -32,6 +33,7 @@ export default class SNWPlugin extends Plugin { console.log("loading " + this.appName); setPluginVariableForIndexer(this); + setPluginVariableUIC_RefArea(this); setPluginVariableForHtmlDecorations(this); setPluginVariableForCM6Gutter(this); setPluginVariableForHeaderRefCount(this); diff --git a/src/ui/components/uic-ref--parent.ts b/src/ui/components/uic-ref--parent.ts index 92a9581..774fb91 100644 --- a/src/ui/components/uic-ref--parent.ts +++ b/src/ui/components/uic-ref--parent.ts @@ -22,7 +22,7 @@ export const getUIC_Hoverview = async (instance: Instance)=>{ const popoverEl = createDiv(); popoverEl.addClass("snw-popover-container"); popoverEl.addClass("search-result-container") - popoverEl.appendChild( await getUIC_Ref_Area(refType, key, filePath, lineNu, true, thePlugin)); + popoverEl.appendChild( await getUIC_Ref_Area(refType, key, filePath, lineNu, true)); instance.setContent(popoverEl); setTimeout( async () => { await setFileLinkHandlers(false, popoverEl); @@ -42,7 +42,7 @@ const getUIC_SidePane = async (refType: string, key: string, filePath: string, l const sidepaneEL = createDiv(); sidepaneEL.addClass("snw-sidepane-container"); sidepaneEL.addClass("search-result-container"); - sidepaneEL.append( (await getUIC_Ref_Area(refType, key, filePath, lineNu, false, thePlugin)) ) + sidepaneEL.append( (await getUIC_Ref_Area(refType, key, filePath, lineNu, false)) ) setTimeout( async () => { await setFileLinkHandlers(false, sidepaneEL); diff --git a/src/ui/components/uic-ref-area.ts b/src/ui/components/uic-ref-area.ts index 466e9f0..184c2cd 100644 --- a/src/ui/components/uic-ref-area.ts +++ b/src/ui/components/uic-ref-area.ts @@ -1,5 +1,6 @@ //wrapper element for references area. shared between popover and sidepane + import { setIcon } from "obsidian"; import { getReferencesCache, getSnwAllLinksResolutions } from "src/indexer"; import SNWPlugin from "src/main"; @@ -8,6 +9,12 @@ import { getUIC_Ref_Item } from "./uic-ref-item"; import { getUIC_Ref_Title_Div } from "./uic-ref-title"; +let thePlugin: SNWPlugin; + +export function setPluginVariableUIC_RefArea(plugin: SNWPlugin) { + thePlugin = plugin; +} + export /** * Crates the primarhy "AREA" body for displaying refrences. This is the overall wrapper for the title and individaul references * @@ -17,7 +24,7 @@ export /** * @param {boolean} isHoverView * @return {*} {Promise} */ -const getUIC_Ref_Area = async (refType: string, key: string, filePath: string, lineNu: number, isHoverView:boolean, thePlugin: SNWPlugin): Promise => { +const getUIC_Ref_Area = async (refType: string, key: string, filePath: string, lineNu: number, isHoverView:boolean): Promise => { const refAreaItems = await getRefAreaItems(refType, key, filePath); const refAreaContainerEl = createDiv(); @@ -65,7 +72,13 @@ const getRefAreaItems = async (refType: string, key: string, filePath: string): const wrapperEl = createDiv(); - for (const file_path of uniqueFileKeys ) { + let maxItemsToShow = uniqueFileKeys.length-1; + + if(thePlugin.settings.maxFileCountToDisplay!=1000 && maxItemsToShow >= thePlugin.settings.maxFileCountToDisplay-1) + maxItemsToShow = thePlugin.settings.maxFileCountToDisplay; + + for (let index = 0; index < maxItemsToShow; index++) { + const file_path = uniqueFileKeys[index]; const responseItemContainerEl = createDiv(); responseItemContainerEl.addClass("snw-ref-item-container"); responseItemContainerEl.addClass("tree-item"); diff --git a/src/ui/settingsTab.ts b/src/ui/settingsTab.ts index 650a733..9b1b92b 100644 --- a/src/ui/settingsTab.ts +++ b/src/ui/settingsTab.ts @@ -4,7 +4,8 @@ import SNWPlugin from "../main"; export interface Settings { enableOnStartupDesktop: boolean; enableOnStartupMobile: boolean; - minimumRefCountThreshold: number; + minimumRefCountThreshold: number; //minimum required to display a count + maxFileCountToDisplay: number; // maximum number of items to display in popup or sidepane displayIncomingFilesheader: boolean; displayInlineReferencesLivePreview: boolean; displayInlineReferencesMarkdown: boolean; @@ -25,6 +26,7 @@ export const DEFAULT_SETTINGS: Settings = { enableOnStartupDesktop: true, enableOnStartupMobile: true, minimumRefCountThreshold: 1, + maxFileCountToDisplay: 50, displayIncomingFilesheader: true, displayInlineReferencesLivePreview: true, displayInlineReferencesMarkdown: true, @@ -55,6 +57,37 @@ export class SettingsTab extends PluginSettingTab { containerEl.createEl('h2', { text: this.thePlugin.appName }); + + containerEl.createEl("h2", { text: "Thresholds" }); + new Setting(containerEl) + .setName("Minimal required count to show counter") + .setDesc(`This setting defines how many references there needs to be for the reference count box to appear. May require reloading open files. + Currently set to: ${this.thePlugin.settings.minimumRefCountThreshold} refernences.`) + .addSlider(slider => slider + .setLimits(1, 1000 , 1) + .setValue(this.thePlugin.settings.minimumRefCountThreshold) + .onChange(async (value) => { + this.thePlugin.settings.minimumRefCountThreshold = value; + await this.thePlugin.saveSettings(); + }) + .setDynamicTooltip() + ) + + new Setting(containerEl) + .setName("Maximum file references to show") + .setDesc(`This setting defines the max amount of files with their references are displayed in the popup or sidebar. Set to 1000 for no maximum. + Currently set to: ${this.thePlugin.settings.maxFileCountToDisplay} refernences.`) + .addSlider(slider => slider + .setLimits(1, 1000 , 1) + .setValue(this.thePlugin.settings.maxFileCountToDisplay) + .onChange(async (value) => { + this.thePlugin.settings.maxFileCountToDisplay = value; + await this.thePlugin.saveSettings(); + }) + .setDynamicTooltip() + ) + + containerEl.createEl("h2", { text: "Enable on startup" }); new Setting(containerEl) .setName("Enable upon startup (Desktop)") @@ -240,21 +273,7 @@ export class SettingsTab extends PluginSettingTab { }); }); - containerEl.createEl("h2", { text: "Other Settings" }); - new Setting(containerEl) - .setName("Minimal file count threshold") - .setDesc(`This setting defines how many references there needs to be for the reference count box to appear. Default is one reference. - Currently set to: ${this.thePlugin.settings.minimumRefCountThreshold} refernences.`) - .addSlider(slider => slider - .setLimits(1, 20 , 1) - .setValue(this.thePlugin.settings.minimumRefCountThreshold) - .onChange(async (value) => { - this.thePlugin.settings.minimumRefCountThreshold = value; - await this.thePlugin.saveSettings(); - }) - .setDynamicTooltip() - ) containerEl.createEl("h2", { text: "Cache Tuning" });