summaryrefslogtreecommitdiff
path: root/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/StructuralSearchAction.java
blob: fdfccb951361529e463d5058e3f9dd263f5d1615 (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
46
47
48
49
package com.intellij.structuralsearch.plugin;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.structuralsearch.plugin.ui.Configuration;
import com.intellij.structuralsearch.plugin.ui.SearchContext;
import com.intellij.structuralsearch.plugin.ui.SearchDialog;

public class StructuralSearchAction extends AnAction {

  /** Handles IDEA action event
   * @param event the event of action
   */
  public void actionPerformed(AnActionEvent event) {
    triggerAction(null, SearchContext.buildFromDataContext(event.getDataContext()));
  }

  public static void triggerAction(Configuration config, SearchContext searchContext) {
    //StructuralSearchPlugin.getInstance(searchContext.getProject());
    final SearchDialog searchDialog = new SearchDialog(searchContext);

    if (config!=null) {
      searchDialog.setUseLastConfiguration(true);
      searchDialog.setValuesFromConfig(config);
    }

    searchDialog.show();
  }

  /** Updates the state of the action
   * @param event the action event
   */
  public void update(AnActionEvent event) {
    final Presentation presentation = event.getPresentation();
    final DataContext context = event.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(context);
    final StructuralSearchPlugin plugin = project==null ? null:StructuralSearchPlugin.getInstance( project );

    if (plugin == null || plugin.isSearchInProgress() || plugin.isDialogVisible()) {
      presentation.setEnabled( false );
    } else {
      presentation.setEnabled( true );
    }

    super.update(event);
  }

}