From 908a7092bc345bd96d8a3143e8355ff95f0a24b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sun, 13 Sep 2015 18:51:40 +0200 Subject: [PATCH 1/7] Clean dialogs and add some windows support --- src/CMakeLists.txt | 9 +- src/dialogs.cc | 50 +++++++++ src/dialogs.h | 14 +++ src/dialogs_win.cc | 52 ++++++++++ src/juci.cc | 2 +- src/singletons.cc | 7 ++ src/singletons.h | 2 + src/window.cc | 253 ++++++++++++++------------------------------- src/window.h | 7 -- 9 files changed, 208 insertions(+), 188 deletions(-) create mode 100644 src/dialogs.cc create mode 100644 src/dialogs.h create mode 100644 src/dialogs_win.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3cbdb24..deec0b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,13 +88,18 @@ set(source_files juci.h tooltips.cc singletons.h singletons.cc + dialogs.h cmake.h cmake.cc) if(MSYS) - list(APPEND source_files terminal_win.cc) + list(APPEND source_files terminal_win.cc dialogs_win.cc) + list(APPEND source_files dialogs_win.cc) + message("MSYS detected") else() - list(APPEND source_files terminal.cc) + list(APPEND source_files terminal.cc dialogs.cc) + list(APPEND source_files dialogs.cc) + message("UNIX detected") endif() if(${validation}) diff --git a/src/dialogs.cc b/src/dialogs.cc new file mode 100644 index 0000000..8ff3882 --- /dev/null +++ b/src/dialogs.cc @@ -0,0 +1,50 @@ +#include "dialogs.h" +#include "singletons.h" +#include +#include + +std::string open_dialog(const std::string &title, + const std::vector> buttons, + Gtk::FileChooserAction gtk_options) { + Gtk::FileChooserDialog dialog(title, gtk_options); + if(Singleton::directories()->current_path!="") + 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()); + dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); + // dialog.set_transient_for(parent); TODO add parent + for (auto &button : buttons) + dialog.add_button(button.first, button.second); + return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; +} + + +std::string Dialog::select_folder() { + return open_dialog("Please choose a 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 open_dialog("Please create a 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 open_dialog("Please create a 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::select_file() { + return open_dialog("Please choose a folder", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_OPEN); +} + +std::string Dialog::save_file() { + return open_dialog("Please choose a file", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_OPEN); +} \ No newline at end of file diff --git a/src/dialogs.h b/src/dialogs.h new file mode 100644 index 0000000..5acf6ea --- /dev/null +++ b/src/dialogs.h @@ -0,0 +1,14 @@ +#ifndef JUCI_DIALOG_H_ +#define JUCI_DIALOG_H_ +#include + +class Dialog { + public: + static std::string select_folder(); + static std::string select_file(); + static std::string new_file(); + static std::string new_folder(); + static std::string save_file(); +}; // namespace Dialog + +#endif // JUCI_DIALOG_H_ \ No newline at end of file diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc new file mode 100644 index 0000000..f245f31 --- /dev/null +++ b/src/dialogs_win.cc @@ -0,0 +1,52 @@ +#include "dialogs.h" +#include +#include + +std::string Dialog::select_folder() { + char selected_folder[MAX_PATH]; + char init_path[MAX_PATH]; + auto title = "Please select a folder"; + selected_folder[0] = 0; + init_path[0] = 0; + + BROWSEINFOA browse; + browse.hwndOwner = 0; + browse.pidlRoot = NULL; + browse.lpszTitle = title; + browse.pszDisplayName = init_path; + browse.ulFlags = 0; + browse.lpfn = NULL; + auto result = SHBrowseForFolder(&browse); + + if(result) + SHGetPathFromIDListA(result, selected_folder); + + std::string dir(selected_folder); + return dir; +} +/* +std::string Dialog::new_file() { + return open_dialog("Please create a 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 open_dialog("Please create a 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::select_file() { + return open_dialog("Please choose a folder", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_OPEN); +} + +std::string Dialog::save_file() { + return open_dialog("Please choose a file", + {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, + Gtk::FILE_CHOOSER_ACTION_OPEN); +} + +*/ \ No newline at end of file diff --git a/src/juci.cc b/src/juci.cc index a97b8ee..c83eb47 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -45,7 +45,7 @@ void app::on_activate() { bool first_directory=true; for(auto &directory: directories) { if(first_directory) { - window->directories.open(directory); + Singleton::directories()->open(directory); first_directory=false; } else { diff --git a/src/singletons.cc b/src/singletons.cc index 4633763..9040d55 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -5,12 +5,19 @@ std::unique_ptr Singleton::Config::directories_=std::unique std::unique_ptr Singleton::Config::terminal_=std::unique_ptr(new Terminal::Config()); std::unique_ptr Singleton::Config::window_ = std::unique_ptr(new Window::Config()); std::unique_ptr Singleton::terminal_=std::unique_ptr(); +std::unique_ptr Singleton::directories_=std::unique_ptr(); Terminal *Singleton::terminal() { if(!terminal_) terminal_=std::unique_ptr(new Terminal()); return terminal_.get(); } + +Directories *Singleton::directories() { + if(!directories_) + directories_=std::unique_ptr(new Directories()); + return directories_.get(); +} std::unique_ptr Singleton::status_=std::unique_ptr(); Gtk::Label *Singleton::status() { if(!status_) diff --git a/src/singletons.h b/src/singletons.h index 8fa6a86..33297ea 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -30,12 +30,14 @@ public: static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static Terminal *terminal(); + static Directories *directories(); static Gtk::Label *status(); static Gtk::Label *info(); private: static std::unique_ptr terminal_; static std::unique_ptr status_; static std::unique_ptr info_; + static std::unique_ptr directories_; }; #endif // JUCI_SINGLETONS_H_ diff --git a/src/window.cc b/src/window.cc index 13bfa5a..0daf779 100644 --- a/src/window.cc +++ b/src/window.cc @@ -5,6 +5,7 @@ #include "config.h" //#include "api.h" #include +#include "dialogs.h" #include //TODO: remove using namespace std; //TODO: remove @@ -30,7 +31,7 @@ void Window::generate_keybindings() { } } -Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compiling(false) { +Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::directories()), compiling(false) { DEBUG("start"); set_title("juCi++"); set_default_size(600, 400); @@ -42,7 +43,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil create_menu(); box.pack_start(menu.get_widget(), Gtk::PACK_SHRINK); - directory_and_notebook_panes.pack1(directories, Gtk::SHRINK); + directory_and_notebook_panes.pack1(*Singleton::directories(), Gtk::SHRINK); notebook_vbox.pack_start(notebook); notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK); directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK); @@ -60,7 +61,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil box.pack_end(vpaned); show_all_children(); - directories.on_row_activated=[this](const std::string &file) { + Singleton::directories()->on_row_activated=[this](const std::string &file) { notebook.open(file); }; @@ -100,7 +101,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil if(auto menu_item=dynamic_cast(menu.ui_manager->get_widget("/MenuBar/SourceMenu/SourceRename"))) menu_item->set_sensitive((bool)notebook.get_current_view()->rename_similar_tokens); - directories.select(notebook.get_current_view()->file_path); + Singleton::directories()->select(notebook.get_current_view()->file_path); if(auto source_view=dynamic_cast(notebook.get_current_view())) { if(source_view->reparse_needed) { @@ -140,23 +141,86 @@ void Window::create_menu() { hide(); }); menu.action_group->add(Gtk::Action::create("FileNewFile", "New File"), Gtk::AccelKey(menu.key_map["new_file"]), [this]() { - new_file_dialog(); + boost::filesystem::path path = Dialog::new_file(); + if(path!="") { + if(boost::filesystem::exists(path)) { + Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); + } + else { + if(juci::filesystem::write(path)) { + if(Singleton::directories()->current_path!="") + Singleton::directories()->update(); + notebook.open(path.string()); + Singleton::terminal()->print("New file "+path.string()+" created.\n"); + } + else + Singleton::terminal()->print("Error: could not create new file "+path.string()+".\n"); + } + } }); menu.action_group->add(Gtk::Action::create("FileNewFolder", "New Folder"), Gtk::AccelKey(menu.key_map["new_folder"]), [this]() { - new_folder_dialog(); + auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + boost::filesystem::path path = Dialog::new_folder(); + if(boost::filesystem::last_write_time(path)>=time_now) { + if(Singleton::directories()->current_path!="") + Singleton::directories()->update(); + Singleton::terminal()->print("New folder "+path.string()+" created.\n"); + } + else + Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); + Singleton::directories()->select(path); }); menu.action_group->add(Gtk::Action::create("FileNewProject", "New Project")); menu.action_group->add(Gtk::Action::create("FileNewProjectCpp", "C++"), [this]() { - new_cpp_project_dialog(); + boost::filesystem::path project_path = Dialog::new_folder(); + auto project_name=project_path.filename().string(); + for(size_t c=0;cprint("Error: "+cmakelists_path.string()+" already exists.\n"); + return; + } + if(boost::filesystem::exists(cpp_main_path)) { + Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n"); + return; + } + std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n"; + std::string cpp_main="#include \n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; + if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) { + Singleton::directories()->open(project_path); + notebook.open(cpp_main_path); + Singleton::terminal()->print("C++ project "+project_name+" created.\n"); + } + else + Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n"); }); menu.action_group->add(Gtk::Action::create("FileOpenFile", "Open File"), Gtk::AccelKey(menu.key_map["open_file"]), [this]() { - open_file_dialog(); + notebook.open(Dialog::select_file()); }); menu.action_group->add(Gtk::Action::create("FileOpenFolder", "Open Folder"), Gtk::AccelKey(menu.key_map["open_folder"]), [this]() { - open_folder_dialog(); + Singleton::directories()->open(Dialog::select_folder()); }); menu.action_group->add(Gtk::Action::create("FileSaveAs", "Save As"), Gtk::AccelKey(menu.key_map["save_as"]), [this]() { - save_file_dialog(); + auto path = Dialog::save_file(); + if(path.size()>0) { + std::ofstream file(path); + if(file) { + file << notebook.get_current_view()->get_buffer()->get_text(); + file.close(); + if(Singleton::directories()->current_path!="") + Singleton::directories()->update(); + notebook.open(path); + Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n"); + } + else + Singleton::terminal()->print("Error saving file\n"); + } }); menu.action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu.key_map["save"]), [this]() { @@ -301,7 +365,7 @@ void Window::create_menu() { if(content!="") { last_run_command=content; Singleton::terminal()->async_print("Running: "+content+'\n'); - Singleton::terminal()->async_execute(content, directories.current_path, [this, content](int exit_code){ + Singleton::terminal()->async_execute(content, Singleton::directories()->current_path, [this, content](int exit_code){ Singleton::terminal()->async_print(content+" returned: "+boost::lexical_cast(exit_code)+'\n'); }); } @@ -388,173 +452,6 @@ void Window::hide() { Gtk::Window::hide(); } -void Window::new_file_dialog() { - Gtk::FileChooserDialog dialog("Please create a new file", Gtk::FILE_CHOOSER_ACTION_SAVE); - if(directories.current_path!="") - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); - else - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); - dialog.set_transient_for(*this); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Save", Gtk::RESPONSE_OK); - - int result = dialog.run(); - if(result==Gtk::RESPONSE_OK) { - boost::filesystem::path path = dialog.get_filename(); - if(path!="") { - if(boost::filesystem::exists(path)) { - Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); - } - else { - if(juci::filesystem::write(path)) { - if(directories.current_path!="") - directories.update(); - notebook.open(path.string()); - Singleton::terminal()->print("New file "+path.string()+" created.\n"); - } - else - Singleton::terminal()->print("Error: could not create new file "+path.string()+".\n"); - } - } - } -} - -void Window::new_folder_dialog() { - auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - Gtk::FileChooserDialog dialog("Please create a new folder", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); - if(directories.current_path!="") - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); - else - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); - dialog.set_transient_for(*this); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Create", Gtk::RESPONSE_OK); - - int result = dialog.run(); - if(result==Gtk::RESPONSE_OK) { - boost::filesystem::path path=dialog.get_filename(); - if(boost::filesystem::last_write_time(path)>=time_now) { - if(directories.current_path!="") - directories.update(); - Singleton::terminal()->print("New folder "+path.string()+" created.\n"); - } - else - Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); - directories.select(path); - } -} - -void Window::new_cpp_project_dialog() { - Gtk::FileChooserDialog dialog("Please create and/or choose a folder", Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); - if(directories.current_path!="") - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); - else - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); - dialog.set_transient_for(*this); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Create", Gtk::RESPONSE_OK); - - int result = dialog.run(); - if(result==Gtk::RESPONSE_OK) { - boost::filesystem::path project_path=dialog.get_filename(); - auto project_name=project_path.filename().string(); - for(size_t c=0;cprint("Error: "+cmakelists_path.string()+" already exists.\n"); - return; - } - if(boost::filesystem::exists(cpp_main_path)) { - Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n"); - return; - } - std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n"; - std::string cpp_main="#include \n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; - if(juci::filesystem::write(cmakelists_path, cmakelists) && juci::filesystem::write(cpp_main_path, cpp_main)) { - directories.open(project_path); - notebook.open(cpp_main_path); - Singleton::terminal()->print("C++ project "+project_name+" created.\n"); - } - else - Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n"); - } -} - -void Window::open_folder_dialog() { - Gtk::FileChooserDialog dialog("Please choose a folder", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); - if(directories.current_path!="") - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); - else - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); - dialog.set_transient_for(*this); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Open", Gtk::RESPONSE_OK); - - int result = dialog.run(); - - if(result==Gtk::RESPONSE_OK) { - std::string project_path=dialog.get_filename(); - directories.open(project_path); - } -} - -void Window::open_file_dialog() { - Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN); - if(directories.current_path!="") - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), directories.current_path.string().c_str()); - else - gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); - dialog.set_transient_for(*this); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Open", Gtk::RESPONSE_OK); - - int result = dialog.run(); - - if(result==Gtk::RESPONSE_OK) { - std::string path = dialog.get_filename(); - notebook.open(path); - } -} - -void Window::save_file_dialog() { - if(notebook.get_current_page()==-1) - return; - Gtk::FileChooserDialog dialog(*this, "Please choose a file", Gtk::FILE_CHOOSER_ACTION_SAVE); - gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), notebook.get_current_view()->file_path.string().c_str()); - dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - dialog.add_button("Cancel", Gtk::RESPONSE_CANCEL); - dialog.add_button("Save", Gtk::RESPONSE_OK); - - int result = dialog.run(); - if(result==Gtk::RESPONSE_OK) { - auto path = dialog.get_filename(); - if(path.size()>0) { - std::ofstream file(path); - if(file) { - file << notebook.get_current_view()->get_buffer()->get_text(); - file.close(); - if(directories.current_path!="") - directories.update(); - notebook.open(path); - Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n"); - } - else - Singleton::terminal()->print("Error saving file\n"); - } - } -} - void Window::search_and_replace_entry() { entry_box.clear(); entry_box.labels.emplace_back(); diff --git a/src/window.h b/src/window.h index 5c8b349..5cfb91f 100644 --- a/src/window.h +++ b/src/window.h @@ -12,7 +12,6 @@ class Window : public Gtk::Window { public: Window(); - Directories directories; Notebook notebook; class Config { public: @@ -41,12 +40,6 @@ private: void create_menu(); void hide(); - void new_file_dialog(); - void new_folder_dialog(); - void new_cpp_project_dialog(); - void open_folder_dialog(); - void open_file_dialog(); - void save_file_dialog(); void search_and_replace_entry(); void goto_line_entry(); void rename_token_entry(); From 9df554750540bdfe1b14a223bdddd784624fe45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sun, 13 Sep 2015 21:25:18 +0200 Subject: [PATCH 2/7] Change implementation to Vista and up --- src/dialogs_win.cc | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index f245f31..c9e6f57 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -1,33 +1,26 @@ #include "dialogs.h" -#include -#include +#include +#include +#include +#include + +#ifndef check(__fun__) +#define MESSAGE "An error occurred when trying open windows dialog" +#define check(__fun__) auto __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE) +#endif + std::string Dialog::select_folder() { - char selected_folder[MAX_PATH]; - char init_path[MAX_PATH]; - auto title = "Please select a folder"; - selected_folder[0] = 0; - init_path[0] = 0; - - BROWSEINFOA browse; - browse.hwndOwner = 0; - browse.pidlRoot = NULL; - browse.lpszTitle = title; - browse.pszDisplayName = init_path; - browse.ulFlags = 0; - browse.lpfn = NULL; - auto result = SHBrowseForFolder(&browse); + IFileOpenDialog *dialog = nullptr; + check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))); + DWORD options; + check(dialog->GetOptions(&options)); - if(result) - SHGetPathFromIDListA(result, selected_folder); - - std::string dir(selected_folder); - return dir; } /* std::string Dialog::new_file() { return open_dialog("Please create a new file", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, + {std::make_pair("Cancel", Gtk::RESPONSECANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, Gtk::FILE_CHOOSER_ACTION_SAVE); } From ddeeb1998906bd9bf11671d98427be84dd12465b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 21 Sep 2015 18:42:22 +0200 Subject: [PATCH 3/7] Vista implementation of pick folder --- src/CMakeLists.txt | 6 ++-- src/dialogs_win.cc | 81 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index deec0b9..7bf09cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -93,18 +93,18 @@ set(source_files juci.h cmake.cc) if(MSYS) - list(APPEND source_files terminal_win.cc dialogs_win.cc) + list(APPEND source_files terminal_win.cc) list(APPEND source_files dialogs_win.cc) message("MSYS detected") else() - list(APPEND source_files terminal.cc dialogs.cc) + list(APPEND source_files terminal.cc) list(APPEND source_files dialogs.cc) message("UNIX detected") endif() if(${validation}) add_executable(${project_name} ${source_files}) - + # add_library(${module} SHARED # api # api_ext) diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index c9e6f57..acf03bd 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -1,45 +1,78 @@ #include "dialogs.h" +#include #include #include #include -#include +#include "singletons.h" +#include -#ifndef check(__fun__) +#ifndef check #define MESSAGE "An error occurred when trying open windows dialog" -#define check(__fun__) auto __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE) +HRESULT __hr__; +#define check(__fun__) __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE) #endif +class win_string { + public: + win_string() : str(nullptr) { } + ~win_string() { CoTaskMemFree(static_cast(str)); } + std::string operator()(){ + std::string res; + if (str != nullptr) { + std::wstringstream ss; + ss << str; + res = std::string(ss.str().begin(), ss.str().end()); + } + return res; + } + wchar_t** operator&() { return &str; } + private: + wchar_t* str; +}; -std::string Dialog::select_folder() { - IFileOpenDialog *dialog = nullptr; - check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))); - DWORD options; - check(dialog->GetOptions(&options)); +class CommonDialog { + public: + CommonDialog() : dialog(nullptr) { + check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))); + check(dialog->GetOptions(&options)); + } + CommonDialog(const std::string &title, unsigned option) : CommonDialog() { + set_title(title); + add_option(option); + } + void set_title(const std::string &title) { check(dialog->SetTitle(title)); } + void add_option(unsigned option) { check(dialog->SetOptions(options | option)); } + std::string show() { + check(dialog->Show(nullptr)); + IShellItem *result = nullptr; + check(dialog->GetResult(&result)); + win_string str; + check(result->GetDisplayName(SIGDN_FILESYSPATH, &str));; + result->Release(); + return str(); + } + private: + IFileOpenDialog * dialog; + DWORD options; +}; + +std::string Dialog::select_folder() { + return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); } -/* + std::string Dialog::new_file() { - return open_dialog("Please create a new file", - {std::make_pair("Cancel", Gtk::RESPONSECANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_SAVE); + return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); } std::string Dialog::new_folder() { - return open_dialog("Please create a new folder", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); + return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); } std::string Dialog::select_file() { - return open_dialog("Please choose a folder", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_OPEN); + return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); } std::string Dialog::save_file() { - return open_dialog("Please choose a file", - {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, - Gtk::FILE_CHOOSER_ACTION_OPEN); -} - -*/ \ No newline at end of file + return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); +} \ No newline at end of file From 317e5a8528be28cd0f586b71cbe1cd251c578c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 21 Sep 2015 19:19:47 +0200 Subject: [PATCH 4/7] Rename logging function due to namespace conflict --- src/config.cc | 4 ++-- src/directories.cc | 14 +++++++------- src/juci.cc | 2 +- src/logging.h | 14 +++++++------- src/notebook.cc | 18 +++++++++--------- src/source.cc | 6 +++--- src/terminal.cc | 8 ++++---- src/window.cc | 4 ++-- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/config.cc b/src/config.cc index d7bcaa1..75e750c 100644 --- a/src/config.cc +++ b/src/config.cc @@ -65,7 +65,7 @@ void MainConfig::GenerateSource() { void MainConfig::GenerateDirectoryFilter() { auto dir_cfg=Singleton::Config::directories(); - DEBUG("Fetching directory filter"); + JDEBUG("Fetching directory filter"); boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); @@ -73,5 +73,5 @@ void MainConfig::GenerateDirectoryFilter() { dir_cfg->exceptions.emplace_back(i.second.get_value()); for ( auto &i : ignore_json ) dir_cfg->ignored.emplace_back(i.second.get_value()); - DEBUG("Directory filter fetched"); + JDEBUG("Directory filter fetched"); } diff --git a/src/directories.cc b/src/directories.cc index 5a761a4..5416936 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -23,7 +23,7 @@ namespace sigc { } Directories::Directories() : stop_update_thread(false) { - DEBUG("start"); + JDEBUG("start"); add(tree_view); set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); tree_store = Gtk::TreeStore::create(column_record); @@ -120,7 +120,7 @@ Directories::~Directories() { } void Directories::open(const boost::filesystem::path& dir_path) { - DEBUG("start"); + JDEBUG("start"); if(dir_path=="") return; @@ -142,21 +142,21 @@ void Directories::open(const boost::filesystem::path& dir_path) { current_path=dir_path; - DEBUG("end"); + JDEBUG("end"); } void Directories::update() { - DEBUG("start"); + JDEBUG("start"); update_mutex.lock(); for(auto &last_write_time: last_write_times) { add_path(last_write_time.first, last_write_time.second.first); } update_mutex.unlock(); - DEBUG("end"); + JDEBUG("end"); } void Directories::select(const boost::filesystem::path &path) { - DEBUG("start"); + JDEBUG("start"); if(current_path=="") return; @@ -196,7 +196,7 @@ void Directories::select(const boost::filesystem::path &path) { } return false; }); - DEBUG("end"); + JDEBUG("end"); } bool Directories::ignored(std::string path) { diff --git a/src/juci.cc b/src/juci.cc index c83eb47..c4164bc 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -9,7 +9,7 @@ void init_logging() { boost::log::add_common_attributes(); boost::log::add_file_log(boost::log::keywords::file_name = Singleton::log_dir() + "juci.log", boost::log::keywords::auto_flush = true); - INFO("Logging initalized"); + JINFO("Logging initalized"); } int app::on_command_line(const Glib::RefPtr &cmd) { diff --git a/src/logging.h b/src/logging.h index fbd9f89..7fd780b 100644 --- a/src/logging.h +++ b/src/logging.h @@ -15,12 +15,12 @@ #define INFO_VAR(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define WARNING_VAR(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define FATAL_VAR(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; -#define ERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; -#define TRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define DEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define INFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define WARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define FATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define ERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; +#define JTRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JDEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JINFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JWARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JFATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #endif // JUCI_LOGGING_H_ diff --git a/src/notebook.cc b/src/notebook.cc index 40b9874..041f8c1 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -48,7 +48,7 @@ Source::View* Notebook::get_current_view() { } void Notebook::open(const boost::filesystem::path &file_path) { - DEBUG("start"); + JDEBUG("start"); for(int c=0;cfile_path) { set_current_page(c); @@ -124,13 +124,13 @@ void Notebook::open(const boost::filesystem::path &file_path) { set_tab_label_text(*(get_nth_page(page)), title); }); - DEBUG("end"); + JDEBUG("end"); } bool Notebook::save(int page, bool reparse_needed) { - DEBUG("start"); + JDEBUG("start"); if(page>=size()) { - DEBUG("end false"); + JDEBUG("end false"); return false; } auto view=get_view(page); @@ -166,12 +166,12 @@ bool Notebook::save(int page, bool reparse_needed) { } } } - DEBUG("end true"); + JDEBUG("end true"); return true; } Singleton::terminal()->print("Error: could not save file " +view->file_path.string()+"\n"); } - DEBUG("end false"); + JDEBUG("end false"); return false; } @@ -182,11 +182,11 @@ bool Notebook::save_current() { } bool Notebook::close_current_page() { - DEBUG("start"); + JDEBUG("start"); if (get_current_page()!=-1) { if(get_current_view()->get_buffer()->get_modified()){ if(!save_modified_dialog()) { - DEBUG("end false"); + JDEBUG("end false"); return false; } } @@ -202,7 +202,7 @@ bool Notebook::close_current_page() { scrolled_windows.erase(scrolled_windows.begin()+index); hboxes.erase(hboxes.begin()+index); } - DEBUG("end true"); + JDEBUG("end true"); return true; } diff --git a/src/source.cc b/src/source.cc index 98cb8ff..b25a30c 100644 --- a/src/source.cc +++ b/src/source.cc @@ -972,7 +972,7 @@ clang::Index Source::ClangViewParse::clang_index(0, 0); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language): Source::View(file_path, language), project_path(project_path), parse_error(false) { - DEBUG("start"); + JDEBUG("start"); auto scheme = get_source_buffer()->get_style_scheme(); auto tag_table=get_buffer()->get_tag_table(); for (auto &item : Singleton::Config::source()->clang_types) { @@ -991,7 +991,7 @@ Source::View(file_path, language), project_path(project_path), parse_error(false // // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background(); // // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); } else - INFO("Style " + item.second + " not found in " + scheme->get_name()); + JINFO("Style " + item.second + " not found in " + scheme->get_name()); } } @@ -1039,7 +1039,7 @@ Source::View(file_path, language), project_path(project_path), parse_error(false bracket_regex=std::regex(std::string("^(")+tab_char+"*).*\\{ *$"); no_bracket_statement_regex=std::regex(std::string("^(")+tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); no_bracket_no_para_statement_regex=std::regex(std::string("^(")+tab_char+"*)(else|try|do) *$"); - DEBUG("end"); + JDEBUG("end"); } Source::ClangViewParse::~ClangViewParse() { diff --git a/src/terminal.cc b/src/terminal.cc index eb96fcf..7cee28b 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -154,7 +154,7 @@ Terminal::Terminal() { } int Terminal::execute(const std::string &command, const boost::filesystem::path &path) { - DEBUG("start"); + JDEBUG("start"); int stdin_fd, stdout_fd, stderr_fd; auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd); @@ -192,14 +192,14 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path close(stdout_fd); close(stderr_fd); - DEBUG("end"); + JDEBUG("end"); return exit_code; } } void Terminal::async_execute(const std::string &command, const boost::filesystem::path &path, std::function callback) { std::thread async_execute_thread([this, command, path, callback](){ - DEBUG("start"); + JDEBUG("start"); int stdin_fd, stdout_fd, stderr_fd; async_executes_mutex.lock(); stdin_buffer.clear(); @@ -254,7 +254,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem if(callback) callback(exit_code); - DEBUG("end"); + JDEBUG("end"); } }); async_execute_thread.detach(); diff --git a/src/window.cc b/src/window.cc index 0daf779..8ac72a6 100644 --- a/src/window.cc +++ b/src/window.cc @@ -32,7 +32,7 @@ void Window::generate_keybindings() { } Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::directories()), compiling(false) { - DEBUG("start"); + JDEBUG("start"); set_title("juCi++"); set_default_size(600, 400); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); @@ -133,7 +133,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::director about.set_comments("This is an open source IDE with high-end features to make your programming experience juicy"); about.set_license_type(Gtk::License::LICENSE_MIT_X11); about.set_transient_for(*this); - DEBUG("end"); + JDEBUG("end"); } // Window constructor void Window::create_menu() { From 2ea1e1821abf88c1b5ff1b42ac67fdd24dadfb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 21 Sep 2015 19:19:47 +0200 Subject: [PATCH 5/7] Rename logging function due to namespace conflict --- src/config.cc | 4 ++-- src/directories.cc | 14 +++++++------- src/juci.cc | 2 +- src/logging.h | 14 +++++++------- src/notebook.cc | 18 +++++++++--------- src/source.cc | 6 +++--- src/terminal.cc | 8 ++++---- src/terminal_win.cc | 4 ++-- src/window.cc | 4 ++-- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/config.cc b/src/config.cc index d7bcaa1..75e750c 100644 --- a/src/config.cc +++ b/src/config.cc @@ -65,7 +65,7 @@ void MainConfig::GenerateSource() { void MainConfig::GenerateDirectoryFilter() { auto dir_cfg=Singleton::Config::directories(); - DEBUG("Fetching directory filter"); + JDEBUG("Fetching directory filter"); boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter"); boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); @@ -73,5 +73,5 @@ void MainConfig::GenerateDirectoryFilter() { dir_cfg->exceptions.emplace_back(i.second.get_value()); for ( auto &i : ignore_json ) dir_cfg->ignored.emplace_back(i.second.get_value()); - DEBUG("Directory filter fetched"); + JDEBUG("Directory filter fetched"); } diff --git a/src/directories.cc b/src/directories.cc index 5a761a4..5416936 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -23,7 +23,7 @@ namespace sigc { } Directories::Directories() : stop_update_thread(false) { - DEBUG("start"); + JDEBUG("start"); add(tree_view); set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); tree_store = Gtk::TreeStore::create(column_record); @@ -120,7 +120,7 @@ Directories::~Directories() { } void Directories::open(const boost::filesystem::path& dir_path) { - DEBUG("start"); + JDEBUG("start"); if(dir_path=="") return; @@ -142,21 +142,21 @@ void Directories::open(const boost::filesystem::path& dir_path) { current_path=dir_path; - DEBUG("end"); + JDEBUG("end"); } void Directories::update() { - DEBUG("start"); + JDEBUG("start"); update_mutex.lock(); for(auto &last_write_time: last_write_times) { add_path(last_write_time.first, last_write_time.second.first); } update_mutex.unlock(); - DEBUG("end"); + JDEBUG("end"); } void Directories::select(const boost::filesystem::path &path) { - DEBUG("start"); + JDEBUG("start"); if(current_path=="") return; @@ -196,7 +196,7 @@ void Directories::select(const boost::filesystem::path &path) { } return false; }); - DEBUG("end"); + JDEBUG("end"); } bool Directories::ignored(std::string path) { diff --git a/src/juci.cc b/src/juci.cc index c83eb47..c4164bc 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -9,7 +9,7 @@ void init_logging() { boost::log::add_common_attributes(); boost::log::add_file_log(boost::log::keywords::file_name = Singleton::log_dir() + "juci.log", boost::log::keywords::auto_flush = true); - INFO("Logging initalized"); + JINFO("Logging initalized"); } int app::on_command_line(const Glib::RefPtr &cmd) { diff --git a/src/logging.h b/src/logging.h index fbd9f89..7fd780b 100644 --- a/src/logging.h +++ b/src/logging.h @@ -15,12 +15,12 @@ #define INFO_VAR(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define WARNING_VAR(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; #define FATAL_VAR(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; -#define ERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; -#define TRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define DEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define INFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define WARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define FATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; -#define ERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JERROR_VAR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): " << #x << "=<" << x << ">"; +#define JTRACE(x) BOOST_LOG_TRIVIAL(trace) << "** Trace: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JDEBUG(x) BOOST_LOG_TRIVIAL(debug) << "** Debug: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JINFO(x) BOOST_LOG_TRIVIAL(info) << "** Info: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JWARNING(x) BOOST_LOG_TRIVIAL(warning) << "** Warning: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JFATAL(x) BOOST_LOG_TRIVIAL(fatal) << "** Fatal: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; +#define JERROR(x) BOOST_LOG_TRIVIAL(error) << "** Error: " << __FILE__ << "@" << __func__ << "(" << __LINE__ << "): \"" << x << "\""; #endif // JUCI_LOGGING_H_ diff --git a/src/notebook.cc b/src/notebook.cc index 40b9874..041f8c1 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -48,7 +48,7 @@ Source::View* Notebook::get_current_view() { } void Notebook::open(const boost::filesystem::path &file_path) { - DEBUG("start"); + JDEBUG("start"); for(int c=0;cfile_path) { set_current_page(c); @@ -124,13 +124,13 @@ void Notebook::open(const boost::filesystem::path &file_path) { set_tab_label_text(*(get_nth_page(page)), title); }); - DEBUG("end"); + JDEBUG("end"); } bool Notebook::save(int page, bool reparse_needed) { - DEBUG("start"); + JDEBUG("start"); if(page>=size()) { - DEBUG("end false"); + JDEBUG("end false"); return false; } auto view=get_view(page); @@ -166,12 +166,12 @@ bool Notebook::save(int page, bool reparse_needed) { } } } - DEBUG("end true"); + JDEBUG("end true"); return true; } Singleton::terminal()->print("Error: could not save file " +view->file_path.string()+"\n"); } - DEBUG("end false"); + JDEBUG("end false"); return false; } @@ -182,11 +182,11 @@ bool Notebook::save_current() { } bool Notebook::close_current_page() { - DEBUG("start"); + JDEBUG("start"); if (get_current_page()!=-1) { if(get_current_view()->get_buffer()->get_modified()){ if(!save_modified_dialog()) { - DEBUG("end false"); + JDEBUG("end false"); return false; } } @@ -202,7 +202,7 @@ bool Notebook::close_current_page() { scrolled_windows.erase(scrolled_windows.begin()+index); hboxes.erase(hboxes.begin()+index); } - DEBUG("end true"); + JDEBUG("end true"); return true; } diff --git a/src/source.cc b/src/source.cc index 98cb8ff..b25a30c 100644 --- a/src/source.cc +++ b/src/source.cc @@ -972,7 +972,7 @@ clang::Index Source::ClangViewParse::clang_index(0, 0); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language): Source::View(file_path, language), project_path(project_path), parse_error(false) { - DEBUG("start"); + JDEBUG("start"); auto scheme = get_source_buffer()->get_style_scheme(); auto tag_table=get_buffer()->get_tag_table(); for (auto &item : Singleton::Config::source()->clang_types) { @@ -991,7 +991,7 @@ Source::View(file_path, language), project_path(project_path), parse_error(false // // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background(); // // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); } else - INFO("Style " + item.second + " not found in " + scheme->get_name()); + JINFO("Style " + item.second + " not found in " + scheme->get_name()); } } @@ -1039,7 +1039,7 @@ Source::View(file_path, language), project_path(project_path), parse_error(false bracket_regex=std::regex(std::string("^(")+tab_char+"*).*\\{ *$"); no_bracket_statement_regex=std::regex(std::string("^(")+tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); no_bracket_no_para_statement_regex=std::regex(std::string("^(")+tab_char+"*)(else|try|do) *$"); - DEBUG("end"); + JDEBUG("end"); } Source::ClangViewParse::~ClangViewParse() { diff --git a/src/terminal.cc b/src/terminal.cc index eb96fcf..7cee28b 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -154,7 +154,7 @@ Terminal::Terminal() { } int Terminal::execute(const std::string &command, const boost::filesystem::path &path) { - DEBUG("start"); + JDEBUG("start"); int stdin_fd, stdout_fd, stderr_fd; auto pid=popen3(command, path.string(), &stdin_fd, &stdout_fd, &stderr_fd); @@ -192,14 +192,14 @@ int Terminal::execute(const std::string &command, const boost::filesystem::path close(stdout_fd); close(stderr_fd); - DEBUG("end"); + JDEBUG("end"); return exit_code; } } void Terminal::async_execute(const std::string &command, const boost::filesystem::path &path, std::function callback) { std::thread async_execute_thread([this, command, path, callback](){ - DEBUG("start"); + JDEBUG("start"); int stdin_fd, stdout_fd, stderr_fd; async_executes_mutex.lock(); stdin_buffer.clear(); @@ -254,7 +254,7 @@ void Terminal::async_execute(const std::string &command, const boost::filesystem if(callback) callback(exit_code); - DEBUG("end"); + JDEBUG("end"); } }); async_execute_thread.detach(); diff --git a/src/terminal_win.cc b/src/terminal_win.cc index e79014d..8cd9238 100644 --- a/src/terminal_win.cc +++ b/src/terminal_win.cc @@ -332,7 +332,7 @@ void Terminal::kill_async_executes(bool force) { } int Terminal::print(const std::string &message, bool bold){ - INFO("Terminal: PrintMessage"); + JINFO("Terminal: PrintMessage"); if(bold) get_buffer()->insert_with_tag(get_buffer()->end(), message, bold_tag); else @@ -349,7 +349,7 @@ int Terminal::print(const std::string &message, bool bold){ } void Terminal::print(int line_nr, const std::string &message){ - INFO("Terminal: PrintMessage at line " << line_nr); + JINFO("Terminal: PrintMessage at line " << line_nr); auto iter=get_buffer()->get_iter_at_line(line_nr); while(!iter.ends_line()) iter++; diff --git a/src/window.cc b/src/window.cc index 0daf779..8ac72a6 100644 --- a/src/window.cc +++ b/src/window.cc @@ -32,7 +32,7 @@ void Window::generate_keybindings() { } Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::directories()), compiling(false) { - DEBUG("start"); + JDEBUG("start"); set_title("juCi++"); set_default_size(600, 400); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); @@ -133,7 +133,7 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::director about.set_comments("This is an open source IDE with high-end features to make your programming experience juicy"); about.set_license_type(Gtk::License::LICENSE_MIT_X11); about.set_transient_for(*this); - DEBUG("end"); + JDEBUG("end"); } // Window constructor void Window::create_menu() { From f9269690cb31cd3b315cc8000d5c706d27be7311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 21 Sep 2015 19:56:04 +0200 Subject: [PATCH 6/7] Create enum for options --- src/dialogs_win.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index acf03bd..e6ab2fc 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -57,22 +57,31 @@ class CommonDialog { DWORD options; }; +enum FILEOPENOPTIONS { + OVERWRITEPROMPT = 0x2, STRICTFILETYPES = 0x4, NOCHANGEDIR = 0x8, PICKFOLDERS = 0x20, + FORCEFILESYSTEM = 0x40, ALLNONSTORAGEITEMS = 0x80, NOVALIDATE = 0x100, ALLOWMULTISELECT = 0x200, + PATHMUSTEXIST = 0x800, FILEMUSTEXIST = 0x1000, CREATEPROMPT = 0x2000, SHAREAWARE = 0x4000, + NOREADONLYRETURN = 0x8000, NOTESTFILECREATE = 0x10000, HIDEMRUPLACES = 0x20000, + HIDEPINNEDPLACES = 0x40000, NODEREFERENCELINKS = 0x100000, DONTADDTORECENT = 0x2000000, + FORCESHOWHIDDEN = 0x10000000, DEFAULTNOMINIMODE = 0x20000000, FORCEPREVIEWPANEON = 0x40000000 +}; + std::string Dialog::select_folder() { - return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); + return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); } std::string Dialog::new_file() { - return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); + return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); } std::string Dialog::new_folder() { - return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); + return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); } std::string Dialog::select_file() { - return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); + return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); } std::string Dialog::save_file() { - return (CommonDialog("Please select a folder", FOS_PICKFOLDERS)).show(); + return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); } \ No newline at end of file From 893ebe79bf501ada8e4e073bc1b671ce6ddb27ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 28 Sep 2015 22:42:55 +0200 Subject: [PATCH 7/7] Better fault toleranse when exitin dialogs unusually --- src/CMakeLists.txt | 6 ++-- src/dialogs.cc | 2 +- src/dialogs_win.cc | 77 ++++------------------------------------------ src/singletons.h | 6 ++-- src/window.cc | 26 +++++++++++----- 5 files changed, 33 insertions(+), 84 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7bf09cc..db08352 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,7 +88,6 @@ set(source_files juci.h tooltips.cc singletons.h singletons.cc - dialogs.h cmake.h cmake.cc) @@ -98,6 +97,7 @@ if(MSYS) message("MSYS detected") else() list(APPEND source_files terminal.cc) + list(APPEND source_files dialogs.h) list(APPEND source_files dialogs.cc) message("UNIX detected") endif() @@ -115,6 +115,7 @@ if(${validation}) ${GTKMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS} ${LCL_INCLUDE_DIRS} + "C:/msys64/mingw64/include/dialogs" ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR}) @@ -124,6 +125,7 @@ if(${validation}) ${Boost_LIBRARY_DIRS} # ${PYTHON_INCLUDE_DIRS} ${LCL_LIBRARY_DIRS} + C:/msys64/mingw64/bin ${LIBCLANG_LIBRARY_DIRS}) # set_target_properties(${module} @@ -132,11 +134,11 @@ if(${validation}) # target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) # target_link_libraries(${module} ${Boost_LIBRARIES}) - target_link_libraries(${project_name} ${LIBCLANG_LIBRARIES} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} + "C:/msys64/mingw64/bin/libdialogs.dll" ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} ${ASPELL_LIBRARIES} diff --git a/src/dialogs.cc b/src/dialogs.cc index 8ff3882..e1e424f 100644 --- a/src/dialogs.cc +++ b/src/dialogs.cc @@ -1,4 +1,4 @@ -#include "dialogs.h" +#include #include "singletons.h" #include #include diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index e6ab2fc..24133b1 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -1,87 +1,22 @@ #include "dialogs.h" -#include -#include -#include -#include -#include "singletons.h" -#include - -#ifndef check -#define MESSAGE "An error occurred when trying open windows dialog" -HRESULT __hr__; -#define check(__fun__) __hr__ = __fun__; if(FAILED(__hr__)) Singleton::terminal()->print(MESSAGE) -#endif - -class win_string { - public: - win_string() : str(nullptr) { } - ~win_string() { CoTaskMemFree(static_cast(str)); } - std::string operator()(){ - std::string res; - if (str != nullptr) { - std::wstringstream ss; - ss << str; - res = std::string(ss.str().begin(), ss.str().end()); - } - return res; - } - wchar_t** operator&() { return &str; } - private: - wchar_t* str; -}; - -class CommonDialog { - public: - CommonDialog() : dialog(nullptr) { - check(CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&dialog))); - check(dialog->GetOptions(&options)); - } - CommonDialog(const std::string &title, unsigned option) : CommonDialog() { - set_title(title); - add_option(option); - } - void set_title(const std::string &title) { check(dialog->SetTitle(title)); } - void add_option(unsigned option) { check(dialog->SetOptions(options | option)); } - std::string show() { - check(dialog->Show(nullptr)); - IShellItem *result = nullptr; - check(dialog->GetResult(&result)); - win_string str; - check(result->GetDisplayName(SIGDN_FILESYSPATH, &str));; - result->Release(); - return str(); - } - - private: - IFileOpenDialog * dialog; - DWORD options; -}; - -enum FILEOPENOPTIONS { - OVERWRITEPROMPT = 0x2, STRICTFILETYPES = 0x4, NOCHANGEDIR = 0x8, PICKFOLDERS = 0x20, - FORCEFILESYSTEM = 0x40, ALLNONSTORAGEITEMS = 0x80, NOVALIDATE = 0x100, ALLOWMULTISELECT = 0x200, - PATHMUSTEXIST = 0x800, FILEMUSTEXIST = 0x1000, CREATEPROMPT = 0x2000, SHAREAWARE = 0x4000, - NOREADONLYRETURN = 0x8000, NOTESTFILECREATE = 0x10000, HIDEMRUPLACES = 0x20000, - HIDEPINNEDPLACES = 0x40000, NODEREFERENCELINKS = 0x100000, DONTADDTORECENT = 0x2000000, - FORCESHOWHIDDEN = 0x10000000, DEFAULTNOMINIMODE = 0x20000000, FORCEPREVIEWPANEON = 0x40000000 -}; +#include std::string Dialog::select_folder() { - return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); + return c_select_folder(); } std::string Dialog::new_file() { - return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); + return c_new_file(); } std::string Dialog::new_folder() { - return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); + return c_new_folder(); } std::string Dialog::select_file() { - return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); + return c_select_file(); } std::string Dialog::save_file() { - return (CommonDialog("Please select a folder", PICKFOLDERS)).show(); + return c_save_file(); } \ No newline at end of file diff --git a/src/singletons.h b/src/singletons.h index 33297ea..f4fc2be 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -26,9 +26,9 @@ public: static std::unique_ptr directories_; static std::unique_ptr terminal_; }; - static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } - static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } - static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } + static std::string config_dir() { return std::string(getenv("AppData")) + "/.juci/config/"; } + static std::string log_dir() { return std::string(getenv("AppData")) + "/.juci/log/"; } + static std::string style_dir() { return std::string(getenv("AppData")) + "/.juci/styles/"; } static Terminal *terminal(); static Directories *directories(); static Gtk::Label *status(); diff --git a/src/window.cc b/src/window.cc index 8ac72a6..7eeef82 100644 --- a/src/window.cc +++ b/src/window.cc @@ -38,6 +38,10 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(*Singleton::director set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); add(box); + auto i = Gtk::IconTheme::get_default(); + for (auto &c : i->get_search_path()) + Singleton::terminal()->print(c + "\n"); + generate_keybindings(); //PluginApi(&this->notebook, &this->menu); create_menu(); @@ -161,13 +165,17 @@ void Window::create_menu() { menu.action_group->add(Gtk::Action::create("FileNewFolder", "New Folder"), Gtk::AccelKey(menu.key_map["new_folder"]), [this]() { auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); boost::filesystem::path path = Dialog::new_folder(); - if(boost::filesystem::last_write_time(path)>=time_now) { - if(Singleton::directories()->current_path!="") - Singleton::directories()->update(); - Singleton::terminal()->print("New folder "+path.string()+" created.\n"); + if(boost::filesystem::exists(path)) { + if(boost::filesystem::last_write_time(path)>=time_now) { + if(Singleton::directories()->current_path!="") + Singleton::directories()->update(); + Singleton::terminal()->print("New folder "+path.string()+" created.\n"); + } + else + Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); + } else { + Singleton::terminal()->print("Cancel \n"); } - else - Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); Singleton::directories()->select(path); }); menu.action_group->add(Gtk::Action::create("FileNewProject", "New Project")); @@ -204,7 +212,11 @@ void Window::create_menu() { notebook.open(Dialog::select_file()); }); menu.action_group->add(Gtk::Action::create("FileOpenFolder", "Open Folder"), Gtk::AccelKey(menu.key_map["open_folder"]), [this]() { - Singleton::directories()->open(Dialog::select_folder()); + auto path = Dialog::select_folder(); + if (boost::filesystem::exists(path)) + Singleton::directories()->open(path); + else + Singleton::terminal()->print("Cancel \n"); }); menu.action_group->add(Gtk::Action::create("FileSaveAs", "Save As"), Gtk::AccelKey(menu.key_map["save_as"]), [this]() { auto path = Dialog::save_file();