|
1 | 1 | import { spawnSync } from "child_process";
|
2 |
| -import { FileSystemAdapter, Notice, Plugin, PluginSettingTab, Setting, SuggestModal } from "obsidian"; |
| 2 | +import { FileSystemAdapter, FuzzySuggestModal, Notice, Plugin, PluginSettingTab, Setting, SuggestModal } from "obsidian"; |
3 | 3 | import simpleGit, { FileStatusResult, SimpleGit } from "simple-git";
|
4 | 4 |
|
5 | 5 | enum PluginState {
|
@@ -68,6 +68,15 @@ export default class ObsidianGit extends Plugin {
|
68 | 68 | callback: () => new CustomMessageModal(this).open()
|
69 | 69 | });
|
70 | 70 |
|
| 71 | + this.addCommand({ |
| 72 | + id: "list-changed-files", |
| 73 | + name: "List changed files", |
| 74 | + callback: async () => { |
| 75 | + const status = await this.git.status(); |
| 76 | + new ChangedFilesModal(this, status.files).open(); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
71 | 80 | this.init();
|
72 | 81 |
|
73 | 82 | // init statusBar
|
@@ -596,3 +605,41 @@ class CustomMessageModal extends SuggestModal<string> {
|
596 | 605 | }
|
597 | 606 |
|
598 | 607 | }
|
| 608 | +class ChangedFilesModal extends FuzzySuggestModal<FileStatusResult> { |
| 609 | + plugin: ObsidianGit; |
| 610 | + changedFiles: FileStatusResult[]; |
| 611 | + |
| 612 | + constructor(plugin: ObsidianGit, changedFiles: FileStatusResult[]) { |
| 613 | + super(plugin.app); |
| 614 | + this.plugin = plugin; |
| 615 | + this.changedFiles = changedFiles; |
| 616 | + console.log(changedFiles); |
| 617 | + this.setPlaceholder("Only files in vault can be openend!"); |
| 618 | + } |
| 619 | + |
| 620 | + getItems(): FileStatusResult[] { |
| 621 | + return this.changedFiles; |
| 622 | + } |
| 623 | + |
| 624 | + getItemText(item: FileStatusResult): string { |
| 625 | + if (item.index == "?" && item.working_dir == "?") { |
| 626 | + return `Untracked | ${item.path}`; |
| 627 | + } |
| 628 | + |
| 629 | + let working_dir = ""; |
| 630 | + let index = ""; |
| 631 | + |
| 632 | + if (item.working_dir != " ") working_dir = `Working dir: ${item.working_dir} `; |
| 633 | + if (item.index != " ") index = `Index: ${item.index}`; |
| 634 | + |
| 635 | + return `${working_dir}${index} | ${item.path}`; |
| 636 | + } |
| 637 | + |
| 638 | + onChooseItem(item: FileStatusResult, _: MouseEvent | KeyboardEvent): void { |
| 639 | + if (this.plugin.app.metadataCache.getFirstLinkpathDest(item.path, "") == null) { |
| 640 | + new Notice("Can't open file in Obsidian"); |
| 641 | + } else { |
| 642 | + this.plugin.app.workspace.openLinkText(item.path, "/"); |
| 643 | + } |
| 644 | + } |
| 645 | +} |
0 commit comments