commit 0ad7592aca6842833e7f0dfa1215d780a7381adb
parent 3f171446662ca7bc2d28a3f5dad44107acdf91a8
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 20 Jun 2016 23:43:04 -0400
browser: add repository column (collapsed by default)
Diffstat:
3 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -86,6 +86,7 @@ void Browser::onInit()
{AUTO_STR("Version"), 80},
{AUTO_STR("Author"), 95},
{AUTO_STR("Type"), 70},
+ {AUTO_STR("Repository"), 120, ListView::CollapseFlag},
});
m_list->onActivate([=] { history(m_list->itemUnderMouse()); });
@@ -642,10 +643,12 @@ ListView::Row Browser::makeRow(const Entry &entry) const
const string &version = getValue(VersionColumn, entry);
const string &author = getValue(AuthorColumn, entry);
const string &type = getValue(TypeColumn, entry);
+ const string &remote = getValue(RemoteColumn, entry);
return {
make_autostring(state), make_autostring(name), make_autostring(category),
- make_autostring(version), make_autostring(author), make_autostring(type)
+ make_autostring(version), make_autostring(author), make_autostring(type),
+ make_autostring(remote),
};
}
@@ -755,8 +758,9 @@ bool Browser::match(const Entry &entry) const
const string &name = getValue(NameColumn, entry);
const string &category = getValue(CategoryColumn, entry);
const string &author = getValue(AuthorColumn, entry);
+ const string &remote = getValue(RemoteColumn, entry);
- return m_filter.match(name + category + author);
+ return m_filter.match(name + category + author + remote);
}
auto Browser::getEntry(const int listIndex) -> Entry *
diff --git a/src/listview.cpp b/src/listview.cpp
@@ -56,7 +56,7 @@ void ListView::addColumn(const Column &col)
LVCOLUMN item{};
item.mask |= LVCF_WIDTH;
- item.cx = adjustWidth(col.width);
+ item.cx = col.test(CollapseFlag) ? 0 : adjustWidth(col.width);
if(!col.test(NoLabelFlag)) {
item.mask |= LVCF_TEXT;
@@ -412,13 +412,34 @@ void ListView::headerMenu(const int x, const int y)
const int id = menu.show(x, y, handle());
if(id == ACTION_RESTORE)
- restoreDefaults();
+ resetColumns();
else if(id >> 8 == 1) {
const int col = id & 0xff;
resizeColumn(col, columnWidth(col) ? 0 : m_cols[col].width);
}
}
+void ListView::resetColumns()
+{
+ vector<int> order(columnCount());
+
+ for(int i = 0; i < columnCount(); i++) {
+ order[i] = i;
+
+ const Column &col = m_cols[i];
+ resizeColumn(i, col.test(CollapseFlag) ? 0 : col.width);
+ }
+
+ ListView_SetColumnOrderArray(handle(), columnCount(), &order[0]);
+
+ if(m_sort && m_defaultSort) {
+ setSortArrow(false);
+ m_sort = m_defaultSort;
+ setSortArrow(true);
+ sort();
+ }
+}
+
bool ListView::restore(const string &data, const int userVersion)
{
m_userVersion = userVersion; // for save()
@@ -478,27 +499,6 @@ bool ListView::restore(const string &data, const int userVersion)
return true;
}
-void ListView::restoreDefaults()
-{
- vector<int> order(columnCount());
-
- for(int i = 0; i < columnCount(); i++) {
- order[i] = i;
-
- const Column &col = m_cols[i];
- resizeColumn(i, col.width);
- }
-
- ListView_SetColumnOrderArray(handle(), columnCount(), &order[0]);
-
- if(m_sort && m_defaultSort) {
- setSortArrow(false);
- m_sort = m_defaultSort;
- setSortArrow(true);
- sort();
- }
-}
-
string ListView::save() const
{
vector<int> order(columnCount());
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -33,7 +33,8 @@ public:
enum SortOrder { AscendingOrder, DescendingOrder };
enum ColumnFlag {
- NoLabelFlag = 1<<0,
+ NoLabelFlag = 1<<0,
+ CollapseFlag = 1<<1,
};
struct Column {
@@ -76,8 +77,8 @@ public:
bool empty() const { return rowCount() < 1; }
bool restore(const std::string &, int userVersion);
- void restoreDefaults();
std::string save() const;
+ void resetColumns();
void onSelect(const VoidSignal::slot_type &slot) { m_onSelect.connect(slot); }
void onActivate(const VoidSignal::slot_type &slot) { m_onActivate.connect(slot); }