This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 101133
Collapse All | Expand All

(-)java/editor/src/org/netbeans/modules/editor/java/BracketCompletion.java (-1 / +6 lines)
Lines 690-697 Link Here
690
   * Returns true if bracket completion is enabled in options.
690
   * Returns true if bracket completion is enabled in options.
691
   */
691
   */
692
  private static boolean completionSettingEnabled() {
692
  private static boolean completionSettingEnabled() {
693
    return ((Boolean)Settings.getValue(JavaKit.class, JavaSettingsNames.PAIR_CHARACTERS_COMPLETION)).booleanValue();
693
      Object result = Settings.getValue(JavaKit.class, JavaSettingsNames.PAIR_CHARACTERS_COMPLETION);
694
      if (result == null) {
695
          return false;
696
      } else {
697
          return ((Boolean) result).booleanValue();
694
  }
698
  }
699
  }
695
700
696
  /**
701
  /**
697
   * Returns for an opening bracket or quote the appropriate closing
702
   * Returns for an opening bracket or quote the appropriate closing
(-)java/editor/src/org/netbeans/modules/editor/java/JavaKit.java (+3 lines)
Lines 44-49 Link Here
44
import org.netbeans.modules.editor.MainMenuAction;
44
import org.netbeans.modules.editor.MainMenuAction;
45
import org.netbeans.modules.editor.NbEditorKit;
45
import org.netbeans.modules.editor.NbEditorKit;
46
import org.netbeans.modules.editor.NbEditorUtilities;
46
import org.netbeans.modules.editor.NbEditorUtilities;
47
import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction;
47
import org.netbeans.modules.java.editor.codegen.GenerateCodeAction;
48
import org.netbeans.modules.java.editor.codegen.GenerateCodeAction;
48
import org.netbeans.modules.java.editor.imports.FastImportAction;
49
import org.netbeans.modules.java.editor.imports.FastImportAction;
49
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
50
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
Lines 229-234 Link Here
229
				   new InstantRenameAction(),
230
				   new InstantRenameAction(),
230
                                   new JavaFixImports(),
231
                                   new JavaFixImports(),
231
                                   new GenerateCodeAction(),
232
                                   new GenerateCodeAction(),
233
                                   new InsertSemicolonAction(true),
234
                                   new InsertSemicolonAction(false),
232
                                   new SelectCodeElementAction(selectNextElementAction, true),
235
                                   new SelectCodeElementAction(selectNextElementAction, true),
233
                                   new SelectCodeElementAction(selectPreviousElementAction, false),
236
                                   new SelectCodeElementAction(selectPreviousElementAction, false),
234
                                   
237
                                   
(-)java/editor/src/org/netbeans/modules/java/editor/codegen/InsertSemicolonAction.java (+89 lines)
Line 0 Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
16
 */
17
package org.netbeans.modules.java.editor.codegen;
18
19
import java.awt.event.ActionEvent;
20
import javax.swing.text.BadLocationException;
21
import javax.swing.text.Caret;
22
import javax.swing.text.JTextComponent;
23
import org.netbeans.editor.BaseAction;
24
import org.netbeans.editor.BaseDocument;
25
import org.netbeans.editor.BaseKit;
26
import org.netbeans.editor.Formatter;
27
import org.netbeans.editor.Utilities;
28
import org.openide.util.Exceptions;
29
30
/**
31
 * Action which inserts an appropriate character at line-end without moving
32
 * the caret.
33
 *
34
 * @author Tim Boudreau
35
 */
36
public final class InsertSemicolonAction extends BaseAction {
37
    private final boolean withNewline;
38
    private final char what;
39
    
40
    protected InsertSemicolonAction (String name, char what, boolean withNewline) {
41
        super(name);
42
        this.withNewline = withNewline;
43
        this.what = what;
44
    }
45
46
    public InsertSemicolonAction(String name, boolean withNewline) {
47
        this (name, ';', withNewline);
48
    }
49
    
50
    public InsertSemicolonAction(boolean withNewLine) {
51
        this (withNewLine ? "complete-line-newline" : "complete-line", ';', 
52
                withNewLine);
53
    }
54
55
    @Override
56
    public void actionPerformed(ActionEvent evt, final JTextComponent target) {
57
        if (!target.isEditable() || !target.isEnabled()) {
58
            target.getToolkit().beep();
59
            return;
60
        }
61
        final BaseDocument doc = (BaseDocument) target.getDocument();
62
        final class R implements Runnable {
63
            public void run() {
64
                Caret caret = target.getCaret();
65
                int dotpos = caret.getDot();
66
                Formatter formatter = doc.getFormatter();
67
                formatter.indentLock();
68
                try {
69
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
70
                    doc.insertString(eoloffset, "" + what, null);
71
                    if (withNewline) {
72
                        //This is code from the editor module, but it is
73
                        //a pretty strange way to do this:
74
                        doc.insertString(dotpos, "-", null); //NOI18N
75
                        doc.remove(dotpos, 1);
76
                        int eolDot = Utilities.getRowEnd(target, caret.getDot());
77
                        int newDotPos = formatter.indentNewLine(doc, eolDot);
78
                        caret.setDot(newDotPos);
79
                    }
80
                } catch (BadLocationException ex) {
81
                    Exceptions.printStackTrace(ex);
82
                } finally {
83
                    formatter.indentUnlock();
84
                }
85
            }
86
        };
87
        doc.runAtomicAsUser(new R());
88
    }
89
}
(-)java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings-Mac.xml (+2 lines)
Lines 31-34 Link Here
31
    <bind key="OS-DOWN" remove="true"/>
31
    <bind key="OS-DOWN" remove="true"/>
32
    <bind key="DOS-DOWN" actionName="select-element-previous"/>
32
    <bind key="DOS-DOWN" actionName="select-element-previous"/>
33
    <bind key="O-I" actionName="generate-code"/>
33
    <bind key="O-I" actionName="generate-code"/>
34
    <bind actionName="complete-line" key="D-SEMICOLON"/>
35
    <bind actionName="complete-line-newline" key="DS-SEMICOLON"/>
34
</bindings>
36
</bindings>
(-)java/editor/src/org/netbeans/modules/java/editor/resources/DefaultKeyBindings.xml (+2 lines)
Lines 42-45 Link Here
42
42
43
    <bind actionName="in-place-refactoring" key="D-R"/>
43
    <bind actionName="in-place-refactoring" key="D-R"/>
44
    <bind actionName="generate-code" key="O-INSERT"/>
44
    <bind actionName="generate-code" key="O-INSERT"/>
45
    <bind actionName="complete-line" key="D-SEMICOLON"/>
46
    <bind actionName="complete-line-newline" key="DS-SEMICOLON"/>
45
</bindings>
47
</bindings>

Return to bug 101133