-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathextension.js
More file actions
73 lines (65 loc) · 2.57 KB
/
extension.js
File metadata and controls
73 lines (65 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var vscode = require('vscode');
var copypaste = require('copy-paste');
var path = require('path');
var sb = null;
function OnStatusBarUpdate( textEditor ) {
textEditor = textEditor ? textEditor : vscode.window.activeTextEditor;
if( textEditor ){
var config = vscode.workspace.getConfiguration('ActiveFileInStatusBar');
if( !textEditor.document || textEditor.document.isUntitled ){
sb.text = '';
sb.hide();
}
else {
var filePath = textEditor.document.fileName;
if (!config.fullpath){
filePath = vscode.workspace.asRelativePath(textEditor.document.fileName)
filePath = path.normalize(filePath)
}
sb.tooltip = 'Copy active file to clipboard';
if (config.revealFile) {
sb.tooltip = 'Reveal file';
}
sb.color = config.color;
sb.text = filePath;
sb.show();
}
}
}
function CreateStatusBar() {
var config = vscode.workspace.getConfiguration('ActiveFileInStatusBar');
var sb = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, -1);
sb.text = '';
sb.command = 'extension.ActiveFileInStatusBarClicked';
return sb;
}
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
var config = vscode.workspace.getConfiguration('ActiveFileInStatusBar');
if (config.enable) {
sb = CreateStatusBar();
vscode.window.onDidChangeActiveTextEditor( OnStatusBarUpdate );
vscode.workspace.onDidChangeConfiguration( OnStatusBarUpdate );
OnStatusBarUpdate( vscode.window.activeTextEditor );
context.subscriptions.push(sb);
}
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
var disposable = vscode.commands.registerCommand('extension.ActiveFileInStatusBarClicked', function (args) {
var config = vscode.workspace.getConfiguration('ActiveFileInStatusBar');
if (config.revealFile){
vscode.commands.executeCommand('workbench.action.files.revealActiveFileInWindows')
}
else {
copypaste.copy(sb.text)
}
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;