mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
This commit is contained in:
@@ -12,6 +12,10 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
@@ -21,7 +25,9 @@ public final class VcsConfiguration implements JDOMExternalizable, ProjectCompon
|
||||
public boolean PUT_FOCUS_INTO_COMMENT = false;
|
||||
public boolean SHOW_CHECKIN_OPTIONS = true;
|
||||
public boolean FORCE_NON_EMPTY_COMMENT = false;
|
||||
public String LAST_COMMIT_MESSAGE = "";
|
||||
|
||||
private ArrayList<String> myLastCommitMessages = new ArrayList<String>();
|
||||
|
||||
public boolean SAVE_LAST_COMMIT_MESSAGE = true;
|
||||
public float CHECKIN_DIALOG_SPLITTER_PROPORTION = 0.8f;
|
||||
|
||||
@@ -40,6 +46,8 @@ public final class VcsConfiguration implements JDOMExternalizable, ProjectCompon
|
||||
public boolean SHOW_FILE_HISTORY_AS_TREE = false;
|
||||
public float FILE_HISTORY_SPLITTER_PROPORTION = 0.6f;
|
||||
public boolean SHOW_STATUS_OPTIONS = true;
|
||||
private static final int MAX_STORED_MESSAGES = 10;
|
||||
private static final String MESSAGE_ELEMENT_NAME = "MESSAGE";
|
||||
|
||||
public static VcsConfiguration createEmptyConfiguration(Project project) {
|
||||
return new VcsConfiguration(project);
|
||||
@@ -47,10 +55,20 @@ public final class VcsConfiguration implements JDOMExternalizable, ProjectCompon
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
final List messages = element.getChildren(MESSAGE_ELEMENT_NAME);
|
||||
for (Iterator iterator = messages.iterator(); iterator.hasNext();) {
|
||||
saveCommitMessage(((Element)iterator.next()).getText());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
for (Iterator<String> iterator = myLastCommitMessages.iterator(); iterator.hasNext();) {
|
||||
String message = iterator.next();
|
||||
final Element messageElement = new Element(MESSAGE_ELEMENT_NAME);
|
||||
messageElement.setText(message);
|
||||
element.addContent(messageElement);
|
||||
}
|
||||
}
|
||||
|
||||
public static VcsConfiguration getInstance(Project project) {
|
||||
@@ -93,4 +111,24 @@ public final class VcsConfiguration implements JDOMExternalizable, ProjectCompon
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveCommitMessage(final String comment) {
|
||||
while (myLastCommitMessages.size() >= MAX_STORED_MESSAGES) {
|
||||
myLastCommitMessages.remove(0);
|
||||
}
|
||||
myLastCommitMessages.add(comment);
|
||||
}
|
||||
|
||||
public String getLastCommitMessage() {
|
||||
if (myLastCommitMessages.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return myLastCommitMessages.get(myLastCommitMessages.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getRecentMessages() {
|
||||
return myLastCommitMessages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.intellij.openapi.vcs.ui;
|
||||
|
||||
import com.intellij.ui.ColoredListCellRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CommitMessage extends JPanel{
|
||||
|
||||
private final JTextArea myCommentArea = new JTextArea();
|
||||
private final JComboBox myRecentMessages = new JComboBox();
|
||||
|
||||
class RecentMessage {
|
||||
private final boolean canBeInserted;
|
||||
private final String myPresentation;
|
||||
private final String myValue;
|
||||
|
||||
public RecentMessage(final boolean canBeInserted, final String presentation, final String value) {
|
||||
this.canBeInserted = canBeInserted;
|
||||
myPresentation = presentation;
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public boolean isCanBeInserted() {
|
||||
return canBeInserted;
|
||||
}
|
||||
|
||||
public String getPresentation() {
|
||||
return myPresentation;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
}
|
||||
|
||||
public CommitMessage(ArrayList<String> recentMessages) {
|
||||
super(new BorderLayout());
|
||||
add(new JScrollPane(myCommentArea), BorderLayout.CENTER);
|
||||
add(new JLabel("Comment:"), BorderLayout.NORTH);
|
||||
if (!recentMessages.isEmpty()) {
|
||||
add(myRecentMessages, BorderLayout.SOUTH);
|
||||
|
||||
myRecentMessages.addItem(new RecentMessage(false, "<Recent messages>", null));
|
||||
|
||||
for (Iterator<String> iterator = recentMessages.iterator(); iterator.hasNext();) {
|
||||
String s = iterator.next();
|
||||
myRecentMessages.addItem(new RecentMessage(true, createPresentation(s), s));
|
||||
}
|
||||
|
||||
myRecentMessages.setRenderer(new ColoredListCellRenderer() {
|
||||
protected void customizeCellRenderer(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean selected,
|
||||
boolean hasFocus
|
||||
) {
|
||||
if (value instanceof RecentMessage) {
|
||||
append(((RecentMessage)value).getPresentation(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
myRecentMessages.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Object selectedItem = myRecentMessages.getSelectedItem();
|
||||
if (selectedItem instanceof RecentMessage && ((RecentMessage)selectedItem).canBeInserted) {
|
||||
setText(((RecentMessage)selectedItem).getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String createPresentation(final String s) {
|
||||
String converted = s.replaceAll("\n", " ");
|
||||
if (converted.length() < 20) {
|
||||
return converted;
|
||||
} else {
|
||||
return converted.substring(0, 20) + "...";
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(final String initialMessage) {
|
||||
myCommentArea.setText(initialMessage);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return myCommentArea.getText().trim();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
myCommentArea.setRows(3);
|
||||
myCommentArea.setWrapStyleWord(true);
|
||||
myCommentArea.setLineWrap(true);
|
||||
myCommentArea.setSelectionStart(0);
|
||||
myCommentArea.setSelectionEnd(myCommentArea.getText().length());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user