use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class QuickDocOnMouseOverManager method closeQuickDocIfPossible.
private void closeQuickDocIfPossible() {
myAlarm.cancelAllRequests();
DocumentationManager docManager = getDocManager();
if (docManager == null) {
return;
}
JBPopup hint = docManager.getDocInfoHint();
if (hint == null) {
return;
}
hint.cancel();
myDocumentationManager = null;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class QuickDocUtil method getActiveDocComponent.
@Nullable
public static DocumentationComponent getActiveDocComponent(@NotNull Project project) {
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
DocumentationComponent component;
JBPopup hint = documentationManager.getDocInfoHint();
if (hint != null) {
component = (DocumentationComponent) ((AbstractPopup) hint).getComponent();
} else if (documentationManager.hasActiveDockedDocWindow()) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION);
Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent();
component = selectedContent == null ? null : (DocumentationComponent) selectedContent.getComponent();
} else {
component = null;
}
return component;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class StopAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(project);
List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(dataContext);
if (isPlaceGlobal(e)) {
int todoSize = cancellableProcesses.size() + stoppableDescriptors.size();
if (todoSize == 1) {
if (!stoppableDescriptors.isEmpty()) {
ExecutionManagerImpl.stopProcess(stoppableDescriptors.get(0));
} else {
cancellableProcesses.get(0).second.cancel();
}
return;
}
Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(cancellableProcesses, stoppableDescriptors, getRecentlyStartedContentDescriptor(dataContext));
if (handlerItems == null || handlerItems.first.isEmpty()) {
return;
}
final JBList list = new JBList(handlerItems.first);
if (handlerItems.second != null)
list.setSelectedValue(handlerItems.second, true);
list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() {
@Nullable
@Override
public String getTextFor(Object value) {
return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
}
@Nullable
@Override
public Icon getIconFor(Object value) {
return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
}
@Override
public boolean hasSeparatorAboveOf(Object value) {
return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
}
}));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setMovable(true).setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process").setFilteringEnabled(o -> ((HandlerItem) o).displayName).setItemChoosenCallback(() -> {
List valuesList = list.getSelectedValuesList();
for (Object o : valuesList) {
if (o instanceof HandlerItem)
((HandlerItem) o).stop();
}
}).setRequestFocus(true).createPopup();
InputEvent inputEvent = e.getInputEvent();
Component component = inputEvent != null ? inputEvent.getComponent() : null;
if (component != null && ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace())) {
popup.showUnderneathOf(component);
} else if (project == null) {
popup.showInBestPositionFor(dataContext);
} else {
popup.showCenteredInCurrentWindow(project);
}
} else {
ExecutionManagerImpl.stopProcess(getRecentlyStartedContentDescriptor(dataContext));
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class StudyEditInputAction method showInput.
public void showInput(final Project project) {
final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
if (selectedEditor != null) {
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
assert openedFile != null;
TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
assert taskFile != null;
final Task currentTask = taskFile.getTask();
tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
tabbedPane.addListener(new TabsListener.Adapter() {
@Override
public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
if (newSelection.getIcon() != null) {
int tabCount = tabbedPane.getTabCount();
VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
assert testsDir != null;
UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
userTest.setEditable(true);
StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
myEditableTabs.put(testTab, userTest);
tabbedPane.addTabSilently(testTab, tabCount - 1);
tabbedPane.select(testTab, true);
}
}
});
List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
int i = 1;
for (UserTest userTest : userTests) {
String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
myContentPanel.addInputContent(inputFileText);
myContentPanel.addOutputContent(outputFileText);
TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
tabbedPane.addTabSilently(testTab, i - 1);
if (userTest.isEditable()) {
myEditableTabs.put(testTab, userTest);
}
i++;
}
TabInfo plusTab = new TabInfo(new JPanel());
plusTab.setIcon(PlatformIcons.ADD_ICON);
tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
assert selectedStudyEditor != null;
hint.showInCenterOf(selectedStudyEditor.getComponent());
hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ShowCoveringTestsAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final DataContext context = e.getDataContext();
final Project project = e.getProject();
LOG.assertTrue(project != null);
final Editor editor = e.getData(CommonDataKeys.EDITOR);
LOG.assertTrue(editor != null);
final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
LOG.assertTrue(currentSuite != null);
final File[] traceFiles = getTraceFiles(project);
final Set<String> tests = new HashSet<>();
Runnable runnable = () -> {
for (File traceFile : traceFiles) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(traceFile));
extractTests(traceFile, in, tests);
} catch (Exception ex) {
LOG.error(traceFile.getName(), ex);
} finally {
try {
in.close();
} catch (IOException ex) {
LOG.error(ex);
}
}
}
};
if (ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Extract information about tests", false, project)) {
//todo cache them? show nothing found message
final String[] testNames = ArrayUtil.toStringArray(tests);
Arrays.sort(testNames);
if (testNames.length == 0) {
HintManager.getInstance().showErrorHint(editor, "Failed to load covered tests");
return;
}
final List<PsiElement> elements = currentSuite.getCoverageEngine().findTestsByNames(testNames, project);
final ImplementationViewComponent component;
final String title = "Tests covering line " + myClassFQName + ":" + myLineData.getLineNumber();
final ComponentPopupBuilder popupBuilder;
if (!elements.isEmpty()) {
component = new ImplementationViewComponent(PsiUtilCore.toPsiElementArray(elements), 0);
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setDimensionServiceKey(project, "ShowTestsPopup", false).setCouldPin(popup -> {
component.showInUsageView();
popup.cancel();
return false;
});
} else {
component = null;
final JPanel panel = new PanelWithText("Following test" + (testNames.length > 1 ? "s" : "") + " could not be found: " + StringUtil.join(testNames, "<br/>").replace("_", "."));
popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
}
final JBPopup popup = popupBuilder.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE).setProject(project).setResizable(true).setMovable(true).setTitle(title).createPopup();
popup.showInBestPositionFor(editor);
if (component != null) {
component.setHint(popup, title);
}
}
}
Aggregations