Search in sources :

Example 1 with ContentChooser

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

the class ShowMessageHistoryAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    CommitMessageI commitMessageI;
    final DataContext dc = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dc);
    final Refreshable panel = CheckinProjectPanel.PANEL_KEY.getData(dc);
    commitMessageI = (panel instanceof CommitMessageI) ? (CommitMessageI) panel : VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(dc);
    if (commitMessageI != null && project != null) {
        final VcsConfiguration configuration = VcsConfiguration.getInstance(project);
        if (!configuration.getRecentMessages().isEmpty()) {
            final ContentChooser<String> contentChooser = new ContentChooser<String>(project, VcsBundle.message("dialog.title.choose.commit.message.from.history"), false) {

                protected void removeContentAt(final String content) {
                    configuration.removeMessage(content);
                }

                protected String getStringRepresentationFor(final String content) {
                    return content;
                }

                protected List<String> getContents() {
                    final List<String> recentMessages = configuration.getRecentMessages();
                    Collections.reverse(recentMessages);
                    return recentMessages;
                }
            };
            if (contentChooser.showAndGet()) {
                final int selectedIndex = contentChooser.getSelectedIndex();
                if (selectedIndex >= 0) {
                    commitMessageI.setCommitMessage(contentChooser.getAllContents().get(selectedIndex));
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ContentChooser(com.intellij.openapi.editor.actions.ContentChooser) Refreshable(com.intellij.openapi.vcs.ui.Refreshable)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)1 ContentChooser (com.intellij.openapi.editor.actions.ContentChooser)1 Project (com.intellij.openapi.project.Project)1 Refreshable (com.intellij.openapi.vcs.ui.Refreshable)1