[gnote] Embed note toolbar into main window



commit 8212a22c74c98bbabdcde1cd12df0933db515c7c
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun May 19 22:13:06 2013 +0300

    Embed note toolbar into main window
    
    Part of Bug 699119.

 src/noteaddin.cpp                   |   11 +++++---
 src/notebooks/notebooknoteaddin.cpp |   22 +++++++++-------
 src/notebooks/notebooknoteaddin.hpp |    3 +-
 src/notewindow.cpp                  |   45 +++++++++++++++++++---------------
 src/notewindow.hpp                  |   15 ++++++-----
 5 files changed, 54 insertions(+), 42 deletions(-)
---
diff --git a/src/noteaddin.cpp b/src/noteaddin.cpp
index 2e1e699..82ef294 100644
--- a/src/noteaddin.cpp
+++ b/src/noteaddin.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012 Aurimas Cernius
+ * Copyright (C) 2012-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -91,8 +91,10 @@ namespace gnote {
     for(ToolItemMap::const_iterator iter = m_toolbar_items.begin();
         iter != m_toolbar_items.end(); ++iter) {
       if ((iter->first->get_parent() == NULL) ||
-          (iter->first->get_parent() != window->toolbar())) {
-        window->toolbar()->insert (*(iter->first), iter->second);
+          (iter->first->get_parent() != window->embeddable_toolbar())) {
+        Gtk::Grid *grid = window->embeddable_toolbar();
+        int col = grid->get_children().size();
+        grid->attach(*(iter->first), col, 0, 1, 1);
       }
     }
   }
@@ -118,7 +120,8 @@ namespace gnote {
     m_toolbar_items [item] = position;
       
     if (m_note->is_opened()) {
-      get_window()->toolbar()->insert (*item, position);
+      Gtk::Grid *grid = get_window()->embeddable_toolbar();
+      grid->attach(*item, grid->get_children().size(), 0, 1, 1);
     }
   }
 
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index 56d83ce..58d35f3 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -66,11 +66,16 @@ namespace notebooks {
 
   void NotebookNoteAddin::initialize_tool_button()
   {
-    m_toolButton = Gtk::manage(
-      new gnote::utils::ToolMenuButton(*manage(new Gtk::Image(
-          IconManager::obj().get_icon(IconManager::NOTEBOOK, 22))), "",
-                                       m_menu));
-    m_toolButton->set_is_important(true);
+    gint icon_size = 16;
+    gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &icon_size, NULL);
+
+    Gtk::Grid *grid = manage(new Gtk::Grid);
+    grid->attach(*manage(new Gtk::Image(
+      IconManager::obj().get_icon(IconManager::NOTEBOOK, icon_size))),
+                 0, 0, 1, 1);
+    m_label_widget = manage(new Gtk::Label("try"));
+    grid->attach(*m_label_widget, 1, 0, 1, 1);
+    m_toolButton = Gtk::manage(new gnote::utils::ToolMenuButton(*grid, m_menu));
     m_toolButton->set_tooltip_text(_("Place this note into a notebook"));
 
     m_show_menu_cid = m_menu->signal_show()
@@ -183,11 +188,8 @@ namespace notebooks {
   {
     std::string labelText = (notebook ? notebook->get_name() : _("Notebook"));
     
-    Gtk::Label * l = dynamic_cast<Gtk::Label*>(m_toolButton->get_label_widget());
-    if (l) {
-      l->set_text(labelText);
-      m_toolButton->show_all();
-    }
+    m_label_widget->set_text(labelText);
+    m_toolButton->show_all();
   }
 
   void NotebookNoteAddin::update_menu()
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index 9422724..5603c42 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2012 Aurimas Cernius
+ * Copyright (C) 2011-2013 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -63,6 +63,7 @@ namespace notebooks {
     void update_menu();
     void get_notebook_menu_items(std::list<NotebookMenuItem*> &);
     gnote::utils::ToolMenuButton  *m_toolButton;
+    Gtk::Label               *m_label_widget;
     Gtk::Menu                *m_menu;
     std::list<Gtk::MenuItem *> m_menu_items;
     Gtk::RadioButtonGroup     m_radio_group;
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index 697ab05..ba4d415 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -23,6 +23,7 @@
 #endif
 
 #include <glibmm/i18n.h>
+#include <gtkmm/grid.h>
 #include <gtkmm/image.h>
 #include <gtkmm/stock.h>
 #include <gtkmm/separatortoolitem.h>
@@ -85,8 +86,7 @@ namespace gnote {
 
     m_plugin_menu = manage(make_plugin_menu());
 
-    m_toolbar = manage(make_toolbar());
-    m_toolbar->show();
+    m_embeddable_toolbar = manage(make_toolbar());
 
     m_template_widget = make_template_bar();
 
@@ -113,7 +113,6 @@ namespace gnote {
 
     set_focus_child(*m_editor);
 
-    pack_start(*m_toolbar, false, false, 0);
     pack_start(*m_template_widget, false, false, 0);
     pack_start(*m_editor_window, true, true, 0);
   }
@@ -257,6 +256,11 @@ namespace gnote {
     return get_find_handler().goto_previous_result();
   }
 
+  Gtk::Grid *NoteWindow::embeddable_toolbar()
+  {
+    return m_embeddable_toolbar;
+  }
+
 
     // Delete this Note.
     //
@@ -329,9 +333,12 @@ namespace gnote {
   // Add Link button, Font menu, Delete button to the window's
   // toolbar.
   //
-  Gtk::Toolbar *NoteWindow::make_toolbar()
+  Gtk::Grid *NoteWindow::make_toolbar()
   {
-    Gtk::Toolbar *tb = new Gtk::Toolbar();
+    Gtk::IconSize icon_size = Gtk::IconSize::from_name(gtk_icon_size_get_name(GTK_ICON_SIZE_MENU));
+
+    Gtk::Grid *grid = manage(new Gtk::Grid);
+    int grid_col = 0;
 
     m_pin_image = manage(new Gtk::Image);
     if(m_note.is_pinned()) {
@@ -343,12 +350,12 @@ namespace gnote {
 
     m_pin_button = manage(new Gtk::ToolButton(*m_pin_image, _("Pin")));
     m_pin_button->signal_clicked().connect(sigc::mem_fun(*this, &NoteWindow::on_pin_button_clicked));
-    tb->insert(*m_pin_button, -1);
+    grid->attach(*m_pin_button, grid_col++, 0, 1, 1);
     notebooks::NotebookManager::obj().signal_note_pin_status_changed
       .connect(sigc::mem_fun(*this, &NoteWindow::on_pin_status_changed));
 
     m_link_button = manage(new Gtk::ToolButton(
-                             *manage(new Gtk::Image (Gtk::Stock::JUMP_TO, tb->get_icon_size())),
+                             *manage(new Gtk::Image(Gtk::Stock::JUMP_TO, icon_size)),
                              _("Link")));
     m_link_button->set_use_underline(true);
     m_link_button->set_is_important(true);
@@ -357,45 +364,43 @@ namespace gnote {
       sigc::mem_fun(*this, &NoteWindow::link_button_clicked));
     m_link_button->set_tooltip_text(_("Link selected text to a new note (Ctrl-L)"));
     m_link_button->show_all();
-    tb->insert(*m_link_button, -1);
+    grid->attach(*m_link_button, grid_col++, 0, 1, 1);
 
-    utils::ToolMenuButton *text_button = manage(new utils::ToolMenuButton(*tb,
-                                                  Gtk::Stock::SELECT_FONT,
-                                                  _("_Text"),
-                                                  m_text_menu));
+    utils::ToolMenuButton *text_button = manage(new utils::ToolMenuButton(
+        *manage(new Gtk::Image(Gtk::Stock::SELECT_FONT, icon_size)), _("_Text"), m_text_menu));
     text_button->set_use_underline(true);
     text_button->set_is_important(true);
     text_button->show_all();
-    tb->insert(*text_button, -1);
+    grid->attach(*text_button, grid_col++, 0, 1, 1);
     text_button->set_tooltip_text(_("Set properties of text"));
 
     utils::ToolMenuButton *plugin_button = Gtk::manage(
-      new utils::ToolMenuButton (*tb, Gtk::Stock::EXECUTE,
+      new utils::ToolMenuButton(*manage(new Gtk::Image(Gtk::Stock::EXECUTE, icon_size)),
                                  _("T_ools"),
                                  m_plugin_menu));
     plugin_button->set_use_underline(true);
     plugin_button->show_all();
-    tb->insert(*plugin_button, -1);
+    grid->attach(*plugin_button, grid_col++, 0, 1, 1);
     plugin_button->set_tooltip_text(_("Use tools on this note"));
 
-    tb->insert(*manage(new Gtk::SeparatorToolItem()), -1);
+    grid->attach(*manage(new Gtk::SeparatorToolItem()), grid_col++, 0, 1, 1);
 
     m_delete_button = manage(new Gtk::ToolButton(Gtk::Stock::DELETE));
     m_delete_button->set_use_underline(true);
     m_delete_button->signal_clicked().connect(
       sigc::mem_fun(*this, &NoteWindow::on_delete_button_clicked));
     m_delete_button->show_all();
-    tb->insert(*m_delete_button, -1);
+    grid->attach(*m_delete_button, grid_col++, 0, 1, 1);
     m_delete_button->set_tooltip_text(_("Delete this note"));
 
       // Don't allow deleting the "Start Here" note...
     if (m_note.is_special()) {
       m_delete_button->set_sensitive(false);
     }
-    tb->insert(*manage(new Gtk::SeparatorToolItem()), -1);
+    grid->attach(*manage(new Gtk::SeparatorToolItem()), grid_col++, 0, 1, 1);
 
-    tb->show_all();
-    return tb;
+    grid->show_all();
+    return grid;
   }
 
 
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index fe2ebae..3a5e586 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -25,8 +25,8 @@
 #define _NOTEWINDOW_HPP__
 
 #include <gtkmm/accelgroup.h>
+#include <gtkmm/grid.h>
 #include <gtkmm/searchentry.h>
-#include <gtkmm/toolbar.h>
 #include <gtkmm/toolbutton.h>
 #include <gtkmm/menu.h>
 #include <gtkmm/checkmenuitem.h>
@@ -35,6 +35,7 @@
 #include <gtkmm/textview.h>
 #include <gtkmm/scrolledwindow.h>
 
+#include "mainwindowembeds.hpp"
 #include "note.hpp"
 #include "undo.hpp"
 #include "utils.hpp"
@@ -131,6 +132,7 @@ class NoteWindow
   : public Gtk::VBox
   , public utils::EmbeddableWidget
   , public utils::SearchableItem
+  , public HasEmbeddableToolbar
 {
 public:
   NoteWindow(Note &);
@@ -146,6 +148,9 @@ public:
   virtual bool goto_next_result();
   virtual bool goto_previous_result();
 
+  // use co-variant return
+  virtual Gtk::Grid *embeddable_toolbar();
+
   void set_size(int width, int height)
     {
       m_width = width;
@@ -160,10 +165,6 @@ public:
     {
       return m_editor;
     }
-  Gtk::Toolbar * toolbar() const
-    {
-      return m_toolbar;
-    }
   Gtk::ToolButton * delete_button() const
     {
       return m_delete_button;
@@ -192,7 +193,7 @@ private:
   void on_selection_mark_set(const Gtk::TextIter&, const Glib::RefPtr<Gtk::TextMark>&);
   void update_link_button_sensitivity();
   void on_populate_popup(Gtk::Menu*);
-  Gtk::Toolbar * make_toolbar();
+  Gtk::Grid *make_toolbar();
   Gtk::Menu * make_plugin_menu();
   Gtk::Box * make_template_bar();
   void on_untemplate_button_click();
@@ -217,7 +218,7 @@ private:
   int                           m_x;
   int                           m_y;
   Glib::RefPtr<Gtk::AccelGroup> m_accel_group;
-  Gtk::Toolbar                 *m_toolbar;
+  Gtk::Grid                    *m_embeddable_toolbar;
   Gtk::Image                   *m_pin_image;
   Gtk::ToolButton              *m_pin_button;
   Gtk::ToolButton              *m_link_button;


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