mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Add settings to hide button to open conflicts view
This commit is contained in:
parent
fc890b5d95
commit
7bca8262f4
3 changed files with 63 additions and 13 deletions
55
src/main.ts
55
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<ConflictResolution[]> {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue