mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 14:26:00 +00:00
context menu
This commit is contained in:
@@ -30,11 +30,38 @@ export default async function invalidateCommands() {
|
|||||||
if (!command.isGroupCommand) continue;
|
if (!command.isGroupCommand) continue;
|
||||||
const groupSources = values.filter(x => x.group == command.group && !x.isGroupCommand && x.enabled);
|
const groupSources = values.filter(x => x.group == command.group && !x.isGroupCommand && x.enabled);
|
||||||
command.enabled = groupSources.length > 0;
|
command.enabled = groupSources.length > 0;
|
||||||
for(const source of groupSources) {
|
// for (const source of groupSources) {
|
||||||
source.keyTextFromGroup = command.keyText;
|
// source.keyTextFromGroup = command.keyText;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res || dct;
|
return res || dct;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isInvalidatedDefinitions = false;
|
||||||
|
|
||||||
|
export async function invalidateCommandDefinitions() {
|
||||||
|
if (isInvalidatedDefinitions) return;
|
||||||
|
isInvalidatedDefinitions = true;
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
isInvalidatedDefinitions = false;
|
||||||
|
|
||||||
|
commands.update(dct => {
|
||||||
|
let res = { ...dct };
|
||||||
|
const values = Object.values(res) as GlobalCommand[];
|
||||||
|
// test enabled for group commands
|
||||||
|
for (const command of values) {
|
||||||
|
if (!command.isGroupCommand) continue;
|
||||||
|
const groupSources = values.filter(x => x.group == command.group && !x.isGroupCommand);
|
||||||
|
|
||||||
|
for (const source of groupSources) {
|
||||||
|
source.keyTextFromGroup = command.keyText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
invalidateCommands();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { commands } from '../stores';
|
import { commands } from '../stores';
|
||||||
import invalidateCommands from './invalidateCommands';
|
import { invalidateCommandDefinitions } from './invalidateCommands';
|
||||||
|
|
||||||
export interface SubCommand {
|
export interface SubCommand {
|
||||||
text: string;
|
text: string;
|
||||||
@@ -39,16 +39,5 @@ export default function registerCommand(command: GlobalCommand) {
|
|||||||
enabled: !testEnabled,
|
enabled: !testEnabled,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
invalidateCommands();
|
invalidateCommandDefinitions();
|
||||||
// if (enabledStore) {
|
|
||||||
// enabledStore.subscribe(value => {
|
|
||||||
// commands.update(x => ({
|
|
||||||
// ...x,
|
|
||||||
// [command.id]: {
|
|
||||||
// ...x[command.id],
|
|
||||||
// enabled: value,
|
|
||||||
// },
|
|
||||||
// }));
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,24 @@ registerCommand({
|
|||||||
group: 'saveAs',
|
group: 'saveAs',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'group.undo',
|
||||||
|
category: null,
|
||||||
|
isGroupCommand: true,
|
||||||
|
name: 'Undo',
|
||||||
|
keyText: 'Ctrl+Z',
|
||||||
|
group: 'undo',
|
||||||
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'group.redo',
|
||||||
|
category: null,
|
||||||
|
isGroupCommand: true,
|
||||||
|
name: 'Redo',
|
||||||
|
keyText: 'Ctrl+Y',
|
||||||
|
group: 'redo',
|
||||||
|
});
|
||||||
|
|
||||||
if (electron) {
|
if (electron) {
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'file.open',
|
id: 'file.open',
|
||||||
@@ -175,6 +193,7 @@ export function registerFileCommands({
|
|||||||
execute = false,
|
execute = false,
|
||||||
toggleComment = false,
|
toggleComment = false,
|
||||||
findReplace = false,
|
findReplace = false,
|
||||||
|
undoRedo = false,
|
||||||
}) {
|
}) {
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: idPrefix + '.save',
|
id: idPrefix + '.save',
|
||||||
@@ -248,4 +267,22 @@ export function registerFileCommands({
|
|||||||
onClick: () => getCurrentEditor().replace(),
|
onClick: () => getCurrentEditor().replace(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (undoRedo) {
|
||||||
|
registerCommand({
|
||||||
|
id: idPrefix + '.undo',
|
||||||
|
category,
|
||||||
|
name: 'Undo',
|
||||||
|
group: 'undo',
|
||||||
|
testEnabled: () => getCurrentEditor()?.canUndo(),
|
||||||
|
onClick: () => getCurrentEditor().undo(),
|
||||||
|
});
|
||||||
|
registerCommand({
|
||||||
|
id: idPrefix + '.redo',
|
||||||
|
category,
|
||||||
|
group: 'redo',
|
||||||
|
name: 'Replace',
|
||||||
|
testEnabled: () => getCurrentEditor()?.canRedo(),
|
||||||
|
onClick: () => getCurrentEditor().redo(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
id: 'dataGrid.undo',
|
id: 'dataGrid.undo',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'Undo',
|
name: 'Undo',
|
||||||
keyText: 'Ctrl+Z',
|
group: 'undo',
|
||||||
icon: 'icon undo',
|
icon: 'icon undo',
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canUndo,
|
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canUndo,
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
id: 'dataGrid.redo',
|
id: 'dataGrid.redo',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
name: 'Redo',
|
name: 'Redo',
|
||||||
keyText: 'Ctrl+Y',
|
group: 'redo',
|
||||||
icon: 'icon redo',
|
icon: 'icon redo',
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canRedo,
|
testEnabled: () => getCurrentDataGrid()?.getGrider()?.canRedo,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
export let onChange;
|
export let onChange;
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
// export let menu;
|
export let menu;
|
||||||
|
|
||||||
let domCanvas;
|
let domCanvas;
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper" use:contextMenu={menu}>
|
||||||
{#if !(tables?.length > 0)}
|
{#if !(tables?.length > 0)}
|
||||||
<div class="empty">Drag & drop tables or views from left panel here</div>
|
<div class="empty">Drag & drop tables or views from left panel here</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
function handleClick(item) {
|
function handleClick(item) {
|
||||||
|
if (item.disabled) return;
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
if (item.onClick) item.onClick();
|
if (item.onClick) item.onClick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
fileExtension: 'qdesign',
|
fileExtension: 'qdesign',
|
||||||
|
|
||||||
execute: true,
|
execute: true,
|
||||||
|
undoRedo: true,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@
|
|||||||
$: {
|
$: {
|
||||||
busy;
|
busy;
|
||||||
sessionId;
|
sessionId;
|
||||||
|
$editorState;
|
||||||
invalidateCommands();
|
invalidateCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +144,22 @@
|
|||||||
return $editorState.value || '';
|
return $editorState.value || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canUndo() {
|
||||||
|
return $modelState.canUndo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function undo() {
|
||||||
|
dispatchModel({ type: 'undo' });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canRedo() {
|
||||||
|
return $modelState.canRedo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function redo() {
|
||||||
|
dispatchModel({ type: 'redo' });
|
||||||
|
}
|
||||||
|
|
||||||
const generatePreview = (value, engine) => {
|
const generatePreview = (value, engine) => {
|
||||||
if (!engine || !value) return;
|
if (!engine || !value) return;
|
||||||
const sql = generateDesignedQuery(value, engine);
|
const sql = generateDesignedQuery(value, engine);
|
||||||
@@ -181,6 +199,18 @@
|
|||||||
// />
|
// />
|
||||||
// </TabPage>
|
// </TabPage>
|
||||||
// )}
|
// )}
|
||||||
|
function createMenu() {
|
||||||
|
return [
|
||||||
|
{ command: 'designer.execute' },
|
||||||
|
{ command: 'designer.kill' },
|
||||||
|
{ divider: true },
|
||||||
|
{ command: 'designer.save' },
|
||||||
|
{ command: 'designer.saveAs' },
|
||||||
|
{ divider: true },
|
||||||
|
{ command: 'designer.undo' },
|
||||||
|
{ command: 'designer.redo' },
|
||||||
|
];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<VerticalSplitter initialValue="70%">
|
<VerticalSplitter initialValue="70%">
|
||||||
@@ -191,6 +221,7 @@
|
|||||||
{database}
|
{database}
|
||||||
engine={$connection && $connection.engine}
|
engine={$connection && $connection.engine}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
menu={createMenu}
|
||||||
/>
|
/>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { currentDropDownMenu } from '../stores';
|
|||||||
export default function contextMenu(node, items) {
|
export default function contextMenu(node, items) {
|
||||||
const handleContextMenu = e => {
|
const handleContextMenu = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
const left = e.pageX;
|
const left = e.pageX;
|
||||||
const top = e.pageY;
|
const top = e.pageY;
|
||||||
currentDropDownMenu.set({ left, top, items: _.isFunction(items) ? items() : items });
|
currentDropDownMenu.set({ left, top, items: _.isFunction(items) ? items() : items });
|
||||||
|
|||||||
Reference in New Issue
Block a user