reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

obsquery.cpp (2528B)


      1 /* ReaPack: Package manager for REAPER
      2  * Copyright (C) 2015-2025  Christian Fillion
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU Lesser General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU Lesser General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Lesser General Public License
     15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 #include "obsquery.hpp"
     19 
     20 #include "listview.hpp"
     21 #include "menu.hpp"
     22 #include "package.hpp"
     23 #include "resource.hpp"
     24 
     25 #include <sstream>
     26 
     27 enum { ACTION_SELECT_ALL = 300, ACTION_UNSELECT_ALL };
     28 
     29 ObsoleteQuery::ObsoleteQuery(std::vector<Registry::Entry> *entries, bool *enable)
     30   : Dialog(IDD_OBSQUERY_DIALOG), m_entries(entries), m_enable(enable)
     31 {
     32 }
     33 
     34 void ObsoleteQuery::onInit()
     35 {
     36   Dialog::onInit();
     37 
     38   m_enableCtrl = getControl(IDC_ENABLE);
     39   m_okBtn = getControl(IDOK);
     40 
     41   m_list = createControl<ListView>(IDC_LIST, ListView::Columns{
     42     {"Package", 550}
     43   });
     44 
     45   m_list->onSelect >> [=] { setEnabled(m_list->hasSelection(), m_okBtn); };
     46   m_list->onFillContextMenu >> [=] (Menu &menu, int) {
     47     menu.addAction("Select &all", ACTION_SELECT_ALL);
     48     menu.addAction("&Unselect all", ACTION_UNSELECT_ALL);
     49     return true;
     50   };
     51 
     52   m_list->reserveRows(m_entries->size());
     53 
     54   for(const Registry::Entry &entry : *m_entries) {
     55     std::ostringstream stream;
     56     stream << entry.remote << '/' << entry.category << '/'
     57       << Package::displayName(entry.package, entry.description);
     58     m_list->createRow()->setCell(0, stream.str());
     59   }
     60 
     61   m_list->autoSizeHeader();
     62 
     63   setChecked(true, m_enableCtrl);
     64 
     65   disable(m_okBtn);
     66 }
     67 
     68 void ObsoleteQuery::onCommand(const int id, int event)
     69 {
     70   switch(id) {
     71   case IDOK:
     72     prepare();
     73     break;
     74   case IDC_ENABLE:
     75     *m_enable = isChecked(m_enableCtrl);
     76     break;
     77   case ACTION_SELECT_ALL:
     78     m_list->selectAll();
     79     break;
     80   case ACTION_UNSELECT_ALL:
     81     m_list->unselectAll();
     82     break;
     83   }
     84 
     85   Dialog::onCommand(id, event);
     86 }
     87 
     88 void ObsoleteQuery::prepare()
     89 {
     90   std::vector<Registry::Entry> selected;
     91 
     92   for(int index : m_list->selection())
     93     selected.emplace_back(m_entries->at(index));
     94 
     95   m_entries->swap(selected);
     96 }