From 92489acfe183355db68ea9186f0da6fe5d083fa4 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 11 Nov 2015 14:04:05 +0100 Subject: [PATCH] Added message on screen when creating compile_commands.json. --- src/CMakeLists.txt | 5 +- src/cmake.cc | 8 ++- src/dialogs.cc | 82 ++++++++++++++++++++------- src/dialogs.h | 34 ++++------- src/dialogs_unix.cc | 32 +++++++++++ src/{terminal.cc => terminal_unix.cc} | 0 6 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 src/dialogs_unix.cc rename src/{terminal.cc => terminal_unix.cc} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5e7cdb..7c5bf99 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,6 +72,7 @@ set(source_files juci.h singletons.cc cmake.h cmake.cc + dialogs.cc ../libclangmm/src/CodeCompleteResults.cc ../libclangmm/src/CompilationDatabase.cc @@ -92,8 +93,8 @@ if(MSYS) list(APPEND source_files terminal_win.cc) list(APPEND source_files dialogs_win.cc) else() - list(APPEND source_files terminal.cc) - list(APPEND source_files dialogs.cc) + list(APPEND source_files terminal_unix.cc) + list(APPEND source_files dialogs_unix.cc) endif() add_executable(${project_name} ${source_files}) diff --git a/src/cmake.cc b/src/cmake.cc index 7304358..63c67ac 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -2,6 +2,7 @@ #include "singletons.h" #include "filesystem.h" #include +#include "dialogs.h" #include //TODO: remove using namespace std; //TODO: remove @@ -45,8 +46,11 @@ CMake::CMake(const boost::filesystem::path &path) { } bool CMake::create_compile_commands(const boost::filesystem::path &path) { - Singleton::terminal->print("Creating "+path.string()+"/compile_commands.json\n"); - if(Singleton::terminal->execute(Singleton::config->terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path)==EXIT_SUCCESS) { + auto message=Dialog::Message("Creating "+path.string()+"/compile_commands.json"); + message.wait_until_drawn(); + auto exit_code=Singleton::terminal->execute(Singleton::config->terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path); + message.hide(); + if(exit_code==EXIT_SUCCESS) { #ifdef _WIN32 //Temporary fix to MSYS2's libclang auto compile_commands_path=path; compile_commands_path+="/compile_commands.json"; diff --git a/src/dialogs.cc b/src/dialogs.cc index 04aff01..c34ff72 100644 --- a/src/dialogs.cc +++ b/src/dialogs.cc @@ -1,32 +1,70 @@ #include "dialogs.h" +#include "juci.h" +#include "singletons.h" -std::string Dialog::open_folder() { - return gtk_dialog("Open Folder", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); +namespace sigc { +#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE + template + struct functor_trait { + typedef decltype (::sigc::mem_fun(std::declval(), + &Functor::operator())) _intermediate; + typedef typename _intermediate::result_type result_type; + typedef Functor functor_type; + }; +#else + SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE +#endif } -std::string Dialog::new_file() { - return gtk_dialog("New File", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_SAVE); +Dialog::Message::Message(const std::string &text): Gtk::Window(Gtk::WindowType::WINDOW_POPUP), label(text) { + auto font_desc=label.get_pango_context()->get_font_description(); + font_desc.set_size(font_desc.get_size()*2); + label.create_pango_context(); + label.get_pango_context()->set_font_description(font_desc); + add(label); + + property_decorated()=false; + set_accept_focus(false); + set_skip_taskbar_hint(true); + + auto g_application=g_application_get_default(); + auto gio_application=Glib::wrap(g_application, true); + auto application=Glib::RefPtr::cast_static(gio_application); + set_transient_for(*application->window); + set_position(Gtk::WindowPosition::WIN_POS_CENTER_ON_PARENT); + label.signal_draw().connect([this](const Cairo::RefPtr& cr) { + label_drawn=true; + return false; + }); + show_all(); } -std::string Dialog::new_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); +void Dialog::Message::wait_until_drawn() { + while(gtk_events_pending() || !label_drawn) + gtk_main_iteration(); } -std::string Dialog::open_file() { - return gtk_dialog("Open File", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_OPEN); -} +std::string Dialog::gtk_dialog(const std::string &title, + const std::vector> &buttons, + Gtk::FileChooserAction gtk_options, + const std::string &file_name) { + Gtk::FileChooserDialog dialog(title, gtk_options); + + 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::cast_static(gio_application); + dialog.set_transient_for(*application->window); + + auto current_path=application->window->notebook.get_current_folder(); + if(current_path.empty()) + current_path=boost::filesystem::current_path(); + gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), current_path.string().c_str()); -std::string Dialog::save_file_as(const boost::filesystem::path &file_path) { - return gtk_dialog("Save File As", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string()); + 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); + + for (auto &button : buttons) + dialog.add_button(button.first, button.second); + return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; } - diff --git a/src/dialogs.h b/src/dialogs.h index f85a0b3..446cc03 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -4,8 +4,6 @@ #include #include #include -#include "singletons.h" -#include "juci.h" class Dialog { public: @@ -15,31 +13,21 @@ public: static std::string new_folder(); static std::string save_file_as(const boost::filesystem::path &file_path); + class Message : public Gtk::Window { + public: + Message(const std::string &text); + + void wait_until_drawn(); + private: + Gtk::Label label; + bool label_drawn=false; + }; + private: static std::string gtk_dialog(const std::string &title, const std::vector> &buttons, Gtk::FileChooserAction gtk_options, - const std::string &file_name = "") { - Gtk::FileChooserDialog dialog(title, gtk_options); - - 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::cast_static(gio_application); - dialog.set_transient_for(*application->window); - - auto current_path=application->window->notebook.get_current_folder(); - if(current_path.empty()) - current_path=boost::filesystem::current_path(); - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), 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); - - for (auto &button : buttons) - dialog.add_button(button.first, button.second); - return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; - } + const std::string &file_name = ""); }; #endif //JUCI_DIALOG_H_ diff --git a/src/dialogs_unix.cc b/src/dialogs_unix.cc new file mode 100644 index 0000000..04aff01 --- /dev/null +++ b/src/dialogs_unix.cc @@ -0,0 +1,32 @@ +#include "dialogs.h" + +std::string Dialog::open_folder() { + return gtk_dialog("Open Folder", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); +} + +std::string Dialog::new_file() { + return gtk_dialog("New File", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_SAVE); +} + +std::string Dialog::new_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() { + return gtk_dialog("Open File", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_OPEN); +} + +std::string Dialog::save_file_as(const boost::filesystem::path &file_path) { + return gtk_dialog("Save File As", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string()); +} + diff --git a/src/terminal.cc b/src/terminal_unix.cc similarity index 100% rename from src/terminal.cc rename to src/terminal_unix.cc