reapack

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

commit 3aab3df7e6d781556d94b76c47c27fbfdc99c824
parent 3bbe8afab3f132850052f6e09df08803a8cd693e
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 31 Jan 2016 21:19:57 -0500

new about dialog for repositories

Diffstat:
MRakefile | 2+-
Mmacosx.tup | 3+++
Asrc/about.cpp | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/about.hpp | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/about.mm | 35+++++++++++++++++++++++++++++++++++
Msrc/dialog.hpp | 6+++---
Msrc/listview.cpp | 3+++
Msrc/listview.hpp | 3+++
Msrc/main.cpp | 4++++
Msrc/manager.cpp | 17+++++++++++++++++
Msrc/manager.hpp | 1+
Msrc/resource.hpp | 19++++++++++++++-----
Msrc/resource.rc | 17+++++++++++++++++
Asrc/tabbar.cpp | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/tabbar.hpp | 48++++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 401 insertions(+), 9 deletions(-)

diff --git a/Rakefile b/Rakefile @@ -2,7 +2,7 @@ task :default => [:prepare, :build, :test] desc 'Prepare the source code for building using prepare.rb' task :prepare do - sources = FileList['src/*.{h,c}pp'] + sources = FileList['src/*.{{h,c}pp,mm}'] ruby 'prepare.rb', *sources, :verbose => false end diff --git a/macosx.tup b/macosx.tup @@ -28,3 +28,6 @@ TSTARGET := bin/test BUILDDEPS := src/resource.rc_mac_menu src/resource.rc_mac_dlg : src/resource.rc |> php $(SWELL)/mac_resgen.php %f |> $(BUILDDEPS) + +# build Objective-C files +: foreach src/*.mm | $(BUILDDEPS) |> !build |> build/%B_mm.o diff --git a/src/about.cpp b/src/about.cpp @@ -0,0 +1,112 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2016 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "about.hpp" + +#include "encoding.hpp" +#include "index.hpp" +#include "listview.hpp" +#include "resource.hpp" +#include "tabbar.hpp" + +using namespace std; + +About::About(RemoteIndex *index) + : Dialog(IDD_ABOUT_DIALOG), m_index(index) +{ +} + +void About::onInit() +{ + m_about = getControl(IDC_ABOUT); + + m_cats = createControl<ListView>(IDC_CATEGORIES, ListView::Columns{ + {AUTO_STR("Category"), 140} + }); + + m_cats->onSelect(bind(&About::updatePackages, this, false)); + + m_packages = createControl<ListView>(IDC_PACKAGES, ListView::Columns{ + {AUTO_STR("Name"), 350}, + {AUTO_STR("Version"), 90}, + {AUTO_STR("Author"), 100}, + }); + + m_tabs = createControl<TabBar>(IDC_TABS, TabBar::Tabs{ + {AUTO_STR("Description"), {m_about}}, + {AUTO_STR("Packages"), {m_cats->handle(), m_packages->handle()}}, + {AUTO_STR("Installed Files"), {}}, + }); + + populate(); +} + +void About::onCommand(const int id) +{ + switch(id) { + case IDOK: + case IDCANCEL: + close(); + break; + } +} + +void About::populate() +{ + const auto_string &name = make_autostring(m_index->name()); + + auto_char title[255] = {}; + auto_snprintf(title, sizeof(title), AUTO_STR("About %s"), name.c_str()); + + SetWindowText(handle(), title); + + setAboutText( + AUTO_STR("{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n") + AUTO_STR("This is some {\\b bold} text.\\par\n") + AUTO_STR("}") + ); + + m_cats->addRow({AUTO_STR("<All Categories>")}); + + for(Category *cat : m_index->categories()) + m_cats->addRow({make_autostring(cat->name())}); + + updatePackages(true); +} + +void About::updatePackages(const bool force) +{ + const PackageList *pkgList; + + // -2: no selection, -1: all categories, >0 selected category + const int catIndex = m_cats->currentIndex() - 1; + + if(catIndex == -2 && !force) + return; + else if(catIndex < 0) + pkgList = &m_index->packages(); + else + pkgList = &m_index->category(catIndex)->packages(); + + m_packages->clear(); + + for(Package *pkg : *pkgList) { + const auto_string &name = make_autostring(pkg->name()); + const auto_string &lastVer = make_autostring(pkg->lastVersion()->name()); + m_packages->addRow({name, lastVer, AUTO_STR("John Doe")}); + } +} diff --git a/src/about.hpp b/src/about.hpp @@ -0,0 +1,50 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2016 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef REAPACK_ABOUT_HPP +#define REAPACK_ABOUT_HPP + +#include "dialog.hpp" + +#include "encoding.hpp" + +class ListView; +class RemoteIndex; +class TabBar; + +class About : public Dialog { +public: + About(RemoteIndex *index); + +protected: + void onInit() override; + void onCommand(int) override; + +private: + void populate(); + void updatePackages(bool); + void setAboutText(const auto_string &); + + RemoteIndex *m_index; + + TabBar *m_tabs; + HWND m_about; + ListView *m_cats; + ListView *m_packages; +}; + +#endif diff --git a/src/about.mm b/src/about.mm @@ -0,0 +1,35 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2016 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "about.hpp" + +#include <Cocoa/Cocoa.h> + +void About::setAboutText(const auto_string &text) +{ + NSString *str = [NSString + stringWithCString:text.c_str() + encoding:NSUTF8StringEncoding + ]; + + NSTextView *textView = (NSTextView *)m_about; + + [textView + replaceCharactersInRange: NSMakeRange(0, [[textView string] length]) + withRTF: [str dataUsingEncoding: NSUTF8StringEncoding] + ]; +} diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -97,7 +97,6 @@ protected: return ctrl; } - virtual void onInit() = 0; virtual void onShow(); virtual void onHide(); @@ -114,10 +113,11 @@ private: const int m_template; bool m_isVisible; - std::map<int, Control *> m_controls; - REAPER_PLUGIN_HINSTANCE m_instance; HWND m_parent; HWND m_handle; + + std::map<int, Control *> m_controls; }; + #endif diff --git a/src/listview.cpp b/src/listview.cpp @@ -114,5 +114,8 @@ void ListView::onNotify(LPNMHDR info, LPARAM) case LVN_ITEMCHANGED: m_onSelect(); break; + case NM_DBLCLK: + m_onDoubleClick(); + break; }; } diff --git a/src/listview.hpp b/src/listview.hpp @@ -46,6 +46,8 @@ public: int currentIndex() const; void onSelect(const Callback &callback) { m_onSelect.connect(callback); } + void onDoubleClick(const Callback &callback) + { m_onDoubleClick.connect(callback); } protected: void onNotify(LPNMHDR, LPARAM) override; @@ -57,6 +59,7 @@ private: int m_rowSize; Signal m_onSelect; + Signal m_onDoubleClick; }; #endif diff --git a/src/main.cpp b/src/main.cpp @@ -85,6 +85,10 @@ static void menuHook(const char *name, HMENU handle, int f) menu.addAction(AUTO_STR("Manage remotes..."), NamedCommandLookup("_REAPACK_MANAGE")); + + menu.addSeparator(); + + menu.addAction(AUTO_STR("About ReaPack v0.1"), 0); } extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( diff --git a/src/manager.cpp b/src/manager.cpp @@ -17,8 +17,10 @@ #include "manager.hpp" +#include "about.hpp" #include "config.hpp" #include "encoding.hpp" +#include "index.hpp" #include "menu.hpp" #include "reapack.hpp" #include "remote.hpp" @@ -47,6 +49,8 @@ void Manager::onInit() {AUTO_STR("URL"), URL_WIDTH}, {AUTO_STR("State"), 60}, }); + + m_list->onDoubleClick(bind(&Manager::about, this)); } void Manager::onCommand(const int id) @@ -165,6 +169,19 @@ void Manager::uninstall() m_list->removeRow(m_list->currentIndex()); } +void Manager::about() +{ + const Remote &remote = currentRemote(); + + if(remote.isNull()) + return; + + RemoteIndex *index = RemoteIndex::load(remote.name()); + unique_ptr<RemoteIndex> ptr(index); + + Dialog::Show<About>(instance(), parent(), index); +} + bool Manager::confirm() const { if(m_uninstall.empty()) diff --git a/src/manager.hpp b/src/manager.hpp @@ -46,6 +46,7 @@ private: void setRemoteEnabled(const bool); bool isRemoteEnabled(const Remote &remote) const; void uninstall(); + void about(); bool confirm() const; void apply(); diff --git a/src/resource.hpp b/src/resource.hpp @@ -21,6 +21,7 @@ #ifndef _WIN32 #define PROGRESS_CLASS "msctls_progress32" #define WC_LISTVIEW "SysListView32" +#define WC_TABCONTROL "SysTabControl32" #else #include <commctrl.h> #endif @@ -32,11 +33,19 @@ #define IDD_PROGRESS_DIALOG 100 #define IDD_REPORT_DIALOG 101 #define IDD_CONFIG_DIALOG 102 +#define IDD_ABOUT_DIALOG 103 -#define IDC_LABEL 200 -#define IDC_PROGRESS 201 -#define IDC_REPORT 202 -#define IDC_LIST 203 -#define IDC_IMPORT 204 +#define IDC_LABEL 200 +#define IDC_PROGRESS 201 +#define IDC_REPORT 202 +#define IDC_LIST 203 +#define IDC_IMPORT 204 +#define IDC_TABS 205 +#define IDC_ENABLE 206 +#define IDC_DONATE 207 +#define IDC_WEBSITE 208 +#define IDC_ABOUT 209 +#define IDC_CATEGORIES 210 +#define IDC_PACKAGES 211 #endif diff --git a/src/resource.rc b/src/resource.rc @@ -37,3 +37,20 @@ BEGIN DEFPUSHBUTTON "OK", IDOK, 240, 160, 40, 14 PUSHBUTTON "Cancel", IDCANCEL, 284, 160, 40, 14 END + +IDD_ABOUT_DIALOG DIALOGEX 0, 0, 440, 250 +STYLE DIALOG_STYLE +FONT DIALOG_FONT +BEGIN + CONTROL "", IDC_TABS, WC_TABCONTROL, 0, 0, 2, 440, 223 + EDITTEXT IDC_ABOUT, 10, 20, 420, 200, + WS_VSCROLL | ES_MULTILINE | ES_READONLY | NOT WS_TABSTOP + CONTROL "", IDC_CATEGORIES, WC_LISTVIEW, LVS_REPORT | LVS_SINGLESEL | + LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP, 10, 20, 86, 200 + CONTROL "", IDC_PACKAGES, WC_LISTVIEW, LVS_REPORT | LVS_SINGLESEL | + LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP, 100, 20, 330, 200 + PUSHBUTTON "Website", IDC_WEBSITE, 5, 230, 45, 14 + PUSHBUTTON "Donate...", IDC_DONATE, 54, 230, 45, 14 + PUSHBUTTON "Enable this repository!", IDC_ENABLE, 285, 230, 100, 14 + DEFPUSHBUTTON "Close", IDOK, 389, 230, 45, 14 +END diff --git a/src/tabbar.cpp b/src/tabbar.cpp @@ -0,0 +1,90 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2016 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "tabbar.hpp" + +#ifdef _WIN32 +#include <commctrl.h> +#endif + +TabBar::TabBar(const Tabs &tabs, HWND handle) + : Control(handle), m_size(0), m_lastPage(0) +{ + for(const Tab &tab : tabs) + addTab(tab); +} + +int TabBar::addTab(const Tab &tab) +{ + int index = m_size++; + + for(HWND control : tab.page) + ShowWindow(control, SW_HIDE); + + m_pages.push_back(tab.page); + + TCITEM item{}; + item.mask |= TCIF_TEXT; + item.pszText = const_cast<auto_char *>(tab.text.c_str()); + + TabCtrl_InsertItem(handle(), index, &item); + + if(index == 0) + switchPage(); + + return index; +} + +int TabBar::currentIndex() const +{ + return TabCtrl_GetCurSel(handle()); +} + +void TabBar::onNotify(LPNMHDR info, LPARAM) +{ + switch(info->code) { + case TCN_SELCHANGE: + switchPage(); + break; + }; +} + +void TabBar::switchPage() +{ + if(m_lastPage > -1) { + for(HWND control : m_pages[m_lastPage]) + ShowWindow(control, SW_HIDE); + } + + const int index = currentIndex(); + + if(index < 0 || (size_t)index >= m_pages.size()) { + m_lastPage = -1; + return; + } + + const Page &page = m_pages[index]; + m_lastPage = index; + + if(page.empty()) + return; + + for(HWND control : page) + ShowWindow(control, SW_SHOW); + + SetFocus(page.front()); +} diff --git a/src/tabbar.hpp b/src/tabbar.hpp @@ -0,0 +1,48 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2016 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef REAPACK_TABBAR_HPP +#define REAPACK_TABBAR_HPP + +#include "control.hpp" + +#include <vector> + +#include "encoding.hpp" + +class TabBar : public Control { +public: + typedef std::vector<HWND> Page; + struct Tab { auto_string text; Page page; }; + typedef std::vector<Tab> Tabs; + + TabBar(const Tabs &tabs, HWND handle); + int addTab(const Tab &); + int currentIndex() const; + +protected: + void onNotify(LPNMHDR, LPARAM) override; + +private: + void switchPage(); + + int m_size; + int m_lastPage; + std::vector<Page> m_pages; +}; + +#endif