basicInput.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 * as fs from 'fs';
  14. import { getTemplate, getTemplateFull } from './template';
  15. import { getHeadercpp, getHeaderhpp } from './header';
  16. export async function createQuickClass() {
  17. let name = await vscode.window.showInputBox({
  18. prompt: "Enter your Class Name",
  19. placeHolder: "ClassName",
  20. validateInput: (text: string): string | undefined => {
  21. if (!text){
  22. return 'You must enter a name';
  23. } else {
  24. return undefined;
  25. }
  26. }
  27. });
  28. if (name !== undefined){
  29. name = name.charAt(0).toUpperCase() + name.slice(1)
  30. const wsedit = new vscode.WorkspaceEdit();
  31. const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
  32. const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
  33. const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
  34. let command = (vscode.workspace.getConfiguration().get('headercppclass.headerId') as string).trim();
  35. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  36. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  37. vscode.workspace.applyEdit(wsedit);
  38. getTemplate( name, filePathCpp, filePathHpp );
  39. await getHeadercpp( command, filePathCpp );
  40. await getHeaderhpp( command, filePathHpp );
  41. }
  42. }
  43. /*
  44. export async function createClass() {
  45. let name = await vscode.window.showInputBox({
  46. prompt: "Enter your Class Name",
  47. placeHolder: "ClassName",
  48. validateInput: (text: string): string | undefined => {
  49. if (!text){
  50. return 'You must enter a name';
  51. } else {
  52. return undefined;
  53. }
  54. }
  55. });
  56. let value1: string | undefined;
  57. let value2: string | undefined;
  58. let value3: string | undefined;
  59. let valueArray = [];
  60. let typeArray = [];
  61. for ( ; value1 !== 'exit' || !value1; )
  62. {
  63. value1 = await vscode.window.showInputBox({
  64. prompt: "Enter your Type Name, (Press 'exit' for leave.)",
  65. placeHolder: "Type",
  66. validateInput: (text: string): string | undefined => {
  67. if (!text){
  68. return 'You must enter a Type or Press \'exit\' if finish';
  69. } else {
  70. return undefined;
  71. }
  72. }
  73. })
  74. if (value1 != 'exit')
  75. value2 = await vscode.window.showInputBox({
  76. prompt: "Enter your variable Name",
  77. placeHolder: "Variable Name",
  78. validateInput: (text: string): string | undefined => {
  79. if (!text){
  80. return 'You must enter a Variable';
  81. } else {
  82. return undefined;
  83. }
  84. }
  85. })
  86. if (value1 !== 'exit')
  87. {
  88. typeArray.push(value1?.toLowerCase());
  89. valueArray.push(value2?.toLowerCase());
  90. }
  91. }
  92. if (name !== undefined){
  93. name = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase()
  94. const wsedit = new vscode.WorkspaceEdit();
  95. const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
  96. const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
  97. const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
  98. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  99. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  100. vscode.workspace.applyEdit(wsedit);
  101. getTemplateFull( name, filePathCpp, filePathHpp, valueArray, typeArray )
  102. }
  103. }
  104. */