-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor to use classes in most places * Handle case where updates to different files in quick succession could cancel pending (debounced) update for the first * More granular updating of config values * Don't use lodash * Render decorations from cache when switching active files
- Loading branch information
1 parent
4a8f0e9
commit 59767ca
Showing
8 changed files
with
298 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
import * as vscode from "vscode"; | ||
import { | ||
Disposable, | ||
window, | ||
StatusBarAlignment, | ||
StatusBarItem, | ||
workspace, | ||
ConfigurationChangeEvent, | ||
} from "vscode"; | ||
import { ENABLED_CONFIG, TOGGLE_COMMAND, MENU_BAR_CONFIG } from "./constants"; | ||
|
||
export function activateMenuBarItem(subscriptions: { dispose(): any }[]) { | ||
const statusBarItem = vscode.window.createStatusBarItem( | ||
vscode.StatusBarAlignment.Left, | ||
100 | ||
); | ||
statusBarItem.command = TOGGLE_COMMAND; | ||
const PLAY = "\u25BA"; | ||
const STOP = "\u25A0"; | ||
|
||
const PLAY = "\u25BA"; | ||
const STOP = "\u25A0"; | ||
export default class MenuBarItem implements Disposable { | ||
private readonly _disposables: Disposable[] = []; | ||
private readonly _statusBarItem: StatusBarItem; | ||
constructor() { | ||
this._disposables = []; | ||
this._statusBarItem = window.createStatusBarItem( | ||
StatusBarAlignment.Left, | ||
100 // What should this number be? | ||
); | ||
this._statusBarItem.command = TOGGLE_COMMAND; | ||
|
||
function setText() { | ||
const config = vscode.workspace.getConfiguration(); | ||
this._disposables.push(this._statusBarItem); | ||
|
||
this._setText(); | ||
this._setVisibility(); | ||
|
||
workspace.onDidChangeConfiguration( | ||
this._handleConfigChange, | ||
this, | ||
this._disposables | ||
); | ||
} | ||
|
||
_handleConfigChange(event: ConfigurationChangeEvent) { | ||
if (event.affectsConfiguration(ENABLED_CONFIG)) { | ||
this._setText(); | ||
} | ||
if (event.affectsConfiguration(MENU_BAR_CONFIG)) { | ||
this._setVisibility(); | ||
} | ||
} | ||
|
||
_setText() { | ||
const config = workspace.getConfiguration(); | ||
const icon = config.get(ENABLED_CONFIG) ? STOP : PLAY; | ||
const action = config.get(ENABLED_CONFIG) ? "hide" : "show"; | ||
statusBarItem.text = `(${icon})`; | ||
statusBarItem.tooltip = `Click to ${action} implicit parentheses.`; | ||
this._statusBarItem.text = `(${icon})`; | ||
this._statusBarItem.tooltip = `Click to ${action} implicit parentheses.`; | ||
} | ||
|
||
function setVisibility() { | ||
if (vscode.workspace.getConfiguration().get(MENU_BAR_CONFIG)) { | ||
statusBarItem.show(); | ||
_setVisibility() { | ||
if (workspace.getConfiguration().get(MENU_BAR_CONFIG)) { | ||
this._statusBarItem.show(); | ||
} else { | ||
statusBarItem.hide(); | ||
this._statusBarItem.hide(); | ||
} | ||
} | ||
|
||
setText(); | ||
setVisibility(); | ||
|
||
vscode.workspace.onDidChangeConfiguration( | ||
(event) => { | ||
if (event.affectsConfiguration(ENABLED_CONFIG)) { | ||
setText(); | ||
} | ||
if (event.affectsConfiguration(MENU_BAR_CONFIG)) { | ||
setVisibility(); | ||
} | ||
}, | ||
null, | ||
subscriptions | ||
); | ||
subscriptions.push(statusBarItem); | ||
dispose() { | ||
this._disposables.forEach((disposable) => disposable.dispose()); | ||
} | ||
} |
Oops, something went wrong.