Skip to content

Commit e40efb6

Browse files
committed
Add keyvalue file memory
1 parent 676c79d commit e40efb6

12 files changed

Lines changed: 572 additions & 22 deletions

icons/forget-kv-dark.png

1.24 KB
Loading

icons/forget-kv-dark.svg

Lines changed: 128 additions & 0 deletions
Loading

icons/forget-kv-light.png

1.05 KB
Loading

icons/forget-kv-light.svg

Lines changed: 98 additions & 0 deletions
Loading

icons/remember-kv-dark.png

1.29 KB
Loading

icons/remember-kv-dark.svg

Lines changed: 126 additions & 0 deletions
Loading

icons/remember-kv-light.png

1.1 KB
Loading

icons/remember-kv-light.svg

Lines changed: 95 additions & 0 deletions
Loading

package.json

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"id": "fgd",
118118
"configuration": "./lang-config-kv.json",
119119
"aliases": [
120-
"FGD",
120+
"Valve FGD",
121121
"Forge Game Data",
122122
"Hammer Game Data"
123123
],
@@ -129,8 +129,8 @@
129129
"id": "captions",
130130
"configuration": "./lang-config-kv.json",
131131
"aliases": [
132-
"Source Engine Captions",
133-
"Source Engine Subtitles"
132+
"Valve Source Engine Captions",
133+
"Valve Source Engine Subtitles"
134134
],
135135
"firstLine": "^\"?(?i)lang(?-i)\"?",
136136
"filenamePatterns": [
@@ -142,8 +142,8 @@
142142
"id": "cfg",
143143
"configuration": "./lang-config-kv.json",
144144
"aliases": [
145-
"Source Engine Configuration",
146-
"Source Engine Commands"
145+
"Valve Source Engine Configuration",
146+
"Valve Source Engine Commands"
147147
],
148148
"extensions": [
149149
".cfg"
@@ -209,7 +209,7 @@
209209
{
210210
"id": "fxc",
211211
"aliases": [
212-
"FXC Shader"
212+
"Valve FXC Shader"
213213
],
214214
"extensions": [
215215
".fxc",
@@ -297,12 +297,22 @@
297297
},
298298
{
299299
"command": "kv.remember",
300-
"title": "Remember file path as Valve KeyValue file",
300+
"title": "Remember this as KeyValue file",
301301
"shortTitle": "Remember KeyValue File",
302302
"category": "KeyValue",
303303
"icon": {
304-
"light": "./icons/start-light.svg",
305-
"dark": "./icons/start-dark.svg"
304+
"light": "./icons/remember-kv-light.png",
305+
"dark": "./icons/remember-kv-dark.png"
306+
}
307+
},
308+
{
309+
"command": "kv.forget",
310+
"title": "Forget this as KeyValue file",
311+
"shortTitle": "Forget KeyValue File",
312+
"category": "KeyValue",
313+
"icon": {
314+
"light": "./icons/forget-kv-light.png",
315+
"dark": "./icons/forget-kv-dark.png"
306316
}
307317
}
308318
],
@@ -317,6 +327,16 @@
317327
"when": "resourceLangId == qc && resourceScheme == 'file'",
318328
"command": "mdl.compile",
319329
"group": "navigation"
330+
},
331+
{
332+
"when": "sourceEngine.showKvForget && resourceScheme == 'file'",
333+
"command": "kv.forget",
334+
"group": "navigation"
335+
},
336+
{
337+
"when": "sourceEngine.showKvRemember && resourceScheme == 'file'",
338+
"command": "kv.remember",
339+
"group": "navigation"
320340
}
321341
]
322342
},
@@ -397,16 +417,6 @@
397417
"type": "boolean",
398418
"default": true,
399419
"description": "Automatically use keyvalue file format for common file names like gameinfo.txt, subtitles_english.txt..."
400-
},
401-
"sourceEngine.detectKeyvalueFiles.customRules": {
402-
"type": "array",
403-
"default": [],
404-
"description": "Define custom rules to detect keyvalue files based on the file name"
405-
},
406-
"sourceEngine.detectKeyvalueFiles.onlyUseCustomRules": {
407-
"type": "boolean",
408-
"default": false,
409-
"description": "Disables all the common file name rules that come with the extension. Useful if some standard rule is causing problems and you would rather define them yourself"
410420
}
411421
}
412422
},

src/KvFileDetection.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path";
22
import * as vscode from "vscode";
33
import * as main from "./main";
4+
import { isRemembered, updateForgetRememberCommandContext } from "./KvFileMemory";
45

56
type DetectableLanguageId = "keyvalue" | "soundscript" | "captions";
67

@@ -41,12 +42,20 @@ export function init(context: vscode.ExtensionContext): void {
4142

4243
function onChangeEditor(document: vscode.TextDocument): void {
4344
main.debugOutput.appendLine(`Active editor changed to ${document.uri.fsPath}`);
45+
updateForgetRememberCommandContext(document);
4446

4547
detectKeyvalueFile(document);
4648
}
4749

4850
function detectKeyvalueFile(document: vscode.TextDocument): void {
4951

52+
if(isRemembered(document.uri.fsPath)) {
53+
main.debugOutput.appendLine(`Remembered keyvalue file opened (${document.uri.fsPath})`);
54+
vscode.languages.setTextDocumentLanguage(document, "keyvalue");
55+
return;
56+
}
57+
58+
5059
const enabled = main.config.get("detectKeyvalueFiles.enabled");
5160
if(!enabled) {
5261
return;
@@ -55,6 +64,10 @@ function detectKeyvalueFile(document: vscode.TextDocument): void {
5564
main.debugOutput.appendLine("File has language id: " + document.languageId);
5665
if(document.languageId !== "plaintext") return;
5766

67+
detectKeyValueFileFromName(document);
68+
}
69+
70+
function detectKeyValueFileFromName(document: vscode.TextDocument): void {
5871
main.debugOutput.appendLine(`Potential kv file opened (${document.uri.fsPath})`);
5972

6073
const langId = getPotentialKvFileLanguageId(document);

0 commit comments

Comments
 (0)