commit 62f2c935e64cf9cba9f1662f8d7c091c54e29bd3
parent 984b6830dd148d522a396a7ab6c8f1c27412f18a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 21 Sep 2016 21:26:25 -0400
browser: make the about window follow browser section [p=1730194]
Diffstat:
8 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -50,7 +50,7 @@ void About::onInit()
{
Dialog::onInit();
- m_tabs = createControl<TabBar>(IDC_TABS);
+ m_tabs = createControl<TabBar>(IDC_TABS, this);
m_desc = createControl<RichEdit>(IDC_ABOUT);
m_menu = createControl<ListView>(IDC_MENU);
@@ -138,7 +138,8 @@ void About::setDelegate(const DelegatePtr &delegate)
InvalidateRect(handle(), nullptr, true);
#endif
- show();
+ if(!isVisible())
+ show();
}
void About::setTitle(const string &what)
diff --git a/src/about.hpp b/src/about.hpp
@@ -44,6 +44,8 @@ public:
About();
void setDelegate(const DelegatePtr &);
+ template<typename T>
+ bool testDelegate() { return dynamic_cast<T *>(m_delegate.get()) != nullptr; }
void setTitle(const std::string &);
void setMetadata(const Metadata *, bool substitution = false);
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -90,7 +90,7 @@ void Browser::onInit()
});
m_list->onActivate([=] { aboutPackage(m_list->itemUnderMouse()); });
- m_list->onSelect([=] { setEnabled(m_list->hasSelection(), m_actionsBtn); });
+ m_list->onSelect(bind(&Browser::onSelection, this));
m_list->onContextMenu(bind(&Browser::fillContextMenu,
this, placeholders::_1, placeholders::_2));
@@ -287,6 +287,22 @@ void Browser::onTimer(const int id)
checkFilter();
}
+void Browser::onSelection()
+{
+ setEnabled(m_list->hasSelection(), m_actionsBtn);
+
+ About *about = m_reapack->about(false);
+ const Entry *entry = getEntry(m_list->currentIndex());
+
+ if(!about || !entry)
+ return;
+
+ if(about->testDelegate<AboutIndexDelegate>())
+ about->setDelegate(make_shared<AboutIndexDelegate>(entry->index, m_reapack));
+ else if(about->testDelegate<AboutPackageDelegate>() && entry->package)
+ about->setDelegate(make_shared<AboutPackageDelegate>(entry->package, m_reapack));
+}
+
bool Browser::fillContextMenu(Menu &menu, const int index)
{
m_currentIndex = index;
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -103,6 +103,7 @@ private:
Entry makeEntry(const Package *, const Registry::Entry &, const IndexPtr &) const;
+ void onSelection();
bool fillContextMenu(Menu &, int index);
void populate(const std::vector<IndexPtr> &);
void transferActions();
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -230,10 +230,12 @@ void ReaPack::aboutSelf()
}, m_mainWindow);
}
-About *ReaPack::about()
+About *ReaPack::about(const bool instantiate)
{
if(m_about)
return m_about;
+ else if(!instantiate)
+ return nullptr;
m_about = Dialog::Create<About>(m_instance, m_mainWindow);
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -72,7 +72,7 @@ public:
void importRemote();
void manageRemotes();
void aboutSelf();
- About *about();
+ About *about(bool instantiate = true);
Browser *browsePackages();
void refreshManager();
void refreshBrowser();
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
@@ -17,12 +17,14 @@
#include "tabbar.hpp"
+#include "dialog.hpp"
+
#ifdef _WIN32
#include <commctrl.h>
#endif
-TabBar::TabBar(HWND handle, const Tabs &tabs)
- : Control(handle), m_lastPage(-1)
+TabBar::TabBar(HWND handle, Dialog *parent, const Tabs &tabs)
+ : Control(handle), m_parent(parent), m_lastPage(-1)
{
for(const Tab &tab : tabs)
addTab(tab);
@@ -70,7 +72,7 @@ void TabBar::setFocus()
{
const int index = currentIndex();
- if(index > -1)
+ if(index > -1 && m_parent->hasFocus())
SetFocus(m_pages[index].front());
}
@@ -123,5 +125,5 @@ void TabBar::switchPage()
for(HWND control : page)
ShowWindow(control, SW_SHOW);
- SetFocus(page.front());
+ setFocus();
}
diff --git a/src/tabbar.hpp b/src/tabbar.hpp
@@ -24,13 +24,15 @@
#include "encoding.hpp"
+class Dialog;
+
class TabBar : public Control {
public:
typedef std::vector<HWND> Page;
struct Tab { auto_string text; Page page; };
typedef std::vector<Tab> Tabs;
- TabBar(HWND handle, const Tabs &tabs = {});
+ TabBar(HWND handle, Dialog *parent, const Tabs &tabs = {});
int addTab(const Tab &);
int currentIndex() const;
void setCurrentIndex(int);
@@ -45,6 +47,7 @@ protected:
private:
void switchPage();
+ Dialog *m_parent;
int m_lastPage;
std::vector<Page> m_pages;
};