Improved: update smart_contexts_open_dashboard to use plugin for dashboard opening and adjust command registration

This commit is contained in:
Brian Joseph Petro 2026-07-21 13:31:30 -04:00
parent 78523122b8
commit 0f3a28ccec
4 changed files with 29 additions and 14 deletions

View file

@ -21,7 +21,7 @@ import { env_copy_selected_notes_to_clipboard as env_copy_selected_notes_to_clip
import { env_open_file_selection_in_context_builder as env_open_file_selection_in_context_builder_action, menus as env_open_file_selection_in_context_builder_action_menus } from './src/actions/env/open_file_selection_in_context_builder.js';
import { env_open_folder_in_context_builder as env_open_folder_in_context_builder_action, menus as env_open_folder_in_context_builder_action_menus } from './src/actions/env/open_folder_in_context_builder.js';
import { smart_contexts_insert_codeblock as smart_contexts_insert_codeblock_action, commands as smart_contexts_insert_codeblock_action_commands } from './src/actions/smart-contexts/insert_codeblock.js';
import { smart_contexts_open_dashboard as smart_contexts_open_dashboard_action, ribbon_icons as smart_contexts_open_dashboard_action_ribbon_icons, menus as smart_contexts_open_dashboard_action_menus } from './src/actions/smart-contexts/open_dashboard.js';
import { smart_contexts_open_dashboard as smart_contexts_open_dashboard_action, commands as smart_contexts_open_dashboard_action_commands, ribbon_icons as smart_contexts_open_dashboard_action_ribbon_icons, menus as smart_contexts_open_dashboard_action_menus } from './src/actions/smart-contexts/open_dashboard.js';
import { smart_contexts_open_new as smart_contexts_open_new_action, commands as smart_contexts_open_new_action_commands, ribbon_icons as smart_contexts_open_new_action_ribbon_icons } from './src/actions/smart-contexts/open_new.js';
import { smart_contexts_open_onboarding as smart_contexts_open_onboarding_action, commands as smart_contexts_open_onboarding_action_commands, menus as smart_contexts_open_onboarding_action_menus } from './src/actions/smart-contexts/open_onboarding.js';
import { source_copy_current as source_copy_current_action, commands as source_copy_current_action_commands, ribbon_icons as source_copy_current_action_ribbon_icons } from './src/actions/source/copy_current.js';
@ -59,7 +59,7 @@ export const smart_env_config = {
env_open_file_selection_in_context_builder: { action: env_open_file_selection_in_context_builder_action, menus: env_open_file_selection_in_context_builder_action_menus, version: "2.4.6" },
env_open_folder_in_context_builder: { action: env_open_folder_in_context_builder_action, menus: env_open_folder_in_context_builder_action_menus, version: "2.4.6" },
smart_contexts_insert_codeblock: { action: smart_contexts_insert_codeblock_action, commands: smart_contexts_insert_codeblock_action_commands, version: "2.4.6" },
smart_contexts_open_dashboard: { action: smart_contexts_open_dashboard_action, ribbon_icons: smart_contexts_open_dashboard_action_ribbon_icons, menus: smart_contexts_open_dashboard_action_menus, version: "2.4.6" },
smart_contexts_open_dashboard: { action: smart_contexts_open_dashboard_action, commands: smart_contexts_open_dashboard_action_commands, ribbon_icons: smart_contexts_open_dashboard_action_ribbon_icons, menus: smart_contexts_open_dashboard_action_menus, version: "2.4.6" },
smart_contexts_open_new: { action: smart_contexts_open_new_action, commands: smart_contexts_open_new_action_commands, ribbon_icons: smart_contexts_open_new_action_ribbon_icons, version: "2.4.6" },
smart_contexts_open_onboarding: { action: smart_contexts_open_onboarding_action, commands: smart_contexts_open_onboarding_action_commands, menus: smart_contexts_open_onboarding_action_menus, version: "2.4.6" },
source_copy_current: { action: source_copy_current_action, commands: source_copy_current_action_commands, ribbon_icons: source_copy_current_action_ribbon_icons, version: "2.4.6" },

View file

@ -3,20 +3,35 @@
*
* @this {import('smart-contexts').SmartContexts} Collection scope
* @param {object} [params={}]
* @param {object} [params.plugin]
* @returns {boolean}
*/
export function smart_contexts_open_dashboard(params = {}) {
const app = params.app
|| this?.env?.plugin?.app
|| this?.env?.obsidian_app
|| globalThis.app
;
if (typeof app?.commands?.executeCommandById !== 'function') return false;
const plugin = params.plugin || this?.env?.smart_context_plugin;
if (typeof plugin?.open_contexts_dashboard !== 'function') return false;
app.commands.executeCommandById('smart-context:smart-contexts-dashboard');
plugin.open_contexts_dashboard();
return true;
}
export const commands = {
'smart-contexts-dashboard': {
name: 'Open: Management dashboard (show named contexts) view',
register_when({ plugin }) {
return plugin.manifest.id === 'smart-context';
},
params({ plugin }) {
return { plugin };
},
get_scope({ env }) {
return env.smart_contexts;
},
},
};
export const menus = {
'smart_contexts:menu': {
title: 'Open named contexts dashboard',
@ -34,8 +49,8 @@ export const ribbon_icons = {
return plugin.manifest.id === 'smart-context';
},
params({ app }) {
return { app };
params({ plugin }) {
return { plugin };
},
get_scope({ env }) {

View file

@ -115,7 +115,7 @@ export async function post_process(ctx, container, params = {}) {
menu.addSeparator();
ctx.env?.build_menu?.('smart_context:copy_menu', menu, ctx, menu_params);
menu.addSeparator();
ctx.env?.build_menu?.('smart_contexts:menu', menu, ctx, menu_params);
ctx.env?.build_menu?.('smart_contexts:menu', menu, ctx.collection, menu_params);
show_menu(menu, event, menu_btn);
};

View file

@ -53,8 +53,8 @@ export default class SmartContextPlugin extends SmartPlugin {
this.register_folder_menu();
this.register_files_menu();
ContextsDashboardView.register_item_view(this);
this.ReleaseNotesView.register_item_view(this);
ContextsDashboardView.register_item_view(this, { skip_command_registration: true });
this.ReleaseNotesView.register_item_view(this, { skip_command_registration: true });
// First-run onboarding
if (this.is_new_user()) {