Browse Source

Improved and consistant default directory handling for run command and dialogs.

merge-requests/365/head
eidheim 10 years ago
parent
commit
a288ce37cb
  1. 16
      src/dialogs.h
  2. 24
      src/dialogs_win.cc
  3. 11
      src/notebook.cc
  4. 1
      src/notebook.h
  5. 12
      src/window.cc

16
src/dialogs.h

@ -21,19 +21,21 @@ private:
Gtk::FileChooserAction gtk_options, Gtk::FileChooserAction gtk_options,
const std::string &file_name = "") { const std::string &file_name = "") {
Gtk::FileChooserDialog dialog(title, gtk_options); 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 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 gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::cast_static(gio_application); auto application=Glib::RefPtr<Application>::cast_static(gio_application);
dialog.set_transient_for(*application->window); 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) for (auto &button : buttons)
dialog.add_button(button.first, button.second); dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";

24
src/dialogs_win.cc

@ -29,8 +29,7 @@ public:
if(!set_title(title) || !add_option(option)) if(!set_title(title) || !add_option(option))
return ""; return "";
auto dirs = Singleton::directories->current_path; if(!set_folder())
if(!set_folder(dirs.empty() ? boost::filesystem::current_path().native() : dirs.native()))
return ""; return "";
return show(); return show();
@ -42,10 +41,10 @@ public:
if(!set_title(title) || !add_option(option)) if(!set_title(title) || !add_option(option))
return ""; return "";
if(!set_folder())
return "";
std::vector<COMDLG_FILTERSPEC> extensions; std::vector<COMDLG_FILTERSPEC> extensions;
if(!file_path.empty()) { if(!file_path.empty()) {
if(!set_folder(file_path.parent_path().native()))
return "";
if(file_path.has_extension() && file_path.filename()!=file_path.extension()) { if(file_path.has_extension() && file_path.filename()!=file_path.extension()) {
auto extension=(L"*"+file_path.extension().native()).c_str(); auto extension=(L"*"+file_path.extension().native()).c_str();
extensions.emplace_back(COMDLG_FILTERSPEC{extension, extension}); extensions.emplace_back(COMDLG_FILTERSPEC{extension, extension});
@ -53,11 +52,6 @@ public:
return ""; 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"*.*"}); extensions.emplace_back(COMDLG_FILTERSPEC{L"All files", L"*.*"});
if(dialog->SetFileTypes(extensions.size(), extensions.data())!=S_OK) if(dialog->SetFileTypes(extensions.size(), extensions.data())!=S_OK)
return ""; return "";
@ -98,8 +92,16 @@ private:
} }
/** Sets the directory to start browsing */ /** Sets the directory to start browsing */
bool set_folder(const std::wstring &directory_path) { bool set_folder() {
std::wstring path=directory_path; 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);
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; size_t pos=0;
while((pos=path.find(L'/', pos))!=std::wstring::npos) {//TODO: issue bug report on boost::filesystem::path::native on MSYS2 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"\\"); path.replace(pos, 1, L"\\");

11
src/notebook.cc

@ -262,6 +262,17 @@ bool Notebook::close_current_page() {
return true; 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() { bool Notebook::save_modified_dialog() {
Gtk::MessageDialog dialog((Gtk::Window&)(*get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::MessageDialog dialog((Gtk::Window&)(*get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_default_response(Gtk::RESPONSE_YES);

1
src/notebook.h

@ -21,6 +21,7 @@ public:
bool save(int page, bool reparse_needed=false); bool save(int page, bool reparse_needed=false);
bool save_current(); bool save_current();
void configure(int view_nr); void configure(int view_nr);
boost::filesystem::path get_current_path();
private: private:
bool save_modified_dialog(); bool save_modified_dialog();

12
src/window.cc

@ -489,21 +489,13 @@ void Window::set_menu_actions() {
entry_box.labels.emplace_back(); entry_box.labels.emplace_back();
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
label_it->update=[label_it](int state, const std::string& message){ 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, ""); label_it->update(0, "");
entry_box.entries.emplace_back(last_run_command, [this](const std::string& content){ entry_box.entries.emplace_back(last_run_command, [this](const std::string& content){
if(content!="") { if(content!="") {
last_run_command=content; last_run_command=content;
boost::filesystem::path run_path; auto run_path=notebook.get_current_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;
Singleton::terminal->async_print("Running: "+content+'\n'); Singleton::terminal->async_print("Running: "+content+'\n');
Singleton::terminal->async_execute(content, run_path, [this, content](int exit_code){ Singleton::terminal->async_execute(content, run_path, [this, content](int exit_code){

Loading…
Cancel
Save