[bijiben] NoteTitle: don't ask for dialog on note creation



commit d09aea2df8a34dec81ec4a2234fd3739fcf4bea9
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Tue Nov 20 01:56:47 2012 +0100

    NoteTitle: don't ask for dialog on note creation
    
    Either the user inputs several rows and first one is the title
    Or, closes note with a single row then it becomes the title
    The only proper way is to track new notes versus old notes
    as soon as we want to keep names for old notes
    And allow user to rename notes

 src/bjb-main-toolbar.c                  |   10 +--------
 src/libbiji/biji-note-book.c            |    4 ++-
 src/libbiji/biji-note-obj.c             |   34 +++++++++++++++++++++++++++++++
 src/libbiji/biji-note-obj.h             |    4 +++
 src/libbiji/editor/biji-webkit-editor.c |   15 +++++++++++++
 5 files changed, 57 insertions(+), 10 deletions(-)
---
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 6040c11..e948735 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -74,20 +74,12 @@ G_DEFINE_TYPE (BjbMainToolbar, bjb_main_toolbar, G_TYPE_OBJECT);
 static void
 on_new_note_clicked (GtkWidget *but, BjbMainView *view)
 {
-  gchar *title;
   BijiNoteObj *result ;
   BijiNoteBook *book ;
 
-  title = note_title_dialog(GTK_WINDOW(bjb_main_view_get_window(view)),
-                            "New Note : Title",
-                            "New Note");
-
-  if (!title)
-    return;
-
   /* append note to collection */
   book = bjb_window_base_get_book(bjb_main_view_get_window(view));
-  result = biji_note_book_get_new_note_from_string (book, title);
+  result = biji_note_book_get_new_note_from_string (book, "");
 
   /* Go to that note */
   switch_to_note_view(view,result);
diff --git a/src/libbiji/biji-note-book.c b/src/libbiji/biji-note-book.c
index 5f5b5db..c5a5546 100644
--- a/src/libbiji/biji-note-book.c
+++ b/src/libbiji/biji-note-book.c
@@ -663,6 +663,7 @@ get_note_skeleton (BijiNoteBook *book)
   }
 
   biji_note_obj_set_all_dates_now (ret);
+  biji_note_obj_set_title_survives (ret, FALSE);
   return ret;
 }
 
@@ -677,7 +678,8 @@ biji_note_book_get_new_note_from_string (BijiNoteBook *book,
   BijiNoteObj *ret = get_note_skeleton (book);
 
   /* Note will copy title */
-  biji_note_obj_set_title (ret, title);
+  if (title && g_strcmp0 (title, "") != 0)
+    biji_note_obj_set_title (ret, title);
 
   biji_note_obj_save_note (ret);
   note_book_append_new_note (book,ret);
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index dd3b5c3..f44b41a 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -58,6 +58,7 @@ struct _BijiNoteObjPrivate
    * Templates are just "system:notebook:" tags.*/
   GList                 *tags ;
   gboolean              is_template ;
+  gboolean              does_title_survive;
 
   /* Signals */
   gulong note_renamed;
@@ -109,6 +110,10 @@ biji_note_obj_init (BijiNoteObj *self)
   priv->book = NULL ;
   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->html = NULL;
@@ -391,6 +396,7 @@ gboolean
 biji_note_obj_set_title(BijiNoteObj *note,gchar *title)
 {
   gboolean initial = FALSE;
+  note->priv->does_title_survive = TRUE;
 
   if (!biji_note_id_get_title(note->priv->id))
     initial = TRUE;
@@ -410,6 +416,20 @@ biji_note_obj_set_title(BijiNoteObj *note,gchar *title)
 }
 
 gboolean
+biji_note_obj_title_survives (BijiNoteObj *note)
+{
+  return note->priv->does_title_survive;
+}
+
+void
+biji_note_obj_set_title_survives (BijiNoteObj *obj, gboolean value)
+{
+  g_return_if_fail (BIJI_IS_NOTE_OBJ(obj));
+
+  obj->priv->does_title_survive = value;
+}
+
+gboolean
 biji_note_obj_set_last_change_date (BijiNoteObj* n,gchar* date)
 {
   g_return_val_if_fail (BIJI_IS_NOTE_OBJ(n), FALSE);
@@ -829,6 +849,20 @@ static void
 _biji_note_obj_close (BijiNoteObj *note)
 {
   note->priv->editor = NULL;
+
+  /* TODO : check if note is totaly blank
+   * then delete it */
+
+  /* The title might remain unsert if
+   * - new note
+   * - only one row
+   * In such case we want to change title */
+  if ( ! biji_note_obj_title_survives (note)
+      && note->priv->raw_text
+      && g_strcmp0 (note->priv->raw_text, "") != 0)
+  {
+    biji_note_obj_set_title (note, note->priv->raw_text);
+  }
 }
 
 GtkWidget *
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index a5f8db8..0e8b962 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -86,6 +86,10 @@ gboolean note_obj_are_same(BijiNoteObj *a, BijiNoteObj* b);
 
 gchar * biji_note_obj_get_title (BijiNoteObj *obj);
 
+/* 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);
+
 gchar* biji_note_obj_get_path (BijiNoteObj *n);
 
 gboolean biji_note_obj_set_last_change_date (BijiNoteObj* n,gchar* date);
diff --git a/src/libbiji/editor/biji-webkit-editor.c b/src/libbiji/editor/biji-webkit-editor.c
index d928b42..5e4bb3f 100644
--- a/src/libbiji/editor/biji-webkit-editor.c
+++ b/src/libbiji/editor/biji-webkit-editor.c
@@ -253,6 +253,21 @@ on_content_changed (WebKitWebView *view)
   biji_note_obj_set_html_content (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;
+
+    rows = g_strsplit (html, "<div", 2);
+    g_warning ("title is %s", rows[0]);
+
+    if (g_strv_length (rows) > 1)
+      biji_note_obj_set_title (note, rows[0]);
+
+    g_strfreev (rows);
+  }
+
   g_free (html);
   g_free (text);
 



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