Skip to content

Commit

Permalink
Decouple UI update from internal state
Browse files Browse the repository at this point in the history
Previously the Paredit StatusBar's toggleBarItem was being updated
throughout multiple setters. Now we refactor the UI update into a
single method and remove the internal `_enabled` state which is now
unused.
  • Loading branch information
John Preston committed Sep 21, 2020
1 parent dccd384 commit b2a8ec4
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions src/paredit/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as paredit from './extension';

export class StatusBar {

private _enabled: Boolean;
private _visible: Boolean;
private _keyMap: String;

Expand All @@ -16,56 +15,42 @@ export class StatusBar {
this._toggleBarItem.text = "(λ)";
this._toggleBarItem.tooltip = "";
this._toggleBarItem.command = 'paredit.togglemode';
this._enabled = false;
this._visible = false;
this.keyMap = keymap;

paredit.onPareditKeyMapChanged((keymap) => {
this.keyMap = keymap;
})
})
}

get keyMap() {
return this._keyMap;
}

set keyMap(keymap: String) {

switch (keymap.trim().toLowerCase()) {
this._keyMap = keymap;
this.updateUIState();
}

updateUIState() {
switch (this.keyMap.trim().toLowerCase()) {
case 'original':
this._keyMap = 'original';
this.enabled = true;
this.visible = true;
this._toggleBarItem.text = "(λ)";
this._toggleBarItem.tooltip = "Toggle to strict Mode"
this._toggleBarItem.tooltip = "Toggle to strict Mode";
this._toggleBarItem.color = undefined;
break;
case 'strict':
this._keyMap = 'strict';
this.enabled = true;
this.visible = true;
this._toggleBarItem.text = "[λ]";
this._toggleBarItem.tooltip = "Toggle to original Mode"
this._toggleBarItem.tooltip = "Toggle to original Mode";
this._toggleBarItem.color = undefined;
break;
default:
this._keyMap = 'none';
this.enabled = false;
this.visible = true;
this._toggleBarItem.text = "λ";
this._toggleBarItem.tooltip = "Calva Paredit Keymap is set to none, Toggle to Strict Mode is Disabled"
}
}

get enabled() {
return this._enabled;
}

set enabled(value: Boolean) {
this._enabled = value;

if (this._enabled) {
this._toggleBarItem.color = undefined;
} else {
this._toggleBarItem.color = statusbar.color.inactive;
this._toggleBarItem.color = statusbar.color.inactive;
}
}

Expand All @@ -84,4 +69,4 @@ export class StatusBar {
dispose() {
this._toggleBarItem.dispose();
}
}
}

0 comments on commit b2a8ec4

Please sign in to comment.