Browse Source

Added message on screen when creating compile_commands.json.

merge-requests/365/head
eidheim 10 years ago
parent
commit
92489acfe1
  1. 5
      src/CMakeLists.txt
  2. 8
      src/cmake.cc
  3. 82
      src/dialogs.cc
  4. 34
      src/dialogs.h
  5. 32
      src/dialogs_unix.cc
  6. 0
      src/terminal_unix.cc

5
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})

8
src/cmake.cc

@ -2,6 +2,7 @@
#include "singletons.h"
#include "filesystem.h"
#include <regex>
#include "dialogs.h"
#include <iostream> //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";

82
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 <typename Functor>
struct functor_trait<Functor, false> {
typedef decltype (::sigc::mem_fun(std::declval<Functor&>(),
&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);
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);
}
property_decorated()=false;
set_accept_focus(false);
set_skip_taskbar_hint(true);
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);
auto g_application=g_application_get_default();
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::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<Cairo::Context>& cr) {
label_drawn=true;
return false;
});
show_all();
}
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());
void Dialog::Message::wait_until_drawn() {
while(gtk_events_pending() || !label_drawn)
gtk_main_iteration();
}
std::string Dialog::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);
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);
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() : "";
}

34
src/dialogs.h

@ -4,8 +4,6 @@
#include <boost/filesystem.hpp>
#include <vector>
#include <gtkmm.h>
#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<std::pair<std::string, Gtk::ResponseType>> &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<Application>::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_

32
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());
}

0
src/terminal.cc → src/terminal_unix.cc

Loading…
Cancel
Save