mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-ui: wire up a save action
We need this so we have something more simplified for consumers such as Builder to avoid all the duplicated code.
This commit is contained in:
@ -473,3 +473,66 @@ sysprof_display_open (SysprofDisplay *self,
|
||||
|
||||
update_title_child_property (self);
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_display_save (SysprofDisplay *self)
|
||||
{
|
||||
SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self);
|
||||
g_autoptr(GFile) file = NULL;
|
||||
GtkFileChooserNative *native;
|
||||
SysprofCaptureReader *reader;
|
||||
GtkWindow *parent;
|
||||
gint res;
|
||||
|
||||
g_return_if_fail (SYSPROF_IS_DISPLAY (self));
|
||||
|
||||
if (!(reader = sysprof_capture_view_get_reader (priv->capture_view)))
|
||||
return;
|
||||
|
||||
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
|
||||
|
||||
native = gtk_file_chooser_native_new (_("Save Recording"),
|
||||
parent,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
_("Save"),
|
||||
_("Cancel"));
|
||||
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (native), TRUE);
|
||||
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (native), TRUE);
|
||||
gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER (native), TRUE);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (native), "capture.sysprof");
|
||||
|
||||
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
|
||||
|
||||
switch (res)
|
||||
{
|
||||
case GTK_RESPONSE_ACCEPT:
|
||||
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
|
||||
|
||||
if (g_file_is_native (file))
|
||||
{
|
||||
g_autofree gchar *path = g_file_get_path (file);
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
if (!sysprof_capture_reader_save_as (reader, path, &error))
|
||||
{
|
||||
GtkWidget *msg;
|
||||
|
||||
msg = gtk_message_dialog_new (parent,
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
_("Failed to save recording: %s"),
|
||||
error->message);
|
||||
gtk_window_present (GTK_WINDOW (msg));
|
||||
g_signal_connect (msg, "response", G_CALLBACK (gtk_widget_destroy), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
|
||||
}
|
||||
|
||||
@ -51,5 +51,7 @@ gboolean sysprof_display_is_empty (SysprofDisplay *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
void sysprof_display_open (SysprofDisplay *self,
|
||||
GFile *file);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
void sysprof_display_save (SysprofDisplay *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@ -160,3 +160,27 @@ sysprof_notebook_open (SysprofNotebook *self,
|
||||
|
||||
sysprof_display_open (SYSPROF_DISPLAY (display), file);
|
||||
}
|
||||
|
||||
static SysprofDisplay *
|
||||
sysprof_notebook_get_current (SysprofNotebook *self)
|
||||
{
|
||||
gint page;
|
||||
|
||||
g_assert (SYSPROF_IS_NOTEBOOK (self));
|
||||
|
||||
if ((page = gtk_notebook_get_current_page (GTK_NOTEBOOK (self))) >= 0)
|
||||
return SYSPROF_DISPLAY (gtk_notebook_get_nth_page (GTK_NOTEBOOK (self), page));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_notebook_save (SysprofNotebook *self)
|
||||
{
|
||||
SysprofDisplay *display;
|
||||
|
||||
g_return_if_fail (SYSPROF_IS_NOTEBOOK (self));
|
||||
|
||||
if ((display = sysprof_notebook_get_current (self)))
|
||||
sysprof_display_save (display);
|
||||
}
|
||||
|
||||
@ -46,5 +46,7 @@ void sysprof_notebook_close_current (SysprofNotebook *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
void sysprof_notebook_open (SysprofNotebook *self,
|
||||
GFile *file);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
void sysprof_notebook_save (SysprofNotebook *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@ -20,6 +20,13 @@
|
||||
<attribute name="accel"><primary>o</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section id="win-menu-save">
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Save Capture…</attribute>
|
||||
<attribute name="action">win.save-capture</attribute>
|
||||
<attribute name="accel"><primary>s</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section id="win-menu-close">
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Close</attribute>
|
||||
|
||||
@ -105,6 +105,17 @@ close_tab_cb (GSimpleAction *action,
|
||||
sysprof_notebook_close_current (self->notebook);
|
||||
}
|
||||
|
||||
static void
|
||||
save_capture_cb (GSimpleAction *action,
|
||||
GVariant *param,
|
||||
gpointer user_data)
|
||||
{
|
||||
SysprofWindow *self = user_data;
|
||||
|
||||
g_return_if_fail (SYSPROF_IS_WINDOW (self));
|
||||
|
||||
sysprof_notebook_save (self->notebook);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_window_class_init (SysprofWindowClass *klass)
|
||||
@ -127,6 +138,7 @@ sysprof_window_init (SysprofWindow *self)
|
||||
{ "close-tab", close_tab_cb },
|
||||
{ "new-tab", new_tab_cb },
|
||||
{ "switch-tab", switch_tab_cb, "i" },
|
||||
{ "save-capture", save_capture_cb },
|
||||
};
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
Reference in New Issue
Block a user