[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 438/473: Merge list page into favorites and recent pages.
noreply at xfce.org
noreply at xfce.org
Tue Feb 17 00:00:08 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 f1861131fd7df19603c07dfe8a66f62154946cec
Author: Graeme Gott <graeme at gottcode.org>
Date: Tue Dec 31 13:16:27 2013 -0500
Merge list page into favorites and recent pages.
---
panel-plugin/CMakeLists.txt | 1 -
panel-plugin/favorites-page.cpp | 96 +++++++++++++++++++++++++++-
panel-plugin/favorites-page.h | 12 +++-
panel-plugin/list-page.cpp | 134 ---------------------------------------
panel-plugin/list-page.h | 53 ----------------
panel-plugin/recent-page.cpp | 49 ++++++++++++--
panel-plugin/recent-page.h | 10 +--
7 files changed, 153 insertions(+), 202 deletions(-)
diff --git a/panel-plugin/CMakeLists.txt b/panel-plugin/CMakeLists.txt
index 1a9e5d9..b0a3755 100644
--- a/panel-plugin/CMakeLists.txt
+++ b/panel-plugin/CMakeLists.txt
@@ -79,7 +79,6 @@ add_library(whiskermenu MODULE
icon-size.cpp
launcher.cpp
launcher-view.cpp
- list-page.cpp
page.cpp
plugin.cpp
profile-picture.cpp
diff --git a/panel-plugin/favorites-page.cpp b/panel-plugin/favorites-page.cpp
index b03ac51..4b21b3b 100644
--- a/panel-plugin/favorites-page.cpp
+++ b/panel-plugin/favorites-page.cpp
@@ -33,13 +33,20 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
FavoritesPage::FavoritesPage(Window* window) :
- ListPage(wm_settings->favorites, window)
+ Page(window)
{
get_view()->set_reorderable(true);
}
//-----------------------------------------------------------------------------
+FavoritesPage::~FavoritesPage()
+{
+ unset_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
bool FavoritesPage::contains(Launcher* launcher) const
{
if (!launcher)
@@ -94,6 +101,26 @@ void FavoritesPage::remove(Launcher* launcher)
//-----------------------------------------------------------------------------
+void FavoritesPage::set_menu_items()
+{
+ GtkTreeModel* model = get_window()->get_applications()->create_launcher_model(wm_settings->favorites);
+ get_view()->set_model(model);
+ g_signal_connect_slot(model, "row-changed", &FavoritesPage::on_row_changed, this);
+ g_signal_connect_slot(model, "row-inserted", &FavoritesPage::on_row_inserted, this);
+ g_signal_connect_slot(model, "row-deleted", &FavoritesPage::on_row_deleted, this);
+ g_object_unref(model);
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::unset_menu_items()
+{
+ // Clear treeview
+ get_view()->unset_model();
+}
+
+//-----------------------------------------------------------------------------
+
void FavoritesPage::extend_context_menu(GtkWidget* menu)
{
GtkWidget* menuitem = gtk_separator_menu_item_new();
@@ -121,6 +148,65 @@ bool FavoritesPage::remember_launcher(Launcher* launcher)
//-----------------------------------------------------------------------------
+void FavoritesPage::on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+ if (pos >= wm_settings->favorites.size())
+ {
+ return;
+ }
+
+ Launcher* launcher;
+ gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, &launcher, -1);
+ if (launcher)
+ {
+ g_assert(launcher->get_type() == Launcher::Type);
+ wm_settings->favorites[pos] = launcher->get_desktop_id();
+ wm_settings->set_modified();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+
+ std::string desktop_id;
+ Launcher* launcher;
+ gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, &launcher, -1);
+ if (launcher)
+ {
+ g_assert(launcher->get_type() == Launcher::Type);
+ desktop_id = launcher->get_desktop_id();
+ }
+
+ if (pos >= wm_settings->favorites.size())
+ {
+ wm_settings->favorites.push_back(desktop_id);
+ wm_settings->set_modified();
+ }
+ else if (wm_settings->favorites.at(pos) != desktop_id)
+ {
+ wm_settings->favorites.insert(wm_settings->favorites.begin() + pos, desktop_id);
+ wm_settings->set_modified();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+void FavoritesPage::on_row_deleted(GtkTreeModel*, GtkTreePath* path)
+{
+ size_t pos = gtk_tree_path_get_indices(path)[0];
+ if (pos < wm_settings->favorites.size())
+ {
+ wm_settings->favorites.erase(wm_settings->favorites.begin() + pos);
+ wm_settings->set_modified();
+ }
+}
+
+//-----------------------------------------------------------------------------
+
void FavoritesPage::sort(std::vector<Launcher*>& items) const
{
for (std::vector<std::string>::const_iterator i = wm_settings->favorites.begin(), end = wm_settings->favorites.end(); i != end; ++i)
@@ -147,7 +233,9 @@ void FavoritesPage::sort_ascending()
{
desktop_ids.push_back((*i)->get_desktop_id());
}
- set_desktop_ids(desktop_ids);
+ wm_settings->favorites = desktop_ids;
+ wm_settings->set_modified();
+ set_menu_items();
}
//-----------------------------------------------------------------------------
@@ -162,7 +250,9 @@ void FavoritesPage::sort_descending()
{
desktop_ids.push_back((*i)->get_desktop_id());
}
- set_desktop_ids(desktop_ids);
+ wm_settings->favorites = desktop_ids;
+ wm_settings->set_modified();
+ set_menu_items();
}
//-----------------------------------------------------------------------------
diff --git a/panel-plugin/favorites-page.h b/panel-plugin/favorites-page.h
index 1eb8092..e8be1f6 100644
--- a/panel-plugin/favorites-page.h
+++ b/panel-plugin/favorites-page.h
@@ -18,24 +18,32 @@
#ifndef WHISKERMENU_FAVORITES_PAGE_H
#define WHISKERMENU_FAVORITES_PAGE_H
-#include "list-page.h"
+#include "page.h"
+
+#include <vector>
namespace WhiskerMenu
{
-class FavoritesPage : public ListPage
+class FavoritesPage : public Page
{
public:
FavoritesPage(Window* window);
+ ~FavoritesPage();
bool contains(Launcher* launcher) const;
void add(Launcher* launcher);
void remove(Launcher* launcher);
+ void set_menu_items();
+ void unset_menu_items();
private:
void extend_context_menu(GtkWidget* menu);
bool remember_launcher(Launcher* launcher);
+ void on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
+ void on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
+ void on_row_deleted(GtkTreeModel*, GtkTreePath* path);
void sort(std::vector<Launcher*>& items) const;
void sort_ascending();
void sort_descending();
diff --git a/panel-plugin/list-page.cpp b/panel-plugin/list-page.cpp
deleted file mode 100644
index 5b0d2f6..0000000
--- a/panel-plugin/list-page.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
- *
- * This library 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 2 of the License, or
- * (at your option) any later version.
- *
- * This library 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 library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "list-page.h"
-
-#include "applications-page.h"
-#include "launcher.h"
-#include "launcher-view.h"
-#include "settings.h"
-#include "slot.h"
-#include "window.h"
-
-using namespace WhiskerMenu;
-
-//-----------------------------------------------------------------------------
-
-ListPage::ListPage(std::vector<std::string>& desktop_ids, Window* window) :
- Page(window),
- m_desktop_ids(desktop_ids)
-{
-}
-
-//-----------------------------------------------------------------------------
-
-ListPage::~ListPage()
-{
- unset_menu_items();
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::set_menu_items()
-{
- GtkTreeModel* model = get_window()->get_applications()->create_launcher_model(m_desktop_ids);
- get_view()->set_model(model);
- g_signal_connect_slot(model, "row-changed", &ListPage::on_row_changed, this);
- g_signal_connect_slot(model, "row-inserted", &ListPage::on_row_inserted, this);
- g_signal_connect_slot(model, "row-deleted", &ListPage::on_row_deleted, this);
- g_object_unref(model);
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::unset_menu_items()
-{
- // Clear treeview
- get_view()->unset_model();
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::set_desktop_ids(const std::vector<std::string>& desktop_ids)
-{
- m_desktop_ids = desktop_ids;
- if (get_view()->get_model())
- {
- set_menu_items();
- }
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
-{
- size_t pos = gtk_tree_path_get_indices(path)[0];
- if (pos >= m_desktop_ids.size())
- {
- return;
- }
-
- Launcher* launcher;
- gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, &launcher, -1);
- if (launcher)
- {
- g_assert(launcher->get_type() == Launcher::Type);
- m_desktop_ids[pos] = launcher->get_desktop_id();
- wm_settings->set_modified();
- }
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter)
-{
- size_t pos = gtk_tree_path_get_indices(path)[0];
-
- std::string desktop_id;
- Launcher* launcher;
- gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, &launcher, -1);
- if (launcher)
- {
- g_assert(launcher->get_type() == Launcher::Type);
- desktop_id = launcher->get_desktop_id();
- }
-
- 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();
- }
-}
-
-//-----------------------------------------------------------------------------
-
-void ListPage::on_row_deleted(GtkTreeModel*, GtkTreePath* path)
-{
- size_t pos = gtk_tree_path_get_indices(path)[0];
- if (pos < m_desktop_ids.size())
- {
- m_desktop_ids.erase(m_desktop_ids.begin() + pos);
- wm_settings->set_modified();
- }
-}
-
-//-----------------------------------------------------------------------------
diff --git a/panel-plugin/list-page.h b/panel-plugin/list-page.h
deleted file mode 100644
index 2ef03d5..0000000
--- a/panel-plugin/list-page.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
- *
- * This library 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 2 of the License, or
- * (at your option) any later version.
- *
- * This library 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 library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef WHISKERMENU_LIST_PAGE_H
-#define WHISKERMENU_LIST_PAGE_H
-
-#include "page.h"
-
-#include <string>
-#include <vector>
-
-namespace WhiskerMenu
-{
-
-class ListPage : public Page
-{
-public:
- ListPage(std::vector<std::string>& desktop_ids, Window* window);
- ~ListPage();
-
- virtual void add(Launcher* launcher)=0;
- void set_menu_items();
- void unset_menu_items();
-
-protected:
- void set_desktop_ids(const std::vector<std::string>& desktop_ids);
-
-private:
- void on_row_changed(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
- void on_row_inserted(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter);
- void on_row_deleted(GtkTreeModel*, GtkTreePath* path);
-
-private:
- std::vector<std::string>& m_desktop_ids;
-};
-
-}
-
-#endif // WHISKERMENU_LIST_PAGE_H
diff --git a/panel-plugin/recent-page.cpp b/panel-plugin/recent-page.cpp
index add3817..94770d7 100644
--- a/panel-plugin/recent-page.cpp
+++ b/panel-plugin/recent-page.cpp
@@ -17,10 +17,12 @@
#include "recent-page.h"
+#include "applications-page.h"
#include "launcher.h"
#include "launcher-view.h"
#include "settings.h"
#include "slot.h"
+#include "window.h"
#include <algorithm>
@@ -31,7 +33,7 @@ using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
RecentPage::RecentPage(Window* window) :
- ListPage(wm_settings->recent, window)
+ Page(window)
{
// Prevent going over max
if (wm_settings->recent.size() > wm_settings->recent_items_max)
@@ -43,6 +45,13 @@ RecentPage::RecentPage(Window* window) :
//-----------------------------------------------------------------------------
+RecentPage::~RecentPage()
+{
+ unset_menu_items();
+}
+
+//-----------------------------------------------------------------------------
+
void RecentPage::add(Launcher* launcher)
{
if (!launcher)
@@ -50,9 +59,10 @@ void RecentPage::add(Launcher* launcher)
return;
}
+ std::string desktop_id = launcher->get_desktop_id();
if (!wm_settings->recent.empty())
{
- std::vector<std::string>::iterator i = std::find(wm_settings->recent.begin(), wm_settings->recent.end(), launcher->get_desktop_id());
+ std::vector<std::string>::iterator i = std::find(wm_settings->recent.begin(), wm_settings->recent.end(), desktop_id);
// Skip if already first launcher
if (i == wm_settings->recent.begin())
@@ -66,6 +76,9 @@ void RecentPage::add(Launcher* launcher)
GtkTreeIter iter;
gtk_tree_model_iter_nth_child(model, &iter, NULL, std::distance(wm_settings->recent.begin(), i));
gtk_list_store_move_after(GTK_LIST_STORE(model), &iter, NULL);
+ wm_settings->recent.erase(i);
+ wm_settings->recent.insert(wm_settings->recent.begin(), desktop_id);
+ wm_settings->set_modified();
return;
}
}
@@ -78,6 +91,8 @@ void RecentPage::add(Launcher* launcher)
LauncherView::COLUMN_TEXT, launcher->get_text(),
LauncherView::COLUMN_LAUNCHER, launcher,
-1);
+ wm_settings->recent.insert(wm_settings->recent.begin(), desktop_id);
+ wm_settings->set_modified();
// Prevent going over max
enforce_item_count();
@@ -87,15 +102,40 @@ void RecentPage::add(Launcher* launcher)
void RecentPage::enforce_item_count()
{
+ if (wm_settings->recent_items_max >= wm_settings->recent.size())
+ {
+ return;
+ }
+
GtkListStore* store = GTK_LIST_STORE(get_view()->get_model());
- while (wm_settings->recent.size() > wm_settings->recent_items_max)
+ for (size_t i = wm_settings->recent.size() - 1, end = wm_settings->recent_items_max; i >= end; --i)
{
GtkTreeIter iter;
- if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, wm_settings->recent.size() - 1))
+ if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, i))
{
gtk_list_store_remove(store, &iter);
}
}
+
+ wm_settings->recent.erase(wm_settings->recent.begin() + wm_settings->recent_items_max, wm_settings->recent.end());
+ wm_settings->set_modified();
+}
+
+//-----------------------------------------------------------------------------
+
+void RecentPage::set_menu_items()
+{
+ GtkTreeModel* model = get_window()->get_applications()->create_launcher_model(wm_settings->recent);
+ get_view()->set_model(model);
+ g_object_unref(model);
+}
+
+//-----------------------------------------------------------------------------
+
+void RecentPage::unset_menu_items()
+{
+ // Clear treeview
+ get_view()->unset_model();
}
//-----------------------------------------------------------------------------
@@ -117,6 +157,7 @@ void RecentPage::extend_context_menu(GtkWidget* menu)
void RecentPage::clear_menu()
{
gtk_list_store_clear(GTK_LIST_STORE(get_view()->get_model()));
+ wm_settings->set_modified();
}
//-----------------------------------------------------------------------------
diff --git a/panel-plugin/recent-page.h b/panel-plugin/recent-page.h
index 4412dfa..d0c079d 100644
--- a/panel-plugin/recent-page.h
+++ b/panel-plugin/recent-page.h
@@ -18,25 +18,25 @@
#ifndef WHISKERMENU_RECENT_PAGE_H
#define WHISKERMENU_RECENT_PAGE_H
-#include "list-page.h"
+#include "page.h"
namespace WhiskerMenu
{
-class RecentPage : public ListPage
+class RecentPage : public Page
{
public:
RecentPage(Window* window);
+ ~RecentPage();
void add(Launcher* launcher);
void enforce_item_count();
+ void set_menu_items();
+ void unset_menu_items();
private:
void extend_context_menu(GtkWidget* menu);
void clear_menu();
-
-private:
- size_t m_max_items;
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list