[gtranslator/file-chooser-native] Use GtkFileChooserNative
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator/file-chooser-native] Use GtkFileChooserNative
- Date: Sat, 12 Sep 2020 08:43:53 +0000 (UTC)
commit 31fc32d4f0c28969bb3a8333f6e8196c6ae8a4ba
Author: Daniel García Moreno <dani danigm net>
Date: Fri Sep 11 11:01:01 2020 +0200
Use GtkFileChooserNative
This patch uses the GtkFileChooserNative instead of the GtkFileChooser
to open and save po files. This will improve the experience for flatpak
because it will show bookmarks and the integration with the host system
is better.
This change also introduces a small issue with file paths. The
GtkFileChooserNative returns a path like `/run/user/...` for each file
so it's not possible to know the real path of that file.
We were showing the full file path on the headerbar, but with this temp
path that's not useful, so this patch removes that subtitle.
You can notice this problem also when clicking on "save as" because the
default folder will be that temp path, instead the user folder.
Fix https://gitlab.gnome.org/GNOME/gtranslator/-/issues/116
src/gtr-actions-file.c | 58 ++++++++++----------------------------------------
src/gtr-file-dialogs.c | 11 +++++-----
src/gtr-window.c | 7 ------
3 files changed, 16 insertions(+), 60 deletions(-)
---
diff --git a/src/gtr-actions-file.c b/src/gtr-actions-file.c
index 27137b3b..fec93d79 100644
--- a/src/gtr-actions-file.c
+++ b/src/gtr-actions-file.c
@@ -151,24 +151,11 @@ gtr_file_chooser_analyse (gpointer dialog,
{
gint reply;
- reply = gtk_dialog_run (GTK_DIALOG (dialog));
- switch (reply)
- {
- case GTK_RESPONSE_ACCEPT:
- if (mode == FILESEL_OPEN)
- {
- gtr_po_parse_files_from_dialog (GTK_WIDGET (dialog), window);
- }
- break;
- case GTK_RESPONSE_CANCEL:
- gtk_widget_hide (GTK_WIDGET (dialog));
- break;
- case GTK_RESPONSE_DELETE_EVENT:
- gtk_widget_hide (GTK_WIDGET (dialog));
- break;
- default:
- break;
- }
+ reply = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
+ if (reply == GTK_RESPONSE_ACCEPT && mode == FILESEL_OPEN)
+ gtr_po_parse_files_from_dialog (GTK_WIDGET (dialog), window);
+
+ g_object_unref (dialog);
}
gboolean
@@ -261,7 +248,7 @@ save_dialog_response_cb (GtkDialog * dialog,
if (response_id != GTK_RESPONSE_ACCEPT)
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (dialog);
return;
}
@@ -271,7 +258,7 @@ save_dialog_response_cb (GtkDialog * dialog,
location = g_file_new_for_path (filename);
g_free (filename);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (dialog);
if (po != NULL)
{
@@ -329,9 +316,7 @@ gtr_save_file_as_dialog (GtkAction * action, GtrWindow * window)
{
GtkWidget *dialog = NULL;
GtrTab *current_page;
- GtrPo *po;
- GFile *location;
- gchar *uri = NULL;
+ gint reply = 0;
if (dialog != NULL)
{
@@ -340,12 +325,10 @@ gtr_save_file_as_dialog (GtkAction * action, GtrWindow * window)
}
current_page = gtr_window_get_active_tab (window);
- po = gtr_tab_get_po (current_page);
-
dialog = gtr_file_chooser_new (GTK_WINDOW (window),
FILESEL_SAVE,
_("Save file as…"),
- _gtr_application_get_last_dir (GTR_APP));
+ g_get_home_dir ());
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
TRUE);
@@ -354,29 +337,10 @@ gtr_save_file_as_dialog (GtkAction * action, GtrWindow * window)
G_CALLBACK (confirm_overwrite_callback), NULL);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- /*Set the suggested file */
- location = gtr_po_get_location (po);
-
- uri = g_file_get_uri (location);
-
- g_object_unref (location);
-
- if (uri)
- gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
-
- g_free (uri);
-
- /*
- * FIXME: If we can't set the uri we should add a default path and name
- */
-
g_object_set_data (G_OBJECT (dialog), GTR_TAB_SAVE_AS, current_page);
- g_signal_connect (dialog,
- "response", G_CALLBACK (save_dialog_response_cb), window);
-
- gtk_widget_show (GTK_WIDGET (dialog));
+ reply = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
+ save_dialog_response_cb (GTK_DIALOG (dialog), reply, window);
}
/*
diff --git a/src/gtr-file-dialogs.c b/src/gtr-file-dialogs.c
index 9a0d7c58..1972ccb6 100644
--- a/src/gtr-file-dialogs.c
+++ b/src/gtr-file-dialogs.c
@@ -33,20 +33,19 @@ gtr_file_chooser_new (GtkWindow * parent,
FileselMode mode,
const gchar * title, const gchar * dir)
{
- GtkWidget *dialog;
+ GtkFileChooserNative *dialog;
GtkFileFilter *filter;
- dialog = gtk_file_chooser_dialog_new (title,
+ dialog = gtk_file_chooser_native_new (title,
parent,
(mode ==
FILESEL_SAVE) ?
GTK_FILE_CHOOSER_ACTION_SAVE :
GTK_FILE_CHOOSER_ACTION_OPEN,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
(mode ==
FILESEL_SAVE) ? _("_Save") :
- _("_Open"), GTK_RESPONSE_ACCEPT,
- NULL);
+ _("_Open"), _("_Cancel"));
+
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (dir)
@@ -80,5 +79,5 @@ gtr_file_chooser_new (GtkWindow * parent,
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
- return dialog;
+ return GTK_WIDGET (dialog);
}
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 2e5c1cc2..e5abad1d 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -194,13 +194,11 @@ set_window_title (GtrWindow * window, gboolean with_path)
GtrTab *active_tab;
GFile *file;
gchar *title;
- gchar *subtitle;
GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
GtkHeaderBar *header;
if (with_path)
{
- gchar *path;
gchar *basename;
active_tab = gtr_window_get_active_tab (window);
@@ -208,9 +206,7 @@ set_window_title (GtrWindow * window, gboolean with_path)
state = gtr_po_get_state (gtr_tab_get_po (active_tab));
po = gtr_tab_get_po (active_tab);
file = gtr_po_get_location (po);
- path = g_file_get_path (file);
basename = g_file_get_basename (file);
- subtitle = path;
if (state == GTR_PO_STATE_MODIFIED)
{
@@ -231,7 +227,6 @@ set_window_title (GtrWindow * window, gboolean with_path)
else
{
title = g_strdup (_("Translation Editor"));
- subtitle = g_strdup ("");
}
gtk_window_set_title (GTK_WINDOW (window), title);
@@ -239,10 +234,8 @@ set_window_title (GtrWindow * window, gboolean with_path)
// notebook headerbar
header = GTK_HEADER_BAR (gtr_notebook_get_header (GTR_NOTEBOOK (priv->notebook)));
gtk_header_bar_set_title (header, title);
- gtk_header_bar_set_subtitle (header, subtitle);
g_free (title);
- g_free (subtitle);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]