modal
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
import { NoteSharingService } from "src/NoteSharingService";
|
import { NoteSharingService } from "src/NoteSharingService";
|
||||||
import { DEFAULT_SETTINGS, PluginSettings } from "src/obsidian/PluginSettings";
|
import { DEFAULT_SETTINGS, PluginSettings } from "src/obsidian/PluginSettings";
|
||||||
import SettingsTab from "src/obsidian/SettingsTab";
|
import SettingsTab from "src/obsidian/SettingsTab";
|
||||||
|
import { SharedNoteSuccessModal } from "src/ui/SharedNoteSuccessModal";
|
||||||
|
|
||||||
// Remember to rename these classes and interfaces!
|
// Remember to rename these classes and interfaces!
|
||||||
|
|
||||||
@@ -27,18 +28,7 @@ export default class NoteSharingPlugin extends Plugin {
|
|||||||
this.addSettingTab(new SettingsTab(this.app, this));
|
this.addSettingTab(new SettingsTab(this.app, this));
|
||||||
|
|
||||||
// Add note sharing command
|
// Add note sharing command
|
||||||
this.addCommand({
|
this.addCommands();
|
||||||
id: "obsidian-note-sharing-share-note",
|
|
||||||
name: "Create share link",
|
|
||||||
checkCallback: (checking: boolean) => {
|
|
||||||
// Only works on Markdown views
|
|
||||||
const activeView =
|
|
||||||
this.app.workspace.getActiveViewOfType(MarkdownView);
|
|
||||||
if (!activeView) return false;
|
|
||||||
if (checking) return true;
|
|
||||||
this.noteSharingService.shareNote(activeView.getViewData());
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.eventRef = this.app.workspace.on(
|
this.eventRef = this.app.workspace.on(
|
||||||
"file-menu",
|
"file-menu",
|
||||||
@@ -62,6 +52,21 @@ export default class NoteSharingPlugin extends Plugin {
|
|||||||
this.noteSharingService.serverUrl = this.settings.serverUrl;
|
this.noteSharingService.serverUrl = this.settings.serverUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addCommands() {
|
||||||
|
this.addCommand({
|
||||||
|
id: "obsidian-note-sharing-share-note",
|
||||||
|
name: "Create share link",
|
||||||
|
checkCallback: (checking: boolean) => {
|
||||||
|
// Only works on Markdown views
|
||||||
|
const activeView =
|
||||||
|
this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||||
|
if (!activeView) return false;
|
||||||
|
if (checking) return true;
|
||||||
|
this.shareNote(activeView.getViewData());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.dev/platers/obsidian-linter/blob/c30ceb17dcf2c003ca97862d94cbb0fd47b83d52/src/main.ts#L139-L149
|
// https://github.dev/platers/obsidian-linter/blob/c30ceb17dcf2c003ca97862d94cbb0fd47b83d52/src/main.ts#L139-L149
|
||||||
onMenuOpenCallback(menu: Menu, file: TAbstractFile, source: string) {
|
onMenuOpenCallback(menu: Menu, file: TAbstractFile, source: string) {
|
||||||
if (file instanceof TFile && file.extension === "md") {
|
if (file instanceof TFile && file.extension === "md") {
|
||||||
@@ -69,11 +74,14 @@ export default class NoteSharingPlugin extends Plugin {
|
|||||||
item.setIcon("paper-plane-glyph");
|
item.setIcon("paper-plane-glyph");
|
||||||
item.setTitle("Share note");
|
item.setTitle("Share note");
|
||||||
item.onClick(async (evt) => {
|
item.onClick(async (evt) => {
|
||||||
this.noteSharingService.shareNote(
|
this.shareNote(await this.app.vault.read(file));
|
||||||
await this.app.vault.read(file)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async shareNote(mdText: string) {
|
||||||
|
const url = await this.noteSharingService.shareNote(mdText);
|
||||||
|
new SharedNoteSuccessModal(this, url).open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class NoteSharingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mdView Markdown file to share.
|
* @param mdText Markdown file to share.
|
||||||
* @returns link to shared note with attached decryption key.
|
* @returns link to shared note with attached decryption key.
|
||||||
*/
|
*/
|
||||||
public async shareNote(mdText: string): Promise<string> {
|
public async shareNote(mdText: string): Promise<string> {
|
||||||
|
|||||||
18
plugin/src/ui/SharedNoteSuccessModal.ts
Normal file
18
plugin/src/ui/SharedNoteSuccessModal.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import NoteSharingPlugin from "main";
|
||||||
|
import { Modal, TextComponent } from "obsidian";
|
||||||
|
|
||||||
|
export class SharedNoteSuccessModal extends Modal {
|
||||||
|
private url: string;
|
||||||
|
|
||||||
|
constructor(plugin: NoteSharingPlugin, url: string) {
|
||||||
|
super(plugin.app);
|
||||||
|
this.url = url;
|
||||||
|
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
this.titleEl.innerText = "Shared note";
|
||||||
|
new TextComponent(this.contentEl).setValue(this.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user