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; |