5252import java .util .ArrayList ;
5353import java .util .Arrays ;
5454import java .util .Collections ;
55- import java .util .Comparator ;
5655import java .util .Enumeration ;
5756import java .util .HashMap ;
5857import java .util .LinkedList ;
8281import javax .swing .event .MenuListener ;
8382import javax .swing .text .BadLocationException ;
8483
84+ import org .fife .ui .rsyntaxtextarea .folding .FoldManager ;
85+
8586import com .jcraft .jsch .JSchException ;
8687
8788import cc .arduino .CompilerProgressListener ;
9495import cc .arduino .view .findreplace .FindReplace ;
9596import jssc .SerialPortException ;
9697import processing .app .debug .RunnerException ;
98+ import processing .app .debug .TargetBoard ;
9799import processing .app .forms .PasswordAuthorizationDialog ;
98100import processing .app .helpers .DocumentTextChangeListener ;
99101import processing .app .helpers .Keys ;
@@ -147,9 +149,6 @@ public boolean test(SketchController controller) {
147149 }
148150 }
149151
150- private final static List <String > BOARD_PROTOCOLS_ORDER = Arrays .asList ("serial" , "network" );
151- private final static List <String > BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays .asList (tr ("Serial ports" ), tr ("Network ports" ));
152-
153152 final Base base ;
154153
155154 // otherwise, if the window is resized with the message label
@@ -1041,22 +1040,30 @@ class BoardPortJCheckBoxMenuItem extends JCheckBoxMenuItem {
10411040 private BoardPort port ;
10421041
10431042 public BoardPortJCheckBoxMenuItem (BoardPort port ) {
1044- super (port .getLabel ());
1043+ super ();
1044+ this .port = port ;
1045+ setText (toString ());
10451046 addActionListener (e -> {
10461047 selectSerialPort (port .getAddress ());
10471048 base .onBoardOrPortChange ();
10481049 });
1049- this .port = port ;
10501050 }
10511051
10521052 @ Override
10531053 public String toString () {
10541054 // This is required for serialPrompt()
1055- return port .getLabel ();
1055+ String label = port .getLabel ();
1056+ if (port .getBoardName () != null && !port .getBoardName ().isEmpty ()) {
1057+ label += " (" + port .getBoardName () + ")" ;
1058+ }
1059+ return label ;
10561060 }
10571061 }
10581062
10591063 private void populatePortMenu () {
1064+ final List <String > PROTOCOLS_ORDER = Arrays .asList ("serial" , "network" );
1065+ final List <String > PROTOCOLS_LABELS = Arrays .asList (tr ("Serial ports" ), tr ("Network ports" ));
1066+
10601067 portMenu .removeAll ();
10611068
10621069 String selectedPort = PreferencesData .get ("serial.port" );
@@ -1065,31 +1072,43 @@ private void populatePortMenu() {
10651072
10661073 ports = platform .filterPorts (ports , PreferencesData .getBoolean ("serial.ports.showall" ));
10671074
1068- Collections .sort (ports , new Comparator <BoardPort >() {
1069- @ Override
1070- public int compare (BoardPort o1 , BoardPort o2 ) {
1071- return (BOARD_PROTOCOLS_ORDER .indexOf (o1 .getProtocol ()) - BOARD_PROTOCOLS_ORDER .indexOf (o2 .getProtocol ())) * 10 +
1072- o1 .getAddress ().compareTo (o2 .getAddress ());
1073- }
1075+ ports .stream () //
1076+ .filter (port -> port .getProtocolLabel () == null || port .getProtocolLabel ().isEmpty ())
1077+ .forEach (port -> {
1078+ int labelIdx = PROTOCOLS_ORDER .indexOf (port .getProtocol ());
1079+ if (labelIdx != -1 ) {
1080+ port .setProtocolLabel (PROTOCOLS_LABELS .get (labelIdx ));
1081+ } else {
1082+ port .setProtocolLabel (port .getProtocol ());
1083+ }
1084+ });
1085+
1086+ Collections .sort (ports , (port1 , port2 ) -> {
1087+ String pr1 = port1 .getProtocol ();
1088+ String pr2 = port2 .getProtocol ();
1089+ int prIdx1 = PROTOCOLS_ORDER .contains (pr1 ) ? PROTOCOLS_ORDER .indexOf (pr1 ) : 999 ;
1090+ int prIdx2 = PROTOCOLS_ORDER .contains (pr2 ) ? PROTOCOLS_ORDER .indexOf (pr2 ) : 999 ;
1091+ int r = prIdx1 - prIdx2 ;
1092+ if (r != 0 )
1093+ return r ;
1094+ r = port1 .getProtocolLabel ().compareTo (port2 .getProtocolLabel ());
1095+ if (r != 0 )
1096+ return r ;
1097+ return port1 .getAddress ().compareTo (port2 .getAddress ());
10741098 });
10751099
1076- String lastProtocol = null ;
1077- String lastProtocolTranslated ;
1100+ String lastProtocol = "" ;
1101+ String lastProtocolLabel = "" ;
10781102 for (BoardPort port : ports ) {
1079- if (lastProtocol == null || !port .getProtocol ().equals (lastProtocol )) {
1080- if (lastProtocol != null ) {
1103+ if (! port . getProtocol (). equals ( lastProtocol ) || !port .getProtocolLabel ().equals (lastProtocolLabel )) {
1104+ if (! lastProtocol . isEmpty () ) {
10811105 portMenu .addSeparator ();
10821106 }
10831107 lastProtocol = port .getProtocol ();
1084-
1085- if (BOARD_PROTOCOLS_ORDER .indexOf (port .getProtocol ()) != -1 ) {
1086- lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS .get (BOARD_PROTOCOLS_ORDER .indexOf (port .getProtocol ()));
1087- } else {
1088- lastProtocolTranslated = port .getProtocol ();
1089- }
1090- JMenuItem lastProtocolMenuItem = new JMenuItem (tr (lastProtocolTranslated ));
1091- lastProtocolMenuItem .setEnabled (false );
1092- portMenu .add (lastProtocolMenuItem );
1108+ lastProtocolLabel = port .getProtocolLabel ();
1109+ JMenuItem item = new JMenuItem (tr (lastProtocolLabel ));
1110+ item .setEnabled (false );
1111+ portMenu .add (item );
10931112 }
10941113 String address = port .getAddress ();
10951114
@@ -1648,8 +1667,17 @@ public void removeAllLineHighlights() {
16481667 }
16491668
16501669 public void addLineHighlight (int line ) throws BadLocationException {
1651- getCurrentTab ().getTextArea ().addLineHighlight (line , new Color (1 , 0 , 0 , 0.2f ));
1652- getCurrentTab ().getTextArea ().setCaretPosition (getCurrentTab ().getTextArea ().getLineStartOffset (line ));
1670+ SketchTextArea textArea = getCurrentTab ().getTextArea ();
1671+ FoldManager foldManager = textArea .getFoldManager ();
1672+ if (foldManager .isLineHidden (line )) {
1673+ for (int i = 0 ; i < foldManager .getFoldCount (); i ++) {
1674+ if (foldManager .getFold (i ).containsLine (line )) {
1675+ foldManager .getFold (i ).setCollapsed (false );
1676+ }
1677+ }
1678+ }
1679+ textArea .addLineHighlight (line , new Color (1 , 0 , 0 , 0.2f ));
1680+ textArea .setCaretPosition (textArea .getLineStartOffset (line ));
16531681 }
16541682
16551683
@@ -2392,9 +2420,9 @@ private void handleBoardInfo() {
23922420 for (BoardPort port : ports ) {
23932421 if (port .getAddress ().equals (selectedPort )) {
23942422 label = port .getBoardName ();
2395- vid = port .getVID ( );
2396- pid = port .getPID ( );
2397- iserial = port .getISerial ( );
2423+ vid = port .getPrefs (). get ( "vid" );
2424+ pid = port .getPrefs (). get ( "pid" );
2425+ iserial = port .getPrefs (). get ( "iserial" );
23982426 protocol = port .getProtocol ();
23992427 found = true ;
24002428 break ;
@@ -2564,12 +2592,12 @@ private void statusEmpty() {
25642592 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25652593
25662594 protected void onBoardOrPortChange () {
2567- Map < String , String > boardPreferences = BaseNoGui .getBoardPreferences ();
2568- if (boardPreferences != null )
2569- lineStatus .setBoardName (boardPreferences . get ( "name" ));
2595+ TargetBoard board = BaseNoGui .getTargetBoard ();
2596+ if (board != null )
2597+ lineStatus .setBoardName (board . getName ( ));
25702598 else
25712599 lineStatus .setBoardName ("-" );
2572- lineStatus .setSerialPort (PreferencesData .get ("serial.port" ));
2600+ lineStatus .setPort (PreferencesData .get ("serial.port" ));
25732601 lineStatus .repaint ();
25742602 }
25752603
0 commit comments