[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 235/473: Only save settings when changed.

noreply at xfce.org noreply at xfce.org
Mon Feb 16 23:56:45 CET 2015


This is an automated email from the git hooks/post-receive script.

gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit fb69d6c2a9d786fb248ee0540fc91bd1a464e77c
Author: Graeme Gott <graeme at gottcode.org>
Date:   Mon Nov 11 10:01:38 2013 -0500

    Only save settings when changed.
---
 panel-plugin/command.cpp              |   14 ++++++++++++++
 panel-plugin/command.h                |    5 +----
 panel-plugin/configuration-dialog.cpp |   10 ++++++++++
 panel-plugin/list-page.cpp            |    6 +++++-
 panel-plugin/page.cpp                 |    2 --
 panel-plugin/plugin.cpp               |   15 ++++++++++-----
 panel-plugin/recent-page.cpp          |    2 +-
 panel-plugin/settings.cpp             |    6 ++++++
 panel-plugin/settings.h               |   13 +++++++++++++
 panel-plugin/window.cpp               |   23 +++++++++++------------
 panel-plugin/window.h                 |    7 -------
 11 files changed, 71 insertions(+), 32 deletions(-)

diff --git a/panel-plugin/command.cpp b/panel-plugin/command.cpp
index c889207..21f23f5 100644
--- a/panel-plugin/command.cpp
+++ b/panel-plugin/command.cpp
@@ -17,6 +17,8 @@
 
 #include "command.h"
 
+#include "settings.h"
+
 #include <string>
 
 extern "C"
@@ -136,6 +138,18 @@ void Command::set(const gchar* command)
 		g_free(m_command);
 		m_command = g_strdup(command);
 		m_status = WHISKERMENU_COMMAND_UNCHECKED;
+		wm_settings->set_modified();
+	}
+}
+
+//-----------------------------------------------------------------------------
+
+void Command::set_shown(bool shown)
+{
+	if (shown != m_shown)
+	{
+		m_shown = shown;
+		wm_settings->set_modified();
 	}
 }
 
diff --git a/panel-plugin/command.h b/panel-plugin/command.h
index a7bbcc5..d14be08 100644
--- a/panel-plugin/command.h
+++ b/panel-plugin/command.h
@@ -52,10 +52,7 @@ public:
 
 	void set(const gchar* command);
 
-	void set_shown(bool shown)
-	{
-		m_shown = shown;
-	}
+	void set_shown(bool shown);
 
 	void check();
 
diff --git a/panel-plugin/configuration-dialog.cpp b/panel-plugin/configuration-dialog.cpp
index 52904be..fbd98d8 100644
--- a/panel-plugin/configuration-dialog.cpp
+++ b/panel-plugin/configuration-dialog.cpp
@@ -121,6 +121,7 @@ void ConfigurationDialog::choose_icon()
 void ConfigurationDialog::category_icon_size_changed(GtkComboBox* combo)
 {
 	wm_settings->category_icon_size = gtk_combo_box_get_active(combo) - 1;
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -128,6 +129,7 @@ void ConfigurationDialog::category_icon_size_changed(GtkComboBox* combo)
 void ConfigurationDialog::item_icon_size_changed(GtkComboBox* combo)
 {
 	wm_settings->launcher_icon_size = gtk_combo_box_get_active(combo) - 1;
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -150,6 +152,7 @@ void ConfigurationDialog::title_changed()
 void ConfigurationDialog::toggle_hover_switch_category(GtkToggleButton* button)
 {
 	wm_settings->category_hover_activate = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -157,6 +160,7 @@ void ConfigurationDialog::toggle_hover_switch_category(GtkToggleButton* button)
 void ConfigurationDialog::toggle_show_name(GtkToggleButton* button)
 {
 	wm_settings->launcher_show_name = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 	m_plugin->reload();
 }
 
@@ -165,6 +169,7 @@ void ConfigurationDialog::toggle_show_name(GtkToggleButton* button)
 void ConfigurationDialog::toggle_show_description(GtkToggleButton* button)
 {
 	wm_settings->launcher_show_description = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 	m_plugin->reload();
 }
 
@@ -174,6 +179,7 @@ void ConfigurationDialog::toggle_position_search_alternate(GtkToggleButton* butt
 {
 	bool active = gtk_toggle_button_get_active(button);
 	wm_settings->position_search_alternate = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 	gtk_widget_set_sensitive(GTK_WIDGET(m_position_commands_alternate), active);
 }
 
@@ -182,6 +188,7 @@ void ConfigurationDialog::toggle_position_search_alternate(GtkToggleButton* butt
 void ConfigurationDialog::toggle_position_commands_alternate(GtkToggleButton* button)
 {
 	wm_settings->position_commands_alternate = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -189,6 +196,7 @@ void ConfigurationDialog::toggle_position_commands_alternate(GtkToggleButton* bu
 void ConfigurationDialog::toggle_load_hierarchy(GtkToggleButton* button)
 {
 	wm_settings->load_hierarchy = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 	m_plugin->reload();
 }
 
@@ -197,6 +205,7 @@ void ConfigurationDialog::toggle_load_hierarchy(GtkToggleButton* button)
 void ConfigurationDialog::toggle_remember_favorites(GtkToggleButton* button)
 {
 	wm_settings->favorites_in_recent = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -204,6 +213,7 @@ void ConfigurationDialog::toggle_remember_favorites(GtkToggleButton* button)
 void ConfigurationDialog::toggle_display_recent(GtkToggleButton* button)
 {
 	wm_settings->display_recent = gtk_toggle_button_get_active(button);
+	wm_settings->set_modified();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/list-page.cpp b/panel-plugin/list-page.cpp
index 3916d82..4684f60 100644
--- a/panel-plugin/list-page.cpp
+++ b/panel-plugin/list-page.cpp
@@ -20,6 +20,7 @@
 #include "applications-page.h"
 #include "launcher.h"
 #include "launcher-view.h"
+#include "settings.h"
 #include "window.h"
 
 #include <algorithm>
@@ -155,7 +156,7 @@ void ListPage::on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIte
 	if (launcher)
 	{
 		m_desktop_ids[pos] = launcher->get_desktop_id();
-		get_window()->set_modified(); // Handle favorites being rearranged
+		wm_settings->set_modified();
 	}
 }
 
@@ -176,10 +177,12 @@ void ListPage::on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIt
 	if (pos >= m_desktop_ids.size())
 	{
 		m_desktop_ids.push_back(desktop_id);
+		wm_settings->set_modified();
 	}
 	else if (m_desktop_ids.at(pos) != desktop_id)
 	{
 		m_desktop_ids.insert(m_desktop_ids.begin() + pos, desktop_id);
+		wm_settings->set_modified();
 	}
 }
 
@@ -191,6 +194,7 @@ void ListPage::on_row_deleted(GtkTreePath* path)
 	if (pos < m_desktop_ids.size())
 	{
 		m_desktop_ids.erase(m_desktop_ids.begin() + pos);
+		wm_settings->set_modified();
 	}
 }
 
diff --git a/panel-plugin/page.cpp b/panel-plugin/page.cpp
index 1f393ce..f456a95 100644
--- a/panel-plugin/page.cpp
+++ b/panel-plugin/page.cpp
@@ -360,7 +360,6 @@ void Page::add_selected_to_favorites()
 	Launcher* launcher = get_selected_launcher();
 	g_assert(launcher != NULL);
 	m_window->get_favorites()->add(launcher);
-	m_window->set_modified();
 }
 
 //-----------------------------------------------------------------------------
@@ -370,7 +369,6 @@ void Page::remove_selected_from_favorites()
 	Launcher* launcher = get_selected_launcher();
 	g_assert(launcher != NULL);
 	m_window->get_favorites()->remove(launcher);
-	m_window->set_modified();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/plugin.cpp b/panel-plugin/plugin.cpp
index f24187b..71e79ad 100644
--- a/panel-plugin/plugin.cpp
+++ b/panel-plugin/plugin.cpp
@@ -188,6 +188,8 @@ void Plugin::set_button_style(ButtonStyle style)
 		gtk_widget_hide(GTK_WIDGET(m_button_label));
 	}
 
+	wm_settings->set_modified();
+
 	size_changed(xfce_panel_plugin_get_size(m_plugin));
 }
 
@@ -196,6 +198,7 @@ void Plugin::set_button_style(ButtonStyle style)
 void Plugin::set_button_title(const std::string& title)
 {
 	wm_settings->button_title = title;
+	wm_settings->set_modified();
 	gtk_label_set_markup(m_button_label, wm_settings->button_title.c_str());
 	size_changed(xfce_panel_plugin_get_size(m_plugin));
 }
@@ -205,6 +208,7 @@ void Plugin::set_button_title(const std::string& title)
 void Plugin::set_button_icon_name(const std::string& icon)
 {
 	wm_settings->button_icon_name = icon;
+	wm_settings->set_modified();
 	xfce_panel_image_set_from_source(m_button_icon, icon.c_str());
 	size_changed(xfce_panel_plugin_get_size(m_plugin));
 }
@@ -250,10 +254,7 @@ void Plugin::menu_hidden()
 {
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_button), false);
 	xfce_panel_plugin_block_autohide(m_plugin, false);
-	if (m_window->get_modified())
-	{
-		save();
-	}
+	save();
 }
 
 //-----------------------------------------------------------------------------
@@ -299,7 +300,11 @@ bool Plugin::remote_event(gchar* name, GValue* value)
 void Plugin::save()
 {
 	m_window->save();
-	wm_settings->save(xfce_panel_plugin_save_location(m_plugin, true));
+
+	if (wm_settings->get_modified())
+	{
+		wm_settings->save(xfce_panel_plugin_save_location(m_plugin, true));
+	}
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/recent-page.cpp b/panel-plugin/recent-page.cpp
index d632874..f77f65f 100644
--- a/panel-plugin/recent-page.cpp
+++ b/panel-plugin/recent-page.cpp
@@ -34,6 +34,7 @@ RecentPage::RecentPage(Window* window) :
 	if (wm_settings->recent.size() > m_max_items)
 	{
 		wm_settings->recent.erase(wm_settings->recent.begin() + m_max_items, wm_settings->recent.end());
+		wm_settings->set_modified();
 	}
 }
 
@@ -94,7 +95,6 @@ void RecentPage::extend_context_menu(GtkWidget* menu)
 void RecentPage::clear_menu()
 {
 	gtk_list_store_clear(GTK_LIST_STORE(get_view()->get_model()));
-	get_window()->set_modified();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/settings.cpp b/panel-plugin/settings.cpp
index ea83c6d..db002a5 100644
--- a/panel-plugin/settings.cpp
+++ b/panel-plugin/settings.cpp
@@ -72,6 +72,8 @@ static void write_vector_entry(XfceRc* rc, const char* key, const std::vector<st
 //-----------------------------------------------------------------------------
 
 Settings::Settings() :
+	m_modified(false),
+
 	button_icon_name("xfce4-whiskermenu"),
 	button_title_visible(false),
 	button_icon_visible(true),
@@ -171,6 +173,8 @@ void Settings::load(char* file)
 
 	xfce_rc_close(rc);
 
+	m_modified = false;
+
 	command_settings->check();
 	command_lockscreen->check();
 	command_logout->check();
@@ -231,6 +235,8 @@ void Settings::save(char* file)
 	xfce_rc_write_int_entry(rc, "menu-height", menu_height);
 
 	xfce_rc_close(rc);
+
+	m_modified = false;
 }
 
 //-----------------------------------------------------------------------------
diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h
index d8a61a2..5b9efbd 100644
--- a/panel-plugin/settings.h
+++ b/panel-plugin/settings.h
@@ -39,6 +39,19 @@ class Settings
 	void load(char* file);
 	void save(char* file);
 
+	bool m_modified;
+
+public:
+	bool get_modified() const
+	{
+		return m_modified;
+	}
+
+	void set_modified()
+	{
+		m_modified = true;
+	}
+
 public:
 	std::vector<std::string> favorites;
 	std::vector<std::string> recent;
diff --git a/panel-plugin/window.cpp b/panel-plugin/window.cpp
index d760955..7c79631 100644
--- a/panel-plugin/window.cpp
+++ b/panel-plugin/window.cpp
@@ -45,8 +45,7 @@ Window::Window() :
 	m_layout_left(true),
 	m_layout_bottom(true),
 	m_layout_search_alternate(false),
-	m_layout_commands_alternate(false),
-	m_modified(false)
+	m_layout_commands_alternate(false)
 {
 	m_geometry.x = 0;
 	m_geometry.y = 0;
@@ -550,9 +549,16 @@ void Window::show(GtkWidget* parent, bool horizontal)
 
 void Window::save()
 {
-	wm_settings->menu_width = m_geometry.width;
-	wm_settings->menu_height = m_geometry.height;
-	m_modified = false;
+	if (wm_settings->menu_width != m_geometry.width)
+	{
+		wm_settings->menu_width = m_geometry.width;
+		wm_settings->set_modified();
+	}
+	if (wm_settings->menu_height != m_geometry.height)
+	{
+		wm_settings->menu_height = m_geometry.height;
+		wm_settings->set_modified();
+	}
 }
 
 //-----------------------------------------------------------------------------
@@ -595,13 +601,6 @@ void Window::set_loaded()
 
 //-----------------------------------------------------------------------------
 
-void Window::set_modified()
-{
-	m_modified = true;
-}
-
-//-----------------------------------------------------------------------------
-
 void Window::unset_items()
 {
 	m_search_results->unset_menu_items();
diff --git a/panel-plugin/window.h b/panel-plugin/window.h
index 0a8e975..3ab000e 100644
--- a/panel-plugin/window.h
+++ b/panel-plugin/window.h
@@ -70,18 +70,12 @@ public:
 		return m_recent;
 	}
 
-	bool get_modified() const
-	{
-		return m_modified;
-	}
-
 	void hide();
 	void show(GtkWidget* parent, bool horizontal);
 	void save();
 	void set_categories(const std::vector<SectionButton*>& categories);
 	void set_items();
 	void set_loaded();
-	void set_modified();
 	void unset_items();
 
 private:
@@ -139,7 +133,6 @@ private:
 	bool m_layout_bottom;
 	bool m_layout_search_alternate;
 	bool m_layout_commands_alternate;
-	bool m_modified;
 
 
 private:

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list