[gnote] Save main window sorting, always show it
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Save main window sorting, always show it
- Date: Sun, 7 Jul 2013 20:43:35 +0000 (UTC)
commit 2f55a3bf6a7b45b33ddbcc34ee62f8da2124390d
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Jul 7 23:41:48 2013 +0300
Save main window sorting, always show it
Main window is always sorder, show it (fixes Bug 700609).
Save sorting and restore on next invocation (fixes Bug 700436).
data/org.gnome.gnote.gschema.xml.in | 5 ++
src/preferences.cpp | 1 +
src/preferences.hpp | 1 +
src/searchnoteswidget.cpp | 92 ++++++++++++++++++++++++++++++++---
src/searchnoteswidget.hpp | 4 ++
5 files changed, 96 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.gnote.gschema.xml.in b/data/org.gnome.gnote.gschema.xml.in
index 28b0717..0217e70 100644
--- a/data/org.gnome.gnote.gschema.xml.in
+++ b/data/org.gnome.gnote.gschema.xml.in
@@ -70,6 +70,11 @@
<_summary>Saved splitter position of Search window splitter.</_summary>
<_description>Determines Search window splitter position in pixels; stored on Gnote
exit.</_description>
</key>
+ <key name="search-sorting" type="s">
+ <default>'change:asc'</default>
+ <_summary>Saved sorting of the Search window.</_summary>
+ <_description>Determines Search window initial sorting.</_description>
+ </key>
<key name="sync-fuse-mount-timeout-ms" type="i">
<default>10000</default>
<_summary>FUSE Mounting Timeout (ms)</_summary>
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 1b7a1c0..c40366b 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -66,6 +66,7 @@ namespace gnote {
const char * Preferences::SEARCH_WINDOW_WIDTH = "search-window-width";
const char * Preferences::SEARCH_WINDOW_HEIGHT = "search-window-height";
const char * Preferences::SEARCH_WINDOW_SPLITTER_POS = "search-window-splitter-pos";
+ const char * Preferences::SEARCH_SORTING = "search-sorting";
const char * Preferences::SYNC_FUSE_MOUNT_TIMEOUT = "sync-fuse-mount-timeout-ms";
const char * Preferences::SYNC_FUSE_WDFS_ACCEPT_SSLCERT = "accept-sslcert";
diff --git a/src/preferences.hpp b/src/preferences.hpp
index 014228c..d2e9b89 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -64,6 +64,7 @@ namespace gnote {
static const char *SEARCH_WINDOW_WIDTH;
static const char *SEARCH_WINDOW_HEIGHT;
static const char *SEARCH_WINDOW_SPLITTER_POS;
+ static const char *SEARCH_SORTING;
static const char *KEYBINDING_SHOW_NOTE_MENU;
static const char *KEYBINDING_OPEN_START_HERE;
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index c7d50fd..b28b463 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -59,6 +59,8 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
, m_note_list_context_menu(NULL)
, m_notebook_list_context_menu(NULL)
, m_initial_position_restored(false)
+ , m_sort_column_id(2)
+ , m_sort_column_order(Gtk::SORT_DESCENDING)
{
set_hexpand(true);
set_vexpand(true);
@@ -101,8 +103,9 @@ SearchNotesWidget::SearchNotesWidget(NoteManager & m)
notebooks::NotebookManager::obj().signal_note_pin_status_changed
.connect(sigc::mem_fun(*this, &SearchNotesWidget::on_note_pin_status_changed));
- Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE)->signal_changed()
- .connect(sigc::mem_fun(*this, &SearchNotesWidget::on_settings_changed));
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE);
+ settings->signal_changed().connect(sigc::mem_fun(*this, &SearchNotesWidget::on_settings_changed));
+ parse_sorting_setting(settings->get_string(Preferences::SEARCH_SORTING));
}
SearchNotesWidget::~SearchNotesWidget()
@@ -486,6 +489,10 @@ void SearchNotesWidget::update_results()
sigc::mem_fun(*this, &SearchNotesWidget::compare_titles));
m_store_sort->set_sort_func(2 /* change date */,
sigc::mem_fun(*this, &SearchNotesWidget::compare_dates));
+ m_store_sort->set_sort_column(m_sort_column_id, m_sort_column_order);
+ m_store_sort->unset_default_sort_func();
+ m_store_sort->signal_sort_column_changed()
+ .connect(sigc::mem_fun(*this, &SearchNotesWidget::on_sorting_changed));
int cnt = 0;
@@ -983,14 +990,12 @@ void SearchNotesWidget::on_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragCo
void SearchNotesWidget::remove_matches_column()
{
- if(m_matches_column == NULL) {
+ if(m_matches_column == NULL || !m_matches_column->get_visible()) {
return;
}
- m_tree->remove_column(*m_matches_column);
- m_matches_column = NULL;
-
- m_store_sort->set_sort_column(2, Gtk::SORT_DESCENDING);
+ m_matches_column->set_visible(false);
+ m_store_sort->set_sort_column(m_sort_column_id, m_sort_column_order);
}
// called when no search results are found in the selected notebook
@@ -1044,6 +1049,10 @@ void SearchNotesWidget::add_matches_column()
m_tree->append_column(*m_matches_column);
m_store_sort->set_sort_column(4, Gtk::SORT_DESCENDING);
}
+ else {
+ m_matches_column->set_visible(true);
+ m_store_sort->set_sort_column(4, Gtk::SORT_DESCENDING);
+ }
}
bool SearchNotesWidget::show_all_search_results()
@@ -1420,4 +1429,73 @@ void SearchNotesWidget::on_settings_changed(const Glib::ustring & key)
}
}
+void SearchNotesWidget::on_sorting_changed()
+{
+ // don't do anything if in search mode
+ if(m_matches_column && m_matches_column->get_visible()) {
+ return;
+ }
+
+ if(m_store_sort) {
+ m_store_sort->get_sort_column_id(m_sort_column_id, m_sort_column_order);
+ Glib::ustring value;
+ switch(m_sort_column_id) {
+ case 1:
+ value = "note:";
+ break;
+ case 2:
+ value = "change:";
+ break;
+ default:
+ return;
+ }
+ if(m_sort_column_order == Gtk::SORT_ASCENDING) {
+ value += "asc";
+ }
+ else {
+ value += "desc";
+ }
+ Preferences::obj().get_schema_settings(Preferences::SCHEMA_GNOTE)->set_string(
+ Preferences::SEARCH_SORTING, value);
+ }
+}
+
+void SearchNotesWidget::parse_sorting_setting(const Glib::ustring & sorting)
+{
+ std::vector<std::string> tokens;
+ sharp::string_split(tokens, sorting.lowercase(), ":");
+ if(tokens.size() != 2) {
+ ERR_OUT(_("Failed to parse setting %s (Value: %s):"), Preferences::SEARCH_SORTING, sorting.c_str());
+ ERR_OUT(_("Expected format 'column:order'"));
+ return;
+ }
+ int column_id;
+ Gtk::SortType order;
+ if(tokens[0] == "note") {
+ column_id = 1;
+ }
+ else if(tokens[0] == "change") {
+ column_id = 2;
+ }
+ else {
+ ERR_OUT(_("Failed to parse setting %s (Value: %s):"), Preferences::SEARCH_SORTING, sorting.c_str());
+ ERR_OUT(_("Unrecognized column %s"), tokens[0].c_str());
+ return;
+ }
+ if(tokens[1] == "asc") {
+ order = Gtk::SORT_ASCENDING;
+ }
+ else if(tokens[1] == "desc") {
+ order = Gtk::SORT_DESCENDING;
+ }
+ else {
+ ERR_OUT(_("Failed to parse setting %s (Value: %s):"), Preferences::SEARCH_SORTING, sorting.c_str());
+ ERR_OUT(_("Unrecognized order %s"), tokens[1].c_str());
+ return;
+ }
+
+ m_sort_column_id = column_id;
+ m_sort_column_order = order;
+}
+
}
diff --git a/src/searchnoteswidget.hpp b/src/searchnoteswidget.hpp
index 3c2c5fb..bfe9bc3 100644
--- a/src/searchnoteswidget.hpp
+++ b/src/searchnoteswidget.hpp
@@ -121,6 +121,8 @@ private:
void on_new_notebook();
void on_delete_notebook();
void on_settings_changed(const Glib::ustring & key);
+ void on_sorting_changed();
+ void parse_sorting_setting(const Glib::ustring & sorting);
class RecentSearchColumnTypes
: public Gtk::TreeModelColumnRecord
@@ -172,6 +174,8 @@ private:
Gtk::Menu *m_notebook_list_context_menu;
bool m_initial_position_restored;
std::string m_search_text;
+ int m_sort_column_id;
+ Gtk::SortType m_sort_column_order;
static Glib::RefPtr<Gdk::Pixbuf> get_note_icon();
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]