本文整理汇总了Java中com.intellij.openapi.actionSystem.CommonDataKeys类的典型用法代码示例。如果您正苦于以下问题:Java CommonDataKeys类的具体用法?Java CommonDataKeys怎么用?Java CommonDataKeys使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonDataKeys类属于com.intellij.openapi.actionSystem包,在下文中一共展示了CommonDataKeys类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doExecute
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
super.doExecute(editor, caret, dataContext);
VirtualFile vf = (CommonDataKeys.VIRTUAL_FILE.getData(dataContext));
if (IMWindowFactory.getDefault() == null) {
return;
}
String path = VFSUtils.getPath(vf);
if (!TextUtils.isEmpty(path)) {
String text = editor.getSelectionModel().getSelectedText();
int line = EditorUtils.getEditorLine(editor);
ReviewDialog dialog = new ReviewDialog();
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setData(path, line, text);
dialog.setVisible(true);
dialog.dispose();
}
}
示例2: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
this.project = e.getData(CommonDataKeys.PROJECT);
String description = this.showInputDialog(SlackChannel.getIdDescription(), null);
if (!isValidField(description)) {
errorMessage();
return;
}
String token = this.showInputDialog(SlackChannel.getTokenDescription(), null);
if (!isValidField(token)) {
errorMessage();
return;
}
String channel = this.showInputDialog(SlackChannel.getChanneNameDescription(), "");
SlackStorage.getInstance().registerChannel(new SlackChannel(token, description, channel));
Messages.showMessageDialog(this.project, "Settings Saved.", "Information", Messages.getInformationIcon());
}
示例3: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event) {
// TODO: insert action logic here
Project project = event.getData(PlatformDataKeys.PROJECT);
Object nav = event.getData(CommonDataKeys.NAVIGATABLE);
String path;
try {
if (nav instanceof PsiDirectory) {
PsiDirectory directory = (PsiDirectory) nav;
path = directory.getVirtualFile().getPath();
} else {
PsiFile file = (PsiFile) nav;
path = file.getVirtualFile().getPath();
}
Toast.make(project, MessageType.INFO, "Open: " + path);
Runtime.getRuntime().exec("cmd /c start " + path);
} catch (Exception e) {
e.printStackTrace();
if (nav instanceof PsiClass) {
Toast.make(project, MessageType.ERROR, "Could not open the java file, double-click to open.");
return;
}
Toast.make(project, MessageType.ERROR, e.getMessage());
}
}
示例4: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
/**
* Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
*
* @param event the performed action
*/
@Override
public final void actionPerformed(final AnActionEvent event) {
final Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
final Project project = event.getData(CommonDataKeys.PROJECT);
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
final int start = caret.getSelectionStart();
final int end = caret.getSelectionEnd();
final String string = generateString();
final int newEnd = start + string.length();
document.replaceString(start, end, string);
caret.setSelection(start, newEnd);
});
WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}
示例5: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor != null) {
final SelectionModel selectionModel = editor.getSelectionModel();
final ImportImpexHttpClient client = new ImportImpexHttpClient();
final String selectedText = selectionModel.getSelectedText();
if (StringUtils.isNotEmpty(selectedText)) {
final HybrisHttpResult hybrisHttpResult = client.importImpex(selectedText);
ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
}
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:15,代码来源:ImportImpexAction.java
示例6: update
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setEnabledAndVisible(false);
Project project = e.getProject();
if (project == null) {
return;
}
if (!CCUtils.isCourseCreator(project)) {
return;
}
DataContext context = e.getDataContext();
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
if (file == null ) {
return;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, file);
if (taskFile == null || taskFile.getAnswerPlaceholders().isEmpty()) {
return;
}
presentation.setEnabledAndVisible(true);
}
示例7: getState
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Nullable
protected CCState getState(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null || !CCUtils.isCourseCreator(project)) {
return null;
}
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
if (psiFile == null) {
return null;
}
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) {
return null;
}
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
return null;
}
TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
if (taskFile == null) {
return null;
}
AnswerPlaceholder answerPlaceholder = StudyUtils.getAnswerPlaceholder(editor.getCaretModel().getOffset(), getPlaceholders(taskFile));
return new CCState(taskFile, answerPlaceholder, psiFile, editor, project);
}
示例8: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getData(CommonDataKeys.PROJECT);
if (view == null || project == null) {
return;
}
final String courseId = Messages.showInputDialog("Please, enter course id", "Get Course From Stepik", null);
if (StringUtil.isNotEmpty(courseId)) {
ProgressManager.getInstance().run(new Task.Modal(project, "Creating Course", true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
createCourse(project, courseId);
}
});
}
}
示例9: update
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void update(@NotNull AnActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setEnabledAndVisible(false);
Project project = e.getProject();
if (project == null) {
return;
}
if (!CCUtils.isCourseCreator(project)) {
return;
}
final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
if (file != null && StudyUtils.getTaskFile(project, file.getVirtualFile()) != null) {
presentation.setEnabledAndVisible(true);
}
}
示例10: getTask
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
private static TaskWithSubtasks getTask(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null || !CCUtils.isCourseCreator(project)) {
return null;
}
VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
if (virtualFile == null) {
return null;
}
while (virtualFile.getName().equals(EduNames.SRC) || !virtualFile.isDirectory()) {
VirtualFile parent = virtualFile.getParent();
if (parent != null) {
virtualFile = parent;
}
}
final Task task = StudyUtils.getTask(project, virtualFile);
return task instanceof TaskWithSubtasks ? (TaskWithSubtasks)task : null;
}
示例11: actionPerformed
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFile == null || project == null || editor == null) {
return;
}
Task task = StudyUtils.getTaskForFile(project, virtualFile);
if (task == null) return;
if (!(task instanceof TaskWithSubtasks)) {
task = convertToTaskWithSubtasks(task, project);
}
addSubtask((TaskWithSubtasks)task, project);
}
示例12: update
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public void update(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Presentation presentation = e.getPresentation();
presentation.setEnabledAndVisible(false);
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFile == null || project == null) {
return;
}
if (!CCUtils.isCourseCreator(project)) {
return;
}
if (StudyUtils.getTaskForFile(project, virtualFile) != null || StudyUtils.getTask(project, virtualFile) != null) {
presentation.setEnabledAndVisible(true);
}
}
示例13: canMove
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public boolean canMove(DataContext dataContext) {
if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) {
return false;
}
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null) {
return false;
}
final PsiDirectory[] directories = view.getDirectories();
if (directories.length == 0 || directories.length > 1) {
return false;
}
final PsiDirectory sourceDirectory = directories[0];
return CCUtils.isLessonDir(sourceDirectory);
}
示例14: canMove
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
@Override
public boolean canMove(DataContext dataContext) {
if (CommonDataKeys.PSI_FILE.getData(dataContext) != null) {
return false;
}
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null) {
return false;
}
final PsiDirectory[] directories = view.getDirectories();
if (directories.length == 0 || directories.length > 1) {
return false;
}
final PsiDirectory sourceDirectory = directories[0];
return isTaskDir(sourceDirectory);
}
示例15: isAvailable
import com.intellij.openapi.actionSystem.CommonDataKeys; //导入依赖的package包/类
/**
* Checked whether or not this action can be enabled.
*
* <p>Requirements to be enabled: * User must be in a Java source folder.
*
* @param dataContext to figure out where the user is.
* @return {@code true} when the action is available, {@code false} when the action is not
* available.
*/
private boolean isAvailable(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return false;
}
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null || view.getDirectories().length == 0) {
return false;
}
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiDirectory dir : view.getDirectories()) {
if (projectFileIndex.isUnderSourceRootOfType(
dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES)
&& checkPackageExists(dir)) {
return true;
}
}
return false;
}