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 79ea2cade2c0d9fd266e5cf5cced6fd9b534a3d4
Author: Graeme Gott <gra...@gottcode.org>
Date:   Tue Jan 21 05:59:25 2020 -0500

    Use C++ type system for casting.
---
 panel-plugin/category.cpp           | 31 ++++++++++++-------------------
 panel-plugin/category.h             | 11 +----------
 panel-plugin/element.h              |  4 +---
 panel-plugin/favorites-page.cpp     | 16 +++++++---------
 panel-plugin/launcher-tree-view.cpp |  2 +-
 panel-plugin/launcher.h             | 11 +----------
 panel-plugin/page.cpp               | 17 ++++++++---------
 panel-plugin/run-action.h           | 11 +----------
 panel-plugin/search-action.h        | 11 +----------
 9 files changed, 33 insertions(+), 81 deletions(-)

diff --git a/panel-plugin/category.cpp b/panel-plugin/category.cpp
index d03ebed..e096264 100644
--- a/panel-plugin/category.cpp
+++ b/panel-plugin/category.cpp
@@ -29,11 +29,6 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
-static bool is_category(const Element* element)
-{
-       return element && (element->get_type() == Category::Type);
-}
-
 static bool is_null(const Element* element)
 {
        return !element;
@@ -75,9 +70,9 @@ Category::~Category()
 
        for (std::vector<Element*>::const_iterator i = m_items.begin(), end = 
m_items.end(); i != end; ++i)
        {
-               if (is_category(*i))
+               if (Category* category = dynamic_cast<Category*>(*i))
                {
-                       delete *i;
+                       delete category;
                }
        }
 }
@@ -133,7 +128,8 @@ bool Category::empty() const
 {
        for (std::vector<Element*>::const_iterator i = m_items.begin(), end = 
m_items.end(); i != end; ++i)
        {
-               if (*i && (!is_category(*i) || 
!static_cast<Category*>(*i)->empty()))
+               Category* category = dynamic_cast<Category*>(*i);
+               if ((!category && *i) || !category->empty())
                {
                        return false;
                }
@@ -185,9 +181,8 @@ void Category::insert_items(GtkTreeStore* model, 
GtkTreeIter* parent)
        for (std::vector<Element*>::size_type i = 0, end = m_items.size(); i < 
end; ++i)
        {
                Element* element = m_items.at(i);
-               if (is_category(element))
+               if (Category* category = dynamic_cast<Category*>(element))
                {
-                       Category* category = static_cast<Category*>(element);
                        if (category->empty())
                        {
                                continue;
@@ -207,9 +202,8 @@ void Category::insert_items(GtkTreeStore* model, 
GtkTreeIter* parent)
                        g_free(text);
                        category->insert_items(model, &iter);
                }
-               else if (element)
+               else if (Launcher* launcher = dynamic_cast<Launcher*>(element))
                {
-                       Launcher* launcher = static_cast<Launcher*>(element);
                        gtk_tree_store_insert_with_values(model,
                                        NULL, parent, INT_MAX,
                                        LauncherView::COLUMN_ICON, 
launcher->get_icon(),
@@ -238,9 +232,8 @@ void Category::insert_items(GtkListStore* model)
        for (std::vector<Element*>::size_type i = 0, end = m_items.size(); i < 
end; ++i)
        {
                Element* element = m_items.at(i);
-               if (element)
+               if (Launcher* launcher = dynamic_cast<Launcher*>(element))
                {
-                       Launcher* launcher = static_cast<Launcher*>(element);
                        gtk_list_store_insert_with_values(model,
                                        NULL, INT_MAX,
                                        LauncherView::COLUMN_ICON, 
launcher->get_icon(),
@@ -275,9 +268,9 @@ void Category::merge()
        std::vector<Category*> categories;
        for (std::vector<Element*>::const_iterator i = m_items.begin(), end = 
m_items.end(); i != end; ++i)
        {
-               if (is_category(*i))
+               if (Category* category = dynamic_cast<Category*>(*i))
                {
-                       categories.push_back(static_cast<Category*>(*i));
+                       categories.push_back(category);
                }
        }
        std::vector<Category*>::size_type last_direct = categories.size();
@@ -291,9 +284,9 @@ void Category::merge()
 
                for (std::vector<Element*>::const_iterator j = 
category->m_items.begin(), end = category->m_items.end(); j != end; ++j)
                {
-                       if (is_category(*j))
+                       if (Category* subcategory = dynamic_cast<Category*>(*j))
                        {
-                               
categories.push_back(static_cast<Category*>(*j));
+                               categories.push_back(subcategory);
                        }
                }
        }
@@ -308,7 +301,7 @@ void Category::merge()
        // Remove subcategories
        for (std::vector<Element*>::iterator i = m_items.begin(), end = 
m_items.end(); i != end; ++i)
        {
-               if (is_category(*i))
+               if (dynamic_cast<Category*>(*i))
                {
                        *i = NULL;
                }
diff --git a/panel-plugin/category.h b/panel-plugin/category.h
index 164db8c..ebab893 100644
--- a/panel-plugin/category.h
+++ b/panel-plugin/category.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2017 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2017, 2020 Graeme Gott <gra...@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
@@ -36,15 +36,6 @@ public:
        explicit Category(GarconMenuDirectory* directory);
        ~Category();
 
-       enum
-       {
-               Type = 1
-       };
-       int get_type() const
-       {
-               return Type;
-       }
-
        SectionButton* get_button();
 
        GtkTreeModel* get_model();
diff --git a/panel-plugin/element.h b/panel-plugin/element.h
index 9e02963..88adf1c 100644
--- a/panel-plugin/element.h
+++ b/panel-plugin/element.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2016, 2019 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2015, 2016, 2019, 2020 Graeme Gott <gra...@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
@@ -48,8 +48,6 @@ public:
                g_free(m_sort_key);
        }
 
-       virtual int get_type() const = 0;
-
        GIcon* get_icon() const
        {
                return m_icon;
diff --git a/panel-plugin/favorites-page.cpp b/panel-plugin/favorites-page.cpp
index 8512e24..b22a6f6 100644
--- a/panel-plugin/favorites-page.cpp
+++ b/panel-plugin/favorites-page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2016, 2019 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2015, 2016, 2019, 2020 Graeme Gott <gra...@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
@@ -175,11 +175,10 @@ void FavoritesPage::on_row_changed(GtkTreeModel* model, 
GtkTreePath* path, GtkTr
                return;
        }
 
-       Launcher* launcher;
-       gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, 
&launcher, -1);
-       if (launcher)
+       Element* element = NULL;
+       gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, 
&element, -1);
+       if (Launcher* launcher = dynamic_cast<Launcher*>(element))
        {
-               g_assert(launcher->get_type() == Launcher::Type);
                wm_settings->favorites[pos] = launcher->get_desktop_id();
                wm_settings->set_modified();
        }
@@ -192,11 +191,10 @@ void FavoritesPage::on_row_inserted(GtkTreeModel* model, 
GtkTreePath* path, GtkT
        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)
+       Element* element = NULL;
+       gtk_tree_model_get(model, iter, LauncherView::COLUMN_LAUNCHER, 
&element, -1);
+       if (Launcher* launcher = dynamic_cast<Launcher*>(element))
        {
-               g_assert(launcher->get_type() == Launcher::Type);
                desktop_id = launcher->get_desktop_id();
        }
 
diff --git a/panel-plugin/launcher-tree-view.cpp 
b/panel-plugin/launcher-tree-view.cpp
index 9ec7063..77417ad 100644
--- a/panel-plugin/launcher-tree-view.cpp
+++ b/panel-plugin/launcher-tree-view.cpp
@@ -298,7 +298,7 @@ void LauncherTreeView::on_row_activated(GtkTreeView* 
tree_view, GtkTreePath* pat
        GtkTreeIter iter;
        gtk_tree_model_get_iter(m_model, &iter, path);
        gtk_tree_model_get(m_model, &iter, COLUMN_LAUNCHER, &element, -1);
-       if (element && (element->get_type() != Category::Type))
+       if (element && !dynamic_cast<Category*>(element))
        {
                return;
        }
diff --git a/panel-plugin/launcher.h b/panel-plugin/launcher.h
index 2e34579..a023831 100644
--- a/panel-plugin/launcher.h
+++ b/panel-plugin/launcher.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2016, 2019 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2015, 2016, 2019, 2020 Graeme Gott <gra...@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
@@ -83,15 +83,6 @@ public:
        explicit Launcher(GarconMenuItem* item);
        ~Launcher();
 
-       enum
-       {
-               Type = 2
-       };
-       int get_type() const
-       {
-               return Type;
-       }
-
        std::vector<DesktopAction*> get_actions() const
        {
                return m_actions;
diff --git a/panel-plugin/page.cpp b/panel-plugin/page.cpp
index 4528c7f..0c75435 100644
--- a/panel-plugin/page.cpp
+++ b/panel-plugin/page.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019 Graeme Gott 
<gra...@gottcode.org>
+ * Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Graeme Gott 
<gra...@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
@@ -190,9 +190,8 @@ void Page::launcher_activated(GtkTreePath* path)
        }
 
        // Add to recent
-       if (element->get_type() == Launcher::Type)
+       if (Launcher* launcher = dynamic_cast<Launcher*>(element))
        {
-               Launcher* launcher = static_cast<Launcher*>(element);
                if (remember_launcher(launcher))
                {
                        m_window->get_recent()->add(launcher);
@@ -250,14 +249,14 @@ gboolean Page::view_button_press_event(GtkWidget*, 
GdkEvent* event)
                return false;
        }
 
+       Element* element = NULL;
        GtkTreeModel* model = m_view->get_model();
        GtkTreeIter iter;
        gtk_tree_model_get_iter(model, &iter, path);
        gtk_tree_path_free(path);
-       gtk_tree_model_get(model, &iter, LauncherView::COLUMN_LAUNCHER, 
&m_selected_launcher, -1);
-       if (!m_selected_launcher || (m_selected_launcher->get_type() != 
Launcher::Type))
+       gtk_tree_model_get(model, &iter, LauncherView::COLUMN_LAUNCHER, 
&element, -1);
+       if (!(m_selected_launcher = dynamic_cast<Launcher*>(element)))
        {
-               m_selected_launcher = NULL;
                m_drag_enabled = false;
                m_view->unset_drag_source();
                m_view->unset_drag_dest();
@@ -340,13 +339,13 @@ gboolean Page::view_popup_menu_event(GtkWidget*)
 void Page::create_context_menu(GtkTreePath* path, GdkEvent* event)
 {
        // Get selected launcher
+       Element* element = NULL;
        GtkTreeModel* model = m_view->get_model();
        GtkTreeIter iter;
        gtk_tree_model_get_iter(model, &iter, path);
-       gtk_tree_model_get(model, &iter, LauncherView::COLUMN_LAUNCHER, 
&m_selected_launcher, -1);
-       if (!m_selected_launcher || (m_selected_launcher->get_type() != 
Launcher::Type))
+       gtk_tree_model_get(model, &iter, LauncherView::COLUMN_LAUNCHER, 
&element, -1);
+       if (!(m_selected_launcher = dynamic_cast<Launcher*>(element)))
        {
-               m_selected_launcher = NULL;
                gtk_tree_path_free(path);
                return;
        }
diff --git a/panel-plugin/run-action.h b/panel-plugin/run-action.h
index 02c7666..be9c0a8 100644
--- a/panel-plugin/run-action.h
+++ b/panel-plugin/run-action.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2015, 2020 Graeme Gott <gra...@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
@@ -30,15 +30,6 @@ class RunAction : public Element
 public:
        RunAction();
 
-       enum
-       {
-               Type = 4
-       };
-       int get_type() const
-       {
-               return Type;
-       }
-
        void run(GdkScreen* screen) const;
        guint search(const Query& query);
 
diff --git a/panel-plugin/search-action.h b/panel-plugin/search-action.h
index 9d045f3..a380781 100644
--- a/panel-plugin/search-action.h
+++ b/panel-plugin/search-action.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015 Graeme Gott <gra...@gottcode.org>
+ * Copyright (C) 2013, 2015, 2020 Graeme Gott <gra...@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
@@ -32,15 +32,6 @@ public:
        SearchAction(const gchar* name, const gchar* pattern, const gchar* 
command, bool is_regex, bool show_description);
        ~SearchAction();
 
-       enum
-       {
-               Type = 3
-       };
-       int get_type() const
-       {
-               return Type;
-       }
-
        const gchar* get_name() const
        {
                return m_name.c_str();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
https://mail.xfce.org/mailman/listinfo/xfce4-commits

Reply via email to