[gnote] Refactor embeddable widgets
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Refactor embeddable widgets
- Date: Thu, 23 May 2013 20:50:40 +0000 (UTC)
commit 501550519084f5be07a94e20c80789e7cbc848b2
Author: Aurimas Černius <aurisc4 gmail com>
Date: Thu May 23 23:47:42 2013 +0300
Refactor embeddable widgets
* Move all embeddable related classes to mainwindowembeds
* Add methods for sizing/positioning to EmbeddableWidget
* Make Search and Note windows implement new methods for
* sizing/positioning
* Fix splitter in search window (Bug 700431)
src/Makefile.am | 2 +-
src/addins/statistics/statisticswidget.cpp | 4 +-
src/addins/statistics/statisticswidget.hpp | 4 +-
src/mainwindow.hpp | 3 +-
src/mainwindowembeds.cpp | 81 ++++++++++++++++++++++++++
src/mainwindowembeds.hpp | 56 ++++++++++++++++++
src/notewindow.cpp | 33 +++++++----
src/notewindow.hpp | 7 ++-
src/recentchanges.cpp | 85 +++++++++++++++++++---------
src/recentchanges.hpp | 16 +++---
src/searchnoteswidget.cpp | 74 ++++++++++---------------
src/searchnoteswidget.hpp | 10 ++-
src/utils.cpp | 17 ------
src/utils.hpp | 63 --------------------
14 files changed, 271 insertions(+), 184 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0e807a9..4dceadb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -110,7 +110,7 @@ libgnote_la_SOURCES = \
itagmanager.hpp itagmanager.cpp \
importaddin.hpp importaddin.cpp \
mainwindow.hpp mainwindow.cpp \
- mainwindowembeds.hpp \
+ mainwindowembeds.hpp mainwindowembeds.cpp \
noteaddin.hpp noteaddin.cpp \
notebuffer.hpp notebuffer.cpp \
noteeditor.hpp noteeditor.cpp \
diff --git a/src/addins/statistics/statisticswidget.cpp b/src/addins/statistics/statisticswidget.cpp
index 3998240..2b467c4 100644
--- a/src/addins/statistics/statisticswidget.cpp
+++ b/src/addins/statistics/statisticswidget.cpp
@@ -174,7 +174,7 @@ std::string StatisticsWidget::get_name() const
void StatisticsWidget::foreground()
{
- gnote::utils::EmbeddableWidget::foreground();
+ gnote::EmbeddableWidget::foreground();
StatisticsModel::Ptr model = StatisticsModel::Ptr::cast_static(get_model());
model->active(true);
model->update();
@@ -183,7 +183,7 @@ void StatisticsWidget::foreground()
void StatisticsWidget::background()
{
- gnote::utils::EmbeddableWidget::background();
+ gnote::EmbeddableWidget::background();
StatisticsModel::Ptr::cast_static(get_model())->active(false);
}
diff --git a/src/addins/statistics/statisticswidget.hpp b/src/addins/statistics/statisticswidget.hpp
index 9edbaeb..6f649f8 100644
--- a/src/addins/statistics/statisticswidget.hpp
+++ b/src/addins/statistics/statisticswidget.hpp
@@ -23,15 +23,15 @@
#include <gtkmm/treeview.h>
+#include "mainwindowembeds.hpp"
#include "notemanager.hpp"
-#include "utils.hpp"
namespace statistics {
class StatisticsWidget
: public Gtk::TreeView
- , public gnote::utils::EmbeddableWidget
+ , public gnote::EmbeddableWidget
{
public:
StatisticsWidget(gnote::NoteManager & nm);
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index 5b72038..9b7fea6 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -21,6 +21,7 @@
#ifndef _MAINWINDOW_HPP_
#define _MAINWINDOW_HPP_
+#include "mainwindowembeds.hpp"
#include "note.hpp"
#include "utils.hpp"
@@ -29,7 +30,7 @@ namespace gnote {
class MainWindow
: public utils::ForcedPresentWindow
- , public utils::EmbeddableWidgetHost
+ , public EmbeddableWidgetHost
{
public:
static MainWindow *get_owning(Gtk::Widget & widget);
diff --git a/src/mainwindowembeds.cpp b/src/mainwindowembeds.cpp
new file mode 100644
index 0000000..d48523a
--- /dev/null
+++ b/src/mainwindowembeds.cpp
@@ -0,0 +1,81 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2013 Aurimas Cernius
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "mainwindowembeds.hpp"
+
+
+namespace gnote {
+
+void EmbeddableWidget::embed(EmbeddableWidgetHost *h)
+{
+ //remove from previous host, if any
+ if(m_host) {
+ m_host->unembed_widget(*this);
+ }
+ m_host = h;
+ signal_embedded();
+}
+
+void EmbeddableWidget::unembed()
+{
+ m_host = NULL;
+ signal_unembedded();
+}
+
+void EmbeddableWidget::foreground()
+{
+ signal_foregrounded();
+}
+
+void EmbeddableWidget::background()
+{
+ signal_backgrounded();
+}
+
+void EmbeddableWidget::hint_position(int &, int &)
+{
+}
+
+void EmbeddableWidget::hint_size(int &, int &)
+{
+}
+
+void EmbeddableWidget::size_internals()
+{
+}
+
+
+bool SearchableItem::supports_goto_result()
+{
+ return false;
+}
+
+bool SearchableItem::goto_next_result()
+{
+ return false;
+}
+
+bool SearchableItem::goto_previous_result()
+{
+ return false;
+}
+
+}
+
diff --git a/src/mainwindowembeds.hpp b/src/mainwindowembeds.hpp
index 3e7bb06..c2af95e 100644
--- a/src/mainwindowembeds.hpp
+++ b/src/mainwindowembeds.hpp
@@ -18,11 +18,63 @@
*/
+#ifndef _MAINWINDOWEMBEDS_HPP_
+#define _MAINWINDOWEMBEDS_HPP_
+
+
#include <gtkmm/widget.h>
namespace gnote {
+class EmbeddableWidget;
+class EmbeddableWidgetHost
+{
+public:
+ virtual void embed_widget(EmbeddableWidget &) = 0;
+ virtual void unembed_widget(EmbeddableWidget &) = 0;
+ virtual void foreground_embedded(EmbeddableWidget &) = 0;
+ virtual void background_embedded(EmbeddableWidget &) = 0;
+ virtual bool running() = 0;
+};
+
+class EmbeddableWidget
+{
+public:
+ EmbeddableWidget() : m_host(NULL) {}
+ virtual std::string get_name() const = 0;
+ virtual void embed(EmbeddableWidgetHost *h);
+ virtual void unembed();
+ virtual void foreground();
+ virtual void background();
+ virtual void hint_position(int & x, int & y);
+ virtual void hint_size(int & width, int & height);
+ virtual void size_internals();
+ EmbeddableWidgetHost *host() const
+ {
+ return m_host;
+ }
+
+ sigc::signal<void, const std::string &> signal_name_changed;
+ sigc::signal<void> signal_embedded;
+ sigc::signal<void> signal_unembedded;
+ sigc::signal<void> signal_foregrounded;
+ sigc::signal<void> signal_backgrounded;
+private:
+ EmbeddableWidgetHost *m_host;
+};
+
+
+class SearchableItem
+{
+public:
+ virtual void perform_search(const std::string & search_text) = 0;
+ virtual bool supports_goto_result();
+ virtual bool goto_next_result();
+ virtual bool goto_previous_result();
+};
+
+
class HasEmbeddableToolbar
{
public:
@@ -30,3 +82,7 @@ public:
};
}
+
+
+#endif
+
diff --git a/src/notewindow.cpp b/src/notewindow.cpp
index ba4d415..041eb4f 100644
--- a/src/notewindow.cpp
+++ b/src/notewindow.cpp
@@ -143,31 +143,21 @@ namespace gnote {
void NoteWindow::foreground()
{
//addins may add accelarators, so accel group must be there
- utils::EmbeddableWidgetHost *current_host = host();
+ EmbeddableWidgetHost *current_host = host();
Gtk::Window *parent = dynamic_cast<Gtk::Window*>(current_host);
if(parent) {
add_accel_group(*parent);
}
- utils::EmbeddableWidget::foreground();
+ EmbeddableWidget::foreground();
if(parent) {
- parent->set_default_size(m_width, m_height);
- Glib::RefPtr<Gdk::Window> parent_window = parent->get_window();
- if(parent_window != 0 && (parent_window->get_state() & Gdk::WINDOW_STATE_MAXIMIZED) == 0
- && parent->get_visible()) {
- parent_window->resize(m_width, m_height);
- }
- if(m_x >= 0 && m_y >= 0 && !current_host->running()) {
- parent->move(m_x, m_y);
- }
parent->set_focus(*m_editor);
}
- m_editor->scroll_to(m_editor->get_buffer()->get_insert());
}
void NoteWindow::background()
{
- utils::EmbeddableWidget::background();
+ EmbeddableWidget::background();
Gtk::Window *parent = dynamic_cast<Gtk::Window*>(host());
if(!parent) {
return;
@@ -192,6 +182,23 @@ namespace gnote {
}
}
+ void NoteWindow::hint_position(int & x, int & y)
+ {
+ x = m_x;
+ y = m_y;
+ }
+
+ void NoteWindow::hint_size(int & width, int & height)
+ {
+ width = m_width;
+ height = m_height;
+ }
+
+ void NoteWindow::size_internals()
+ {
+ m_editor->scroll_to(m_editor->get_buffer()->get_insert());
+ }
+
void NoteWindow::add_accel_group(Gtk::Window & window)
{
if(!m_accel_group) {
diff --git a/src/notewindow.hpp b/src/notewindow.hpp
index 3a5e586..dff9d42 100644
--- a/src/notewindow.hpp
+++ b/src/notewindow.hpp
@@ -130,8 +130,8 @@ private:
class NoteWindow
: public Gtk::VBox
- , public utils::EmbeddableWidget
- , public utils::SearchableItem
+ , public EmbeddableWidget
+ , public SearchableItem
, public HasEmbeddableToolbar
{
public:
@@ -142,6 +142,9 @@ public:
void set_name(const std::string & name);
virtual void foreground();
virtual void background();
+ virtual void hint_position(int & x, int & y);
+ virtual void hint_size(int & width, int & height);
+ virtual void size_internals();
virtual void perform_search(const std::string & text);
virtual bool supports_goto_result();
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index c46c6f1..2a14e4b 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -246,7 +246,7 @@ namespace gnote {
}
else {
m_search_box.hide();
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->perform_search("");
}
@@ -255,7 +255,7 @@ namespace gnote {
void NoteRecentChanges::on_find_next_button_clicked()
{
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->goto_next_result();
}
@@ -263,7 +263,7 @@ namespace gnote {
void NoteRecentChanges::on_find_prev_button_clicked()
{
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->goto_previous_result();
}
@@ -275,7 +275,7 @@ namespace gnote {
m_search_entry.grab_focus();
Glib::ustring text = m_search_entry.get_text();
if(text != "") {
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->perform_search(text);
}
@@ -284,7 +284,7 @@ namespace gnote {
void NoteRecentChanges::present_search()
{
- utils::EmbeddableWidget *current = currently_embedded();
+ EmbeddableWidget *current = currently_embedded();
if(&m_search_notes_widget == dynamic_cast<SearchNotesWidget*>(current)) {
return;
}
@@ -340,7 +340,7 @@ namespace gnote {
std::vector<Gtk::Widget*> current = m_embed_box.get_children();
for(std::vector<Gtk::Widget*>::iterator iter = current.begin();
iter != current.end(); ++iter) {
- utils::EmbeddableWidget *widget = dynamic_cast<utils::EmbeddableWidget*>(*iter);
+ EmbeddableWidget *widget = dynamic_cast<EmbeddableWidget*>(*iter);
if(widget) {
background_embedded(*widget);
}
@@ -369,7 +369,7 @@ namespace gnote {
on_close_window();
}
else {
- utils::EmbeddableWidget *current_item = currently_embedded();
+ EmbeddableWidget *current_item = currently_embedded();
if(current_item) {
background_embedded(*current_item);
}
@@ -391,11 +391,21 @@ namespace gnote {
// Select "All Notes" in the notebooks list
m_search_notes_widget.select_all_notes_notebook();
+ EmbeddableWidget *widget = NULL;
if(m_embed_box.get_children().size() == 0 && m_embedded_widgets.size() > 0) {
- foreground_embedded(**m_embedded_widgets.rbegin());
+ widget = *m_embedded_widgets.rbegin();
+ foreground_embedded(*widget);
}
- std::vector<Gtk::Widget*> embedded = m_embed_box.get_children();
+
MainWindow::on_show();
+
+ if(widget) {
+ int x = 0, y = 0;
+ widget->hint_position(x, y);
+ if(x && y) {
+ move(x, y);
+ }
+ }
}
void NoteRecentChanges::set_search_text(const std::string & value)
@@ -403,23 +413,29 @@ namespace gnote {
m_search_entry.set_text(value);
}
- void NoteRecentChanges::embed_widget(utils::EmbeddableWidget & widget)
+ void NoteRecentChanges::embed_widget(EmbeddableWidget & widget)
{
if(std::find(m_embedded_widgets.begin(), m_embedded_widgets.end(), &widget) == m_embedded_widgets.end())
{
widget.embed(this);
m_embedded_widgets.push_back(&widget);
}
- utils::EmbeddableWidget *current = currently_embedded();
- if(current && current != &widget) {
+ EmbeddableWidget *current = currently_embedded();
+ if(current == &widget) {
+ return;
+ }
+ if(current) {
background_embedded(*current);
}
- foreground_embedded(widget);
+
+ if(get_visible()) {
+ foreground_embedded(widget);
+ }
}
- void NoteRecentChanges::unembed_widget(utils::EmbeddableWidget & widget)
+ void NoteRecentChanges::unembed_widget(EmbeddableWidget & widget)
{
bool show_other = false;
- std::list<utils::EmbeddableWidget*>::iterator iter = std::find(
+ std::list<EmbeddableWidget*>::iterator iter = std::find(
m_embedded_widgets.begin(), m_embedded_widgets.end(), &widget);
if(iter != m_embedded_widgets.end()) {
if(is_foreground(**iter)) {
@@ -439,7 +455,7 @@ namespace gnote {
}
}
- void NoteRecentChanges::foreground_embedded(utils::EmbeddableWidget & widget)
+ void NoteRecentChanges::foreground_embedded(EmbeddableWidget & widget)
{
try {
if(currently_embedded() == &widget) {
@@ -447,8 +463,25 @@ namespace gnote {
}
Gtk::Widget &wid = dynamic_cast<Gtk::Widget&>(widget);
m_embed_box.add(wid);
- widget.foreground();
wid.show();
+ widget.foreground();
+
+ bool maximized = Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE)->get_boolean(
+ Preferences::MAIN_WINDOW_MAXIMIZED);
+ if(get_realized()) {
+ //if window is showing, use actual state
+ maximized = get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED;
+ }
+ int width = 0, height = 0;
+ widget.hint_size(width, height);
+ if(width && height) {
+ set_default_size(width, height);
+ if(!maximized && get_visible()) {
+ get_window()->resize(width, height);
+ }
+ }
+ widget.size_internals();
+
update_toolbar(widget);
on_embedded_name_changed(widget.get_name());
m_current_embedded_name_slot = widget.signal_name_changed
@@ -458,7 +491,7 @@ namespace gnote {
}
}
- void NoteRecentChanges::background_embedded(utils::EmbeddableWidget & widget)
+ void NoteRecentChanges::background_embedded(EmbeddableWidget & widget)
{
try {
if(currently_embedded() != &widget) {
@@ -475,12 +508,12 @@ namespace gnote {
m_embedded_toolbar.remove();
}
- bool NoteRecentChanges::is_foreground(utils::EmbeddableWidget & widget)
+ bool NoteRecentChanges::is_foreground(EmbeddableWidget & widget)
{
std::vector<Gtk::Widget*> current = m_embed_box.get_children();
for(std::vector<Gtk::Widget*>::iterator iter = current.begin();
iter != current.end(); ++iter) {
- if(dynamic_cast<utils::EmbeddableWidget*>(*iter) == &widget) {
+ if(dynamic_cast<EmbeddableWidget*>(*iter) == &widget) {
return true;
}
}
@@ -488,10 +521,10 @@ namespace gnote {
return false;
}
- utils::EmbeddableWidget *NoteRecentChanges::currently_embedded()
+ EmbeddableWidget *NoteRecentChanges::currently_embedded()
{
std::vector<Gtk::Widget*> children = m_embed_box.get_children();
- return children.size() ? dynamic_cast<utils::EmbeddableWidget*>(children[0]) : NULL;
+ return children.size() ? dynamic_cast<EmbeddableWidget*>(children[0]) : NULL;
}
bool NoteRecentChanges::on_map_event(GdkEventAny *evt)
@@ -524,7 +557,7 @@ namespace gnote {
std::string search_text = get_search_text();
if(search_text.empty()) {
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->perform_search(search_text);
}
@@ -553,7 +586,7 @@ namespace gnote {
return;
}
- utils::SearchableItem *searchable_widget = dynamic_cast<utils::SearchableItem*>(currently_embedded());
+ SearchableItem *searchable_widget = dynamic_cast<SearchableItem*>(currently_embedded());
if(searchable_widget) {
searchable_widget->perform_search(search_text);
}
@@ -566,14 +599,14 @@ namespace gnote {
return text;
}
- void NoteRecentChanges::update_toolbar(utils::EmbeddableWidget & widget)
+ void NoteRecentChanges::update_toolbar(EmbeddableWidget & widget)
{
bool search = dynamic_cast<SearchNotesWidget*>(&widget) == &m_search_notes_widget;
m_all_notes_button->set_visible(!search);
m_new_note_button->set_visible(search);
try {
- utils::SearchableItem & searchable_item = dynamic_cast<utils::SearchableItem&>(widget);
+ SearchableItem & searchable_item = dynamic_cast<SearchableItem&>(widget);
m_search_button.show();
if(searchable_item.supports_goto_result()) {
m_find_next_prev_box.show();
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index dc932fc..5d597ba 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -49,10 +49,10 @@ public:
virtual void new_note();
virtual void present_search();
- virtual void embed_widget(utils::EmbeddableWidget &);
- virtual void unembed_widget(utils::EmbeddableWidget &);
- virtual void foreground_embedded(utils::EmbeddableWidget &);
- virtual void background_embedded(utils::EmbeddableWidget &);
+ virtual void embed_widget(EmbeddableWidget &);
+ virtual void unembed_widget(EmbeddableWidget &);
+ virtual void foreground_embedded(EmbeddableWidget &);
+ virtual void background_embedded(EmbeddableWidget &);
virtual bool running()
{
return m_mapped;
@@ -67,8 +67,8 @@ private:
void on_close_window();
bool on_delete(GdkEventAny *);
bool on_key_pressed(GdkEventKey *);
- bool is_foreground(utils::EmbeddableWidget &);
- utils::EmbeddableWidget *currently_embedded();
+ bool is_foreground(EmbeddableWidget &);
+ EmbeddableWidget *currently_embedded();
Gtk::Toolbar *make_toolbar();
void make_search_box();
void on_embedded_name_changed(const std::string & name);
@@ -76,7 +76,7 @@ private:
void on_entry_activated();
void entry_changed_timeout();
std::string get_search_text();
- void update_toolbar(utils::EmbeddableWidget & widget);
+ void update_toolbar(EmbeddableWidget & widget);
void on_show_window_menu(Gtk::Button *button);
void on_search_button_toggled();
void on_find_next_button_clicked();
@@ -97,7 +97,7 @@ private:
Gtk::Button *m_all_notes_button;
Gtk::Button *m_new_note_button;
Gtk::SearchEntry m_search_entry;
- std::list<utils::EmbeddableWidget*> m_embedded_widgets;
+ std::list<EmbeddableWidget*> m_embedded_widgets;
bool m_mapped;
sigc::connection m_current_embedded_name_slot;
utils::InterruptableTimeout *m_entry_changed_timeout;
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 640d7fe..fc1b7f5 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -87,8 +87,6 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
m_matches_window.add(*m_tree);
m_matches_window.show();
- restore_position();
-
pack_start(m_hpaned, true, true, 0);
// Update on changes to notes
@@ -202,7 +200,6 @@ void SearchNotesWidget::restore_matches_window()
if(m_no_matches_box && m_hpaned.get_child2() == m_no_matches_box) {
m_hpaned.remove(*m_no_matches_box);
m_hpaned.add2(m_matches_window);
- restore_position();
}
}
@@ -258,44 +255,6 @@ Gtk::Widget *SearchNotesWidget::make_notebooks_pane()
return sw;
}
-void SearchNotesWidget::restore_position()
-{
- Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
- .get_schema_settings(Preferences::SCHEMA_GNOTE);
- int x = settings->get_int(Preferences::SEARCH_WINDOW_X_POS);
- int y = settings->get_int(Preferences::SEARCH_WINDOW_Y_POS);
- int width = settings->get_int(Preferences::SEARCH_WINDOW_WIDTH);
- int height = settings->get_int(Preferences::SEARCH_WINDOW_HEIGHT);
- int pos = settings->get_int(Preferences::SEARCH_WINDOW_SPLITTER_POS);
- bool maximized = settings->get_boolean(Preferences::MAIN_WINDOW_MAXIMIZED);
-
- if((width == 0) || (height == 0)) {
- return;
- }
- Gtk::Window *window = get_owning_window();
- if(!window) {
- return;
- }
-
- if(window->get_realized()) {
- //if window is showing, use actual state
- maximized = window->get_window()->get_state() & Gdk::WINDOW_STATE_MAXIMIZED;
- }
-
- window->set_default_size(width, height);
- if(!m_initial_position_restored) {
- window->move(x, y);
- m_initial_position_restored = true;
- }
-
- if(!maximized && window->get_visible()) {
- window->get_window()->resize(width, height);
- }
- if(pos) {
- m_hpaned.set_position(pos);
- }
-}
-
void SearchNotesWidget::save_position()
{
int x;
@@ -303,7 +262,7 @@ void SearchNotesWidget::save_position()
int width;
int height;
- utils::EmbeddableWidgetHost *current_host = host();
+ EmbeddableWidgetHost *current_host = host();
if(!current_host || !current_host->running()) {
return;
}
@@ -1406,8 +1365,7 @@ void SearchNotesWidget::on_delete_notebook()
void SearchNotesWidget::foreground()
{
- utils::EmbeddableWidget::foreground();
- restore_position();
+ EmbeddableWidget::foreground();
Gtk::Window *win = dynamic_cast<Gtk::Window*>(host());
if(win) {
win->add_accel_group(m_accel_group);
@@ -1416,7 +1374,7 @@ void SearchNotesWidget::foreground()
void SearchNotesWidget::background()
{
- utils::EmbeddableWidget::background();
+ EmbeddableWidget::background();
save_position();
Gtk::Window *win = dynamic_cast<Gtk::Window*>(host());
if(win) {
@@ -1424,4 +1382,30 @@ void SearchNotesWidget::background()
}
}
+void SearchNotesWidget::hint_position(int & x, int & y)
+{
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+ .get_schema_settings(Preferences::SCHEMA_GNOTE);
+ x = settings->get_int(Preferences::SEARCH_WINDOW_X_POS);
+ y = settings->get_int(Preferences::SEARCH_WINDOW_Y_POS);
+}
+
+void SearchNotesWidget::hint_size(int & width, int & height)
+{
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+ .get_schema_settings(Preferences::SCHEMA_GNOTE);
+ width = settings->get_int(Preferences::SEARCH_WINDOW_WIDTH);
+ height = settings->get_int(Preferences::SEARCH_WINDOW_HEIGHT);
+}
+
+void SearchNotesWidget::size_internals()
+{
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+ .get_schema_settings(Preferences::SCHEMA_GNOTE);
+ int pos = settings->get_int(Preferences::SEARCH_WINDOW_SPLITTER_POS);
+ if(pos) {
+ m_hpaned.set_position(pos);
+ }
+}
+
}
diff --git a/src/searchnoteswidget.hpp b/src/searchnoteswidget.hpp
index f92b001..33ca564 100644
--- a/src/searchnoteswidget.hpp
+++ b/src/searchnoteswidget.hpp
@@ -31,7 +31,7 @@
#include <gtkmm/scrolledwindow.h>
#include <sigc++/sigc++.h>
-#include "utils.hpp"
+#include "mainwindowembeds.hpp"
#include "notebooks/notebook.hpp"
#include "notebooks/notebookstreeview.hpp"
@@ -40,8 +40,8 @@ namespace gnote {
class SearchNotesWidget
: public Gtk::VBox
- , public utils::EmbeddableWidget
- , public utils::SearchableItem
+ , public EmbeddableWidget
+ , public SearchableItem
{
public:
SearchNotesWidget(NoteManager & m);
@@ -49,6 +49,9 @@ public:
virtual std::string get_name() const;
virtual void foreground();
virtual void background();
+ virtual void hint_position(int & x, int & y);
+ virtual void hint_size(int & width, int & height);
+ virtual void size_internals();
virtual void perform_search(const std::string & search_text);
void select_all_notes_notebook();
@@ -62,7 +65,6 @@ private:
void perform_search();
void restore_matches_window();
Gtk::Widget *make_notebooks_pane();
- void restore_position();
void save_position();
void notebook_pixbuf_cell_data_func(Gtk::CellRenderer *, const Gtk::TreeIter &);
void notebook_text_cell_data_func(Gtk::CellRenderer *, const Gtk::TreeIter &);
diff --git a/src/utils.cpp b/src/utils.cpp
index 6e14ed9..b9f5d1a 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -815,23 +815,6 @@ namespace gnote {
{
set_active(false);
}
-
-
- bool SearchableItem::supports_goto_result()
- {
- return false;
- }
-
- bool SearchableItem::goto_next_result()
- {
- return false;
- }
-
- bool SearchableItem::goto_previous_result()
- {
- return false;
- }
-
}
}
diff --git a/src/utils.hpp b/src/utils.hpp
index 6d6c9a9..b77120a 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -245,69 +245,6 @@ namespace gnote {
void release_button();
};
- class EmbeddableWidget;
- class EmbeddableWidgetHost
- {
- public:
- virtual void embed_widget(EmbeddableWidget &) = 0;
- virtual void unembed_widget(EmbeddableWidget &) = 0;
- virtual void foreground_embedded(EmbeddableWidget &) = 0;
- virtual void background_embedded(EmbeddableWidget &) = 0;
- virtual bool running() = 0;
- };
-
- class EmbeddableWidget
- {
- public:
- EmbeddableWidget() : m_host(NULL) {}
- virtual std::string get_name() const = 0;
- virtual void embed(EmbeddableWidgetHost *h)
- {
- //remove from previous host, if any
- if(m_host) {
- m_host->unembed_widget(*this);
- }
- m_host = h;
- signal_embedded();
- }
- virtual void unembed()
- {
- m_host = NULL;
- signal_unembedded();
- }
- virtual void foreground()
- {
- signal_foregrounded();
- }
- virtual void background()
- {
- signal_backgrounded();
- }
- EmbeddableWidgetHost *host() const
- {
- return m_host;
- }
-
- sigc::signal<void, const std::string &> signal_name_changed;
- sigc::signal<void> signal_embedded;
- sigc::signal<void> signal_unembedded;
- sigc::signal<void> signal_foregrounded;
- sigc::signal<void> signal_backgrounded;
- private:
- EmbeddableWidgetHost *m_host;
- };
-
-
- class SearchableItem
- {
- public:
- virtual void perform_search(const std::string & search_text) = 0;
- virtual bool supports_goto_result();
- virtual bool goto_next_result();
- virtual bool goto_previous_result();
- };
-
-
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]