Skip to content

Commit

Permalink
feat: use elmessage for contextmenu action
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Feb 25, 2025
1 parent 9dc7efb commit 847d636
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
4 changes: 2 additions & 2 deletions plugins/oeyoews/vue-contextmenu/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"title": "$:/plugins/oeyoews/vue-contextmenu",
"description": "TiddlyWiki contextmenu plugin by Vue3",
"author": "oeyoews",
"version": "0.0.1",
"version": "0.1.0",
"core-version": ">=5.3.0",
"type": "application/json",
"plugin-type": "plugin",
"name": "vue-contextmenu",
"meat#disabled": "yes",
"qrcode": "yes",
"created": "2024-03-19",
"created": "20240319",
"dependents": [
"$:/plugins/oeyoews/neotw-vue3",
"$:/plugins/oeyoews/tiddlywiki-tailwindcss-plus",
Expand Down
57 changes: 50 additions & 7 deletions plugins/oeyoews/vue-contextmenu/tiddlers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module-type: library

const { h, ref, reactive } = window.Vue;

const { ElMessage } = require('element-plus.min.js');
const getTemplate = require('$:/plugins/oeyoews/neotw-vue3/getTemplate.js');
// const allTags = Object.keys($tw.wiki.getTagMap()).filter(
// (t) => !t.startsWith('$:/'),
Expand Down Expand Up @@ -70,6 +71,10 @@ const app = (target, title, self) => {
handleConfirm() {
this.dialogVisible = false;
$tw.wiki.setText(title, 'tags', null, this.tags);
ElMessage({
type: 'success',
message: 'Tags updated',
});
},
getTags(title) {
if (!title) {
Expand All @@ -80,11 +85,12 @@ const app = (target, title, self) => {
let tags = tiddler ? tiddler : []; // 使用逗号分隔, 不考虑tag 本身包含逗号的情况
return tags;
},
operation(type, param) {
operation(type, param, callback) {
self.dispatchEvent({
type,
param,
});
typeof callback === 'function' && callback();
},

getStoryList() {
Expand Down Expand Up @@ -140,7 +146,13 @@ const app = (target, title, self) => {
label: t('menu.close2'),
icon: getIcon('close2'),
disabled: this.getStoryList().length === 1 ? true : false,
onClick: () => o('tm-close-other-tiddlers', title),
onClick: () =>
o('tm-close-other-tiddlers', title, () => {
ElMessage({
type: 'success',
message: 'Close other tiddlers successfully',
});
}),
divided: true,
},
{
Expand All @@ -154,15 +166,27 @@ const app = (target, title, self) => {
label: t('menu.copy'),
icon: h(Icon, { icon: icons.copy }),
onClick: () => {
$tw.utils.copyToClipboard(title);
$tw.utils.copyToClipboard(title, {
doNotNotify: true,
});
ElMessage({
type: 'success',
message: 'Copy tiddler title successfully',
});
},
},
{
label: t('menu.copy2'),
icon: getIcon('copy2'),
onClick: () => {
const text = $tw.wiki.getTiddlerText(title);
$tw.utils.copyToClipboard(text);
$tw.utils.copyToClipboard(text, {
doNotNotify: true,
});
ElMessage({
type: 'success',
message: 'Copy tiddler text successfully',
});
},
},
],
Expand All @@ -173,12 +197,19 @@ const app = (target, title, self) => {
onClick: () => {
const foldPrefix = '$:/state/folded/';
$tw.wiki.setText(foldPrefix + title, 'text', null, 'hide');
ElMessage({ type: 'success', message: 'Fold successfully' });
},
},
{
label: t('menu.delete'),
icon: getIcon('delete'),
onClick: () => o('tm-delete-tiddler', title),
onClick: () =>
o('tm-delete-tiddler', title, () => {
ElMessage({
type: 'success',
message: 'Delete successfully',
});
}),
},
{
label: t('menu.newWindow'),
Expand All @@ -191,9 +222,15 @@ const app = (target, title, self) => {
onClick: async () => {
const to = window.prompt('Rename to:', title);
// const to = await $tw.showDialog('prompt', 'rename', title);
if (to) {
if (to && to !== title) {
// o('tm-rename-tiddler', title, '99');
$tw.wiki.renameTiddler(title, to);
ElMessage({ type: 'success', message: `Rename successfully` });
} else {
ElMessage({
type: 'info',
message: 'Rename canceled',
});
}
},
},
Expand All @@ -205,7 +242,13 @@ const app = (target, title, self) => {
{
label: t('menu.permalink'),
icon: getIcon('link'),
onClick: () => o('tm-permalink', title),
onClick: () =>
o('tm-permalink', title, () => {
// ElMessage({
// type: 'success',
// message: 'Copy permalink successfully',
// });
}),
},
];

Expand Down
1 change: 0 additions & 1 deletion plugins/oeyoews/vue-contextmenu/tiddlers/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class ExampleWidget extends Widget {
try {
const app = createApp(component(parent, title, this));

app.use(TiddlyWikiVue);
app.use(ContextMenu);
app.use(i18n);
app.use(ElementPlus);
Expand Down

0 comments on commit 847d636

Please sign in to comment.