Search in sources :

Example 1 with DataManagerImpl

use of com.intellij.ide.impl.DataManagerImpl in project intellij-community by JetBrains.

the class ModuleRule method getData.

@Override
public Object getData(DataProvider dataProvider) {
    Object moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataProvider);
    if (moduleContext != null) {
        return moduleContext;
    }
    Project project = CommonDataKeys.PROJECT.getData(dataProvider);
    if (project == null) {
        PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
        if (element == null) {
            PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider);
            if (psiElements != null && psiElements.length > 0) {
                element = psiElements[0];
            }
        }
        if (element == null || !element.isValid())
            return null;
        project = element.getProject();
    }
    VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataProvider);
    if (files == null) {
        GetDataRule dataRule = ((DataManagerImpl) DataManager.getInstance()).getDataRule(CommonDataKeys.VIRTUAL_FILE_ARRAY.getName());
        if (dataRule != null) {
            files = (VirtualFile[]) dataRule.getData(dataProvider);
        }
    }
    if (files == null) {
        return null;
    }
    Module singleModule = null;
    for (VirtualFile file : files) {
        Module module = ModuleUtilCore.findModuleForFile(file, project);
        if (module == null) {
            return null;
        }
        if (singleModule == null) {
            singleModule = module;
        } else if (module != singleModule) {
            return null;
        }
    }
    return singleModule;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) DataManagerImpl(com.intellij.ide.impl.DataManagerImpl)

Example 2 with DataManagerImpl

use of com.intellij.ide.impl.DataManagerImpl in project intellij-community by JetBrains.

the class IdeMenuBar method updateMenuActions.

void updateMenuActions() {
    myNewVisibleActions.clear();
    if (!myDisabled) {
        DataContext dataContext = ((DataManagerImpl) myDataManager).getDataContextTest(this);
        expandActionGroup(dataContext, myNewVisibleActions, myActionManager);
    }
    if (!myNewVisibleActions.equals(myVisibleActions)) {
        // should rebuild UI
        final boolean changeBarVisibility = myNewVisibleActions.isEmpty() || myVisibleActions.isEmpty();
        final List<AnAction> temp = myVisibleActions;
        myVisibleActions = myNewVisibleActions;
        myNewVisibleActions = temp;
        removeAll();
        final boolean enableMnemonics = !UISettings.getInstance().getDisableMnemonics();
        for (final AnAction action : myVisibleActions) {
            add(new ActionMenu(null, ActionPlaces.MAIN_MENU, (ActionGroup) action, myPresentationFactory, enableMnemonics, true));
        }
        fixMenuBackground();
        updateMnemonicsVisibility();
        if (myClockPanel != null) {
            add(myClockPanel);
            add(myButton);
        }
        validate();
        if (changeBarVisibility) {
            invalidate();
            final JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
            if (frame != null) {
                frame.validate();
            }
        }
    }
}
Also used : ActionMenu(com.intellij.openapi.actionSystem.impl.ActionMenu) DataManagerImpl(com.intellij.ide.impl.DataManagerImpl)

Aggregations

DataManagerImpl (com.intellij.ide.impl.DataManagerImpl)2 ActionMenu (com.intellij.openapi.actionSystem.impl.ActionMenu)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1