mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
add button to display the command in the command palette
This commit is contained in:
@@ -4,28 +4,20 @@ import {FuzzySuggester, DatabaseList} from "./FuzzySuggester";
|
||||
import {uploadCommandGeneral, uploadCommandNext} from "../upload/uploadCommand";
|
||||
import ObsidianSyncNotionPlugin from "src/main";
|
||||
|
||||
|
||||
interface Command {
|
||||
id: string;
|
||||
name: string;
|
||||
editorCallback: (editor: Editor, view: MarkdownView) => Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
// create the commands list
|
||||
export default class RibbonCommands {
|
||||
plugin: ObsidianSyncNotionPlugin;
|
||||
|
||||
// Total commands that will be used
|
||||
Ncommand = [
|
||||
{
|
||||
id: "share-to-notionnext",
|
||||
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
// await this.plugin.uploadCommand()
|
||||
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app)
|
||||
}
|
||||
},
|
||||
{
|
||||
id: "share-to-notion",
|
||||
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
Ncommand: Command[] = [];
|
||||
|
||||
async ribbonDisplay() {
|
||||
const NcommandList: DatabaseList[] = [];
|
||||
@@ -46,6 +38,28 @@ export default class RibbonCommands {
|
||||
constructor(plugin: ObsidianSyncNotionPlugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
// Check if NextButton is true, then include the corresponding command
|
||||
if (this.plugin.settings.NextButton) {
|
||||
this.Ncommand.push({
|
||||
id: "share-to-notionnext",
|
||||
name: i18nConfig.CommandName, // Use the translated text from i18nConfig
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check if GeneralButton is true, then include the corresponding command
|
||||
if (this.plugin.settings.GeneralButton) {
|
||||
this.Ncommand.push({
|
||||
id: "share-to-notion",
|
||||
name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig
|
||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||
await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Register all the commands
|
||||
this.Ncommand.forEach(command => {
|
||||
this.plugin.addCommand(
|
||||
|
||||
@@ -6,9 +6,8 @@ export const I18n: { [key: string]: any } = {
|
||||
CommandName: "Share to NotionNext Database",
|
||||
CommandIDGeneral: "share-to-notion",
|
||||
CommandNameGeneral: "Share to Notion General Database",
|
||||
NotionNextVersion: "NotionNext Version Database",
|
||||
NotionNextVersionDesc:
|
||||
"Turn on this option if you are using NotionNext",
|
||||
NotionNextButton: "NotionNext command switch",
|
||||
NotionNextButtonDesc: "Open this option, Sync to NotionNext command will be displayed in the command palette",
|
||||
NotionNextSettingHeader: "NotionNext Database Settings",
|
||||
NotionAPI: "Notion API Token",
|
||||
NotionAPIDesc: "It's a secret",
|
||||
@@ -24,7 +23,9 @@ export const I18n: { [key: string]: any } = {
|
||||
"Your notion ID (optional),share link likes:https://username.notion.site/,your notion id is [username]",
|
||||
NotionUserText: "Enter your notion ID (options)",
|
||||
NotionGeneralSettingHeader: "General Notion Database Settings",
|
||||
NotYetFinish:
|
||||
NotionGeneralButton: "Notion General command switch",
|
||||
NotionGeneralButtonDesc: "Open this option, Sync to Notion General Database command will be displayed in the command palette",
|
||||
NotYetFinish:
|
||||
"Not finished. This function will be available in the next version",
|
||||
PlaceHolder: "Enter database Name",
|
||||
"notion-logo": "Share to NotionNext",
|
||||
@@ -41,6 +42,9 @@ export const I18n: { [key: string]: any } = {
|
||||
"The 'NNon' property is missing in the settings. Please set it up.",
|
||||
"set-api-id":
|
||||
"Please set up the notion API and database ID in the settings tab.",
|
||||
NotionCustomSettingHeader: "Notion Custom Database Settings",
|
||||
NotionCustomButton: "Notion Customised command switch",
|
||||
NotionCustomButtonDesc: "Open this option, Sync to Notion Customised Database command will be displayed in the command palette",
|
||||
},
|
||||
zh: {
|
||||
ribbonIcon: "分享到 NotionNext",
|
||||
@@ -49,8 +53,8 @@ export const I18n: { [key: string]: any } = {
|
||||
CommandName: "分享到 NotionNext",
|
||||
CommandIDGeneral: "share-to-notion",
|
||||
CommandNameGeneral: "分享到 Notion 普通数据库",
|
||||
NotionNextVersion: "NotionNext 版本数据库",
|
||||
NotionNextVersionDesc: "如果你使用的是NotionNext,请打开此选项",
|
||||
NotionNextButton: "NotionNext 同步命令开关",
|
||||
NotionNextButtonDesc: "打开此选项,NotionNext 同步将显示在命令面板中",
|
||||
NotionNextSettingHeader: "NotionNext 数据库参数设置",
|
||||
NotionAPI: "Notion API 令牌",
|
||||
NotionAPIDesc: "显示为密码",
|
||||
@@ -66,6 +70,8 @@ export const I18n: { [key: string]: any } = {
|
||||
"你的 Notion ID(可选),分享链接类似:https://username.notion.site/,你的 Notion ID 是 [username]",
|
||||
NotionUserText: "输入你的 Notion ID(可选)",
|
||||
NotionGeneralSettingHeader: "普通 Notion 数据库设置",
|
||||
NotionGeneralButton: "普通数据库同步命令开关",
|
||||
NotionGeneralButtonDesc: "打开此选项,同步到普通数据库命令将显示在命令面板中",
|
||||
NotYetFinish: "未完成。此功能将在之后版本中提供",
|
||||
PlaceHolder: "输入数据库名称",
|
||||
"notion-logo": "分享到NotionNext",
|
||||
@@ -78,6 +84,9 @@ export const I18n: { [key: string]: any } = {
|
||||
"设置标签失败,请检查文件的frontmatter,或者在插件设置中关闭设置tags开关",
|
||||
NNonMissing: "未设置'NNon'属性,请在插件设置中选择NotionNext数据库。",
|
||||
"set-api-id": "请在插件设置中设置notion API和database ID",
|
||||
NotionCustomSettingHeader: "Notion 自定义数据库设置",
|
||||
NotionCustomButton: "Notion 自定义数据库同步命令开关",
|
||||
NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
0
src/ui/addButton.ts
Normal file
0
src/ui/addButton.ts
Normal file
@@ -3,25 +3,33 @@ import {i18nConfig} from "../lang/I18n";
|
||||
import ObsidianSyncNotionPlugin from "../main";
|
||||
|
||||
export interface PluginSettings {
|
||||
NNon: boolean;
|
||||
NextButton: boolean;
|
||||
notionAPINext: string;
|
||||
databaseIDNext: string;
|
||||
bannerUrl: string;
|
||||
notionUser: string;
|
||||
proxy: string;
|
||||
GeneralButton: boolean;
|
||||
notionAPIGeneral: string;
|
||||
databaseIDGeneral: string;
|
||||
CustomButton: boolean;
|
||||
notionAPICustom: string;
|
||||
databaseIDCustom: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: PluginSettings = {
|
||||
NNon: undefined,
|
||||
NextButton: true,
|
||||
notionAPINext: "",
|
||||
databaseIDNext: "",
|
||||
bannerUrl: "",
|
||||
notionUser: "",
|
||||
proxy: "",
|
||||
GeneralButton: true,
|
||||
notionAPIGeneral: "",
|
||||
databaseIDGeneral: "",
|
||||
CustomButton: false,
|
||||
notionAPICustom: "",
|
||||
databaseIDCustom: "",
|
||||
};
|
||||
|
||||
|
||||
@@ -40,17 +48,17 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
||||
|
||||
containerEl.createEl('h2', {text: i18nConfig.GeneralSetting})
|
||||
|
||||
// new Setting(containerEl)
|
||||
// .setName(i18nConfig.NotionNextVersion)
|
||||
// .setDesc(i18nConfig.NotionNextVersionDesc)
|
||||
// .addToggle((toggle) =>
|
||||
// toggle
|
||||
// .setValue(this.plugin.settings.NNon)
|
||||
// .onChange(async (value) => {
|
||||
// this.plugin.settings.NNon = value;
|
||||
// await this.plugin.saveSettings();
|
||||
// })
|
||||
// );
|
||||
new Setting(containerEl)
|
||||
.setName(i18nConfig.NotionNextButton)
|
||||
.setDesc(i18nConfig.NotionNextButtonDesc)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.NextButton)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.NextButton = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18nConfig.BannerUrl)
|
||||
@@ -119,6 +127,17 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
||||
|
||||
// new Setting(containerEl)
|
||||
// .setName(i18nConfig.NotYetFinish)
|
||||
new Setting(containerEl)
|
||||
.setName(i18nConfig.NotionGeneralButton)
|
||||
.setDesc(i18nConfig.NotionGeneralButtonDesc)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.GeneralButton)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.GeneralButton = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
// new Setting(containerEl)
|
||||
// .setName("Convert tags(optional)")
|
||||
@@ -161,5 +180,20 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
||||
}
|
||||
);
|
||||
|
||||
// Custom Database Settings
|
||||
|
||||
containerEl.createEl('h2', {text: i18nConfig.NotionCustomSettingHeader});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(i18nConfig.NotionCustomButton)
|
||||
.setDesc(i18nConfig.NotionCustomButtonDesc)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.plugin.settings.CustomButton)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.CustomButton = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user