Skip to content

Commit

Permalink
Add "Complement automatically" status to the status bar (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadashi-aikawa committed Jun 4, 2022
1 parent 4e5296f commit 7874a09
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main.ts
Expand Up @@ -49,11 +49,15 @@ export default class VariousComponents extends Plugin {
this.statusBar = ProviderStatusBar.new(
this.addStatusBarItem(),
this.settings.showMatchStrategy,
this.settings.showIndexingStatus
this.settings.showIndexingStatus,
this.settings.showComplementAutomatically
);
this.statusBar.setOnClickStrategyListener(async () => {
await this.settingTab.toggleMatchStrategy();
});
this.statusBar.setOnClickComplementAutomatically(async () => {
await this.settingTab.toggleComplementAutomatically();
});

const debouncedSaveData = debounce(async () => {
await this.saveData(this.settings);
Expand Down
16 changes: 16 additions & 0 deletions src/setting/settings.ts
Expand Up @@ -28,6 +28,7 @@ export interface Settings {

// appearance
showMatchStrategy: boolean;
showComplementAutomatically: boolean;
showIndexingStatus: boolean;
descriptionOnSuggestion: string;

Expand Down Expand Up @@ -93,6 +94,7 @@ export const DEFAULT_SETTINGS: Settings = {

// appearance
showMatchStrategy: true,
showComplementAutomatically: true,
showIndexingStatus: true,
descriptionOnSuggestion: "Short",

Expand Down Expand Up @@ -344,6 +346,20 @@ export class VariousComplementsSettingTab extends PluginSettingTab {
);
});

new Setting(containerEl)
.setName("Show Complement automatically")
.setDesc(
"Show complement automatically at the status bar. Changing this option requires a restart to take effect."
)
.addToggle((tc) => {
tc.setValue(this.plugin.settings.showComplementAutomatically).onChange(
async (value) => {
this.plugin.settings.showComplementAutomatically = value;
await this.plugin.saveSettings();
}
);
});

new Setting(containerEl)
.setName("Show Indexing status")
.setDesc(
Expand Down
3 changes: 3 additions & 0 deletions src/ui/AutoCompleteSuggest.ts
Expand Up @@ -308,6 +308,9 @@ export class AutoCompleteSuggest
this.settings = settings;

this.statusBar.setMatchStrategy(this.matchStrategy);
this.statusBar.setComplementAutomatically(
this.settings.complementAutomatically
);

try {
this.tokenizer = await createTokenizer(this.tokenizerStrategy, this.app);
Expand Down
23 changes: 20 additions & 3 deletions src/ui/ProviderStatusBar.ts
Expand Up @@ -7,13 +7,15 @@ export class ProviderStatusBar {
public customDictionary: HTMLElement | null,
public internalLink: HTMLElement | null,
public frontMatter: HTMLElement | null,
public matchStrategy: HTMLElement | null
public matchStrategy: HTMLElement | null,
public complementAutomatically: HTMLElement | null
) {}

static new(
statusBar: HTMLElement,
showMatchStrategy: boolean,
showIndexingStatus: boolean
showIndexingStatus: boolean,
showComplementAutomatically: boolean
): ProviderStatusBar {
const currentFile = showIndexingStatus
? statusBar.createEl("span", {
Expand Down Expand Up @@ -53,19 +55,31 @@ export class ProviderStatusBar {
})
: null;

console.log(showComplementAutomatically);
const complementAutomatically = showComplementAutomatically
? statusBar.createEl("span", {
text: "---",
cls: "various-complements__footer various-complements__footer__complement-automatically",
})
: null;

return new ProviderStatusBar(
currentFile,
currentVault,
customDictionary,
internalLink,
frontMatter,
matchStrategy
matchStrategy,
complementAutomatically
);
}

setOnClickStrategyListener(listener: () => void) {
this.matchStrategy?.addEventListener("click", listener);
}
setOnClickComplementAutomatically(listener: () => void) {
this.complementAutomatically?.addEventListener("click", listener);
}

setCurrentFileDisabled() {
this.currentFile?.setText("---");
Expand Down Expand Up @@ -118,4 +132,7 @@ export class ProviderStatusBar {
setMatchStrategy(strategy: MatchStrategy) {
this.matchStrategy?.setText(strategy.name);
}
setComplementAutomatically(automatically: boolean) {
this.complementAutomatically?.setText(automatically ? "auto" : "manual");
}
}
6 changes: 6 additions & 0 deletions styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7874a09

Please sign in to comment.