browser.hpp (3904B)
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 #ifndef REAPACK_BROWSER_HPP 19 #define REAPACK_BROWSER_HPP 20 21 #include "dialog.hpp" 22 23 #include "package.hpp" 24 25 #include <functional> 26 #include <list> 27 #include <memory> 28 #include <optional> 29 #include <string> 30 #include <vector> 31 32 class Index; 33 class ListView; 34 class Menu; 35 class Registry; 36 class Version; 37 38 typedef std::shared_ptr<const Index> IndexPtr; 39 40 class Browser : public Dialog { 41 public: 42 enum Action { 43 ACTION_VERSION = 80, 44 ACTION_FILTERTYPE, 45 ACTION_LATEST = 300, 46 ACTION_LATEST_ALL, 47 ACTION_REINSTALL, 48 ACTION_REINSTALL_ALL, 49 ACTION_UNINSTALL, 50 ACTION_UNINSTALL_ALL, 51 ACTION_PIN, 52 ACTION_BLEEDINGEDGE, 53 ACTION_ABOUT_PKG, 54 ACTION_ABOUT_REMOTE, 55 ACTION_RESET_ALL, 56 ACTION_COPY, 57 ACTION_SYNCHRONIZE, 58 ACTION_REFRESH, 59 ACTION_UPLOAD, 60 ACTION_MANAGE, 61 }; 62 63 Browser(); 64 void refresh(bool stale = false); 65 void setFilter(const std::string &); 66 67 protected: 68 void onInit() override; 69 void onCommand(int, int) override; 70 void onTimer(int) override; 71 bool onKeyDown(int, int) override; 72 void onClose() override; 73 74 private: 75 class Entry; // browser_entry.hpp 76 77 enum View { 78 AllView, 79 QueuedView, 80 InstalledView, 81 OutOfDateView, 82 ObsoleteView, 83 UninstalledView, 84 }; 85 86 enum LoadState { 87 Init, 88 Loading, 89 Loaded, 90 DeferredLoaded, 91 }; 92 93 void onSelection(); 94 bool fillContextMenu(Menu &, int index); 95 void populate(const std::vector<IndexPtr> &, const Registry *); 96 void transferActions(); 97 bool match(const Entry &) const; 98 void updateFilter(); 99 void updateAbout(); 100 void fillList(); 101 Entry *getEntry(int listIndex); 102 void updateDisplayLabel(); 103 void displayButton(); 104 void actionsButton(); 105 void fillMenu(Menu &); 106 void fillSelectionMenu(Menu &); 107 bool isFiltered(Package::Type) const; 108 bool hasAction(const Entry *) const; 109 void listDo(const std::function<void (int)> &, const std::vector<int> &); 110 void currentDo(const std::function<void (int)> &); 111 void selectionDo(const std::function<void (int)> &); 112 View currentView() const; 113 void copy(); 114 bool confirm() const; 115 bool apply(); 116 117 // Only call the following functions using currentDo or selectionDo (listDo) 118 // (so that the display label is updated and the list sorted and filtered as 119 // needed) 120 void resetActions(int index); 121 void updateAction(const int index); 122 void toggleTarget(const int index, const Version *); 123 void resetTarget(int index); 124 125 void installLatest(int index, bool toggle); 126 void installLatestAll(); 127 void reinstall(int index, bool toggle); 128 void installVersion(int index, size_t verIndex); 129 void uninstall(int index, bool toggle); 130 void toggleFlag(int index, int mask); 131 132 // these can be called directly because they don't use updateAction() 133 void aboutRemote(int index, bool focus = true); 134 void aboutPackage(int index, bool focus = true); 135 136 LoadState m_loadState; 137 int m_currentIndex; 138 139 std::optional<Package::Type> m_typeFilter; 140 std::vector<Entry> m_entries; 141 std::list<Entry *> m_actions; 142 143 HWND m_filter; 144 HWND m_view; 145 HWND m_displayBtn; 146 HWND m_actionsBtn; 147 ListView *m_list; 148 HWND m_applyBtn; 149 Serializer m_serializer; 150 }; 151 152 #endif