From 7bca8262f4a49e2212ba3cf9cc4877f08c43a840 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Sat, 1 Mar 2025 17:05:09 +0100 Subject: [PATCH] Add settings to hide button to open conflicts view --- src/main.ts | 55 +++++++++++++++++++++++++++++++--------- src/settings/settings.ts | 2 ++ src/settings/tab.ts | 19 +++++++++++++- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index a6a750e..cc8e720 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,8 @@ export default class GitHubSyncPlugin extends Plugin { logger: Logger; statusBarItem: HTMLElement | null = null; - uploadModifiedFilesRibbonIcon: HTMLElement | null = null; + syncRibbonIcon: HTMLElement | null = null; + conflictsRibbonIcon: HTMLElement | null = null; activeLeafChangeListener: EventRef | null = null; vaultCreateListener: EventRef | null = null; @@ -80,16 +81,13 @@ export default class GitHubSyncPlugin extends Plugin { async onload() { await this.loadSettings(); + this.logger = new Logger(this.app.vault, this.settings.enableLogging); + this.logger.init(); + this.registerView( CONFLICTS_RESOLUTION_VIEW_TYPE, (leaf) => new ConflictsResolutionView(leaf, this, this.conflicts), ); - this.addRibbonIcon("merge", "Open sync conflicts resolution", async () => { - await this.activateView(); - this.getConflictsView()?.setConflictFiles(this.conflicts); - }); - this.logger = new Logger(this.app.vault, this.settings.enableLogging); - this.logger.init(); this.addSettingTab(new GitHubSyncSettingsTab(this.app, this)); @@ -118,6 +116,10 @@ export default class GitHubSyncPlugin extends Plugin { this.showStatusBarItem(); } + if (this.settings.showConflictsRibbonButton) { + this.showConflictsRibbonIcon(); + } + if (this.settings.showSyncRibbonButton) { this.showSyncRibbonIcon(); } @@ -130,6 +132,14 @@ export default class GitHubSyncPlugin extends Plugin { icon: "refresh-cw", callback: this.sync.bind(this), }); + + this.addCommand({ + id: "merge", + name: "Open sync conflicts view", + repeatable: false, + icon: "refresh-cw", + callback: this.openConflictsView.bind(this), + }); } async sync() { @@ -208,19 +218,40 @@ export default class GitHubSyncPlugin extends Plugin { } showSyncRibbonIcon() { - if (this.uploadModifiedFilesRibbonIcon) { + if (this.syncRibbonIcon) { return; } - this.uploadModifiedFilesRibbonIcon = this.addRibbonIcon( + this.syncRibbonIcon = this.addRibbonIcon( "refresh-cw", "Sync with GitHub", this.sync.bind(this), ); } - hideUploadModifiedFilesRibbonIcon() { - this.uploadModifiedFilesRibbonIcon?.remove(); - this.uploadModifiedFilesRibbonIcon = null; + hideSyncRibbonIcon() { + this.syncRibbonIcon?.remove(); + this.syncRibbonIcon = null; + } + + showConflictsRibbonIcon() { + if (this.conflictsRibbonIcon) { + return; + } + this.conflictsRibbonIcon = this.addRibbonIcon( + "merge", + "Open sync conflicts view", + this.openConflictsView.bind(this), + ); + } + + hideConflictsRibbonIcon() { + this.conflictsRibbonIcon?.remove(); + this.conflictsRibbonIcon = null; + } + + async openConflictsView() { + await this.activateView(); + this.getConflictsView()?.setConflictFiles(this.conflicts); } async onConflicts(conflicts: ConflictFile[]): Promise { diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 97dba70..e1da5d5 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -11,6 +11,7 @@ export interface GitHubSyncSettings { conflictHandling: "ignore" | "ask" | "overwrite"; showStatusBarItem: boolean; showSyncRibbonButton: boolean; + showConflictsRibbonButton: boolean; enableLogging: boolean; } @@ -27,5 +28,6 @@ export const DEFAULT_SETTINGS: GitHubSyncSettings = { conflictHandling: "overwrite", showStatusBarItem: true, showSyncRibbonButton: true, + showConflictsRibbonButton: true, enableLogging: true, }; diff --git a/src/settings/tab.ts b/src/settings/tab.ts index 031619e..da4ca76 100644 --- a/src/settings/tab.ts +++ b/src/settings/tab.ts @@ -211,7 +211,24 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab { if (value) { this.plugin.showSyncRibbonIcon(); } else { - this.plugin.hideUploadModifiedFilesRibbonIcon(); + this.plugin.hideSyncRibbonIcon(); + } + }); + }); + + new Setting(containerEl) + .setName("Show conflicts view button") + .setDesc("Displays a ribbon button that opens the conflicts view") + .addToggle((toggle) => { + toggle + .setValue(this.plugin.settings.showConflictsRibbonButton) + .onChange((value) => { + this.plugin.settings.showConflictsRibbonButton = value; + this.plugin.saveSettings(); + if (value) { + this.plugin.showConflictsRibbonIcon(); + } else { + this.plugin.hideConflictsRibbonIcon(); } }); });