コード例 #1
0
  @Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);

    Presentation presentation = e.getPresentation();
    DataContext context = e.getDataContext();
    EditorWindow window = getEditorWindow(context);
    if (window == null || window.getOwner().isPreview()) {
      presentation.setEnabledAndVisible(false);
    } else {
      if (getFile(context) != null) {
        presentation.setEnabledAndVisible(true);
      } else {
        Content content = getContent(context);
        presentation.setEnabledAndVisible(content != null && content.isPinnable());
      }
    }

    if (ActionPlaces.EDITOR_TAB_POPUP.equals(e.getPlace())
        || ViewContext.CELL_POPUP_PLACE.equals(e.getPlace())) {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.tab")
              : IdeBundle.message("action.pin.tab"));
    } else {
      presentation.setText(
          isSelected(e)
              ? IdeBundle.message("action.unpin.active.tab")
              : IdeBundle.message("action.pin.active.tab"));
    }
  }
コード例 #2
0
ファイル: WindowGroup.java プロジェクト: liyu123/ideavim
 public void closeCurrentWindow(@NotNull DataContext context) {
   final FileEditorManagerEx fileEditorManager = getFileEditorManager(context);
   final EditorWindow window = fileEditorManager.getSplitters().getCurrentWindow();
   if (window != null) {
     window.closeAllExcept(null);
   }
 }
コード例 #3
0
ファイル: WindowGroup.java プロジェクト: liyu123/ideavim
 public void closeAllExceptCurrent(@NotNull DataContext context) {
   final FileEditorManagerEx fileEditorManager = getFileEditorManager(context);
   final EditorWindow current = fileEditorManager.getCurrentWindow();
   for (final EditorWindow window : fileEditorManager.getWindows()) {
     if (window != current) {
       window.closeAllExcept(null);
     }
   }
 }
コード例 #4
0
 private void closeEditor() {
   boolean unsplit = false;
   if (mySplittedWindow != null && !mySplittedWindow.isDisposed()) {
     final EditorWithProviderComposite[] editors = mySplittedWindow.getEditors();
     if (editors.length == 1 && Comparing.equal(editors[0].getFile(), myNewVirtualFile)) {
       unsplit = true;
     }
   }
   FileEditorManager.getInstance(myProject).closeFile(myNewVirtualFile);
   if (unsplit) {
     for (EditorWindow editorWindow : mySplittedWindow.findSiblings()) {
       editorWindow.unsplit(true);
     }
   }
 }
コード例 #5
0
ファイル: WindowGroup.java プロジェクト: liyu123/ideavim
 @Nullable
 private static Rectangle getEditorWindowRectangle(@NotNull EditorWindow window) {
   final EditorWithProviderComposite editor = window.getSelectedEditor();
   if (editor != null) {
     final Point point = editor.getComponent().getLocationOnScreen();
     final Dimension dimension = editor.getComponent().getSize();
     return new Rectangle(point, dimension);
   }
   return null;
 }
コード例 #6
0
ファイル: WindowGroup.java プロジェクト: liyu123/ideavim
  private void splitWindow(
      int orientation, @NotNull DataContext context, @NotNull String filename) {
    final Project project = PlatformDataKeys.PROJECT.getData(context);
    final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);

    VirtualFile virtualFile = null;
    if (filename.length() > 0 && project != null) {
      virtualFile = VimPlugin.getFile().findFile(filename, project);
      if (virtualFile == null) {
        VimPlugin.showMessage("Could not find file: " + filename);
        return;
      }
    }

    final EditorWindow editorWindow = fileEditorManager.getSplitters().getCurrentWindow();
    if (editorWindow != null) {
      editorWindow.split(orientation, true, virtualFile, true);
    }
  }
コード例 #7
0
  @Override
  public void setSelected(AnActionEvent e, boolean state) {
    DataContext context = e.getDataContext();
    VirtualFile file = getFile(context);
    if (file != null) {
      // 1. Check editor
      EditorWindow editorWindow = getEditorWindow(context);
      if (editorWindow != null) {
        if (!editorWindow.isFileOpen(file)) {
          file = editorWindow.getSelectedFile();
          if (file == null) return;
        }

        editorWindow.setFilePinned(file, state);
        return;
      }
    }
    Content content = getContent(context); // at this point content cannot be null
    assert content != null : context;
    content.setPinned(state);
  }
コード例 #8
0
  @Override
  public boolean isSelected(AnActionEvent e) {
    DataContext context = e.getDataContext();
    VirtualFile file = getFile(context);
    if (file != null) {
      // 1. Check editor
      EditorWindow editorWindow = getEditorWindow(context);
      if (editorWindow != null) {
        if (!editorWindow.isFileOpen(file)) {
          file = editorWindow.getSelectedFile();
          if (file == null) return false;
        }

        return editorWindow.isFilePinned(file);
      }
    }
    // 2. Check content
    final Content content = getContent(context);
    if (content != null) {
      return content.isPinned();
    } else {
      return false;
    }
  }
コード例 #9
0
 public void navigate(int injectedOffset) {
   if (myAction.isShowInBalloon()) {
     final JComponent component = myAction.createBalloonComponent(myNewFile);
     if (component != null) {
       final Balloon balloon =
           JBPopupFactory.getInstance()
               .createBalloonBuilder(component)
               .setShadow(true)
               .setAnimationCycle(0)
               .setHideOnClickOutside(true)
               .setHideOnKeyOutside(true)
               .setHideOnAction(false)
               .setFillColor(UIUtil.getControlColor())
               .createBalloon();
       new AnAction() {
         @Override
         public void actionPerformed(AnActionEvent e) {
           balloon.hide();
         }
       }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component);
       Disposer.register(myNewFile.getProject(), balloon);
       final Balloon.Position position = QuickEditAction.getBalloonPosition(myEditor);
       RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor);
       if (position == Balloon.Position.above) {
         final Point p = point.getPoint();
         point =
             new RelativePoint(
                 point.getComponent(), new Point(p.x, p.y - myEditor.getLineHeight()));
       }
       balloon.show(point, position);
     }
   } else {
     final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject);
     final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile);
     if (editors.length == 0) {
       final EditorWindow curWindow = fileEditorManager.getCurrentWindow();
       mySplittedWindow =
           curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true);
     }
     Editor editor =
         fileEditorManager.openTextEditor(
             new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true);
     // fold missing values
     if (editor != null) {
       editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this);
       final FoldingModel foldingModel = editor.getFoldingModel();
       foldingModel.runBatchFoldingOperation(
           () -> {
             for (RangeMarker o :
                 ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) {
               String replacement = o.getUserData(REPLACEMENT_KEY);
               if (StringUtil.isEmpty(replacement)) continue;
               FoldRegion region =
                   foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(), replacement);
               if (region != null) region.setExpanded(false);
             }
           });
     }
     SwingUtilities.invokeLater(
         () -> myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE));
   }
 }
 protected boolean isFileToClose(final EditorComposite editor, final EditorWindow window) {
   return !window.getManager().isChanged(editor) && !window.isFilePinned(editor.getFile());
 }