import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.core.dom.CompilationUnit;
import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
import net.sourceforge.phpdt.internal.ui.actions.AddBlockCommentAction;
import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
import net.sourceforge.phpdt.internal.ui.actions.IndentAction;
private boolean fCloseStringsPHPSQ = true;
- private boolean fCloseBracketsHTML = true;
-
- private boolean fCloseStringsHTML = true;
-
private int fOffset;
private int fLength;
fCloseStringsPHPSQ = enabled;
}
- public void setCloseBracketsHTMLEnabled(boolean enabled) {
- fCloseBracketsHTML = enabled;
- }
-
- public void setCloseStringsHTMLEnabled(boolean enabled) {
- fCloseStringsHTML = enabled;
- }
-
private boolean hasIdentifierToTheRight(IDocument document, int offset) {
try {
int end = offset;
}
}
+ private boolean hasCharacterToTheLeft(IDocument document, int offset, char character) {
+ try {
+ int start = offset;
+ IRegion startLine = document.getLineInformationOfOffset(start);
+ int minStart = startLine.getOffset();
+ while (start != minStart && Character.isWhitespace(document.getChar(start - 1)))
+ --start;
+ return start != minStart && document.getChar(start - 1)== character;
+ } catch (BadLocationException e) {
+ return false;
+ }
+ }
+
private boolean hasCharacterToTheRight(IDocument document, int offset, char character) {
try {
int end = offset;
sourceViewer.setSelectedRange(newSelectionDQ.getOffset(), newSelectionDQ.getLength());
event.doit = false;
break;
- // fall through
case '\'':
if (event.character == '\'') {
if (!fCloseStringsPHPSQ)
IRegion newSelectionSQ = editorSQ.getSelectedRegion();
sourceViewer.setSelectedRange(newSelectionSQ.getOffset(), newSelectionSQ.getLength());
event.doit = false;
+ case '\r': { // insert linebreaks and new closing brace after brace and return
+ if (!fCloseBracketsPHP) {
+ return;
+ }
+ if (hasCharacterToTheLeft(document,offset,'{')) {
+ String lineDelimiter=StubUtility.getLineDelimiterFor(document);
+ int caretPos=sourceViewer.getTextWidget().getCaretOffset();
+ final StringBuffer buffer = new StringBuffer(lineDelimiter);
+ // get indentation
+ IRegion line = document.getLineInformationOfOffset(offset);
+ String currentLine=document.get(line.getOffset(),line.getLength());
+ int index=0;
+ int max=currentLine.length();
+ StringBuffer indent=new StringBuffer();
+ while (index<max && Character.isWhitespace(currentLine.charAt(index))) {
+ indent.append(currentLine.charAt(index));
+ index++;
+ }
+ buffer.append(indent);
+ buffer.append("\t");
+ int cursorPos=buffer.length();
+ buffer.append(lineDelimiter);
+ buffer.append(indent);
+ buffer.append("}");
+ document.replace(offset, length, buffer.toString());
+ sourceViewer.getTextWidget().setCaretOffset(caretPos+cursorPos);
+ event.doit = false;
+ }
+ }
}
}
- // } else if (type.equals(IPHPPartitions.HTML)) {
- // switch (event.character) {
- // case '(':
- // if (hasCharacterToTheRight(document, offset + length, '('))
- // return;
- // // fall through
- // case '[':
- // if (!fCloseBracketsHTML)
- // return;
- // if (hasIdentifierToTheRight(document, offset + length))
- // return;
- // // fall through
- // case '"':
- // if (event.character == '"') {
- // if (!fCloseStringsHTML)
- // return;
- // if (hasIdentifierToTheLeft(document, offset)
- // || hasIdentifierToTheRight(document, offset + length))
- // return;
- // }
- // // ITypedRegion partition=
- // // document.getPartition(offset);
- // // if (!
- // // IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
- // // &&
- // // (partition.getOffset() != offset))
- // // return;
- // final char character = event.character;
- // final char closingCharacter = getPeerCharacter(character);
- // final StringBuffer buffer = new StringBuffer();
- // buffer.append(character);
- // buffer.append(closingCharacter);
- // document.replace(offset, length, buffer.toString());
- // LinkedPositionManager manager = new LinkedPositionManager(document);
- // manager.addPosition(offset + 1, 0);
- // fOffset = offset;
- // fLength = 2;
- // LinkedPositionUI editor = new LinkedPositionUI(sourceViewer,
- // manager);
- // editor.setCancelListener(this);
- // editor.setExitPolicy(new ExitPolicy(closingCharacter));
- // editor.setFinalCaretOffset(offset + 2);
- // editor.enter();
- // IRegion newSelection = editor.getSelectedRegion();
- // sourceViewer.setSelectedRange(newSelection.getOffset(),
- // newSelection.getLength());
- // event.doit = false;
- // }
- // }
} catch (BadLocationException e) {
}
}
// markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
// WorkbenchHelp.setHelp(action,
// IJavaHelpContextIds.ADD_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, 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$
boolean closeBracketsPHP = preferenceStore.getBoolean(CLOSE_BRACKETS_PHP);
boolean closeStringsPHPDQ = preferenceStore.getBoolean(CLOSE_STRINGS_DQ_PHP);
boolean closeStringsPHPSQ = preferenceStore.getBoolean(CLOSE_STRINGS_SQ_PHP);
- boolean closeBracketsHTML = preferenceStore.getBoolean(CLOSE_BRACKETS_HTML);
- boolean closeStringsHTML = preferenceStore.getBoolean(CLOSE_STRINGS_HTML);
fBracketInserter.setCloseBracketsPHPEnabled(closeBracketsPHP);
fBracketInserter.setCloseStringsPHPDQEnabled(closeStringsPHPDQ);
fBracketInserter.setCloseStringsPHPSQEnabled(closeStringsPHPSQ);
- fBracketInserter.setCloseBracketsHTMLEnabled(closeBracketsHTML);
- fBracketInserter.setCloseStringsHTMLEnabled(closeStringsHTML);
ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer instanceof ITextViewerExtension)
((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter);
return character;
case '\'':
return character;
+ case '{':
+ return '}';
default:
throw new IllegalArgumentException();
}
fBracketInserter.setCloseStringsPHPSQEnabled(getPreferenceStore().getBoolean(p));
return;
}
- if (CLOSE_BRACKETS_HTML.equals(p)) {
- fBracketInserter.setCloseBracketsHTMLEnabled(getPreferenceStore().getBoolean(p));
- return;
- }
- if (CLOSE_STRINGS_HTML.equals(p)) {
- fBracketInserter.setCloseStringsHTMLEnabled(getPreferenceStore().getBoolean(p));
- return;
- }
if (SPACES_FOR_TABS.equals(p)) {
if (isTabConversionEnabled())
startTabConversion();