mirror of
https://github.com/jsmorabito/obsidian-commander.git
synced 2026-07-22 06:40:31 +00:00
feat: add Text Toolbar plugin integration
Commander now detects the standalone Text Toolbar plugin at load time and: - Pushes saved commands into the toolbar via its public API (setCommands) - Shows a "Text Toolbar" tab in Commander settings when the plugin is installed, using the existing CommandViewer UI for add/remove/reorder The tab is hidden when the Text Toolbar plugin is not installed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
606593e16a
commit
a2dcc97f3e
6 changed files with 68 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ export const DEFAULT_SETTINGS: CommanderSettings = {
|
|||
pageHeader: [],
|
||||
macros: [],
|
||||
explorer: [],
|
||||
textToolbarCommands: [],
|
||||
hide: {
|
||||
statusbar: [],
|
||||
leftRibbon: [],
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
FileMenuCommandManager,
|
||||
PageHeaderManager,
|
||||
StatusBarManager,
|
||||
TextToolbarIntegrationManager,
|
||||
} from "./manager/commands";
|
||||
import { Action, CommanderSettings } from "./types";
|
||||
import CommanderSettingTab from "./ui/settingTab";
|
||||
|
|
@ -36,6 +37,7 @@ export default class CommanderPlugin extends Plugin {
|
|||
statusBar: StatusBarManager;
|
||||
pageHeader: PageHeaderManager;
|
||||
explorerManager: ExplorerManager;
|
||||
textToolbarIntegration: TextToolbarIntegrationManager;
|
||||
};
|
||||
|
||||
public async executeStartupMacros(): Promise<void> {
|
||||
|
|
@ -95,6 +97,7 @@ export default class CommanderPlugin extends Plugin {
|
|||
statusBar: new StatusBarManager(this, this.settings.statusBar),
|
||||
pageHeader: new PageHeaderManager(this, this.settings.pageHeader),
|
||||
explorerManager: new ExplorerManager(this, this.settings.explorer),
|
||||
textToolbarIntegration: new TextToolbarIntegrationManager(this, this.settings.textToolbarCommands),
|
||||
};
|
||||
|
||||
this.addSettingTab(new CommanderSettingTab(this));
|
||||
|
|
@ -127,6 +130,9 @@ export default class CommanderPlugin extends Plugin {
|
|||
injectIcons(this.settings.advancedToolbar, this);
|
||||
|
||||
this.executeStartupMacros();
|
||||
|
||||
// Push saved commands into the Text Toolbar plugin if it is installed
|
||||
this.manager.textToolbarIntegration.reorder();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import ExplorerManager from "./explorerManager";
|
||||
import TextToolbarIntegrationManager from "./textToolbarIntegrationManager";
|
||||
import {
|
||||
EditorMenuCommandManager,
|
||||
FileMenuCommandManager,
|
||||
|
|
@ -12,6 +13,7 @@ export {
|
|||
FileMenuCommandManager,
|
||||
PageHeaderManager,
|
||||
StatusBarManager,
|
||||
TextToolbarIntegrationManager,
|
||||
TitleBarManager,
|
||||
ExplorerManager,
|
||||
};
|
||||
|
|
|
|||
44
src/manager/commands/textToolbarIntegrationManager.ts
Normal file
44
src/manager/commands/textToolbarIntegrationManager.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import CommanderPlugin from "src/main";
|
||||
import { CommandIconPair } from "src/types";
|
||||
import CommandManagerBase from "./commandManager";
|
||||
|
||||
interface TextToolbarAPI {
|
||||
setCommands(cmds: { id: string; icon: string; name: string }[]): void;
|
||||
}
|
||||
|
||||
function getTextToolbarAPI(plugin: CommanderPlugin): TextToolbarAPI | undefined {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (plugin.app as any).plugins?.plugins?.["text-toolbar"]?.api;
|
||||
}
|
||||
|
||||
export default class TextToolbarIntegrationManager extends CommandManagerBase {
|
||||
public constructor(plugin: CommanderPlugin, pairs: CommandIconPair[]) {
|
||||
super(plugin, pairs);
|
||||
}
|
||||
|
||||
private sync(): void {
|
||||
const api = getTextToolbarAPI(this.plugin);
|
||||
if (!api) return;
|
||||
api.setCommands(this.pairs.map(p => ({ id: p.id, icon: p.icon, name: p.name })));
|
||||
}
|
||||
|
||||
public static isAvailable(plugin: CommanderPlugin): boolean {
|
||||
return getTextToolbarAPI(plugin) !== undefined;
|
||||
}
|
||||
|
||||
public async addCommand(pair: CommandIconPair): Promise<void> {
|
||||
this.pairs.push(pair);
|
||||
await this.plugin.saveSettings();
|
||||
this.sync();
|
||||
}
|
||||
|
||||
public async removeCommand(pair: CommandIconPair): Promise<void> {
|
||||
this.pairs.remove(pair);
|
||||
await this.plugin.saveSettings();
|
||||
this.sync();
|
||||
}
|
||||
|
||||
public reorder(): void {
|
||||
this.sync();
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ export interface CommanderSettings {
|
|||
pageHeader: CommandIconPair[];
|
||||
explorer: CommandIconPair[];
|
||||
macros: Macro[];
|
||||
textToolbarCommands: CommandIconPair[];
|
||||
hide: {
|
||||
statusbar: string[];
|
||||
leftRibbon: string[];
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import CommandViewer from "./commandViewerComponent";
|
|||
import { LeftRibbonHider, StatusbarHider } from "./hidingViewer";
|
||||
import MacroViewer from "./MacroViewer";
|
||||
import { SliderComponent, ToggleComponent } from "./settingComponent";
|
||||
import TextToolbarIntegrationManager from "src/manager/commands/textToolbarIntegrationManager";
|
||||
|
||||
export default function settingTabComponent({
|
||||
plugin,
|
||||
|
|
@ -256,6 +257,19 @@ export default function settingTabComponent({
|
|||
),
|
||||
},
|
||||
|
||||
...(TextToolbarIntegrationManager.isAvailable(plugin)
|
||||
? [
|
||||
{
|
||||
name: "Text Toolbar",
|
||||
tab: (
|
||||
<CommandViewer
|
||||
manager={plugin.manager.textToolbarIntegration}
|
||||
plugin={plugin}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
name: Platform.isMobile ? "Mobile Toolbar" : "Toolbar",
|
||||
tab: <AdvancedToolbarSettings plugin={plugin} />,
|
||||
|
|
|
|||
Loading…
Reference in a new issue