Skip to content

Commit

Permalink
feat: add command to copy workspace URI
Browse files Browse the repository at this point in the history
close #42
  • Loading branch information
Vinzent03 committed Jul 7, 2024
1 parent 1d594b7 commit 31a61b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
getFileUri,
getViewStateFromMode,
} from "./utils";
import { WorkspaceModal } from "./modals/workspace_modal";

export default class AdvancedURI extends Plugin {
settings: AdvancedURISettings;
Expand Down Expand Up @@ -122,6 +123,15 @@ export default class AdvancedURI extends Plugin {
},
});

this.addCommand({
id: "copy-uri-workspace",
name: "Copy URI for workspace",
callback: () => {
const modal = new WorkspaceModal(this);
modal.open();
},
});

this.registerObsidianProtocolHandler("advanced-uri", async (e) => {
const parameters = e as unknown as Parameters;

Expand Down
29 changes: 29 additions & 0 deletions src/modals/workspace_modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FuzzySuggestModal, Notice } from "obsidian";
import AdvancedURI from "../main";

export class WorkspaceModal extends FuzzySuggestModal<string> {
plugin: AdvancedURI;
constructor(plugin: AdvancedURI) {
super(plugin.app);
this.plugin = plugin;
this.setPlaceholder("Choose a workspace");
}

getItems(): string[] {
const workspacesPlugin =
this.app.internalPlugins.getEnabledPluginById("workspaces");
if (!workspacesPlugin) {
new Notice("Workspaces plugin is not enabled");
} else {
return Object.keys(workspacesPlugin.workspaces);
}
}

getItemText(item: string): string {
return item;
}

onChooseItem(item: string, _: MouseEvent | KeyboardEvent): void {
this.plugin.tools.copyURI({ workspace: item });
}
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare module "obsidian" {
} | null;
getEnabledPluginById(plugin: "workspaces"): {
activeWorkspace: Workspace;
workspaces: { [key: string]: any };
saveWorkspace(workspace: Workspace): void;
loadWorkspace(workspace: string): void;
} | null;
Expand Down

0 comments on commit 31a61b9

Please sign in to comment.