mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 12:10:28 +00:00
Add settings for ribbon icons
This commit is contained in:
parent
b23c2a1868
commit
09e8317007
3 changed files with 149 additions and 9 deletions
83
src/main.ts
83
src/main.ts
|
|
@ -15,12 +15,28 @@ export default class GitHubSyncPlugin extends Plugin {
|
|||
eventsConsumer: EventsConsumer;
|
||||
syncIntervalId: number | null = null;
|
||||
|
||||
downloadAllRibbonIcon: HTMLElement | null = null;
|
||||
uploadModifiedFilesRibbonIcon: HTMLElement | null = null;
|
||||
uploadAllFilesRibbonIcon: HTMLElement | null = null;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
await this.loadMetadata();
|
||||
|
||||
this.addSettingTab(new GitHubSyncSettingsTab(this.app, this));
|
||||
|
||||
if (this.settings.showDownloadRibbonButton) {
|
||||
this.showDownloadAllRibbonIcon();
|
||||
}
|
||||
|
||||
if (this.settings.showUploadModifiedFilesRibbonButton) {
|
||||
this.showUploadModifiedFilesRibbonIcon();
|
||||
}
|
||||
|
||||
if (this.settings.showUploadAllFilesRibbonButton) {
|
||||
this.showUploadAllFilesRibbonIcon();
|
||||
}
|
||||
|
||||
this.client = new GithubClient(
|
||||
this.app.vault,
|
||||
this.metadataStore,
|
||||
|
|
@ -51,15 +67,6 @@ export default class GitHubSyncPlugin extends Plugin {
|
|||
// callback: () => {},
|
||||
// });
|
||||
|
||||
this.addRibbonIcon("arrow-down-from-line", "Download all", async () => {
|
||||
await this.client.downloadRepoContent(
|
||||
this.settings.githubOwner,
|
||||
this.settings.githubRepo,
|
||||
this.settings.repoContentDir,
|
||||
this.settings.githubBranch,
|
||||
this.settings.localContentDir,
|
||||
);
|
||||
});
|
||||
// this.addRibbonIcon("arrow-up-from-line", "Upload all", async () => {
|
||||
// const activeFile = this.app.workspace.getActiveFile();
|
||||
// if (!activeFile) {
|
||||
|
|
@ -147,6 +154,64 @@ export default class GitHubSyncPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
showDownloadAllRibbonIcon() {
|
||||
if (this.downloadAllRibbonIcon) {
|
||||
return;
|
||||
}
|
||||
this.downloadAllRibbonIcon = this.addRibbonIcon(
|
||||
"arrow-down-from-line",
|
||||
"Download all files from GitHub",
|
||||
async () => {
|
||||
await this.client.downloadRepoContent(
|
||||
this.settings.githubOwner,
|
||||
this.settings.githubRepo,
|
||||
this.settings.repoContentDir,
|
||||
this.settings.githubBranch,
|
||||
this.settings.localContentDir,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
hideDownloadAllRibbonIcon() {
|
||||
this.downloadAllRibbonIcon?.remove();
|
||||
this.downloadAllRibbonIcon = null;
|
||||
}
|
||||
|
||||
showUploadModifiedFilesRibbonIcon() {
|
||||
if (this.uploadModifiedFilesRibbonIcon) {
|
||||
return;
|
||||
}
|
||||
this.uploadModifiedFilesRibbonIcon = this.addRibbonIcon(
|
||||
"arrow-up",
|
||||
"Upload modified files to GitHub",
|
||||
async () => this.syncModifiedFiles(),
|
||||
);
|
||||
}
|
||||
|
||||
hideUploadModifiedFilesRibbonIcon() {
|
||||
this.uploadModifiedFilesRibbonIcon?.remove();
|
||||
this.uploadModifiedFilesRibbonIcon = null;
|
||||
}
|
||||
|
||||
showUploadAllFilesRibbonIcon() {
|
||||
if (this.uploadAllFilesRibbonIcon) {
|
||||
return;
|
||||
}
|
||||
this.uploadAllFilesRibbonIcon = this.addRibbonIcon(
|
||||
"arrow-up-from-line",
|
||||
"Upload all files to GitHub",
|
||||
async () => {
|
||||
// TODO
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
hideUploadAllFilesRibbonIcon() {
|
||||
this.uploadAllFilesRibbonIcon?.remove();
|
||||
this.uploadAllFilesRibbonIcon = null;
|
||||
}
|
||||
|
||||
private async loadMetadata() {
|
||||
this.metadataStore = new MetadataStore(this.app.vault);
|
||||
await this.metadataStore.load();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ export interface GitHubSyncSettings {
|
|||
localContentDir: string;
|
||||
syncStrategy: "manual" | "interval";
|
||||
syncInterval: number;
|
||||
showStatusBarItem: boolean;
|
||||
showDownloadRibbonButton: boolean;
|
||||
showUploadModifiedFilesRibbonButton: boolean;
|
||||
showUploadAllFilesRibbonButton: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: GitHubSyncSettings = {
|
||||
|
|
@ -18,4 +22,8 @@ export const DEFAULT_SETTINGS: GitHubSyncSettings = {
|
|||
localContentDir: "",
|
||||
syncStrategy: "manual",
|
||||
syncInterval: 1,
|
||||
showStatusBarItem: true,
|
||||
showDownloadRibbonButton: true,
|
||||
showUploadModifiedFilesRibbonButton: true,
|
||||
showUploadAllFilesRibbonButton: true,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -166,5 +166,72 @@ export default class GitHubSyncSettingsTab extends PluginSettingTab {
|
|||
}
|
||||
}),
|
||||
);
|
||||
|
||||
containerEl.createEl("h2", { text: "Interface" });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Show status bar item")
|
||||
.setDesc("Displays the status bar item that show the file synnc status")
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showStatusBarItem)
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.showStatusBarItem = value;
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Show download all files button")
|
||||
.setDesc(
|
||||
"Displays a ribbon button to download all files from the remote repository",
|
||||
)
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showDownloadRibbonButton)
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.showDownloadRibbonButton = value;
|
||||
this.plugin.saveSettings();
|
||||
if (value) {
|
||||
this.plugin.showDownloadAllRibbonIcon();
|
||||
} else {
|
||||
this.plugin.hideDownloadAllRibbonIcon();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Show upload modified files button")
|
||||
.setDesc("Displays a ribbon button to upload modified files")
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showUploadModifiedFilesRibbonButton)
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.showUploadModifiedFilesRibbonButton = value;
|
||||
this.plugin.saveSettings();
|
||||
if (value) {
|
||||
this.plugin.showUploadModifiedFilesRibbonIcon();
|
||||
} else {
|
||||
this.plugin.hideUploadModifiedFilesRibbonIcon();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Show upload modified files button")
|
||||
.setDesc("Displays a ribbon button to upload all files")
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.plugin.settings.showUploadAllFilesRibbonButton)
|
||||
.onChange((value) => {
|
||||
this.plugin.settings.showUploadAllFilesRibbonButton = value;
|
||||
this.plugin.saveSettings();
|
||||
if (value) {
|
||||
this.plugin.showUploadAllFilesRibbonIcon();
|
||||
} else {
|
||||
this.plugin.hideUploadAllFilesRibbonIcon();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue