reapack

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

commit 28016f68ec7c75a307f7c2644daf4493079ebfbb
parent 5ab2389c8e38507c829924eb7b2780e0afad63f9
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu,  9 Feb 2017 21:39:47 -0500

attempt a cross-platform file browser compatible with UNICODE defined

Diffstat:
MTupfile | 2+-
Msrc/dialog.cpp | 1-
Msrc/dialog.hpp | 1+
Asrc/filedialog.cpp | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/filedialog.hpp | 38++++++++++++++++++++++++++++++++++++++
Msrc/manager.cpp | 34++++++++++++++++------------------
6 files changed, 126 insertions(+), 20 deletions(-)

diff --git a/Tupfile b/Tupfile @@ -1,5 +1,5 @@ WDL := vendor/WDL/WDL -WDLSOURCE := $(WDL)/wingui/wndsize.cpp $(WDL)/filebrowse.cpp +WDLSOURCE := $(WDL)/wingui/wndsize.cpp TINYXML := $(WDL)/tinyxml WDLSOURCE += $(TINYXML)/tinyxml.cpp $(TINYXML)/tinystr.cpp diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -18,7 +18,6 @@ #include "dialog.hpp" #include "control.hpp" -#include "encoding.hpp" #include <algorithm> #include <boost/range/adaptor/map.hpp> diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -18,6 +18,7 @@ #ifndef REAPACK_DIALOG_HPP #define REAPACK_DIALOG_HPP +#include "encoding.hpp" #include "serializer.hpp" #include <functional> diff --git a/src/filedialog.cpp b/src/filedialog.cpp @@ -0,0 +1,70 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2017 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 "filedialog.hpp" + +#include "path.hpp" + +#ifndef _WIN32 +#include <swell.h> +#endif + +auto_string FileDialog::getOpenFileName(HWND parent, HINSTANCE instance, + const auto_char *title, const Path &directory, + const auto_char *filters, const auto_char *defaultExt) +{ +#ifdef _WIN32 + auto_char path[4096] = {}; + + OPENFILENAME of{sizeof(OPENFILENAME), parent, instance, + filters, nullptr, 0, 0, path, auto_size(path), + nullptr, 0, make_autocstring(directory.join()), title, + OFN_HIDEREADONLY | OFN_EXPLORER | OFN_FILEMUSTEXIST, 0, 0, defaultExt + }; + + return GetOpenFileName(&of) ? path : auto_string(); +#else + char *path = BrowseForFiles(title, directory.join().c_str(), + nullptr, false, filters); + return path ? path : auto_string(); +#endif +} + +auto_string FileDialog::getSaveFileName(HWND parent, HINSTANCE instance, + const auto_char *title, const Path &directory, + const auto_char *filters, const auto_char *defaultExt) +{ +#ifdef _WIN32 + auto_char path[4096] = {}; + + OPENFILENAME of{sizeof(OPENFILENAME), parent, instance, + filters, nullptr, 0, 0, path, auto_size(path), + nullptr, 0, make_autocstring(directory.join()), title, + OFN_HIDEREADONLY | OFN_EXPLORER | OFN_OVERWRITEPROMPT, 0, 0, defaultExt + }; + + return GetSaveFileName(&of) ? path : auto_string(); +#else + char path[4096] = {}; + + if(BrowseForSaveFile(title, directory.join().c_str(), + nullptr, filters, path, sizeof(path))) + return path; + else + return {}; +#endif +} diff --git a/src/filedialog.hpp b/src/filedialog.hpp @@ -0,0 +1,38 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2017 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_FILEBROWSE_HPP +#define REAPACK_FILEBROWSE_HPP + +#include "encoding.hpp" + +#ifdef _WIN32 +#include <windows.h> +#else +#include <swell-types.h> +#endif + +class Path; + +namespace FileDialog { + auto_string getOpenFileName(HWND, HINSTANCE, const auto_char *title, + const Path &directory, const auto_char *filters, const auto_char *defext); + auto_string getSaveFileName(HWND, HINSTANCE, const auto_char *title, + const Path &directory, const auto_char *filters, const auto_char *defext); +}; + +#endif diff --git a/src/manager.cpp b/src/manager.cpp @@ -20,6 +20,7 @@ #include "about.hpp" #include "config.hpp" #include "encoding.hpp" +#include "filedialog.hpp" #include "import.hpp" #include "menu.hpp" #include "reapack.hpp" @@ -27,11 +28,9 @@ #include "resource.hpp" #include "transaction.hpp" -#include <filebrowse.h> - -static const char *ARCHIVE_FILTER = - "ReaPack Offline Archive (*.ReaPackArchive)\0*.ReaPackArchive\0"; -static const char *ARCHIVE_EXT = "ReaPackArchive"; +static const auto_char *ARCHIVE_FILTER = + AUTO_STR("ReaPack Offline Archive (*.ReaPackArchive)\0*.ReaPackArchive\0"); +static const auto_char *ARCHIVE_EXT = AUTO_STR("ReaPackArchive"); using namespace std; @@ -489,34 +488,33 @@ bool Manager::importRepo() void Manager::importArchive() { - const char *title = "Import offline archive"; + const auto_char *title = AUTO_STR("Import offline archive"); - char *path = WDL_ChooseFileForOpen(handle(), title, - Path::prefixRoot(Path::DATA).join().c_str(), - nullptr, ARCHIVE_FILTER, ARCHIVE_EXT, true, false); + const auto_string &path = FileDialog::getOpenFileName(handle(), instance(), + title, Path::prefixRoot(Path::DATA), ARCHIVE_FILTER, ARCHIVE_EXT); - if(!path) + if(path.empty()) return; auto_char msg[255] = {}; - auto_snprintf(msg, auto_size(msg), "%s (%zu)\n", path, string(path).size()); + auto_snprintf(msg, auto_size(msg), AUTO_STR("%s (%zu)\n"), + path.c_str(), path.size()); MessageBox(handle(), msg, AUTO_STR("Import"), MB_OK); } void Manager::exportArchive() { - const char *title = "Export offline archive"; + const auto_char *title = AUTO_STR("Export offline archive"); - char path[4096] = {}; - const bool ok = WDL_ChooseFileForSave(handle(), title, - Path::prefixRoot(Path::DATA).join().c_str(), - nullptr, ARCHIVE_FILTER, ARCHIVE_EXT, true, path, sizeof(path)); + const auto_string &path = FileDialog::getSaveFileName(handle(), instance(), + title, Path::prefixRoot(Path::DATA), ARCHIVE_FILTER, ARCHIVE_EXT); - if(!ok) + if(path.empty()) return; auto_char msg[255] = {}; - auto_snprintf(msg, auto_size(msg), "%s (%zu)\n", path, string(path).size()); + auto_snprintf(msg, auto_size(msg), AUTO_STR("%s (%zu)\n"), + path.c_str(), path.size()); MessageBox(handle(), msg, AUTO_STR("Export"), MB_OK); }