Browse Source

Now uses gtk dialog on Windows when creating folder, since Windows does not support this...

merge-requests/365/head
eidheim 10 years ago
parent
commit
fe2cf9bea4
  1. 37
      src/dialogs.cc
  2. 28
      src/dialogs.h
  3. 5
      src/dialogs_win.cc

37
src/dialogs.cc

@ -1,58 +1,31 @@
#include "dialogs.h" #include "dialogs.h"
#include "singletons.h"
#include <gtkmm.h>
#include <vector>
#include "juci.h"
std::string open_dialog(const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,
Gtk::FileChooserAction gtk_options,
const std::string &file_name = "") {
Gtk::FileChooserDialog dialog(title, gtk_options);
if(!Singleton::directories->current_path.empty())
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), Singleton::directories->current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
if (!file_name.empty())
gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), file_name.c_str());
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
auto g_application=g_application_get_default(); //TODO: Post issue that Gio::Application::get_default should return pointer and not Glib::RefPtr
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::cast_static(gio_application);
dialog.set_transient_for(*application->window);
for (auto &button : buttons)
dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
}
std::string Dialog::open_folder() { std::string Dialog::open_folder() {
return open_dialog("Open Folder", return gtk_dialog("Open Folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
} }
std::string Dialog::new_file() { std::string Dialog::new_file() {
return open_dialog("New File", return gtk_dialog("New File",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE); Gtk::FILE_CHOOSER_ACTION_SAVE);
} }
std::string Dialog::new_folder() { std::string Dialog::new_folder() {
return open_dialog("New Folder", return gtk_dialog("New Folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
} }
std::string Dialog::open_file() { std::string Dialog::open_file() {
return open_dialog("Open File", return gtk_dialog("Open File",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_OPEN); Gtk::FILE_CHOOSER_ACTION_OPEN);
} }
std::string Dialog::save_file_as(const boost::filesystem::path &file_path) { std::string Dialog::save_file_as(const boost::filesystem::path &file_path) {
return open_dialog("Save File As", return gtk_dialog("Save File As",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string()); Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string());
} }

28
src/dialogs.h

@ -2,6 +2,10 @@
#define JUCI_DIALOG_H_ #define JUCI_DIALOG_H_
#include <string> #include <string>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <vector>
#include <gtkmm.h>
#include "singletons.h"
#include "juci.h"
class Dialog { class Dialog {
public: public:
@ -10,6 +14,30 @@ public:
static std::string new_file(); static std::string new_file();
static std::string new_folder(); static std::string new_folder();
static std::string save_file_as(const boost::filesystem::path &file_path); static std::string save_file_as(const boost::filesystem::path &file_path);
private:
static std::string gtk_dialog(const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,
Gtk::FileChooserAction gtk_options,
const std::string &file_name = "") {
Gtk::FileChooserDialog dialog(title, gtk_options);
if(!Singleton::directories->current_path.empty())
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), Singleton::directories->current_path.string().c_str());
else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str());
if (!file_name.empty())
gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), file_name.c_str());
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
auto g_application=g_application_get_default(); //TODO: Post issue that Gio::Application::get_default should return pointer and not Glib::RefPtr
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::cast_static(gio_application);
dialog.set_transient_for(*application->window);
for (auto &button : buttons)
dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
}
}; };
#endif //JUCI_DIALOG_H_ #endif //JUCI_DIALOG_H_

5
src/dialogs_win.cc

@ -142,7 +142,10 @@ std::string Dialog::new_file() {
} }
std::string Dialog::new_folder() { std::string Dialog::new_folder() {
return Win32Dialog().open(L"New Folder", FOS_PICKFOLDERS); //TODO: this is not working correctly yet //Win32 (IFileDialog) does not support create folder...
return gtk_dialog("New Folder",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
} }
std::string Dialog::open_file() { std::string Dialog::open_file() {

Loading…
Cancel
Save