basicInput.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, getTemplateFull } 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. let command = (vscode.workspace.getConfiguration().get('headercppclass.headerId') as string).trim();
  33. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  34. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  35. vscode.workspace.applyEdit(wsedit);
  36. getTemplate( name, filePathCpp, filePathHpp );
  37. if (command && command.length > 0)
  38. {
  39. vscode.workspace.openTextDocument(filePathCpp.path).then((a: vscode.TextDocument) => {
  40. vscode.window.showTextDocument(a, 1, false).then( e => {
  41. e.edit(() => {
  42. vscode.commands.executeCommand(command).then(() => {})
  43. });
  44. });
  45. }, (err: any) => {
  46. vscode.window.showErrorMessage("Header Cpp Class: " + err.message);
  47. });
  48. vscode.workspace.onDidSaveTextDocument;
  49. vscode.workspace.onDidCloseTextDocument;
  50. }
  51. if (command && command.length > 0)
  52. {
  53. vscode.workspace.openTextDocument(filePathHpp.path).then((a: vscode.TextDocument) => {
  54. vscode.window.showTextDocument(a, 1, false).then( e => {
  55. e.edit(edit => {
  56. vscode.commands.executeCommand(command).then(() => {})
  57. });
  58. });
  59. }, (err: any) => {
  60. vscode.window.showErrorMessage("Header Cpp Class: " + err.message);
  61. });
  62. vscode.workspace.onDidSaveTextDocument;
  63. vscode.workspace.onDidCloseTextDocument;
  64. }
  65. }
  66. }
  67. export async function createClass() {
  68. let name = await vscode.window.showInputBox({
  69. prompt: "Enter your Class Name",
  70. placeHolder: "ClassName",
  71. validateInput: (text: string): string | undefined => {
  72. if (!text){
  73. return 'You must enter a name';
  74. } else {
  75. return undefined;
  76. }
  77. }
  78. });
  79. let value1: string | undefined;
  80. let value2: string | undefined;
  81. let value3: string | undefined;
  82. let valueArray = [];
  83. let typeArray = [];
  84. for ( ; value1 !== 'exit' || !value1; )
  85. {
  86. value1 = await vscode.window.showInputBox({
  87. prompt: "Enter your Type Name, (Press 'exit' for leave.)",
  88. placeHolder: "Type",
  89. validateInput: (text: string): string | undefined => {
  90. if (!text){
  91. return 'You must enter a Type or Press \'exit\' if finish';
  92. } else {
  93. return undefined;
  94. }
  95. }
  96. })
  97. if (value1 != 'exit')
  98. value2 = await vscode.window.showInputBox({
  99. prompt: "Enter your variable Name",
  100. placeHolder: "Variable Name",
  101. validateInput: (text: string): string | undefined => {
  102. if (!text){
  103. return 'You must enter a Variable';
  104. } else {
  105. return undefined;
  106. }
  107. }
  108. })
  109. if (value1 !== 'exit')
  110. {
  111. typeArray.push(value1?.toLowerCase());
  112. valueArray.push(value2?.toLowerCase());
  113. }
  114. }
  115. if (name !== undefined){
  116. name = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase()
  117. const wsedit = new vscode.WorkspaceEdit();
  118. const wsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
  119. const filePathCpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.cpp');
  120. const filePathHpp = vscode.Uri.file(wsPath + '/' + name + '.Class' + '.hpp');
  121. wsedit.createFile(filePathCpp, { ignoreIfExists: true });
  122. wsedit.createFile(filePathHpp, { ignoreIfExists: true });
  123. vscode.workspace.applyEdit(wsedit);
  124. getTemplateFull( name, filePathCpp, filePathHpp, valueArray, typeArray )
  125. }
  126. }