mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[file-history] copy provider for commit details IDEA-158666
This commit is contained in:
@@ -78,6 +78,8 @@ import javax.swing.table.TableCellEditor;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Position;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
@@ -88,6 +90,7 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -174,30 +177,12 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
}
|
||||
};
|
||||
myCommentsStatus.setText("Commit message");
|
||||
myComments = new JEditorPane(UIUtil.HTML_MIME, "") {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
myCommentsStatus.paint(this, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBackground() {
|
||||
return UIUtil.getEditorPaneBackground();
|
||||
}
|
||||
};
|
||||
myComments = new MyCommentsPane();
|
||||
myCommentsStatus.attachTo(myComments);
|
||||
myComments.setPreferredSize(new Dimension(150, 100));
|
||||
myComments.setEditable(false);
|
||||
myComments.setOpaque(false);
|
||||
myComments.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
|
||||
myComments.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
|
||||
|
||||
myRevisionsOrder = new HashMap<>();
|
||||
refreshRevisionsOrder();
|
||||
|
||||
replaceTransferable();
|
||||
|
||||
myUpdateAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myProject);
|
||||
|
||||
final HistoryAsTreeProvider treeHistoryProvider = myHistorySession.getHistoryAsTreeProvider();
|
||||
@@ -335,66 +320,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
return myStartingRevision;
|
||||
}
|
||||
|
||||
private void replaceTransferable() {
|
||||
final TransferHandler originalTransferHandler = myComments.getTransferHandler();
|
||||
|
||||
final TransferHandler newHandler = new TransferHandler("copy") {
|
||||
@Override
|
||||
public void exportAsDrag(final JComponent comp, final InputEvent e, final int action) {
|
||||
originalTransferHandler.exportAsDrag(comp, e, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportToClipboard(final JComponent comp, final Clipboard clip, final int action) throws IllegalStateException {
|
||||
if ((action == COPY || action == MOVE)
|
||||
&& (getSourceActions(comp) & action) != 0) {
|
||||
|
||||
String selectedText = myComments.getSelectedText();
|
||||
final Transferable t;
|
||||
if (selectedText == null) {
|
||||
t = new TextTransferable(myComments.getText(), myOriginalComment);
|
||||
}
|
||||
else {
|
||||
t = new TextTransferable(selectedText);
|
||||
}
|
||||
try {
|
||||
clip.setContents(t, null);
|
||||
exportDone(comp, t, action);
|
||||
return;
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
exportDone(comp, t, NONE);
|
||||
throw ise;
|
||||
}
|
||||
}
|
||||
|
||||
exportDone(comp, null, NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(final JComponent comp, final Transferable t) {
|
||||
return originalTransferHandler.importData(comp, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canImport(final JComponent comp, final DataFlavor[] transferFlavors) {
|
||||
return originalTransferHandler.canImport(comp, transferFlavors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceActions(final JComponent c) {
|
||||
return originalTransferHandler.getSourceActions(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getVisualRepresentation(final Transferable t) {
|
||||
return originalTransferHandler.getVisualRepresentation(t);
|
||||
}
|
||||
};
|
||||
|
||||
myComments.setTransferHandler(newHandler);
|
||||
}
|
||||
|
||||
private DualViewColumnInfo[] createColumnList(Project project, VcsHistoryProvider provider, final VcsHistorySession session) {
|
||||
final VcsDependentHistoryComponents components = provider.getUICustomization(session, this);
|
||||
myAdditionalDetails = components.getDetailsComponent();
|
||||
@@ -1787,4 +1712,73 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme
|
||||
setupDetails();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyCommentsPane extends JEditorPane implements DataProvider, CopyProvider {
|
||||
public MyCommentsPane() {
|
||||
super(UIUtil.HTML_MIME, "");
|
||||
|
||||
setPreferredSize(new Dimension(150, 100));
|
||||
setEditable(false);
|
||||
setOpaque(false);
|
||||
putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
|
||||
addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
myCommentsStatus.paint(this, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBackground() {
|
||||
return UIUtil.getEditorPaneBackground();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedText() {
|
||||
javax.swing.text.Document doc = getDocument();
|
||||
int start = getSelectionStart();
|
||||
int end = getSelectionEnd();
|
||||
|
||||
try {
|
||||
Position p0 = doc.createPosition(start);
|
||||
Position p1 = doc.createPosition(end);
|
||||
StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
|
||||
getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
|
||||
|
||||
return StringUtil.removeHtmlTags(sw.toString());
|
||||
}
|
||||
catch (BadLocationException | IOException e) {
|
||||
LOG.warn(e);
|
||||
}
|
||||
return super.getSelectedText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
String selectedText = getSelectedText();
|
||||
if (selectedText == null || selectedText.isEmpty()) selectedText = myOriginalComment;
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(selectedText));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyEnabled(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyVisible(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user