Skip to content

Commit

Permalink
Made the leo-keys-on flag apearance customizable (shown in the status…
Browse files Browse the repository at this point in the history
…bar)
  • Loading branch information
boltex committed Feb 11, 2020
1 parent d3a67aa commit 6288f23
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as vscode from "vscode";
import { ConfigMembers } from "./types";
import { Constants } from "./constants";
import { Utils } from "./utils";


export class Config implements ConfigMembers {

Expand All @@ -25,7 +27,10 @@ export class Config implements ConfigMembers {

private _isSettingConfig: boolean = false;

constructor(private _context: vscode.ExtensionContext) { }
constructor(
private _context: vscode.ExtensionContext,
private _utils: Utils) {
}

public getConfig(): ConfigMembers {
return {
Expand Down Expand Up @@ -80,8 +85,14 @@ export class Config implements ConfigMembers {
} else {
// * Graphic and theme settings
this.invertNodeContrast = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.INVERT_NODES, false);
this.statusBarString = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.STATUSBAR_STRING, Constants.INTERFACE.STATUSBAR_STRING);
this.statusBarColor = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.STATUSBAR_COLOR, Constants.INTERFACE.STATUSBAR_COLOR);
this.statusBarString = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.STATUSBAR_STRING, Constants.INTERFACE.STATUSBAR_DEFAULT_STRING);
if (this.statusBarString.length > 8) {
this.statusBarString = Constants.INTERFACE.STATUSBAR_DEFAULT_STRING;
}
this.statusBarColor = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.STATUSBAR_COLOR, Constants.INTERFACE.STATUSBAR_DEFAULT_COLOR);
if (!this._utils.isHexColor(this.statusBarColor)) {
this.statusBarColor = Constants.INTERFACE.STATUSBAR_DEFAULT_COLOR;
}
// * Interface elements visibility
this.treeInExplorer = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.TREE_IN_EXPLORER, true);
this.showOpenAside = vscode.workspace.getConfiguration(Constants.CONFIGURATION_SECTION).get(Constants.CONFIGURATION.SHOW_OPEN_ASIDE, true);
Expand Down
5 changes: 3 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export class Constants {
ICON_LIGHT_PATH: "resources/light/box",
ICON_DARK_PATH: "resources/dark/box",
ICON_FILE_EXT: ".svg",
STATUSBAR_COLOR: "#fb7c47", // TODO : maybe get from config instead
STATUSBAR_STRING: "$(keyboard)🦁", // TODO : maybe rename or get from config instead
STATUSBAR_DEFAULT_COLOR: "fb7c47",
STATUSBAR_DEFAULT_STRING: "Literate", // 🦁
STATUSBAR_INDICATOR: "$(keyboard) ",
QUICK_OPEN_LEO_COMMANDS: ">leo: ",
EXPLORER_TREEVIEW_PREFIX: "LEO ",
TREEVIEW_TITLE: "OUTLINE",
Expand Down
9 changes: 5 additions & 4 deletions src/leoIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class LeoIntegration {
this._utils = new Utils();

// * Get configuration settings
this.config = new Config(_context);
this.config = new Config(_context, this._utils);
this.config.getLeoIntegSettings();

// * Build Icon filename paths
Expand Down Expand Up @@ -136,9 +136,9 @@ export class LeoIntegration {

// * Status bar: Show keyboard-Shortcut-Flag to signify Leo keyboard shortcuts are active
this.leoStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
this.leoStatusBarItem.color = Constants.INTERFACE.STATUSBAR_COLOR;
this.leoStatusBarItem.color = this.config.statusBarColor;
this.leoStatusBarItem.command = "leointeg.test"; // just call test function for now to help debugging
this.leoStatusBarItem.text = Constants.INTERFACE.STATUSBAR_STRING;
this.leoStatusBarItem.text = Constants.INTERFACE.STATUSBAR_INDICATOR + this.config.statusBarString;
this.leoStatusBarItem.tooltip = Constants.USER_MESSAGES.STATUSBAR_TOOLTIP_ON;
_context.subscriptions.push(this.leoStatusBarItem);
this.leoStatusBarItem.hide();
Expand Down Expand Up @@ -1084,8 +1084,9 @@ export class LeoIntegration {
clearTimeout(this._updateStatusBarTimeout);
}
vscode.commands.executeCommand(Constants.VSCODE_COMMANDS.SET_CONTEXT, Constants.CONTEXT_FLAGS.LEO_SELECTED, !!this.leoObjectSelected);
this.leoStatusBarItem.text = Constants.INTERFACE.STATUSBAR_INDICATOR + this.config.statusBarString;
if (this.leoObjectSelected && this.fileOpenedReady) { // * Also check in constructor for statusBar properties (the createStatusBarItem call itself)
this.leoStatusBarItem.color = Constants.INTERFACE.STATUSBAR_COLOR;
this.leoStatusBarItem.color = "#" + this.config.statusBarColor;
this.leoStatusBarItem.tooltip = Constants.USER_MESSAGES.STATUSBAR_TOOLTIP_ON;
} else {
this.leoStatusBarItem.color = this.statusbarNormalColor;
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ export class Utils {
"\"}";
}

public isHexColor(hex: string): boolean {
return typeof hex === 'string'
&& hex.length === 6
&& !isNaN(Number('0x' + hex));
}

}

0 comments on commit 6288f23

Please sign in to comment.