mirror of https://gitlab.com/cppit/jucipp
25 changed files with 320 additions and 177 deletions
@ -1,3 +1,3 @@
|
||||
[submodule "libclangmm"] |
||||
path = libclangmm |
||||
url = https://github.com/eidheim/libclangmm.git |
||||
url = https://github.com/cppit/libclangmm/tree/v0.9.3 |
||||
|
||||
@ -1 +0,0 @@
|
||||
Source code for the dll's can be found at https://github.com/cppit/dialogs |
||||
@ -1,11 +0,0 @@
|
||||
extern "C" { |
||||
#ifndef JUCI_C_DIALOGS |
||||
#define JUCI_C_DIALOGS |
||||
__declspec(dllimport) const char* c_select_folder(); |
||||
__declspec(dllimport) const char* c_select_file(); |
||||
__declspec(dllimport) const char* c_new_file(); |
||||
__declspec(dllimport) const char* c_new_folder(); |
||||
__declspec(dllimport) const char* c_save_file(); |
||||
#endif // JUCI_C_DIALOGS
|
||||
}; |
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -1,24 +1,96 @@
|
||||
#ifdef _WIN32 |
||||
#include "dialogs.h" |
||||
#include <dialogs_win.h> |
||||
#include "singletons.h" |
||||
|
||||
#ifndef check |
||||
HRESULT __hr__; |
||||
#define check(__fun__, error_message) \ |
||||
__hr__ = __fun__; \
|
||||
if (FAILED(__hr__)) { \
|
||||
Singleton::terminal()->print(error_message); \
|
||||
throw std::runtime_error(error_message); \
|
||||
}
|
||||
#endif // CHECK
|
||||
|
||||
|
||||
// { WINSTRING
|
||||
WinString::WinString(const std::string &string) { |
||||
std::wstringstream ss; |
||||
ss << s2ws(string); |
||||
ss >> str; |
||||
} |
||||
|
||||
std::string WinString::operator()() { |
||||
std::string res; |
||||
if (str != nullptr) { |
||||
std::wstring ss(str); |
||||
res = ws2s(ss); |
||||
} |
||||
return res; |
||||
} |
||||
|
||||
// http://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
|
||||
std::wstring WinString::s2ws(const std::string& str) { |
||||
typedef std::codecvt_utf8<wchar_t> convert_typeX; |
||||
std::wstring_convert<convert_typeX, wchar_t> converterX; |
||||
return converterX.from_bytes(str); |
||||
} |
||||
|
||||
std::string WinString::ws2s(const std::wstring& wstr) { |
||||
typedef std::codecvt_utf8<wchar_t> convert_typeX; |
||||
std::wstring_convert<convert_typeX, wchar_t> converterX; |
||||
return converterX.to_bytes(wstr); |
||||
} |
||||
|
||||
// WINSTRING }
|
||||
|
||||
// { COMMON_DIALOG
|
||||
CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) { |
||||
check(CoCreateInstance(type, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog)), "Failed to create instance"); |
||||
check(dialog->GetOptions(&options), "Failed to get options from instance"); |
||||
} |
||||
|
||||
void CommonDialog::set_title(const std::string &title) { |
||||
auto tmp = std::wstring(title.begin(), title.end()); |
||||
auto t = tmp.data(); |
||||
check(dialog->SetTitle(t), "Failed to set dialog title"); |
||||
} |
||||
|
||||
void CommonDialog::add_option(unsigned option) { |
||||
check(dialog->SetOptions(options | option), "Failed to set options"); |
||||
} |
||||
|
||||
std::string CommonDialog::show() { |
||||
try { |
||||
check(dialog->Show(nullptr), "Failed to show dialog"); |
||||
IShellItem *result = nullptr; |
||||
check(dialog->GetResult(&result), "Failed to get result from dialog"); |
||||
WinString str; |
||||
check(result->GetDisplayName(SIGDN_FILESYSPATH, &str), "Failed to get display name from dialog"); |
||||
result->Release(); |
||||
return str(); |
||||
} catch (std::exception e) { |
||||
return ""; |
||||
} |
||||
} |
||||
// COMMON_DIALOG }}
|
||||
std::string Dialog::select_folder() { |
||||
return c_select_folder(); |
||||
return (OpenDialog("Select folder", FOS_PICKFOLDERS)).show(); |
||||
} |
||||
|
||||
std::string Dialog::new_file() { |
||||
return c_new_file(); |
||||
return (SaveDialog("Please choose your destination", 0)).show(); |
||||
} |
||||
|
||||
std::string Dialog::new_folder() { |
||||
return c_new_folder(); |
||||
return Dialog::select_folder(); |
||||
} |
||||
|
||||
std::string Dialog::select_file() { |
||||
return c_select_file(); |
||||
return (OpenDialog("Open file", 0)).show(); |
||||
} |
||||
|
||||
std::string Dialog::save_file() { |
||||
return c_save_file(); |
||||
return (SaveDialog("Please choose your destination", 0)).show(); |
||||
} |
||||
#endif |
||||
|
||||
@ -0,0 +1,29 @@
|
||||
#ifndef JUCI_SOURCEFILE_H_ |
||||
#define JUCI_SOURCEFILE_H_ |
||||
#include <vector> |
||||
#include <string> |
||||
#include <boost/filesystem.hpp> |
||||
#include <gtkmm.h> |
||||
|
||||
class filesystem { |
||||
public: |
||||
static std::string read(const std::string &path); |
||||
static std::string read(const boost::filesystem::path &path) { return read(path.string()); } |
||||
static int read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); } |
||||
|
||||
static int read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read_non_utf8(path.string(), text_buffer); } |
||||
|
||||
static std::vector<std::string> read_lines(const std::string &path); |
||||
static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); }; |
||||
|
||||
static bool write(const std::string &path, const std::string &new_content); |
||||
static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } |
||||
static bool write(const std::string &path) { return write(path, ""); }; |
||||
static bool write(const boost::filesystem::path &path) { return write(path, ""); }; |
||||
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); } |
||||
|
||||
}; |
||||
#endif // JUCI_SOURCEFILE_H_
|
||||
@ -1,30 +0,0 @@
|
||||
#ifndef JUCI_SOURCEFILE_H_ |
||||
#define JUCI_SOURCEFILE_H_ |
||||
#include <vector> |
||||
#include <string> |
||||
#include <boost/filesystem.hpp> |
||||
#include "gtkmm.h" |
||||
|
||||
namespace juci { |
||||
class filesystem { |
||||
public: |
||||
static std::string read(const std::string &path); |
||||
static std::string read(const boost::filesystem::path &path) { return read(path.string()); } |
||||
static int read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); } |
||||
|
||||
static int read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static int read_non_utf8(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read_non_utf8(path.string(), text_buffer); } |
||||
|
||||
static std::vector<std::string> read_lines(const std::string &path); |
||||
static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); }; |
||||
|
||||
static bool write(const std::string &path, const std::string &new_content); |
||||
static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } |
||||
static bool write(const std::string &path) { return write(path, ""); }; |
||||
static bool write(const boost::filesystem::path &path) { return write(path, ""); }; |
||||
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer); |
||||
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); } |
||||
}; |
||||
} // namepace juci
|
||||
#endif // JUCI_SOURCEFILE_H_
|
||||
Loading…
Reference in new issue