From 98e1739b59a5ffe589345b45912db47eb2e2ef56 Mon Sep 17 00:00:00 2001 From: Vulpine05 Date: Sun, 21 Aug 2022 22:07:33 -0500 Subject: [PATCH 1/2] Added check if new columns are to be visible by default. --- clientgui/BOINCListCtrl.cpp | 56 ++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/clientgui/BOINCListCtrl.cpp b/clientgui/BOINCListCtrl.cpp index 159ed59e625..2a0912ad7fd 100644 --- a/clientgui/BOINCListCtrl.cpp +++ b/clientgui/BOINCListCtrl.cpp @@ -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 @@ -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]); @@ -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]])); @@ -185,7 +185,7 @@ bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) { strHiddenColumns += pView->m_aStdColNameOrder->Item(i); } pConfig->Write(wxT("HiddenColumns"), strHiddenColumns); - + return true; } @@ -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; @@ -240,19 +239,24 @@ 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) { + int defaultCount = pView->m_iNumDefaultShownColumns; + 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; @@ -260,22 +264,42 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) { } 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 < defaultCount; ++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 From bc8bcde920b8f9889c831c2278ed633ff63bd7cc Mon Sep 17 00:00:00 2001 From: Vulpine05 Date: Mon, 29 Aug 2022 21:16:59 -0500 Subject: [PATCH 2/2] Added check if new columns are to be visible by default. --- clientgui/BOINCListCtrl.cpp | 49 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/clientgui/BOINCListCtrl.cpp b/clientgui/BOINCListCtrl.cpp index 2a0912ad7fd..fd640072b72 100644 --- a/clientgui/BOINCListCtrl.cpp +++ b/clientgui/BOINCListCtrl.cpp @@ -252,7 +252,6 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) { int shownCount = orderArray.size(); int hiddenCount = hiddenArray.size(); int totalCount = pView->m_aStdColNameOrder->size(); - int defaultCount = pView->m_iNumDefaultShownColumns; for (int i = 0; i < totalCount; ++i) { // cycles through updated array of columns. wxString columnNameToFind = pView->m_aStdColNameOrder->Item(i); bool found = false; @@ -281,7 +280,7 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) { for (int k = 0; k < pView->m_iNumDefaultShownColumns; ++k) { defaultArray.Add(pView->m_aStdColNameOrder->Item(pView->m_iDefaultShownColumns[k])); } - for (int k = 0; k < defaultCount; ++k) { + for (int k = 0; k < defaultArray.GetCount(); ++k) { if (defaultArray[k].IsSameAs(columnNameToFind)) { orderArray.Add(columnNameToFind); foundNewDefaultColumns = true; @@ -305,7 +304,7 @@ bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) { // No "ColumnOrder" tag in pConfig // Show all columns in default column order wxASSERT(wxDynamicCast(pView, CBOINCBaseView)); - + SetDefaultColumnDisplay(); } @@ -319,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()) @@ -346,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; columnIDm_iColumnIDToColumnIndex.Add(-1); } - + for (columnID=0; columnIDm_aStdColNameOrder->Item(columnID))) { @@ -375,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 @@ -393,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]; @@ -406,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)) { @@ -449,14 +448,14 @@ void CBOINCListCtrl::SetDefaultColumnDisplay() { int i; wxArrayString orderArray; CBOINCBaseView* pView = (CBOINCBaseView*)GetParent(); - + wxASSERT(wxDynamicCast(pView, CBOINCBaseView)); orderArray.Clear(); for (i=0; im_iNumDefaultShownColumns; ++i) { orderArray.Add(pView->m_aStdColNameOrder->Item(pView->m_iDefaultShownColumns[i])); } - + SetListColumnOrder(orderArray); SetStandardColumnOrder(); } @@ -503,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; @@ -522,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 @@ -541,7 +540,7 @@ void CBOINCListCtrl::DrawProgressBars() x += GetColumnWidth(GetColumnIndexFromOrder(i)); } w = GetColumnWidth(progressColumn); - + #if USE_NATIVE_LISTCONTROL x -= GetScrollPos(wxHORIZONTAL); #else @@ -549,12 +548,12 @@ void CBOINCListCtrl::DrawProgressBars() #endif wxFont theFont = GetFont(); dc.SetFont(theFont); - + for (int i=0; i (topItem + numVisibleItems -1)) continue; - + GetItemRect(row, r); #if ! USE_NATIVE_LISTCONTROL @@ -567,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; @@ -586,7 +585,7 @@ void CBOINCListCtrl::DrawProgressBars() xx += ellipsisWidth; } } - + dc.SetLogicalFunction(wxCOPY); dc.SetBackgroundMode(wxSOLID); dc.SetPen(progressColor); @@ -634,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; @@ -700,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); }