X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/IndentAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/IndentAction.java index 44cfdb5..cf03914 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/IndentAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/actions/IndentAction.java @@ -26,7 +26,9 @@ import net.sourceforge.phpeclipse.phpeditor.PHPEditor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.text.Assert; +//incastrix +//import org.eclipse.jface.text.Assert; +import org.eclipse.core.runtime.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.IDocument; @@ -86,9 +88,12 @@ public class IndentAction extends TextEditorAction { * @param isTabAction * whether the action should insert tabs if over the indentation */ - public IndentAction(ResourceBundle bundle, String prefix, - ITextEditor editor, boolean isTabAction) { - super(bundle, prefix, editor); + public IndentAction (ResourceBundle bundle, + String prefix, + ITextEditor editor, + boolean isTabAction) { + super (bundle, prefix, editor); + fIsTabAction = isTabAction; } @@ -277,39 +282,40 @@ public class IndentAction extends TextEditorAction { to++; indent = command.text.substring(1, to); - } else if (!fIsTabAction && partition.getOffset() == offset - && type.equals(IPHPPartitions.PHP_SINGLELINE_COMMENT)) { - - // line comment starting at position 0 -> indent inside - int slashes = 2; - while (slashes < document.getLength() - 1 - && document.get(offset + slashes, 2).equals("//")) //$NON-NLS-1$ - slashes += 2; - - wsStart = offset + slashes; - - StringBuffer computed = indenter.computeIndentation(offset); - int tabSize = PHPeclipsePlugin - .getDefault() - .getPreferenceStore() - .getInt( - AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH); - while (slashes > 0 && computed.length() > 0) { - char c = computed.charAt(0); - if (c == '\t') - if (slashes > tabSize) - slashes -= tabSize; - else - break; - else if (c == ' ') - slashes--; - else - break; - - computed.deleteCharAt(0); - } - - indent = document.get(offset, wsStart - offset) + computed; +// omit Java style +// } else if (!fIsTabAction && partition.getOffset() == offset +// && type.equals(IPHPPartitions.PHP_SINGLELINE_COMMENT)) { +// +// // line comment starting at position 0 -> indent inside +// int slashes = 2; +// while (slashes < document.getLength() - 1 +// && document.get(offset + slashes, 2).equals("//")) //$NON-NLS-1$ +// slashes += 2; +// +// wsStart = offset + slashes; +// +// StringBuffer computed = indenter.computeIndentation(offset); +// int tabSize = PHPeclipsePlugin +// .getDefault() +// .getPreferenceStore() +// .getInt( +// AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH); +// while (slashes > 0 && computed.length() > 0) { +// char c = computed.charAt(0); +// if (c == '\t') +// if (slashes > tabSize) +// slashes -= tabSize; +// else +// break; +// else if (c == ' ') +// slashes--; +// else +// break; +// +// computed.deleteCharAt(0); +// } +// +// indent = document.get(offset, wsStart - offset) + computed; } } @@ -320,7 +326,8 @@ public class IndentAction extends TextEditorAction { if (computed != null) indent = computed.toString(); else - indent = new String(); + //indent = new String(); + return true; // prevent affecting html part } // change document: @@ -403,10 +410,7 @@ public class IndentAction extends TextEditorAction { else { int size = 0; int l = indent.length(); - int tabSize = PHPeclipsePlugin - .getDefault() - .getPreferenceStore() - .getInt( + int tabSize = PHPeclipsePlugin.getDefault().getPreferenceStore().getInt( AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH); for (int i = 0; i < l; i++) @@ -475,15 +479,19 @@ public class IndentAction extends TextEditorAction { */ private boolean isValidSelection() { ITextSelection selection = getSelection(); - if (selection.isEmpty()) + + if (selection.isEmpty()) { return false; + } int offset = selection.getOffset(); int length = selection.getLength(); IDocument document = getDocument(); - if (document == null) + + if (document == null) { return false; + } try { IRegion firstLine = document.getLineInformationOfOffset(offset); @@ -492,12 +500,17 @@ public class IndentAction extends TextEditorAction { // either the selection has to be empty and the caret in the WS at // the line start // or the selection has to extend over multiple lines - if (length == 0) - return document.get(lineOffset, offset - lineOffset).trim() - .length() == 0; - else + if (length == 0) { + boolean bRet; + + bRet = document.get (lineOffset, offset - lineOffset).trim().length() == 0; + + return bRet; + } + else { // return lineOffset + firstLine.getLength() < offset + length; return false; // only enable for empty selections for now + } } catch (BadLocationException e) { } @@ -526,17 +539,16 @@ public class IndentAction extends TextEditorAction { * * @return the current document or null */ - private IDocument getDocument() { - - ITextEditor editor = getTextEditor(); + private IDocument getDocument() { ITextEditor editor = getTextEditor(); if (editor != null) { - IDocumentProvider provider = editor.getDocumentProvider(); IEditorInput input = editor.getEditorInput(); - if (provider != null && input != null) + + if (provider != null && input != null) { return provider.getDocument(input); - + } } + return null; }