[gtranslator] Disable save button when file is saved



commit 17032b8e27e87555c4b0d8682cc62939861e1971
Author: Daniel García Moreno <danigm wadobo com>
Date:   Sun Sep 16 13:15:49 2018 +0200

    Disable save button when file is saved

 src/gtr-notebook.c | 10 ++++++++++
 src/gtr-notebook.h |  2 ++
 src/gtr-window.c   | 19 ++++++++++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/src/gtr-notebook.c b/src/gtr-notebook.c
index bb1af634..b855d251 100644
--- a/src/gtr-notebook.c
+++ b/src/gtr-notebook.c
@@ -39,6 +39,7 @@ typedef struct
   GtkWidget *progress_trans;
   GtkWidget *progress_fuzzy;
   GtkWidget *progress_untrans;
+  GtkWidget *save;
   GtrProgress *progress;
 } GtrNotebookPrivate;
 
@@ -152,6 +153,7 @@ gtr_notebook_class_init (GtrNotebookClass * klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_fuzzy);
   gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_untrans);
   gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_percentage);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, save);
 }
 
 /***************************** Public funcs ***********************************/
@@ -290,3 +292,11 @@ gtr_notebook_set_progress (GtrNotebook *notebook,
   g_free (untrans_text);
 }
 
+void
+gtr_notebook_enable_save (GtrNotebook *notebook,
+                          gboolean enable)
+{
+  GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
+  gtk_widget_set_sensitive (priv->save, enable);
+}
+
diff --git a/src/gtr-notebook.h b/src/gtr-notebook.h
index 3d199092..53ff6d41 100644
--- a/src/gtr-notebook.h
+++ b/src/gtr-notebook.h
@@ -77,5 +77,7 @@ GtkWidget *gtr_notebook_get_header (GtrNotebook *notebook);
 
 void gtr_notebook_set_progress (GtrNotebook *notebook, gint trans, gint untrans, gint fuzzy);
 
+void gtr_notebook_enable_save (GtrNotebook *notebook, gboolean enable);
+
 G_END_DECLS
 #endif /* __NOTEBOOK_H__ */
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 31ceb6f9..0846bc1a 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -101,6 +101,8 @@ static void          profile_combo_changed            (GtrStatusComboBox *combo,
                                                        GtkMenuItem       *item,
                                                        GtrWindow         *window);
 
+static void update_saved_state (GtrPo *po, GParamSpec *param, gpointer window);
+
 /*
  * gtr_window_update_statusbar_message_count:
  * 
@@ -272,11 +274,13 @@ set_window_title (GtrWindow * window, gboolean with_path)
         {
           /* Translators: this is the title of the window with a modified document */
           title = g_strdup_printf (_("*%s — gtranslator"), basename);
+          gtr_notebook_enable_save (GTR_NOTEBOOK (priv->notebook), TRUE);
         }
       else
         {
           /* Translators: this is the title of the window with a document opened */
           title = g_strdup_printf (_("%s — gtranslator"), basename);
+          gtr_notebook_enable_save (GTR_NOTEBOOK (priv->notebook), FALSE);
         }
 
       g_free (basename);
@@ -299,6 +303,14 @@ set_window_title (GtrWindow * window, gboolean with_path)
   g_free (subtitle);
 }
 
+static void
+update_saved_state (GtrPo *po,
+                    GParamSpec *param,
+                    gpointer window)
+{
+  set_window_title (GTR_WINDOW (window), TRUE);
+}
+
 static void
 notebook_switch_page (GtkNotebook * nb,
                       GtkWidget * page,
@@ -835,6 +847,12 @@ gtr_window_create_tab (GtrWindow * window, GtrPo * po)
 
   gtr_notebook_add_page (GTR_NOTEBOOK (priv->notebook), tab);
 
+  g_signal_connect_after (po,
+                          "notify::state",
+                          G_CALLBACK
+                          (update_saved_state),
+                          window);
+
   return tab;
 }
 
@@ -1153,4 +1171,3 @@ gtr_window_get_tm (GtrWindow *window) {
   GtrWindowPrivate *priv = gtr_window_get_instance_private (window);
   return priv->translation_memory;
 }
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]