Search in sources :

Example 6 with ScopeChooserCombo

use of com.intellij.ide.util.scopeChooser.ScopeChooserCombo in project intellij-community by JetBrains.

the class FindPopupScopeUIImpl method initComponents.

public void initComponents() {
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    String[] names = new String[modules.length];
    for (int i = 0; i < modules.length; i++) {
        names[i] = modules[i].getName();
    }
    Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
    myModuleComboBox = new ComboBox<>(names);
    ActionListener restartSearchListener = e -> scheduleResultsUpdate();
    myModuleComboBox.addActionListener(restartSearchListener);
    myDirectoryChooser = new FindPopupDirectoryChooser(myFindPopupPanel);
    myScopeCombo = new ScopeChooserCombo();
    myScopeCombo.init(myProject, true, true, FindSettings.getInstance().getDefaultScopeName(), new Condition<ScopeDescriptor>() {

        final String projectFilesScopeName = PsiBundle.message("psi.search.scope.project");

        final String moduleFilesScopeName;

        {
            String moduleScopeName = PsiBundle.message("search.scope.module", "");
            final int ind = moduleScopeName.indexOf(' ');
            moduleFilesScopeName = moduleScopeName.substring(0, ind + 1);
        }

        @Override
        public boolean value(ScopeDescriptor descriptor) {
            final String display = descriptor.getDisplay();
            return !projectFilesScopeName.equals(display) && !display.startsWith(moduleFilesScopeName);
        }
    });
    myScopeCombo.setBrowseListener(new ScopeChooserCombo.BrowseListener() {

        private FindModel myModelSnapshot;

        @Override
        public void onBeforeBrowseStarted() {
            myModelSnapshot = myHelper.getModel();
            myFindPopupPanel.getCanClose().set(false);
        }

        @Override
        public void onAfterBrowseFinished() {
            if (myModelSnapshot != null) {
                SearchScope scope = myScopeCombo.getSelectedScope();
                if (scope != null) {
                    myModelSnapshot.setCustomScope(scope);
                }
                myFindPopupPanel.getCanClose().set(true);
            }
        }
    });
    myScopeCombo.getComboBox().addActionListener(restartSearchListener);
    Disposer.register(myFindPopupPanel.getDisposable(), myScopeCombo);
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) ActionListener(java.awt.event.ActionListener) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) ModuleManager(com.intellij.openapi.module.ModuleManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.find(com.intellij.find) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Disposer(com.intellij.openapi.util.Disposer) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) Condition(com.intellij.openapi.util.Condition) PsiBundle(com.intellij.psi.PsiBundle) javax.swing(javax.swing) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) ActionListener(java.awt.event.ActionListener) SearchScope(com.intellij.psi.search.SearchScope) Module(com.intellij.openapi.module.Module)

Example 7 with ScopeChooserCombo

use of com.intellij.ide.util.scopeChooser.ScopeChooserCombo in project intellij-community by JetBrains.

the class LayoutProjectCodeDialog method createUIComponents.

protected void createUIComponents() {
    myScopeCombo = new ScopeChooserCombo(myProject, false, false, FindSettings.getInstance().getDefaultScopeName());
    Disposer.register(myDisposable, myScopeCombo);
}
Also used : ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo)

Example 8 with ScopeChooserCombo

use of com.intellij.ide.util.scopeChooser.ScopeChooserCombo in project intellij-community by JetBrains.

the class SearchDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myContentPanel = new JPanel(new BorderLayout());
    myEditorPanel = createEditorContent();
    myContentPanel.add(BorderLayout.CENTER, myEditorPanel);
    myContentPanel.add(BorderLayout.SOUTH, Box.createVerticalStrut(8));
    JComponent centerPanel = new JPanel(new BorderLayout());
    {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(BorderLayout.CENTER, myContentPanel);
        panel.add(BorderLayout.SOUTH, createTemplateManagementButtons());
        centerPanel.add(BorderLayout.CENTER, panel);
    }
    JPanel optionsContent = new JPanel(new BorderLayout());
    centerPanel.add(BorderLayout.SOUTH, optionsContent);
    JPanel searchOptions = new JPanel();
    searchOptions.setLayout(new GridLayout(getRowsCount(), 1, 0, 0));
    searchOptions.setBorder(IdeBorderFactory.createTitledBorder(SSRBundle.message("ssdialog.options.group.border"), true));
    myScopeChooserCombo = new ScopeChooserCombo(searchContext.getProject(), true, false, FindSettings.getInstance().getDefaultScopeName());
    Disposer.register(myDisposable, myScopeChooserCombo);
    JPanel allOptions = new JPanel(new BorderLayout());
    if (myShowScopePanel) {
        JPanel scopePanel = new JPanel(new GridBagLayout());
        TitledSeparator separator = new TitledSeparator(SSRBundle.message("search.dialog.scope.label"), myScopeChooserCombo.getComboBox());
        scopePanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insetsTop(5), 0, 0));
        scopePanel.add(myScopeChooserCombo, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insetsLeft(10), 0, 0));
        allOptions.add(scopePanel, BorderLayout.SOUTH);
        myScopeChooserCombo.getComboBox().addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                initiateValidation();
            }
        });
    }
    buildOptions(searchOptions);
    allOptions.add(searchOptions, BorderLayout.CENTER);
    optionsContent.add(allOptions, BorderLayout.CENTER);
    if (myRunFindActionOnClose) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
        openInNewTab = new JCheckBox(FindBundle.message("find.open.in.new.tab.checkbox"));
        openInNewTab.setSelected(FindSettings.getInstance().isShowResultsInSeparateView());
        ToolWindow findWindow = ToolWindowManager.getInstance(searchContext.getProject()).getToolWindow(ToolWindowId.FIND);
        openInNewTab.setEnabled(findWindow != null && findWindow.isAvailable());
        panel.add(openInNewTab, BorderLayout.EAST);
        optionsContent.add(BorderLayout.SOUTH, panel);
    }
    updateEditor();
    return centerPanel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) ToolWindow(com.intellij.openapi.wm.ToolWindow) TitledSeparator(com.intellij.ui.TitledSeparator) ItemListener(java.awt.event.ItemListener)

Example 9 with ScopeChooserCombo

use of com.intellij.ide.util.scopeChooser.ScopeChooserCombo in project intellij-community by JetBrains.

the class ScopePanel method createUIComponents.

private void createUIComponents() {
    myRoot = this;
    myCustomScopeSelection = new ScopeChooserCombo();
}
Also used : ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo)

Example 10 with ScopeChooserCombo

use of com.intellij.ide.util.scopeChooser.ScopeChooserCombo in project intellij-community by JetBrains.

the class ScopePanel method initComponent.

public void initComponent(@Nullable Module currentModule, final SearchScope scope) {
    final ItemListener stateListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            myModuleSelection.setEnabled(myModuleScope.isSelected());
            myDirectory.setEnabled(myDirectoryScope.isSelected());
            myRecursive.setEnabled(myDirectoryScope.isSelected());
            myCustomScopeSelection.setEnabled(myCustomScope.isSelected());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                firePropertyChange("scope", null, getSelectedScope());
            }
        }
    };
    final ItemListener scopeListener = new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                firePropertyChange("scope", null, getSelectedScope());
            }
        }
    };
    myWholeProjectScope.addItemListener(stateListener);
    myWholeProjectScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.PROJECT);
    myModuleScope.addItemListener(stateListener);
    myModuleScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.MODULE);
    myDirectoryScope.addItemListener(stateListener);
    myDirectoryScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.DIRECTORY);
    myCustomScope.addItemListener(stateListener);
    myCustomScope.setSelected(scope.getScopeType() == SearchScope.ScopeType.CUSTOM);
    myModuleSelection.fillModules(myProject);
    Module m;
    if (scope.getModuleName() != null) {
        if ((m = ModuleManager.getInstance(myProject).findModuleByName(scope.getModuleName())) == null) {
            m = currentModule;
        }
    } else {
        m = currentModule;
    }
    if (m != null) {
        myModuleSelection.setSelectedModule(m);
    }
    myModuleSelection.addItemListener(scopeListener);
    ((ScopeChooserCombo) myCustomScopeSelection).init(myProject, true, true, scope.getScopeName());
    myCustomScopeSelection.getComboBox().addItemListener(scopeListener);
    myDirectory.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(DocumentEvent e) {
            firePropertyChange("scope", null, getSelectedScope());
        }
    });
    myDirectory.setText(scope.getPath());
    myDirectory.addBrowseFolderListener("Select Path", "Select Path", myProject, FileChooserDescriptorFactory.createSingleFolderDescriptor());
    myRecursive.setSelected(scope.isRecursive());
}
Also used : ItemEvent(java.awt.event.ItemEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) ItemListener(java.awt.event.ItemListener) ScopeChooserCombo(com.intellij.ide.util.scopeChooser.ScopeChooserCombo) Module(com.intellij.openapi.module.Module) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

ScopeChooserCombo (com.intellij.ide.util.scopeChooser.ScopeChooserCombo)10 Module (com.intellij.openapi.module.Module)3 Nullable (org.jetbrains.annotations.Nullable)3 com.intellij.find (com.intellij.find)2 ScopeDescriptor (com.intellij.ide.util.scopeChooser.ScopeDescriptor)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)2 Project (com.intellij.openapi.project.Project)2 Condition (com.intellij.openapi.util.Condition)2 Disposer (com.intellij.openapi.util.Disposer)2 Alarm (com.intellij.util.Alarm)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 CommonBundle (com.intellij.CommonBundle)1 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)1 Language (com.intellij.lang.Language)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1