mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 03:45:59 +00:00
open file command
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { showModal } from '../modals/modalTools';
|
||||
import { get } from 'svelte/store';
|
||||
import newQuery from '../query/newQuery';
|
||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import getElectron from './getElectron';
|
||||
import { extensions } from '../stores';
|
||||
|
||||
export function canOpenByElectron(file, extensions) {
|
||||
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