Bug 8518 - [typing] change case functionality
Summary: [typing] change case functionality
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: 3.0 M1   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 25555 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-01-25 18:12 EST by ovi CLA
Modified: 2006-06-17 01:04 EDT (History)
5 users (show)

See Also:


Attachments
Addition to main menu (33.01 KB, image/jpeg)
2002-11-10 12:49 EST, Sebastian Davids CLA
no flags Details
Addition to pop-up menu (53.95 KB, image/jpeg)
2002-11-10 12:49 EST, Sebastian Davids CLA
no flags Details
tests for Strings.capitalize(String) and Strings.invertCase(String) (4.37 KB, patch)
2002-11-10 12:52 EST, Sebastian Davids CLA
no flags Details | Diff
Adds the To Upper Case, To Lower Case, Invert Case and Capitalize Actions (37.33 KB, patch)
2002-11-10 13:29 EST, Sebastian Davids CLA
no flags Details | Diff
fix (29.69 KB, patch)
2003-06-20 13:24 EDT, Sebastian Davids CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ovi CLA 2002-01-25 18:12:12 EST
change case functionality in editors

function: change to upper case; suggested shortcut: Ctrl U
function: change to lower case; suggested shortcut: Ctrl L
function: invert case; suggested shortcut: Ctrl K
function: capitalize; suggested shortcut: Ctrl Shift U
Comment 1 Erich Gamma CLA 2002-05-11 08:56:34 EDT
excellent third party contribution opportunities

unless somebody contributes - they will not happen for 2.0
Comment 2 Dirk Baeumer CLA 2002-07-24 10:46:26 EDT
Reopening for 2.1 consideration
Comment 3 Claude Knaus CLA 2002-09-13 10:34:30 EDT
Ctrl+K is already used for find next.
Comment 4 Sebastian Davids CLA 2002-11-10 12:49:07 EST
Created attachment 2359 [details]
Addition to main menu
Comment 5 Sebastian Davids CLA 2002-11-10 12:49:40 EST
Created attachment 2360 [details]
Addition to pop-up menu
Comment 6 Sebastian Davids CLA 2002-11-10 12:52:58 EST
Created attachment 2361 [details]
tests for Strings.capitalize(String) and Strings.invertCase(String)
Comment 7 Sebastian Davids CLA 2002-11-10 13:29:38 EST
Created attachment 2362 [details]
Adds the To Upper Case, To Lower Case, Invert Case and Capitalize Actions

I took org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction as a starting
point.

I created the actions ToUpperCaseAction, ToLowerCaseAction, InvertCaseAction,
and CapitalizeAction.

I factored the stuff all 5 classes had into a super class TextSelectionAction
and subclasses all 5 classes from this new one.

TextSelectionAction is package visible -- clients should not know about it.

I added two methods (capitalize(String) and invertCase(String) to class
org.eclipse.jdt.internal.corext.util.Strings.

Both methods have tests in org.eclipse.jdt.ui.tests.text.StringsTest.
Comment 8 Adam Kiezun CLA 2002-11-11 13:31:15 EST
well, i guess

+ * Contributors:
+ *     IBM Corporation - initial API and implementation

should really be:

+ * Contributors:
+ *     Sebastian Davids - initial API and implementation

don't be shy Sebastian - you wrote it, you deserve the credit for it
:)
Comment 9 Martin Aeschlimann CLA 2002-11-12 07:19:32 EST
*** Bug 25555 has been marked as a duplicate of this bug. ***
Comment 10 Martin Aeschlimann CLA 2002-11-12 11:22:10 EST
*** Bug 25555 has been marked as a duplicate of this bug. ***
Comment 11 ovi CLA 2002-11-12 19:05:58 EST
Well, it's great that we have this feature in, but in my opinion the true power 
of change case functionality it's in shortcuts. If I have to use the mouse to 
navigate through (context) menus it becomes ineffective.
Comment 12 Kai-Uwe Maetzel CLA 2003-01-13 12:13:57 EST
"Unassign" PRs because of changes in staffing
Comment 13 Tom Hofmann CLA 2003-05-12 12:26:42 EDT
Case toggling will be added in the upcoming releases. 

Sebastian, thanks for the crafty patch - however, since case toggle is not Java 
specific, this will have to go into the text infrastructure / 
AbstractTextEditor.

The string functions might come in handy, though.
Comment 14 Dani Megert CLA 2003-06-17 04:03:50 EDT
Has been added
Comment 15 ovi CLA 2003-06-17 20:55:06 EDT
Any plans for invert case, capitalize, sentence case ?
Comment 16 Tom Hofmann CLA 2003-06-18 03:14:16 EDT
Seems like Erich's comment 1 is still true - I guess this is nice-to-have 
functionality, but I haven't seen a convincing use case for sentence case yet. 

Of course, if someone would like to contribute a patch...

Pointers:
- Sebastian (comment 7) has already taken a first shot with lots of code (and 
tests!) to reuse. 
- CaseAction  for how toUpper / toLower works at the moment
- AbstractTextEditor.createActions() for how these actions are installed
Comment 17 Sebastian Davids CLA 2003-06-20 13:24:47 EDT
Created attachment 5259 [details]
fix

Implementation notes:

@@ Case Action @@

I factored the "lower/upper" case functionality into a subclass
UpperLowerCaseAction.

I adjusted run() so that it calls the abstract method replace().

I also adjusted the selection handling -- an inverted String might be larger
than the original ... German "Maße" becomes "mASSE" for example.

@@

Created InvertCaseAction and CapitalizeCaseAction.

@@

Created Strings and StringsTest.

Right now StringsTest will not compile because JUnit is not on the classpath of
org.eclipse.ui.workbench.texteditor

Both Strings and StringsTest should be placed somewhere else but I did not know
where :)
Comment 18 Sebastian Davids CLA 2003-06-20 13:34:04 EDT
I assigned:

Capitalize - Ctrl+Shift+C
Invert Case - Ctrl+Shift+I

@@@@

What is sentence case supposed to be?

@@@@

Probably the following might come handy also:

IShouldBeAConstant -> I_SHOULD_BE_A_CONSTANT

Rules:

- all letters are in uppercase 
- each large letter in the input will be preceeded with an _ in the output ...
exception the first letter of the input

How should this "case" change be named?
Comment 19 Sebastian Davids CLA 2003-06-20 15:56:10 EDT
Both of the following cannot be done without considering the locale:

 Guideline 1.5

    Use Headline style capitalization for all titles, including those used for
windows, dialogs, tabs, column headings and push buttons. Capitalize the first
and last words, and all nouns, pronouns, adjectives, verbs and adverbs.  Do not
include ending punctuation.

Guideline 1.6

    Use Sentence style capitalization for all control labels in a dialog or
window, including those for check boxes, radio buttons, group labels, and simple
text fields.  Capitalize the first letter of the first word, and any proper names.
Comment 20 ovi CLA 2003-06-20 18:26:45 EDT
I think the "IShouldBeAConstant -> I_SHOULD_BE_A_CONSTANT" and vice-versa 
transformations are useful when converting between object model and data model 
fields.
Comment 21 Tom Hofmann CLA 2003-06-23 03:03:58 EDT
Thanks for the patch - I will look into it and post feedback as soon as I have 
reviewed it!

- Sentence & Headline (Title) Case: these are not really doable easily, because 
they depend heavily not only on the input locale but on the context as well - 
detecting proper names in unstructured text is still subject to ongoing 
research in Computational Linguistics...

The easy approximation is to uppercase every first letter of a word for title 
case and to uppercase the first letter in a sentence for sentence case, 
respectively. Not sure whether I would use that - I guess it wouldn't be too 
much work, though (see BreakIterator.getSentenceInstance).

- Camel Case to/from Constant Case (fooBar -> FOO_BAR): definitely usable and 
worth to have using the rules stated in comment 18.
Comment 22 Sebastian Davids CLA 2003-06-23 05:07:28 EDT
>>Camel Case to/from Constant Case

I will work on it in the next couple of days.

@@@@

Another question: What about an UI for all of these? -- There should be another
way of accessing these other than key-shortcuts.

a) a context-menu entry with submenu:

Change Case
> To Upper
> To Lower
> Invert
> Capitalize
> To Constant Case
> From Constant Case

b) 

a context-menu entry "Change Case..." with a dialog like (selection "IWantToBe
Converted" [if selection to large cut off at a particular position]):

[] IWANTTOBE CONVERTED
[] iwanttobe converted
[] iwANTtObE CONVERTED
[] IWantToBe Converted
[] I_WANT_TO_BE CONVERTED
[] IWantToBe Converted

OK/Cancel

c) 

a context-menu entry "Change Case..." and a dialog like:

[] To Upper Case
[] To Lower Case
[] Invert
[] Capitalize
[] To Constant Case
[] From Constant Case

<<Preview area>>

OK Cancel
Comment 23 Tom Hofmann CLA 2003-06-23 07:13:14 EDT
We definitely need another UI besides shortcuts. I favor version A.
-tom
Comment 24 Sebastian Davids CLA 2006-06-17 01:04:28 EDT
I attached an updated version of the fix from comment 17 to bug 125825 comment 3.

It supports:

capitalize -> Capitalize
LOWER_CAMEL_CASE -> lowerCamelCase
UPPER_CAMEL_CASE -> UpperCamelCase
iNVERT cASE -> Invert Case
constantCase -> CONSTANT_CASE

This bug can stay closed RESOLVED FIXED even though this bug's original request is not fixed yet but will be by bug 125825.