Bug 192045 - [nls tooling] Properties file editor should have "toggle comment" action
Summary: [nls tooling] Properties file editor should have "toggle comment" action
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.2.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.4 M3   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-06-11 17:14 EDT by Alex Miller CLA
Modified: 2007-10-26 04:19 EDT (History)
4 users (show)

See Also:


Attachments
patch to org.eclipse.jdt.ui (5.76 KB, patch)
2007-06-11 23:05 EDT, Brock Janiczak CLA
no flags Details | Diff
patch to org.eclipse.jdt.ui (8.97 KB, patch)
2007-06-12 21:19 EDT, Brock Janiczak CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Miller CLA 2007-06-11 17:14:52 EDT
It would be great if in the properties file editor there were some way to do the equivalent of the Java "toggle comment" action to add/remove # to the beginning of each line.  

So, given a file foo.properties:

# Neato properties
p1=a
p2=b
p3=c

I would like to highlight lines 2-4, select the "Toggle Comment" action (I'd even be happy to have the key combo be the same as the Java editor key combo even though it makes less sense here) and get this result:

# Neato properties
#p1=a
#p2=b
#p3=c

Selecting the same action again with same lines highlighted would revert to the original version.
Comment 1 Brock Janiczak CLA 2007-06-11 23:05:18 EDT
Created attachment 70941 [details]
patch to org.eclipse.jdt.ui

This basic patch hooks into the prefix/unprefix code in the source viewer.  It exposes the operation only though command keybindings (no context actions)

It does this by registering a new key binding context (editing properties files) and hooking up the existing toggle comment command used in the compilation unit editor.

Would it be possible to push down ToggleCommentAction into the text editing layer?  The action should work for all languages that have single line comments
Comment 2 Dani Megert CLA 2007-06-12 03:16:50 EDT
>Would it be possible to push down ToggleCommentAction into the text editing
>layer? 
Yes, if we find a more generic name as the generic text framework doesn't have the notion of a comment.
Comment 3 Brock Janiczak CLA 2007-06-12 03:30:08 EDT
(In reply to comment #2)
> >Would it be possible to push down ToggleCommentAction into the text editing
> >layer? 
> Yes, if we find a more generic name as the generic text framework doesn't have
> the notion of a comment.
> 
how about TogglePrefixAction?  Under the hood it basically wraps the prefix and unprefix text editor operations.
Comment 4 Dani Megert CLA 2007-06-12 03:34:15 EDT
Yes, sounds good. We should then also move the corresponding tests. While moving down, I would probably only create the action in createActions() but not hook it up in the UI for all editors.

Can you prepare such a patch?
Comment 5 Brock Janiczak CLA 2007-06-12 05:21:55 EDT
I will try to create something either tonight or tomorrow.

I assume that also means that the command definition and keybindings also get pushed down to text?

If the command is pushed down, what should the description be?  Most users would not have a clue what a line prefix is.  You can work around this by naming the context menu actions as "toggle comment", but you the command will still have the odd name in the keys preference page.
Comment 6 Dani Megert CLA 2007-06-12 05:29:36 EDT
>I will try to create something either tonight or tomorrow.
There's no hurry ;-)

Looks like it's better not to create the action createActions() for all editors but instead only provide the generic TogglePrefixAction that can then be created by the individual editor with the desired label and description.
Comment 7 Brock Janiczak CLA 2007-06-12 21:19:16 EDT
Created attachment 71104 [details]
patch to org.eclipse.jdt.ui

Updated patch.

It does not modify the ToggleCommentAction at all as more thought is needed before pushing it down.  Instead, I have cleaned up the previous patch and added the action to the context menu (by overriding createEditorContextMenu).  It also re-uses the Java toggle comment command instead of creating a new one.

Also, the action is not available in the PDE property file editors because they do not activate the new keybinding scope and don't seem to use the PropertyFileEditor directly.
Comment 8 Dani Megert CLA 2007-10-26 04:19:29 EDT
Thanks for the patch. I committed the patch with a few small changes:
- added your credentials to the copyright notes
- remove "(non-javadoc)"
- added @since tags

Available in builds > N20071026-0010.