commit 0b659e37398f0a99b67d94ffa59f2476f6f06ecf
parent cde3c683eb8e313ad6d31ab2aa6ddfebe52d70e0
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 4 Jun 2017 00:18:00 -0400
api: create ImportRepository function
Diffstat:
9 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/api.cpp b/src/api.cpp
@@ -295,3 +295,9 @@ DEFINE_API(PackageEntry*, GetOwner, ((const char*, fn))((char*, errorOut))((int,
return nullptr;
}
});
+
+DEFINE_API(void, ImportRepository, ((const char*, url)), R"(
+ Opens the "Import a repository" dialog with the input box pre-filled with given url.
+)", {
+ reapack->importRemote(url);
+});
diff --git a/src/api.hpp b/src/api.hpp
@@ -53,6 +53,7 @@ namespace API {
extern APIFunc FreeEntry;
extern APIFunc GetEntryInfo;
extern APIFunc GetOwner;
+ extern APIFunc ImportRepository;
};
#endif
diff --git a/src/import.cpp b/src/import.cpp
@@ -34,8 +34,9 @@ using namespace std;
static const auto_char *TITLE = AUTO_STR("ReaPack: Import a repository");
static const string DISCOVER_URL = "https://reapack.com/repos";
-Import::Import(ReaPack *reapack)
- : Dialog(IDD_IMPORT_DIALOG), m_reapack(reapack), m_download(nullptr)
+Import::Import(const string &initialUrl, ReaPack *reapack)
+ : Dialog(IDD_IMPORT_DIALOG), m_initialUrl(initialUrl),
+ m_reapack(reapack), m_download(nullptr)
{
}
@@ -50,6 +51,8 @@ void Import::onInit()
m_discover = getControl(IDC_DISCOVER);
m_ok = getControl(IDOK);
+ SetWindowText(m_url, make_autostring(m_initialUrl).c_str());
+
#ifdef PBM_SETMARQUEE
SendMessage(m_progress, PBM_SETMARQUEE, 1, 0);
#endif
diff --git a/src/import.hpp b/src/import.hpp
@@ -31,7 +31,7 @@ class Remote;
class Import : public Dialog
{
public:
- Import(ReaPack *);
+ Import(const std::string &initialUrl, ReaPack *);
protected:
void onInit() override;
@@ -44,6 +44,7 @@ private:
bool import(const Remote &);
void setWaiting(bool);
+ std::string m_initialUrl;
ReaPack *m_reapack;
MemoryDownload *m_download;
short m_fakePos;
diff --git a/src/main.cpp b/src/main.cpp
@@ -150,7 +150,7 @@ static void setupActions()
&reapack->browseAction, bind(&ReaPack::browsePackages, reapack));
reapack->setupAction("REAPACK_IMPORT", "ReaPack: Import a repository...",
- &reapack->importAction, bind(&ReaPack::importRemote, reapack));
+ &reapack->importAction, bind(&ReaPack::importRemote, reapack, ""));
reapack->setupAction("REAPACK_MANAGE", "ReaPack: Manage repositories...",
&reapack->configAction, bind(&ReaPack::manageRemotes, reapack));
@@ -168,6 +168,7 @@ static void setupAPI()
reapack->setupAPI(&API::FreeEntry);
reapack->setupAPI(&API::GetEntryInfo);
reapack->setupAPI(&API::GetOwner);
+ reapack->setupAPI(&API::ImportRepository);
}
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -470,13 +470,13 @@ void Manager::importExport()
menu.show(getControl(IDC_IMPORT), handle());
}
-bool Manager::importRepo()
+bool Manager::importRepo(const string &url)
{
if(m_importing) // avoid opening the import dialog twice on windows
return true;
m_importing = true;
- const auto ret = Dialog::Show<Import>(instance(), handle(), m_reapack);
+ const auto ret = Dialog::Show<Import>(instance(), handle(), url, m_reapack);
m_importing = false;
return ret != 0;
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -39,7 +39,7 @@ public:
Manager(ReaPack *);
void refresh();
- bool importRepo();
+ bool importRepo(const std::string &url = {});
protected:
void onInit() override;
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -200,13 +200,13 @@ void ReaPack::uninstall(const Remote &remote)
});
}
-void ReaPack::importRemote()
+void ReaPack::importRemote(const string &url)
{
const bool autoClose = m_manager == nullptr;
manageRemotes();
- if(!m_manager->importRepo() && autoClose)
+ if(!m_manager->importRepo(url) && autoClose)
m_manager->close();
}
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -66,7 +66,7 @@ public:
void enable(const Remote &r) { setRemoteEnabled(true, r); }
void uninstall(const Remote &);
- void importRemote();
+ void importRemote(const std::string &url = {});
void manageRemotes();
void aboutSelf();
void about(const Remote &);