5
5
* Author : Black Logic
6
6
* Note : Logic > comment
7
7
* License : GNU GPLv3 with Visual Python special exception
8
- * Date : 2021. 11. 18
8
+ * Date : 2023. 04. 04
9
9
* Change Date :
10
10
*/
11
11
@@ -18,6 +18,61 @@ define([
18
18
] , function ( com_String , PopupComponent ) {
19
19
20
20
const COMMENT_DEFAULT_CODE = '# Write down comments'
21
+ // Templates from NumPy Style Python Docstrings.
22
+ const COMMENT_CLASS_TEMPLATE =
23
+ `"""Summarize the class in one line.
24
+
25
+ Several sentences ...
26
+ providing an extended description.
27
+
28
+ Note
29
+ ----------
30
+ Note about this class.
31
+
32
+ Parameters
33
+ ----------
34
+ param1 : param_type
35
+ Parameter description.
36
+ param2 : param_type
37
+ Parameter description.
38
+
39
+ Attributes
40
+ ----------
41
+ attr1 : attr_type
42
+ Attibute description.
43
+ attr2 : attr_type
44
+ Attibute description.
45
+
46
+ Examples
47
+ ----------
48
+
49
+ References
50
+ ----------
51
+ """`
52
+ const COMMENT_METHOD_TEMPLATE =
53
+ `"""Summarize the function in one line.
54
+
55
+ Several sentences ...
56
+ providing an extended description.
57
+
58
+ Parameters
59
+ ----------
60
+ param1 : param_type
61
+ Parameter description.
62
+ param2 : param_type
63
+ Parameter description.
64
+
65
+ Returns
66
+ -------
67
+ return_type
68
+ Return description.
69
+
70
+ Note
71
+ ----------
72
+
73
+ Examples
74
+ ----------
75
+ """`
21
76
22
77
/**
23
78
* Comment
@@ -29,25 +84,63 @@ define([
29
84
this . config . dataview = false ;
30
85
this . config . codeview = false ;
31
86
this . config . saveOnly = true ;
87
+ this . selectBoxClassName = 'vp-ct-option' ; // Select Box ClassName
32
88
33
89
this . state = {
34
90
code : COMMENT_DEFAULT_CODE ,
35
91
...this . state
36
92
}
37
-
93
+
94
+ this . cmTemplates = { // a kind of templates
95
+ Default : COMMENT_DEFAULT_CODE ,
96
+ Class : COMMENT_CLASS_TEMPLATE ,
97
+ Method : COMMENT_METHOD_TEMPLATE
98
+ }
99
+
38
100
this . _addCodemirror ( 'code' , this . wrapSelector ( '#code' ) ) ;
39
101
}
40
102
41
103
_bindEvent ( ) {
42
104
super . _bindEvent ( ) ;
43
- /** Implement binding events */
105
+
106
+ var commentTemplates = this . cmTemplates ;
107
+ let cmCodeListTemp = this . cmCodeList ;
108
+
109
+ $ ( '.' + this . selectBoxClassName ) . on ( 'change' , function ( ) {
110
+ // get code mirror object
111
+ let targetCmObj = cmCodeListTemp . filter ( obj => obj . key == 'code' ) ;
112
+ var templateOption = $ ( this ) . val ( ) ;
113
+ let cm = targetCmObj [ 0 ] . cm ;
114
+
115
+ // Change Code Mirror Text
116
+ if ( templateOption == 'vp_template_class' ) {
117
+ cm . setValue ( commentTemplates . Class ) ;
118
+ } else if ( templateOption == 'vp_template_method' ) {
119
+ cm . setValue ( commentTemplates . Method ) ;
120
+ } else if ( templateOption == 'vp_template_default' ) {
121
+ cm . setValue ( commentTemplates . Default ) ;
122
+ }
123
+
124
+ cm . save ( ) ;
125
+ } ) ;
44
126
}
45
127
46
128
templateForBody ( ) {
47
129
/** Implement generating template */
48
130
var page = new com_String ( ) ;
49
131
page . appendFormatLine ( '<textarea name="code" class="code vp-state" id="code">{0}</textarea>'
50
132
, this . state . code ) ;
133
+
134
+ // add select box
135
+ page . appendFormatLine ( '<select class="vp-select w100 {0}" >' , this . selectBoxClassName ) ;
136
+ // add options
137
+ Object . entries ( this . cmTemplates ) . forEach ( ( [ optionValue , t_code ] ) => {
138
+ page . appendFormatLine ( '<option value="{0}">{1}</option>' ,
139
+ 'vp_template_' + optionValue . toLowerCase ( ) ,
140
+ optionValue ) ;
141
+ } ) ;
142
+ page . appendFormatLine ( '</select>' ) ;
143
+
51
144
return page . toString ( ) ;
52
145
}
53
146
0 commit comments