filechooser: the preview panel as Caja's information pane
The name stands under the picture in bold and centred, and below the details a button opens the file with the program the system has for its type, "Open With ...", both as in the information pane of Caja. The string comes translated from there. gtkmain.h is included for gtk_get_current_event_time(); on Windows no other header brought it in.
This commit is contained in:
parent
3f065539f5
commit
82361cfd6f
2 changed files with 67 additions and 2 deletions
|
|
@ -54,6 +54,7 @@
|
|||
#include "gtkimagemenuitem.h"
|
||||
#include "gtkinfobar.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtkmain.h"
|
||||
#include "gtkmarshalers.h"
|
||||
#include "gtkmessagedialog.h"
|
||||
#include "gtkmountoperation.h"
|
||||
|
|
@ -1656,6 +1657,54 @@ preview_panel_thumbnail_done (GFile *file,
|
|||
preview_panel_set_picture (impl, thumbnail, &small);
|
||||
}
|
||||
|
||||
/* As in Caja: a button that opens the file with the program the system
|
||||
* has for its type */
|
||||
static void
|
||||
preview_panel_open_clicked (GtkButton *button,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
GAppInfo *app = g_object_get_data (G_OBJECT (button), "gtk-app");
|
||||
GdkAppLaunchContext *context = gdk_app_launch_context_new ();
|
||||
GList files = { impl->preview_file, NULL, NULL };
|
||||
GError *error = NULL;
|
||||
|
||||
gdk_app_launch_context_set_screen (context, gtk_widget_get_screen (GTK_WIDGET (button)));
|
||||
gdk_app_launch_context_set_timestamp (context, gtk_get_current_event_time ());
|
||||
if (impl->preview_file && !g_app_info_launch (app, &files, G_APP_LAUNCH_CONTEXT (context), &error))
|
||||
{
|
||||
error_message (impl, _("Could not open the file"), error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_object_unref (context);
|
||||
}
|
||||
|
||||
static void
|
||||
preview_panel_open_with (GtkFileChooserDefault *impl,
|
||||
GFileInfo *info)
|
||||
{
|
||||
const gchar *type = info ? g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE) : NULL;
|
||||
GList *children = gtk_container_get_children (GTK_CONTAINER (impl->preview_panel_open)), *l;
|
||||
GAppInfo *app;
|
||||
|
||||
for (l = children; l; l = l->next)
|
||||
gtk_widget_destroy (l->data);
|
||||
g_list_free (children);
|
||||
|
||||
app = type ? g_app_info_get_default_for_type (type, FALSE) : NULL;
|
||||
if (app)
|
||||
{
|
||||
gchar *text = g_strdup_printf (_("Open With %s"), g_app_info_get_name (app));
|
||||
GtkWidget *button = gtk_button_new_with_label (text);
|
||||
|
||||
gtk_label_set_ellipsize (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), PANGO_ELLIPSIZE_START);
|
||||
g_object_set_data_full (G_OBJECT (button), I_("gtk-app"), app, g_object_unref);
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (preview_panel_open_clicked), impl);
|
||||
gtk_box_pack_start (GTK_BOX (impl->preview_panel_open), button, FALSE, FALSE, 0);
|
||||
gtk_widget_show (button);
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sound and video, started by the user only */
|
||||
|
||||
/* A button with the icon of @stock_id and its label as the tooltip */
|
||||
|
|
@ -1895,10 +1944,18 @@ preview_panel_update (GtkFileChooserDefault *impl)
|
|||
{
|
||||
gtk_image_clear (GTK_IMAGE (impl->preview_panel_image));
|
||||
gtk_label_set_text (GTK_LABEL (impl->preview_panel_name), "");
|
||||
preview_panel_open_with (impl, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (impl->preview_panel_name), g_file_info_get_display_name (info));
|
||||
{
|
||||
gchar *title = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>",
|
||||
g_file_info_get_display_name (info));
|
||||
|
||||
gtk_label_set_markup (GTK_LABEL (impl->preview_panel_name), title);
|
||||
g_free (title);
|
||||
}
|
||||
preview_panel_open_with (impl, info);
|
||||
|
||||
type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
|
||||
if (type)
|
||||
|
|
@ -2122,6 +2179,7 @@ preview_panel_sync (GtkFileChooserDefault *impl)
|
|||
impl->preview_panel_image = NULL;
|
||||
impl->preview_panel_name = NULL;
|
||||
impl->preview_panel_info = NULL;
|
||||
impl->preview_panel_open = NULL;
|
||||
impl->preview_panel_media = NULL;
|
||||
impl->preview_panel_play = NULL;
|
||||
impl->preview_panel_note = NULL;
|
||||
|
|
@ -2184,7 +2242,10 @@ preview_panel_sync (GtkFileChooserDefault *impl)
|
|||
gtk_label_set_line_wrap (GTK_LABEL (impl->preview_panel_name), TRUE);
|
||||
gtk_label_set_line_wrap_mode (GTK_LABEL (impl->preview_panel_name), PANGO_WRAP_WORD_CHAR);
|
||||
gtk_label_set_selectable (GTK_LABEL (impl->preview_panel_name), TRUE);
|
||||
gtk_misc_set_alignment (GTK_MISC (impl->preview_panel_name), 0.0, 0.0);
|
||||
gtk_label_set_justify (GTK_LABEL (impl->preview_panel_name), GTK_JUSTIFY_CENTER);
|
||||
gtk_misc_set_alignment (GTK_MISC (impl->preview_panel_name), 0.5, 0.0);
|
||||
/* centred by its text, not by the width it asks for */
|
||||
gtk_label_set_width_chars (GTK_LABEL (impl->preview_panel_name), 1);
|
||||
gtk_widget_set_size_request (impl->preview_panel_name, PREVIEW_PANEL_WIDTH (impl), -1);
|
||||
gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_name, FALSE, FALSE, 0);
|
||||
|
||||
|
|
@ -2193,6 +2254,9 @@ preview_panel_sync (GtkFileChooserDefault *impl)
|
|||
gtk_table_set_row_spacings (GTK_TABLE (impl->preview_panel_info), 2);
|
||||
gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_info, FALSE, FALSE, 0);
|
||||
|
||||
impl->preview_panel_open = gtk_vbox_new (FALSE, 6);
|
||||
gtk_box_pack_start (GTK_BOX (impl->preview_panel), impl->preview_panel_open, FALSE, FALSE, 6);
|
||||
|
||||
box = gtk_widget_get_parent (impl->preview_box);
|
||||
impl->preview_panel_handle = preview_panel_handle_new (impl);
|
||||
gtk_box_pack_start (GTK_BOX (box), impl->preview_panel_handle, FALSE, FALSE, 0);
|
||||
|
|
|
|||
|
|
@ -346,6 +346,7 @@ struct _GtkFileChooserDefault
|
|||
GtkWidget *preview_panel_image;
|
||||
GtkWidget *preview_panel_name;
|
||||
GtkWidget *preview_panel_info;
|
||||
GtkWidget *preview_panel_open; /* "Open With ..." */
|
||||
GtkWidget *preview_panel_media; /* play and stop, with a note */
|
||||
GtkWidget *preview_panel_play;
|
||||
GtkWidget *preview_panel_note;
|
||||
|
|
|
|||
Loading…
Reference in a new issue