Skip to content

Commit ed31f67

Browse files
author
angelozerr
committed
Fix #52
1 parent bdaefa6 commit ed31f67

File tree

6 files changed

+255
-6
lines changed

6 files changed

+255
-6
lines changed

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.properties

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ TypeScriptEditor.name=TypeScript Editor
2121
# Hover
2222
ProblemTypeScriptHover= TypeScript Problem
2323
ProblemTypeScriptHoverDescription= TypeScript Problem
24-
TypeScriptHover=TypeScript
25-
TypeScriptHoverDescription=TypeScript
24+
TypeScriptHover= TypeScript
25+
TypeScriptHoverDescription= TypeScript
2626

2727
context.name.0 = TypeScript View
2828
context.description.0 = TypeScript View Context
@@ -62,6 +62,27 @@ IndentAction.label= Correct &Indentation
6262
ActionDefinition.indent.name= Indent Line
6363
ActionDefinition.indent.description=Indents the current line
6464

65+
# Comments Actions
66+
CommentAction.label= Co&mment
67+
ActionDefinition.comment.name= Comment
68+
ActionDefinition.comment.description= Turn the selected lines into JavaScript comments
69+
70+
UncommentAction.label= &Uncomment
71+
ActionDefinition.uncomment.name= Uncomment
72+
ActionDefinition.uncomment.description= Uncomment the selected JavaScript comment lines
73+
74+
ToggleCommentAction.label= Togg&le Comment
75+
ActionDefinition.toggleComment.name= Toggle Comment
76+
ActionDefinition.toggleComment.description= Toggle comment the selected lines
77+
78+
AddBlockCommentAction.label= Add &Block Comment
79+
ActionDefinition.addBlockComment.name= Add Block Comment
80+
ActionDefinition.addBlockComment.description= Enclose the selection with a block comment
81+
82+
RemoveBlockCommentAction.label= Remove Bloc&k Comment
83+
ActionDefinition.removeBlockComment.name= Remove Block Comment
84+
ActionDefinition.removeBlockComment.description= Remove the block comment enclosing the selection
85+
6586
#--- Edit menu
6687
ActionDefinition.show.outline.name= Quick Outline
6788
ActionDefinition.show.outline.description= Show the quick outline for the editor input

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.xml

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
label="%SourceMenu.label"
161161
path="edit"
162162
id="ts.eclipse.ide.jsdt.ui.source.menu">
163+
<separator
164+
name="commentGroup">
165+
</separator>
163166
<separator
164167
name="editGroup">
165168
</separator>
@@ -180,6 +183,47 @@
180183
menubarPath="ts.eclipse.ide.jsdt.ui.source.menu/editGroup"
181184
id="ts.eclipse.ide.jsdt.ui.actions.Indent">
182185
</action>
186+
<!-- Comment Group -->
187+
<!--<action
188+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.add.javadoc.comment"
189+
label="%AddJavaDocCommentAction.label"
190+
retarget="true"
191+
menubarPath="ts.eclipse.ide.jsdt.ui.source.menu/commentGroup"
192+
id="ts.eclipse.ide.jsdt.ui.actions.AddJavaDocComment">
193+
</action>-->
194+
<action
195+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.uncomment"
196+
label="%UncommentAction.label"
197+
retarget="true"
198+
id="ts.eclipse.ide.jsdt.ui.actions.Uncomment">
199+
</action>
200+
<action
201+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.comment"
202+
label="%CommentAction.label"
203+
retarget="true"
204+
id="ts.eclipse.ide.jsdt.ui.actions.Comment">
205+
</action>
206+
<action
207+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.remove.block.comment"
208+
label="%RemoveBlockCommentAction.label"
209+
retarget="true"
210+
menubarPath="ts.eclipse.ide.jsdt.ui.source.menu/commentGroup"
211+
id="ts.eclipse.ide.jsdt.ui.actions.RemoveBlockComment">
212+
</action>
213+
<action
214+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.add.block.comment"
215+
label="%AddBlockCommentAction.label"
216+
retarget="true"
217+
menubarPath="ts.eclipse.ide.jsdt.ui.source.menu/commentGroup"
218+
id="ts.eclipse.ide.jsdt.ui.actions.AddBlockComment">
219+
</action>
220+
<action
221+
definitionId="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"
222+
label="%ToggleCommentAction.label"
223+
retarget="true"
224+
menubarPath="ts.eclipse.ide.jsdt.ui.source.menu/commentGroup"
225+
id="ts.eclipse.ide.jsdt.ui.actions.ToggleComment">
226+
</action>
183227
</actionSet>
184228
</extension>
185229

@@ -260,6 +304,36 @@
260304
description="%ActionDefinition.indent.description"
261305
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
262306
id="ts.eclipse.ide.jsdt.ui.edit.text.java.indent">
307+
</command>
308+
<command
309+
name="%ActionDefinition.comment.name"
310+
description="%ActionDefinition.comment.description"
311+
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
312+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.comment">
313+
</command>
314+
<command
315+
name="%ActionDefinition.uncomment.name"
316+
description="%ActionDefinition.uncomment.description"
317+
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
318+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.uncomment">
319+
</command>
320+
<command
321+
name="%ActionDefinition.toggleComment.name"
322+
description="%ActionDefinition.toggleComment.description"
323+
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
324+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment">
325+
</command>
326+
<command
327+
name="%ActionDefinition.addBlockComment.name"
328+
description="%ActionDefinition.addBlockComment.description"
329+
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
330+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.add.block.comment">
331+
</command>
332+
<command
333+
name="%ActionDefinition.removeBlockComment.name"
334+
description="%ActionDefinition.removeBlockComment.description"
335+
categoryId="ts.eclipse.ide.jsdt.ui.category.source"
336+
id="ts.eclipse.ide.jsdt.ui.edit.text.java.remove.block.comment">
263337
</command>
264338
<!-- search -->
265339
<command
@@ -300,7 +374,47 @@
300374
sequence="M1+I"
301375
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
302376
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.indent"
303-
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
377+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
378+
<key
379+
sequence="M1+M2+C"
380+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
381+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"
382+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
383+
<key
384+
sequence="M1+7"
385+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
386+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"
387+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
388+
<key
389+
sequence="M1+/"
390+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
391+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"
392+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
393+
<!-- alternative for some gtk input modes -->
394+
<key
395+
platform="gtk"
396+
sequence="ESC CTRL+C"
397+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
398+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"
399+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
400+
<key
401+
sequence="M1+M2+/"
402+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
403+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.add.block.comment"
404+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
405+
<!-- free this on MAC, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=113981 -->
406+
<key
407+
platform="carbon"
408+
sequence="M1+M2+/"
409+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
410+
commandId=""
411+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
412+
413+
<key
414+
sequence="M1+M2+\"
415+
contextId="ts.eclipse.ide.jsdt.ui.typeScriptViewScope"
416+
commandId="ts.eclipse.ide.jsdt.ui.edit.text.java.remove.block.comment"
417+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
304418
<!-- search -->
305419
<key
306420
sequence="M1+M2+G"

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptEditor.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
import org.eclipse.ui.texteditor.TextOperationAction;
6767
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
6868
import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
69+
import org.eclipse.wst.jsdt.internal.ui.actions.AddBlockCommentAction;
70+
import org.eclipse.wst.jsdt.internal.ui.actions.RemoveBlockCommentAction;
6971
import org.eclipse.wst.jsdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider;
72+
import org.eclipse.wst.jsdt.internal.ui.javaeditor.ToggleCommentAction;
7073
import org.eclipse.wst.jsdt.internal.ui.text.PreferencesAdapter;
7174
import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
7275
import org.eclipse.wst.jsdt.ui.PreferenceConstants;
@@ -196,6 +199,27 @@ protected void createActions() {
196199
// PlatformUI.getWorkbench().getHelpSystem().setHelp(action,
197200
// IJavaHelpContextIds.FORMAT_ACTION);
198201

202+
action= new ToggleCommentAction(TypeScriptEditorMessages.getResourceBundle(), "ToggleComment.", this); //$NON-NLS-1$
203+
action.setActionDefinitionId(ITypeScriptEditorActionDefinitionIds.TOGGLE_COMMENT);
204+
setAction("ToggleComment", action); //$NON-NLS-1$
205+
markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
206+
//PlatformUI.getWorkbench().getHelpSystem().setHelp(action, IJavaHelpContextIds.TOGGLE_COMMENT_ACTION);
207+
configureToggleCommentAction();
208+
209+
action= new AddBlockCommentAction(TypeScriptEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
210+
action.setActionDefinitionId(ITypeScriptEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
211+
setAction("AddBlockComment", action); //$NON-NLS-1$
212+
markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
213+
markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
214+
// PlatformUI.getWorkbench().getHelpSystem().setHelp(action, IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
215+
216+
action= new RemoveBlockCommentAction(TypeScriptEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
217+
action.setActionDefinitionId(ITypeScriptEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
218+
setAction("RemoveBlockComment", action); //$NON-NLS-1$
219+
markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
220+
markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
221+
// PlatformUI.getWorkbench().getHelpSystem().setHelp(action, IJavaHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION);
222+
199223
action= new IndentAction(TypeScriptEditorMessages.getResourceBundle(), "Indent.", this, false); //$NON-NLS-1$
200224
action.setActionDefinitionId(ITypeScriptEditorActionDefinitionIds.INDENT);
201225
setAction("Indent", action); //$NON-NLS-1$
@@ -823,7 +847,7 @@ private Object getLockObject(IAnnotationModel annotationModel) {
823847
@Override
824848
protected void doSetInput(IEditorInput input) throws CoreException {
825849
super.doSetInput(input);
826-
850+
configureToggleCommentAction();
827851
// try {
828852
// //IDocument document = getSourceViewer().getDocument();
829853
// //setOutlinePageInput(getTypeScriptFile(document));
@@ -991,6 +1015,20 @@ private void setSelection(NavigationBarItem reference, boolean moveCursor) {
9911015
}
9921016
}
9931017

1018+
/**
1019+
* Configures the toggle comment action
1020+
*
1021+
*
1022+
*/
1023+
private void configureToggleCommentAction() {
1024+
IAction action= getAction("ToggleComment"); //$NON-NLS-1$
1025+
if (action instanceof ToggleCommentAction) {
1026+
ISourceViewer sourceViewer= getSourceViewer();
1027+
SourceViewerConfiguration configuration= getSourceViewerConfiguration();
1028+
((ToggleCommentAction)action).configure(sourceViewer, configuration);
1029+
}
1030+
}
1031+
9941032
@Override
9951033
protected void installTabsToSpacesConverter() {
9961034
ISourceViewer sourceViewer = getSourceViewer();

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptEditorActionContributor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public void setActiveEditor(IEditorPart part) {
5151
IActionBars bars = getActionBars();
5252
bars.setGlobalActionHandler(TypeScriptActionConstants.FORMAT, getAction(textEditor, "Format")); //$NON-NLS-1$
5353
bars.setGlobalActionHandler(TypeScriptActionConstants.INDENT, getAction(textEditor, "Indent")); //$NON-NLS-1$
54+
bars.setGlobalActionHandler(TypeScriptActionConstants.COMMENT, getAction(textEditor, "Comment")); //$NON-NLS-1$
55+
bars.setGlobalActionHandler(TypeScriptActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment")); //$NON-NLS-1$
56+
bars.setGlobalActionHandler(TypeScriptActionConstants.TOGGLE_COMMENT, getAction(textEditor, "ToggleComment")); //$NON-NLS-1$
57+
bars.setGlobalActionHandler(TypeScriptActionConstants.ADD_BLOCK_COMMENT,
58+
getAction(textEditor, "AddBlockComment")); //$NON-NLS-1$
59+
bars.setGlobalActionHandler(TypeScriptActionConstants.REMOVE_BLOCK_COMMENT,
60+
getAction(textEditor, "RemoveBlockComment")); //$NON-NLS-1$
5461

5562
fShowOutline.setAction(getAction(textEditor, ITypeScriptEditorActionDefinitionIds.SHOW_OUTLINE));
5663

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/ui/actions/ITypeScriptEditorActionDefinitionIds.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public interface ITypeScriptEditorActionDefinitionIds extends ITextEditorActionD
66

77
/**
88
* Action definition ID of the source -> indent action
9-
* (value <code>"org.eclipse.wst.jsdt.ui.edit.text.java.indent"</code>).
9+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.indent"</code>).
1010
*/
1111
public static final String INDENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.indent"; //$NON-NLS-1$
1212

@@ -16,6 +16,40 @@ public interface ITypeScriptEditorActionDefinitionIds extends ITextEditorActionD
1616
*/
1717
public static final String FORMAT = "ts.eclipse.ide.jsdt.ui.edit.text.java.format"; //$NON-NLS-1$
1818

19+
/**
20+
* Action definition ID of the source -> comment action
21+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.comment"</code>).
22+
*/
23+
public static final String COMMENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.comment"; //$NON-NLS-1$
24+
25+
/**
26+
* Action definition ID of the source -> uncomment action
27+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.uncomment"</code>).
28+
*/
29+
public static final String UNCOMMENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.uncomment"; //$NON-NLS-1$
30+
31+
/**
32+
* Action definition ID of the source -> toggle comment action
33+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"</code>).
34+
*
35+
*/
36+
public static final String TOGGLE_COMMENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.toggle.comment"; //$NON-NLS-1$
37+
38+
39+
/**
40+
* Action definition ID of the source -> add block comment action
41+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.add.block.comment"</code>).
42+
*
43+
*/
44+
public static final String ADD_BLOCK_COMMENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.add.block.comment"; //$NON-NLS-1$
45+
46+
/**
47+
* Action definition ID of the source -> remove block comment action
48+
* (value <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.remove.block.comment"</code>).
49+
*
50+
*/
51+
public static final String REMOVE_BLOCK_COMMENT= "ts.eclipse.ide.jsdt.ui.edit.text.java.remove.block.comment"; //$NON-NLS-1$
52+
1953
/**
2054
* Action definition ID of the search -> references in project action (value
2155
* <code>"ts.eclipse.ide.jsdt.ui.edit.text.java.search.references.in.project"</code>

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/ui/actions/TypeScriptActionConstants.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,47 @@ public class TypeScriptActionConstants {
1010

1111
/**
1212
* Source menu: name of standard Indent global action
13-
* (value <code>"org.eclipse.wst.jsdt.ui.actions.Indent"</code>).
13+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.Indent"</code>).
1414
*
1515
*
1616
*/
1717
public static final String INDENT= "ts.eclipse.ide.jsdt.ui.actions.Indent"; //$NON-NLS-1$
1818

19+
/**
20+
* Source menu: name of standard Comment global action
21+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.Comment"</code>).
22+
*/
23+
public static final String COMMENT= "ts.eclipse.ide.jsdt.ui.actions.Comment"; //$NON-NLS-1$
24+
25+
/**
26+
* Source menu: name of standard Uncomment global action
27+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.Uncomment"</code>).
28+
*/
29+
public static final String UNCOMMENT= "ts.eclipse.ide.jsdt.ui.actions.Uncomment"; //$NON-NLS-1$
30+
31+
/**
32+
* Source menu: name of standard ToggleComment global action
33+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.ToggleComment"</code>).
34+
*
35+
*/
36+
public static final String TOGGLE_COMMENT= "ts.eclipse.ide.jsdt.ui.actions.ToggleComment"; //$NON-NLS-1$
37+
38+
/**
39+
* Source menu: name of standard Block Comment global action
40+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.AddBlockComment"</code>).
41+
*
42+
*
43+
*/
44+
public static final String ADD_BLOCK_COMMENT= "ts.eclipse.ide.jsdt.ui.actions.AddBlockComment"; //$NON-NLS-1$
45+
46+
/**
47+
* Source menu: name of standard Block Uncomment global action
48+
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.RemoveBlockComment"</code>).
49+
*
50+
*
51+
*/
52+
public static final String REMOVE_BLOCK_COMMENT= "ts.eclipse.ide.jsdt.ui.actions.RemoveBlockComment"; //$NON-NLS-1$
53+
1954
/**
2055
* Search menu: name of standard Find References in Project global action
2156
* (value <code>"ts.eclipse.ide.jsdt.ui.actions.ReferencesInProject"</code>

0 commit comments

Comments
 (0)