浏览代码

Add multiple gestion

Etheram68 5 年之前
父节点
当前提交
b96707874d
共有 3 个文件被更改,包括 83 次插入70 次删除
  1. 17 56
      README.md
  2. 5 4
      package.json
  3. 61 10
      src/extension.ts

+ 17 - 56
README.md

@@ -1,65 +1,26 @@
-# autoclasscpp README
+<img
+  src="https://raw.githubusercontent.com/Etheram68/Header-Cpp-Class/master/logo-42.png"
+  width=128>
 
-This is the README for your extension "autoclasscpp". After writing up a brief description, we recommend including the following sections.
+# 42 Lyon/Paris Canonical Class for Cpp
 
-## Features
+## Install
 
-Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
+Launch Quick Open with <kbd>⌘</kbd>+<kbd>P</kbd> and enter
+```
+ext install canonicalclasscpp
+```
 
-For example if there is an image subfolder under your extension project workspace:
+## Usage
+### Insert a header
+ - **macOS** : <kbd>⌘</kbd> + <kbd>⌥</kbd> + <kbd>C</kbd>
+ - **Linux** / **Windows** : <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>C</kbd>.
 
-\!\[feature X\]\(images/feature-x.png\)
+## Issues
 
-> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
-
-## Requirements
-
-If you have any requirements or dependencies, add a section describing those and how to install and configure them.
-
-## Extension Settings
-
-Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
-
-For example:
-
-This extension contributes the following settings:
-
-* `myExtension.enable`: enable/disable this extension
-* `myExtension.thing`: set to `blah` to do something
-
-## Known Issues
-
-Calling out known issues can help limit users opening duplicate issues against your extension.
+To report a bug or ask for a feature, please open a [Github issue](https://github.com/Etheram68/Header-Cpp-Class/issues).
 
 ## Release Notes
 
-Users appreciate release notes as you update your extension.
-
-### 1.0.0
-
-Initial release of ...
-
-### 1.0.1
-
-Fixed issue #.
-
-### 1.1.0
-
-Added features X, Y, and Z.
-
------------------------------------------------------------------------------------------------------------
-
-## Working with Markdown
-
-**Note:** You can author your README using Visual Studio Code.  Here are some useful editor keyboard shortcuts:
-
-* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
-* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
-* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets
-
-### For more information
-
-* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
-* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
-
-**Enjoy!**
+### 0.1.0
+First Version of Auto Create canonical Class for the Cpp language

+ 5 - 4
package.json

@@ -2,8 +2,8 @@
 	"name": "canonicalclasscpp",
 	"displayName": "Canonical Class CPP",
 	"description": "This extension is to automatically create a canonical hpp and cpp file",
-	"version": "0.0.1",
-	"publisher": "frfrey",
+	"version": "0.0.2",
+	"publisher": "Testextensionfrfrey",
 	"icon": "cpp.jpg",
 	"repository": {
 		"type": "git",
@@ -19,7 +19,7 @@
 		"Other"
 	],
 	"activationEvents": [
-		"onCommand:extension.helloWorld"
+		"onCommand:canonicalclass.makeclass"
 	],
 	"main": "./out/extension.js",
 	"contributes": {
@@ -32,7 +32,8 @@
 		"keybindings":[
 			{
 				"command": "canonicalclass.makeclass",
-				"key": "ctrl+shift+c"
+				"key": "ctrl+alt+c",
+				"mac": "cmd+alt+c"
 			}
 		]
 	},

+ 61 - 10
src/extension.ts

@@ -1,23 +1,74 @@
 // The module 'vscode' contains the VS Code extensibility API
 // Import the module and reference it with the alias vscode in your code below
 import * as vscode from 'vscode';
+import * as fs from 'fs';
 
 // this method is called when your extension is activated
 // your extension is activated the very first time the command is executed
 export function activate(context: vscode.ExtensionContext) {
 
-	// Use the console to output diagnostic information (console.log) and errors (console.error)
-	// This line of code will only be executed once when your extension is activated
-	console.log('Congratulations, your extension "autoclasscpp" is now active!');
 
-	// The command has been defined in the package.json file
-	// Now provide the implementation of the command with registerCommand
-	// The commandId parameter must match the command field in package.json
-	let disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
-		// The code you place here will be executed every time your command is executed
+	let disposable = vscode.commands.registerCommand('canonicalclass.makeclass', async function (){
+		let name = await vscode.window.showInputBox({
+			prompt: "Enter your Class Name",
+			validateInput: (text: string): string | undefined => {
+				if (!text){
+					return 'You must enter a name';
+				} else {
+					return undefined;
+				}
+			}
+		})
+		if (name !== undefined){
+			name = name.charAt(0).toUpperCase() + name.slice(1)
 
-		// Display a message box to the user
-		vscode.window.showInformationMessage('Hello World!');
+			const wsedit = new vscode.WorkspaceEdit();
+			const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
+
+			const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
+			const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
+
+			wsedit.createFile(filePathCpp, { ignoreIfExists: true });
+			wsedit.createFile(filePathHpp, { ignoreIfExists: true });
+
+			vscode.workspace.applyEdit(wsedit);
+
+			let len = name.length;
+			len += 23;
+			len = 80 - len - 1
+			let star = "*"
+			for (; len > 0; len--)
+			{
+				star += "*"
+			}
+
+			let classcpp =  "#include \"" + name + ".Class" + ".hpp\"\n\n" +
+							name + "::" + name + "() {}\n\n" +
+							name + "::" + name + "( const " + name + " & object ) {}\n\n" +
+							name + "::~" + name + "()\n{\n	std::cout << \"Destructor called\" << std::endl;\n}\n\n" +
+							name + " &		" + name + "::operator=( " + name + " const & rhs )\n{\n	return (*this);\n}\n\n";
+
+			let classhpp =	"#ifndef " + name.toUpperCase() + "_CLASS" + "_HPP\n" +
+							"#define " + name.toUpperCase() + "_CLASS" + "_HPP\n\n" +
+							"#include <iostream>\n\n" +
+							"class " + name + "\n{\n" +
+							"\n" +
+							"	public:\n" +
+							"\n" +
+							"		" + name + "();\n" +
+							"		" + name + "( " + name + " const & src );\n" +
+							"		~" + name + "();\n" +
+							"\n" +
+							"		" + name + " &		operator=( " + name + " const & rhs );"+
+							"\n\n" +
+							"	private:\n" +
+							"\n" +
+							"};\n\n" +
+							"#endif /* *" + star + " " + name.toUpperCase() + "_CLASS_H */";
+			fs.writeFile(filePathCpp.fsPath, classcpp, function (err: any) { if (err) return console.log(err); });
+			fs.writeFile(filePathHpp.fsPath, classhpp, function (err: any) { if (err) return console.log(err); });
+			vscode.window.showInformationMessage("Files : " + name + ".cpp, " + name + ".hpp created !");
+		}
 	});
 
 	context.subscriptions.push(disposable);