Skip to content

Commit 98e1739

Browse files
committed
Added check if new columns are to be visible by default.
1 parent b37f2ac commit 98e1739

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

clientgui/BOINCListCtrl.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
22
// http://boinc.berkeley.edu
3-
// Copyright (C) 2015 University of California
3+
// Copyright (C) 2022 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -132,7 +132,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
132132
for (iIndex = 0; iIndex < iActualColumnCount; iIndex++) {
133133
m_pParentView->m_iStdColWidthOrder[m_pParentView->m_iColumnIndexToColumnID[iIndex]] = GetColumnWidth(iIndex);
134134
}
135-
135+
136136
for (iIndex = 0; iIndex < iStdColumnCount; iIndex++) {
137137
pConfig->SetPath(strBaseConfigLocation + m_pParentView->m_aStdColNameOrder->Item(iIndex));
138138
pConfig->Write(wxT("Width"), m_pParentView->m_iStdColWidthOrder[iIndex]);
@@ -158,9 +158,9 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
158158
aOrder[i] = i;
159159
}
160160
#endif
161-
161+
162162
strColumnOrder.Printf(wxT("%s"), pView->m_aStdColNameOrder->Item(pView->m_iColumnIndexToColumnID[aOrder[0]]));
163-
163+
164164
for (i = 1; i < iActualColumnCount; ++i)
165165
{
166166
strBuffer.Printf(wxT(";%s"), pView->m_aStdColNameOrder->Item(pView->m_iColumnIndexToColumnID[aOrder[i]]));
@@ -185,7 +185,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
185185
strHiddenColumns += pView->m_aStdColNameOrder->Item(i);
186186
}
187187
pConfig->Write(wxT("HiddenColumns"), strHiddenColumns);
188-
188+
189189
return true;
190190
}
191191

@@ -207,7 +207,6 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
207207
// Cycle through the possible columns updating column widths
208208
for (iIndex = 0; iIndex < iStdColumnCount; iIndex++) {
209209
pConfig->SetPath(strBaseConfigLocation + m_pParentView->m_aStdColNameOrder->Item(iIndex));
210-
211210
pConfig->Read(wxT("Width"), &iTempValue, -1);
212211
if (-1 != iTempValue) {
213212
m_pParentView->m_iStdColWidthOrder[iIndex] = iTempValue;
@@ -240,42 +239,67 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
240239
//
241240
// This will also be triggered if the locale is changed, which will cause
242241
// SetListColumnOrder() to be called again so the wxListCtrl will be set
243-
// up with the correctly labeled columns.
242+
// up with the correctly labeled columns.
243+
//
244244
bool foundNewColumns = false;
245+
bool foundNewDefaultColumns = false;
246+
bool foundNewHiddenColumns = false;
245247

246248
if (pConfig->Read(wxT("HiddenColumns"), &strHiddenColumns)) {
247249
wxArrayString hiddenArray;
250+
wxArrayString defaultArray;
248251
TokenizedStringToArray(strHiddenColumns, ";", &hiddenArray);
249252
int shownCount = orderArray.size();
250253
int hiddenCount = hiddenArray.size();
251254
int totalCount = pView->m_aStdColNameOrder->size();
252-
for (int i = 0; i < totalCount; ++i) {
255+
int defaultCount = pView->m_iNumDefaultShownColumns;
256+
for (int i = 0; i < totalCount; ++i) { // cycles through updated array of columns.
253257
wxString columnNameToFind = pView->m_aStdColNameOrder->Item(i);
254258
bool found = false;
255-
for (int j = 0; j < shownCount; ++j) {
259+
for (int j = 0; j < shownCount; ++j) { // cycles through list of visible columns.
256260
if (orderArray[j].IsSameAs(columnNameToFind)) {
257261
found = true;
258262
break;
259263
}
260264
}
261265
if (found) continue;
262266

263-
for (int j = 0; j < hiddenCount; ++j) {
267+
for (int j = 0; j < hiddenCount; ++j) { // cycles through the hidden columns.
264268
if (hiddenArray[j].IsSameAs(columnNameToFind)) {
265269
found = true;
266270
break;
267271
}
268272
}
269273
if (found) continue;
270-
271-
foundNewColumns = true;
272-
orderArray.Add(columnNameToFind);
274+
275+
foundNewColumns = true;
276+
// If we got this far, then we know this column is new.
277+
// Now it needs to be determined if the new column should be shown by default or not.
278+
// Create array of default columns.
279+
//
280+
defaultArray.Clear();
281+
for (int k = 0; k < pView->m_iNumDefaultShownColumns; ++k) {
282+
defaultArray.Add(pView->m_aStdColNameOrder->Item(pView->m_iDefaultShownColumns[k]));
283+
}
284+
for (int k = 0; k < defaultCount; ++k) {
285+
if (defaultArray[k].IsSameAs(columnNameToFind)) {
286+
orderArray.Add(columnNameToFind);
287+
foundNewDefaultColumns = true;
288+
break;
289+
}
290+
}
291+
if (!foundNewDefaultColumns) {
292+
hiddenArray.Add(columnNameToFind); // No need to order new hidden columns since they are hidden.
293+
foundNewHiddenColumns = true;
294+
}
273295
}
274296
}
275297
if (foundNewColumns) {
276-
bool wasInStandardOrder = IsColumnOrderStandard();
277-
SetListColumnOrder(orderArray);
278-
if (wasInStandardOrder) SetStandardColumnOrder();
298+
if (foundNewDefaultColumns) {
299+
bool wasInStandardOrder = IsColumnOrderStandard();
300+
SetListColumnOrder(orderArray);
301+
if (wasInStandardOrder) SetStandardColumnOrder();
302+
}
279303
}
280304
} else {
281305
// No "ColumnOrder" tag in pConfig

0 commit comments

Comments
 (0)