22
33import com .haleywang .putty .dto .CommandDto ;
44import com .haleywang .putty .util .StringUtils ;
5+ import com .haleywang .putty .view .CommandEditor ;
56import com .haleywang .putty .view .PlaceholderTextField ;
67import com .haleywang .putty .view .SpringRemoteView ;
78import com .haleywang .putty .view .side .SideView ;
9+ import com .mindbright .util .StringUtil ;
10+ import org .fife .ui .rsyntaxtextarea .FoldingAwareIconRowHeader ;
11+ import org .fife .ui .rtextarea .Gutter ;
12+ import org .fife .ui .rtextarea .GutterIconInfo ;
13+ import org .fife .ui .rtextarea .RTextScrollPane ;
814import org .slf4j .Logger ;
915import org .slf4j .LoggerFactory ;
1016
17+ import javax .swing .ImageIcon ;
1118import javax .swing .JButton ;
1219import javax .swing .JPanel ;
13- import javax .swing .JScrollPane ;
1420import javax .swing .JTextArea ;
1521import javax .swing .SwingUtilities ;
1622import javax .swing .border .EmptyBorder ;
1723import javax .swing .border .LineBorder ;
1824import java .awt .BorderLayout ;
1925import java .awt .Color ;
26+ import java .awt .Component ;
27+ import java .awt .Cursor ;
2028import java .awt .event .KeyAdapter ;
2129import java .awt .event .KeyEvent ;
30+ import java .awt .event .MouseAdapter ;
31+ import java .awt .event .MouseEvent ;
32+ import java .net .URL ;
33+ import java .util .Arrays ;
2234
2335
2436/**
@@ -31,6 +43,7 @@ public class CommandEditorPanel extends JPanel implements TextAreaMenu.RunAction
3143 private JTextArea updateCommandTextArea ;
3244 private PlaceholderTextField commandNameTextField ;
3345 private CommandDto currentEditCommand ;
46+ private Gutter gutter ;
3447
3548 public CommandEditorPanel () {
3649 createUpdateCommandPanel ();
@@ -40,9 +53,58 @@ private void createUpdateCommandPanel() {
4053 JPanel updateCommandPanel = this ;
4154 updateCommandPanel .setLayout (new BorderLayout ());
4255
43- updateCommandTextArea = new TextAreaMenu (this );
56+ updateCommandTextArea = new CommandEditor ();
57+
58+ RTextScrollPane sp = new RTextScrollPane (updateCommandTextArea );
59+ sp .setIconRowHeaderEnabled (true );
60+
61+ gutter = sp .getGutter ();
62+
63+ gutter .getIconArea ().addMouseListener (new MouseAdapter () {
64+
65+ @ Override
66+ public void mouseClicked (MouseEvent e ) {
67+ Component [] comps = gutter .getComponents ();
68+ FoldingAwareIconRowHeader iconComp = (FoldingAwareIconRowHeader ) Arrays .stream (comps )
69+ .filter (o -> o instanceof FoldingAwareIconRowHeader )
70+ .findFirst ().orElse (null );
71+ if (iconComp == null ) {
72+ return ;
73+ }
74+ int offs = gutter .getTextArea ().viewToModel (e .getPoint ());
75+ try {
76+ int currLine = gutter .getTextArea ().getLineOfOffset (offs );
77+ GutterIconInfo [] trackingIcons = iconComp .getTrackingIcons (currLine );
78+
79+ if (trackingIcons .length >= 1 ){
80+ //run command
81+ int lineStartOffset = gutter .getTextArea ().getLineStartOffset (currLine );
82+
83+ int lineEndOffset = gutter .getTextArea ().getLineEndOffset (currLine );
84+ String commandText = gutter .getTextArea ().getText (lineStartOffset , (lineEndOffset - lineStartOffset ));
85+ commandText = StringUtils .trim (commandText );
86+ SideView .getInstance ().runWithSelectedText (commandText );
87+ return ;
88+ }
89+ gutter .removeAllTrackingIcons ();
90+
91+ URL url = ClassLoader .getSystemClassLoader ().getResource ("Play16.png" );
92+ assert url != null ;
93+ ImageIcon icon = new ImageIcon (url );
94+
95+ gutter .addOffsetTrackingIcon (offs , icon , "Run" );
96+ } catch (Exception ex ) {
97+ LOGGER .error ("click run icon error" , ex );
98+ }
99+
100+ }
101+
102+
103+
104+ });
105+
106+
44107
45- JScrollPane sp = new JScrollPane (updateCommandTextArea );
46108 updateCommandTextArea .setLineWrap (true );
47109
48110 updateCommandTextArea .setEditable (true );
@@ -95,6 +157,9 @@ public void keyReleased(KeyEvent e) {
95157 updateCommandOuterPanel .setLayout (new BorderLayout ());
96158 updateCommandOuterPanel .add (updateCommandPanel );
97159 updateCommandOuterPanel .setBorder (new EmptyBorder (2 , 2 , 2 , 2 ));
160+
161+ Arrays .stream (gutter .getComponents ()).filter (o -> o instanceof FoldingAwareIconRowHeader )
162+ .findFirst ().ifPresent (o -> o .setCursor (new Cursor (Cursor .HAND_CURSOR )));
98163 }
99164
100165 @ Override
0 commit comments