[bijiben] Rename notes as first row is edited



commit 83004cdb987e55dcd16b0a4a75ef626fd714748c
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Sat Sep 14 23:07:15 2013 +0200

    Rename notes as first row is edited
    
    See #688902
    Do not perform any wrong magic here. When the first row is edited,
    change the note name.

 src/bjb-main-toolbar.c                  |   32 -----------
 src/libbiji/biji-note-book.c            |    1 -
 src/libbiji/biji-note-obj.c             |   87 +++++++++----------------------
 src/libbiji/biji-note-obj.h             |    8 ---
 src/libbiji/editor/biji-webkit-editor.c |   30 +++++-----
 5 files changed, 39 insertions(+), 119 deletions(-)
---
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index b525fb6..5535565 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -600,28 +600,6 @@ delete_item_callback (GtkWidget *item, gpointer user_data)
           BIJI_ITEM (self->priv->note));
 }
 
-static void
-action_rename_note_callback (GtkWidget *w, gpointer user_data)
-{
-  BjbMainToolbar        *bar;
-  BjbMainToolbarPrivate *priv;
-  gchar                 *title;
-  BijiItem *item;
-
-  bar = BJB_MAIN_TOOLBAR (user_data);
-  priv = bar->priv;
-  item = BIJI_ITEM (priv->note);
-
-  title = note_title_dialog (priv->window,
-                             _("Rename Note"),
-                             biji_item_get_title (item));
-
-  if (!title)
-    return;
-
-  biji_note_obj_set_title (priv->note, title);
-  biji_note_obj_save_note (priv->note); //FIXME libbiji needs to to this auto
-}
 
 GtkWidget *
 bjb_note_menu_new (BjbMainToolbar *self)
@@ -675,12 +653,6 @@ bjb_note_menu_new (BjbMainToolbar *self)
 
   }
 
-  /* Rename, view tags, separtor */
-  item = gtk_menu_item_new_with_label(_("Rename"));
-  gtk_menu_shell_append(GTK_MENU_SHELL(result),item);
-  g_signal_connect(item,"activate",
-                   G_CALLBACK(action_rename_note_callback),self);
-
 
   if (biji_item_is_collectable (BIJI_ITEM (priv->note)))
   {
@@ -691,10 +663,6 @@ bjb_note_menu_new (BjbMainToolbar *self)
 
   }
 
-  item = gtk_separator_menu_item_new ();
-  gtk_menu_shell_append (GTK_MENU_SHELL (result), item);
-
-
   /* Delete Note */
   item = gtk_menu_item_new_with_label(_("Delete this Note"));
   gtk_menu_shell_append(GTK_MENU_SHELL(result),item);
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 65df7bf..8e72613 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -635,7 +635,6 @@ get_note_skeleton (BijiNoteBook *book)
   }
 
   biji_note_obj_set_all_dates_now (ret);
-  biji_note_obj_set_title_survives (ret, FALSE);
   return ret;
 }
 
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index ae4d1ef..94dba44 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -50,8 +50,7 @@ struct _BijiNoteObjPrivate
   /* Tags 
    * In Tomboy, templates are 'system:notebook:%s' tags.*/
   GHashTable            *labels;
-  gboolean              is_template ;
-  gboolean              does_title_survive;
+  gboolean              is_template;
 
   /* Signals */
   gulong note_renamed;
@@ -114,10 +113,6 @@ biji_note_obj_init (BijiNoteObj *self)
 
   priv->is_template = FALSE ;
 
-  /* Existing note keep their title.
-   * only brand new notes might see title changed */
-  priv->does_title_survive = TRUE;
-
   /* The editor is NULL so we know it's not opened
    * neither fully deserialized */
   priv->editor = NULL;
@@ -297,52 +292,39 @@ biji_note_obj_get_title (BijiItem *note)
 gboolean
 biji_note_obj_set_title (BijiNoteObj *note, const gchar *proposed_title)
 {
-  gboolean initial = FALSE;
-  note->priv->does_title_survive = TRUE;
-  gchar *title;
+  gchar *old_title, *title;
+  gboolean retval;
 
-  if (!biji_note_id_get_title (note->priv->id))
-    initial = TRUE;
+  title = NULL;
+  old_title = g_strdup (biji_note_id_get_title (note->priv->id));
 
-  if (g_strcmp0 (proposed_title, biji_note_id_get_title (note->priv->id))==0)
-    return FALSE;
 
-  /* If the note is really renamed, check the new title */
-  if (!initial)
+  if (g_strcmp0 (proposed_title, old_title) == 0)
   {
-    title = biji_note_book_get_unique_title (
-              biji_item_get_book (BIJI_ITEM (note)), proposed_title);
-    biji_note_id_set_last_metadata_change_date (note->priv->id,
-                                                g_get_real_time () / G_USEC_PER_SEC);
+    retval = FALSE;
+    goto out;
   }
 
-  /* Otherwise it's up to the caller to sanitize its title */
-  else
-  {
-    title = g_strdup (proposed_title);
-  }
 
-  /* Emit signal even if initial title, just to let know */
-  biji_note_id_set_title (note->priv->id, title);
-  g_free (title);
-  g_signal_emit (G_OBJECT (note), biji_obj_signals[NOTE_RENAMED],0);
-  return TRUE;
-}
-
-
-gboolean
-biji_note_obj_title_survives (BijiNoteObj *note)
-{
-  return note->priv->does_title_survive;
-}
+  title = biji_note_book_get_unique_title (
+              biji_item_get_book (BIJI_ITEM (note)), proposed_title);
+  biji_note_id_set_last_metadata_change_date (note->priv->id,
+                                              g_get_real_time () / G_USEC_PER_SEC);
 
 
-void
-biji_note_obj_set_title_survives (BijiNoteObj *obj, gboolean value)
-{
-  g_return_if_fail (BIJI_IS_NOTE_OBJ(obj));
+  /* Emit signal even if initial title, just to let know */
+  biji_note_id_set_title (note->priv->id, title);
+  g_signal_emit (G_OBJECT (note), biji_obj_signals[NOTE_RENAMED], 0);
+  retval = TRUE;
+
+out:
+  if (old_title != NULL)
+    g_free (old_title);
+  
+  if (title != NULL)
+    g_free (title);
 
-  obj->priv->does_title_survive = value;
+  return retval;
 }
 
 
@@ -865,28 +847,7 @@ _biji_note_obj_close (BijiNoteObj *note)
    * Actually we just need to remove it from book
    * since no change could trigger save */
   if (biji_note_id_get_content (priv->id) == NULL)
-  {
     biji_note_book_remove_item (book, item);
-  }
-
-  /* If the note only has one row. put some title */
-  else if (!biji_note_obj_title_survives (note))
-  {
-    gchar *title;
-    
-    title = biji_note_book_get_unique_title (book,
-                                             biji_note_id_get_content (priv->id));
-    biji_note_obj_set_title (note, title);
-    g_free (title);
-  }
-
-  /* Else the note is not empty & has more than a row.
-   * But the first row might still be empty.*/
-  else if (!biji_note_id_get_title (priv->id) ||
-           g_strcmp0 (biji_note_id_get_title (priv->id),"")==0)
-  {
-    biji_note_obj_set_title (note, biji_note_id_get_content (priv->id));
-  }
 }
 
 GtkWidget *
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index 53642d1..aa1d553 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -79,14 +79,6 @@ gboolean         biji_note_obj_are_same                      (BijiNoteObj *a,
                                                               BijiNoteObj* b);
 
 
-/* will enter hit make title renamed? */
-gboolean         biji_note_obj_title_survives                (BijiNoteObj *note);
-
-
-void             biji_note_obj_set_title_survives            (BijiNoteObj *obj,
-                                                              gboolean value);
-
-
 gboolean         biji_note_obj_set_mtime                     (BijiNoteObj* n,
                                                               gint64 time);
 
diff --git a/src/libbiji/editor/biji-webkit-editor.c b/src/libbiji/editor/biji-webkit-editor.c
index 0c11b68..1d3f4cc 100644
--- a/src/libbiji/editor/biji-webkit-editor.c
+++ b/src/libbiji/editor/biji-webkit-editor.c
@@ -250,6 +250,7 @@ on_content_changed (WebKitWebView *view)
   WebKitDOMDocument    *dom;
   WebKitDOMHTMLElement *elem;
   gchar                *html, *text;
+  gchar                **rows;
 
   /* First html serializing */
   dom = webkit_web_view_get_dom_document (view);
@@ -260,32 +261,31 @@ on_content_changed (WebKitWebView *view)
   biji_note_obj_set_html (note, html);
   biji_note_obj_set_raw_text (note, text);
 
-  /* Now tries to update title if new note
-   * and several rows */
-  if (!biji_note_obj_title_survives (note))
-  {
-    gchar **rows;
+  /* Now tries to update title */
 
-    rows = g_strsplit (text, "\n", 2);
+  rows = g_strsplit (text, "\n", 2);
 
-    /* if we have a line feed, we have a proper title */
-    /* this is equivalent to g_strv_length (rows) > 1 */
-    if (rows && rows[0] && rows[1])
-    {
-      char *title;
-      char *unique_title;
+  /* if we have a line feed, we have a proper title */
+  /* this is equivalent to g_strv_length (rows) > 1 */
+
+  if (rows && rows[0] && rows[1])
+  {
+    gchar *title;
+    gchar *unique_title;
+  
+    title = rows[0];
 
-      title = rows[0];
+    if (g_strcmp0 (title, biji_item_get_title (BIJI_ITEM (note))) != 0)
+    {
       unique_title = biji_note_book_get_unique_title (biji_item_get_book (BIJI_ITEM (note)),
                                                       title);
 
       biji_note_obj_set_title (note, unique_title);
       g_free (unique_title);
     }
-
-    g_strfreev (rows);
   }
 
+  g_strfreev (rows);
   g_free (html);
   g_free (text);
 


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