[gnote] Make several search windows possible
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make several search windows possible
- Date: Sat, 6 Oct 2012 13:20:11 +0000 (UTC)
commit 6a27e8668456aa6bac64791beb02c469428341dd
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Thu Oct 4 22:58:33 2012 +0300
Make several search windows possible
* Make search window multi-instance capable
* Make Gnote class to control multiple search windows
* Remove Search All from note window
* Adjust the rest for changes
src/dbus/remotecontrol.cpp | 15 ++++-------
src/gnote.cpp | 50 +++++++++++++++++++++++++++++----------
src/gnote.hpp | 6 ++++-
src/notewindow.cpp | 35 ----------------------------
src/notewindow.hpp | 1 -
src/prefskeybinder.cpp | 5 +--
src/recentchanges.cpp | 55 +-------------------------------------------
src/recentchanges.hpp | 18 ++++++--------
8 files changed, 59 insertions(+), 126 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 099311c..1639957 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -20,8 +20,8 @@
#include "config.h"
-#include "sharp/map.hpp"
#include "debug.hpp"
+#include "gnote.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "recentchanges.hpp"
@@ -30,6 +30,7 @@
#include "tag.hpp"
#include "tagmanager.hpp"
#include "dbus/remotecontrol.hpp"
+#include "sharp/map.hpp"
namespace gnote {
@@ -147,19 +148,15 @@ namespace gnote {
void RemoteControl::DisplaySearch()
{
- NoteRecentChanges::get_instance(m_manager)->present();
+ Gnote::obj().open_search_all();
}
void RemoteControl::DisplaySearchWithText(const std::string& search_text)
{
- NoteRecentChanges* recent_changes =
- NoteRecentChanges::get_instance (m_manager);
- if (!recent_changes)
- return;
-
+ NoteRecentChanges::Ptr recent_changes = Gnote::obj().get_main_window();
recent_changes->set_search_text(search_text);
- recent_changes->present ();
+ recent_changes->present();
}
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 00e5f44..a4c764d 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -27,6 +27,7 @@
#include <iostream>
+#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <glibmm/thread.h>
@@ -43,7 +44,6 @@
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "preferencesdialog.hpp"
-#include "recentchanges.hpp"
#include "remotecontrolproxy.hpp"
#include "utils.hpp"
#include "xkeybinder.hpp"
@@ -106,13 +106,6 @@ namespace gnote {
}
- void Gnote::on_activate()
- {
- Gtk::Application::on_activate();
- open_search_all();
- }
-
-
int Gnote::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> & command_line)
{
Gtk::Application::on_command_line(command_line);
@@ -131,7 +124,7 @@ namespace gnote {
cmd_line.execute();
}
else {
- ActionManager::obj()["ShowSearchAllNotesAction"]->activate();
+ new_main_window()->present();
}
return 0;
@@ -203,7 +196,7 @@ namespace gnote {
}
else if(m_is_background) {
// Create Search All Notes window as we need it present for application to run
- NoteRecentChanges::get_instance(default_note_manager());
+ new_main_window();
}
else {
am["ShowSearchAllNotesAction"]->activate();
@@ -237,7 +230,7 @@ namespace gnote {
void Gnote::start_tray_icon()
{
// Create Search All Notes window as we need it present for application to run
- NoteRecentChanges::get_instance(default_note_manager());
+ get_main_window();
// Create the tray icon and run the main loop
m_tray_icon = Glib::RefPtr<TrayIcon>(new TrayIcon(default_note_manager()));
@@ -395,7 +388,7 @@ namespace gnote {
about.set_documenters(documenters);
about.set_translator_credits(translators);
// about.set_icon_name("gnote");
- NoteRecentChanges *recent_changes = NoteRecentChanges::get_instance();
+ NoteRecentChanges::Ptr recent_changes = get_main_window();
if(recent_changes && recent_changes->get_visible()) {
about.set_transient_for(*recent_changes);
recent_changes->present();
@@ -403,9 +396,40 @@ namespace gnote {
about.run();
}
+ NoteRecentChanges::Ptr Gnote::new_main_window()
+ {
+ NoteRecentChanges::Ptr win = NoteRecentChanges::create(default_note_manager());
+ std::list<NoteRecentChanges::Ptr>::iterator pos = m_main_windows.insert(m_main_windows.end(), win);
+ win->signal_hide().connect(boost::bind(sigc::mem_fun(*this, &Gnote::on_main_window_closed), pos));
+ add_window(*win);
+ return win;
+ }
+
+ NoteRecentChanges::Ptr Gnote::get_main_window()
+ {
+ for(std::list<NoteRecentChanges::Ptr>::iterator iter = m_main_windows.begin();
+ iter != m_main_windows.end(); ++iter) {
+ return *iter;
+ }
+
+ NoteRecentChanges::Ptr win = new_main_window();
+ return win;
+ }
+
+ void Gnote::on_main_window_closed(std::list<NoteRecentChanges::Ptr>::iterator pos)
+ {
+ remove_window(**pos);
+ m_main_windows.erase(pos);
+
+ // if background mode, we need to have a window, to prevent quit
+ if(m_is_background && !m_main_windows.size()) {
+ new_main_window();
+ }
+ }
+
void Gnote::open_search_all()
{
- NoteRecentChanges::get_instance(default_note_manager())->present();
+ get_main_window()->present();
}
void Gnote::open_note_sync_window()
diff --git a/src/gnote.hpp b/src/gnote.hpp
index d982525..e5c9eea 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -34,6 +34,7 @@
#include "base/singleton.hpp"
#include "actionmanager.hpp"
#include "keybinder.hpp"
+#include "recentchanges.hpp"
#include "remotecontrolproxy.hpp"
#include "tray.hpp"
#include "synchronization/syncdialog.hpp"
@@ -131,6 +132,8 @@ public:
void on_show_preferences_action();
void on_show_help_action();
void on_show_about_action();
+ NoteRecentChanges::Ptr new_main_window();
+ NoteRecentChanges::Ptr get_main_window();
void open_search_all();
void open_note_sync_window();
@@ -163,7 +166,6 @@ public:
return m_sync_dlg;
}
protected:
- virtual void on_activate();
virtual int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> & command_line);
virtual void on_startup();
virtual void on_window_removed(Gtk::Window *window);
@@ -177,6 +179,7 @@ private:
void common_init();
void end_main(bool bus_aquired, bool name_acquired);
void on_sync_dialog_response(int response_id);
+ void on_main_window_closed(std::list<NoteRecentChanges::Ptr>::iterator pos);
NoteManager *m_manager;
IKeybinder *m_keybinder;
@@ -187,6 +190,7 @@ private:
PreferencesDialog *m_prefsdlg;
GnoteCommandLine cmd_line;
sync::SyncDialog::Ptr m_sync_dlg;
+ std::list<NoteRecentChanges::Ptr> m_main_windows;
};
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index adc565b..66a5092 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -325,15 +325,6 @@ namespace gnote {
Gtk::MenuItem *spacer1 = manage(new Gtk::SeparatorMenuItem());
spacer1->show ();
- Gtk::ImageMenuItem *search = manage(new Gtk::ImageMenuItem(
- _("_Search All Notes"), true));
- search->set_image(*manage(new Gtk::Image (Gtk::Stock::FIND, Gtk::ICON_SIZE_MENU)));
- search->signal_activate().connect(sigc::mem_fun(*this, &NoteWindow::search_button_clicked));
- search->add_accelerator ("activate", m_accel_group, GDK_KEY_F,
- (Gdk::CONTROL_MASK | Gdk::SHIFT_MASK),
- Gtk::ACCEL_VISIBLE);
- search->show();
-
Gtk::ImageMenuItem *link = manage(new Gtk::ImageMenuItem(_("_Link to New Note"), true));
link->set_image(*manage(new Gtk::Image (Gtk::Stock::JUMP_TO, Gtk::ICON_SIZE_MENU)));
link->set_sensitive(!m_note.get_buffer()->get_selection().empty());
@@ -363,7 +354,6 @@ namespace gnote {
menu->prepend(*text_item);
menu->prepend(*find_item);
menu->prepend(*link);
- menu->prepend(*search);
Gtk::MenuItem *close_all =
manage(new Gtk::MenuItem(_("Clos_e All Notes"), true));
@@ -397,22 +387,6 @@ namespace gnote {
{
Gtk::Toolbar *tb = new Gtk::Toolbar();
- Gtk::ToolButton *search = manage(new Gtk::ToolButton (
- *manage(new Gtk::Image(
- Gtk::Stock::FIND,
- tb->get_icon_size())
- ), _("Search")));
- search->set_use_underline(true);
- search->set_is_important(true);
- search->signal_clicked().connect(sigc::mem_fun(*this, &NoteWindow::search_button_clicked));
- search->set_tooltip_text(_("Search your notes (Ctrl-Shift-F)"));
- search->add_accelerator("clicked", m_accel_group,
- GDK_KEY_F,
- (Gdk::CONTROL_MASK | Gdk::SHIFT_MASK),
- Gtk::ACCEL_VISIBLE);
- search->show_all();
- tb->insert(*search, -1);
-
m_link_button = manage(new Gtk::ToolButton(
*manage(new Gtk::Image (Gtk::Stock::JUMP_TO, tb->get_icon_size())),
_("Link")));
@@ -716,15 +690,6 @@ namespace gnote {
ActionManager::obj()["NewNoteAction"]->activate();
}
- void NoteWindow::search_button_clicked()
- {
- NoteRecentChanges *search = NoteRecentChanges::get_instance(m_note.manager());
- if (!m_note.get_buffer()->get_selection().empty()) {
- search->set_search_text(m_note.get_buffer()->get_selection());
- }
- search->present();
- }
-
void NoteWindow::change_depth_right_handler()
{
Glib::RefPtr<NoteBuffer>::cast_static(m_editor->get_buffer())->change_cursor_depth_directional(true);
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 472b3a0..db3dd41 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -167,7 +167,6 @@ private:
void create_new_note();
void change_depth_right_handler();
void change_depth_left_handler();
- void search_button_clicked();
Note & m_note;
Glib::RefPtr<Gtk::AccelGroup> m_accel_group;
diff --git a/src/prefskeybinder.cpp b/src/prefskeybinder.cpp
index d68c7e9..00f9b51 100644
--- a/src/prefskeybinder.cpp
+++ b/src/prefskeybinder.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -235,8 +235,7 @@ namespace gnote {
void GnotePrefsKeybinder::key_open_recent_changes()
{
- NoteRecentChanges *recent = NoteRecentChanges::get_instance (m_manager);
- recent->present ();
+ Gnote::obj().open_search_all();
}
}
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 31ef2d1..d215721 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -58,25 +58,9 @@ namespace gnote {
Glib::RefPtr<Gdk::Pixbuf> NoteRecentChanges::s_unfiled_notes_icon;
Glib::RefPtr<Gdk::Pixbuf> NoteRecentChanges::s_notebook_icon;
std::list<std::string> NoteRecentChanges::s_previous_searches;
- NoteRecentChanges *NoteRecentChanges::s_instance = NULL;
- NoteRecentChanges *NoteRecentChanges::get_instance()
- {
- return s_instance;
- }
-
-
- NoteRecentChanges *NoteRecentChanges::get_instance(NoteManager& m)
- {
- if(!s_instance) {
- s_instance = new NoteRecentChanges(m);
- }
- return s_instance;
- }
-
-
void NoteRecentChanges::_init_static()
{
if(s_static_inited) {
@@ -102,7 +86,6 @@ namespace gnote {
, m_entry_changed_timeout(NULL)
, m_clickX(0), m_clickY(0)
{
- Gnote::obj().add_window(*this);
_init_static();
// get_window()->set_icon_name("gnote");
set_default_size(450,400);
@@ -231,18 +214,12 @@ namespace gnote {
focus_chain.clear();
focus_chain.push_back(m_tree);
m_matches_window.set_focus_chain(focus_chain);
-
- Gnote::obj().signal_quit.connect(sigc::mem_fun(*this, &NoteRecentChanges::on_exiting_event));
-
}
NoteRecentChanges::~NoteRecentChanges()
{
- if(m_entry_changed_timeout) {
- delete m_entry_changed_timeout;
- }
- Gnote::obj().remove_window(*this);
+ save_position();
}
@@ -1187,41 +1164,17 @@ namespace gnote {
void NoteRecentChanges::on_close_window()
{
-#if 0
- // Disconnect external signal handlers to prevent bloweup
- manager.NoteDeleted -= OnNotesChanged;
- manager.NoteAdded -= OnNotesChanged;
- manager.NoteRenamed -= OnNoteRenamed;
- manager.NoteSaved -= OnNoteSaved;
-
- Notebooks.NotebookManager.NoteAddedToNotebook -= OnNoteAddedToNotebook;
- Notebooks.NotebookManager.NoteRemovedFromNotebook -= OnNoteRemovedFromNotebook;
-#endif
// The following code has to be done for the MenuBar to
// appear properly the next time this window is opened.
if (m_menubar) {
if(Gnote::obj().windowed()) {
m_content_vbox.remove (*m_menubar);
}
-#if 0
- am ["OpenNoteAction"].Activated -= OnOpenNote;
- am ["DeleteNoteAction"].Activated -= OnDeleteNote;
- am ["NewNotebookAction"].Activated -= OnNewNotebook;
- am ["DeleteNotebookAction"].Activated -= OnDeleteNotebook;
- am ["NewNotebookNoteAction"].Activated -= OnNewNotebookNote;
- am ["OpenNotebookTemplateNoteAction"].Activated -= OnOpenNotebookTemplateNote;
- am ["CloseWindowAction"].Activated -= OnCloseWindow;
-#endif
}
save_position ();
-// Tomboy.ExitingEvent -= OnExitingEvent;
hide ();
- if(Gnote::obj().windowed()) {
- delete s_instance;
- s_instance = NULL;
- }
}
@@ -1719,11 +1672,5 @@ namespace gnote {
}
}
-
- void NoteRecentChanges::on_exiting_event()
- {
- save_position();
- }
-
}
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index 6fa0e85..845e322 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -61,22 +61,22 @@ typedef utils::ForcedPresentWindow<Gtk::ApplicationWindow> NoteRecentChangesPare
class NoteRecentChanges
: public NoteRecentChangesParent
+ , public std::tr1::enable_shared_from_this<NoteRecentChanges>
{
public:
- static NoteRecentChanges *get_instance();
- static NoteRecentChanges *get_instance(NoteManager& m);
+ typedef std::tr1::shared_ptr<NoteRecentChanges> Ptr;
+ typedef std::tr1::weak_ptr<NoteRecentChanges> WeakPtr;
+
+ static Ptr create(NoteManager& m)
+ {
+ return Ptr(new NoteRecentChanges(m));
+ }
virtual ~NoteRecentChanges();
void set_search_text(const std::string & value);
-
-//////
-
protected:
NoteRecentChanges(NoteManager& m);
virtual void on_show();
- ///
-private:
-
private:
static void _init_static();
Gtk::MenuBar *create_menu_bar ();
@@ -149,7 +149,6 @@ private:
std::string get_search_text();
void save_position ();
void restore_position();
- void on_exiting_event();
class RecentNotesColumnTypes
: public Gtk::TreeModelColumnRecord
@@ -217,7 +216,6 @@ private:
static Glib::RefPtr<Gdk::Pixbuf> s_unfiled_notes_icon;
static Glib::RefPtr<Gdk::Pixbuf> s_notebook_icon;
static std::list<std::string> s_previous_searches;
- static NoteRecentChanges *s_instance;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]