Skip to content

Commit

Permalink
Added maxFileCountToDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
TfT Hacker committed Nov 18, 2022
1 parent dfdbf9b commit 4de3bec
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vscode
.vscode
TODONOTES.md

# Intellij
*.iml
Expand Down Expand Up @@ -29,4 +30,5 @@ build
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Thumbs.db

2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/uic-ref--parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
17 changes: 15 additions & 2 deletions src/ui/components/uic-ref-area.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
*
Expand All @@ -17,7 +24,7 @@ export /**
* @param {boolean} isHoverView
* @return {*} {Promise<string>}
*/
const getUIC_Ref_Area = async (refType: string, key: string, filePath: string, lineNu: number, isHoverView:boolean, thePlugin: SNWPlugin): Promise<HTMLElement> => {
const getUIC_Ref_Area = async (refType: string, key: string, filePath: string, lineNu: number, isHoverView:boolean): Promise<HTMLElement> => {
const refAreaItems = await getRefAreaItems(refType, key, filePath);
const refAreaContainerEl = createDiv();

Expand Down Expand Up @@ -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");
Expand Down
49 changes: 34 additions & 15 deletions src/ui/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ export const DEFAULT_SETTINGS: Settings = {
enableOnStartupDesktop: true,
enableOnStartupMobile: true,
minimumRefCountThreshold: 1,
maxFileCountToDisplay: 50,
displayIncomingFilesheader: true,
displayInlineReferencesLivePreview: true,
displayInlineReferencesMarkdown: true,
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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" });

Expand Down

0 comments on commit 4de3bec

Please sign in to comment.