52
52
import java .util .ArrayList ;
53
53
import java .util .Arrays ;
54
54
import java .util .Collections ;
55
- import java .util .Comparator ;
56
55
import java .util .Enumeration ;
57
56
import java .util .HashMap ;
58
57
import java .util .LinkedList ;
82
81
import javax .swing .event .MenuListener ;
83
82
import javax .swing .text .BadLocationException ;
84
83
84
+ import org .fife .ui .rsyntaxtextarea .folding .FoldManager ;
85
+
85
86
import com .jcraft .jsch .JSchException ;
86
87
87
88
import cc .arduino .CompilerProgressListener ;
94
95
import cc .arduino .view .findreplace .FindReplace ;
95
96
import jssc .SerialPortException ;
96
97
import processing .app .debug .RunnerException ;
98
+ import processing .app .debug .TargetBoard ;
97
99
import processing .app .forms .PasswordAuthorizationDialog ;
98
100
import processing .app .helpers .DocumentTextChangeListener ;
99
101
import processing .app .helpers .Keys ;
@@ -147,9 +149,6 @@ public boolean test(SketchController controller) {
147
149
}
148
150
}
149
151
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
-
153
152
final Base base ;
154
153
155
154
// otherwise, if the window is resized with the message label
@@ -1041,22 +1040,30 @@ class BoardPortJCheckBoxMenuItem extends JCheckBoxMenuItem {
1041
1040
private BoardPort port ;
1042
1041
1043
1042
public BoardPortJCheckBoxMenuItem (BoardPort port ) {
1044
- super (port .getLabel ());
1043
+ super ();
1044
+ this .port = port ;
1045
+ setText (toString ());
1045
1046
addActionListener (e -> {
1046
1047
selectSerialPort (port .getAddress ());
1047
1048
base .onBoardOrPortChange ();
1048
1049
});
1049
- this .port = port ;
1050
1050
}
1051
1051
1052
1052
@ Override
1053
1053
public String toString () {
1054
1054
// 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 ;
1056
1060
}
1057
1061
}
1058
1062
1059
1063
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
+
1060
1067
portMenu .removeAll ();
1061
1068
1062
1069
String selectedPort = PreferencesData .get ("serial.port" );
@@ -1065,31 +1072,43 @@ private void populatePortMenu() {
1065
1072
1066
1073
ports = platform .filterPorts (ports , PreferencesData .getBoolean ("serial.ports.showall" ));
1067
1074
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 ());
1074
1098
});
1075
1099
1076
- String lastProtocol = null ;
1077
- String lastProtocolTranslated ;
1100
+ String lastProtocol = "" ;
1101
+ String lastProtocolLabel = "" ;
1078
1102
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 () ) {
1081
1105
portMenu .addSeparator ();
1082
1106
}
1083
1107
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 );
1093
1112
}
1094
1113
String address = port .getAddress ();
1095
1114
@@ -1648,8 +1667,17 @@ public void removeAllLineHighlights() {
1648
1667
}
1649
1668
1650
1669
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 ));
1653
1681
}
1654
1682
1655
1683
@@ -2392,9 +2420,9 @@ private void handleBoardInfo() {
2392
2420
for (BoardPort port : ports ) {
2393
2421
if (port .getAddress ().equals (selectedPort )) {
2394
2422
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" );
2398
2426
protocol = port .getProtocol ();
2399
2427
found = true ;
2400
2428
break ;
@@ -2564,12 +2592,12 @@ private void statusEmpty() {
2564
2592
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2565
2593
2566
2594
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 ( ));
2570
2598
else
2571
2599
lineStatus .setBoardName ("-" );
2572
- lineStatus .setSerialPort (PreferencesData .get ("serial.port" ));
2600
+ lineStatus .setPort (PreferencesData .get ("serial.port" ));
2573
2601
lineStatus .repaint ();
2574
2602
}
2575
2603
0 commit comments