Skip to content

Commit 9a9a93d

Browse files
committed
Fixes issue #54. Always use the main (UI) thread to show the console.
1 parent 3421cbe commit 9a9a93d

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Builder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void run() {
185185
// errors, therefore throw them as CoreExceptions
186186
IStatus status = new Status(IStatus.ERROR,
187187
CppcheclipsePlugin.getId(),
188-
"Could not initialize cppcheck", e2); //$NON-NLS-1$
188+
"Could not initialize cppcheck for project "+ currentProject.getName(), e2); //$NON-NLS-1$
189189
throw new CoreException(status);
190190
}
191191
}

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Console.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import java.io.IOException;
44
import java.io.OutputStream;
55

6+
import org.eclipse.jface.dialogs.MessageDialog;
7+
import org.eclipse.jface.preference.PreferenceDialog;
68
import org.eclipse.swt.SWT;
79
import org.eclipse.swt.widgets.Display;
10+
import org.eclipse.swt.widgets.Shell;
811
import org.eclipse.ui.IWorkbenchPage;
12+
import org.eclipse.ui.IWorkbenchWindow;
913
import org.eclipse.ui.PartInitException;
1014
import org.eclipse.ui.PlatformUI;
1115
import org.eclipse.ui.console.ConsolePlugin;
@@ -15,6 +19,10 @@
1519
import org.eclipse.ui.console.IConsoleView;
1620
import org.eclipse.ui.console.MessageConsole;
1721
import org.eclipse.ui.console.MessageConsoleStream;
22+
import org.eclipse.ui.dialogs.PreferencesUtil;
23+
24+
import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;
25+
import com.googlecode.cppcheclipse.ui.preferences.BinaryPathPreferencePage;
1826

1927
/**
2028
* Wrapper around a console window, which can output an existing InputSteam.
@@ -111,11 +119,30 @@ public void println(String line) throws IOException {
111119
*
112120
* @see com.googlecode.cppcheclipse.command.IConsole#show()
113121
*/
114-
public void show() throws PartInitException {
115-
IWorkbenchPage page = PlatformUI.getWorkbench()
116-
.getActiveWorkbenchWindow().getActivePage();
117-
String id = IConsoleConstants.ID_CONSOLE_VIEW;
118-
IConsoleView view = (IConsoleView) page.showView(id);
119-
view.display(messageConsole);
122+
public void show() {
123+
124+
Runnable runnable = new Runnable() {
125+
public void run() {
126+
// this should only be called from GUI thread
127+
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
128+
if (window == null) {
129+
CppcheclipsePlugin.logError("Could not show console because there is no active workbench window");
130+
return;
131+
}
132+
IWorkbenchPage page = window.getActivePage();
133+
if (page == null) {
134+
CppcheclipsePlugin.logError("Could not show console because there is no active page");
135+
return;
136+
}
137+
try {
138+
IConsoleView view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
139+
view.display(messageConsole);
140+
} catch (PartInitException e) {
141+
CppcheclipsePlugin.logError("Could not show console", e);
142+
}
143+
144+
}
145+
};
146+
Display.getDefault().asyncExec(runnable);
120147
}
121148
}

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/commands/RunCodeAnalysis.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ protected void runResource(IResource resource,
2929
CppcheclipsePlugin.showError(Messages.bind(
3030
Messages.RunCodeAnalysis_Error, resource.getName()),
3131
e1);
32-
try {
33-
// show console in case of exceptions
34-
Console.getInstance().show();
35-
} catch (PartInitException e) {
36-
CppcheclipsePlugin.showError("Could not show console", e);
37-
}
32+
// show console in case of exceptions
33+
Console.getInstance().show();
3834
}
3935
}
4036
}

0 commit comments

Comments
 (0)