Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cc18ed

Browse files
committed
#157 - Add 'Comment Template' to comment logic block
Add 'Comment Template' to comment logic block
1 parent944b218 commit1cc18ed

File tree

1 file changed

+110
-7
lines changed

1 file changed

+110
-7
lines changed

‎js/m_logic/Comment.js‎

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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

2020
constCOMMENT_DEFAULT_CODE='# Write down comments'
21+
// Templates from NumPy Style Python Docstrings.
22+
constCOMMENT_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+
constCOMMENT_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([
2990
this.config.dataview=false;
3091
this.config.codeview=false;
3192
this.config.saveOnly=true;
93+
94+
this.cmKey='code';// Code Mirror Key
95+
this.selectBoxClassName='vp-ct-option';// Select Box ClassName
3296

3397
this.state={
3498
code: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(){
42112
super._bindEvent();
43-
/** Implement binding events */
113+
114+
varcommentTemplates=this.cmTemplates;
115+
varcm_key=this.cmKey;
116+
letcmCodeListTemp=this.cmCodeList;
117+
118+
// Select box change Event
119+
$('.'+this.selectBoxClassName).on('change',function(){
120+
// get code mirror object
121+
lettargetCmObj=cmCodeListTemp.filter(obj=>obj.key==cm_key);
122+
vartemplateOption=$(this).val();
123+
letcm=targetCmObj[0].cm;
124+
125+
// Change Code Mirror Text
126+
if(templateOption=='vp_template_class'){
127+
cm.setValue(commentTemplates.Class);
128+
}elseif(templateOption=='vp_template_method'){
129+
cm.setValue(commentTemplates.Method);
130+
}elseif(templateOption=='vp_template_template'){
131+
cm.setValue(commentTemplates.Template);
132+
}
133+
134+
cm.save();
135+
});
136+
44137
}
45138

139+
46140
templateForBody(){
47141
/** Implement generating template */
48142
varpage=newcom_String();
49143
page.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+
51154
returnpage.toString();
52155
}
53156

54157
open(){
55158
super.open();
56159

57160
if(this.state.code===COMMENT_DEFAULT_CODE){
58-
// set default selection
59-
letcmObj=this.getCodemirror('code');
161+
162+
letcmObj=this.getCodemirror(this.cmKey);
60163
if(cmObj&&cmObj.cm){
61164
cmObj.cm.setSelection({line:0,ch:2},{line:0});
62165
cmObj.cm.focus();
63166
}
64167
}
65168
}
66-
169+
67170
generateCode(){
68171
returnthis.state.code;
69172
}
70-
173+
71174
}
72175

73176
returnComment;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp