Community
Participate
Working Groups
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
excellent third party contribution opportunities unless somebody contributes - they will not happen for 2.0
Reopening for 2.1 consideration
Ctrl+K is already used for find next.
Created attachment 2359 [details] Addition to main menu
Created attachment 2360 [details] Addition to pop-up menu
Created attachment 2361 [details] tests for Strings.capitalize(String) and Strings.invertCase(String)
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.
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 :)
*** Bug 25555 has been marked as a duplicate of this bug. ***
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.
"Unassign" PRs because of changes in staffing
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.
Has been added
Any plans for invert case, capitalize, sentence case ?
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
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 :)
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?
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.
I think the "IShouldBeAConstant -> I_SHOULD_BE_A_CONSTANT" and vice-versa transformations are useful when converting between object model and data model fields.
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.
>>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
We definitely need another UI besides shortcuts. I favor version A. -tom
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.