Skip to content

Commit e9c2d83

Browse files
committed
Adding preview and toggle
1 parent 39f82aa commit e9c2d83

File tree

4 files changed

+91
-5
lines changed

4 files changed

+91
-5
lines changed

package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@
107107
"when": "config.resx-editor.experimentalDelete == true && activeCustomEditorId == 'resx-editor.editor'"
108108
}
109109
],
110+
"editor/title": [
111+
{
112+
"command": "resx-editor.openInTextEditor",
113+
"when": "activeCustomEditorId == 'resx-editor.editor' && activeEditorIsNotPreview == false",
114+
"group": "navigation@1"
115+
},
116+
{
117+
"command": "resx-editor.openPreview",
118+
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'",
119+
"group": "navigation@1"
120+
},
121+
{
122+
"command": "resx-editor.openInResxEditor",
123+
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'",
124+
"group": "navigation@1"
125+
}
126+
],
110127
"commandPalette": [
111128
{
112129
"command": "resx-editor.deleteResource",
@@ -115,6 +132,18 @@
115132
{
116133
"command": "resx-editor.addNewResource",
117134
"when": "activeCustomEditorId == 'resx-editor.editor'"
135+
},
136+
{
137+
"command": "resx-editor.openInTextEditor",
138+
"when": "activeCustomEditorId == 'resx-editor.editor'"
139+
},
140+
{
141+
"command": "resx-editor.openPreview",
142+
"when": "false"
143+
},
144+
{
145+
"command": "resx-editor.openInResxEditor",
146+
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'"
118147
}
119148
]
120149
},
@@ -128,6 +157,24 @@
128157
"command": "resx-editor.addNewResource",
129158
"title": "Add New Resource",
130159
"category": "ResX Editor"
160+
},
161+
{
162+
"command": "resx-editor.openInTextEditor",
163+
"title": "Open in Text Editor",
164+
"category": "ResX Editor",
165+
"icon": "$(notebook-open-as-text)"
166+
},
167+
{
168+
"command": "resx-editor.openPreview",
169+
"title": "Open Preview",
170+
"category": "ResX Editor",
171+
"icon": "$(open-preview)"
172+
},
173+
{
174+
"command": "resx-editor.openInResxEditor",
175+
"title": "Open in ResX Editor",
176+
"category": "ResX Editor",
177+
"icon": "$(notebook-render-output)"
131178
}
132179
]
133180
},

src/extension.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import { ResxProvider } from './resxProvider';
3+
import { AppConstants } from './utilities/constants';
34

45
let outputChannel: vscode.OutputChannel;
56

@@ -9,6 +10,34 @@ export function activate(context: vscode.ExtensionContext) {
910

1011
printChannelOutput("ResX Editor extension activated.", true);
1112

13+
let openPreviewCommand = vscode.commands.registerCommand(AppConstants.openPreviewCommand, () => {
14+
15+
const editor = vscode.window.activeTextEditor;
16+
17+
vscode.commands.executeCommand('vscode.openWith',
18+
editor?.document?.uri,
19+
AppConstants.viewTypeId,
20+
{
21+
preview: true,
22+
viewColumn: vscode.ViewColumn.Beside
23+
});
24+
});
25+
26+
let openInResxEditor = vscode.commands.registerCommand(AppConstants.openInResxEditorCommand, () => {
27+
28+
const editor = vscode.window.activeTextEditor;
29+
30+
vscode.commands.executeCommand('vscode.openWith',
31+
editor?.document?.uri,
32+
AppConstants.viewTypeId,
33+
{
34+
preview: false,
35+
viewColumn: vscode.ViewColumn.Active
36+
});
37+
});
38+
39+
context.subscriptions.push(openPreviewCommand);
40+
context.subscriptions.push(openInResxEditor);
1241
context.subscriptions.push(ResxProvider.register(context));
1342

1443
}

src/resxProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
3838
});
3939

4040
try {
41+
printChannelOutput(document.uri.toString(), true);
4142
if (!this.registered) {
4243
printChannelOutput("deleteResource command registered", true);
4344
this.registered = true;
44-
let deleteCommand = vscode.commands.registerCommand(AppConstants.deleteResource, () => {
45+
let deleteCommand = vscode.commands.registerCommand(AppConstants.deleteResourceCommand, () => {
4546

4647
this.currentPanel?.webview.postMessage({
4748
type: 'delete'
4849
});
4950
});
5051

51-
let addCommand = vscode.commands.registerCommand(AppConstants.commandAddNewResource, () => {
52+
let addCommand = vscode.commands.registerCommand(AppConstants.addNewResourceCommand, () => {
5253
// get all the inputs we need
5354
const inputs = newResourceInput(this.context);
5455
// then do something with them
@@ -62,6 +63,12 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
6263
});
6364
});
6465

66+
let openInTextEditorCommand = vscode.commands.registerCommand(AppConstants.openInTextEditorCommand, () => {
67+
printChannelOutput("openInTextEditor command called", true);
68+
vscode.commands.executeCommand('workbench.action.reopenTextEditor', document?.uri);
69+
});
70+
71+
this.context.subscriptions.push(openInTextEditorCommand);
6572
this.context.subscriptions.push(deleteCommand);
6673
this.context.subscriptions.push(addCommand);
6774
}
@@ -104,7 +111,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
104111
vscode.window.showInformationMessage(e.message);
105112
return;
106113
case 'add':
107-
vscode.commands.executeCommand(AppConstants.commandAddNewResource);
114+
vscode.commands.executeCommand(AppConstants.addNewResourceCommand);
108115
return;
109116

110117
}

src/utilities/constants.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export class AppConstants {
2-
static commandAddNewResource = 'resx-editor.addNewResource';
3-
static deleteResource = 'resx-editor.deleteResource';
2+
static addNewResourceCommand = 'resx-editor.addNewResource';
3+
static deleteResourceCommand = 'resx-editor.deleteResource';
44
static viewTypeId = 'resx-editor.editor';
55
static promptKeyName = 'Provide a Key for the resource';
66
static promptValueName = 'Provide a Value for the resource';
77
static promptCommentName = 'Provide a Comment for the resource';
88
static addNewTitle = 'Add new resource';
9+
static openInTextEditorCommand = 'resx-editor.openInTextEditor';
10+
static openPreviewCommand = 'resx-editor.openPreview';
11+
static openInResxEditorCommand = 'resx-editor.openInResxEditor';
912
}

0 commit comments

Comments
 (0)