[rdct] fix GTW-825[Loading-tasks-and-contexts-unavailable-in-ThinClient]: opening of popup was broken due to unsafe cast

GitOrigin-RevId: 5445381c9eb7d9549984a9a318f897db5b3ec705
This commit is contained in:
Alisa Afonina
2023-10-30 10:22:03 +00:00
committed by intellij-monorepo-bot
parent 4d48826561
commit c14512fda7
2 changed files with 39 additions and 31 deletions
@@ -110,13 +110,13 @@ public class SwitchTaskAction extends ComboBoxAction implements DumbAware {
DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
assert project != null;
ListPopupImpl popup = createPopup(dataContext, null, true);
ListPopup popup = createPopup(dataContext, null, true);
popup.showCenteredInCurrentWindow(project);
}
private static ListPopupImpl createPopup(@NotNull DataContext dataContext,
@Nullable Runnable onDispose,
boolean withTitle) {
private static ListPopup createPopup(@NotNull DataContext dataContext,
@Nullable Runnable onDispose,
boolean withTitle) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Ref<Boolean> shiftPressed = Ref.create(false);
List<TaskListItem> items = project == null ? Collections.emptyList() :
@@ -163,7 +163,7 @@ public class SwitchTaskAction extends ComboBoxAction implements DumbAware {
}
};
final ListPopupImpl popup = (ListPopupImpl)JBPopupFactory.getInstance().createListPopup(step);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
if (onDispose != null) {
Disposer.register(popup, new Disposable() {
@Override
@@ -176,23 +176,26 @@ public class SwitchTaskAction extends ComboBoxAction implements DumbAware {
return popup;
}
popup.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context"));
popup.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context"), SwingConstants.LEFT);
popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
var popupImpl = (popup instanceof ListPopupImpl) ? (ListPopupImpl)popup : null;
if (popupImpl == null) return popup;
//todo: RDCT-627
popupImpl.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
popup.setCaption(TaskBundle.message("popup.title.merge.with.current.context"));
}
});
popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
popupImpl.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
popup.setCaption(TaskBundle.message("popup.title.switch.to.task"));
}
});
popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
popupImpl.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
popup.handleSelect(true);
@@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.tasks.LocalTask;
@@ -129,29 +130,33 @@ public class LoadContextAction extends BaseTaskAction {
group.add(createItem(info, shiftPressed));
}
final ListPopupImpl popup = (ListPopupImpl)JBPopupFactory.getInstance()
ListPopup popup = JBPopupFactory.getInstance()
.createActionGroupPopup(TaskBundle.message("popup.title.load.context"), group, e.getDataContext(), false, null, MAX_ROW_COUNT);
popup.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context"));
popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
popup.setCaption(TaskBundle.message("popup.title.merge.with.current.context"));
}
});
popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
popup.setCaption(TaskBundle.message("popup.title.load.context"));
}
});
popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
popup.handleSelect(true);
}
});
var popupImpl = (popup instanceof ListPopupImpl) ? (ListPopupImpl)popup : null;
if (popupImpl != null) {
//todo: RDCT-627
popupImpl.setAdText(TaskBundle.message("popup.advertisement.press.shift.to.merge.with.current.context"));
popupImpl.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(true);
popup.setCaption(TaskBundle.message("popup.title.merge.with.current.context"));
}
});
popupImpl.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
shiftPressed.set(false);
popup.setCaption(TaskBundle.message("popup.title.load.context"));
}
});
popupImpl.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
popup.handleSelect(true);
}
});
}
popup.showCenteredInCurrentWindow(project);
}