Stephan Herrmann | 53b3b92 | 2015-02-14 22:37:15 +0100 | [diff] [blame] | 1 | ### Eclipse Workspace Patch 1.0 |
| 2 | #P org.eclipse.jdt.ui |
| 3 | diff --git ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java |
| 4 | index bbcb3bb..949bf62 100644 |
| 5 | --- ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java |
| 6 | +++ ui/org/eclipse/jdt/internal/ui/preferences/formatter/IndentationTabPage.java |
| 7 | @@ -19,8 +19,6 @@ |
| 8 | import org.eclipse.swt.widgets.Composite; |
| 9 | import org.eclipse.swt.widgets.Group; |
| 10 | |
| 11 | -import org.eclipse.core.runtime.Assert; |
| 12 | - |
| 13 | import org.eclipse.jdt.core.JavaCore; |
| 14 | import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
| 15 | |
| 16 | @@ -60,7 +58,6 @@ |
| 17 | "}";//$NON-NLS-1$ |
| 18 | |
| 19 | private CompilationUnitPreview fPreview; |
| 20 | - private String fOldTabChar= null; |
| 21 | |
| 22 | public IndentationTabPage(ModifyDialog modifyDialog, Map<String, String> workingValues) { |
| 23 | super(modifyDialog, workingValues); |
| 24 | @@ -79,21 +76,17 @@ |
| 25 | }; |
| 26 | final ComboPreference tabPolicy= createComboPref(generalGroup, numColumns, FormatterMessages.IndentationTabPage_general_group_option_tab_policy, DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, tabPolicyValues, tabPolicyLabels); |
| 27 | final CheckboxPreference onlyForLeading= createCheckboxPref(generalGroup, numColumns, FormatterMessages.IndentationTabPage_use_tabs_only_for_leading_indentations, DefaultCodeFormatterConstants.FORMATTER_USE_TABS_ONLY_FOR_LEADING_INDENTATIONS, FALSE_TRUE); |
| 28 | - final NumberPreference indentSize= createNumberPref(generalGroup, numColumns, FormatterMessages.IndentationTabPage_general_group_option_indent_size, DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, 0, 32); |
| 29 | + final NumberPreference indentSize= createNumberPref(generalGroup, numColumns, FormatterMessages.IndentationTabPage_general_group_option_indent_size, DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, 0, 32); |
| 30 | final NumberPreference tabSize= createNumberPref(generalGroup, numColumns, FormatterMessages.IndentationTabPage_general_group_option_tab_size, DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, 0, 32); |
| 31 | |
| 32 | - String tabchar= fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); |
| 33 | - updateTabPreferences(tabchar, tabSize, indentSize, onlyForLeading); |
| 34 | - tabPolicy.addObserver(new Observer() { |
| 35 | + updateTabPreferences(indentSize, onlyForLeading); |
| 36 | + Observer tabObserver = new Observer() { |
| 37 | public void update(Observable o, Object arg) { |
| 38 | - updateTabPreferences((String) arg, tabSize, indentSize, onlyForLeading); |
| 39 | + updateTabPreferences(indentSize, onlyForLeading); |
| 40 | } |
| 41 | - }); |
| 42 | - tabSize.addObserver(new Observer() { |
| 43 | - public void update(Observable o, Object arg) { |
| 44 | - indentSize.updateWidget(); |
| 45 | - } |
| 46 | - }); |
| 47 | + }; |
| 48 | + tabPolicy.addObserver(tabObserver); |
| 49 | + tabSize.addObserver(tabObserver); |
| 50 | |
| 51 | final Group typeMemberGroup= createGroup(numColumns, composite, FormatterMessages.IndentationTabPage_field_alignment_group_title); |
| 52 | createCheckboxPref(typeMemberGroup, numColumns, FormatterMessages.IndentationTabPage_field_alignment_group_align_fields_in_columns, DefaultCodeFormatterConstants.FORMATTER_ALIGN_TYPE_MEMBERS_ON_COLUMNS, FALSE_TRUE); |
| 53 | @@ -141,50 +134,17 @@ |
| 54 | fPreview.update(); |
| 55 | } |
| 56 | |
| 57 | - private void updateTabPreferences(String tabPolicy, NumberPreference tabPreference, NumberPreference indentPreference, CheckboxPreference onlyForLeading) { |
| 58 | - /* |
| 59 | - * If the tab-char is SPACE (or TAB), INDENTATION_SIZE |
| 60 | - * preference is not used by the core formatter. We piggy back the |
| 61 | - * visual tab length setting in that preference in that case. If the |
| 62 | - * user selects MIXED, we use the previous TAB_SIZE preference as the |
| 63 | - * new INDENTATION_SIZE (as this is what it really is) and set the |
| 64 | - * visual tab size to the value piggy backed in the INDENTATION_SIZE |
| 65 | - * preference. See also CodeFormatterUtil. |
| 66 | - */ |
| 67 | - if (DefaultCodeFormatterConstants.MIXED.equals(tabPolicy)) { |
| 68 | - if (JavaCore.SPACE.equals(fOldTabChar) || JavaCore.TAB.equals(fOldTabChar)) |
| 69 | - swapTabValues(); |
| 70 | - tabPreference.setEnabled(true); |
| 71 | - tabPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 72 | - indentPreference.setEnabled(true); |
| 73 | - indentPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE); |
| 74 | - onlyForLeading.setEnabled(true); |
| 75 | - } else if (JavaCore.SPACE.equals(tabPolicy)) { |
| 76 | - if (DefaultCodeFormatterConstants.MIXED.equals(fOldTabChar)) |
| 77 | - swapTabValues(); |
| 78 | - tabPreference.setEnabled(true); |
| 79 | - tabPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE); |
| 80 | - indentPreference.setEnabled(true); |
| 81 | - indentPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 82 | - onlyForLeading.setEnabled(false); |
| 83 | - } else if (JavaCore.TAB.equals(tabPolicy)) { |
| 84 | - if (DefaultCodeFormatterConstants.MIXED.equals(fOldTabChar)) |
| 85 | - swapTabValues(); |
| 86 | - tabPreference.setEnabled(true); |
| 87 | - tabPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 88 | - indentPreference.setEnabled(false); |
| 89 | - indentPreference.setKey(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 90 | - onlyForLeading.setEnabled(true); |
| 91 | - } else { |
| 92 | - Assert.isTrue(false); |
| 93 | - } |
| 94 | - fOldTabChar= tabPolicy; |
| 95 | - } |
| 96 | + private void updateTabPreferences(NumberPreference indentPreference, CheckboxPreference onlyForLeading) { |
| 97 | + String tabPolicy = fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); |
| 98 | + onlyForLeading.setEnabled(!JavaCore.SPACE.equals(tabPolicy)); |
| 99 | |
| 100 | - private void swapTabValues() { |
| 101 | - String tabSize= fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 102 | - String indentSize= fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE); |
| 103 | - fWorkingValues.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, indentSize); |
| 104 | - fWorkingValues.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, tabSize); |
| 105 | + if (JavaCore.TAB.equals(tabPolicy)) { |
| 106 | + // indentation size preference must be disabled and show the same value as tab size |
| 107 | + String tabSize= fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE); |
| 108 | + fWorkingValues.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, tabSize); |
| 109 | + indentPreference.setEnabled(false); |
| 110 | + } else { |
| 111 | + indentPreference.setEnabled(true); |
| 112 | + } |
| 113 | } |
| 114 | } |