Example #1
0
  public boolean processExKey(Editor editor, @NotNull KeyStroke stroke, boolean charOnly) {
    // This will only get called if somehow the key focus ended up in the editor while the ex entry
    // window
    // is open. So I'll put focus back in the editor and process the key.

    ExEntryPanel panel = ExEntryPanel.getInstance();
    if (panel.isActive()) {
      panel.requestFocus();
      panel.handleKey(stroke);

      return true;
    } else {
      CommandState.getInstance(editor).popState();
      KeyHandler.getInstance().reset(editor);
      return false;
    }

    /*
    if (!charOnly || stroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED && ExEntryPanel.getInstance().isActive())
    {
        ExEntryPanel panel = ExEntryPanel.getInstance();
        panel.handleKey(stroke);

        return true;
    }
    else
    {
        return false;
    }
    */
  }
Example #2
0
  public void actionPerformed(@NotNull AnActionEvent event) {
    if (logger.isDebugEnabled()) {
      logger.debug("actionPerformed=" + event);
    }
    if (!VimPlugin.isEnabled()) {
      return;
    }

    if (event.getInputEvent() instanceof KeyEvent) {
      KeyEvent ke = (KeyEvent) event.getInputEvent();
      Editor editor = event.getData(PlatformDataKeys.EDITOR);
      if (editor != null) {
        KeyStroke key = KeyStroke.getKeyStrokeForEvent(ke);
        KeyHandler.getInstance().handleKey(editor, key, event.getDataContext());
      } else {
        if (ExEntryPanel.getInstance().isActive()) {
          KeyEvent e =
              new KeyEvent(
                  ke.getComponent(),
                  ke.getID(),
                  ke.getWhen(),
                  ke.getModifiers(),
                  ke.getKeyCode(),
                  ke.getKeyChar(),
                  ke.getKeyLocation());
          ExEntryPanel.getInstance().processKey(e);
        }
      }
    }
  }
Example #3
0
 public void startFilterCommand(
     @NotNull Editor editor, DataContext context, @NotNull Command cmd) {
   String initText = getRange(editor, cmd) + "!";
   CommandState.getInstance(editor)
       .pushState(
           CommandState.Mode.EX_ENTRY, CommandState.SubMode.NONE, KeyParser.MAPPING_CMD_LINE);
   ExEntryPanel panel = ExEntryPanel.getInstance();
   panel.activate(editor, context, ":", initText, 1);
 }
Example #4
0
  public void startExCommand(@NotNull Editor editor, DataContext context, @NotNull Command cmd) {
    if (editor.isOneLineMode()) // Don't allow ex commands in one line editors
    {
      return;
    }

    String initText = getRange(editor, cmd);
    CommandState.getInstance(editor)
        .pushState(
            CommandState.Mode.EX_ENTRY, CommandState.SubMode.NONE, KeyParser.MAPPING_CMD_LINE);
    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.activate(editor, context, ":", initText, 1);
  }
Example #5
0
  public void startSearchCommand(
      @NotNull Editor editor, DataContext context, int count, char leader) {
    if (editor.isOneLineMode()) // Don't allow searching in one line editors
    {
      return;
    }

    String initText = "";
    String label = "" + leader;

    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.activate(editor, context, label, initText, count);
  }
Example #6
0
  public String endSearchCommand(@NotNull final Editor editor, @NotNull DataContext context) {
    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.deactivate();

    final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            VirtualFile vf = EditorData.getVirtualFile(editor);
            if (!ApplicationManager.getApplication().isUnitTestMode() && vf != null) {
              FileEditorManager.getInstance(project)
                  .openFile(EditorData.getVirtualFile(editor), true);
            }
          }
        });

    record(editor, panel.getText());
    return panel.getText();
  }
Example #7
0
  public boolean cancelExEntry(@NotNull final Editor editor, @NotNull final DataContext context) {
    CommandState.getInstance(editor).popState();
    KeyHandler.getInstance().reset(editor);
    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.deactivate();
    final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            // editor.getContentComponent().requestFocus();
            VirtualFile vf = EditorData.getVirtualFile(editor);
            if (vf != null) {
              FileEditorManager.getInstance(project)
                  .openFile(EditorData.getVirtualFile(editor), true);
            }
          }
        });

    return true;
  }
Example #8
0
  public boolean processExEntry(@NotNull final Editor editor, @NotNull final DataContext context) {
    ExEntryPanel panel = ExEntryPanel.getInstance();
    panel.deactivate();
    boolean res = true;
    int flags = 0;
    try {
      CommandState.getInstance(editor).popState();
      logger.debug("processing command");
      final String text = panel.getText();
      record(editor, text);
      if (logger.isDebugEnabled()) logger.debug("swing=" + SwingUtilities.isEventDispatchThread());
      if (panel.getLabel().equals(":")) {
        flags = CommandParser.getInstance().processCommand(editor, context, text, 1);
        if (logger.isDebugEnabled()) logger.debug("flags=" + flags);
        if (CommandState.getInstance(editor).getMode() == CommandState.Mode.VISUAL) {
          CommandGroups.getInstance().getMotion().exitVisual(editor, true);
        }
      } else {
        int pos =
            CommandGroups.getInstance()
                .getSearch()
                .search(
                    editor,
                    text,
                    panel.getCount(),
                    panel.getLabel().equals("/")
                        ? Command.FLAG_SEARCH_FWD
                        : Command.FLAG_SEARCH_REV,
                    true);
        if (pos == -1) {
          res = false;
        }
      }
    } catch (ExException ex) {
      // VimPlugin.showMessage(ex.getMessage());
      ProcessGroup.logger.info(ex.getMessage());
      VimPlugin.indicateError();
      res = false;
    } catch (Exception bad) {
      ProcessGroup.logger.error(bad);
      VimPlugin.indicateError();
      res = false;
    } finally {
      final int flg = flags;
      final Project project = PlatformDataKeys.PROJECT.getData(context); // API change - don't merge
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              // editor.getContentComponent().requestFocus();
              // Reopening the file was the only way I could solve the focus problem introduced in
              // IDEA at
              // version 1050.
              if (!ApplicationManager.getApplication().isUnitTestMode()
                  && (flg & CommandParser.RES_DONT_REOPEN) == 0) {
                VirtualFile vf = EditorData.getVirtualFile(editor);
                if (vf != null) {
                  FileEditorManager.getInstance(project)
                      .openFile(EditorData.getVirtualFile(editor), true);
                }
              }

              // If the result of the ex command is to display the "more" panel, show it here.
              if ((flg & CommandParser.RES_MORE_PANEL) != 0
                  && MorePanel.getInstance(editor).hasText()) {
                RunnableHelper.runReadCommand(
                    project,
                    new Runnable() {
                      public void run() {
                        MorePanel.getInstance(editor).activate();
                      }
                    },
                    "ShowMorePanel",
                    "ExCommand");
              }
            }
          });
    }

    return res;
  }