tmf: Add keyboard shortcuts for Next/Previous Marker
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 2 Nov 2015 20:35:34 +0000 (15:35 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 9 Nov 2015 20:00:36 +0000 (15:00 -0500)
Support '.' for Next Marker and ',' for Previous Marker.

Support Shift key for extending the selection, both with the keyboard
shortcut and with the action button.

Update the status line when Next/Previous Marker changes the selection.

Clarify the marker event source API to indicate that the previous and
next markers should be included in the marker list.

Change-Id: I1f435e9620030809f10f3788eca40521c8a745a9
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/59512
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEventSource.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index f7a66f59a213730ece3f0f0ac60a7ba80183e7b2..79c3453591c50ac66636ba697784aec2609120b5 100644 (file)
@@ -528,6 +528,20 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
                     zoomIn();
                 } else if (e.character == '-') {
                     zoomOut();
+                } else if (e.keyCode == '.') {
+                    boolean extend = (e.stateMask & SWT.SHIFT) != 0;
+                    if (extend) {
+                        extendToNextMarker();
+                    } else {
+                        selectNextMarker();
+                    }
+                } else if (e.keyCode == ',') {
+                    boolean extend = (e.stateMask & SWT.SHIFT) != 0;
+                    if (extend) {
+                        extendToPrevMarker();
+                    } else {
+                        selectPrevMarker();
+                    }
                 }
                 adjustVerticalScrollBar();
             }
@@ -2110,19 +2124,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             fNextMarkerAction = new Action(Messages.TmfTimeGraphViewer_NextMarkerActionText, IAction.AS_DROP_DOWN_MENU) {
                 @Override
                 public void runWithEvent(Event event) {
-                    final long time = Math.min(fSelectionBegin, fSelectionEnd);
-                    final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
-                    List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
-                    if (markers == null) {
-                        return;
-                    }
-                    for (IMarkerEvent marker : markers) {
-                        if ((marker.getTime() > time ||
-                                (marker.getTime() == time && marker.getDuration() > duration))
-                                && !fSkippedMarkerCategories.contains(marker.getCategory())) {
-                            setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
-                            return;
-                        }
+                    boolean extend = (event.stateMask & SWT.SHIFT) != 0;
+                    if (extend) {
+                        extendToNextMarker();
+                    } else {
+                        selectNextMarker();
                     }
                 }
             };
@@ -2183,20 +2189,11 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
             fPreviousMarkerAction = new Action() {
                 @Override
                 public void runWithEvent(Event event) {
-                    final long time = Math.min(fSelectionBegin, fSelectionEnd);
-                    final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
-                    List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
-                    if (markers == null) {
-                        return;
-                    }
-                    for (int i = markers.size() - 1; i >= 0; i--) {
-                        IMarkerEvent marker = markers.get(i);
-                        if ((marker.getTime() < time ||
-                                (marker.getTime() == time && marker.getDuration() < duration))
-                                && !fSkippedMarkerCategories.contains(marker.getCategory())) {
-                            setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
-                            return;
-                        }
+                    boolean extend = (event.stateMask & SWT.SHIFT) != 0;
+                    if (extend) {
+                        extendToPrevMarker();
+                    } else {
+                        selectPrevMarker();
                     }
                 }
             };
@@ -2243,6 +2240,92 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         return fMarkersMenu;
     }
 
+    /**
+     * Select the next marker that begins at or after the current selection
+     * begin time. Markers that begin at the same time are ordered by end time.
+     */
+    private void selectNextMarker() {
+        List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
+        if (markers == null) {
+            return;
+        }
+        for (IMarkerEvent marker : markers) {
+            final long time = Math.min(fSelectionBegin, fSelectionEnd);
+            final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+            if ((marker.getTime() > time ||
+                    (marker.getTime() == time && marker.getDuration() > duration))
+                    && !fSkippedMarkerCategories.contains(marker.getCategory())) {
+                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
+                fTimeGraphCtrl.updateStatusLine();
+                return;
+            }
+        }
+    }
+
+    /**
+     * Select the previous marker that begins at or before the current selection
+     * begin time. Markers that begin at the same time are ordered by end time.
+     */
+    private void selectPrevMarker() {
+        List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
+        if (markers == null) {
+            return;
+        }
+        final long time = Math.min(fSelectionBegin, fSelectionEnd);
+        final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
+        for (int i = markers.size() - 1; i >= 0; i--) {
+            IMarkerEvent marker = markers.get(i);
+            if ((marker.getTime() < time ||
+                    (marker.getTime() == time && marker.getDuration() < duration))
+                    && !fSkippedMarkerCategories.contains(marker.getCategory())) {
+                setSelectionRangeNotify(marker.getTime(), marker.getTime() + marker.getDuration());
+                fTimeGraphCtrl.updateStatusLine();
+                return;
+            }
+        }
+    }
+
+    /**
+     * Extend the selection to the closest next marker end time.
+     */
+    private void extendToNextMarker() {
+        List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
+        if (markers == null) {
+            return;
+        }
+        IMarkerEvent nextMarker = null;
+        for (IMarkerEvent marker : markers) {
+            if (marker.getTime() + marker.getDuration() > fSelectionEnd
+                    && !fSkippedMarkerCategories.contains(marker.getCategory())
+                    && (nextMarker == null || marker.getTime() + marker.getDuration() < nextMarker.getTime() + nextMarker.getDuration())) {
+                nextMarker = marker;
+            }
+        }
+        if (nextMarker != null) {
+            setSelectionRangeNotify(fSelectionBegin, nextMarker.getTime() + nextMarker.getDuration());
+            fTimeGraphCtrl.updateStatusLine();
+        }
+    }
+
+    /**
+     * Extend the selection to the closest previous marker start time.
+     */
+    private void extendToPrevMarker() {
+        List<IMarkerEvent> markers = getTimeGraphControl().getMarkers();
+        if (markers == null) {
+            return;
+        }
+        for (int i = markers.size() - 1; i >= 0; i--) {
+            IMarkerEvent marker = markers.get(i);
+            if (marker.getTime() < fSelectionEnd
+                    && !fSkippedMarkerCategories.contains(marker.getCategory())) {
+                setSelectionRangeNotify(fSelectionBegin, marker.getTime());
+                fTimeGraphCtrl.updateStatusLine();
+                return;
+            }
+        }
+    }
+
     private IMarkerEvent getBookmarkAtSelection() {
         final long time = Math.min(fSelectionBegin, fSelectionEnd);
         final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
index d2bd15df2d84d250da34a24c4de79560f6c29d9c..d9d2d43ec317343d460c68e122dd090921c73cca 100644 (file)
@@ -32,8 +32,12 @@ public interface IMarkerEventSource {
     @NonNull List<String> getMarkerCategories();
 
     /**
-     * Gets the list of marker events of a specific category in a given time
-     * range.
+     * Gets the list of marker events of a specific category that intersect the
+     * given time range (inclusively).
+     * <p>
+     * The list should include the nearest previous marker that starts before
+     * the time range (it might already be included if it intersects the time
+     * range), and the nearest next marker that starts after the time range.
      *
      * @param category
      *            The marker category
index 88d7061afdd0dc139d8d6ec7bd11a93de9309df9..b2edddd4fe208e821a42cccf0e2128a0e7ffea05 100644 (file)
@@ -2236,6 +2236,15 @@ public class TimeGraphControl extends TimeGraphBaseControl
         }
     }
 
+    /**
+     * Update the status line following a change of selection.
+     *
+     * @since 2.0
+     */
+    public void updateStatusLine() {
+        updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
+    }
+
     private void updateStatusLine(int x) {
         // use the time provider of the time graph scale for the status line
         ITimeDataProvider tdp = fTimeGraphScale.getTimeProvider();
This page took 0.03022 seconds and 5 git commands to generate.