[gtranslator] Block message table navigation on message errors



commit bebb0f6fb9357890256f07fb45c1ebeba58a9b09
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 1 19:34:31 2012 +0200

    Block message table navigation on message errors
    
    Emit ::message-edition-finished before telling the message
    table to move on to the next message, so the message is checked
    for errors and navigation can be blocked.

 src/gtr-tab.c |  100 ++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 67 insertions(+), 33 deletions(-)
---
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 3c4fef0..d7c1052 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -1207,24 +1207,11 @@ void
 gtr_tab_message_go_to (GtrTab * tab,
                        GtrMsg * to_go, gboolean searching, GtrTabMove move)
 {
-  GtrPo *po;
-  GList *current_msg;
   static gboolean first_msg = TRUE;
 
   g_return_if_fail (tab != NULL);
   g_return_if_fail (GTR_IS_MSG (to_go));
 
-  po = tab->priv->po;
-
-  current_msg = gtr_po_get_current_message (po);
-
-  /*
-   * Emitting message-edition-finished signal
-   */
-  if (!searching && !first_msg)
-    g_signal_emit (G_OBJECT (tab), signals[MESSAGE_EDITION_FINISHED],
-                   0, GTR_MSG (current_msg->data));
-
   if (!tab->priv->blocking || first_msg)
     {
       gboolean plurals;
@@ -1630,6 +1617,20 @@ gtr_tab_unblock_movement (GtrTab * tab)
   tab->priv->blocking = FALSE;
 }
 
+static gboolean
+_gtr_tab_finish_edition (GtrTab * tab)
+{
+  GList *current_msg;
+
+  current_msg = gtr_po_get_current_message (tab->priv->po);
+
+  /* movement is blocked/unblocked within the handler */
+  g_signal_emit (G_OBJECT (tab), signals[MESSAGE_EDITION_FINISHED],
+		 0, GTR_MSG (current_msg->data));
+
+  return !tab->priv->blocking;
+}
+
 /**
  * gtr_tab_go_to_next:
  * @tab: a #GtrTab
@@ -1641,11 +1642,14 @@ gtr_tab_go_to_next (GtrTab * tab)
 {
   GtrMsg *msg;
 
-  msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
-                                    GTR_NAVIGATE_NEXT, NULL);
-
-  gtr_tab_message_go_to (tab, msg,
-                         FALSE, GTR_TAB_MOVE_NEXT);
+  if (_gtr_tab_finish_edition (tab))
+    {
+      msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
+                                        GTR_NAVIGATE_NEXT, NULL);
+      if (msg)
+        gtr_tab_message_go_to (tab, msg,
+                               FALSE, GTR_TAB_MOVE_NEXT);
+    }
 }
 
 /**
@@ -1659,11 +1663,14 @@ gtr_tab_go_to_prev (GtrTab * tab)
 {
   GtrMsg *msg;
 
-  msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
-                                    GTR_NAVIGATE_PREV, NULL);
-
-  gtr_tab_message_go_to (tab, msg,
-                         FALSE, GTR_TAB_MOVE_PREV);
+  if (_gtr_tab_finish_edition (tab))
+    {
+      msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
+                                        GTR_NAVIGATE_PREV, NULL);
+      if (msg)
+        gtr_tab_message_go_to (tab, msg,
+                               FALSE, GTR_TAB_MOVE_PREV);
+    }
 }
 
 /**
@@ -1677,10 +1684,14 @@ gtr_tab_go_to_first (GtrTab * tab)
 {
   GtrMsg *msg;
 
-  msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
-                                    GTR_NAVIGATE_FIRST, NULL);
-  gtr_tab_message_go_to (tab, msg,
-                         FALSE, GTR_TAB_MOVE_NONE);
+  if (_gtr_tab_finish_edition (tab))
+    {
+      msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
+                                        GTR_NAVIGATE_FIRST, NULL);
+      if (msg)
+        gtr_tab_message_go_to (tab, msg,
+                               FALSE, GTR_TAB_MOVE_NONE);
+    }
 }
 
 /**
@@ -1694,11 +1705,14 @@ gtr_tab_go_to_last (GtrTab * tab)
 {
   GtrMsg *msg;
 
-  msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
-                                    GTR_NAVIGATE_LAST, NULL);
-
-  gtr_tab_message_go_to (tab, msg,
-                         FALSE, GTR_TAB_MOVE_NONE);
+  if (_gtr_tab_finish_edition (tab))
+    {
+      msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
+                                        GTR_NAVIGATE_LAST, NULL);
+      if (msg)
+        gtr_tab_message_go_to (tab, msg,
+                               FALSE, GTR_TAB_MOVE_NONE);
+    }
 }
 
 /**
@@ -1714,10 +1728,12 @@ gtr_tab_go_to_next_fuzzy (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_NEXT,
                                     gtr_msg_is_fuzzy);
-
   if (msg != NULL)
     {
       gtr_tab_message_go_to (tab, msg, FALSE, GTR_TAB_MOVE_NONE);
@@ -1740,6 +1756,9 @@ gtr_tab_go_to_prev_fuzzy (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_PREV,
                                     gtr_msg_is_fuzzy);
@@ -1777,6 +1796,9 @@ gtr_tab_go_to_next_untrans (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_NEXT,
                                     message_is_untranslated);
@@ -1802,6 +1824,9 @@ gtr_tab_go_to_prev_untrans (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_PREV,
                                     message_is_untranslated);
@@ -1827,6 +1852,9 @@ gtr_tab_go_to_next_fuzzy_or_untrans (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_PREV,
                                     message_is_fuzzy_or_untranslated);
@@ -1852,6 +1880,9 @@ gtr_tab_go_to_prev_fuzzy_or_untrans (GtrTab * tab)
 {
   GtrMsg *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return FALSE;
+
   msg = gtr_message_table_navigate (GTR_MESSAGE_TABLE (tab->priv->message_table),
                                     GTR_NAVIGATE_PREV,
                                     message_is_fuzzy_or_untranslated);
@@ -1878,6 +1909,9 @@ gtr_tab_go_to_number (GtrTab * tab, gint number)
   GtrPo *po;
   GList *msg;
 
+  if (!_gtr_tab_finish_edition (tab))
+    return;
+
   po = gtr_tab_get_po (tab);
   msg = gtr_po_get_msg_from_number (po, number);
   if (msg != NULL)



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