mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 514423 - Ensure CodanCReconciler is installed on editors from all windows
Change-Id: I323a78fc1bd3a43270e27be7eb21c13f5a85de9f
This commit is contained in:
parent
efa1662b6c
commit
cacb84e277
3 changed files with 58 additions and 11 deletions
|
@ -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) {
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue