[gnote] Update notebook note addin with popover support
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Update notebook note addin with popover support
- Date: Thu, 24 Dec 2015 14:18:45 +0000 (UTC)
commit 828060754303a59d1982fa7e3873f5c394d30632
Author: Aurimas Černius <aurisc4 gmail com>
Date: Thu Dec 24 16:17:30 2015 +0200
Update notebook note addin with popover support
src/actionmanager.cpp | 2 +
src/notebooks/notebooknoteaddin.cpp | 179 ++++++++++++++++++-----------------
src/notebooks/notebooknoteaddin.hpp | 16 ++-
3 files changed, 102 insertions(+), 95 deletions(-)
---
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 45f1ffd..05230c5 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -77,6 +77,8 @@ namespace gnote {
register_main_window_action("delete-note", NULL);
register_main_window_action("important-note", &Glib::Variant<bool>::variant_type());
register_main_window_action("enable-spell-check", &Glib::Variant<bool>::variant_type());
+ register_main_window_action("new-notebook", NULL);
+ register_main_window_action("move-to-notebook", &Glib::Variant<Glib::ustring>::variant_type());
}
diff --git a/src/notebooks/notebooknoteaddin.cpp b/src/notebooks/notebooknoteaddin.cpp
index a5a2d22..e434b94 100644
--- a/src/notebooks/notebooknoteaddin.cpp
+++ b/src/notebooks/notebooknoteaddin.cpp
@@ -21,8 +21,7 @@
#include <glibmm/i18n.h>
-#include <gtkmm/imagemenuitem.h>
-#include <gtkmm/separatormenuitem.h>
+#include <gtkmm/modelbutton.h>
#include "notebooks/notebooknoteaddin.hpp"
#include "notebooks/notebookmanager.hpp"
@@ -34,61 +33,6 @@
#include "notewindow.hpp"
-namespace {
-
-class NotebookNoteAction
- : public Gtk::Action
-{
-public:
- static Glib::RefPtr<Gtk::Action> create(const sigc::slot<void, Gtk::Menu*> & slot)
- {
- return Glib::RefPtr<Gtk::Action>(new NotebookNoteAction(slot));
- }
- virtual Gtk::Widget *create_menu_item_vfunc() override
- {
- m_submenu_built = false;
- Gtk::MenuItem *menu_item = new Gtk::ImageMenuItem;
- m_menu = manage(new Gtk::Menu);
- m_menu->signal_hide().connect(
- sigc::mem_fun(*this, &NotebookNoteAction::on_menu_hidden));
- menu_item->set_submenu(*m_menu);
- return menu_item;
- }
-protected:
- virtual void on_activate() override
- {
- Gtk::Action::on_activate();
- if(m_submenu_built) {
- return;
- }
- update_menu();
- }
-private:
- explicit NotebookNoteAction(const sigc::slot<void, Gtk::Menu*> & slot)
- : m_submenu_built(false)
- , m_update_menu_slot(slot)
- {
- set_name("NotebookAction");
- set_label(_("Notebook"));
- set_tooltip(_("Place this note into a notebook"));
- }
- void on_menu_hidden()
- {
- m_submenu_built = false;
- }
- void update_menu()
- {
- m_update_menu_slot(m_menu);
- m_submenu_built = true;
- }
-
- Gtk::Menu *m_menu;
- bool m_submenu_built;
- sigc::slot<void, Gtk::Menu*> m_update_menu_slot;
-};
-
-}
-
namespace gnote {
namespace notebooks {
@@ -126,66 +70,121 @@ namespace notebooks {
void NotebookNoteAddin::on_note_opened()
{
+ auto note_win = get_window();
+ note_win->signal_foregrounded.connect(sigc::mem_fun(*this,
&NotebookNoteAddin::on_note_window_foregrounded));
+ note_win->signal_backgrounded.connect(sigc::mem_fun(*this,
&NotebookNoteAddin::on_note_window_backgrounded));
+ }
+
+
+ void NotebookNoteAddin::on_note_window_foregrounded()
+ {
+ EmbeddableWidgetHost *host = get_window()->host();
+ m_new_notebook_cid = host->find_action("new-notebook")->signal_activate()
+ .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_new_notebook_menu_item));
+ Notebook::Ptr current_notebook = NotebookManager::obj().get_notebook_from_note(get_note());
+ Glib::ustring name;
+ if(current_notebook) {
+ name = current_notebook->get_name();
+ }
+ MainWindowAction::Ptr action = host->find_action("move-to-notebook");
+ action->set_state(Glib::Variant<Glib::ustring>::create(name));
+ m_move_to_notebook_cid = action->signal_change_state()
+ .connect(sigc::mem_fun(*this, &NotebookNoteAddin::on_move_to_notebook));
+ }
+
+
+ void NotebookNoteAddin::on_note_window_backgrounded()
+ {
+ m_new_notebook_cid.disconnect();
+ m_move_to_notebook_cid.disconnect();
+ }
+
+
+ std::map<int, Gtk::Widget*> NotebookNoteAddin::get_actions_popover_widgets() const
+ {
+ auto widgets = NoteAddin::get_actions_popover_widgets();
if(!get_note()->contains_tag(get_template_tag())) {
- add_note_action(NotebookNoteAction::create(sigc::mem_fun(*this, &NotebookNoteAddin::update_menu)),
- gnote::NOTEBOOK_ORDER);
+ Gtk::Widget *notebook_button = utils::create_popover_submenu_button("notebooks-submenu",
_("Notebook"));
+ utils::add_item_to_ordered_map(widgets, gnote::NOTEBOOK_ORDER, notebook_button);
+
+ auto submenu = utils::create_popover_submenu("notebooks-submenu");
+ update_menu(submenu);
+ utils::add_item_to_ordered_map(widgets, 1000000, submenu);
}
+
+ return widgets;
}
- void NotebookNoteAddin::on_new_notebook_menu_item()
+ void NotebookNoteAddin::on_new_notebook_menu_item(const Glib::VariantBase&) const
{
Note::List noteList;
noteList.push_back(get_note());
NotebookManager::obj().prompt_create_new_notebook(
dynamic_cast<Gtk::Window*>(get_window()->host()), noteList);
+ get_window()->signal_popover_widgets_changed();
}
- void NotebookNoteAddin::update_menu(Gtk::Menu *menu)
+ void NotebookNoteAddin::on_move_to_notebook(const Glib::VariantBase & state)
{
- // Clear the old items
- FOREACH(Gtk::Widget *menu_item, menu->get_children()) {
- menu->remove(*menu_item);
+ get_window()->host()->find_action("move-to-notebook")->set_state(state);
+ Glib::ustring name = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(state).get();
+ Notebook::Ptr notebook;
+ if(name.size()) {
+ notebook = NotebookManager::obj().get_notebook(name);
}
+ NotebookManager::obj().move_note_to_notebook(get_note(), notebook);
+ }
+
+
+ void NotebookNoteAddin::update_menu(Gtk::Grid *menu) const
+ {
+ int top = 0;
+ int sub_top = 0;
+ Gtk::Grid *subgrid = manage(new Gtk::Grid);
+ subgrid->property_margin_top() = 10;
+ subgrid->property_margin_bottom() = 10;
// Add new notebook item
- Gtk::ImageMenuItem *new_notebook_item = manage(new Gtk::ImageMenuItem(_("_New notebook..."), true));
- new_notebook_item->set_image(*manage(new Gtk::Image(
- IconManager::obj().get_icon(IconManager::NOTEBOOK_NEW, 16))));
- new_notebook_item->signal_activate().connect(sigc::mem_fun(*this,
&NotebookNoteAddin::on_new_notebook_menu_item));
- new_notebook_item->show();
- menu->append(*new_notebook_item);
+ Gtk::Widget *new_notebook_item = manage(utils::create_popover_button("win.new-notebook", _("_New
notebook...")));
+ subgrid->attach(*new_notebook_item, 0, sub_top++, 1, 1);
+ menu->attach(*subgrid, 0, top++, 1, 1);
// Add the "(no notebook)" item at the top of the list
- NotebookMenuItem *no_notebook_item = manage(new NotebookMenuItem(get_note(), Notebook::Ptr()));
- no_notebook_item->show_all();
- menu->append(*no_notebook_item);
+ subgrid = manage(new Gtk::Grid);
+ sub_top = 0;
+ subgrid->property_margin_top() = 10;
+ subgrid->property_margin_bottom() = 10;
+ Gtk::ModelButton *no_notebook_item = dynamic_cast<Gtk::ModelButton*>(manage(
+ utils::create_popover_button("win.move-to-notebook", _("No notebook"))));
+ gtk_actionable_set_action_target_value(GTK_ACTIONABLE(no_notebook_item->gobj()),
g_variant_new_string(""));
+ subgrid->attach(*no_notebook_item, 0, sub_top++, 1, 1);
- NotebookMenuItem *active_menu_item = no_notebook_item;
- Notebook::Ptr current_notebook = NotebookManager::obj().get_notebook_from_note(get_note());
-
// Add in all the real notebooks
- std::list<NotebookMenuItem*> notebook_menu_items;
+ std::list<Gtk::ModelButton*> notebook_menu_items;
get_notebook_menu_items(notebook_menu_items);
if(!notebook_menu_items.empty()) {
- Gtk::SeparatorMenuItem *separator = manage(new Gtk::SeparatorMenuItem());
- separator->show_all();
- menu->append(*separator);
-
- FOREACH(NotebookMenuItem *item, notebook_menu_items) {
- item->show_all();
- menu->append(*item);
- if(current_notebook == item->get_notebook())
- active_menu_item = item;
+ FOREACH(Gtk::ModelButton *item, notebook_menu_items) {
+ subgrid->attach(*item, 0, sub_top++, 1, 1);
}
+
}
- active_menu_item->set_active(true);
+ menu->attach(*subgrid, 0, top++, 1, 1);
+
+ subgrid = manage(new Gtk::Grid);
+ sub_top = 0;
+ subgrid->property_margin_top() = 10;
+ subgrid->property_margin_bottom() = 10;
+ Gtk::Widget *back_button = utils::create_popover_submenu_button("main", _("_Back"));
+ dynamic_cast<Gtk::ModelButton*>(back_button)->property_inverted() = true;
+ subgrid->attach(*back_button, 0, sub_top++, 1, 1);
+ menu->attach(*subgrid, 0, top++, 1, 1);
}
- void NotebookNoteAddin::get_notebook_menu_items(std::list<NotebookMenuItem*>& items)
+ void NotebookNoteAddin::get_notebook_menu_items(std::list<Gtk::ModelButton*>& items) const
{
Glib::RefPtr<Gtk::TreeModel> model = NotebookManager::obj().get_notebooks();
Gtk::TreeIter iter;
@@ -196,7 +195,9 @@ namespace notebooks {
for(iter = model->children().begin(); iter != model->children().end(); ++iter) {
Notebook::Ptr notebook;
iter->get_value(0, notebook);
- NotebookMenuItem *item = manage(new NotebookMenuItem(get_note(), notebook));
+ Gtk::ModelButton *item = dynamic_cast<Gtk::ModelButton*>(manage(
+ utils::create_popover_button("win.move-to-notebook", notebook->get_name())));
+ gtk_actionable_set_action_target_value(GTK_ACTIONABLE(item->gobj()),
g_variant_new_string(notebook->get_name().c_str()));
items.push_back(item);
}
}
diff --git a/src/notebooks/notebooknoteaddin.hpp b/src/notebooks/notebooknoteaddin.hpp
index f87e2ba..189f0a0 100644
--- a/src/notebooks/notebooknoteaddin.hpp
+++ b/src/notebooks/notebooknoteaddin.hpp
@@ -24,12 +24,10 @@
#ifndef __NOTEBOOKS_NOTEBOOK_NOTE_ADDIN_HPP__
#define __NOTEBOOKS_NOTEBOOK_NOTE_ADDIN_HPP__
-#include <gtkmm/menu.h>
-#include <gtkmm/menutoolbutton.h>
+#include <gtkmm/modelbutton.h>
#include "base/macros.hpp"
#include "noteaddin.hpp"
-#include "notebooks/notebookmenuitem.hpp"
namespace gnote {
namespace notebooks {
@@ -43,15 +41,21 @@ namespace notebooks {
virtual void initialize() override;
virtual void shutdown() override;
virtual void on_note_opened() override;
+ virtual std::map<int, Gtk::Widget*> get_actions_popover_widgets() const override;
protected:
NotebookNoteAddin();
private:
- void on_new_notebook_menu_item();
- void get_notebook_menu_items(std::list<NotebookMenuItem*> &);
- void update_menu(Gtk::Menu *);
+ void on_note_window_foregrounded();
+ void on_note_window_backgrounded();
+ void on_new_notebook_menu_item(const Glib::VariantBase&) const;
+ void on_move_to_notebook(const Glib::VariantBase &);
+ void get_notebook_menu_items(std::list<Gtk::ModelButton*> &) const;
+ void update_menu(Gtk::Grid *) const;
+ sigc::connection m_new_notebook_cid;
+ sigc::connection m_move_to_notebook_cid;
static Tag::Ptr s_templateTag;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]