[vcs-log] show references tooltip for selected commit on the same shortcut as quick...
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Mon, 24 Oct 2016 03:15:30 +0000 (06:15 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Mon, 24 Oct 2016 03:15:30 +0000 (06:15 +0300)
platform/vcs-log/impl/src/META-INF/vcs-log.xml
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowCommitTooltipAction.java [new file with mode: 0644]
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/GraphTableController.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/VcsLogGraphTable.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java

index bf957053ab197e1e6a63b13948013e63bcaa5382..4f44100f5b9e03882ebe2b0fae6c52be3444f175 100644 (file)
@@ -56,6 +56,9 @@
             text="Show History as Graph" description="Show History as Graph" internal="true"/>
     <action class="com.intellij.vcs.log.ui.actions.PrintIndexInfoAction" id="Vcs.Log.Print.Index.Info"
             text="Print Index Info" description="Print Index Info for a Commit into Log File" internal="true"/>
+    <action class="com.intellij.vcs.log.ui.actions.ShowCommitTooltipAction" id="Vcs.Log.ShowTooltip"
+            text="Show Commit Tooltip" description="Show tooltip for currently selected commit in the Log"
+            use-shortcut-of="QuickJavaDoc"/>
 
     <group id="Vcs.Log.Settings">
       <reference id="Vcs.Log.ShowRootsColumnAction"/>
diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowCommitTooltipAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ShowCommitTooltipAction.java
new file mode 100644 (file)
index 0000000..192f142
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.vcs.log.ui.actions;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.openapi.project.Project;
+import com.intellij.vcs.log.VcsLogDataKeys;
+import com.intellij.vcs.log.VcsLogUi;
+import com.intellij.vcs.log.ui.VcsLogUiImpl;
+import com.intellij.vcs.log.ui.frame.VcsLogGraphTable;
+import org.jetbrains.annotations.NotNull;
+
+public class ShowCommitTooltipAction extends DumbAwareAction {
+  public ShowCommitTooltipAction() {
+    super("Show Commit Tooltip", "Show tooltip for currently selected commit in the Log", null);
+  }
+
+  @Override
+  public void update(@NotNull AnActionEvent e) {
+    Project project = e.getProject();
+    VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI);
+    if (project == null || ui == null) {
+      e.getPresentation().setEnabledAndVisible(false);
+    }
+    else {
+      e.getPresentation().setEnabledAndVisible(ui instanceof VcsLogUiImpl && ((VcsLogUiImpl)ui).getTable().getSelectedRowCount() == 1);
+    }
+  }
+
+  @Override
+  public void actionPerformed(@NotNull AnActionEvent e) {
+    VcsLogGraphTable table = ((VcsLogUiImpl)e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI)).getTable();
+    table.showTooltip(table.getSelectedRow());
+  }
+}
index 143f1d7211b116aff258cee644031346be46d5f3..e5e32872825d5fc2bc374629bfaf7b4cadf472f7 100644 (file)
@@ -184,21 +184,33 @@ public class GraphTableController {
   }
 
   private void showOrHideCommitTooltip(int row, int column, @NotNull MouseEvent e) {
-    JComponent tipComponent = myCommitRenderer.getTooltip(myTable.getValueAt(row, column), calcPoint4Graph(e.getPoint()),
+    if (!showTooltip(row, column, e.getPoint(), false)) {
+      if (IdeTooltipManager.getInstance().hasCurrent()) {
+        IdeTooltipManager.getInstance().hideCurrent(e);
+      }
+    }
+  }
+
+  private boolean showTooltip(int row, int column, @NotNull Point point, boolean now) {
+    JComponent tipComponent = myCommitRenderer.getTooltip(myTable.getValueAt(row, column), calcPoint4Graph(point),
                                                           myTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN)
                                                             .getWidth());
 
     if (tipComponent != null) {
       myTable.getExpandableItemsHandler().setEnabled(false);
       IdeTooltip tooltip =
-        new IdeTooltip(myTable, e.getPoint(), new Wrapper(tipComponent)).setPreferredPosition(Balloon.Position.below);
-      IdeTooltipManager.getInstance().show(tooltip, false);
-    }
-    else {
-      if (IdeTooltipManager.getInstance().hasCurrent()) {
-        IdeTooltipManager.getInstance().hideCurrent(e);
-      }
+        new IdeTooltip(myTable, point, new Wrapper(tipComponent)).setPreferredPosition(Balloon.Position.below);
+      IdeTooltipManager.getInstance().show(tooltip, now);
+      return true;
     }
+    return false;
+  }
+
+  public void showTooltip(int row) {
+    TableColumn rootColumn = myTable.getColumnModel().getColumn(GraphTableModel.ROOT_COLUMN);
+    Point point = new Point(rootColumn.getWidth() + myCommitRenderer.getToolipXCoordinate(row),
+                            row * myTable.getRowHeight() + myTable.getRowHeight() / 2);
+    showTooltip(row, GraphTableModel.COMMIT_COLUMN, point, true);
   }
 
   private void performRootColumnAction() {
index 698ebd3ec0f08edea8680f1e9a9a03b1e3e612a4..fc3105a813cb93a9e674ecbd06d262a39b057f15 100644 (file)
@@ -430,6 +430,10 @@ public class VcsLogGraphTable extends TableWithProgress implements DataProvider,
     myController.handleGraphAnswer(answer, dataCouldChange, null, null);
   }
 
+  public void showTooltip(int row) {
+    myController.showTooltip(row);
+  }
+
   static class Selection {
     @NotNull private final VcsLogGraphTable myTable;
     @NotNull private final TIntHashSet mySelectedCommits;
index bf43444298f20c47bd38d493ada16fe6053f7c48..f5bdf2302a101c19a810a29362133d3527f76b95 100644 (file)
@@ -27,10 +27,12 @@ import com.intellij.vcs.log.paint.GraphCellPainter;
 import com.intellij.vcs.log.paint.PaintParameters;
 import com.intellij.vcs.log.ui.frame.ReferencesPanel;
 import com.intellij.vcs.log.ui.frame.VcsLogGraphTable;
+import com.intellij.vcs.log.ui.tables.GraphTableModel;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
+import javax.swing.table.TableColumn;
 import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.util.Collection;
@@ -211,6 +213,17 @@ public class GraphCommitCellRenderer extends ColoredTableCellRenderer {
     return null;
   }
 
+  public int getToolipXCoordinate(int row) {
+    GraphCommitCell cell = getAssertCommitCell(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN));
+    Collection<VcsRef> refs = cell.getRefsToThisCommit();
+    if (!refs.isEmpty()) {
+      customizeRefsPainter(myReferencePainter, refs, getForeground());
+      TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
+      return commitColumn.getWidth() - (myReferencePainter.getSize().width - LabelPainter.GRADIENT_WIDTH) / 2;
+    }
+    return -1;
+  }
+
   private static class PaintInfo {
     private int myWidth;
     @NotNull private Image myImage;