当前位置: 首页>>代码示例>>Java>>正文


Java DataContext类代码示例

本文整理汇总了Java中com.intellij.openapi.actionSystem.DataContext的典型用法代码示例。如果您正苦于以下问题:Java DataContext类的具体用法?Java DataContext怎么用?Java DataContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataContext类属于com.intellij.openapi.actionSystem包,在下文中一共展示了DataContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isRenamingHandlerWithValidName

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
private boolean isRenamingHandlerWithValidName(@NotNull String name, Project project) {
  PsiElement elementToRename;
  String oldName;
  Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
  if (editor != null) {
    DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
    elementToRename = PsiElementRenameHandler.getElement(dataContext);
    if (elementToRename instanceof AppleScriptHandler) {
      oldName = ((AppleScriptHandler) elementToRename).getName();
      final String[] newParts = name.split(":");
      final String[] oldParts = oldName != null ? oldName.split(":") : null;
      if (oldParts == null || oldParts.length != newParts.length) {
        return false;
      }
      for (String part : newParts) {
        if (!isIdentifier(part)) {
          return false;
        }
      }
      return true;
    } else
      return false;
  } else
    return false;
}
 
开发者ID:ant-druha,项目名称:AppleScript-IDEA,代码行数:26,代码来源:AppleScriptNamesValidator.java

示例2: doExecute

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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();
    }
}
 
开发者ID:Jamling,项目名称:SmartQQ4IntelliJ,代码行数:21,代码来源:ReviewHandler.java

示例3: getExtensionDirectory

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
public static PsiDirectory getExtensionDirectory(@NotNull AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    if (project == null) {
        return null;
    }

    DataContext dataContext = event.getDataContext();
    IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (view == null) {
        return null;
    }

    PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return null;
    }

    return FilesystemUtil.findParentExtensionDirectory(directories[0]);
}
 
开发者ID:cedricziel,项目名称:idea-php-typo3-plugin,代码行数:20,代码来源:ExtensionUtility.java

示例4: execute

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:24,代码来源:ClosingTagHandler.java

示例5: preprocessEnter

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
@Override
public Result preprocessEnter(
    @NotNull PsiFile psiFile,
    @NotNull Editor editor,
    @NotNull Ref<Integer> caretOffset,
    @NotNull Ref<Integer> caretOffsetChange,
    @NotNull DataContext dataContext,
    @Nullable EditorActionHandler originalHandler) {
  if (psiFile instanceof SoyFile && isBetweenSiblingTags(psiFile, caretOffset.get())) {
    if (originalHandler != null) {
      originalHandler.execute(editor, dataContext);
    }
    return Result.Default;
  }
  return Result.Continue;
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:17,代码来源:EnterHandler.java

示例6: postProcessEnter

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
@Override
public Result postProcessEnter(
    @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
  if (file.getFileType() != SoyFileType.INSTANCE) {
    return Result.Continue;
  }

  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(caretOffset);
  Document document = editor.getDocument();

  int lineNumber = document.getLineNumber(caretOffset) - 1;
  int lineStartOffset = document.getLineStartOffset(lineNumber);
  String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));

  if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
    handleEnterInComment(element, file, editor);
  } else if (lineTextBeforeCaret.startsWith("/*")) {
    insertText(file, editor, " * \n ", 3);
  }

  return Result.Continue;
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:24,代码来源:EnterHandler.java

示例7: beforeEditorTyping

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
@Override
public void beforeEditorTyping(char c, DataContext dataContext) {
    Instant now = Instant.now();
    Duration between = Duration.between(lastInputTime, now);
    lastInputTime = now;

    if (between.getSeconds() < comboCoolTimeSec) {
        comboCount++;
    } else {
        comboCount = 0;
        return;
    }

    RihoReactionNotifier publisher = project.getMessageBus().syncPublisher(RihoReactionNotifier.REACTION_NOTIFIER);
    switch (comboCount) {
        case 5: publisher.reaction(Reaction.of(FacePattern.SMILE1, Duration.ofSeconds(3))); break;
        case 10: publisher.reaction(Reaction.of(FacePattern.SMILE2, Duration.ofSeconds(3))); break;
        case 15: publisher.reaction(Reaction.of(FacePattern.SURPRISE, Duration.ofSeconds(5))); break;
        case 20:
        case 30: publisher.reaction(Reaction.of(FacePattern.AWAWA, Duration.ofSeconds(3))); break;
    }
}
 
开发者ID:orekyuu,项目名称:Riho,代码行数:23,代码来源:IdeActionListener.java

示例8: update

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:24,代码来源:CCDeleteAllAnswerPlaceholdersAction.java

示例9: actionPerformed

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:CCNewSubtaskAction.java

示例10: update

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:CCNewSubtaskAction.java

示例11: invoke

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
  assert element != null;
  PsiDirectory directory = (PsiDirectory)element;
  Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  rename(project, course, directory);
  ProjectView.getInstance(project).refresh();
  FileEditorManagerEx managerEx = FileEditorManagerEx.getInstanceEx(project);
  for (VirtualFile virtualFile : managerEx.getOpenFiles()) {
    managerEx.updateFilePresentation(virtualFile);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:CCRenameHandler.java

示例12: canMove

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:19,代码来源:CCLessonMoveHandlerDelegate.java

示例13: canMove

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:CCTaskMoveHandlerDelegate.java

示例14: isAvailable

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的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;
}
 
开发者ID:uber,项目名称:RIBs,代码行数:32,代码来源:GenerateAction.java

示例15: actionPerformed

import com.intellij.openapi.actionSystem.DataContext; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  List<String> fileNames = findTestDataFiles(dataContext);
  if (fileNames == null || fileNames.isEmpty()) {
    String testData = guessTestData(dataContext);
    if (testData == null) {
      String message = "Cannot find testdata files for class";
      final Notification notification = new Notification("testdata", "Found no testdata files", message, NotificationType.INFORMATION);
      Notifications.Bus.notify(notification, project);
      return;
    }
    fileNames = Collections.singletonList(testData);
  }

  final Editor editor = e.getData(CommonDataKeys.EDITOR);
  final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
  final RelativePoint point = editor != null ? popupFactory.guessBestPopupLocation(editor) : popupFactory.guessBestPopupLocation(dataContext);

  TestDataNavigationHandler.navigate(point, fileNames, project);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:NavigateToTestDataAction.java


注:本文中的com.intellij.openapi.actionSystem.DataContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。