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));
}
}
}
}
}
Aggregations