public void actionPerformed(AnActionEvent e) { final int modifiers = e.getModifiers(); final boolean forceOpenInNewFrame = (modifiers & InputEvent.CTRL_MASK) != 0 || (modifiers & InputEvent.SHIFT_MASK) != 0; Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); if (!new File(myProjectPath).exists()) { Messages.showErrorDialog( project, "The path " + FileUtil.toSystemDependentName(myProjectPath) + " does not exist.\n" + "If it is on a removable or network drive, please make sure that the drive is connected.", "Reopen Project"); return; } RecentProjectsManagerBase.getInstance() .doOpenProject(myProjectPath, project, forceOpenInNewFrame); }
public RecentProjectPanel() { super(new BorderLayout()); final AnAction[] recentProjectActions = RecentProjectsManagerBase.getInstance().getRecentProjectsActions(false); myList = new MyList(recentProjectActions); myList.setCellRenderer(new RecentProjectItemRenderer()); new ClickListener() { @Override public boolean onClick(MouseEvent event, int clickCount) { int selectedIndex = myList.getSelectedIndex(); if (selectedIndex >= 0) { if (myList.getCellBounds(selectedIndex, selectedIndex).contains(event.getPoint())) { Object selection = myList.getSelectedValue(); if (selection != null) { ((AnAction) selection) .actionPerformed( AnActionEvent.createFromInputEvent( (AnAction) selection, event, ActionPlaces.WELCOME_SCREEN)); } } } return true; } }.installOn(myList); myList.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selection = myList.getSelectedValue(); if (selection != null) { ((AnAction) selection) .actionPerformed( AnActionEvent.createFromInputEvent( (AnAction) selection, null, ActionPlaces.WELCOME_SCREEN)); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionListener deleteAction = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReopenProjectAction selection = (ReopenProjectAction) myList.getSelectedValue(); final int rc = Messages.showOkCancelDialog( RecentProjectPanel.this, "Remove '" + selection.getTemplatePresentation().getText() + "' from recent projects list?", "Remove Recent Project", Messages.getQuestionIcon()); if (rc == 0) { final RecentProjectsManagerBase manager = RecentProjectsManagerBase.getInstance(); manager.removePath(selection.getProjectPath()); ListUtil.removeSelectedItems(myList); } } }; myList.registerKeyboardAction( deleteAction, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); myList.registerKeyboardAction( deleteAction, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); myList.addMouseMotionListener( new MouseMotionAdapter() { boolean myIsEngaged = false; public void mouseMoved(MouseEvent e) { if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { Point point = e.getPoint(); int index = myList.locationToIndex(point); myList.setSelectedIndex(index); final Rectangle bounds = myList.getCellBounds(index, index); if (bounds != null && bounds.contains(point)) { myList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { myList.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } else { myIsEngaged = true; } } }); myList.setSelectedIndex(0); JBScrollPane scroll = new JBScrollPane(myList); scroll.setBorder(null); JComponent list = recentProjectActions.length == 0 ? myList : ListWithFilter.wrap( myList, scroll, new Function<Object, String>() { @Override public String fun(Object o) { ReopenProjectAction item = (ReopenProjectAction) o; String home = SystemProperties.getUserHome(); String path = item.getProjectPath(); if (FileUtil.startsWith(path, home)) { path = path.substring(home.length()); } return item.getProjectName() + " " + path; } }); add(list, BorderLayout.CENTER); JPanel title = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 28); } }; title.setBorder(new BottomLineBorder()); JLabel titleLabel = new JLabel("Recent Projects"); title.add(titleLabel); titleLabel.setHorizontalAlignment(SwingConstants.CENTER); titleLabel.setForeground(WelcomeScreenColors.CAPTION_FOREGROUND); title.setBackground(WelcomeScreenColors.CAPTION_BACKGROUND); add(title, BorderLayout.NORTH); setBorder(new LineBorder(WelcomeScreenColors.BORDER_COLOR)); }