Skip to content

Commit db78d3a

Browse files
committed
switched to message dialog
1 parent d4e9a01 commit db78d3a

File tree

3 files changed

+45
-39
lines changed

3 files changed

+45
-39
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class Messages extends NLS
3030
public static String EimJsonChangedMsgDetail;
3131
public static String EimJsonStateChangedMsgDetail;
3232

33+
public static String MsgYes;
34+
public static String MsgNo;
35+
3336
static
3437
{
3538
// initialize resource bundle

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ IDFGuideLinkLabel_Text=Select the version of ESP-IDF you want to use. Click the
99
EimJsonChangedMsgTitle=ESP-IDF Installation Changed
1010
EimJsonChangedMsgDetail=It seems the ESP-IDF tools have been modified. To maintain consistency, we recommend refreshing your installation. Would you like to proceed with the update?
1111
EimJsonStateChangedMsgDetail=It looks like the ESP-IDF installation was modified since last start. The Espressif IDE cannot guarantee the consistency. Kindly refresh the installation via ESP-IDF Manager.
12-
12+
MsgYes=Yes
13+
MsgNo=No

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/watcher/EimJsonUiChangeHandler.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.nio.file.Path;
99

10+
import org.eclipse.jface.dialogs.MessageDialog;
1011
import org.eclipse.swt.SWT;
1112
import org.eclipse.swt.widgets.Display;
1213
import org.eclipse.swt.widgets.MessageBox;
@@ -39,7 +40,7 @@ public class EimJsonUiChangeHandler implements EimJsonChangeListener
3940
{
4041
private Preferences preferences;
4142
private EimJson eimJson;
42-
43+
4344
public EimJsonUiChangeHandler(Preferences preferences)
4445
{
4546
this.preferences = preferences;
@@ -51,29 +52,29 @@ public void onJsonFileChanged(Path file)
5152
int response = displayMessageToUser();
5253
handleUserResponse(response);
5354
}
54-
55+
5556
public int displayMessageToUser()
5657
{
57-
final int[] response = new int[] {-1};
58+
final int[] response = new int[] { -1 };
5859
Display display = Display.getDefault();
5960
display.syncExec(() -> {
6061
Shell shell = display.getActiveShell();
6162
if (shell == null)
6263
{
6364
shell = new Shell(display);
6465
}
65-
MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
66-
messageBox.setText(Messages.EimJsonChangedMsgTitle);
67-
messageBox.setMessage(Messages.EimJsonChangedMsgDetail);
68-
response[0] = messageBox.open();
66+
MessageDialog messageDialog = new MessageDialog(shell, Messages.EimJsonChangedMsgTitle, null,
67+
Messages.EimJsonChangedMsgDetail, MessageDialog.WARNING, 0,
68+
new String[] { Messages.MsgYes, Messages.MsgNo });
69+
response[0] = messageDialog.open();
6970
});
70-
71+
7172
return response[0];
7273
}
7374

7475
public void handleUserResponse(int response)
7576
{
76-
if (response == SWT.YES)
77+
if (response == 0)
7778
{
7879
try
7980
{
@@ -83,61 +84,62 @@ public void handleUserResponse(int response)
8384
// only one entry in eimJson so we can simply refresh the IDE environment with that.
8485
setupToolsInIde();
8586
}
86-
else
87+
else
8788
{
8889
// multiple entries in json so launch manager for user to handle this
8990
launchEspIdfManager();
9091
}
9192
}
92-
catch (IOException | PartInitException e)
93+
catch (
94+
IOException
95+
| PartInitException e)
9396
{
9497
Logger.log(e);
9598
}
9699
}
97-
100+
98101
EimJsonStateChecker checker = new EimJsonStateChecker(preferences);
99102
checker.updateLastSeenTimestamp();
100103
}
101-
104+
102105
private void loadEimJson() throws IOException
103106
{
104107
EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser();
105108
eimJson = eimIdfConfiguratinParser.getEimJson(true);
106109
}
107-
108-
109-
110+
110111
private void setupToolsInIde()
111112
{
112-
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(eimJson.getIdfInstalled().get(0), eimJson, getConsoleStream(true), getConsoleStream(false));
113+
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(eimJson.getIdfInstalled().get(0), eimJson,
114+
getConsoleStream(true), getConsoleStream(false));
113115
setupToolsInIde.schedule();
114116
}
115-
117+
116118
private void launchEspIdfManager() throws PartInitException
117119
{
118120
Display.getDefault().asyncExec(() -> {
119-
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
120-
if (activeww != null && activeww.getActivePage() != null)
121-
{
122-
try
123-
{
124-
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson),
125-
ESPIDFManagerEditor.EDITOR_ID, true);
126-
}
127-
catch (PartInitException e)
128-
{
129-
Logger.log("Failed to open ESP-IDF Manager Editor.");
130-
Logger.log(e);
131-
}
132-
}
133-
else
134-
{
135-
Logger.log("Cannot open ESP-IDF Manager Editor. No active workbench window yet.");
136-
}
137-
});
121+
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
122+
if (activeww != null && activeww.getActivePage() != null)
123+
{
124+
try
125+
{
126+
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson), ESPIDFManagerEditor.EDITOR_ID,
127+
true);
128+
}
129+
catch (PartInitException e)
130+
{
131+
Logger.log("Failed to open ESP-IDF Manager Editor.");
132+
Logger.log(e);
133+
}
134+
}
135+
else
136+
{
137+
Logger.log("Cannot open ESP-IDF Manager Editor. No active workbench window yet.");
138+
}
139+
});
138140

139141
}
140-
142+
141143
private MessageConsoleStream getConsoleStream(boolean errorStream)
142144
{
143145
IDFConsole idfConsole = new IDFConsole();

0 commit comments

Comments
 (0)