[bijiben] selectionToolbar - mainView : cleanup



commit 442789c441c4439faf6dfff9f7f0ac692695cba8
Author: Pierre-Yves Luyten <py luyten fr>
Date:   Mon May 27 23:06:45 2013 +0200

    selectionToolbar - mainView : cleanup

 src/bjb-main-toolbar.c      |    2 +-
 src/bjb-main-view.c         |  105 -------------------------------------------
 src/bjb-main-view.h         |   11 +----
 src/bjb-selection-toolbar.c |   84 ++++++++++++++++++++++++++++++----
 4 files changed, 76 insertions(+), 126 deletions(-)
---
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 8a624b6..62378ca 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -108,7 +108,7 @@ update_selection_label (BjbMainToolbar *self)
   gint length;
   gchar *label;
 
-  selected = bjb_main_view_get_selection (self->priv->parent);
+  selected = bjb_main_view_get_selected_items (self->priv->parent);
   length = g_list_length (selected);
   g_list_free (selected);
 
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 9156127..d3ee396 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -246,28 +246,6 @@ get_note_url_from_tree_path(GtkTreePath *path, BjbMainView *self)
   return note_path ;
 }
 
-void
-action_tag_selected_items (GtkWidget *w, BjbMainView *view)
-{
-  GList *notes = NULL;
-  GList *paths, *l;
-
-  /*  GtkTreePath */
-  paths = get_selected_paths(view);
-
-  for (l=paths ; l != NULL ; l=l->next)
-  {
-    gchar *url = get_note_url_from_tree_path (l->data, view) ;
-    notes = g_list_prepend (notes, biji_note_book_get_item_at_path
-                                 (bjb_window_base_get_book(view->priv->window),url));
-    g_free (url);
-  }
-
-  g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
-  bjb_note_tag_dialog_new (GTK_WINDOW (view->priv->window), notes);
-  g_list_free (notes);
-}
-
 
 GList *
 bjb_main_view_get_selected_items (BjbMainView *view)
@@ -295,84 +273,6 @@ bjb_main_view_get_selected_items (BjbMainView *view)
   return result;
 }
 
-gboolean
-bjb_main_view_get_selected_items_color (BjbMainView *view, GdkRGBA *color)
-{
-  GList *paths;
-  gchar *url;
-  BijiItem *item;
-
-  /*  GtkTreePath */
-  paths = get_selected_paths(view);
-  url = get_note_url_from_tree_path (paths->data, view) ;
-  item = biji_note_book_get_item_at_path (bjb_window_base_get_book(view->priv->window), url);
-  g_free (url);
-  g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
-
-  if (BIJI_IS_NOTE_OBJ (item))
-    return biji_note_obj_get_rgba (BIJI_NOTE_OBJ (item), color);
-
-  return FALSE;
-}
-
-void
-action_color_selected_items (GtkWidget *w, BjbMainView *view)
-{
-  GList *items = NULL ;
-  GList *paths, *l;
-
-  GdkRGBA color;
-  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (w), &color);
-
-  /*  GtkTreePath */
-  paths = get_selected_paths(view);
-
-  for (l=paths ; l != NULL ; l=l->next)
-  {
-    gchar *url = get_note_url_from_tree_path (l->data, view) ;
-    items = g_list_prepend (items, biji_note_book_get_item_at_path
-                                   (bjb_window_base_get_book(view->priv->window),url));
-    g_free (url);
-  }
-
-  g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
-
-  for (l=items ; l != NULL ; l=l->next)
-  {
-    if (BIJI_IS_NOTE_OBJ (l->data))
-      biji_note_obj_set_rgba (BIJI_NOTE_OBJ (l->data), &color);
-  }
-
-  g_list_free (items);
-}
-
-void
-action_delete_selected_items (GtkWidget *w, BjbMainView *view)
-{
-  GList *items = NULL;
-  GList *paths, *l;
-
-  /*  GtkTreePath */
-  paths = get_selected_paths(view);
-
-  for (l=paths ; l != NULL ; l=l->next)
-  {
-    gchar *url = get_note_url_from_tree_path (l->data, view) ;
-    items = g_list_prepend (items, biji_note_book_get_item_at_path
-                               (bjb_window_base_get_book(view->priv->window),url));
-    g_free (url);
-  }
-
-  g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
-
-  for (l=items ; l != NULL ; l=l->next)
-  {
-    biji_note_book_remove_item (bjb_window_base_get_book (view->priv->window),
-                                BIJI_ITEM (l->data));
-  }
-
-  g_list_free (items);
-}
 
 static void
 on_selection_mode_changed_cb (BjbMainView *self)
@@ -661,8 +561,3 @@ bjb_main_view_set_view_type (BjbMainView *view, GdMainViewType type)
   gd_main_view_set_view_type (view->priv->view, type);
 }
 
-GList *
-bjb_main_view_get_selection (BjbMainView *view)
-{
-  return gd_main_view_get_selection (view->priv->view);
-}
diff --git a/src/bjb-main-view.h b/src/bjb-main-view.h
index 980c243..c0cb36f 100644
--- a/src/bjb-main-view.h
+++ b/src/bjb-main-view.h
@@ -60,17 +60,9 @@ GtkWidget *bjb_main_view_get_window(BjbMainView *view);
 
 void action_new_window_callback(GtkAction *action, gpointer bjb_main_view);
 
-GList *bjb_main_view_get_selected_items (BjbMainView *view);
-
-/* Currently it simply looks for first selected note found. Maybe most common color?
- * Or use default color when several ones including at least one default color?*/
-gboolean bjb_main_view_get_selected_items_color (BjbMainView *view, GdkRGBA *color); // killme... killme...
 
-void action_color_selected_items (GtkWidget *w,BjbMainView *view);
-
-void action_tag_selected_items (GtkWidget *w, BjbMainView *view);
+GList *bjb_main_view_get_selected_items (BjbMainView *view);
 
-void action_delete_selected_items (GtkWidget *w,BjbMainView *view);
 
 gboolean bjb_main_view_get_iter_at_note (BjbMainView  *view,
                                          BijiNoteObj  *note,
@@ -95,7 +87,6 @@ GdMainViewType bjb_main_view_get_view_type (BjbMainView *view);
 
 void bjb_main_view_set_view_type (BjbMainView *view, GdMainViewType type);
 
-GList *bjb_main_view_get_selection (BjbMainView *view); // killme... killme...
 
 G_END_DECLS
 
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index a105e4c..44fce13 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -25,8 +25,10 @@
 #include <libgd/gd.h>
 
 #include "bjb-color-button.h"
+#include "bjb-note-tag-dialog.h"
 #include "bjb-main-view.h"
 #include "bjb-selection-toolbar.h"
+#include "bjb-window-base.h"
 
 enum
 {
@@ -59,6 +61,56 @@ struct _BjbSelectionToolbarPrivate
 
 G_DEFINE_TYPE (BjbSelectionToolbar, bjb_selection_toolbar, GTK_TYPE_TOOLBAR);
 
+
+static void
+action_color_selected_items (GtkWidget *w, BjbSelectionToolbar *self)
+{
+  GList *l, *selection;
+  GdkRGBA color = {0,0,0,0};
+
+  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (w), &color);
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+
+  for (l=selection; l !=NULL; l=l->next)
+  {
+    if (BIJI_IS_NOTE_OBJ (l->data))
+      biji_note_obj_set_rgba (l->data, &color);
+  }
+
+  g_list_free (selection);
+}
+
+static void
+action_tag_selected_items (GtkWidget *w, BjbSelectionToolbar *self)
+{
+  GList *selection;
+
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+  bjb_note_tag_dialog_new
+    (GTK_WINDOW (bjb_main_view_get_window (self->priv->view)), selection);
+
+  g_list_free (selection);
+}
+
+
+static void
+action_delete_selected_items (GtkWidget *w, BjbSelectionToolbar *self)
+{
+  GList *l, *selection;
+  BijiNoteBook *book;
+
+  selection = bjb_main_view_get_selected_items (self->priv->view);
+  book = bjb_window_base_get_book (bjb_main_view_get_window (self->priv->view));
+
+  for (l=selection; l !=NULL; l=l->next)
+  {
+    biji_note_book_remove_item (book, BIJI_ITEM (l->data));
+  }
+
+  g_list_free (selection);
+}
+
+
 static void
 bjb_selection_toolbar_fade_in (BjbSelectionToolbar *self)
 {
@@ -72,6 +124,7 @@ bjb_selection_toolbar_fade_out (BjbSelectionToolbar *self)
   gtk_widget_set_opacity (self->priv->widget, 0);
 }
 
+
 static void
 bjb_selection_toolbar_set_item_visibility (BjbSelectionToolbar *self)
 {
@@ -88,16 +141,27 @@ bjb_selection_toolbar_set_item_visibility (BjbSelectionToolbar *self)
    * Color, awlays */
   gtk_widget_set_visible (priv->toolbar_trash, TRUE);
 
-  if (bjb_main_view_get_selected_items_color (priv->view, &color))
-    gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->toolbar_color), &color);
+  for (l=selection; l !=NULL; l=l->next)
+  {
+    if (BIJI_IS_NOTE_OBJ (l->data))
+    {
+      if (biji_note_obj_get_rgba (BIJI_NOTE_OBJ (l->data), &color))
+      {
+        gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->toolbar_color), &color);
+        break;
+      }
+    }
+  }
+
 
   /* Organize */
-  gtk_widget_set_opacity (priv->toolbar_tag, 1);
+  gtk_widget_set_visible (priv->toolbar_tag, 1);
+
   for (l=selection; l!=NULL; l=l->next)
   {
     if (BIJI_IS_COLLECTION (l->data))
     {
-      gtk_widget_set_opacity (priv->toolbar_tag, 0);
+      gtk_widget_set_visible (priv->toolbar_tag, 0);
       break;
     }
   }
@@ -260,14 +324,14 @@ bjb_selection_toolbar_constructed(GObject *obj)
                     G_CALLBACK(bjb_selection_toolbar_selection_changed),
                     self);
 
-  g_signal_connect(priv->toolbar_color,"color-set",
-                   G_CALLBACK(action_color_selected_items),priv->view);
+  g_signal_connect (priv->toolbar_color,"color-set",
+                    G_CALLBACK (action_color_selected_items), self);
 
-  g_signal_connect(priv->toolbar_tag,"clicked",
-                   G_CALLBACK(action_tag_selected_items),priv->view);
+  g_signal_connect (priv->toolbar_tag,"clicked",
+                    G_CALLBACK (action_tag_selected_items), self);
 
-  g_signal_connect(priv->toolbar_trash,"clicked",
-                   G_CALLBACK(action_delete_selected_items),priv->view);
+  g_signal_connect (priv->toolbar_trash,"clicked",
+                    G_CALLBACK (action_delete_selected_items), self);
 }
 
 static void


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