Skip to content
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ only tested on Ubuntu and OSX, so may not other Linuxs, and/or Windows

## Release Notes

### 0.1.2
fixed issue [#12](https://github.com/nexus-uw/vscode-gtm/issues/12) and [#7](https://github.com/nexus-uw/vscode-gtm/issues/7)

### 0.1.1 (arbitrary minor version bump)
fixed https://github.com/nexus-uw/vscode-gtm/issues/5
updated README to have proper version
Expand Down
48 changes: 29 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export function activate(context: vscode.ExtensionContext) {
// check if gtm is installed + available
run_cmd('gtm', ['verify', '>= 1.2.1'])
.then((res: Result) => {
if(res.output != 'true'){
vscode.window.showWarningMessage('Installed gtm version is below v1.2.1. Please update your gtm installation.');
}
if (res.output != 'true') {
vscode.window.showWarningMessage('Installed gtm version is below v1.2.1. Please update your gtm installation.');
}
}, (res: Result) => {
if (res.code < 0) {
vscode.window.showErrorMessage('gtm is not available on your $PATH. please install it first');
Expand All @@ -40,7 +40,7 @@ export function activate(context: vscode.ExtensionContext) {

let gtmStatusBar = new GTMStatusBar()

function handleUpdateEvent(fileName: string){
function handleUpdateEvent(fileName: string) {
const now = new Date();
// if a new file is being saved OR it have been at least MIN_UPDATE_FREQUENCE_MS, record it
if (fileName !== lastSavedFileName || (now.getTime() - lastUpdated.getTime()) >= MIN_UPDATE_FREQUENCE_MS) {
Expand All @@ -55,32 +55,42 @@ export function activate(context: vscode.ExtensionContext) {
vscode.workspace.onDidSaveTextDocument((e: vscode.TextDocument) => handleUpdateEvent(e.fileName), this, subscriptions);

// report to gtm everytime the user's selection of text changes
vscode.window.onDidChangeTextEditorSelection((e:vscode.TextEditorSelectionChangeEvent) => handleUpdateEvent(e.textEditor.document.fileName), this, subscriptions);
vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => {
if (e && e.textEditor && e.textEditor.document) {
handleUpdateEvent(e.textEditor.document.fileName);
}
}, this, subscriptions);

// report to gtm everytime the user switches textEditors
vscode.window.onDidChangeActiveTextEditor((e:vscode.TextEditor) => handleUpdateEvent(e.document.fileName), this, subscriptions);
vscode.window.onDidChangeActiveTextEditor((e: vscode.TextEditor) => {
// Note that the event also fires when the active editor changes to undefined.
if (e && e.document) {
handleUpdateEvent(e.document.fileName);
}

}, this, subscriptions);
}

class GTMStatusBar {
private statusBarItem: vscode.StatusBarItem;

public updateStatus(statusText: string) {

// Create as needed
if (!this.statusBarItem) {
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
}
// Create as needed
if (!this.statusBarItem) {
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
}

// Get the current text editor
let editor = vscode.window.activeTextEditor;
if (!editor) {
this.statusBarItem.hide();
return;
}
// Get the current text editor
let editor = vscode.window.activeTextEditor;
if (!editor) {
this.statusBarItem.hide();
return;
}

// Update the status bar
this.statusBarItem.text = statusText;
this.statusBarItem.show();
// Update the status bar
this.statusBarItem.text = statusText;
this.statusBarItem.show();
}
}

Expand Down