66 * Note : Logic > comment
77 * License : GNU GPLv3 with Visual Python special exception
88 * Date : 2021. 11. 18
9- * Change Date :
9+ * Change Date : 2022. 08. 10
1010 */
1111
1212//============================================================================
@@ -18,6 +18,67 @@ define([
1818] , function ( com_String , PopupComponent ) {
1919
2020const COMMENT_DEFAULT_CODE = '# Write down comments'
21+ // Templates from NumPy Style Python Docstrings.
22+ const COMMENT_CLASS_TEMPLATE =
23+ `
24+ """Summarize the class in one line.
25+
26+ Several sentences ...
27+ providing an extended description.
28+
29+ Note
30+ ----------
31+ Note about this class.
32+
33+ Parameters
34+ ----------
35+ param1 : param_type
36+ Parameter description.
37+ param2 : param_type
38+ Parameter description.
39+
40+ Attributes
41+ ----------
42+ attr1 : attr_type
43+ Attibute description.
44+ attr2 : attr_type
45+ Attibute description.
46+
47+ Examples
48+ ----------
49+
50+ References
51+ ----------
52+
53+ """
54+ `
55+ const COMMENT_METHOD_TEMPLATE =
56+ `
57+ """Summarize the function in one line.
58+
59+ Several sentences ...
60+ providing an extended description.
61+
62+ Parameters
63+ ----------
64+ param1 : param_type
65+ Parameter description.
66+ param2 : param_type
67+ Parameter description.
68+
69+ Returns
70+ -------
71+ return_type
72+ Return description.
73+
74+ Note
75+ ----------
76+
77+ Examples
78+ ----------
79+
80+ """
81+ `
2182
2283/**
2384 * Comment
@@ -29,45 +90,87 @@ define([
2990this . config . dataview = false ;
3091this . config . codeview = false ;
3192this . config . saveOnly = true ;
93+
94+ this . cmKey = 'code' ; // Code Mirror Key
95+ this . selectBoxClassName = 'vp-ct-option' ; // Select Box ClassName
3296
3397this . state = {
3498code :COMMENT_DEFAULT_CODE ,
3599 ...this . state
100+ } ;
101+
102+ this . cmTemplates = { // a kind of templates
103+ Template :COMMENT_DEFAULT_CODE ,
104+ Class :COMMENT_CLASS_TEMPLATE ,
105+ Method :COMMENT_METHOD_TEMPLATE
36106}
37107
38- this . _addCodemirror ( 'code' , this . wrapSelector ( '#code' ) ) ;
108+ this . _addCodemirror ( this . cmKey , this . wrapSelector ( '#code' ) ) ;
39109}
40110
41111_bindEvent ( ) {
42112super . _bindEvent ( ) ;
43- /** Implement binding events */
113+
114+ var commentTemplates = this . cmTemplates ;
115+ var cm_key = this . cmKey ;
116+ let cmCodeListTemp = this . cmCodeList ;
117+
118+ // Select box change Event
119+ $ ( '.' + this . selectBoxClassName ) . on ( 'change' , function ( ) {
120+ // get code mirror object
121+ let targetCmObj = cmCodeListTemp . filter ( obj => obj . key == cm_key ) ;
122+ var templateOption = $ ( this ) . val ( ) ;
123+ let cm = targetCmObj [ 0 ] . cm ;
124+
125+ // Change Code Mirror Text
126+ if ( templateOption == 'vp_template_class' ) {
127+ cm . setValue ( commentTemplates . Class ) ;
128+ } else if ( templateOption == 'vp_template_method' ) {
129+ cm . setValue ( commentTemplates . Method ) ;
130+ } else if ( templateOption == 'vp_template_template' ) {
131+ cm . setValue ( commentTemplates . Template ) ;
132+ }
133+
134+ cm . save ( ) ;
135+ } ) ;
136+
44137}
45138
139+
46140templateForBody ( ) {
47141/** Implement generating template */
48142var page = new com_String ( ) ;
49143page . appendFormatLine ( '<textarea name="code" class="code vp-state" id="code">{0}</textarea>'
50144, this . state . code ) ;
145+ // add select box
146+ page . appendFormatLine ( '<select class="vp-select w100 {0}" >' , this . selectBoxClassName ) ;
147+ // add options
148+ Object . entries ( this . cmTemplates ) . forEach ( ( [ opt , t_code ] ) => {
149+ page . appendFormatLine ( '<option value="{0}">{1}</option>' ,
150+ 'vp_template_' + opt . toLowerCase ( ) , opt ) ;
151+ } ) ;
152+ page . appendFormatLine ( '</select>' ) ;
153+
51154return page . toString ( ) ;
52155}
53156
54157open ( ) {
55158super . open ( ) ;
56159
57160if ( this . state . code === COMMENT_DEFAULT_CODE ) {
58- // set default selection
59- let cmObj = this . getCodemirror ( 'code' ) ;
161+
162+ let cmObj = this . getCodemirror ( this . cmKey ) ;
60163if ( cmObj && cmObj . cm ) {
61164cmObj . cm . setSelection ( { line :0 , ch :2 } , { line :0 } ) ;
62165cmObj . cm . focus ( ) ;
63166}
64167}
65168}
66-
169+
67170generateCode ( ) {
68171return this . state . code ;
69172}
70-
173+
71174}
72175
73176return Comment ;