summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/find/editorHeaderActions/SwitchToFind.java
blob: 7e4b555d264c6609c3b5339046f8a52c71305afc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.intellij.find.editorHeaderActions;

import com.intellij.find.EditorSearchComponent;
import com.intellij.find.FindModel;
import com.intellij.find.FindUtil;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.DumbAware;

/**
* Created by IntelliJ IDEA.
* User: zajac
* Date: 05.03.11
* Time: 10:57
* To change this template use File | Settings | File Templates.
*/
public class SwitchToFind extends EditorHeaderAction implements DumbAware {
  public SwitchToFind(EditorSearchComponent editorSearchComponent) {
    super(editorSearchComponent);
    AnAction findAction = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND);
    if (findAction != null) {
      registerCustomShortcutSet(findAction.getShortcutSet(), editorSearchComponent);
    }
  }

  @Override
  public void actionPerformed(AnActionEvent e) {
    if (KeymapUtil.isEmacsKeymap()) {
      // Emacs users are accustomed to the editor that executes 'find next' on subsequent pressing of shortcut that
      // activates 'incremental search'. Hence, we do the similar hack here for them.
      AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT);
      action.update(e);
      action.actionPerformed(e);
      return;
    }

    EditorSearchComponent component = getEditorSearchComponent();
    final FindModel findModel = component.getFindModel();
    FindUtil.configureFindModel(false, null, findModel, false);
    component.selectAllText();
  }
}