Skip to content

Commit

Permalink
feat: add delete repo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Aug 13, 2022
1 parent 6195ce3 commit 26cdfb8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,25 @@ export default class ObsidianGit extends Plugin {
callback: async () => this.removeRemote()
});

this.addCommand({
id: "delete-repo",
name: "CAUTION: Delete repository",
callback: async () => {
const repoExists = await this.app.vault.adapter.exists(`${this.settings.basePath}/.git`);
if (repoExists) {
const modal = new GeneralModal(this.app, ["NO", "YES"], "Do you really want to delete the repository? This action cannot be undone.", false, true);
const shouldDelete = await modal.open() === "YES";
if (shouldDelete) {
await this.app.vault.adapter.rmdir(`${this.settings.basePath}/.git`, true);
new Notice("Successfully deleted repository. Please reload the plugin");

}
} else {
new Notice("No repository found");
}
}
});

this.addCommand({
id: "init-repo",
name: "Initialize a new repo",
Expand Down
10 changes: 6 additions & 4 deletions src/ui/modals/generalModal.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { App, SuggestModal } from "obsidian";

export class GeneralModal extends SuggestModal<string> {
list: string[];
resolve: ((value: string | PromiseLike<string>) => void) | null = null;


constructor(app: App, remotes: string[], placeholder: string, private allowEmpty = false) {
constructor(app: App, private options: string[], placeholder: string, private allowEmpty = false, private onlySelection: boolean = false) {
super(app);
this.list = remotes;
this.setPlaceholder(placeholder);
}

Expand All @@ -28,7 +26,11 @@ export class GeneralModal extends SuggestModal<string> {
}

getSuggestions(query: string): string[] {
return [(this.allowEmpty || query.length > 0) ? query : "...", ...this.list];
if (this.onlySelection) {
return this.options;
} else {
return [(this.allowEmpty || query.length > 0) ? query : "...", ...this.options];
}
}

renderSuggestion(value: string, el: HTMLElement): void {
Expand Down

0 comments on commit 26cdfb8

Please sign in to comment.