diff --git a/src/libsysprof-gtk/sysprof-session.c b/src/libsysprof-gtk/sysprof-session.c index e2062efa..d4cea732 100644 --- a/src/libsysprof-gtk/sysprof-session.c +++ b/src/libsysprof-gtk/sysprof-session.c @@ -364,3 +364,18 @@ sysprof_session_list_tracks (SysprofSession *self) return g_object_ref (G_LIST_MODEL (self->tracks)); } + +void +sysprof_session_zoom_to_selection (SysprofSession *self) +{ + g_return_if_fail (SYSPROF_IS_SESSION (self)); + + if (memcmp (&self->visible_time, &self->selected_time, sizeof self->visible_time) == 0) + return; + + self->visible_time = self->selected_time; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VISIBLE_TIME]); + + sysprof_session_update_axis (self); +} diff --git a/src/libsysprof-gtk/sysprof-session.h b/src/libsysprof-gtk/sysprof-session.h index 2a3ea927..358382db 100644 --- a/src/libsysprof-gtk/sysprof-session.h +++ b/src/libsysprof-gtk/sysprof-session.h @@ -52,6 +52,8 @@ SYSPROF_AVAILABLE_IN_ALL void sysprof_session_select_time (SysprofSession *self, const SysprofTimeSpan *time_span); SYSPROF_AVAILABLE_IN_ALL +void sysprof_session_zoom_to_selection (SysprofSession *self); +SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_session_list_tracks (SysprofSession *self); G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-tracks-view.c b/src/libsysprof-gtk/sysprof-tracks-view.c index 5d25475a..71d58080 100644 --- a/src/libsysprof-gtk/sysprof-tracks-view.c +++ b/src/libsysprof-gtk/sysprof-tracks-view.c @@ -319,6 +319,19 @@ G_GNUC_END_IGNORE_DEPRECATIONS gtk_widget_get_height (GTK_WIDGET (self)))); } +static void +sysprof_tracks_view_zoom_to_selection (GtkWidget *widget, + const char *action_name, + GVariant *params) +{ + SysprofTracksView *self = (SysprofTracksView *)widget; + + g_assert (SYSPROF_IS_TRACKS_VIEW (self)); + + if (self->session != NULL) + sysprof_session_zoom_to_selection (self->session); +} + static void sysprof_tracks_view_measure (GtkWidget *widget, GtkOrientation orientation, @@ -467,6 +480,8 @@ sysprof_tracks_view_class_init (SysprofTracksViewClass *klass) gtk_widget_class_bind_template_callback (widget_class, sysprof_tracks_view_drag_end_cb); gtk_widget_class_bind_template_callback (widget_class, sysprof_tracks_view_drag_update_cb); + gtk_widget_class_install_action (widget_class, "zoom-to-selection", NULL, sysprof_tracks_view_zoom_to_selection); + g_type_ensure (SYSPROF_TYPE_TIME_RULER); g_type_ensure (SYSPROF_TYPE_TRACK_VIEW); }