Lines 866-871
Link Here
|
866 |
} |
866 |
} |
867 |
} |
867 |
} |
868 |
|
868 |
|
|
|
869 |
|
870 |
/** |
871 |
* Reindent the current line. |
872 |
* |
873 |
* @todo Fix it such that it doesn't modify the selection |
874 |
*/ |
875 |
public static class ReindentLineAction extends BaseAction { |
876 |
|
877 |
static final long serialVersionUID =1L; |
878 |
|
879 |
public ReindentLineAction() { |
880 |
// TODO: figure out what these flags are all about |
881 |
super(BaseKit.reindentLineAction, |
882 |
ABBREV_RESET | MAGIC_POSITION_RESET | UNDO_MERGE_RESET); |
883 |
//putValue ("helpID", ReindentLineAction.class.getName ()); |
884 |
} |
885 |
|
886 |
public void actionPerformed(ActionEvent evt, JTextComponent target) { |
887 |
if (target != null) { |
888 |
if (!target.isEditable() || !target.isEnabled()) { |
889 |
target.getToolkit().beep(); |
890 |
return; |
891 |
} |
892 |
|
893 |
// Todo: operate iterately over all the lines in the |
894 |
// selection |
895 |
|
896 |
// Note: there is a Utilities.reformat(doc, pos) |
897 |
// method - is that all I need? |
898 |
|
899 |
|
900 |
// This code is copied from FormatAction in this |
901 |
// same file - I just tweaked the code which used |
902 |
// to look at the selection to compute the line bounds |
903 |
// instead. Finally, I adjust the caret position to |
904 |
// the first non-whitespace character instead of |
905 |
// column 0. |
906 |
|
907 |
Caret caret = target.getCaret(); |
908 |
BaseDocument doc = (BaseDocument)target.getDocument(); |
909 |
GuardedDocument gdoc = (doc instanceof GuardedDocument) |
910 |
? (GuardedDocument)doc : null; |
911 |
|
912 |
doc.atomicLock(); |
913 |
try { |
914 |
|
915 |
int caretLine = Utilities.getLineOffset(doc, caret.getDot()); |
916 |
int startPos; |
917 |
Position endPosition; |
918 |
|
919 |
|
920 |
/* |
921 |
if (caret.isSelectionVisible()) { |
922 |
startPos = target.getSelectionStart(); |
923 |
endPosition = doc.createPosition(target.getSelectionEnd()); |
924 |
} else { |
925 |
startPos = 0; |
926 |
endPosition = doc.createPosition(doc.getLength()); |
927 |
} |
928 |
*/ |
929 |
startPos = Utilities.getRowStart(doc, caret.getDot()); |
930 |
endPosition = |
931 |
doc.createPosition(Utilities.getRowEnd(doc, caret.getDot())); |
932 |
|
933 |
|
934 |
|
935 |
int pos = startPos; |
936 |
if (gdoc != null) { |
937 |
pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); |
938 |
} |
939 |
|
940 |
while (pos < endPosition.getOffset()) { |
941 |
int stopPos = endPosition.getOffset(); |
942 |
if (gdoc != null) { // adjust to start of the next guarded block |
943 |
stopPos = gdoc.getGuardedBlockChain().adjustToNextBlockStart(pos); |
944 |
if (stopPos == -1) { |
945 |
stopPos = endPosition.getOffset(); |
946 |
} |
947 |
} |
948 |
|
949 |
int reformattedLen = doc.getFormatter().reformat(doc, pos, stopPos); |
950 |
pos = pos + reformattedLen; |
951 |
|
952 |
if (gdoc != null) { // adjust to end of current block |
953 |
pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos); |
954 |
} |
955 |
} |
956 |
|
957 |
// Restore the line |
958 |
pos = Utilities.getRowStartFromLineOffset(doc, caretLine); |
959 |
if (pos >= 0) { |
960 |
|
961 |
pos = Utilities.getRowFirstNonWhite(doc, pos); |
962 |
|
963 |
caret.setDot(pos); |
964 |
} |
965 |
} catch (GuardedException e) { |
966 |
target.getToolkit().beep(); |
967 |
} catch (BadLocationException e) { |
968 |
if (System.getProperty("netbeans.debug.exceptions") != null) { // NOI18N |
969 |
e.printStackTrace(); |
970 |
} |
971 |
} finally { |
972 |
doc.atomicUnlock(); |
973 |
} |
974 |
|
975 |
} |
976 |
} |
977 |
} |
978 |
|
979 |
|
869 |
public static class AdjustWindowAction extends BaseAction { |
980 |
public static class AdjustWindowAction extends BaseAction { |
870 |
|
981 |
|
871 |
int percentFromWindowTop; |
982 |
int percentFromWindowTop; |