mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 05:12:18 +00:00
feat: adding ability turn off .sql / .sqlite / .sqlseal / .db file view
This commit is contained in:
parent
a82863bd8a
commit
38717981b0
5 changed files with 77 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
"sqlseal": minor
|
||||
"sqlseal": major
|
||||
---
|
||||
|
||||
adding support for .sql and .sqlseal files
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ export class InitFactory {
|
|||
return new SQLSealFileView(leaf, dbManager, viewPluginGenerator, rendererRegistry, cellParser, settings, sync, db)
|
||||
})
|
||||
|
||||
// Register extensions for SQLSeal file view
|
||||
plugin.registerExtensions(['sql', 'sqlseal', 'sqlite', 'db'], SQLSEAL_FILE_VIEW)
|
||||
// Extensions for SQLSeal file view are registered by SettingsSQLControls
|
||||
|
||||
plugin.addCommand({
|
||||
id: 'sqlseal-command-explorer',
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export interface SQLSealSettings {
|
|||
enableViewer: boolean;
|
||||
enableEditing: boolean;
|
||||
enableJSONViewer: boolean;
|
||||
enableSQLViewer: boolean;
|
||||
enableDynamicUpdates: boolean;
|
||||
enableSyntaxHighlighting: boolean;
|
||||
defaultView: 'grid' | 'markdown' | 'html';
|
||||
|
|
@ -18,6 +19,7 @@ export const DEFAULT_SETTINGS: SQLSealSettings = {
|
|||
enableViewer: true,
|
||||
enableEditing: true,
|
||||
enableJSONViewer: true,
|
||||
enableSQLViewer: true,
|
||||
enableDynamicUpdates: true,
|
||||
enableSyntaxHighlighting: true,
|
||||
defaultView: 'grid',
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { SQLSealSettingsTab } from "./SQLSealSettingsTab";
|
|||
import { Settings } from "./Settings";
|
||||
import { SettingsCSVControls } from "./settingsTabSection/SettingsCSVControls";
|
||||
import { SettingsJsonControls } from "./settingsTabSection/SettingsJsonControls";
|
||||
import { SettingsSQLControls } from "./settingsTabSection/SettingsSQLControls";
|
||||
import { ViewPluginGeneratorType } from "../syntaxHighlight/viewPluginGenerator";
|
||||
|
||||
@(makeInjector<SettingsModule>()(["plugin", "settingsTab", "app", "settings", "viewPluginGenerator"]))
|
||||
|
|
@ -18,8 +19,9 @@ export class SettingsInit {
|
|||
) {
|
||||
const csvControl = new SettingsCSVControls(settings, app, plugin, viewPluginGenerator);
|
||||
const jsonControl = new SettingsJsonControls(settings, app, plugin, viewPluginGenerator);
|
||||
const sqlControl = new SettingsSQLControls(settings, app, plugin);
|
||||
|
||||
const controls = [csvControl, jsonControl];
|
||||
const controls = [csvControl, jsonControl, sqlControl];
|
||||
|
||||
settingsTab.registerControls(...controls);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
import { App, Plugin, Setting } from "obsidian";
|
||||
import { Settings } from "../Settings";
|
||||
import {
|
||||
checkTypeViewAvaiability,
|
||||
} from "../utils/viewInspector";
|
||||
import { SettingsControls } from "./SettingsControls";
|
||||
import { SQLSEAL_FILE_VIEW } from "../../explorer/SQLSealFileView";
|
||||
|
||||
export class SettingsSQLControls extends SettingsControls {
|
||||
private registeredView: string | null = null;
|
||||
|
||||
constructor(settings: Settings, app: App, plugin: Plugin) {
|
||||
super(settings, app, plugin)
|
||||
}
|
||||
|
||||
register() {
|
||||
if (this.settings.get("enableSQLViewer")) {
|
||||
const view = checkTypeViewAvaiability(this.app, 'sql');
|
||||
if (view && view !== SQLSEAL_FILE_VIEW) {
|
||||
this.registeredView = view;
|
||||
return;
|
||||
}
|
||||
|
||||
// Register extensions when enabling
|
||||
this.plugin.registerExtensions(['sql', 'sqlseal', 'sqlite', 'db'], SQLSEAL_FILE_VIEW);
|
||||
}
|
||||
}
|
||||
|
||||
unregister() {
|
||||
this.app.workspace.detachLeavesOfType(SQLSEAL_FILE_VIEW);
|
||||
(this.app as any).viewRegistry.unregisterExtensions([
|
||||
'sql', 'sqlseal', 'sqlite', 'db'
|
||||
]);
|
||||
}
|
||||
|
||||
display(el: HTMLDivElement) {
|
||||
el.empty();
|
||||
el.createEl("h2", { text: "SQL Explorer" });
|
||||
|
||||
const view = checkTypeViewAvaiability(this.app, "sql");
|
||||
|
||||
if (view && view !== SQLSEAL_FILE_VIEW) {
|
||||
el.createDiv({
|
||||
text: "SQL files are already handled by different plugin. To enable SQLSeal SQL viewer, disable other plugin that handles it",
|
||||
cls: "sqlseal-settings-warn",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
new Setting(el)
|
||||
.setName("Enable SQL Explorer")
|
||||
.setDesc(
|
||||
"Enables SQL, SQLSeal, SQLite and DB files in your vault to preview then and execture queries.",
|
||||
)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.settings.get("enableSQLViewer"))
|
||||
.onChange(async (value) => {
|
||||
this.settings.set("enableSQLViewer", !!value);
|
||||
if (!!value) {
|
||||
// Enabled
|
||||
this.register();
|
||||
} else {
|
||||
// Disabled
|
||||
this.unregister();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue