Index: libsrc/org/netbeans/editor/ActionFactory.java =================================================================== RCS file: /cvs/editor/libsrc/org/netbeans/editor/ActionFactory.java,v retrieving revision 1.35 diff -u -u -r1.35 ActionFactory.java --- libsrc/org/netbeans/editor/ActionFactory.java 9 Jul 2002 10:59:10 -0000 1.35 +++ libsrc/org/netbeans/editor/ActionFactory.java 2 Apr 2003 17:32:04 -0000 @@ -828,6 +828,117 @@ } } + + /** + * Reindent the current line. + * + * @todo Fix it such that it doesn't modify the selection + */ + public static class ReindentLineAction extends BaseAction { + + static final long serialVersionUID =1L; + + public ReindentLineAction() { + // TODO: figure out what these flags are all about + super(BaseKit.reindentLineAction, + ABBREV_RESET | MAGIC_POSITION_RESET | UNDO_MERGE_RESET); + //putValue ("helpID", ReindentLineAction.class.getName ()); + } + + public void actionPerformed(ActionEvent evt, JTextComponent target) { + if (target != null) { + if (!target.isEditable() || !target.isEnabled()) { + target.getToolkit().beep(); + return; + } + + // Todo: operate iterately over all the lines in the + // selection + + // Note: there is a Utilities.reformat(doc, pos) + // method - is that all I need? + + + // This code is copied from FormatAction in this + // same file - I just tweaked the code which used + // to look at the selection to compute the line bounds + // instead. Finally, I adjust the caret position to + // the first non-whitespace character instead of + // column 0. + + Caret caret = target.getCaret(); + BaseDocument doc = (BaseDocument)target.getDocument(); + GuardedDocument gdoc = (doc instanceof GuardedDocument) + ? (GuardedDocument)doc : null; + + doc.atomicLock(); + try { + + int caretLine = Utilities.getLineOffset(doc, caret.getDot()); + int startPos; + Position endPosition; + + + /* + if (caret.isSelectionVisible()) { + startPos = target.getSelectionStart(); + endPosition = doc.createPosition(target.getSelectionEnd()); + } else { + startPos = 0; + endPosition = doc.createPosition(doc.getLength()); + } + */ + startPos = Utilities.getRowStart(doc, caret.getDot()); + endPosition = + doc.createPosition(Utilities.getRowEnd(doc, caret.getDot())); + + + + int pos = startPos; + if (gdoc != null) { + pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); + } + + while (pos < endPosition.getOffset()) { + int stopPos = endPosition.getOffset(); + if (gdoc != null) { // adjust to start of the next guarded block + stopPos = gdoc.getGuardedBlockChain().adjustToNextBlockStart(pos); + if (stopPos == -1) { + stopPos = endPosition.getOffset(); + } + } + + int reformattedLen = doc.getFormatter().reformat(doc, pos, stopPos); + pos = pos + reformattedLen; + + if (gdoc != null) { // adjust to end of current block + pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); + } + } + + // Restore the line + pos = Utilities.getRowStartFromLineOffset(doc, caretLine); + if (pos >= 0) { + + pos = Utilities.getRowFirstNonWhite(doc, pos); + + caret.setDot(pos); + } + } catch (GuardedException e) { + target.getToolkit().beep(); + } catch (BadLocationException e) { + if (System.getProperty("netbeans.debug.exceptions") != null) { // NOI18N + e.printStackTrace(); + } + } finally { + doc.atomicUnlock(); + } + + } + } + } + + public static class AdjustWindowAction extends BaseAction { int percentFromWindowTop; Index: libsrc/org/netbeans/editor/BaseKit.java =================================================================== RCS file: /cvs/editor/libsrc/org/netbeans/editor/BaseKit.java,v retrieving revision 1.86 diff -u -u -r1.86 BaseKit.java --- libsrc/org/netbeans/editor/BaseKit.java 27 Feb 2003 23:36:16 -0000 1.86 +++ libsrc/org/netbeans/editor/BaseKit.java 2 Apr 2003 17:32:06 -0000 @@ -130,6 +130,9 @@ /** Shift line right action */ public static final String shiftLineRightAction = "shift-line-right"; // NOI18N + /** Reindent Line action */ + public static final String reindentLineAction = "reindent-line"; // NOI18N + /** Shift line left action */ public static final String shiftLineLeftAction = "shift-line-left"; // NOI18N @@ -578,6 +581,7 @@ new ActionFactory.RedoAction(), new ActionFactory.WordMatchAction(wordMatchNextAction, true), new ActionFactory.WordMatchAction(wordMatchPrevAction, false), + new ActionFactory.ReindentLineAction(), new ActionFactory.ShiftLineAction(shiftLineLeftAction, false), new ActionFactory.ShiftLineAction(shiftLineRightAction, true), new ActionFactory.AdjustWindowAction(adjustWindowTopAction, 0), Index: libsrc/org/netbeans/editor/Bundle.properties =================================================================== RCS file: /cvs/editor/libsrc/org/netbeans/editor/Bundle.properties,v retrieving revision 1.32 diff -u -u -r1.32 Bundle.properties --- libsrc/org/netbeans/editor/Bundle.properties 24 Feb 2003 16:02:33 -0000 1.32 +++ libsrc/org/netbeans/editor/Bundle.properties 2 Apr 2003 17:32:07 -0000 @@ -90,6 +90,7 @@ paste-from-clipboard=Paste popup-remove-selection=Delete redo=Redo +reindent-line=Re-indent Line remove-line=Delete Line remove-line-begin=Delete Preceding Characters in Line remove-selection=Delete Selection @@ -308,4 +309,4 @@ ## ext.Completion.java ext.Completion.wait=Please wait... -#--- \ No newline at end of file +#--- Index: libsrc/org/netbeans/editor/SettingsDefaults.java =================================================================== RCS file: /cvs/editor/libsrc/org/netbeans/editor/SettingsDefaults.java,v retrieving revision 1.26 diff -u -u -r1.26 SettingsDefaults.java --- libsrc/org/netbeans/editor/SettingsDefaults.java 27 Feb 2003 23:36:24 -0000 1.26 +++ libsrc/org/netbeans/editor/SettingsDefaults.java 2 Apr 2003 17:32:08 -0000 @@ -187,14 +187,30 @@ KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), BaseKit.insertBreakAction ), + /* This is an appropriate emacs binding, but what do we do + in non-emacs mode? Let's see what JBuilder does. new MultiKeyBinding( - KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), + KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK), + BaseKit.insertTabAction + ), + */ + new MultiKeyBinding( + new KeyStroke[] { + KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK), + KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0) + }, BaseKit.insertTabAction ), new MultiKeyBinding( + KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), + BaseKit.reindentLineAction + ), + /* + new MultiKeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK), BaseKit.removeTabAction ), + */ new MultiKeyBinding( KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), BaseKit.deletePrevCharAction