Skip to content

Commit

Permalink
Merge pull request #520 from dyaskur/master
Browse files Browse the repository at this point in the history
add copy shortcut and default copy type setting
  • Loading branch information
Fabio286 authored Jan 16, 2023
2 parents 0e80e82 + 4c16d8c commit 5624b3b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
38 changes: 36 additions & 2 deletions src/renderer/components/ModalSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@
</div>
</div>
</div>
<div class="column col-12 h6 mt-4 text-uppercase mb-1">
{{ t('word.resultsTable') }}
</div>
<div class="column col-12 col-sm-12 columns">
<div class="form-group column col-12">
<div class="col-5 col-sm-12">
<label class="form-label">
{{ t('message.defaultCopyType') }}
</label>
</div>
<div class="col-3 col-sm-12">
<BaseSelect
v-model="defaultCopyType"
class="form-select"
:options="copyTypes"
option-track-by="code"
option-label="name"
@change="changeDefaultCopyType(defaultCopyType)"
/>
</div>
</div>
</div>
</form>
</div>
</div>
Expand Down Expand Up @@ -393,6 +415,7 @@ const {
autoComplete: selectedAutoComplete,
lineWrap: selectedLineWrap,
executeSelected: selectedExecuteSelected,
defaultCopyType: selectedCopyType,
notificationsTimeout,
restoreTabs,
disableBlur,
Expand All @@ -416,7 +439,8 @@ const {
changeApplicationTheme,
changeEditorTheme,
changeEditorFontSize,
updateNotificationsTimeout
updateNotificationsTimeout,
changeDefaultCopyType
} = settingsStore;
const {
hideSettingModal: closeModal,
Expand All @@ -432,7 +456,7 @@ const appLogo = require('../images/logo.svg');
const darkPreview = require('../images/dark.png');
const lightPreview = require('../images/light.png');
const exampleQuery = `-- This is an example
SELECT
SELECT
employee.id,
employee.first_name,
employee.last_name,
Expand All @@ -448,6 +472,7 @@ ORDER BY
`;
const localLocale: Ref<AvailableLocale> = ref(null);
const defaultCopyType: Ref<string> = ref(null);
const localPageSize: Ref<number> = ref(null);
const localTimeout: Ref<number> = ref(null);
const localEditorTheme: Ref<string> = ref(null);
Expand Down Expand Up @@ -511,6 +536,14 @@ const locales = computed(() => {
return locales;
});
const copyTypes = computed(() => [
{ code: 'cell', name: t('word.cell') },
{ code: 'html', name: t('word.table') },
{ code: 'json', name: 'JSON' },
{ code: 'csv', name: 'CSV' },
{ code: 'sql', name: 'SQL insert' }
]);
const hasUpdates = computed(() => ['available', 'downloading', 'downloaded', 'link'].includes(updateStatus.value));
const workspace = computed(() => {
Expand Down Expand Up @@ -570,6 +603,7 @@ const toggleExecuteSelected = () => {
};
localLocale.value = selectedLocale.value;
defaultCopyType.value = selectedCopyType.value;
localPageSize.value = pageSize.value as number;
localTimeout.value = notificationsTimeout.value as number;
localEditorTheme.value = editorTheme.value as string;
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/components/WorkspaceTabQueryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const settingsStore = useSettingsStore();
const consoleStore = useConsoleStore();
const { getWorkspace } = useWorkspacesStore();
const { dataTabLimit: pageSize } = storeToRefs(settingsStore);
const { dataTabLimit: pageSize, defaultCopyType } = storeToRefs(settingsStore);
const { consoleHeight } = storeToRefs(consoleStore);
Expand Down Expand Up @@ -697,6 +697,18 @@ const onKey = async (e: KeyboardEvent) => {
if ((e.ctrlKey || e.metaKey) && e.code === 'KeyA' && !e.altKey)
selectAllRows(e);
if ((e.ctrlKey || e.metaKey) && e.code === 'KeyC' && !e.altKey) {
const copyType = defaultCopyType.value;
if (selectedRows.value.length >= 1) {
if (selectedRows.value.length === 1 && copyType === 'cell')
await navigator.clipboard.writeText(scrollElement.value.querySelector('.td.selected').innerText);
else if (selectedRows.value.length > 1 && copyType === 'cell')
copyRow('html');
else
copyRow(copyType);
}
}
// row navigation stuff
if (!(e.ctrlKey || e.metaKey) && (e.code.includes('Arrow') || e.code === 'Tab') && sortedResults.value.length > 0 && !e.altKey) {
e.preventDefault();
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/i18n/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export const enUS = {
appearence: 'Appearence',
color: 'Color',
label: 'Label',
icon: 'Icon'
icon: 'Icon',
resultsTable: 'Results table'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',
Expand Down Expand Up @@ -333,7 +334,8 @@ export const enUS = {
folderName: 'Folder name',
deleteFolder: 'Delete folder',
editConnectionAppearence: 'Edit connection appearence',
executeSelectedQuery: 'Execute selected query'
executeSelectedQuery: 'Execute selected query',
defaultCopyType: 'Default copy type'
},
faker: {
address: 'Address',
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/id-ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ export const idID = {
folderName: 'Nama folder',
deleteFolder: 'Hapus folder',
editConnectionAppearence: 'Ubah connection appearence',
executeSelectedQuery: 'Eksekusi query yang dipilih'
executeSelectedQuery: 'Eksekusi query yang dipilih',
defaultCopyType: 'Jenis salin default'
},
faker: {
address: 'Alamat',
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const useSettingsStore = defineStore('settings', {
restoreTabs: settingsStore.get('restore_tabs', true) as boolean,
disableBlur: settingsStore.get('disable_blur', false) as boolean,
disableScratchpad: settingsStore.get('disable_scratchpad', false) as boolean,
shortcuts: shortcutsStore.get('shortcuts', []) as ShortcutRecord[]
shortcuts: shortcutsStore.get('shortcuts', []) as ShortcutRecord[],
defaultCopyType: settingsStore.get('default_copy_type', 'cell') as string
}),
actions: {
changeLocale (locale: AvailableLocale) {
Expand Down Expand Up @@ -92,6 +93,10 @@ export const useSettingsStore = defineStore('settings', {
},
updateShortcuts (shortcuts: ShortcutRecord[]) {
this.shortcuts = shortcuts;
},
changeDefaultCopyType (type: string) {
this.defaultCopyType = type;
settingsStore.set('default_copy_type', this.defaultCopyType);
}
}
});

0 comments on commit 5624b3b

Please sign in to comment.