Merge branch 'master' of github.com:dbgate/dbgate

This commit is contained in:
Jan Prochazka 2024-05-08 07:46:31 +02:00
commit 397a6b54ff
6 changed files with 60 additions and 2 deletions

View File

@ -31,6 +31,7 @@
return [ return [
{ text: 'Rename column', onClick: handleRenameColumn }, { text: 'Rename column', onClick: handleRenameColumn },
{ text: 'Drop column', onClick: handleDropColumn }, { text: 'Drop column', onClick: handleDropColumn },
{ text: 'Copy name', onClick: () => navigator.clipboard.writeText(data.columnName)},
]; ];
} }

View File

@ -1,4 +1,6 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import {copyTextToClipboard} from "../utility/clipboard";
export const extractKey = props => props.name; export const extractKey = props => props.name;
export function disconnectDatabaseConnection(conid, database, showConfirmation = true) { export function disconnectDatabaseConnection(conid, database, showConfirmation = true) {
@ -169,6 +171,10 @@
); );
}; };
const handleCopyName = async () => {
copyTextToClipboard(name);
}
const handleDisconnect = () => { const handleDisconnect = () => {
disconnectDatabaseConnection(connection._id, name); disconnectDatabaseConnection(connection._id, name);
}; };
@ -295,6 +301,7 @@
!connection.isReadOnly && !connection.isReadOnly &&
!connection.singleDatabase && { onClick: handleDropDatabase, text: 'Drop database' }, !connection.singleDatabase && { onClick: handleDropDatabase, text: 'Drop database' },
{ divider: true }, { divider: true },
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleCopyName, text: 'Copy database name' },
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleShowDiagram, text: 'Show diagram' }, driver?.databaseEngineTypes?.includes('sql') && { onClick: handleShowDiagram, text: 'Show diagram' },
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleSqlGenerator, text: 'SQL Generator' }, driver?.databaseEngineTypes?.includes('sql') && { onClick: handleSqlGenerator, text: 'SQL Generator' },
driver?.supportsDatabaseProfiler && { onClick: handleDatabaseProfiler, text: 'Database profiler' }, driver?.supportsDatabaseProfiler && { onClick: handleDatabaseProfiler, text: 'Database profiler' },

View File

@ -1,4 +1,6 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import {copyTextToClipboard} from "../utility/clipboard";
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName); export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
export const createMatcher = export const createMatcher =
({ schemaName, pureName, columns }) => ({ schemaName, pureName, columns }) =>
@ -80,6 +82,11 @@
isTruncate: true, isTruncate: true,
requiresWriteAccess: true, requiresWriteAccess: true,
}, },
{
label: 'Copy table name',
isCopyTableName: true,
requiresWriteAccess: false
},
{ {
label: 'Create table backup', label: 'Create table backup',
isDuplicateTable: true, isDuplicateTable: true,
@ -511,6 +518,8 @@
saveScriptToDatabase(dbid, `db.dropCollection('${data.pureName}')`); saveScriptToDatabase(dbid, `db.dropCollection('${data.pureName}')`);
}, },
}); });
} else if (menu.isCopyTableName) {
copyTextToClipboard(data.pureName);
} else if (menu.isRenameCollection) { } else if (menu.isRenameCollection) {
showModal(InputTextModal, { showModal(InputTextModal, {
label: 'New collection name', label: 'New collection name',

View File

@ -575,6 +575,7 @@ export function registerFileCommands({
findReplace = false, findReplace = false,
undoRedo = false, undoRedo = false,
executeAdditionalCondition = null, executeAdditionalCondition = null,
copyPaste = false,
}) { }) {
if (save) { if (save) {
registerCommand({ registerCommand({
@ -645,6 +646,25 @@ export function registerFileCommands({
}); });
} }
if(copyPaste) {
registerCommand({
id: idPrefix + '.copy',
category,
name: 'Copy',
keyText: 'CtrlOrCommand+C',
testEnabled: () => getCurrentEditor() != null,
onClick: () => getCurrentEditor().copy(),
});
registerCommand({
id: idPrefix + '.paste',
category,
name: 'Paste',
keyText: 'CtrlOrCommand+V',
testEnabled: () => getCurrentEditor() != null,
onClick: () => getCurrentEditor().paste(),
})
}
if (findReplace) { if (findReplace) {
registerCommand({ registerCommand({
id: idPrefix + '.find', id: idPrefix + '.find',

View File

@ -1,4 +1,7 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import registerCommand from "../commands/registerCommand";
import {copyTextToClipboard} from "../utility/clipboard";
const getCurrentEditor = () => getActiveComponent('QueryTab'); const getCurrentEditor = () => getActiveComponent('QueryTab');
registerCommand({ registerCommand({
@ -37,6 +40,7 @@
toggleComment: true, toggleComment: true,
findReplace: true, findReplace: true,
executeAdditionalCondition: () => getCurrentEditor()?.hasConnection(), executeAdditionalCondition: () => getCurrentEditor()?.hasConnection(),
copyPaste: true
}); });
registerCommand({ registerCommand({
id: 'query.executeCurrent', id: 'query.executeCurrent',
@ -53,8 +57,6 @@
import { getContext, onDestroy, onMount } from 'svelte'; import { getContext, onDestroy, onMount } from 'svelte';
import sqlFormatter from 'sql-formatter'; import sqlFormatter from 'sql-formatter';
import registerCommand from '../commands/registerCommand';
import VerticalSplitter from '../elements/VerticalSplitter.svelte'; import VerticalSplitter from '../elements/VerticalSplitter.svelte';
import SqlEditor from '../query/SqlEditor.svelte'; import SqlEditor from '../query/SqlEditor.svelte';
import useEditorData from '../query/useEditorData'; import useEditorData from '../query/useEditorData';
@ -81,6 +83,7 @@
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte'; import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte'; import ToolStripSaveButton from '../buttons/ToolStripSaveButton.svelte';
import ToolStripCommandSplitButton from '../buttons/ToolStripCommandSplitButton.svelte'; import ToolStripCommandSplitButton from '../buttons/ToolStripCommandSplitButton.svelte';
import {getClipboardText} from "../utility/clipboard";
export let tabid; export let tabid;
export let conid; export let conid;
@ -241,6 +244,17 @@
domEditor.getEditor().execCommand('togglecomment'); domEditor.getEditor().execCommand('togglecomment');
} }
export function copy() {
const selectedText = domEditor.getEditor().getSelectedText();
copyTextToClipboard(selectedText);
}
export function paste() {
getClipboardText().then((text) => {
domEditor.getEditor().execCommand('paste', text);
});
}
export function find() { export function find() {
domEditor.getEditor().execCommand('find'); domEditor.getEditor().execCommand('find');
} }
@ -311,6 +325,8 @@
{ command: 'query.save' }, { command: 'query.save' },
{ command: 'query.saveAs' }, { command: 'query.saveAs' },
{ divider: true }, { divider: true },
{ command: 'query.copy' },
{ command: 'query.paste' },
{ command: 'query.find' }, { command: 'query.find' },
{ command: 'query.replace' }, { command: 'query.replace' },
{ divider: true }, { divider: true },

View File

@ -66,6 +66,11 @@ export function copyTextToClipboard(text) {
} }
} }
/* Currently this doesn't work in firefox stable, but works in nightly */
export async function getClipboardText() {
return await navigator.clipboard.readText();
}
export function extractRowCopiedValue(row, col) { export function extractRowCopiedValue(row, col) {
let value = row[col]; let value = row[col];
if (value === undefined) value = _.get(row, col); if (value === undefined) value = _.get(row, col);