mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 19:13:59 +00:00
open file command
This commit is contained in:
@@ -56,12 +56,7 @@ function buildMenu() {
|
|||||||
label: 'File',
|
label: 'File',
|
||||||
submenu: [
|
submenu: [
|
||||||
commandItem('new.connection'),
|
commandItem('new.connection'),
|
||||||
{
|
commandItem('file.open'),
|
||||||
label: 'Open file',
|
|
||||||
click() {
|
|
||||||
mainWindow.webContents.executeJavaScript(`dbgate_openFile()`);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
commandItem('group.save'),
|
commandItem('group.save'),
|
||||||
commandItem('group.saveAs'),
|
commandItem('group.saveAs'),
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
@@ -70,13 +65,7 @@ function buildMenu() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Window',
|
label: 'Window',
|
||||||
submenu: [
|
submenu: [commandItem('new.query'), { type: 'separator' }, commandItem('tabs.closeAll'), { role: 'minimize' }],
|
||||||
commandItem('new.query'),
|
|
||||||
{ type: 'separator' },
|
|
||||||
|
|
||||||
commandItem('tabs.closeAll'),
|
|
||||||
{ role: 'minimize' },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import { showModal } from '../modals/modalTools';
|
|||||||
import newQuery from '../query/newQuery';
|
import newQuery from '../query/newQuery';
|
||||||
import saveTabFile from '../utility/saveTabFile';
|
import saveTabFile from '../utility/saveTabFile';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
import getElectron from '../utility/getElectron';
|
||||||
|
import { openElectronFile } from '../utility/openElectronFile';
|
||||||
|
|
||||||
|
const electron = getElectron();
|
||||||
|
|
||||||
function themeCommand(theme: ThemeDefinition) {
|
function themeCommand(theme: ThemeDefinition) {
|
||||||
return {
|
return {
|
||||||
@@ -136,6 +140,16 @@ registerCommand({
|
|||||||
group: 'saveAs',
|
group: 'saveAs',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (electron) {
|
||||||
|
registerCommand({
|
||||||
|
id: 'file.open',
|
||||||
|
category: 'File',
|
||||||
|
name: 'Open',
|
||||||
|
keyText: 'Ctrl+O',
|
||||||
|
onClick: openElectronFile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function registerFileCommands({
|
export function registerFileCommands({
|
||||||
idPrefix,
|
idPrefix,
|
||||||
category,
|
category,
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
import newQuery from '../query/newQuery';
|
import newQuery from '../query/newQuery';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
|
import getElectron from './getElectron';
|
||||||
|
import { extensions } from '../stores';
|
||||||
|
|
||||||
export function canOpenByElectron(file, extensions) {
|
export function canOpenByElectron(file, extensions) {
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
@@ -45,3 +48,27 @@ export function openElectronFileCore(filePath, extensions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFileFormatFilters(extensions) {
|
||||||
|
return extensions.fileFormats.filter(x => x.readerFunc).map(x => ({ name: x.name, extensions: [x.extension] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileFormatExtensions(extensions) {
|
||||||
|
return extensions.fileFormats.filter(x => x.readerFunc).map(x => x.extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openElectronFile() {
|
||||||
|
const electron = getElectron();
|
||||||
|
const ext = get(extensions);
|
||||||
|
const filePaths = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
|
||||||
|
filters: [
|
||||||
|
{ name: `All supported files`, extensions: ['sql', ...getFileFormatExtensions(ext)] },
|
||||||
|
{ name: `SQL files`, extensions: ['sql'] },
|
||||||
|
...getFileFormatFilters(ext),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const filePath = filePaths && filePaths[0];
|
||||||
|
if (canOpenByElectron(filePath, ext)) {
|
||||||
|
openElectronFileCore(filePath, ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user