From 4aa2593c2536236af0680274d2554867287071a8 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Mon, 2 Nov 2015 15:35:34 -0500 Subject: [PATCH] tmf: Add keyboard shortcuts for Next/Previous Marker 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 Reviewed-on: https://git.eclipse.org/r/59512 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../ui/widgets/timegraph/TimeGraphViewer.java | 137 ++++++++++++++---- .../timegraph/model/IMarkerEventSource.java | 8 +- .../timegraph/widgets/TimeGraphControl.java | 9 ++ 3 files changed, 125 insertions(+), 29 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java index f7a66f59a2..79c3453591 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java @@ -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 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 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 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 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 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 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; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEventSource.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEventSource.java index d2bd15df2d..d9d2d43ec3 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEventSource.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/IMarkerEventSource.java @@ -32,8 +32,12 @@ public interface IMarkerEventSource { @NonNull List 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). + *

+ * 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 diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index 88d7061afd..b2edddd4fe 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -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(); -- 2.34.1