[gnote] Make NoteRecentChanges handle note display
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Make NoteRecentChanges handle note display
- Date: Sat, 6 Oct 2012 13:20:26 +0000 (UTC)
commit a9391b447c05abea5c3f0cb9fabf334a3ba49b97
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Fri Oct 5 23:05:49 2012 +0300
Make NoteRecentChanges handle note display
* New method present_note() to display note
* New method get_owning() to get NoteRecentChanges window, owning widget
* Use above methods to open notes from itself
* New method Gnote::get_window_for_note to find or create main window, that can be used to open note
* Use the above accross Gnote to open note window
src/addins/backlinks/backlinkmenuitem.cpp | 10 +++++-
src/dbus/remotecontrol.cpp | 12 ++++++-
src/dbus/remotecontrol.hpp | 3 +-
src/gnote.cpp | 21 ++++++++++++
src/gnote.hpp | 1 +
src/noterenamedialog.cpp | 18 ++++++++---
src/prefskeybinder.cpp | 4 ++-
src/recentchanges.cpp | 49 ++++++++++++++++++++++++++--
src/recentchanges.hpp | 2 +
src/synchronization/syncdialog.cpp | 18 ++++++++---
src/synchronization/syncdialog.hpp | 3 +-
src/tray.cpp | 6 ++-
src/watchers.cpp | 20 +++++++-----
src/watchers.hpp | 2 +-
14 files changed, 138 insertions(+), 31 deletions(-)
---
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index 83d5286..0087044 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -18,6 +19,7 @@
*/
+#include "gnote.hpp"
#include "notewindow.hpp"
#include "backlinkmenuitem.hpp"
@@ -59,7 +61,13 @@ void BacklinkMenuItem::on_activate()
find.property_visible() = true;
find.set_search_text(m_title_search);
- m_note->get_window()->present ();
+ gnote::NoteRecentChanges::Ptr window = gnote::NoteRecentChanges::get_owning(*this);
+ if(!window) {
+ window = gnote::Gnote::obj().new_main_window();
+ }
+
+ window->present_note(m_note);
+ window->present();
}
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 1639957..7c9b0eb 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -120,7 +120,7 @@ namespace gnote {
return false;
}
- note->get_window()->present();
+ present_note(note);
return true;
}
@@ -134,7 +134,7 @@ namespace gnote {
return false;
}
- note->get_window()->present();
+ present_note(note);
// Pop open the find-bar
NoteFindBar & findbar = note->get_window()->get_find_bar();
@@ -407,4 +407,12 @@ void RemoteControl::on_note_saved(const Note::Ptr & note)
}
+void RemoteControl::present_note(const Note::Ptr & note)
+{
+ NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ window->present_note(note);
+ window->present();
+}
+
+
}
diff --git a/src/dbus/remotecontrol.hpp b/src/dbus/remotecontrol.hpp
index b0b323d..70e2f75 100644
--- a/src/dbus/remotecontrol.hpp
+++ b/src/dbus/remotecontrol.hpp
@@ -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
@@ -74,6 +74,7 @@ private:
void on_note_added(const Note::Ptr &);
void on_note_deleted(const Note::Ptr &);
void on_note_saved(const Note::Ptr &);
+ void present_note(const Note::Ptr &);
NoteManager & m_manager;
};
diff --git a/src/gnote.cpp b/src/gnote.cpp
index a4c764d..5c97fac 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -427,6 +427,27 @@ namespace gnote {
}
}
+ NoteRecentChanges::Ptr Gnote::get_window_for_note()
+ {
+ NoteRecentChanges::Ptr window;
+ //Find first visible window or any window otherwise
+ for(std::list<NoteRecentChanges::Ptr>::iterator iter = m_main_windows.begin();
+ iter != m_main_windows.end(); ++iter) {
+ if((*iter)->get_visible()) {
+ window = *iter;
+ break;
+ }
+ if(!window) {
+ window = *iter;
+ }
+ }
+ if(!window) {
+ window = new_main_window();
+ }
+
+ return window;
+ }
+
void Gnote::open_search_all()
{
get_main_window()->present();
diff --git a/src/gnote.hpp b/src/gnote.hpp
index e5c9eea..f24d41c 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -134,6 +134,7 @@ public:
void on_show_about_action();
NoteRecentChanges::Ptr new_main_window();
NoteRecentChanges::Ptr get_main_window();
+ NoteRecentChanges::Ptr get_window_for_note();
void open_search_all();
void open_note_sync_window();
diff --git a/src/noterenamedialog.cpp b/src/noterenamedialog.cpp
index 6ee6b3c..4d13c86 100644
--- a/src/noterenamedialog.cpp
+++ b/src/noterenamedialog.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011 Aurimas Cernius
+ * Copyright (C) 2011-2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
*
* This program is free software: you can redistribute it and/or modify
@@ -28,8 +28,10 @@
#include <glibmm/i18n.h>
+#include "gnote.hpp"
#include "notewindow.hpp"
#include "noterenamedialog.hpp"
+#include "recentchanges.hpp"
namespace gnote {
@@ -359,13 +361,19 @@ void NoteRenameDialog::on_notes_view_row_activated(
if (!note)
return;
- NoteWindow * const window = note->get_window();
- if (!window)
- return;
+ Gtk::Widget *parent = get_parent();
+ NoteRecentChanges::Ptr window;
+ if(parent) {
+ window = NoteRecentChanges::get_owning(*parent);
+ }
+ if(!window) {
+ window = Gnote::obj().new_main_window();
+ }
+ window->present_note(note);
window->present();
- NoteFindBar & find = window->get_find_bar();
+ NoteFindBar & find = note->get_window()->get_find_bar();
find.show_all();
find.property_visible() = true;
find.set_search_text(Glib::ustring::compose("\"%1\"", old_title));
diff --git a/src/prefskeybinder.cpp b/src/prefskeybinder.cpp
index 00f9b51..7c2cd01 100644
--- a/src/prefskeybinder.cpp
+++ b/src/prefskeybinder.cpp
@@ -204,7 +204,9 @@ namespace gnote {
{
Note::Ptr note = m_manager.find_by_uri (m_manager.start_note_uri());
if (note) {
- note->get_window()->present ();
+ NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ window->present_note(note);
+ window->present();
}
}
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index d215721..09bacf7 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -223,6 +223,40 @@ namespace gnote {
}
+ void NoteRecentChanges::present_note(const Note::Ptr & note)
+ {
+ note->get_window()->show();
+ }
+
+
+ NoteRecentChanges::Ptr NoteRecentChanges::get_owning(Gtk::Widget & widget)
+ {
+ Ptr owner;
+ Gtk::Container *container = widget.get_parent();
+ if(!container) {
+ try {
+ return dynamic_cast<NoteRecentChanges &>(widget).shared_from_this();
+ }
+ catch(std::bad_cast &) {
+ return owner;
+ }
+ }
+
+ Gtk::Container *cntr = container->get_parent();
+ while(cntr) {
+ container = cntr;
+ cntr = container->get_parent();
+ }
+
+ NoteRecentChanges *recent_changes = dynamic_cast<NoteRecentChanges*>(container);
+ if(recent_changes) {
+ owner = recent_changes->shared_from_this();
+ }
+
+ return owner;
+ }
+
+
Gtk::MenuBar *NoteRecentChanges::create_menu_bar ()
{
ActionManager &am(ActionManager::obj());
@@ -1145,8 +1179,15 @@ namespace gnote {
void NoteRecentChanges::on_open_note()
{
Note::List selected_notes = get_selected_notes ();
- for(Note::List::iterator iter = selected_notes.begin(); iter != selected_notes.end(); ++iter) {
- (*iter)->get_window()->present();
+ Note::List::iterator iter = selected_notes.begin();
+ if(iter != selected_notes.end()) {
+ present_note(*iter);
+ ++iter;
+ }
+ for(; iter != selected_notes.end(); ++iter) {
+ NoteRecentChanges::Ptr window = Gnote::obj().new_main_window();
+ window->present_note(*iter);
+ window->present();
}
}
@@ -1289,7 +1330,7 @@ namespace gnote {
Note::Ptr note = (*iter)[m_column_types.note];
- note->get_window()->present ();
+ present_note(note);
// Tell the new window to highlight the matches and
// prepopulate the Firefox-style search
@@ -1507,7 +1548,7 @@ namespace gnote {
if (!templateNote)
return; // something seriously went wrong
- templateNote->get_window()->present ();
+ present_note(templateNote);
}
notebooks::Notebook::Ptr NoteRecentChanges::get_selected_notebook ()
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index 845e322..6115d74 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -71,9 +71,11 @@ public:
{
return Ptr(new NoteRecentChanges(m));
}
+ static Ptr get_owning(Gtk::Widget & widget);
virtual ~NoteRecentChanges();
void set_search_text(const std::string & value);
+ void present_note(const Note::Ptr & note);
protected:
NoteRecentChanges(NoteManager& m);
virtual void on_show();
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 17f887e..c7e4152 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -465,7 +465,7 @@ void SyncDialog::on_row_activated(const Gtk::TreeModel::Path & path, Gtk::TreeVi
Note::Ptr note = Gnote::obj().default_note_manager().find(noteTitle);
if(note != 0) {
- note->get_window()->present();
+ present_note(note);
}
}
@@ -672,9 +672,10 @@ void SyncDialog::note_conflict_detected(NoteManager & manager,
}
-void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer)
+void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer this__)
{
NoteConflictDetectedArgs *args = static_cast<NoteConflictDetectedArgs*>(data);
+ SyncDialog *this_ = static_cast<SyncDialog*>(this__);
try {
SyncTitleConflictDialog conflictDlg(args->localConflictNote, args->noteUpdateTitles);
Gtk::ResponseType reponse = Gtk::RESPONSE_OK;
@@ -717,13 +718,13 @@ void SyncDialog::on_note_conflict_detected(GObject*, gpointer data, gpointer)
if(conflictDlg.always_perform_this_action()) {
args->savedBehavior = args->resolution;
}
- rename_note(args->localConflictNote, conflictDlg.renamed_title(), true);
+ this_->rename_note(args->localConflictNote, conflictDlg.renamed_title(), true);
break;
case RENAME_EXISTING_NO_UPDATE:
if(conflictDlg.always_perform_this_action()) {
args->savedBehavior = args->resolution;
}
- rename_note(args->localConflictNote, conflictDlg.renamed_title(), false);
+ this_->rename_note(args->localConflictNote, conflictDlg.renamed_title(), false);
break;
case CANCEL:
break;
@@ -778,9 +779,16 @@ void SyncDialog::rename_note(const Note::Ptr & note, const std::string & newTitl
catch(...) {} // TODO: Handle exception in case that newCompleteContent is invalid XML
}
if(noteOpen) {
- renamedNote->get_window()->present();
+ present_note(renamedNote);
}
}
+void SyncDialog::present_note(const Note::Ptr & note)
+{
+ NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ window->present_note(note);
+ window->present();
+}
+
}
}
diff --git a/src/synchronization/syncdialog.hpp b/src/synchronization/syncdialog.hpp
index ad19e0b..99290a2 100644
--- a/src/synchronization/syncdialog.hpp
+++ b/src/synchronization/syncdialog.hpp
@@ -62,7 +62,6 @@ namespace sync {
static void on_expander_activated(GtkExpander*, gpointer);
static void on_sync_state_changed(GObject*, int, gpointer);
static void on_note_conflict_detected(GObject*, gpointer, gpointer);
- static void rename_note(const Note::Ptr & note, const std::string & newTitle, bool updateReferencingNotes);
SyncDialog();
bool on_pulse_progress_bar();
@@ -70,6 +69,8 @@ namespace sync {
void treeview_col1_data_func(Gtk::CellRenderer *renderer, const Gtk::TreeIter & iter);
void treeview_col2_data_func(Gtk::CellRenderer *renderer, const Gtk::TreeIter & iter);
void sync_state_changed_(SyncState state);
+ void rename_note(const Note::Ptr & note, const std::string & newTitle, bool updateReferencingNotes);
+ void present_note(const Note::Ptr &);
Gtk::Image *m_image;
Gtk::Label *m_header_label;
diff --git a/src/tray.cpp b/src/tray.cpp
index cf452b4..633bb91 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -99,7 +99,9 @@ namespace gnote {
{
if(!m_inhibit_activate) {
if(m_note) {
- m_note->get_window()->present();
+ NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ window->present_note(m_note);
+ window->present();
}
}
}
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 16fdc68..5afcbb8 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -33,10 +33,12 @@
#include "sharp/string.hpp"
#include "debug.hpp"
+#include "gnote.hpp"
#include "noteeditor.hpp"
#include "notemanager.hpp"
#include "notewindow.hpp"
#include "preferences.hpp"
+#include "recentchanges.hpp"
#include "tagmanager.hpp"
#include "triehit.hpp"
#include "watchers.hpp"
@@ -222,10 +224,6 @@ namespace gnote {
Note::Ptr existing = manager().find (title);
if (existing && (existing != get_note())) {
- // Present the window in case it got unmapped...
- // FIXME: Causes flicker.
- get_note()->get_window()->present ();
-
show_name_clash_error (title);
return false;
}
@@ -883,7 +881,8 @@ namespace gnote {
}
- bool NoteLinkWatcher::open_or_create_link(const Gtk::TextIter & start,
+ bool NoteLinkWatcher::open_or_create_link(const NoteEditor & editor,
+ const Gtk::TextIter & start,
const Gtk::TextIter & end)
{
std::string link_name = start.get_text (end);
@@ -914,18 +913,23 @@ namespace gnote {
// also works around the bug.
if (link) {
DBG_OUT ("Opening note '%s' on click...", link_name.c_str());
- link->get_window()->present ();
+ NoteRecentChanges::Ptr window = NoteRecentChanges::get_owning(const_cast<NoteEditor&>(editor));
+ if(!window) {
+ window = Gnote::obj().new_main_window();
+ }
+ window->present_note(link);
+ window->present();
return true;
}
return false;
}
- bool NoteLinkWatcher::on_link_tag_activated(const NoteTag::Ptr &, const NoteEditor &,
+ bool NoteLinkWatcher::on_link_tag_activated(const NoteTag::Ptr &, const NoteEditor & editor,
const Gtk::TextIter &start,
const Gtk::TextIter &end)
{
- return open_or_create_link (start, end);
+ return open_or_create_link(editor, start, end);
}
diff --git a/src/watchers.hpp b/src/watchers.hpp
index 4d57a59..a8a9353 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -185,7 +185,7 @@ namespace gnote {
void on_apply_tag(const Glib::RefPtr<Gtk::TextBuffer::Tag> & tag,
const Gtk::TextIter & start, const Gtk::TextIter &end);
- bool open_or_create_link(const Gtk::TextIter &,const Gtk::TextIter &);
+ bool open_or_create_link(const NoteEditor &, const Gtk::TextIter &,const Gtk::TextIter &);
bool on_link_tag_activated(const NoteTag::Ptr &, const NoteEditor &,
const Gtk::TextIter &, const Gtk::TextIter &);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]