Răsfoiți Sursa

Add function for adding header

Etheram68 5 ani în urmă
părinte
comite
b13f1f6fd6
5 a modificat fișierele cu 64 adăugiri și 32 ștergeri
  1. 3 0
      README.md
  2. 1 1
      package.json
  3. 8 29
      src/basicInput.ts
  4. 2 2
      src/extension.ts
  5. 50 0
      src/header.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.2.0
+Add function for adding header on file
+
 ### 0.1.9
 Remove multi choice for working in
 

+ 1 - 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.9",
+	"version": "0.2.0",
 	"publisher": "frfreyCanonicalClassCPP",
 	"icon": "42.png",
 	"repository": {

+ 8 - 29
src/basicInput.ts

@@ -11,10 +11,13 @@
 /* ************************************************************************** */
 
 import * as vscode from 'vscode';
+import * as fs from 'fs';
 
 import { getTemplate, getTemplateFull } from './template';
+import { getHeadercpp, getHeaderhpp } from './header';
 
 export async function createQuickClass() {
+
 	let name = await vscode.window.showInputBox({
 		prompt: "Enter your Class Name",
 		placeHolder: "ClassName",
@@ -26,6 +29,7 @@ export async function createQuickClass() {
 			}
 		}
 	});
+
 	if (name !== undefined){
 		name = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase()
 
@@ -43,37 +47,11 @@ export async function createQuickClass() {
 		vscode.workspace.applyEdit(wsedit);
 
 		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;
-		}
+		await getHeadercpp( command, filePathCpp );
+		await getHeaderhpp( command, filePathHpp );
 	}
 }
-
+/*
 export async function createClass() {
 	let name = await vscode.window.showInputBox({
 		prompt: "Enter your Class Name",
@@ -141,3 +119,4 @@ export async function createClass() {
 		getTemplateFull( name, filePathCpp, filePathHpp, valueArray, typeArray )
 	}
 }
+*/

+ 2 - 2
src/extension.ts

@@ -11,10 +11,10 @@
 /* ************************************************************************** */
 
 import { window, commands, ExtensionContext } from 'vscode';
-import { createQuickClass, createClass } from './basicInput';
+import { createQuickClass } from './basicInput';
 
 export function activate(context: ExtensionContext) {
-	context.subscriptions.push(commands.registerCommand('canonicalclass.makeclass', async () => {
+	context.subscriptions.push(commands.registerCommand('canonicalclass.makeclass', () => {
 		/*const options: { [key: string]: (context: ExtensionContext) => Promise<void> } = {
 			createQuickClass,
 			createClass,

+ 50 - 0
src/header.ts

@@ -0,0 +1,50 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   header.ts                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: frfrey <frfrey@student.42lyon.fr>          +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2020/07/23 20:24:24 by frfrey            #+#    #+#             */
+/*   Updated: 2020/07/23 20:24:24 by frfrey           ###   ########lyon.fr   */
+/*                                                                            */
+/* ************************************************************************** */
+
+import * as vscode from 'vscode';
+import { assert } from 'console';
+
+export async function getHeadercpp(command: string, filePathCpp: vscode.Uri) {
+
+	if (command && command.length > 0)
+	{
+		await vscode.workspace.openTextDocument(filePathCpp).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;
+	}
+}
+
+export async function getHeaderhpp(command: string, filePathHpp: vscode.Uri) {
+
+	if (command && command.length > 0)
+	{
+		await vscode.workspace.openTextDocument(filePathHpp).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;
+	}
+}