From 68cf3092208830e075c4fe5eddfdcbef3f11596a Mon Sep 17 00:00:00 2001
From: Mark Tiefenbruck <mark@fluxbox.org>
Date: Mon, 12 May 2008 18:13:56 -0700
Subject: implement smarter reloading for custom menus

---
 ChangeLog         |  3 +++
 src/FbCommands.cc | 17 ++++++++++++-----
 src/FbCommands.hh |  3 ++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 89a93d6..80147cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
  (Format: Year/Month/Day)
 Changes for 1.1
+*08/05/13:
+   * Only reload custom menus when necessary (Mark)
+     FbCommands.cc/hh
 *08/05/12:
    * Only reload the keys file if the contents have changed (Mark)
      Keys.cc/hh fluxbox.cc/hh
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index 3a09b69..e0d0768 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -343,16 +343,23 @@ void ShowCustomMenuCmd::execute() {
     if (screen == 0)
         return;
 
-    if (m_menu.get()) {
-        m_menu->removeAll();
-        m_menu->setLabel("");
-    } else
+    if (!m_menu.get() || screen->screenNumber() != m_menu->screenNumber()) {
         m_menu.reset(screen->createMenu(""));
+        m_menu->setReloadHelper(new FbTk::AutoReloadHelper());
+        m_menu->reloadHelper()->setReloadCmd(FbTk::RefCount<FbTk::Command<void> >(new FbTk::SimpleCommand<ShowCustomMenuCmd>(*this, &ShowCustomMenuCmd::reload)));
+        m_menu->reloadHelper()->setMainFile(custom_menu_file);
+    } else
+        m_menu->reloadHelper()->checkReload();
 
-    MenuCreator::createFromFile(custom_menu_file, *m_menu.get());
     ::showMenu(*screen, *m_menu.get());
 }
 
+void ShowCustomMenuCmd::reload() {
+    m_menu->removeAll();
+    m_menu->setLabel("");
+    MenuCreator::createFromFile(custom_menu_file, *m_menu.get(), m_menu->reloadHelper());
+}
+
 REGISTER_COMMAND(rootmenu, FbCommands::ShowRootMenuCmd, void);
 
 void ShowRootMenuCmd::execute() {
diff --git a/src/FbCommands.hh b/src/FbCommands.hh
index 3ad45c4..811fb78 100644
--- a/src/FbCommands.hh
+++ b/src/FbCommands.hh
@@ -132,9 +132,10 @@ class ShowCustomMenuCmd: public FbTk::Command<void> {
 public:
     explicit ShowCustomMenuCmd(const std::string &arguments);
     void execute();
+    void reload();
 private:
    std::string custom_menu_file;
-   std::auto_ptr<FbTk::Menu> m_menu;    
+   std::auto_ptr<FbMenu> m_menu;    
 };
 
 class ShowRootMenuCmd: public FbTk::Command<void> {
-- 
cgit v0.11.2