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;
* @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;
}
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;
}
}
if (computed != null)
indent = computed.toString();
else
- indent = new String();
+ //indent = new String();
+ return true; // prevent affecting html part
}
// change document:
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++)
*/
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);
// 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) {
}
*
* @return the current document or <code>null</code>
*/
- 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;
}