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 30147
Collapse All | Expand All

(-)libsrc/org/netbeans/editor/ActionFactory.java (+111 lines)
Lines 828-833 Link Here
828
        }
828
        }
829
    }
829
    }
830
830
831
832
    /**
833
     * Reindent the current line.
834
     *
835
     * @todo Fix it such that it doesn't modify the selection
836
     */
837
    public static class ReindentLineAction extends BaseAction {
838
839
        static final long serialVersionUID =1L;
840
841
        public ReindentLineAction() {
842
            // TODO: figure out what these flags are all about
843
            super(BaseKit.reindentLineAction,
844
                  ABBREV_RESET | MAGIC_POSITION_RESET | UNDO_MERGE_RESET);
845
            //putValue ("helpID", ReindentLineAction.class.getName ());
846
        }
847
848
        public void actionPerformed(ActionEvent evt, JTextComponent target) {
849
            if (target != null) {
850
                if (!target.isEditable() || !target.isEnabled()) {
851
                    target.getToolkit().beep();
852
                    return;
853
                }
854
855
                // Todo: operate iterately over all the lines in the
856
                // selection
857
858
                // Note: there is a Utilities.reformat(doc, pos)
859
                // method - is that all I need?
860
861
862
                // This code is copied from FormatAction in this
863
                // same file - I just tweaked the code which used
864
                // to look at the selection to compute the line bounds
865
                // instead. Finally, I adjust the caret position to
866
                // the first non-whitespace character instead of
867
                // column 0.
868
                
869
                Caret caret = target.getCaret();
870
                BaseDocument doc = (BaseDocument)target.getDocument();
871
                GuardedDocument gdoc = (doc instanceof GuardedDocument)
872
                                       ? (GuardedDocument)doc : null;
873
874
                doc.atomicLock();
875
                try {
876
877
                    int caretLine = Utilities.getLineOffset(doc, caret.getDot());
878
                    int startPos;
879
                    Position endPosition;
880
881
882
                    /*
883
                    if (caret.isSelectionVisible()) {
884
                        startPos = target.getSelectionStart();
885
                        endPosition = doc.createPosition(target.getSelectionEnd());
886
                    } else {
887
                        startPos = 0;
888
                        endPosition = doc.createPosition(doc.getLength());
889
                    }
890
                    */
891
                    startPos = Utilities.getRowStart(doc, caret.getDot());
892
                    endPosition =
893
                      doc.createPosition(Utilities.getRowEnd(doc, caret.getDot()));
894
895
896
                    
897
                    int pos = startPos;
898
                    if (gdoc != null) {
899
                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
900
                    }
901
902
                    while (pos < endPosition.getOffset()) {
903
                        int stopPos = endPosition.getOffset();
904
                        if (gdoc != null) { // adjust to start of the next guarded block
905
                            stopPos = gdoc.getGuardedBlockChain().adjustToNextBlockStart(pos);
906
                            if (stopPos == -1) {
907
                                stopPos = endPosition.getOffset();
908
                            }
909
                        }
910
911
                        int reformattedLen = doc.getFormatter().reformat(doc, pos, stopPos);
912
                        pos = pos + reformattedLen;
913
914
                        if (gdoc != null) { // adjust to end of current block
915
                            pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
916
                        }
917
                    }
918
919
                    // Restore the line
920
                    pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
921
                    if (pos >= 0) {
922
                        
923
                        pos = Utilities.getRowFirstNonWhite(doc, pos);
924
                        
925
                        caret.setDot(pos);
926
                    }
927
                } catch (GuardedException e) {
928
                    target.getToolkit().beep();
929
                } catch (BadLocationException e) {
930
                    if (System.getProperty("netbeans.debug.exceptions") != null) { // NOI18N
931
                        e.printStackTrace();
932
                    }
933
                } finally {
934
                    doc.atomicUnlock();
935
                }
936
                
937
            }
938
        }
939
    }
940
941
    
831
    public static class AdjustWindowAction extends BaseAction {
942
    public static class AdjustWindowAction extends BaseAction {
832
943
833
        int percentFromWindowTop;
944
        int percentFromWindowTop;
(-)libsrc/org/netbeans/editor/BaseKit.java (+4 lines)
Lines 130-135 Link Here
130
    /** Shift line right action */
130
    /** Shift line right action */
131
    public static final String shiftLineRightAction = "shift-line-right"; // NOI18N
131
    public static final String shiftLineRightAction = "shift-line-right"; // NOI18N
132
132
133
    /** Reindent Line action */
134
    public static final String reindentLineAction = "reindent-line"; // NOI18N
135
133
    /** Shift line left action */
136
    /** Shift line left action */
134
    public static final String shiftLineLeftAction = "shift-line-left"; // NOI18N
137
    public static final String shiftLineLeftAction = "shift-line-left"; // NOI18N
135
138
Lines 578-583 Link Here
578
                   new ActionFactory.RedoAction(),
581
                   new ActionFactory.RedoAction(),
579
                   new ActionFactory.WordMatchAction(wordMatchNextAction, true),
582
                   new ActionFactory.WordMatchAction(wordMatchNextAction, true),
580
                   new ActionFactory.WordMatchAction(wordMatchPrevAction, false),
583
                   new ActionFactory.WordMatchAction(wordMatchPrevAction, false),
584
                   new ActionFactory.ReindentLineAction(),
581
                   new ActionFactory.ShiftLineAction(shiftLineLeftAction, false),
585
                   new ActionFactory.ShiftLineAction(shiftLineLeftAction, false),
582
                   new ActionFactory.ShiftLineAction(shiftLineRightAction, true),
586
                   new ActionFactory.ShiftLineAction(shiftLineRightAction, true),
583
                   new ActionFactory.AdjustWindowAction(adjustWindowTopAction, 0),
587
                   new ActionFactory.AdjustWindowAction(adjustWindowTopAction, 0),
(-)libsrc/org/netbeans/editor/Bundle.properties (-1 / +2 lines)
Lines 90-95 Link Here
90
paste-from-clipboard=Paste
90
paste-from-clipboard=Paste
91
popup-remove-selection=Delete
91
popup-remove-selection=Delete
92
redo=Redo
92
redo=Redo
93
reindent-line=Re-indent Line
93
remove-line=Delete Line
94
remove-line=Delete Line
94
remove-line-begin=Delete Preceding Characters in Line
95
remove-line-begin=Delete Preceding Characters in Line
95
remove-selection=Delete Selection
96
remove-selection=Delete Selection
Lines 308-311 Link Here
308
## ext.Completion.java
309
## ext.Completion.java
309
ext.Completion.wait=Please wait...
310
ext.Completion.wait=Please wait...
310
311
311
#---
312
#---
(-)libsrc/org/netbeans/editor/SettingsDefaults.java (-1 / +17 lines)
Lines 187-200 Link Here
187
              KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
187
              KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
188
              BaseKit.insertBreakAction
188
              BaseKit.insertBreakAction
189
          ),
189
          ),
190
          /* This is an appropriate emacs binding, but what do we do
191
             in non-emacs mode? Let's see what JBuilder does.
190
          new MultiKeyBinding(
192
          new MultiKeyBinding(
191
              KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
193
              KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK),
194
              BaseKit.insertTabAction
195
          ),
196
          */
197
          new MultiKeyBinding(
198
              new KeyStroke[] {                              
199
                  KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK),
200
                  KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)
201
              },
192
              BaseKit.insertTabAction
202
              BaseKit.insertTabAction
193
          ),
203
          ),
194
          new MultiKeyBinding(
204
          new MultiKeyBinding(
205
              KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
206
              BaseKit.reindentLineAction
207
          ),
208
          /*
209
          new MultiKeyBinding(
195
              KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK),
210
              KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK),
196
              BaseKit.removeTabAction
211
              BaseKit.removeTabAction
197
          ),
212
          ),
213
          */
198
          new MultiKeyBinding(
214
          new MultiKeyBinding(
199
              KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
215
              KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
200
              BaseKit.deletePrevCharAction
216
              BaseKit.deletePrevCharAction

Return to bug 30147