Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-05-29 05:45:38 +0000
committerNathan Ridge2017-05-29 17:18:28 +0000
commitcacb84e277e346a42bc49d62c32c793396ad96f3 (patch)
tree59f28efa9e262ae6c97e3bfaa484521e779fe2a9
parentefa1662b6ceb5338db8a18b91c05a1762d4d66c6 (diff)
downloadorg.eclipse.cdt-cacb84e277e346a42bc49d62c32c793396ad96f3.tar.gz
org.eclipse.cdt-cacb84e277e346a42bc49d62c32c793396ad96f3.tar.xz
org.eclipse.cdt-cacb84e277e346a42bc49d62c32c793396ad96f3.zip
Bug 514423 - Ensure CodanCReconciler is installed on editors from all windows
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java17
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanWindowListener.java34
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java18
3 files changed, 58 insertions, 11 deletions
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
index cfb97d1e50..cd01b6cfa7 100644
--- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
@@ -24,9 +24,12 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
/**
* Enables Codan's "run as you type", "run on file save" and "run on file open" launch modes.
@@ -35,6 +38,20 @@ class CodanPartListener implements IPartListener2 {
private CodanCReconciler reconciler;
private IPostSaveListener postSaveListener;
+ /**
+ * Installs CodanPartListener on the given workbench window.
+ * Must be called from the UI thread.
+ */
+ static void installOnWindow(IWorkbenchWindow window) {
+ final IWorkbenchPage page = window.getActivePage();
+ CodanPartListener partListener = new CodanPartListener();
+ page.addPartListener(partListener);
+ // Check current open editors.
+ for (IEditorReference ref : page.getEditorReferences()) {
+ partListener.partOpened(ref);
+ }
+ }
+
@Override
public void partActivated(IWorkbenchPartReference partRef) {
}
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanWindowListener.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanWindowListener.java
new file mode 100644
index 0000000000..ae52b478fa
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanWindowListener.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Nathan Ridge.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.ui.cxx;
+
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbenchWindow;
+
+/**
+ * Used to install CodanPartListener on any additional windows that may be
+ * opened in the workbench.
+ */
+public class CodanWindowListener implements IWindowListener {
+ @Override
+ public void windowActivated(IWorkbenchWindow window) {
+ }
+
+ @Override
+ public void windowDeactivated(IWorkbenchWindow window) {
+ }
+
+ @Override
+ public void windowClosed(IWorkbenchWindow window) {
+ }
+
+ @Override
+ public void windowOpened(IWorkbenchWindow window) {
+ CodanPartListener.installOnWindow(window);
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java
index 40f4b373ad..44b9eba817 100644
--- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java
@@ -12,10 +12,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx;
-import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
@@ -36,16 +34,14 @@ public class Startup implements IStartup {
workbench.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
- IWorkbenchWindow active = workbench.getActiveWorkbenchWindow();
- if (active == null)
- return; // The workbench is shutting down.
- final IWorkbenchPage page = active.getActivePage();
- CodanPartListener partListener = new CodanPartListener();
- page.addPartListener(partListener);
- // Check current open editors.
- for (IEditorReference ref : page.getEditorReferences()) {
- partListener.partOpened(ref);
+ // Install a part listener on currenly open workbench windows.
+ for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
+ CodanPartListener.installOnWindow(window);
}
+
+ // Install a window listener which will be notified of
+ // new windows opening, and install a part listener on them.
+ workbench.addWindowListener(new CodanWindowListener());
}
});
}

Back to the top