Skip to content

Commit

Permalink
adding command to open mapped views
Browse files Browse the repository at this point in the history
  • Loading branch information
spoo-bar committed Jul 24, 2019
1 parent ab2c639 commit a276d98
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to the "Biffy" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## 1.6.0
### Added
* Command to open a mapped file based on the GUID

## 1.5.2
### Changed
* Running mapping on a bxml page, now saves and updates the corresponding content in the BIF-Source/mapped folder.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This is the repository for VS Code extension for BIF.
* Syntax highlighting
* Block commenting (`Ctrl + K + C` and `Ctrl + K + U`)
* Snippet completion
* Open premapped bxml view based in GUID


## Configuration
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Biffy",
"description": "Language tools for BIF",
"publisher": "spoorthi",
"version": "1.5.3",
"version": "1.6.0",
"license": "SEE LICENSE IN LICENSE",
"engines": {
"vscode": "^1.30.0"
Expand All @@ -22,7 +22,8 @@
},
"activationEvents": [
"onLanguage:bif",
"onCommand:biffy.mapObject"
"onCommand:biffy.mapObject",
"onCommand:biffy.openMappedFile"
],
"main": "./out/src/extension",
"icon": "images/icon.png",
Expand Down Expand Up @@ -86,11 +87,15 @@
"commands": [
{
"command": "biffy.mapObject",
"title": "Generate Merged Preview"
"title": "Biffy : Generate Merged Preview"
},
{
"command": "biffy.generateGuid",
"title": "Generate GUID"
"title": "Biffy : Generate GUID"
},
{
"command": "biffy.openMappedFile",
"title": "Biffy : Open Mapped File"
}
],
"keybindings": [
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.window.activeTextEditor.insertSnippet(new vscode.SnippetString(guid));
}
});

vscode.commands.registerCommand('biffy.openMappedFile', async () => {
vscode.window.showInputBox({ prompt : "Which mapped file to open ?" }).then(value => {
bifMapObject.openMappedFile(value);
});
});

}
27 changes: 26 additions & 1 deletion src/features/BifMapObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as path from 'path';
import * as fs from 'fs';
import Helper from '../utils/helper';
import { ITypeScriptServiceClient } from '../ITypeScriptServiceClient';

Expand Down Expand Up @@ -54,6 +55,30 @@ export default class BifMapObject {
return path.basename(document.fileName);
}

public openMappedFile(mappedId : string) {
if(this.helper.checkGuidValidity(mappedId)) {
var mappedFolderPath = path.join(this.bifSourcePath, "mapped");
if(fs.existsSync(mappedFolderPath)) {
let file = fs.readdirSync(mappedFolderPath).filter(file => fs.statSync(path.join(mappedFolderPath, file)).isFile()).find(file => file.startsWith(mappedId));
if(file) {
var filePath = path.join(mappedFolderPath, file);
vscode.workspace.openTextDocument(vscode.Uri.file(filePath)).then(document => {
vscode.window.showTextDocument(document).then();
});
}
else {
vscode.window.showErrorMessage("File not found in mapped folder : " + mappedId + ".bxml");
}
}
else {
vscode.window.showErrorMessage("Mapped folder doesn't exist at " + mappedFolderPath);
}
}
else {
vscode.window.showErrorMessage("Input wasnt a valid guid");
}
}

private isBXMLFile(mappedFileName) : boolean {
var ext = mappedFileName.substr(mappedFileName.lastIndexOf('.') + 1);
if(ext === "bxml") {
Expand Down

0 comments on commit a276d98

Please sign in to comment.