basicInput.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* basicInput.ts :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: frfrey <frfrey@student.42lyon.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2020/07/22 10:21:45 by frfrey #+# #+# */
  9. /* Updated: 2020/07/22 10:21:45 by frfrey ### ########lyon.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. import * as vscode from 'vscode';
  13. import { getTemplate } from './template';
  14. export async function createQuickClass() {
  15. let name = await vscode.window.showInputBox({
  16. prompt: "Enter your Class Name",
  17. placeHolder: "ClassName",
  18. validateInput: (text: string): string | undefined => {
  19. if (!text){
  20. return 'You must enter a name';
  21. } else {
  22. return undefined;
  23. }
  24. }
  25. });
  26. if (name !== undefined){
  27. name = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase()
  28. const wsedit = new vscode.WorkspaceEdit();
  29. const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
  30. const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
  31. const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
  32. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  33. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  34. vscode.workspace.applyEdit(wsedit);
  35. getTemplate(name, filePathCpp, filePathHpp )
  36. }
  37. }
  38. export async function createClass() {
  39. let name = await vscode.window.showInputBox({
  40. prompt: "Enter your Class Name",
  41. placeHolder: "ClassName",
  42. validateInput: (text: string): string | undefined => {
  43. if (!text){
  44. return 'You must enter a name';
  45. } else {
  46. return undefined;
  47. }
  48. }
  49. });
  50. if (name !== undefined){
  51. name = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase
  52. const wsedit = new vscode.WorkspaceEdit();
  53. const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
  54. const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
  55. const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
  56. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  57. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  58. vscode.workspace.applyEdit(wsedit);
  59. getTemplate(name, filePathCpp, filePathHpp )
  60. }
  61. }