[gnote] Always open new windows from tray
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Always open new windows from tray
- Date: Mon, 17 Jun 2013 18:35:54 +0000 (UTC)
commit 177385f865ad20b6975a5624d5d1172c2afe25ab
Author: Aurimas Černius <aurisc4 gmail com>
Date: Mon Jun 17 21:34:14 2013 +0300
Always open new windows from tray
Also remove UIManager along the way.
Part of Bug 700458.
data/Makefile.am | 4 -
data/UIManagerLayout.xml | 39 --------
src/actionmanager.cpp | 124 +++++-------------------
src/actionmanager.hpp | 20 ++---
src/gnote.cpp | 2 +-
src/iactionmanager.hpp | 5 +-
src/notebooks/notebookapplicationaddin.cpp | 86 +++++------------
src/notebooks/notebookapplicationaddin.hpp | 8 +-
src/tray.cpp | 142 ++++++++++-----------------
src/tray.hpp | 7 +-
10 files changed, 122 insertions(+), 315 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 06dcdd2..70405ad 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -34,14 +34,10 @@ $(dbusservice_DATA): $(dbusservice_in_files) Makefile
man_MANS = gnote.1
-gnotedatadir = @datadir@/gnote
-gnotedata_DATA = UIManagerLayout.xml
-
noinst_DATA =
EXTRA_DIST = \
- UIManagerLayout.xml \
$(desktop_in_files) \
$(pkgconfig_in_files) \
org.gnome.gnote.gschema.xml.in \
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 5db2690..063c709 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -59,10 +59,7 @@
#include <gtkmm/image.h>
#include <gtkmm/stock.h>
-#include <libxml/tree.h>
-
#include "sharp/string.hpp"
-#include "sharp/xml.hpp"
#include "debug.hpp"
#include "actionmanager.hpp"
#include "iconmanager.hpp"
@@ -70,8 +67,7 @@
namespace gnote {
ActionManager::ActionManager()
- : m_ui(Gtk::UIManager::create())
- , m_main_window_actions(Gtk::ActionGroup::create("MainWindow"))
+ : m_main_window_actions(Gtk::ActionGroup::create("MainWindow"))
{
populate_action_groups();
make_app_actions();
@@ -79,87 +75,6 @@ namespace gnote {
}
- void ActionManager::load_interface()
- {
- Gtk::UIManager::ui_merge_id id = m_ui->add_ui_from_file(DATADIR"/gnote/UIManagerLayout.xml");
- DBG_ASSERT(id, "merge failed");
- Gtk::Window::set_default_icon_name("gnote");
-
- Gtk::ImageMenuItem *imageitem = (Gtk::ImageMenuItem*)m_ui->get_widget (
- "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote");
- DBG_ASSERT(imageitem, "Item not found");
- if (imageitem) {
- imageitem->set_image(*manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
- }
- }
-
-
- /// <summary>
- /// Get all widgets represents by XML elements that are children
- /// of the placeholder element specified by path.
- /// </summary>
- /// <param name="path">
- /// A <see cref="System.String"/> representing the path to
- /// the placeholder of interest.
- /// </param>
- /// <returns>
- /// A <see cref="IList`1"/> of Gtk.Widget objects corresponding
- /// to the XML child elements of the placeholder element.
- /// </returns>
- void ActionManager::get_placeholder_children(const std::string & path,
- std::list<Gtk::Widget*> & children) const
- {
- // Wrap the UIManager XML in a root element
- // so that it's real parseable XML.
- std::string xml = "<root>" + m_ui->get_ui() + "</root>";
-
- xmlDocPtr doc = xmlParseDoc((const xmlChar*)xml.c_str());
- if(doc == NULL) {
- return;
- }
-
- // Get the element name
- std::string placeholderName = sharp::string_substring(path, sharp::string_last_index_of(
- path, "/") + 1);
- DBG_OUT("path = %s placeholdername = %s", path.c_str(), placeholderName.c_str());
-
- sharp::XmlNodeSet nodes = sharp::xml_node_xpath_find(xmlDocGetRootElement(doc),
- "//placeholder");
- // Find the placeholder specified in the path
- for(sharp::XmlNodeSet::const_iterator iter = nodes.begin();
- iter != nodes.end(); ++iter) {
- xmlNodePtr placeholderNode = *iter;
-
- if (placeholderNode->type == XML_ELEMENT_NODE) {
-
- xmlChar * prop = xmlGetProp(placeholderNode, (const xmlChar*)"name");
- if(!prop) {
- continue;
- }
- if(xmlStrEqual(prop, (const xmlChar*)placeholderName.c_str())) {
-
- // Return each child element's widget
- for(xmlNodePtr widgetNode = placeholderNode->children;
- widgetNode; widgetNode = widgetNode->next) {
-
- if(widgetNode->type == XML_ELEMENT_NODE) {
-
- xmlChar * widgetName = xmlGetProp(widgetNode, (const xmlChar*)"name");
- if(widgetName) {
- children.push_back(get_widget(path + "/"
- + (const char*)widgetName));
- xmlFree(widgetName);
- }
- }
- }
- }
- xmlFree(prop);
- }
- }
- xmlFreeDoc(doc);
- }
-
-
void ActionManager::populate_action_groups()
{
Glib::RefPtr<Gtk::Action> action;
@@ -196,21 +111,15 @@ namespace gnote {
"ShowSearchAllNotesAction", Gtk::Stock::FIND,
_("_Search All Notes"), _("Open the Search All Notes window"));
m_main_window_actions->add(action);
-
- m_ui->insert_action_group(m_main_window_actions);
}
Glib::RefPtr<Gtk::Action> ActionManager::find_action_by_name(const std::string & n) const
{
- Glib::ListHandle<Glib::RefPtr<Gtk::ActionGroup> > actiongroups = m_ui->get_action_groups();
- for(Glib::ListHandle<Glib::RefPtr<Gtk::ActionGroup> >::const_iterator iter(actiongroups.begin());
- iter != actiongroups.end(); ++iter) {
- Glib::ListHandle<Glib::RefPtr<Gtk::Action> > actions = (*iter)->get_actions();
- for(Glib::ListHandle<Glib::RefPtr<Gtk::Action> >::const_iterator iter2(actions.begin());
- iter2 != actions.end(); ++iter2) {
- if((*iter2)->get_name() == n) {
- return *iter2;
- }
+ Glib::ListHandle<Glib::RefPtr<Gtk::Action> > actions = m_main_window_actions->get_actions();
+ for(Glib::ListHandle<Glib::RefPtr<Gtk::Action> >::const_iterator iter2(actions.begin());
+ iter2 != actions.end(); ++iter2) {
+ if((*iter2)->get_name() == n) {
+ return *iter2;
}
}
DBG_OUT("%s not found", n.c_str());
@@ -362,4 +271,25 @@ namespace gnote {
return res;
}
+ void ActionManager::add_tray_menu_item(Gtk::MenuItem & item)
+ {
+ m_tray_menu_items.push_back(&item);
+ }
+
+ void ActionManager::remove_tray_menu_item(Gtk::MenuItem & item)
+ {
+ for(std::vector<Gtk::MenuItem*>::iterator iter = m_tray_menu_items.begin();
+ iter != m_tray_menu_items.end(); ++iter) {
+ if(*iter == &item) {
+ m_tray_menu_items.erase(iter);
+ break;
+ }
+ }
+ }
+
+ std::vector<Gtk::MenuItem*> ActionManager::get_tray_menu_items()
+ {
+ return m_tray_menu_items;
+ }
+
}
diff --git a/src/actionmanager.hpp b/src/actionmanager.hpp
index f4b0b2f..e940145 100644
--- a/src/actionmanager.hpp
+++ b/src/actionmanager.hpp
@@ -29,8 +29,6 @@
#include <giomm/menu.h>
#include <giomm/simpleaction.h>
#include <gtkmm/action.h>
-#include <gtkmm/uimanager.h>
-#include <gdkmm/pixbuf.h>
#include "iactionmanager.hpp"
@@ -46,18 +44,9 @@ public:
{
return find_action_by_name(n);
}
- virtual Gtk::Widget * get_widget(const std::string &n) const
- {
- return m_ui->get_widget(n);
- }
- void load_interface();
- void get_placeholder_children(const std::string & p, std::list<Gtk::Widget*> & placeholders) const;
void populate_action_groups();
Glib::RefPtr<Gtk::Action> find_action_by_name(const std::string & n) const;
- virtual const Glib::RefPtr<Gtk::UIManager> & get_ui()
- {
- return m_ui;
- }
+
virtual Glib::RefPtr<Gio::SimpleAction> get_app_action(const std::string & name) const;
const std::vector<Glib::RefPtr<Gio::SimpleAction> > & get_app_actions() const
{
@@ -70,6 +59,10 @@ public:
virtual void add_main_window_search_action(const Glib::RefPtr<Gtk::Action> & action, int order);
virtual void remove_main_window_search_action(const std::string & name);
virtual std::vector<Glib::RefPtr<Gtk::Action> > get_main_window_search_actions();
+
+ virtual void add_tray_menu_item(Gtk::MenuItem & item);
+ virtual void remove_tray_menu_item(Gtk::MenuItem & item);
+ virtual std::vector<Gtk::MenuItem*> get_tray_menu_items();
private:
void make_app_actions();
void make_app_menu_items();
@@ -79,7 +72,6 @@ private:
void remove_main_window_action(std::map<int, Glib::RefPtr<Gtk::Action> > & actions, const std::string &
name);
std::vector<Glib::RefPtr<Gtk::Action> > get_main_window_actions(std::map<int, Glib::RefPtr<Gtk::Action> >
& actions);
- Glib::RefPtr<Gtk::UIManager> m_ui;
Glib::RefPtr<Gtk::ActionGroup> m_main_window_actions;
std::vector<Glib::RefPtr<Gio::SimpleAction> > m_app_actions;
@@ -107,6 +99,8 @@ private:
typedef std::multimap<int, AppMenuItem> AppMenuItemMultiMap;
AppMenuItemMultiMap m_app_menu_items;
std::map<int, Glib::RefPtr<Gtk::Action> > m_main_window_search_actions;
+
+ std::vector<Gtk::MenuItem*> m_tray_menu_items;
};
diff --git a/src/gnote.cpp b/src/gnote.cpp
index aae886f..37ebede 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -152,7 +152,7 @@ namespace gnote {
m_manager = new NoteManager(note_path);
new notebooks::NotebookManager(default_note_manager());
m_keybinder = new XKeybinder();
- (new ActionManager)->load_interface();
+ new ActionManager;
sync::SyncManager::init(default_note_manager());
setup_global_actions();
diff --git a/src/iactionmanager.hpp b/src/iactionmanager.hpp
index d871fcb..d4f108c 100644
--- a/src/iactionmanager.hpp
+++ b/src/iactionmanager.hpp
@@ -49,8 +49,9 @@ public:
virtual void add_main_window_search_action(const Glib::RefPtr<Gtk::Action> & action, int order) = 0;
virtual void remove_main_window_search_action(const std::string & name) = 0;
virtual std::vector<Glib::RefPtr<Gtk::Action> > get_main_window_search_actions() = 0;
- virtual const Glib::RefPtr<Gtk::UIManager> & get_ui() = 0;
- virtual Gtk::Widget * get_widget(const std::string &n) const = 0;
+ virtual void add_tray_menu_item(Gtk::MenuItem & item) = 0;
+ virtual void remove_tray_menu_item(Gtk::MenuItem & item) = 0;
+ virtual std::vector<Gtk::MenuItem*> get_tray_menu_items() = 0;
sigc::signal<void> signal_main_window_search_actions_changed;
};
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index 7d1471f..51b9127 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -52,62 +52,32 @@ namespace gnote {
NotebookApplicationAddin::NotebookApplicationAddin()
: m_initialized(false)
- , m_notebookUi(0)
+ , m_tray_menu_item(NULL)
, m_trayNotebookMenu(NULL)
{
}
- static const char * uixml = " <ui>"
- " <popup name='TrayIconMenu' action='TrayIconMenuAction'>"
- " <placeholder name='TrayNewNotePlaceholder'>"
- " <menuitem name='TrayNewNotebookMenu' action='TrayNewNotebookMenuAction' position='top' />"
- " </placeholder>"
- " </popup>"
- "</ui>";
-
void NotebookApplicationAddin::initialize ()
{
- m_actionGroup = Glib::RefPtr<Gtk::ActionGroup>(Gtk::ActionGroup::create("Notebooks"));
- m_actionGroup->add(
- Gtk::Action::create ("TrayNewNotebookMenuAction", Gtk::Stock::NEW,
- _("Notebooks"),
- _("Create a new note in a notebook")));
-
+ m_tray_menu_item = new Gtk::ImageMenuItem(
+ *manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTEBOOK, 16))),
+ _("Notebooks"));
+ m_tray_menu_item->set_tooltip_text(_("Create a new note in a notebook"));
+ m_tray_menu_item->show();
IActionManager & am(IActionManager::obj());
- m_notebookUi = am.get_ui()->add_ui_from_string (uixml);
-
- am.get_ui()->insert_action_group (m_actionGroup, 0);
-
- Gtk::MenuItem *item = dynamic_cast<Gtk::MenuItem*>(
- am.get_widget ("/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNotebookMenu"));
- if (item) {
- Gtk::ImageMenuItem *image_item = dynamic_cast<Gtk::ImageMenuItem*>(item);
- if (image_item) {
- image_item->set_image(*manage(new Gtk::Image(
- IconManager::obj().get_icon(IconManager::NOTEBOOK, 16))));
- }
- m_trayNotebookMenu = manage(new Gtk::Menu());
- item->set_submenu(*m_trayNotebookMenu);
-
- m_trayNotebookMenu->signal_show()
- .connect(sigc::mem_fun(*this,
- &NotebookApplicationAddin::on_tray_notebook_menu_shown));
- m_trayNotebookMenu->signal_hide()
- .connect(sigc::mem_fun(*this,
- &NotebookApplicationAddin::on_tray_notebook_menu_hidden));
- }
-
- Gtk::ImageMenuItem *imageitem = dynamic_cast<Gtk::ImageMenuItem*>(
- am.get_widget ("/NotebooksTreeContextMenu/NewNotebookNote"));
- if (imageitem) {
- imageitem->set_image(*manage(new Gtk::Image(
- IconManager::obj().get_icon(IconManager::NOTE_NEW, 16))));
- }
+ am.add_tray_menu_item(*m_tray_menu_item);
+ m_trayNotebookMenu = manage(new Gtk::Menu());
+ m_tray_menu_item->set_submenu(*m_trayNotebookMenu);
+
+ m_trayNotebookMenu->signal_show()
+ .connect(sigc::mem_fun(*this, &NotebookApplicationAddin::on_tray_notebook_menu_shown));
+ m_trayNotebookMenu->signal_hide()
+ .connect(sigc::mem_fun(*this, &NotebookApplicationAddin::on_tray_notebook_menu_hidden));
NoteManager & nm(note_manager());
-
+
for(Note::List::const_iterator iter = nm.get_notes().begin();
iter != nm.get_notes().end(); ++iter) {
const Note::Ptr & note(*iter);
@@ -134,24 +104,16 @@ namespace gnote {
void NotebookApplicationAddin::shutdown ()
{
IActionManager & am(IActionManager::obj());
- try {
- am.get_ui()->remove_action_group(m_actionGroup);
- }
- catch (...)
- {
- }
- try {
- am.get_ui()->remove_ui(m_notebookUi);
- }
- catch (...)
- {
- }
- m_notebookUi = 0;
-
- if (m_trayNotebookMenu) {
- delete m_trayNotebookMenu;
+ if(m_tray_menu_item) {
+ am.remove_tray_menu_item(*m_tray_menu_item);
+ Gtk::Container *container = m_tray_menu_item->get_parent();
+ if(container) {
+ container->remove(*m_tray_menu_item);
+ }
+ delete m_tray_menu_item;
+ m_tray_menu_item = NULL;
}
-
+
m_initialized = false;
}
diff --git a/src/notebooks/notebookapplicationaddin.hpp b/src/notebooks/notebookapplicationaddin.hpp
index 7c27e5a..aaea5ef 100644
--- a/src/notebooks/notebookapplicationaddin.hpp
+++ b/src/notebooks/notebookapplicationaddin.hpp
@@ -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
@@ -25,9 +25,6 @@
#include <list>
-#include <gdkmm/pixbuf.h>
-#include <gtkmm/actiongroup.h>
-
#include "applicationaddin.hpp"
#include "note.hpp"
@@ -59,8 +56,7 @@ namespace gnote {
void on_new_notebook_action(const Glib::VariantBase&);
bool m_initialized;
- guint m_notebookUi;
- Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
+ Gtk::MenuItem *m_tray_menu_item;
Gtk::Menu *m_trayNotebookMenu;
std::list<Gtk::MenuItem*> m_trayNotebookMenuItems;
};
diff --git a/src/tray.cpp b/src/tray.cpp
index 965ef4c..e10dcb5 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -93,7 +93,7 @@ namespace gnote {
{
if(!m_inhibit_activate) {
if(m_note) {
- MainWindow & window = IGnote::obj().get_window_for_note();
+ MainWindow & window = IGnote::obj().new_main_window();
window.present_note(m_note);
window.present();
}
@@ -207,28 +207,32 @@ namespace gnote {
Gtk::Menu * Tray::make_tray_notes_menu()
{
- Gtk::Menu *menu;
-
- IActionManager & am(IActionManager::obj());
-
- menu = (Gtk::Menu*)am.get_widget("/TrayIconMenu");
- DBG_ASSERT(menu, "menu not found");
+ Gtk::Menu *menu = manage(new Gtk::Menu);
+
+ m_new_note_item = manage(new Gtk::ImageMenuItem);
+ m_new_note_item->set_image(*manage(new Gtk::Image(Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU)));
+ m_new_note_item->set_label(_("Create _New Note"));
+ m_new_note_item->set_use_underline(true);
+ m_new_note_item->set_tooltip_text(_("Create a new note"));
+ m_new_note_item->show();
+ m_new_note_item->signal_activate()
+ .connect(sigc::mem_fun(*this, &Tray::on_new_note_activate));
+ menu->insert(*m_new_note_item, -1);
+ m_search_notes_item = manage(new Gtk::ImageMenuItem);
+ m_search_notes_item->set_image(*manage(new Gtk::Image(Gtk::Stock::FIND, Gtk::ICON_SIZE_MENU)));
+ m_search_notes_item->set_label(_("_Search All Notes"));
+ m_search_notes_item->set_use_underline(true);
+ m_search_notes_item->set_tooltip_text(_("Open the Search All Notes window"));
+ m_search_notes_item->show();
+ m_search_notes_item->signal_activate()
+ .connect(sigc::mem_fun(*this, &Tray::on_search_notes_activate));
+ menu->insert(*m_search_notes_item, -1);
bool enable_keybindings = Preferences::obj().get_schema_settings(
Preferences::SCHEMA_GNOTE)->get_boolean(Preferences::ENABLE_KEYBINDINGS);
if (enable_keybindings) {
- Gtk::MenuItem *item =
(Gtk::MenuItem*)am.get_widget("/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote");
- if(item) {
- KeybindingToAccel::add_accelerator(m_keybinder, *item, Preferences::KEYBINDING_CREATE_NEW_NOTE);
- }
- item = (Gtk::MenuItem*)am.get_widget("/TrayIconMenu/ShowSearchAllNotes");
- if(item) {
- KeybindingToAccel::add_accelerator(m_keybinder, *item, Preferences::KEYBINDING_OPEN_RECENT_CHANGES);
- }
- item = (Gtk::MenuItem*)am.get_widget("/TrayIconMenu/OpenStartHereNote");
- if(item) {
- KeybindingToAccel::add_accelerator(m_keybinder, *item, Preferences::KEYBINDING_OPEN_START_HERE);
- }
+ KeybindingToAccel::add_accelerator(m_keybinder, *m_new_note_item,
Preferences::KEYBINDING_CREATE_NEW_NOTE);
+ KeybindingToAccel::add_accelerator(m_keybinder, *m_search_notes_item,
Preferences::KEYBINDING_OPEN_RECENT_CHANGES);
}
return menu;
@@ -249,56 +253,19 @@ namespace gnote {
m_tray_menu->show_all();
}
- void Tray::remove_recently_changed_notes()
- {
- std::list<Gtk::MenuItem*>::iterator iter;
- for(iter = m_recent_notes.begin();
- iter != m_recent_notes.end(); ++iter) {
- m_tray_menu->remove(**iter);
- }
- m_recent_notes.clear();
- }
-
void Tray::add_recently_changed_notes()
{
int min_size = Preferences::obj().get_schema_settings(
Preferences::SCHEMA_GNOTE)->get_int(Preferences::MENU_NOTE_COUNT);
int max_size = 18;
int list_size = 0;
- bool menuOpensUpward = m_trayicon.menu_opens_upward();
NoteMenuItem *item;
- // Remove the old dynamic items
- remove_recently_changed_notes();
-
- // Assume menu opens downward, move common items to top of menu
- ActionManager & am(static_cast<ActionManager &>(IActionManager::obj()));
- Gtk::MenuItem* newNoteItem = (Gtk::MenuItem*)am.get_widget(
- "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote");
- Gtk::MenuItem* searchNotesItem = (Gtk::MenuItem*)am.get_widget(
- "/TrayIconMenu/ShowSearchAllNotes");
- m_tray_menu->reorder_child (*newNoteItem, 0);
- int insertion_point = 1; // If menu opens downward
-
- // Find all child widgets under the TrayNewNotePlaceholder
- // element. Make sure those added by add-ins are
- // properly accounted for and reordered.
- std::list<Gtk::Widget*> newNotePlaceholderWidgets;
- std::list<Gtk::Widget*> allChildWidgets;
- am.get_placeholder_children("/TrayIconMenu/TrayNewNotePlaceholder", allChildWidgets);
- for(std::list<Gtk::Widget*>::const_iterator iter = allChildWidgets.begin();
- iter != allChildWidgets.end(); ++iter) {
- Gtk::MenuItem * menuitem = dynamic_cast<Gtk::MenuItem*>(*iter);
-
- if (menuitem && (menuitem != newNoteItem)) {
- newNotePlaceholderWidgets.push_back(menuitem);
- m_tray_menu->reorder_child (*menuitem, insertion_point);
- insertion_point++;
- }
+ std::vector<Gtk::Widget*> old_items = m_tray_menu->get_children();
+ for(std::vector<Gtk::Widget*>::iterator iter = old_items.begin();
+ iter != old_items.end(); ++iter) {
+ m_tray_menu->remove(**iter);
}
-
- m_tray_menu->reorder_child (*searchNotesItem, insertion_point);
- insertion_point++;
sharp::DateTime days_ago(sharp::DateTime::now());
days_ago.add_days(-3);
@@ -343,11 +310,7 @@ namespace gnote {
if (show) {
item = Gtk::manage(new NoteMenuItem (note, true));
- // Add this widget to the menu (+insertion_point to add after new+search+...)
- m_tray_menu->insert(*item, list_size + insertion_point);
- // Keep track of this item so we can remove it later
- m_recent_notes.push_back(item);
-
+ m_tray_menu->insert(*item, -1);
list_size++;
}
}
@@ -355,14 +318,7 @@ namespace gnote {
Note::Ptr start = m_manager.find_by_uri(m_manager.start_note_uri());
if (start) {
item = Gtk::manage(new NoteMenuItem(start, false));
- if (menuOpensUpward) {
- m_tray_menu->insert (*item, list_size + insertion_point);
- }
- else {
- m_tray_menu->insert (*item, insertion_point);
- }
- m_recent_notes.push_back(item);
-
+ m_tray_menu->insert(*item, -1);
list_size++;
bool enable_keybindings = Preferences::obj().get_schema_settings(
@@ -372,28 +328,36 @@ namespace gnote {
}
}
-
- // FIXME: Rearrange this stuff to have less wasteful reordering
- if (menuOpensUpward) {
- // Relocate common items to bottom of menu
- insertion_point -= 1;
- m_tray_menu->reorder_child (*searchNotesItem, list_size + insertion_point);
- for(std::list<Gtk::Widget*>::iterator widget = newNotePlaceholderWidgets.begin();
- widget != newNotePlaceholderWidgets.end(); ++widget) {
- Gtk::MenuItem *menuitem = dynamic_cast<Gtk::MenuItem*>(*widget);
- if(menuitem) {
- m_tray_menu->reorder_child (*menuitem, list_size + insertion_point);
- }
- }
- m_tray_menu->reorder_child (*newNoteItem, list_size + insertion_point);
- insertion_point = list_size;
+ bool menuOpensUpward = m_trayicon.menu_opens_upward();
+ ActionManager & am(static_cast<ActionManager &>(IActionManager::obj()));
+ int insertion_point = 0; // If menu opens downward
+ if(menuOpensUpward) {
+ insertion_point = -1;
}
Gtk::SeparatorMenuItem *separator = manage(new Gtk::SeparatorMenuItem());
m_tray_menu->insert(*separator, insertion_point);
- m_recent_notes.push_back(separator);
+ m_tray_menu->insert(*m_search_notes_item, insertion_point);
+ std::vector<Gtk::MenuItem*> items = am.get_tray_menu_items();
+ for(std::vector<Gtk::MenuItem*>::iterator iter = items.begin(); iter != items.end(); ++iter) {
+ m_tray_menu->insert(**iter, insertion_point);
+ }
+ m_tray_menu->insert(*m_new_note_item, insertion_point);
+ }
+
+ void Tray::on_new_note_activate()
+ {
+ MainWindow &win = IGnote::obj().new_main_window();
+ win.new_note();
+ win.present();
}
+ void Tray::on_search_notes_activate()
+ {
+ IGnote::obj().new_main_window().present();
+ }
+
+
TrayIcon::TrayIcon(IKeybinder & keybinder, NoteManager & manager)
: Gtk::StatusIcon()
, m_tray(new Tray(manager, *this, keybinder))
diff --git a/src/tray.hpp b/src/tray.hpp
index 29e797c..30dd0fd 100644
--- a/src/tray.hpp
+++ b/src/tray.hpp
@@ -78,14 +78,17 @@ public:
Gtk::Menu * tray_menu()
{ return m_tray_menu; }
void update_tray_menu(Gtk::Widget * parent);
- void remove_recently_changed_notes();
void add_recently_changed_notes();
private:
+ void on_new_note_activate();
+ void on_search_notes_activate();
+
NoteManager & m_manager;
IGnoteTray & m_trayicon;
Gtk::Menu *m_tray_menu;
+ Gtk::ImageMenuItem *m_new_note_item;
+ Gtk::ImageMenuItem *m_search_notes_item;
bool m_menu_added;
- std::list<Gtk::MenuItem*> m_recent_notes;
IKeybinder & m_keybinder;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]