Skip to content

Commit 01b41c2

Browse files
IEP-1583: Closing old editor window when old workspace is found (#1262)
* IEP-1583: Closing old editor window when old workspace is found * fix: address NPE while launching --------- Co-authored-by: Kondal Kolipaka <[email protected]>
1 parent 639e4f4 commit 01b41c2

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import org.eclipse.swt.widgets.Display;
2020
import org.eclipse.swt.widgets.MessageBox;
2121
import org.eclipse.swt.widgets.Shell;
22+
import org.eclipse.ui.IEditorPart;
23+
import org.eclipse.ui.IEditorReference;
2224
import org.eclipse.ui.IStartup;
2325
import org.eclipse.ui.IWorkbench;
26+
import org.eclipse.ui.IWorkbenchPage;
2427
import org.eclipse.ui.IWorkbenchWindow;
2528
import org.eclipse.ui.PartInitException;
2629
import org.eclipse.ui.PlatformUI;
@@ -93,6 +96,7 @@ public void earlyStartup()
9396
if (toolInitializer.isOldEspIdfConfigPresent() && !toolInitializer.isOldConfigExported())
9497
{
9598
Logger.log("Old configuration found and not converted");
99+
closeEspIdfManager();
96100
boolean isEimInApplications = checkIfEimPathMacOsIsInApplications();
97101
if (!isEimInApplications)
98102
{
@@ -213,6 +217,33 @@ private void displayInformationMessageBox(String messageTitle, String message)
213217
}, ignored -> {
214218
});
215219
}
220+
221+
private void closeEspIdfManager()
222+
{
223+
Display.getDefault().asyncExec(() -> {
224+
IWorkbenchWindow window = EclipseHandler.getActiveWorkbenchWindow();
225+
if (window != null)
226+
{
227+
IWorkbenchPage page = window.getActivePage();
228+
if (page != null)
229+
{
230+
IEditorReference[] editors = page.getEditorReferences();
231+
for (IEditorReference editorRef : editors)
232+
{
233+
if (ESPIDFManagerEditor.EDITOR_ID.equals(editorRef.getId()))
234+
{
235+
IEditorPart editor = editorRef.getEditor(false);
236+
if (editor != null)
237+
{
238+
page.closeEditor(editor, false);
239+
}
240+
}
241+
}
242+
}
243+
}
244+
});
245+
}
246+
216247

217248
private void showEimJsonStateChangeNotification()
218249
{

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/ESPIDFManagerEditor.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
/**
1818
* Editor main class used for tools management
19+
*
1920
* @author Ali Azam Rana
2021
*
2122
*/
2223
public class ESPIDFManagerEditor extends EditorPart
2324
{
2425
public static final String EDITOR_ID = "com.espressif.idf.ui.manageespidf";
25-
26+
2627
@Override
2728
public void init(IEditorSite site, IEditorInput input) throws PartInitException
2829
{
2930
setSite(site);
3031
setInput(input);
3132
setPartName(Messages.EspIdfEditorTitle);
3233
}
33-
34-
34+
3535
@Override
3636
public void doSave(IProgressMonitor monitor)
3737
{
@@ -49,30 +49,36 @@ public boolean isSaveAsAllowed()
4949
{
5050
return false;
5151
}
52-
52+
5353
@Override
5454
public void createPartControl(Composite parent)
5555
{
56-
ESPIDFMainTablePage espidfMainTablePage = ESPIDFMainTablePage
57-
.getInstance(((EimEditorInput) getEditorInput()).getEimJson());
58-
espidfMainTablePage.createPage(parent);
59-
if (((EimEditorInput) getEditorInput()).isFirstStartup())
56+
IEditorInput input = getEditorInput();
57+
58+
if (input instanceof EimEditorInput eimInput)
6059
{
61-
espidfMainTablePage.setupInitialEspIdf();
60+
ESPIDFMainTablePage espidfMainTablePage = ESPIDFMainTablePage.getInstance(eimInput.getEimJson());
61+
espidfMainTablePage.createPage(parent);
62+
if (eimInput.isFirstStartup())
63+
{
64+
espidfMainTablePage.setupInitialEspIdf();
65+
}
66+
}
67+
else
68+
{
69+
getSite().getPage().closeEditor(this, false);
6270
}
6371
}
6472

65-
6673
@Override
6774
public boolean isDirty()
6875
{
6976
return false;
7077
}
7178

72-
7379
@Override
7480
public void setFocus()
7581
{
76-
82+
7783
}
7884
}

0 commit comments

Comments
 (0)