Skip to content

Commit

Permalink
Merge pull request #4897 from Vulpine05/Vulpine05_NewColumns
Browse files Browse the repository at this point in the history
[Manager] Add check if new columns are to be visible by default
  • Loading branch information
AenBleidd authored Aug 30, 2022
2 parents 382bcea + bc8bcde commit 2a261b4
Showing 1 changed file with 62 additions and 39 deletions.
101 changes: 62 additions & 39 deletions clientgui/BOINCListCtrl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2015 University of California
// Copyright (C) 2022 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -132,7 +132,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
for (iIndex = 0; iIndex < iActualColumnCount; iIndex++) {
m_pParentView->m_iStdColWidthOrder[m_pParentView->m_iColumnIndexToColumnID[iIndex]] = GetColumnWidth(iIndex);
}

for (iIndex = 0; iIndex < iStdColumnCount; iIndex++) {
pConfig->SetPath(strBaseConfigLocation + m_pParentView->m_aStdColNameOrder->Item(iIndex));
pConfig->Write(wxT("Width"), m_pParentView->m_iStdColWidthOrder[iIndex]);
Expand All @@ -158,9 +158,9 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
aOrder[i] = i;
}
#endif

strColumnOrder.Printf(wxT("%s"), pView->m_aStdColNameOrder->Item(pView->m_iColumnIndexToColumnID[aOrder[0]]));

for (i = 1; i < iActualColumnCount; ++i)
{
strBuffer.Printf(wxT(";%s"), pView->m_aStdColNameOrder->Item(pView->m_iColumnIndexToColumnID[aOrder[i]]));
Expand All @@ -185,7 +185,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
strHiddenColumns += pView->m_aStdColNameOrder->Item(i);
}
pConfig->Write(wxT("HiddenColumns"), strHiddenColumns);

return true;
}

Expand All @@ -207,7 +207,6 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
// Cycle through the possible columns updating column widths
for (iIndex = 0; iIndex < iStdColumnCount; iIndex++) {
pConfig->SetPath(strBaseConfigLocation + m_pParentView->m_aStdColNameOrder->Item(iIndex));

pConfig->Read(wxT("Width"), &iTempValue, -1);
if (-1 != iTempValue) {
m_pParentView->m_iStdColWidthOrder[iIndex] = iTempValue;
Expand Down Expand Up @@ -240,48 +239,72 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
//
// This will also be triggered if the locale is changed, which will cause
// SetListColumnOrder() to be called again so the wxListCtrl will be set
// up with the correctly labeled columns.
// up with the correctly labeled columns.
//
bool foundNewColumns = false;
bool foundNewDefaultColumns = false;
bool foundNewHiddenColumns = false;

if (pConfig->Read(wxT("HiddenColumns"), &strHiddenColumns)) {
wxArrayString hiddenArray;
wxArrayString defaultArray;
TokenizedStringToArray(strHiddenColumns, ";", &hiddenArray);
int shownCount = orderArray.size();
int hiddenCount = hiddenArray.size();
int totalCount = pView->m_aStdColNameOrder->size();
for (int i = 0; i < totalCount; ++i) {
for (int i = 0; i < totalCount; ++i) { // cycles through updated array of columns.
wxString columnNameToFind = pView->m_aStdColNameOrder->Item(i);
bool found = false;
for (int j = 0; j < shownCount; ++j) {
for (int j = 0; j < shownCount; ++j) { // cycles through list of visible columns.
if (orderArray[j].IsSameAs(columnNameToFind)) {
found = true;
break;
}
}
if (found) continue;

for (int j = 0; j < hiddenCount; ++j) {
for (int j = 0; j < hiddenCount; ++j) { // cycles through the hidden columns.
if (hiddenArray[j].IsSameAs(columnNameToFind)) {
found = true;
break;
}
}
if (found) continue;

foundNewColumns = true;
orderArray.Add(columnNameToFind);

foundNewColumns = true;
// If we got this far, then we know this column is new.
// Now it needs to be determined if the new column should be shown by default or not.
// Create array of default columns.
//
defaultArray.Clear();
for (int k = 0; k < pView->m_iNumDefaultShownColumns; ++k) {
defaultArray.Add(pView->m_aStdColNameOrder->Item(pView->m_iDefaultShownColumns[k]));
}
for (int k = 0; k < defaultArray.GetCount(); ++k) {
if (defaultArray[k].IsSameAs(columnNameToFind)) {
orderArray.Add(columnNameToFind);
foundNewDefaultColumns = true;
break;
}
}
if (!foundNewDefaultColumns) {
hiddenArray.Add(columnNameToFind); // No need to order new hidden columns since they are hidden.
foundNewHiddenColumns = true;
}
}
}
if (foundNewColumns) {
bool wasInStandardOrder = IsColumnOrderStandard();
SetListColumnOrder(orderArray);
if (wasInStandardOrder) SetStandardColumnOrder();
if (foundNewDefaultColumns) {
bool wasInStandardOrder = IsColumnOrderStandard();
SetListColumnOrder(orderArray);
if (wasInStandardOrder) SetStandardColumnOrder();
}
}
} else {
// No "ColumnOrder" tag in pConfig
// Show all columns in default column order
wxASSERT(wxDynamicCast(pView, CBOINCBaseView));

SetDefaultColumnDisplay();
}

Expand All @@ -295,7 +318,7 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {

void CBOINCListCtrl::TokenizedStringToArray(wxString tokenized, char * delimiters, wxArrayString* array) {
wxString name;

array->Clear();
wxStringTokenizer tok(tokenized, delimiters);
while (tok.HasMoreTokens())
Expand All @@ -322,22 +345,22 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
int columnID = 0; // ID of column, e.g. COLUMN_PROJECT, COLUMN_STATUS, etc.
int sortColumnIndex = -1;
wxArrayInt aOrder(shownColCount);

CBOINCBaseView* pView = (CBOINCBaseView*)GetParent();
wxASSERT(wxDynamicCast(pView, CBOINCBaseView));

pView->m_iColumnIndexToColumnID.Clear();
for (i=colCount-1; i>=0; --i) {
DeleteColumn(i);
}

stdCount = pView->m_aStdColNameOrder->GetCount();

pView->m_iColumnIDToColumnIndex.Clear();
for (columnID=0; columnID<stdCount; ++columnID) {
pView->m_iColumnIDToColumnIndex.Add(-1);
}

for (columnID=0; columnID<stdCount; ++columnID) {
for (columnPosition=0; columnPosition<shownColCount; ++columnPosition) {
if (orderArray[columnPosition].IsSameAs(pView->m_aStdColNameOrder->Item(columnID))) {
Expand All @@ -351,7 +374,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
}
}
}

// Prevent a crash bug if we just changed to a new locale.
//
// If a column has the same name in both the old and new locale, we guard against
Expand All @@ -369,7 +392,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
pView->m_iColumnIDToColumnIndex[columnID] = columnID;
}
}

// If sort column is now hidden, set the new first column as sort column
if (pView->m_iSortColumnID >= 0) {
sortColumnIndex = pView->m_iColumnIDToColumnIndex[pView->m_iSortColumnID];
Expand All @@ -382,7 +405,7 @@ void CBOINCListCtrl::SetListColumnOrder(wxArrayString& orderArray) {
pView->SetSortColumn(sortColumnIndex);
}
}

#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
colCount = GetColumnCount();
if ((shownColCount > 0) && (shownColCount <= stdCount) && (colCount == shownColCount)) {
Expand Down Expand Up @@ -425,14 +448,14 @@ void CBOINCListCtrl::SetDefaultColumnDisplay() {
int i;
wxArrayString orderArray;
CBOINCBaseView* pView = (CBOINCBaseView*)GetParent();

wxASSERT(wxDynamicCast(pView, CBOINCBaseView));

orderArray.Clear();
for (i=0; i<pView->m_iNumDefaultShownColumns; ++i) {
orderArray.Add(pView->m_aStdColNameOrder->Item(pView->m_iDefaultShownColumns[i]));
}

SetListColumnOrder(orderArray);
SetStandardColumnOrder();
}
Expand Down Expand Up @@ -479,11 +502,11 @@ void CBOINCListCtrl::DrawProgressBars()
wxRect r, rr;
int w = 0, x = 0, xx, yy, ww;
int progressColumn = -1;

if (m_pParentView->GetProgressColumn() >= 0) {
progressColumn = m_pParentView->m_iColumnIDToColumnIndex[m_pParentView->GetProgressColumn()];
}

#if USE_NATIVE_LISTCONTROL
wxClientDC dc(this);
m_bProgressBarEventPending = false;
Expand All @@ -498,10 +521,10 @@ void CBOINCListCtrl::DrawProgressBars()

int n = (int)m_iRowsNeedingProgressBars.GetCount();
if (n <= 0) return;

wxColour progressColor = wxTheColourDatabase->Find(wxT("LIGHT BLUE"));
wxBrush progressBrush(progressColor);

numItems = GetItemCount();
if (numItems) {
topItem = GetTopItem(); // Doesn't work properly for Mac Native control in wxMac-2.8.7
Expand All @@ -517,20 +540,20 @@ void CBOINCListCtrl::DrawProgressBars()
x += GetColumnWidth(GetColumnIndexFromOrder(i));
}
w = GetColumnWidth(progressColumn);

#if USE_NATIVE_LISTCONTROL
x -= GetScrollPos(wxHORIZONTAL);
#else
CalcScrolledPosition(x, 0, &x, &yy);
#endif
wxFont theFont = GetFont();
dc.SetFont(theFont);

for (int i=0; i<n; ++i) {
row = m_iRowsNeedingProgressBars[i];
if (row < topItem) continue;
if (row > (topItem + numVisibleItems -1)) continue;


GetItemRect(row, r);
#if ! USE_NATIVE_LISTCONTROL
Expand All @@ -543,9 +566,9 @@ void CBOINCListCtrl::DrawProgressBars()

wxString progressString = m_pParentView->GetProgressText(row);
dc.GetTextExtent(progressString, &xx, &yy);

r.y += (r.height - yy - 1) / 2;

// Adapted from ellipis code in wxRendererGeneric::DrawHeaderButtonContents()
if (xx > r.width) {
int ellipsisWidth;
Expand All @@ -562,7 +585,7 @@ void CBOINCListCtrl::DrawProgressBars()
xx += ellipsisWidth;
}
}

dc.SetLogicalFunction(wxCOPY);
dc.SetBackgroundMode(wxSOLID);
dc.SetPen(progressColor);
Expand Down Expand Up @@ -610,7 +633,7 @@ void MyEvtHandler::OnPaint(wxPaintEvent & event)

void CBOINCListCtrl::PostDrawProgressBarEvent() {
if (m_bProgressBarEventPending) return;

CDrawProgressBarEvent newEvent(wxEVT_DRAW_PROGRESSBAR, this);
AddPendingEvent(newEvent);
m_bProgressBarEventPending = true;
Expand Down Expand Up @@ -676,7 +699,7 @@ void CBOINCListCtrl::OnMouseDown(wxMouseEvent& event) {
// on Mac, which is double-buffered to eliminate flicker.)
void CBOINCListCtrl::RefreshCell(int row, int col) {
wxRect r;

GetSubItemRect(row, col, r);
RefreshRect(r);
}

0 comments on commit 2a261b4

Please sign in to comment.