Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

57 handle settings theme change without vscode reload #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions media/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

<link href="{{styleResetUri}}" rel="stylesheet" />
<link href="{{styleMainUri}}" rel="stylesheet" />
<link href="{{styleMainColorUri}}" rel="stylesheet" />
<link href="{{styleMainColorUri}}" rel="stylesheet" id="main-color-theme"/>
<link href="{{styleTabulatorUri}}" rel="stylesheet" />
<link href="{{styleFontAwesomeUri}}" rel="stylesheet" />
<link href="{{styleTabsUri}}" rel="stylesheet" />
<link href="{{styleTabsColorUri}}" rel="stylesheet" />
<link href="{{styleTabsColorUri}}" rel="stylesheet" id="tabs-color-theme"/>

<title>Parquet Visualizer</title>
<script nonce="{{nonce}}" type="text/javascript" src="{{scripts}}/tabulator/tabulator.min.js"></script>
Expand Down
39 changes: 29 additions & 10 deletions media/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
let metadataTable;
let resultsTable;

let aceEditor;

let dataTableBuilt = false;
let queryTableBuilt = false;

Expand Down Expand Up @@ -316,13 +318,13 @@
queryResultsContainer.id = "query-results";
queryTabPanel?.appendChild(queryResultsContainer);

var editor = ace.edit("editor");
aceEditor = ace.edit("editor");

editor.setTheme(aceTheme);
editor.session.setMode("ace/mode/sql");
editor.setValue(defaultQuery);
aceEditor.setTheme(aceTheme);
aceEditor.session.setMode("ace/mode/sql");
aceEditor.setValue(defaultQuery);

editor.setOptions({
aceEditor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
Expand All @@ -337,11 +339,11 @@
var langTools = ace.require("ace/ext/language_tools");
langTools.addCompleter(completer);

editor.commands.addCommand({
aceEditor.commands.addCommand({
name: 'runQuery',
bindKey: shortCutMapping,
exec: function(editor) {
runQuery(editor);
exec: function(aceEditor) {
runQuery(aceEditor);
}
});

Expand All @@ -353,7 +355,7 @@
runQueryButton.classList.add("tabulator-page", "flex-button");

runQueryButton?.addEventListener('click', (e) => {
runQuery(editor);
runQuery(aceEditor);
});
buttonContainer?.appendChild(runQueryButton);

Expand All @@ -363,7 +365,7 @@
clearQueryTextButton.classList.add("tabulator-page", "flex-button");

clearQueryTextButton?.addEventListener('click', (e) => {
editor.setValue("");
aceEditor.setValue("");
});

buttonContainer?.appendChild(clearQueryTextButton);
Expand Down Expand Up @@ -547,6 +549,13 @@
resetQueryControl();
}

function handleColorThemeChangeById(id, href){
var mainColorThemeLink = document.getElementById(id);
if (mainColorThemeLink.rel === "stylesheet"){
mainColorThemeLink.href = href;
}
}

function updateTable(
/** @type {any} */ data,
/** @type {any} */ headers,
Expand Down Expand Up @@ -960,6 +969,16 @@
}
break;
}
case 'colorThemeChange': {
console.log(body);
handleColorThemeChangeById("main-color-theme", body.pathMainCssFile);
handleColorThemeChangeById("tabs-color-theme", body.pathTabsCssFile);

// Set ace theme
aceEditor.setTheme(body.aceTheme);

break;
}
case 'error': {
handleError();
break;
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
"parquet-visualizer.dateTimeFormat": {
"markdownDescription": "Set datetime format for columns of timestamp type. Defaults to ISO8601. You can set a custom format like `YYYY-MM-DD HH:mm:ss.SSS Z`. Find rules for formatting [here](https://www.npmjs.com/package/date-and-time#formatdateobj-arg-utc).",
"type": "string",
"enumDescriptions": [
"ISO8601",
"RFC2822"
],
"default": "ISO8601"
},
"parquet-visualizer.outputDateTimeFormatInUTC": {
Expand Down
68 changes: 51 additions & 17 deletions src/parquet-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,26 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
async openCustomDocument(uri: vscode.Uri): Promise<CustomParquetDocument> {
// console.log(`openCustomDocument(uri: ${uri})`);
const document: CustomParquetDocument = await CustomParquetDocument.create(uri);

this.listeners.push(vscode.window.onDidChangeActiveColorTheme((e => {
const cssPathNames = getCssPathNameByVscodeTheme(e.kind);
const pathMainCssFile = vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', cssPathNames.mainCssFile
);

const pathTabsCssFile = vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', cssPathNames.tabsCssFile
);

const aceTheme = getAceTheme(e.kind);
for (const webviewPanel of this.webviews.get(document.uri)) {
this.postMessage(webviewPanel, 'colorThemeChange', {
aceTheme: aceTheme,
pathMainCssFile: webviewPanel.webview.asWebviewUri(pathMainCssFile).toString(true),
pathTabsCssFile: webviewPanel.webview.asWebviewUri(pathTabsCssFile).toString(true)
});
}
})));

this.listeners.push(vscode.workspace.onDidChangeConfiguration((e: vscode.ConfigurationChangeEvent) => {
if (affectsDocument(e)) {
Expand Down Expand Up @@ -538,12 +558,7 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
// get Code completions for the editor
const aceEditorCompletions = this.getAceEditorCompletions(schema);

let aceTheme = '';
if (vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Light) {
aceTheme = 'ace/theme/dawn';
} else {
aceTheme = 'ace/theme/idle_fingers';
}
const aceTheme = getAceTheme(vscode.window.activeColorTheme.kind);

const data = {
headers: headers,
Expand Down Expand Up @@ -659,21 +674,13 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
const styleVSCodeUri = webview.asWebviewUri(vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', 'vscode.css'));

let tabsColorCssFile = '';
let parquetEditorColorCssFile = '';
if (vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Light) {
tabsColorCssFile = 'tabs-color-light.css';
parquetEditorColorCssFile = 'parquet-visualizer-color-light.css';
} else {
tabsColorCssFile = 'tabs-color-dark.css';
parquetEditorColorCssFile = 'parquet-visualizer-color-dark.css';
}
const cssPathNames = getCssPathNameByVscodeTheme(vscode.window.activeColorTheme.kind);

const styleMainUri = webview.asWebviewUri(vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', 'parquet-visualizer.css'));

const styleMainColorUri = webview.asWebviewUri(vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', parquetEditorColorCssFile));
this.context.extensionUri, 'media', 'styles', cssPathNames.mainCssFile));

const styleTabulatorUri = webview.asWebviewUri(vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', 'tabulator', 'tabulator.min.css'));
Expand All @@ -685,7 +692,7 @@ export class ParquetEditorProvider implements vscode.CustomReadonlyEditorProvide
this.context.extensionUri, 'media', 'styles', 'tabs.css'));

const styleTabsColorUri = webview.asWebviewUri(vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'styles', tabsColorCssFile));
this.context.extensionUri, 'media', 'styles', cssPathNames.tabsCssFile));

const htmlUri = vscode.Uri.joinPath(
this.context.extensionUri, 'media', 'index.html'
Expand Down Expand Up @@ -749,4 +756,31 @@ class WebviewCollection {
this._webviews.delete(entry);
});
}
}

function getAceTheme(themeKind: vscode.ColorThemeKind){
let aceTheme = '';
if (themeKind === vscode.ColorThemeKind.Light) {
aceTheme = 'ace/theme/dawn';
} else {
aceTheme = 'ace/theme/idle_fingers';
}
return aceTheme;
}

function getCssPathNameByVscodeTheme(themeKind: vscode.ColorThemeKind){
let tabsColorCssFile = '';
let parquetEditorColorCssFile = '';
if (themeKind === vscode.ColorThemeKind.Light) {
tabsColorCssFile = 'tabs-color-light.css';
parquetEditorColorCssFile = 'parquet-visualizer-color-light.css';
} else {
tabsColorCssFile = 'tabs-color-dark.css';
parquetEditorColorCssFile = 'parquet-visualizer-color-dark.css';
}

return {
mainCssFile: parquetEditorColorCssFile,
tabsCssFile: tabsColorCssFile
};
}
Loading