Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Jun 29, 2023
2 parents 0199da7 + e9c2d83 commit c4a3a7a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
52 changes: 51 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "resx-editor",
"displayName": "ResX Viewer and Editor",
"description": "Editor and viewer for resx/resw resource files",
"author": "Tim Heuer",
"author": {
"name": "Tim Heuer",
"url": "https://timheuer.com"
},
"publisher": "timheuer",
"icon": "icon.png",
"repository": {
Expand Down Expand Up @@ -104,6 +107,23 @@
"when": "config.resx-editor.experimentalDelete == true && activeCustomEditorId == 'resx-editor.editor'"
}
],
"editor/title": [
{
"command": "resx-editor.openInTextEditor",
"when": "activeCustomEditorId == 'resx-editor.editor' && activeEditorIsNotPreview == false",
"group": "navigation@1"
},
{
"command": "resx-editor.openPreview",
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'",
"group": "navigation@1"
},
{
"command": "resx-editor.openInResxEditor",
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'",
"group": "navigation@1"
}
],
"commandPalette": [
{
"command": "resx-editor.deleteResource",
Expand All @@ -112,6 +132,18 @@
{
"command": "resx-editor.addNewResource",
"when": "activeCustomEditorId == 'resx-editor.editor'"
},
{
"command": "resx-editor.openInTextEditor",
"when": "activeCustomEditorId == 'resx-editor.editor'"
},
{
"command": "resx-editor.openPreview",
"when": "false"
},
{
"command": "resx-editor.openInResxEditor",
"when": "(resourceExtname == '.resx' || resourceExtname == '.resw') && activeCustomEditorId != 'resx-editor.editor'"
}
]
},
Expand All @@ -125,6 +157,24 @@
"command": "resx-editor.addNewResource",
"title": "Add New Resource",
"category": "ResX Editor"
},
{
"command": "resx-editor.openInTextEditor",
"title": "Open in Text Editor",
"category": "ResX Editor",
"icon": "$(notebook-open-as-text)"
},
{
"command": "resx-editor.openPreview",
"title": "Open Preview",
"category": "ResX Editor",
"icon": "$(open-preview)"
},
{
"command": "resx-editor.openInResxEditor",
"title": "Open in ResX Editor",
"category": "ResX Editor",
"icon": "$(notebook-render-output)"
}
]
},
Expand Down
29 changes: 29 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { ResxProvider } from './resxProvider';
import { AppConstants } from './utilities/constants';

let outputChannel: vscode.OutputChannel;

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

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

let openPreviewCommand = vscode.commands.registerCommand(AppConstants.openPreviewCommand, () => {

const editor = vscode.window.activeTextEditor;

vscode.commands.executeCommand('vscode.openWith',
editor?.document?.uri,
AppConstants.viewTypeId,
{
preview: true,
viewColumn: vscode.ViewColumn.Beside
});
});

let openInResxEditor = vscode.commands.registerCommand(AppConstants.openInResxEditorCommand, () => {

const editor = vscode.window.activeTextEditor;

vscode.commands.executeCommand('vscode.openWith',
editor?.document?.uri,
AppConstants.viewTypeId,
{
preview: false,
viewColumn: vscode.ViewColumn.Active
});
});

context.subscriptions.push(openPreviewCommand);
context.subscriptions.push(openInResxEditor);
context.subscriptions.push(ResxProvider.register(context));

}
Expand Down
13 changes: 10 additions & 3 deletions src/resxProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
});

try {
printChannelOutput(document.uri.toString(), true);
if (!this.registered) {
printChannelOutput("deleteResource command registered", true);
this.registered = true;
let deleteCommand = vscode.commands.registerCommand(AppConstants.deleteResource, () => {
let deleteCommand = vscode.commands.registerCommand(AppConstants.deleteResourceCommand, () => {

this.currentPanel?.webview.postMessage({
type: 'delete'
});
});

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

let openInTextEditorCommand = vscode.commands.registerCommand(AppConstants.openInTextEditorCommand, () => {
printChannelOutput("openInTextEditor command called", true);
vscode.commands.executeCommand('workbench.action.reopenTextEditor', document?.uri);
});

this.context.subscriptions.push(openInTextEditorCommand);
this.context.subscriptions.push(deleteCommand);
this.context.subscriptions.push(addCommand);
}
Expand Down Expand Up @@ -104,7 +111,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
vscode.window.showInformationMessage(e.message);
return;
case 'add':
vscode.commands.executeCommand(AppConstants.commandAddNewResource);
vscode.commands.executeCommand(AppConstants.addNewResourceCommand);
return;

}
Expand Down
7 changes: 5 additions & 2 deletions src/utilities/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export class AppConstants {
static commandAddNewResource = 'resx-editor.addNewResource';
static deleteResource = 'resx-editor.deleteResource';
static addNewResourceCommand = 'resx-editor.addNewResource';
static deleteResourceCommand = 'resx-editor.deleteResource';
static viewTypeId = 'resx-editor.editor';
static promptKeyName = 'Provide a Key for the resource';
static promptValueName = 'Provide a Value for the resource';
static promptCommentName = 'Provide a Comment for the resource';
static addNewTitle = 'Add new resource';
static openInTextEditorCommand = 'resx-editor.openInTextEditor';
static openPreviewCommand = 'resx-editor.openPreview';
static openInResxEditorCommand = 'resx-editor.openInResxEditor';
}

0 comments on commit c4a3a7a

Please sign in to comment.