diff --git a/src/dialogs.h b/src/dialogs.h index f5e4b0c..02fa700 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -21,19 +21,21 @@ private: 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::cast_static(gio_application); dialog.set_transient_for(*application->window); + auto current_path=application->window->notebook.get_current_path(); + 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() : ""; diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index 2c0a19b..b2f3ba1 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -29,8 +29,7 @@ public: if(!set_title(title) || !add_option(option)) return ""; - auto dirs = Singleton::directories->current_path; - if(!set_folder(dirs.empty() ? boost::filesystem::current_path().native() : dirs.native())) + if(!set_folder()) return ""; return show(); @@ -42,10 +41,10 @@ public: if(!set_title(title) || !add_option(option)) return ""; + if(!set_folder()) + return ""; std::vector extensions; if(!file_path.empty()) { - if(!set_folder(file_path.parent_path().native())) - return ""; if(file_path.has_extension() && file_path.filename()!=file_path.extension()) { auto extension=(L"*"+file_path.extension().native()).c_str(); extensions.emplace_back(COMDLG_FILTERSPEC{extension, extension}); @@ -53,11 +52,6 @@ public: return ""; } } - else { - auto dirs = Singleton::directories->current_path; - if(!set_folder(dirs.empty() ? boost::filesystem::current_path().native() : dirs.native())) - return ""; - } extensions.emplace_back(COMDLG_FILTERSPEC{L"All files", L"*.*"}); if(dialog->SetFileTypes(extensions.size(), extensions.data())!=S_OK) return ""; @@ -98,8 +92,16 @@ private: } /** Sets the directory to start browsing */ - bool set_folder(const std::wstring &directory_path) { - std::wstring path=directory_path; + bool set_folder() { + 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); + + auto current_path=application->window->notebook.get_current_path(); + if(current_path.empty()) + current_path=boost::filesystem::current_path(); + + std::wstring path=current_path.native(); size_t pos=0; while((pos=path.find(L'/', pos))!=std::wstring::npos) {//TODO: issue bug report on boost::filesystem::path::native on MSYS2 path.replace(pos, 1, L"\\"); diff --git a/src/notebook.cc b/src/notebook.cc index 74d9107..441f9e0 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -262,6 +262,17 @@ bool Notebook::close_current_page() { return true; } +boost::filesystem::path Notebook::get_current_path() { + boost::filesystem::path current_path; + + if(get_current_page()!=-1) + current_path=get_current_view()->project_path; + else + current_path=Singleton::directories->current_path; + + return current_path; +} + bool Notebook::save_modified_dialog() { Gtk::MessageDialog dialog((Gtk::Window&)(*get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); dialog.set_default_response(Gtk::RESPONSE_YES); diff --git a/src/notebook.h b/src/notebook.h index abb70c7..91840b6 100644 --- a/src/notebook.h +++ b/src/notebook.h @@ -21,6 +21,7 @@ public: bool save(int page, bool reparse_needed=false); bool save_current(); void configure(int view_nr); + boost::filesystem::path get_current_path(); private: bool save_modified_dialog(); diff --git a/src/window.cc b/src/window.cc index 1ad2711..4a9446f 100644 --- a/src/window.cc +++ b/src/window.cc @@ -489,21 +489,13 @@ void Window::set_menu_actions() { entry_box.labels.emplace_back(); auto label_it=entry_box.labels.begin(); label_it->update=[label_it](int state, const std::string& message){ - label_it->set_text("Run Command directory order: file project path, file directory, opened directory, current directory"); + label_it->set_text("Run Command directory order: file project path, opened directory, current directory"); }; label_it->update(0, ""); entry_box.entries.emplace_back(last_run_command, [this](const std::string& content){ if(content!="") { last_run_command=content; - boost::filesystem::path run_path; - if(notebook.get_current_page()!=-1) { - if(notebook.get_current_view()->project_path!="") - run_path=notebook.get_current_view()->project_path; - else - run_path=notebook.get_current_view()->file_path.parent_path(); - } - else - run_path=Singleton::directories->current_path; + auto run_path=notebook.get_current_path(); Singleton::terminal->async_print("Running: "+content+'\n'); Singleton::terminal->async_execute(content, run_path, [this, content](int exit_code){