commit c31231f88341b5e80fe563bf769b870aff396865
parent 62c4365e94698bdcc17e4511e0472eaf6b1f85a5
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 14 Sep 2017 03:06:14 -0400
refactor the new receipt page generation code
Diffstat:
5 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/src/receipt.cpp b/src/receipt.cpp
@@ -67,14 +67,24 @@ void Receipt::addError(const ErrorInfo &err)
m_errors.push_back(err);
}
-ReceiptPages Receipt::pages() const
+ReceiptPage Receipt::installedPage() const
{
- return ReceiptPages{{
- {m_installs, "Installed"},
- {m_removals, "Removed"},
- {m_exports, "Exported"},
- {m_errors, "Error", "Errors"},
- }};
+ return {m_installs, "Installed"};
+}
+
+ReceiptPage Receipt::removedPage() const
+{
+ return {m_removals, "Removed"};
+}
+
+ReceiptPage Receipt::exportedPage() const
+{
+ return {m_exports, "Exported"};
+}
+
+ReceiptPage Receipt::errorPage() const
+{
+ return {m_errors, "Error", "Errors"};
}
void ReceiptPage::setTitle(const char *title)
diff --git a/src/receipt.hpp b/src/receipt.hpp
@@ -21,7 +21,6 @@
#include "registry.hpp"
#include "errors.hpp"
-#include <array>
#include <vector>
#include <set>
@@ -32,7 +31,6 @@ class ReceiptPage;
class Version;
typedef std::shared_ptr<const Index> IndexPtr;
-typedef std::array<ReceiptPage, 4> ReceiptPages;
class Receipt {
public:
@@ -44,9 +42,7 @@ public:
Receipt();
bool test(Flag f) const { return (m_flags & f) != 0; }
-
bool empty() const;
- ReceiptPages pages() const;
void addInstall(const Version *, const Registry::Entry &);
void addRemoval(const Path &p);
@@ -54,8 +50,14 @@ public:
void addExport(const Path &p);
void addError(const ErrorInfo &);
+ ReceiptPage installedPage() const;
+ ReceiptPage removedPage() const;
+ ReceiptPage exportedPage() const;
+ ReceiptPage errorPage() const;
+
private:
int m_flags;
+
std::multiset<InstallTicket> m_installs;
std::set<Path> m_removals;
std::set<Path> m_exports;
diff --git a/src/report.cpp b/src/report.cpp
@@ -25,7 +25,7 @@
using namespace std;
Report::Report(const Receipt *receipt)
- : Dialog(IDD_REPORT_DIALOG), m_receipt(receipt)
+ : Dialog(IDD_REPORT_DIALOG), m_receipt(receipt), m_empty(true)
{
}
@@ -33,24 +33,20 @@ void Report::onInit()
{
Dialog::onInit();
- HWND report = getControl(IDC_REPORT);
- TabBar *tabbar = createControl<TabBar>(IDC_TABS, this);
-
- tabbar->onTabChange([=] (const int i) {
- Win32::setWindowText(report, m_pages[i].c_str());
+ m_tabbar = createControl<TabBar>(IDC_TABS, this);
+ m_tabbar->onTabChange([=] (const int i) {
+ Win32::setWindowText(getControl(IDC_REPORT), m_pages[i].c_str());
});
- bool firstPage = true;
-
- for(const ReceiptPage &page : m_receipt->pages()) {
- m_pages.emplace_back(page.contents());
- tabbar->addTab({page.title().c_str()});
+ const ReceiptPage pages[] = {
+ m_receipt->installedPage(),
+ m_receipt->removedPage(),
+ m_receipt->exportedPage(),
+ m_receipt->errorPage(),
+ };
- if(firstPage && !page.empty()) {
- tabbar->setCurrentIndex(tabbar->count() - 1);
- firstPage = false;
- }
- }
+ for(const auto &page : pages)
+ addPage(page);
SetFocus(getControl(IDOK));
@@ -67,3 +63,14 @@ void Report::onTimer(int timer)
"These newly installed files won't be loaded until REAPER is restarted.",
"ReaPack Notice", MB_OK);
}
+
+void Report::addPage(const ReceiptPage &page)
+{
+ m_pages.emplace_back(page.contents());
+ m_tabbar->addTab({page.title().c_str()});
+
+ if(m_empty && !page.empty()) {
+ m_tabbar->setCurrentIndex(m_tabbar->count() - 1);
+ m_empty = false;
+ }
+}
diff --git a/src/report.hpp b/src/report.hpp
@@ -21,6 +21,8 @@
#include "dialog.hpp"
class Receipt;
+class ReceiptPage;
+class TabBar;
class Report : public Dialog {
public:
@@ -31,7 +33,11 @@ protected:
void onTimer(int) override;
private:
+ void addPage(const ReceiptPage &);
+
const Receipt *m_receipt;
+ bool m_empty;
+ TabBar *m_tabbar;
std::vector<std::string> m_pages;
};
diff --git a/test/receipt.cpp b/test/receipt.cpp
@@ -159,7 +159,7 @@ TEST_CASE("sort InstallTickets (case insensitive)", M) {
r.addInstall(&ver3, {}); // z is the last letter
r.addInstall(&ver1, {}); // a test (duplicate)
r.addInstall(&ver2, {}); // Uppercase Name
- const string page = r.pages()[0].contents();
+ const string page = r.installedPage().contents();
REQUIRE(page.find(pkg1.name()) < page.find(pkg2.name()));
REQUIRE(page.find(pkg2.name()) < page.find(pkg3.name()));