Quellcode durchsuchen

Add header on file of you have extension with header

Etheram68 vor 5 Jahren
Ursprung
Commit
0386a37c23
4 geänderte Dateien mit 51 neuen und 3 gelöschten Zeilen
  1. 3 0
      README.md
  2. 12 1
      package.json
  3. 32 1
      src/basicInput.ts
  4. 4 1
      src/template.ts

+ 3 - 0
README.md

@@ -29,6 +29,9 @@ To report a bug or ask for a feature, please open a [Github issue](https://githu
 
 ## Release Notes
 
+### 0.1.9
+Remove multi choice for working in
+
 ### 0.1.7
 Add multi posibiliter choice for create a class
 

+ 12 - 1
package.json

@@ -2,7 +2,7 @@
 	"name": "canonicalclasscpp",
 	"displayName": "42 Canonical Class CPP",
 	"description": "This extension is to automatically create a canonical hpp and cpp file",
-	"version": "0.1.8",
+	"version": "0.1.9",
 	"publisher": "frfreyCanonicalClassCPP",
 	"icon": "42.png",
 	"repository": {
@@ -25,6 +25,17 @@
 	],
 	"main": "./out/extension.js",
 	"contributes": {
+		"configuration": {
+			"properties": {
+				"headercppclass.headerId": {
+					"title": "Header ID",
+					"type": "string",
+					"scope": "window",
+					"default": "101header.insertHeader",
+					"description": "The id of the command to execute at the creation of the skeleton (example: 42header.insertHeader). CAREFUL: this will actually EXECUTE the command and unknown commands will result in no skeleton creations! Leave it to blank for no command to execute"
+				}
+			}
+		},
 		"commands": [
 			{
 				"command": "canonicalclass.makeclass",

+ 32 - 1
src/basicInput.ts

@@ -11,6 +11,7 @@
 /* ************************************************************************** */
 
 import * as vscode from 'vscode';
+
 import { getTemplate, getTemplateFull } from './template';
 
 export async function createQuickClass() {
@@ -34,12 +35,42 @@ export async function createQuickClass() {
 		const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
 		const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
 
+		let command = (vscode.workspace.getConfiguration().get('headercppclass.headerId') as string).trim();
+
 		wsedit.createFile(filePathCpp, { ignoreIfExists: true });
 		wsedit.createFile(filePathHpp, { ignoreIfExists: true });
 
 		vscode.workspace.applyEdit(wsedit);
 
-		getTemplate( name, filePathCpp, filePathHpp )
+		getTemplate( name, filePathCpp, filePathHpp );
+		if (command && command.length > 0)
+		{
+			vscode.workspace.openTextDocument(filePathCpp.path).then((a: vscode.TextDocument) => {
+				vscode.window.showTextDocument(a, 1, false).then( e => {
+					e.edit(() => {
+						vscode.commands.executeCommand(command).then(() => {})
+					});
+				});
+			}, (err: any) => {
+				vscode.window.showErrorMessage("Header Cpp Class: " + err.message);
+			});
+			vscode.workspace.onDidSaveTextDocument;
+			vscode.workspace.onDidCloseTextDocument;
+		}
+		if (command && command.length > 0)
+		{
+			vscode.workspace.openTextDocument(filePathHpp.path).then((a: vscode.TextDocument) => {
+				vscode.window.showTextDocument(a, 1, false).then( e => {
+					e.edit(edit => {
+						vscode.commands.executeCommand(command).then(() => {})
+					});
+				});
+			}, (err: any) => {
+				vscode.window.showErrorMessage("Header Cpp Class: " + err.message);
+			});
+			vscode.workspace.onDidSaveTextDocument;
+			vscode.workspace.onDidCloseTextDocument;
+		}
 	}
 }
 

+ 4 - 1
src/template.ts

@@ -13,7 +13,9 @@
 import * as vscode from 'vscode';
 import * as fs from 'fs';
 
-export const getTemplate = ( name: string, filePathCpp: vscode.Uri , filePathHpp: vscode.Uri  ) => {
+export const getTemplate = ( name: string | undefined, filePathCpp: vscode.Uri , filePathHpp: vscode.Uri  ) => {
+	if (name)
+	{
 		let len = name.length;
 		len += 23;
 		len = 80 - len - 1
@@ -58,6 +60,7 @@ export const getTemplate = ( name: string, filePathCpp: vscode.Uri , filePathHpp
 		fs.writeFile(filePathHpp.fsPath, classhpp, function (err: any) { if (err) return console.log(err); });
 
 		vscode.window.showInformationMessage("Files : " + name + ".class.cpp, " + name + ".class.hpp created !");
+	}
 }