дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
refactor(database): take plugin table menu entries from a workbench registry (#7423)
The Database tree imported pluginDatabaseTableMenuItems from features/plugins directly (from #7372). The table context type and a provider registry now live in workbench/contributions; features/plugins registers its provider.
Цей коміт міститься в:
1 джерело
b7c2d4eacb
коміт
a36516d463
4 files changed
+37
-16
No files matched your search
@@ -1,9 +1,8 @@
|
||||
/** Menus of the Database tool window, laid out like IDEA's (New ▸, Copy/Paste ▸, SQL Scripts ▸ …). */
|
||||
import { choosePath } from "@/platform/choosePath";
|
||||
import { pluginDatabaseTableMenuItems } from "@/features/plugins/uiPoints";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import type { MenuItem } from "@/ui";
|
||||
import { notifications } from "@/workbench/contributions";
|
||||
import { databaseTableMenuItems, notifications } from "@/workbench/contributions";
|
||||
import { fileSourceName, parseSourceUrl } from "./model";
|
||||
import { VENDORS, vendorById, vendorOf, vendorPreset, type DbVendor } from "./vendors";
|
||||
import { MAX_RECENT_VENDORS, readRecentVendors } from "./recentVendors";
|
||||
@@ -208,7 +207,7 @@ export function nodeMenu(n: DbNode | null, selection: readonly DbNode[] = []): M
|
||||
kind: node.table.kind,
|
||||
driver: sourceById(node.id)?.driver ?? "",
|
||||
}));
|
||||
const plugins = pluginDatabaseTableMenuItems(tables);
|
||||
const plugins = databaseTableMenuItems(tables);
|
||||
return plugins.length ? [...builtin, sep, ...plugins] : builtin;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ import { useDatabase } from "@/features/database/store";
|
||||
import type { DbNode } from "@/features/database/nodes";
|
||||
import { defineBuiltinUiPoints } from "../points";
|
||||
import { clearUiContributions, syncUiContributions } from "../projection";
|
||||
import { pluginDatabaseTableMenuItems, type DatabaseTableContext } from "../uiPoints";
|
||||
import type { DatabaseTableContext } from "@/workbench/contributions";
|
||||
import { pluginDatabaseTableMenuItems } from "../uiPoints";
|
||||
|
||||
const initialDatabase = useDatabase.getState();
|
||||
let stop: () => void;
|
||||
|
||||
@@ -24,7 +24,11 @@ import { evaluateWhen, getContext, useContextKeys } from "@/platform/context";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { isMacHost, registerExtensionBindings } from "@/platform/keymap";
|
||||
import { addFileIconProvider, bumpFileIconRevision, fileIconName, registerExternalIcons, type MenuItem } from "@/ui";
|
||||
import { addContributedFileTemplate } from "@/workbench/contributions";
|
||||
import {
|
||||
addContributedFileTemplate,
|
||||
registerDatabaseTableMenuProvider,
|
||||
type DatabaseTableContext,
|
||||
} from "@/workbench/contributions";
|
||||
import {
|
||||
addContributedSnippets,
|
||||
registerEditorKind,
|
||||
@@ -188,17 +192,7 @@ export function pluginViewItemMenuItems(pluginId: string, view: string, key: str
|
||||
return flattenSingleGroups(out);
|
||||
}
|
||||
|
||||
/** Non-secret table context passed to Database table menu commands (API 1.20). */
|
||||
export interface DatabaseTableContext {
|
||||
sourceId: string;
|
||||
catalog: string | null;
|
||||
schema: string;
|
||||
table: string;
|
||||
kind: string;
|
||||
driver: string;
|
||||
}
|
||||
|
||||
/** The right-clicked table is included in selection by the Database tree. */
|
||||
/** Database table menu commands (API 1.20); the right-clicked table is included in selection by the Database tree. */
|
||||
export function pluginDatabaseTableMenuItems(tables: readonly DatabaseTableContext[]): MenuItem[] {
|
||||
if (!tables.length) return [];
|
||||
const out: MenuItem[] = [];
|
||||
@@ -235,6 +229,8 @@ export function pluginDatabaseTableMenuItems(tables: readonly DatabaseTableConte
|
||||
return flattenSingleGroups(out);
|
||||
}
|
||||
|
||||
registerDatabaseTableMenuProvider(pluginDatabaseTableMenuItems);
|
||||
|
||||
/** The when keys of one selected service. */
|
||||
export function serviceWhenContext(service: ServiceContext, count: number) {
|
||||
return {
|
||||
|
||||
@@ -1152,6 +1152,31 @@ export interface CommitCheckProvider {
|
||||
|
||||
export const useCommitCheckProviders = create<{ providers: CommitCheckProvider[] }>(() => ({ providers: [] }));
|
||||
|
||||
/** The non-secret identity of a table or view selected in the Database tool window. */
|
||||
export interface DatabaseTableContext {
|
||||
sourceId: string;
|
||||
catalog: string | null;
|
||||
schema: string;
|
||||
table: string;
|
||||
kind: string;
|
||||
driver: string;
|
||||
}
|
||||
|
||||
/** Contributed entries of a table's context menu in the Database tool window (plugins'). */
|
||||
export type DatabaseTableMenuProvider = (tables: readonly DatabaseTableContext[]) => MenuItem[];
|
||||
|
||||
const databaseTableMenuProviders = new Set<DatabaseTableMenuProvider>();
|
||||
|
||||
export function registerDatabaseTableMenuProvider(provider: DatabaseTableMenuProvider): () => void {
|
||||
databaseTableMenuProviders.add(provider);
|
||||
return () => void databaseTableMenuProviders.delete(provider);
|
||||
}
|
||||
|
||||
/** The contributed entries for the selected `tables`, in registration order. */
|
||||
export function databaseTableMenuItems(tables: readonly DatabaseTableContext[]): MenuItem[] {
|
||||
return [...databaseTableMenuProviders].flatMap((provider) => provider(tables));
|
||||
}
|
||||
|
||||
export function registerCommitCheckProvider(p: CommitCheckProvider): () => void {
|
||||
useCommitCheckProviders.setState((s) => ({ providers: [...s.providers, p] }));
|
||||
return () => useCommitCheckProviders.setState((s) => ({ providers: s.providers.filter((x) => x !== p) }));
|
||||
|
||||
Reference in new issue
Заблокувати користувача