@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"));
    }
  }
Beispiel #2
0
 public void closeCurrentWindow(@NotNull DataContext context) {
   final FileEditorManagerEx fileEditorManager = getFileEditorManager(context);
   final EditorWindow window = fileEditorManager.getSplitters().getCurrentWindow();
   if (window != null) {
     window.closeAllExcept(null);
   }
 }
Beispiel #3
0
 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);
     }
   }
 }
 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);
     }
   }
 }
Beispiel #5
0
 @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;
 }
Beispiel #6
0
  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);
    }
  }
  @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);
  }
  @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;
    }
  }
 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());
 }