From 23273506de57edba3f7c593ba8180d819567a1b1 Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 1 Jun 2005 21:21:34 +0000 Subject: [PATCH] Action borrowed from cfeclipse: "remove trailing spaces at end of file" --- .../ui/preferences/JavaEditorPreferencePage.java | 343 ++++++++------- .../sourceforge/phpdt/ui/PreferenceConstants.java | 4 +- .../phpeclipse/phpeditor/PHPUnitEditor.java | 454 ++++++++++---------- .../phpeclipse/phpeditor/actions/RTrimAction.java | 114 +++++ .../phpeditor/php/PHPCompletionProcessor.java | 46 +-- 5 files changed, 520 insertions(+), 441 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/actions/RTrimAction.java diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java index 23ce056..42c40a9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/JavaEditorPreferencePage.java @@ -96,10 +96,12 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben public final OverlayPreferenceStore.OverlayKey[] fKeys; private final String[][] fSyntaxColorListModel = new String[][] { - { PreferencesMessages.getString("JavaEditorPreferencePage.multiLineComment"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.multiLineComment"), PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR }, //$NON-NLS-1$ - { PreferencesMessages.getString("JavaEditorPreferencePage.singleLineComment"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.singleLineComment"), PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR }, //$NON-NLS-1$ { PreferencesMessages.getString("JavaEditorPreferencePage.tags"), PreferenceConstants.EDITOR_PHP_TAG_COLOR }, @@ -119,10 +121,10 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben { PreferencesMessages.getString("JavaEditorPreferencePage.others"), PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR }, //$NON-NLS-1$ { PreferencesMessages.getString("JavaEditorPreferencePage.operators"), PreferenceConstants.EDITOR_PHP_OPERATOR_COLOR }, //$NON-NLS-1$ - { PreferencesMessages.getString("JavaEditorPreferencePage.returnKeyword"), - PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR }, - { PreferencesMessages.getString("JavaEditorPreferencePage.braces"), - PreferenceConstants.EDITOR_PHP_BRACE_OPERATOR_COLOR }, + { + PreferencesMessages.getString("JavaEditorPreferencePage.returnKeyword"), + PreferenceConstants.EDITOR_PHP_KEYWORD_RETURN_COLOR }, + { PreferencesMessages.getString("JavaEditorPreferencePage.braces"), PreferenceConstants.EDITOR_PHP_BRACE_OPERATOR_COLOR }, //$NON-NLS-1$ { PreferencesMessages.getString("JavaEditorPreferencePage.phpDocKeywords"), PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR }, //$NON-NLS-1$ @@ -134,16 +136,20 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben }; private final String[][] fAppearanceColorListModel = new String[][] { - { PreferencesMessages.getString("JavaEditorPreferencePage.lineNumberForegroundColor"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.lineNumberForegroundColor"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR }, //$NON-NLS-1$ - { PreferencesMessages.getString("JavaEditorPreferencePage.matchingBracketsHighlightColor2"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.matchingBracketsHighlightColor2"), PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR }, //$NON-NLS-1$ - { PreferencesMessages.getString("JavaEditorPreferencePage.currentLineHighlighColor"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.currentLineHighlighColor"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR }, //$NON-NLS-1$ - { PreferencesMessages.getString("JavaEditorPreferencePage.printMarginColor2"), + { + PreferencesMessages.getString("JavaEditorPreferencePage.printMarginColor2"), AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR }, //$NON-NLS-1$ { PreferencesMessages.getString("JavaEditorPreferencePage.findScopeColor2"), PreferenceConstants.EDITOR_FIND_SCOPE_COLOR }, @@ -246,7 +252,7 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben // private Button fAddJavaDocTagsButton; private Button fEscapeStringsButtonDQ; - + private Button fEscapeStringsButtonSQ; // private Button fGuessMethodArgumentsButton; @@ -276,9 +282,12 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben private Button fShowInVerticalRulerCheckBox; - private Text fBrowserLikeLinksKeyModifierText; - private Button fBrowserLikeLinksCheckBox; - private StatusInfo fBrowserLikeLinksKeyModifierStatus; + private Text fBrowserLikeLinksKeyModifierText; + + private Button fBrowserLikeLinksCheckBox; + + private StatusInfo fBrowserLikeLinksKeyModifierStatus; + // private Button fCompletionInsertsRadioButton; // private Button fCompletionOverwritesRadioButton; // private Button fStickyOccurrencesButton; @@ -339,10 +348,14 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben overlayKeys .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_PHP_TYPE_BOLD)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR_DQ)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD_DQ)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR_SQ)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD_SQ)); + overlayKeys + .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR_DQ)); + overlayKeys + .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD_DQ)); + overlayKeys + .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_STRING_COLOR_SQ)); + overlayKeys + .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STRING_BOLD_SQ)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, @@ -467,22 +480,24 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben // .add(new OverlayPreferenceStore.OverlayKey( // OverlayPreferenceStore.BOOLEAN, // PreferenceConstants.EDITOR_CLOSE_BRACES)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey( - OverlayPreferenceStore.BOOLEAN, - PreferenceConstants.EDITOR_CLOSE_JAVADOCS)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_WORDS)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_STRINGS_DQ)); overlayKeys - .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ)); - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_STRINGS_SQ)); - overlayKeys - .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ)); - + .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_CLOSE_JAVADOCS)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_WRAP_WORDS)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_WRAP_STRINGS_DQ)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_ESCAPE_STRINGS_DQ)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_WRAP_STRINGS_SQ)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FORMAT_JAVADOCS)); - + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, + PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE)); overlayKeys .add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SMART_HOME_END)); @@ -717,19 +732,23 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben Preferences coreStore = createTemporaryCorePreferenceStore(); fJavaTextTools = new JavaTextTools(fOverlayStore, coreStore, false); IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore(); - IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { fOverlayStore, - new PreferencesAdapter(createTemporaryCorePreferenceStore()), generalTextStore }); + IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { + fOverlayStore, + new PreferencesAdapter(createTemporaryCorePreferenceStore()), + generalTextStore }); fPreviewViewer = new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store); - JavaTextTools tools= PHPeclipsePlugin.getDefault().getJavaTextTools(); - PHPSourceViewerConfiguration configuration= new PHPSourceViewerConfiguration(tools.getColorManager(), store, null, IPHPPartitions.PHP_PARTITIONING); -// PHPSourceViewerConfiguration configuration =new PHPSourceViewerConfiguration(fJavaTextTools, null, IPHPPartitions.PHP_PARTITIONING); + JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools(); + PHPSourceViewerConfiguration configuration = new PHPSourceViewerConfiguration(tools.getColorManager(), store, null, + IPHPPartitions.PHP_PARTITIONING); + // PHPSourceViewerConfiguration configuration =new PHPSourceViewerConfiguration(fJavaTextTools, null, + // IPHPPartitions.PHP_PARTITIONING); fPreviewViewer.configure(configuration); - - Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); - fPreviewViewer.getTextWidget().setFont(font); + + Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT); + fPreviewViewer.getTextWidget().setFont(font); new JavaSourcePreviewerUpdater(fPreviewViewer, configuration, store); - fPreviewViewer.setEditable(false); + fPreviewViewer.setEditable(false); String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$ IDocument document = new Document(content); fJavaTextTools.setupJavaDocumentPartitioner(document, IPHPPartitions.PHP_PARTITIONING); @@ -1038,8 +1057,13 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben Iterator e = sortedPreferences.iterator(); while (e.hasNext()) { AnnotationPreference info = (AnnotationPreference) e.next(); - listModelItems.add(new String[] { info.getPreferenceLabel(), info.getColorPreferenceKey(), info.getTextPreferenceKey(), - info.getOverviewRulerPreferenceKey(), info.getHighlightPreferenceKey(), info.getVerticalRulerPreferenceKey(), + listModelItems.add(new String[] { + info.getPreferenceLabel(), + info.getColorPreferenceKey(), + info.getTextPreferenceKey(), + info.getOverviewRulerPreferenceKey(), + info.getHighlightPreferenceKey(), + info.getVerticalRulerPreferenceKey(), info.getTextStylePreferenceKey() }); } String[][] items = new String[listModelItems.size()][]; @@ -1079,7 +1103,7 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben label = PreferencesMessages.getString("JavaEditorPreferencePage.wrapWords");//$NON-NLS-1$ addCheckBox(group, label, PreferenceConstants.EDITOR_WRAP_WORDS, 1); - + label = PreferencesMessages.getString("JavaEditorPreferencePage.wrapStringsDQ");//$NON-NLS-1$ Button button = addCheckBox(group, label, PreferenceConstants.EDITOR_WRAP_STRINGS_DQ, 1); @@ -1094,7 +1118,7 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben //$NON-NLS-1$ fEscapeStringsButtonSQ = addCheckBox(group, label, PreferenceConstants.EDITOR_ESCAPE_STRINGS_SQ, 1); createDependency(button, fEscapeStringsButtonSQ); - + label = PreferencesMessages.getString("JavaEditorPreferencePage.smartPaste"); //$NON-NLS-1$ addCheckBox(group, label, PreferenceConstants.EDITOR_SMART_PASTE, 1); @@ -1119,16 +1143,15 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben // //$NON-NLS-1$ // addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_BRACES, 1); - label = PreferencesMessages - .getString("JavaEditorPreferencePage.closeJavaDocs"); - //$NON-NLS-1$ - button = addCheckBox(group, label, - PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 1); - label = PreferencesMessages - .getString("JavaEditorPreferencePage.formatJavaDocs"); + label = PreferencesMessages.getString("JavaEditorPreferencePage.closeJavaDocs"); //$NON-NLS-1$ - button = addCheckBox(group, label, - PreferenceConstants.EDITOR_FORMAT_JAVADOCS, 1); + button = addCheckBox(group, label, PreferenceConstants.EDITOR_CLOSE_JAVADOCS, 1); + label = PreferencesMessages.getString("JavaEditorPreferencePage.formatJavaDocs"); + //$NON-NLS-1$ + button = addCheckBox(group, label, PreferenceConstants.EDITOR_FORMAT_JAVADOCS, 1); + + label = PreferencesMessages.getString("JavaEditorPreferencePage.p_rtrim_on_save"); + addCheckBox(group, label, PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE, 1); // // label = PreferencesMessages // .getString("JavaEditorPreferencePage.addJavaDocTags"); @@ -1202,124 +1225,111 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben GridLayout layout = new GridLayout(); layout.numColumns = 2; composite.setLayout(layout); - String text= - PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinks"); - //$NON-NLS-1$ - fBrowserLikeLinksCheckBox= addCheckBox(composite, text, - PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, 0); - fBrowserLikeLinksCheckBox.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - boolean state= fBrowserLikeLinksCheckBox.getSelection(); - fBrowserLikeLinksKeyModifierText.setEnabled(state); - handleBrowserLikeLinksKeyModifierModified(); - } - public void widgetDefaultSelected(SelectionEvent e) { - } - }); -// Text field for modifier string - text= - PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinksKeyModifier"); - //$NON-NLS-1$ - fBrowserLikeLinksKeyModifierText= addTextField(composite, text, - PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, 20, 0, - false); - fBrowserLikeLinksKeyModifierText.setTextLimit(Text.LIMIT); - - if - (computeStateMask(fOverlayStore.getString(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER)) - == -1) { - // Fix possible illegal modifier string - int stateMask= - fOverlayStore.getInt(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK); - if (stateMask == -1) - fBrowserLikeLinksKeyModifierText.setText(""); //$NON-NLS-1$ - else - fBrowserLikeLinksKeyModifierText.setText(EditorUtility.getModifierString(stateMask)); - } - fBrowserLikeLinksKeyModifierText.addKeyListener(new KeyListener() { - private boolean isModifierCandidate; - public void keyPressed(KeyEvent e) { - isModifierCandidate= e.keyCode > 0 && e.character == 0 && e.stateMask == - 0; - } - - public void keyReleased(KeyEvent e) { - if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask - && e.character == 0) {// && e.time -time < 1000) { - String modifierString= fBrowserLikeLinksKeyModifierText.getText(); - Point selection= fBrowserLikeLinksKeyModifierText.getSelection(); - int i= selection.x - 1; - while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) { - i--; - } - boolean needsPrefixDelimiter= i > -1 && - !String.valueOf(modifierString.charAt(i)).equals(DELIMITER); - - i= selection.y; - while (i < modifierString.length() && - Character.isWhitespace(modifierString.charAt(i))) { - i++; - } - boolean needsPostfixDelimiter= i < modifierString.length() && - !String.valueOf(modifierString.charAt(i)).equals(DELIMITER); - - String insertString; - - if (needsPrefixDelimiter && needsPostfixDelimiter) - insertString= - PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertDelimiterAndModifierAndDelimiter", - new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$ - else if (needsPrefixDelimiter) - insertString= - PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertDelimiterAndModifier", - new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$ - else if (needsPostfixDelimiter) - insertString= - PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertModifierAndDelimiter", - new String[] {Action.findModifierString(e.stateMask)}); //$NON-NLS-1$ - else - insertString= Action.findModifierString(e.stateMask); - - fBrowserLikeLinksKeyModifierText.insert(insertString); - } - } - }); - - fBrowserLikeLinksKeyModifierText.addModifyListener(new ModifyListener() - { - public void modifyText(ModifyEvent e) { - handleBrowserLikeLinksKeyModifierModified(); - } - }); + String text = PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinks"); + //$NON-NLS-1$ + fBrowserLikeLinksCheckBox = addCheckBox(composite, text, PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS, 0); + fBrowserLikeLinksCheckBox.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + boolean state = fBrowserLikeLinksCheckBox.getSelection(); + fBrowserLikeLinksKeyModifierText.setEnabled(state); + handleBrowserLikeLinksKeyModifierModified(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + // Text field for modifier string + text = PreferencesMessages.getString("JavaEditorPreferencePage.navigation.browserLikeLinksKeyModifier"); + //$NON-NLS-1$ + fBrowserLikeLinksKeyModifierText = addTextField(composite, text, PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER, + 20, 0, false); + fBrowserLikeLinksKeyModifierText.setTextLimit(Text.LIMIT); + + if (computeStateMask(fOverlayStore.getString(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER)) == -1) { + // Fix possible illegal modifier string + int stateMask = fOverlayStore.getInt(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK); + if (stateMask == -1) + fBrowserLikeLinksKeyModifierText.setText(""); //$NON-NLS-1$ + else + fBrowserLikeLinksKeyModifierText.setText(EditorUtility.getModifierString(stateMask)); + } + fBrowserLikeLinksKeyModifierText.addKeyListener(new KeyListener() { + private boolean isModifierCandidate; + + public void keyPressed(KeyEvent e) { + isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0; + } + + public void keyReleased(KeyEvent e) { + if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {// && e.time -time < 1000) { + String modifierString = fBrowserLikeLinksKeyModifierText.getText(); + Point selection = fBrowserLikeLinksKeyModifierText.getSelection(); + int i = selection.x - 1; + while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) { + i--; + } + boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(DELIMITER); + + i = selection.y; + while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) { + i++; + } + boolean needsPostfixDelimiter = i < modifierString.length() + && !String.valueOf(modifierString.charAt(i)).equals(DELIMITER); + + String insertString; + + if (needsPrefixDelimiter && needsPostfixDelimiter) + insertString = PreferencesMessages.getFormattedString( + "JavaEditorPreferencePage.navigation.insertDelimiterAndModifierAndDelimiter", new String[] { Action + .findModifierString(e.stateMask) }); //$NON-NLS-1$ + else if (needsPrefixDelimiter) + insertString = PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertDelimiterAndModifier", + new String[] { Action.findModifierString(e.stateMask) }); //$NON-NLS-1$ + else if (needsPostfixDelimiter) + insertString = PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.insertModifierAndDelimiter", + new String[] { Action.findModifierString(e.stateMask) }); //$NON-NLS-1$ + else + insertString = Action.findModifierString(e.stateMask); + + fBrowserLikeLinksKeyModifierText.insert(insertString); + } + } + }); + + fBrowserLikeLinksKeyModifierText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + handleBrowserLikeLinksKeyModifierModified(); + } + }); return composite; } private void handleBrowserLikeLinksKeyModifierModified() { - String modifiers= fBrowserLikeLinksKeyModifierText.getText(); - int stateMask= computeStateMask(modifiers); - if (fBrowserLikeLinksCheckBox.getSelection() && (stateMask == -1 || - (stateMask & SWT.SHIFT) != 0)) { - if (stateMask == -1) - fBrowserLikeLinksKeyModifierStatus= new StatusInfo(IStatus.ERROR, - PreferencesMessages.getFormattedString("JavaEditorPreferencePage.navigation.modifierIsNotValid", - modifiers)); //$NON-NLS-1$ - else - fBrowserLikeLinksKeyModifierStatus= new StatusInfo(IStatus.ERROR, - PreferencesMessages.getString("JavaEditorPreferencePage.navigation.shiftIsDisabled")); - //$NON-NLS-1$ - setValid(false); - StatusUtil.applyToStatusLine(this, fBrowserLikeLinksKeyModifierStatus); - } else { - fBrowserLikeLinksKeyModifierStatus= new StatusInfo(); - updateStatus(fBrowserLikeLinksKeyModifierStatus); - } + String modifiers = fBrowserLikeLinksKeyModifierText.getText(); + int stateMask = computeStateMask(modifiers); + if (fBrowserLikeLinksCheckBox.getSelection() && (stateMask == -1 || (stateMask & SWT.SHIFT) != 0)) { + if (stateMask == -1) + fBrowserLikeLinksKeyModifierStatus = new StatusInfo(IStatus.ERROR, PreferencesMessages.getFormattedString( + "JavaEditorPreferencePage.navigation.modifierIsNotValid", modifiers)); //$NON-NLS-1$ + else + fBrowserLikeLinksKeyModifierStatus = new StatusInfo(IStatus.ERROR, PreferencesMessages + .getString("JavaEditorPreferencePage.navigation.shiftIsDisabled")); + //$NON-NLS-1$ + setValid(false); + StatusUtil.applyToStatusLine(this, fBrowserLikeLinksKeyModifierStatus); + } else { + fBrowserLikeLinksKeyModifierStatus = new StatusInfo(); + updateStatus(fBrowserLikeLinksKeyModifierStatus); + } + } + + private IStatus getBrowserLikeLinksKeyModifierStatus() { + if (fBrowserLikeLinksKeyModifierStatus == null) + fBrowserLikeLinksKeyModifierStatus = new StatusInfo(); + return fBrowserLikeLinksKeyModifierStatus; } - private IStatus getBrowserLikeLinksKeyModifierStatus() { - if (fBrowserLikeLinksKeyModifierStatus == null) - fBrowserLikeLinksKeyModifierStatus= new StatusInfo(); - return fBrowserLikeLinksKeyModifierStatus; - } /** * Computes the state mask for the given modifier string. * @@ -1461,9 +1471,8 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben fBackgroundDefaultRadioButton.setSelection(default_); fBackgroundCustomRadioButton.setSelection(!default_); fBackgroundColorButton.setEnabled(!default_); - boolean closeJavaDocs = fOverlayStore - .getBoolean(PreferenceConstants.EDITOR_CLOSE_JAVADOCS); -// fAddJavaDocTagsButton.setEnabled(closeJavaDocs); + boolean closeJavaDocs = fOverlayStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_JAVADOCS); + // fAddJavaDocTagsButton.setEnabled(closeJavaDocs); fEscapeStringsButtonDQ.setEnabled(fOverlayStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_DQ)); fEscapeStringsButtonSQ.setEnabled(fOverlayStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS_SQ)); // boolean fillMethodArguments= @@ -1513,7 +1522,7 @@ public class JavaEditorPreferencePage extends PreferencePage implements IWorkben // fJavaEditorHoverConfigurationBlock.performOk(); fFoldingConfigurationBlock.performOk(); fOverlayStore.setValue(PreferenceConstants.EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK, - computeStateMask(fBrowserLikeLinksKeyModifierText.getText())); + computeStateMask(fBrowserLikeLinksKeyModifierText.getText())); fOverlayStore.propagate(); PHPeclipsePlugin.getDefault().savePluginPreferences(); return true; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java index de3a112..718a021 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/PreferenceConstants.java @@ -1701,6 +1701,8 @@ public class PreferenceConstants { */ public static final String EDITOR_SMART_TAB = "smart_tab"; //$NON-NLS-1$ + public static final String EDITOR_P_RTRIM_ON_SAVE = "editor_p_trim_on_save"; //$NON-NLS-1$ + /** * A named preference that controls whether Java comments should be spell-checked. *

@@ -2512,7 +2514,7 @@ public class PreferenceConstants { store.setDefault(PreferenceConstants.EDITOR_FOLDING_IMPORTS, false); store.setDefault(PreferenceConstants.EDITOR_SMART_BACKSPACE, true); - + store.setDefault(PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE, false); // do more complicated stuff // NewJavaProjectPreferencePage.initDefaults(store); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index 49f7d5f..9c99864 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -36,6 +36,7 @@ import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.phpeditor.actions.RTrimAction; import net.sourceforge.phpeclipse.ui.editor.ShowExternalPreviewAction; import org.eclipse.core.internal.runtime.ListenerList; @@ -268,7 +269,7 @@ public class PHPUnitEditor extends PHPEditor { //implements private boolean fIgnoreTextConverters = false; -// private JavaCorrectionAssistant fCorrectionAssistant; + // private JavaCorrectionAssistant fCorrectionAssistant; public AdaptedSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IPreferenceStore store) { @@ -292,10 +293,10 @@ public class PHPUnitEditor extends PHPEditor { //implements String msg = fContentAssistant.showPossibleCompletions(); setStatusLineErrorMessage(msg); return; -// case CORRECTIONASSIST_PROPOSALS: -// msg = fCorrectionAssistant.showPossibleCompletions(); -// setStatusLineErrorMessage(msg); -// return; + // case CORRECTIONASSIST_PROPOSALS: + // msg = fCorrectionAssistant.showPossibleCompletions(); + // setStatusLineErrorMessage(msg); + // return; case UNDO: fIgnoreTextConverters = true; super.doOperation(operation); @@ -315,8 +316,8 @@ public class PHPUnitEditor extends PHPEditor { //implements * @see ITextOperationTarget#canDoOperation(int) */ public boolean canDoOperation(int operation) { -// if (operation == CORRECTIONASSIST_PROPOSALS) -// return isEditable(); + // if (operation == CORRECTIONASSIST_PROPOSALS) + // return isEditable(); return super.canDoOperation(operation); } @@ -326,10 +327,10 @@ public class PHPUnitEditor extends PHPEditor { //implements * @since 3.0 */ public void unconfigure() { -// if (fCorrectionAssistant != null) { -// fCorrectionAssistant.uninstall(); -// fCorrectionAssistant = null; -// } + // if (fCorrectionAssistant != null) { + // fCorrectionAssistant.uninstall(); + // fCorrectionAssistant = null; + // } super.unconfigure(); } @@ -399,8 +400,8 @@ public class PHPUnitEditor extends PHPEditor { //implements */ public void configure(SourceViewerConfiguration configuration) { super.configure(configuration); -// fCorrectionAssistant = new JavaCorrectionAssistant(CompilationUnitEditor.this); -// fCorrectionAssistant.install(this); + // fCorrectionAssistant = new JavaCorrectionAssistant(CompilationUnitEditor.this); + // fCorrectionAssistant.install(this); IAutoEditStrategy smartSemi = new SmartSemicolonAutoEditStrategy(IPHPPartitions.PHP_PARTITIONING); prependAutoEditStrategy(smartSemi, IDocument.DEFAULT_CONTENT_TYPE); prependAutoEditStrategy(smartSemi, IPHPPartitions.PHP_STRING_DQ); @@ -1162,17 +1163,14 @@ public class PHPUnitEditor extends PHPEditor { //implements /** The editor's paint manager */ // private PaintManager fPaintManager; /** The editor's bracket painter */ -// private BracketPainter fBracketPainter; - + // private BracketPainter fBracketPainter; /** The editor's bracket matcher */ private PHPPairMatcher fBracketMatcher; /** The editor's line painter */ -// private LinePainter fLinePainter; - + // private LinePainter fLinePainter; /** The editor's print margin ruler painter */ -// private PrintMarginPainter fPrintMarginPainter; - + // private PrintMarginPainter fPrintMarginPainter; /** The editor's problem painter */ // private ProblemPainter fProblemPainter; /** The editor's tab converter */ @@ -1218,26 +1216,19 @@ public class PHPUnitEditor extends PHPEditor { //implements private final static String CODE_FORMATTER_TAB_SIZE = JavaCore.FORMATTER_TAB_SIZE; /** Preference key for matching brackets */ -// private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS; - + // private final static String MATCHING_BRACKETS = PreferenceConstants.EDITOR_MATCHING_BRACKETS; /** Preference key for matching brackets color */ -// private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; - + // private final static String MATCHING_BRACKETS_COLOR = PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; /** Preference key for highlighting current line */ -// private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE; - + // private final static String CURRENT_LINE = PreferenceConstants.EDITOR_CURRENT_LINE; /** Preference key for highlight color of current line */ -// private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR; - + // private final static String CURRENT_LINE_COLOR = PreferenceConstants.EDITOR_CURRENT_LINE_COLOR; /** Preference key for showing print marging ruler */ -// private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN; - + // private final static String PRINT_MARGIN = PreferenceConstants.EDITOR_PRINT_MARGIN; /** Preference key for print margin ruler color */ -// private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; - + // private final static String PRINT_MARGIN_COLOR = PreferenceConstants.EDITOR_PRINT_MARGIN_COLOR; /** Preference key for print margin ruler column */ -// private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; - + // private final static String PRINT_MARGIN_COLUMN = PreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN; /** Preference key for inserting spaces rather than tabs */ private final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS; @@ -1308,8 +1299,7 @@ public class PHPUnitEditor extends PHPEditor { //implements private final static String CLOSE_STRINGS_SQ_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_SQ_PHP; /** Preference key for automatically wrapping Java strings */ -// private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS_DQ; - + // private final static String WRAP_STRINGS = PreferenceConstants.EDITOR_WRAP_STRINGS_DQ; /** Preference key for automatically closing brackets and parenthesis */ private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP; @@ -1320,8 +1310,7 @@ public class PHPUnitEditor extends PHPEditor { //implements private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS; /** Preference key for automatically formatting phpdocs */ -// private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS; - + // private final static String FORMAT_JAVADOCS = PreferenceConstants.EDITOR_FORMAT_JAVADOCS; /** Preference key for automatically closing strings */ private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML; @@ -1518,51 +1507,50 @@ public class PHPUnitEditor extends PHPEditor { //implements // markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$ // markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$ // - - action= new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT); - setAction("AddBlockComment", action); //$NON-NLS-1$ - markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ - markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ -// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); - - action= new RemoveBlockCommentAction(PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); - setAction("RemoveBlockComment", action); //$NON-NLS-1$ - markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ - markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ -// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION); - -// action= new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, false); //$NON-NLS-1$ -// action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT); -// setAction("Indent", action); //$NON-NLS-1$ -// markAsStateDependentAction("Indent", true); //$NON-NLS-1$ -// markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$ -//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION); -// - action= new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, true); //$NON-NLS-1$ - setAction("IndentOnTab", action); //$NON-NLS-1$ - markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$ - markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$ - + + action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT); + setAction("AddBlockComment", action); //$NON-NLS-1$ + markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$ + markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION); + + action = new RemoveBlockCommentAction(PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$ + action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT); + setAction("RemoveBlockComment", action); //$NON-NLS-1$ + markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ + markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION); + + // action= new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, false); //$NON-NLS-1$ + // action.setActionDefinitionId(PHPEditorActionDefinitionIds.INDENT); + // setAction("Indent", action); //$NON-NLS-1$ + // markAsStateDependentAction("Indent", true); //$NON-NLS-1$ + // markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$ + //// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION); + // + action = new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, true); //$NON-NLS-1$ + setAction("IndentOnTab", action); //$NON-NLS-1$ + markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$ + markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$ + if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_TAB)) { // don't replace Shift Right - have to make sure their enablement is // mutually exclusive // removeActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT); setActionActivationCode("IndentOnTab", '\t', -1, SWT.NONE); //$NON-NLS-1$ } - fGenerateActionGroup= new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); -// ActionGroup rg= new RefactorActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); - -// fActionGroups.addGroup(rg); - fActionGroups.addGroup(fGenerateActionGroup); - - // We have to keep the context menu group separate to have better control over positioning - fContextMenuGroup= new CompositeActionGroup(new ActionGroup[] { - fGenerateActionGroup -// rg, -// new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT) - }); + fGenerateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + // ActionGroup rg= new RefactorActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + + // fActionGroups.addGroup(rg); + fActionGroups.addGroup(fGenerateActionGroup); + + // We have to keep the context menu group separate to have better control over positioning + fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup + // rg, + // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT) + }); } @@ -1623,12 +1611,12 @@ public class PHPUnitEditor extends PHPEditor { //implements linePainter = new LinePainter(getSourceViewer()); linePainter.setHighlightColor(new Color(Display.getCurrent(), 225, 235, 224)); // fPaintManager.addPainter(linePainter); -// if (isBracketHighlightingEnabled()) -// startBracketHighlighting(); -// if (isLineHighlightingEnabled()) -// startLineHighlighting(); -// if (isPrintMarginVisible()) -// showPrintMargin(); + // if (isBracketHighlightingEnabled()) + // startBracketHighlighting(); + // if (isLineHighlightingEnabled()) + // startLineHighlighting(); + // if (isPrintMarginVisible()) + // showPrintMargin(); // Iterator e = ANNOTATION_MAP.keySet().iterator(); // while (e.hasNext()) { // AnnotationType type = (AnnotationType) e.next(); @@ -1678,75 +1666,74 @@ public class PHPUnitEditor extends PHPEditor { //implements } } -// private void startBracketHighlighting() { -// if (fBracketPainter == null) { -// ISourceViewer sourceViewer = getSourceViewer(); -// fBracketPainter = new BracketPainter(sourceViewer); -// fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); -// // fPaintManager.addPainter(fBracketPainter); -// } -// } -// -// private void stopBracketHighlighting() { -// if (fBracketPainter != null) { -// // fPaintManager.removePainter(fBracketPainter); -// fBracketPainter.deactivate(true); -// fBracketPainter.dispose(); -// fBracketPainter = null; -// } -// } - -// private boolean isBracketHighlightingEnabled() { -// IPreferenceStore store = getPreferenceStore(); -// return store.getBoolean(MATCHING_BRACKETS); -// } - -// private void startLineHighlighting() { -// if (fLinePainter == null) { -// ISourceViewer sourceViewer = getSourceViewer(); -// fLinePainter = new LinePainter(sourceViewer); -// fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR)); -// // fPaintManager.addPainter(fLinePainter); -// } -// } - -// private void stopLineHighlighting() { -// if (fLinePainter != null) { -// // fPaintManager.removePainter(fLinePainter); -// fLinePainter.deactivate(true); -// fLinePainter.dispose(); -// fLinePainter = null; -// } -// } - -// private boolean isLineHighlightingEnabled() { -// IPreferenceStore store = getPreferenceStore(); -// return store.getBoolean(CURRENT_LINE); -// } - -// private void showPrintMargin() { -// if (fPrintMarginPainter == null) { -// fPrintMarginPainter = new PrintMarginPainter(getSourceViewer()); -// fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); -// fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); -// // fPaintManager.addPainter(fPrintMarginPainter); -// } -// } - -// private void hidePrintMargin() { -// if (fPrintMarginPainter != null) { -// // fPaintManager.removePainter(fPrintMarginPainter); -// fPrintMarginPainter.deactivate(true); -// fPrintMarginPainter.dispose(); -// fPrintMarginPainter = null; -// } -// } - -// private boolean isPrintMarginVisible() { -// IPreferenceStore store = getPreferenceStore(); -// return store.getBoolean(PRINT_MARGIN); -// } + // private void startBracketHighlighting() { + // if (fBracketPainter == null) { + // ISourceViewer sourceViewer = getSourceViewer(); + // fBracketPainter = new BracketPainter(sourceViewer); + // fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); + // // fPaintManager.addPainter(fBracketPainter); + // } + // } + // + // private void stopBracketHighlighting() { + // if (fBracketPainter != null) { + // // fPaintManager.removePainter(fBracketPainter); + // fBracketPainter.deactivate(true); + // fBracketPainter.dispose(); + // fBracketPainter = null; + // } + // } + + // private boolean isBracketHighlightingEnabled() { + // IPreferenceStore store = getPreferenceStore(); + // return store.getBoolean(MATCHING_BRACKETS); + // } + + // private void startLineHighlighting() { + // if (fLinePainter == null) { + // ISourceViewer sourceViewer = getSourceViewer(); + // fLinePainter = new LinePainter(sourceViewer); + // fLinePainter.setHighlightColor(getColor(CURRENT_LINE_COLOR)); + // // fPaintManager.addPainter(fLinePainter); + // } + // } + + // private void stopLineHighlighting() { + // if (fLinePainter != null) { + // // fPaintManager.removePainter(fLinePainter); + // fLinePainter.deactivate(true); + // fLinePainter.dispose(); + // fLinePainter = null; + // } + // } + + // private boolean isLineHighlightingEnabled() { + // IPreferenceStore store = getPreferenceStore(); + // return store.getBoolean(CURRENT_LINE); + // } + + // private void showPrintMargin() { + // if (fPrintMarginPainter == null) { + // fPrintMarginPainter = new PrintMarginPainter(getSourceViewer()); + // fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); + // fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); + // // fPaintManager.addPainter(fPrintMarginPainter); + // } + // } + + // private void hidePrintMargin() { + // if (fPrintMarginPainter != null) { + // // fPaintManager.removePainter(fPrintMarginPainter); + // fPrintMarginPainter.deactivate(true); + // fPrintMarginPainter.dispose(); + // fPrintMarginPainter = null; + // } + // } + // private boolean isPrintMarginVisible() { + // IPreferenceStore store = getPreferenceStore(); + // return store.getBoolean(PRINT_MARGIN); + // } private int getTabSize() { Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); @@ -1851,49 +1838,49 @@ public class PHPUnitEditor extends PHPEditor { //implements stopTabConversion(); return; } -// if (MATCHING_BRACKETS.equals(p)) { -// if (isBracketHighlightingEnabled()) -// startBracketHighlighting(); -// else -// stopBracketHighlighting(); -// return; -// } -// if (MATCHING_BRACKETS_COLOR.equals(p)) { -// if (fBracketPainter != null) -// fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); -// return; -// } -// if (CURRENT_LINE.equals(p)) { -// if (isLineHighlightingEnabled()) -// startLineHighlighting(); -// else -// stopLineHighlighting(); -// return; -// } -// if (CURRENT_LINE_COLOR.equals(p)) { -// if (fLinePainter != null) { -// stopLineHighlighting(); -// startLineHighlighting(); -// } -// return; -// } -// if (PRINT_MARGIN.equals(p)) { -// if (isPrintMarginVisible()) -// showPrintMargin(); -// else -// hidePrintMargin(); -// return; -// } -// if (PRINT_MARGIN_COLOR.equals(p)) { -// if (fPrintMarginPainter != null) -// fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); -// return; -// } -// if (PRINT_MARGIN_COLUMN.equals(p)) { -// if (fPrintMarginPainter != null) -// fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); -// return; -// } + // if (MATCHING_BRACKETS.equals(p)) { + // if (isBracketHighlightingEnabled()) + // startBracketHighlighting(); + // else + // stopBracketHighlighting(); + // return; + // } + // if (MATCHING_BRACKETS_COLOR.equals(p)) { + // if (fBracketPainter != null) + // fBracketPainter.setHighlightColor(getColor(MATCHING_BRACKETS_COLOR)); + // return; + // } + // if (CURRENT_LINE.equals(p)) { + // if (isLineHighlightingEnabled()) + // startLineHighlighting(); + // else + // stopLineHighlighting(); + // return; + // } + // if (CURRENT_LINE_COLOR.equals(p)) { + // if (fLinePainter != null) { + // stopLineHighlighting(); + // startLineHighlighting(); + // } + // return; + // } + // if (PRINT_MARGIN.equals(p)) { + // if (isPrintMarginVisible()) + // showPrintMargin(); + // else + // hidePrintMargin(); + // return; + // } + // if (PRINT_MARGIN_COLOR.equals(p)) { + // if (fPrintMarginPainter != null) + // fPrintMarginPainter.setMarginRulerColor(getColor(PRINT_MARGIN_COLOR)); + // return; + // } + // if (PRINT_MARGIN_COLUMN.equals(p)) { + // if (fPrintMarginPainter != null) + // fPrintMarginPainter.setMarginRulerColumn(getPreferenceStore().getInt(PRINT_MARGIN_COLUMN)); + // return; + // } // if (OVERVIEW_RULER.equals(p)) { // if (isOverviewRulerVisible()) // showOverviewRuler(); @@ -2085,6 +2072,11 @@ public class PHPUnitEditor extends PHPEditor { //implements } } else { + if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE)) { + RTrimAction trimAction = new RTrimAction(); + trimAction.setActiveEditor(null, getSite().getPage().getActiveEditor()); + trimAction.run(null); + } setStatusLineErrorMessage(null); @@ -2246,15 +2238,16 @@ public class PHPUnitEditor extends PHPEditor { //implements // } // } // } - private void configureTabConverter() { - if (fTabConverter != null) { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof ICompilationUnitDocumentProvider) { - ICompilationUnitDocumentProvider cup= (ICompilationUnitDocumentProvider) provider; - fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); - } - } - } + private void configureTabConverter() { + if (fTabConverter != null) { + IDocumentProvider provider = getDocumentProvider(); + if (provider instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cup = (ICompilationUnitDocumentProvider) provider; + fTabConverter.setLineTracker(cup.createLineTracker(getEditorInput())); + } + } + } + private void startTabConversion() { if (fTabConverter == null) { fTabConverter = new TabConverter(); @@ -2281,33 +2274,33 @@ public class PHPUnitEditor extends PHPEditor { //implements * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, org.eclipse.core.runtime.IProgressMonitor) */ protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) { -// IDocumentProvider p = getDocumentProvider(); -// if (p instanceof PHPDocumentProvider) { -// PHPDocumentProvider cp = (PHPDocumentProvider) p; -// cp.setSavePolicy(fSavePolicy); -// } -// try { -// super.performSave(overwrite, progressMonitor); -// } finally { -// if (p instanceof PHPDocumentProvider) { -// PHPDocumentProvider cp = (PHPDocumentProvider) p; -// cp.setSavePolicy(null); -// } -// } - - IDocumentProvider p= getDocumentProvider(); - if (p instanceof ICompilationUnitDocumentProvider) { - ICompilationUnitDocumentProvider cp= (ICompilationUnitDocumentProvider) p; - cp.setSavePolicy(fSavePolicy); - } - try { - super.performSave(overwrite, progressMonitor); - } finally { - if (p instanceof ICompilationUnitDocumentProvider) { - ICompilationUnitDocumentProvider cp= (ICompilationUnitDocumentProvider) p; - cp.setSavePolicy(null); - } - } + // IDocumentProvider p = getDocumentProvider(); + // if (p instanceof PHPDocumentProvider) { + // PHPDocumentProvider cp = (PHPDocumentProvider) p; + // cp.setSavePolicy(fSavePolicy); + // } + // try { + // super.performSave(overwrite, progressMonitor); + // } finally { + // if (p instanceof PHPDocumentProvider) { + // PHPDocumentProvider cp = (PHPDocumentProvider) p; + // cp.setSavePolicy(null); + // } + // } + + IDocumentProvider p = getDocumentProvider(); + if (p instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cp = (ICompilationUnitDocumentProvider) p; + cp.setSavePolicy(fSavePolicy); + } + try { + super.performSave(overwrite, progressMonitor); + } finally { + if (p instanceof ICompilationUnitDocumentProvider) { + ICompilationUnitDocumentProvider cp = (ICompilationUnitDocumentProvider) p; + cp.setSavePolicy(null); + } + } } /* @@ -2363,7 +2356,8 @@ public class PHPUnitEditor extends PHPEditor { //implements } /* - * @see net.sourceforge.phpdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit, boolean, IProgressMonitor) + * @see net.sourceforge.phpdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(CompilationUnit, boolean, + * IProgressMonitor) * @since 3.0 */ public void reconciled(CompilationUnit ast, boolean forced, IProgressMonitor progressMonitor) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/actions/RTrimAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/actions/RTrimAction.java new file mode 100644 index 0000000..154b992 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/actions/RTrimAction.java @@ -0,0 +1,114 @@ +/* + * Created on Oct 15, 2004 + * + * The MIT License + * Copyright (c) 2004 Stephen Milligan + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software + * is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.sourceforge.phpeclipse.phpeditor.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorActionDelegate; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * @author Stephen Milligan + */ +public class RTrimAction implements IEditorActionDelegate { + + ITextEditor editor = null; + + /** + * + */ + public RTrimAction() { + super(); + } + + public void setActiveEditor(IAction action, IEditorPart targetEditor) { + + if (targetEditor instanceof ITextEditor) { + editor = (ITextEditor) targetEditor; + } + } + + /** + * this gets called for every action + */ + public void run(IAction action) { + IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); + ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection(); + + int currentLine = 0; + int originalCursorOffset = sel.getOffset(); + int cursorOffset = originalCursorOffset; + int originalSelectionLength = sel.getLength(); + int selectionLength = originalSelectionLength; + String oldText; + int lineEnd; + + try { + + while (currentLine < doc.getNumberOfLines()) { + int offset = doc.getLineOffset(currentLine); + int length = doc.getLineLength(currentLine); + oldText = doc.get(offset, length); + + //-- Starts at the end of the line, looking for the first non-first 'white space' + //-- it then breaks out. No point in carrying on, as we have found our true line end + for (lineEnd=oldText.length(); lineEnd > 0; --lineEnd ){ + if ( oldText.charAt(lineEnd-1) != '\t' && oldText.charAt(lineEnd-1) != ' ' ){ + break; + } + } + + //-- Only replace the line if the lengths are different + if ( lineEnd != oldText.length() ) { + String newText = oldText.substring(0, lineEnd); + doc.replace(offset, length, newText); + + if (offset + length <= cursorOffset) { + if (oldText.length() != newText.length()) { + cursorOffset -= oldText.length() - newText.length(); + } + } else if (offset <= cursorOffset + selectionLength && selectionLength > 0) { + selectionLength -= oldText.length() - newText.length(); + } else if (offset + length == cursorOffset + 2) { // Check if the cursor is at the end of the line. + cursorOffset -= 2; + } + } + currentLine++; + } + + TextSelection selection = new TextSelection(doc, cursorOffset, selectionLength); + editor.getSelectionProvider().setSelection(selection); + } catch (Exception blx) { + blx.printStackTrace(); + } + } + + public void selectionChanged(IAction action, ISelection selection) { + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java index fb18a6a..54fe5a6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java @@ -842,11 +842,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { } // if (ExternalInterface.isBookmarkConnected(bookmarkString)) { try { - // Connection connection = bookmark.getConnection(); - // DatabaseMetaData metaData = connection.getMetaData(); - - // if (metaData != null) { - int start = context.getStart(); + int start = context.getStart(); int end = context.getEnd(); String foundSQLTableName = sqlTable.getTableName(); String tableName; @@ -864,55 +860,19 @@ public class PHPCompletionProcessor implements IContentAssistProcessor { for (int i = 0; i < tableNames.length; i++) { sqlList.add(new SQLProposal(tableNames[i], context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE))); } - - // set = metaData.getTables(null, null, prefixWithoutDollar + "%", null); - // while (set.next()) { - // tableName = set.getString("TABLE_NAME"); - // tableName = (tableName == null) ? "" : tableName.trim(); - // if (tableName != null && tableName.length() > 0) { - // sqlList.add(new SQLProposal(tableName, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE))); - // } - // } - // set.close(); } String[] columnNames = ExternalInterface.getMatchingColumnNames(null, bookmarkString, prefixWithoutDollar, null, false); for (int i = 0; i < columnNames.length; i++) { sqlList.add(new SQLProposal(columnNames[i], context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE))); } - // set = metaData.getColumns(null, null, "%", prefixWithoutDollar + "%"); - // SQLProposal sqlProposal; - // while (set.next()) { - // columnName = set.getString("COLUMN_NAME"); - // columnName = (columnName == null) ? "" : columnName.trim(); - // tableName = set.getString("TABLE_NAME"); - // tableName = (tableName == null) ? "" : tableName.trim(); - // if (tableName != null && tableName.length() > 0 && columnName != null && columnName.length() > 0) { - // if (isDollarPrefix) { - // sqlProposal = new SQLProposal(tableName, "$" + columnName, context, region, viewer, PHPUiImages - // .get(PHPUiImages.IMG_COLUMN)); - // } else { - // sqlProposal = new SQLProposal(tableName, columnName, context, region, viewer, PHPUiImages - // .get(PHPUiImages.IMG_COLUMN)); - // } - // if (tableName.equals(foundSQLTableName)) { - // sqlProposal.setRelevance(90); - // } else if (tableName.indexOf(foundSQLTableName) >= 0) { - // sqlProposal.setRelevance(75); - // } - // sqlList.add(sqlProposal); - // } - // } - // set.close(); + sqlResults = new IPHPCompletionProposal[sqlList.size()]; for (int i = 0; i < sqlList.size(); i++) { sqlResults[i] = (SQLProposal) sqlList.get(i); } - // } } catch (Exception /* NotConnectedException */ e) { - // ignore this - not mission critical - // } catch (SQLException e) { - // e.printStackTrace(); + } // } } -- 1.7.1