mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Generify to support move to right and move to down actions
This commit is contained in:
@@ -18,38 +18,45 @@ package com.intellij.ide.actions;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.fileEditor.impl.EditorWindow;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
/**
|
||||
* @author Vladimir Kondratyev
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public abstract class SplitAction extends AnAction implements DumbAware {
|
||||
private final int myOrientation;
|
||||
private final boolean myCloseSource;
|
||||
|
||||
protected SplitAction(final int orientation){
|
||||
protected SplitAction(final int orientation) {
|
||||
this(orientation, false);
|
||||
}
|
||||
|
||||
protected SplitAction(final int orientation, boolean closeSource) {
|
||||
myOrientation = orientation;
|
||||
myCloseSource = closeSource;
|
||||
}
|
||||
|
||||
public void actionPerformed(final AnActionEvent event) {
|
||||
final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
|
||||
final Project project = event.getData(CommonDataKeys.PROJECT);
|
||||
final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
|
||||
final EditorWindow window = EditorWindow.DATA_KEY.getData(event.getDataContext());
|
||||
final EditorWindow window = event.getData(EditorWindow.DATA_KEY);
|
||||
final VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
|
||||
|
||||
fileEditorManager.createSplitter(myOrientation, window);
|
||||
|
||||
if (myCloseSource && window != null && file != null) {
|
||||
window.closeFile(file, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(final AnActionEvent event) {
|
||||
final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
|
||||
final Presentation presentation = event.getPresentation();
|
||||
if (project == null) {
|
||||
presentation.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
|
||||
presentation.setEnabled(fileEditorManager.hasOpenedFile ());
|
||||
final Project project = event.getData(CommonDataKeys.PROJECT);
|
||||
final boolean enabled = project != null && FileEditorManagerEx.getInstanceEx(project).hasOpenedFile();
|
||||
event.getPresentation().setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user