提交 2724cfe9 编写于 作者: S serge-rider

Editor contexts activation fix


Former-commit-id: cf2edd91
上级 6157e132
......@@ -2603,12 +2603,12 @@
<!-- RSV context. It extends SQL editor because RSV can be embedded in editor and thus must overrride it's bindings -->
<context
id="org.jkiss.dbeaver.ui.context.resultset"
parentId="org.jkiss.dbeaver.ui.editors.sql"
parentId="org.eclipse.ui.contexts.window"
name="%context.org.jkiss.dbeaver.ui.context.resultset.name"
description="%context.org.jkiss.dbeaver.ui.context.resultset.description"/>
<context
id="org.jkiss.dbeaver.ui.context.resultset.focused"
parentId="org.jkiss.dbeaver.ui.context.resultset"
parentId="org.eclipse.ui.contexts.window"
name="%context.org.jkiss.dbeaver.ui.context.resultset.name focused"
description="%context.org.jkiss.dbeaver.ui.context.resultset.description"/>
<context
......
......@@ -71,6 +71,7 @@ public class DBeaverUI implements DBPPlatformUI {
private SharedTextColors sharedTextColors;
private TrayIconHandler trayItem;
private final List<IDisposable> globalDisposables = new ArrayList<>();
private WorkbenchContextListener contextListener;
public static DBeaverUI getInstance() {
if (instance == null) {
......@@ -129,8 +130,8 @@ public class DBeaverUI implements DBPPlatformUI {
DBUserInterface.setInstance(this);
// Register context listener
WorkbenchContextListener.registerInWorkbench();
asyncExec(() -> contextListener = WorkbenchContextListener.registerInWorkbench());
/* // Global focus lister for debug
Display.getCurrent().addFilter(SWT.FocusIn, new Listener() {
@Override
......@@ -141,6 +142,13 @@ public class DBeaverUI implements DBPPlatformUI {
*/
}
public void refreshPartContexts(IWorkbenchPart part) {
if (contextListener != null) {
contextListener.deactivatePartContexts(part);
contextListener.activatePartContexts(part);
}
}
public static AbstractUIJob runUIJob(String jobName, final DBRRunnableWithProgress runnableWithProgress) {
return runUIJob(jobName, 0, runnableWithProgress);
}
......
......@@ -20,10 +20,6 @@ import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IExecutionListener;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.*;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.contexts.IContextActivation;
......@@ -166,20 +162,25 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
@Override
public void partActivated(IWorkbenchPart part) {
activatePartContexts(part);
// log.info(part.getClass().getSimpleName() + " ACTIVATED: " + contextService.getActiveContextIds());
}
void activatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
}
try {
contextService.deferUpdates(true);
if (part instanceof INavigatorModelView) {
if (part.getAdapter(INavigatorModelView.class) != null) {
if (activationNavigator != null) {
//log.debug("Double activation of navigator context");
contextService.deactivateContext(activationNavigator);
}
activationNavigator = contextService.activateContext(NAVIGATOR_CONTEXT_ID);
}
if (part instanceof SQLEditorBase) {
if (part.getAdapter(SQLEditorBase.class) != null) {
if (activationSQL != null) {
//log.debug("Double activation of SQL context");
contextService.deactivateContext(activationSQL);
......@@ -200,11 +201,15 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
finally {
contextService.deferUpdates(false);
}
// log.info(part.getClass().getSimpleName() + " ACTIVATED: " + contextService.getActiveContextIds());
}
@Override
public void partDeactivated(IWorkbenchPart part) {
deactivatePartContexts(part);
// log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
void deactivatePartContexts(IWorkbenchPart part) {
IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
if (contextService == null) {
return;
......@@ -227,7 +232,6 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
finally {
contextService.deferUpdates(false);
}
// log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
@Override
......@@ -245,13 +249,8 @@ class WorkbenchContextListener implements IWindowListener, IPageListener, IPartL
}
static void registerInWorkbench() {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
new WorkbenchContextListener();
}
});
static WorkbenchContextListener registerInWorkbench() {
return new WorkbenchContextListener();
}
private static class CommandExecutionListener implements IExecutionListener {
......
......@@ -159,6 +159,9 @@ public class ProgressEditorPart extends EditorPart {
// Close editor
DBeaverUI.asyncExec(() ->
entityEditor.getSite().getWorkbenchWindow().getActivePage().closeEditor(entityEditor, false));
} else {
// Activate entity editor (we have changed inner editors and need to force contexts activation).
DBeaverUI.asyncExec(() -> DBeaverUI.getInstance().refreshPartContexts(entityEditor));
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册