--- java/editor/src/org/netbeans/modules/editor/java/BracketCompletion.java +++ java/editor/src/org/netbeans/modules/editor/java/BracketCompletion.java @@ -690,8 +690,13 @@ * Returns true if bracket completion is enabled in options. */ private static boolean completionSettingEnabled() { - return ((Boolean)Settings.getValue(JavaKit.class, JavaSettingsNames.PAIR_CHARACTERS_COMPLETION)).booleanValue(); + Object result = Settings.getValue(JavaKit.class, JavaSettingsNames.PAIR_CHARACTERS_COMPLETION); + if (result == null) { + return false; + } else { + return ((Boolean) result).booleanValue(); } + } /** * Returns for an opening bracket or quote the appropriate closing --- java/editor/src/org/netbeans/modules/editor/java/JavaKit.java +++ java/editor/src/org/netbeans/modules/editor/java/JavaKit.java @@ -44,6 +44,7 @@ import org.netbeans.modules.editor.MainMenuAction; import org.netbeans.modules.editor.NbEditorKit; import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction; import org.netbeans.modules.java.editor.codegen.GenerateCodeAction; import org.netbeans.modules.java.editor.imports.FastImportAction; import org.netbeans.modules.java.editor.imports.JavaFixAllImports; @@ -229,6 +230,8 @@ new InstantRenameAction(), new JavaFixImports(), new GenerateCodeAction(), + new InsertSemicolonAction(true), + new InsertSemicolonAction(false), new SelectCodeElementAction(selectNextElementAction, true), new SelectCodeElementAction(selectPreviousElementAction, false), --- java/editor/src/org/netbeans/modules/java/editor/codegen/InsertSemicolonAction.java +++ java/editor/src/org/netbeans/modules/java/editor/codegen/InsertSemicolonAction.java @@ -0,0 +1,89 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ +package org.netbeans.modules.java.editor.codegen; + +import java.awt.event.ActionEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import javax.swing.text.JTextComponent; +import org.netbeans.editor.BaseAction; +import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.BaseKit; +import org.netbeans.editor.Formatter; +import org.netbeans.editor.Utilities; +import org.openide.util.Exceptions; + +/** + * Action which inserts an appropriate character at line-end without moving + * the caret. + * + * @author Tim Boudreau + */ +public final class InsertSemicolonAction extends BaseAction { + private final boolean withNewline; + private final char what; + + protected InsertSemicolonAction (String name, char what, boolean withNewline) { + super(name); + this.withNewline = withNewline; + this.what = what; + } + + public InsertSemicolonAction(String name, boolean withNewline) { + this (name, ';', withNewline); + } + + public InsertSemicolonAction(boolean withNewLine) { + this (withNewLine ? "complete-line-newline" : "complete-line", ';', + withNewLine); + } + + @Override + public void actionPerformed(ActionEvent evt, final JTextComponent target) { + if (!target.isEditable() || !target.isEnabled()) { + target.getToolkit().beep(); + return; + } + final BaseDocument doc = (BaseDocument) target.getDocument(); + final class R implements Runnable { + public void run() { + Caret caret = target.getCaret(); + int dotpos = caret.getDot(); + Formatter formatter = doc.getFormatter(); + formatter.indentLock(); + try { + int eoloffset = Utilities.getRowEnd(target, dotpos); + doc.insertString(eoloffset, "" + what, null); + if (withNewline) { + //This is code from the editor module, but it is + //a pretty strange way to do this: + doc.insertString(dotpos, "-", null); //NOI18N + doc.remove(dotpos, 1); + int eolDot = Utilities.getRowEnd(target, caret.getDot()); + int newDotPos = formatter.indentNewLine(doc, eolDot); + caret.setDot(newDotPos); + } + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } finally { + formatter.indentUnlock(); + } + } + }; + doc.runAtomicAsUser(new R()); + } +} --- java/editor/src/org/netbeans/modules/java/editor/resources/DefaultAbbrevs.xml +++ java/editor/src/org/netbeans/modules/java/editor/resources/DefaultAbbrevs.xml @@ -69,7 +69,19 @@ + + + + + + + + + + + + + --- java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml +++ java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml @@ -42,4 +42,6 @@ + +