Search in sources :

Example 1 with HectorComponentPanel

use of com.intellij.openapi.editor.HectorComponentPanel in project intellij-community by JetBrains.

the class HectorComponent method isModified.

private boolean isModified() {
    final FileViewProvider viewProvider = myFile.getViewProvider();
    for (Language language : mySliders.keySet()) {
        JSlider slider = mySliders.get(language);
        final PsiFile root = viewProvider.getPsi(language);
        HighlightingLevelManager highlightingLevelManager = HighlightingLevelManager.getInstance(myFile.getProject());
        if (root != null && getValue(highlightingLevelManager.shouldHighlight(root), highlightingLevelManager.shouldInspect(root)) != slider.getValue()) {
            return true;
        }
    }
    for (HectorComponentPanel panel : myAdditionalPanels) {
        if (panel.isModified()) {
            return true;
        }
    }
    return false;
}
Also used : HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) PsiFile(com.intellij.psi.PsiFile)

Example 2 with HectorComponentPanel

use of com.intellij.openapi.editor.HectorComponentPanel in project intellij-community by JetBrains.

the class ImportPopupHectorComponentProvider method createConfigurable.

@Override
public HectorComponentPanel createConfigurable(@NotNull final PsiFile file) {
    final Project project = file.getProject();
    final DaemonCodeAnalyzer analyzer = DaemonCodeAnalyzer.getInstance(project);
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final VirtualFile virtualFile = file.getVirtualFile();
    assert virtualFile != null;
    final boolean notInLibrary = !fileIndex.isInLibrarySource(virtualFile) && !fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInContent(virtualFile);
    return new HectorComponentPanel() {

        private JCheckBox myImportPopupCheckBox = new JCheckBox(EditorBundle.message("hector.import.popup.checkbox"));

        @Override
        public JComponent createComponent() {
            DialogUtil.registerMnemonic(myImportPopupCheckBox);
            return myImportPopupCheckBox;
        }

        @Override
        public boolean isModified() {
            return myImportPopupCheckBox.isSelected() != analyzer.isImportHintsEnabled(file);
        }

        @Override
        public void apply() throws ConfigurationException {
            analyzer.setImportHintsEnabled(file, myImportPopupCheckBox.isSelected());
        }

        @Override
        public void reset() {
            myImportPopupCheckBox.setSelected(analyzer.isImportHintsEnabled(file));
            myImportPopupCheckBox.setEnabled(analyzer.isAutohintsAvailable(file));
            myImportPopupCheckBox.setVisible(notInLibrary);
        }

        @Override
        public void disposeUIResources() {
            myImportPopupCheckBox = null;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)

Example 3 with HectorComponentPanel

use of com.intellij.openapi.editor.HectorComponentPanel in project intellij-community by JetBrains.

the class HectorComponent method onClose.

private void onClose() {
    if (isModified()) {
        for (HectorComponentPanel panel : myAdditionalPanels) {
            try {
                panel.apply();
            } catch (ConfigurationException e) {
            //shouldn't be
            }
        }
        forceDaemonRestart();
        DaemonListeners.getInstance(myFile.getProject()).updateStatusBar();
    }
}
Also used : HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 4 with HectorComponentPanel

use of com.intellij.openapi.editor.HectorComponentPanel in project intellij-community by JetBrains.

the class HectorComponent method showComponent.

public void showComponent(RelativePoint point) {
    final JBPopup hector = JBPopupFactory.getInstance().createComponentPopupBuilder(this, this).setRequestFocus(true).setMovable(true).setCancelCallback(() -> {
        for (HectorComponentPanel additionalPanel : myAdditionalPanels) {
            if (!additionalPanel.canClose()) {
                return Boolean.FALSE;
            }
        }
        onClose();
        return Boolean.TRUE;
    }).createPopup();
    Disposer.register(myFile.getProject(), new Disposable() {

        @Override
        public void dispose() {
            final JBPopup oldHector = getOldHector();
            if (oldHector != null && !oldHector.isDisposed()) {
                Disposer.dispose(oldHector);
            }
            Disposer.dispose(hector);
        }
    });
    final JBPopup oldHector = getOldHector();
    if (oldHector != null) {
        oldHector.cancel();
    } else {
        myHectorRef = new WeakReference<>(hector);
        hector.show(point);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) HectorComponentPanel(com.intellij.openapi.editor.HectorComponentPanel) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

HectorComponentPanel (com.intellij.openapi.editor.HectorComponentPanel)4 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 HighlightingLevelManager (com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager)1 Language (com.intellij.lang.Language)1 Disposable (com.intellij.openapi.Disposable)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileViewProvider (com.intellij.psi.FileViewProvider)1 PsiFile (com.intellij.psi.PsiFile)1