adds a "New Folder" button to file_dialog
This commit is contained in:
parent
096c6cb724
commit
9c381da3a6
5 changed files with 33 additions and 11 deletions
|
@ -51,8 +51,8 @@ file_dialog::file_dialog(display &disp, const std::string& file_path, const std:
|
|||
set_textbox(_("File: "), format_filename(file_path), 100);
|
||||
add_button( new gui::dialog_button(disp.video(), _("Delete File"),
|
||||
gui::button::TYPE_PRESS, gui::DELETE_ITEM), dialog::BUTTON_EXTRA);
|
||||
// add_button( new gui::dialog_button(disp.video(), _("New Folder"),
|
||||
// gui::button::TYPE_PRESS, gui::CREATE_ITEM), dialog::BUTTON_CHECKBOX_LEFT);
|
||||
add_button( new gui::dialog_button(disp.video(), _("New Folder"),
|
||||
gui::button::TYPE_PRESS, gui::CREATE_ITEM), dialog::BUTTON_CHECKBOX_LEFT);
|
||||
}
|
||||
|
||||
gui::dialog::dimension_measurements file_dialog::layout(int xloc, int yloc) const
|
||||
|
@ -153,12 +153,31 @@ void file_dialog::action(gui::dialog_process_info &dp_info) {
|
|||
if(files_list_->delete_chosen_file() == -1) {
|
||||
gui::dialog d(get_display(), "", _("Deletion of the file failed."), gui::OK_ONLY);
|
||||
d.show();
|
||||
dp_info.clear_buttons();
|
||||
} else {
|
||||
dp_info.first_time = true;
|
||||
}
|
||||
}
|
||||
set_result(gui::CONTINUE_DIALOG);
|
||||
}
|
||||
//handle "create item" requests
|
||||
else if(result() == gui::CREATE_ITEM)
|
||||
{
|
||||
gui::dialog d(get_display(), _("New Folder"), "", gui::OK_CANCEL);
|
||||
d.set_textbox(_("Name: "));
|
||||
d.show();
|
||||
if(d.result() != gui::CLOSE_DIALOG && !d.textbox_text().empty())
|
||||
{
|
||||
if( !files_list_->make_directory(d.textbox_text()) ) {
|
||||
gui::dialog d2(get_display(), "", _("Creation of the directory failed."), gui::OK_ONLY);
|
||||
d2.show();
|
||||
} else {
|
||||
dp_info.first_time = true;
|
||||
}
|
||||
}
|
||||
dp_info.clear_buttons();
|
||||
set_result(gui::CONTINUE_DIALOG);
|
||||
}
|
||||
|
||||
//update the chosen file
|
||||
if(dp_info.selection != last_selection_
|
||||
|
|
|
@ -337,13 +337,15 @@ std::string get_dir(const std::string& dir_path)
|
|||
return dir_path;
|
||||
}
|
||||
|
||||
void make_directory(const std::string& path)
|
||||
bool make_directory(const std::string& path)
|
||||
{
|
||||
bool ret = true;
|
||||
#ifdef _WIN32
|
||||
_mkdir(path.c_str());
|
||||
ret = (_mkdir(path.c_str()) == 0);
|
||||
#else
|
||||
mkdir(path.c_str(),AccessMode);
|
||||
ret = (mkdir(path.c_str(),AccessMode) == 0);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
//this deletes a directory with no hidden files and subdirectories
|
||||
|
|
|
@ -56,7 +56,7 @@ std::string get_user_data_dir();
|
|||
|
||||
std::string get_cwd();
|
||||
|
||||
void make_directory(const std::string& dirname);
|
||||
bool make_directory(const std::string& dirname);
|
||||
bool delete_directory(const std::string& dirname);
|
||||
|
||||
//basic disk I/O
|
||||
|
|
|
@ -97,10 +97,10 @@ int file_menu::delete_chosen_file() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*void file_menu::make_directory() {
|
||||
::make_directory(chosen_file_);
|
||||
if (ret == -1) {
|
||||
// show_dialog(disp_, NULL, "", _("Deletion of the file failed."), OK_ONLY);
|
||||
bool file_menu::make_directory(const std::string& subdir_name) {
|
||||
bool ret = ::make_directory(add_path(current_dir_, subdir_name));
|
||||
if (ret == false) {
|
||||
// show_dialog(disp_, NULL, "", _("Creation of the directory failed."), OK_ONLY);
|
||||
}
|
||||
else {
|
||||
last_selection_ = -1;
|
||||
|
@ -108,7 +108,7 @@ int file_menu::delete_chosen_file() {
|
|||
chosen_file_ = current_dir_;
|
||||
}
|
||||
return ret;
|
||||
}*/
|
||||
}
|
||||
|
||||
void file_menu::handle_event(const SDL_Event& event) {
|
||||
menu::handle_event(event);
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
bool is_directory(const std::string& fname) const;
|
||||
|
||||
void change_directory(const std::string path);
|
||||
bool make_directory(const std::string& subdir_name);
|
||||
|
||||
protected:
|
||||
void handle_event(const SDL_Event& event);
|
||||
|
|
Loading…
Add table
Reference in a new issue