summaryrefslogtreecommitdiff
path: root/scene/gui/file_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/file_dialog.cpp')
-rw-r--r--scene/gui/file_dialog.cpp135
1 files changed, 69 insertions, 66 deletions
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 6b43425edc..393f14bee2 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -164,7 +164,7 @@ void FileDialog::_action_pressed() {
TreeItem *ti=tree->get_next_selected(NULL);
String fbase=dir_access->get_current_dir();
- DVector<String> files;
+ PoolVector<String> files;
while(ti) {
files.push_back( fbase.plus_file(ti->get_text(0)) );
@@ -186,15 +186,17 @@ void FileDialog::_action_pressed() {
hide();
}else if (mode==MODE_OPEN_ANY || mode==MODE_OPEN_DIR) {
-
String path=dir_access->get_current_dir();
- /*if (tree->get_selected()) {
- Dictionary d = tree->get_selected()->get_metadata(0);
+
+ path=path.replace("\\","/");
+
+ if (TreeItem* item = tree->get_selected()) {
+ Dictionary d = item->get_metadata(0);
if (d["dir"]) {
- path=path+"/"+String(d["name"]);
+ path=path.plus_file(d["name"]);
}
- }*/
- path=path.replace("\\","/");
+ }
+
emit_signal("dir_selected",path);
hide();
}
@@ -348,18 +350,18 @@ void FileDialog::update_file_list() {
files.sort_custom<NoCaseComparator>();
while(!dirs.empty()) {
+ String& dir_name = dirs.front()->get();
+ TreeItem *ti=tree->create_item(root);
+ ti->set_text(0,dir_name+"/");
+ ti->set_icon(0,folder);
- if (dirs.front()->get()!=".") {
- TreeItem *ti=tree->create_item(root);
- ti->set_text(0,dirs.front()->get()+"/");
- ti->set_icon(0,folder);
- Dictionary d;
- d["name"]=dirs.front()->get();
- d["dir"]=true;
- ti->set_metadata(0,d);
- }
- dirs.pop_front();
+ Dictionary d;
+ d["name"]=dir_name;
+ d["dir"]=true;
+
+ ti->set_metadata(0,d);
+ dirs.pop_front();
}
dirs.clear();
@@ -401,11 +403,12 @@ void FileDialog::update_file_list() {
while(!files.empty()) {
bool match=patterns.empty();
+ String match_str;
for(List<String>::Element *E=patterns.front();E;E=E->next()) {
if (files.front()->get().matchn(E->get())) {
-
+ match_str=E->get();
match=true;
break;
}
@@ -430,14 +433,14 @@ void FileDialog::update_file_list() {
d["dir"]=false;
ti->set_metadata(0,d);
- if (file->get_text()==files.front()->get())
+ if (file->get_text()==files.front()->get() || match_str==files.front()->get())
ti->select(0);
}
files.pop_front();
}
- if (tree->get_root() && tree->get_root()->get_children())
+ if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected()==NULL)
tree->get_root()->get_children()->select(0);
files.clear();
@@ -612,7 +615,7 @@ void FileDialog::set_access(Access p_access) {
void FileDialog::invalidate() {
- if (is_visible()) {
+ if (is_visible_in_tree()) {
update_file_list();
invalidated=false;
} else {
@@ -683,44 +686,44 @@ bool FileDialog::default_show_hidden_files=false;
void FileDialog::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("_unhandled_input"),&FileDialog::_unhandled_input);
-
- ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected);
- ObjectTypeDB::bind_method(_MD("_tree_db_selected"),&FileDialog::_tree_dc_selected);
- ObjectTypeDB::bind_method(_MD("_dir_entered"),&FileDialog::_dir_entered);
- ObjectTypeDB::bind_method(_MD("_file_entered"),&FileDialog::_file_entered);
- ObjectTypeDB::bind_method(_MD("_action_pressed"),&FileDialog::_action_pressed);
- ObjectTypeDB::bind_method(_MD("_cancel_pressed"),&FileDialog::_cancel_pressed);
- ObjectTypeDB::bind_method(_MD("_filter_selected"),&FileDialog::_filter_selected);
- ObjectTypeDB::bind_method(_MD("_save_confirm_pressed"),&FileDialog::_save_confirm_pressed);
-
- ObjectTypeDB::bind_method(_MD("clear_filters"),&FileDialog::clear_filters);
- ObjectTypeDB::bind_method(_MD("add_filter","filter"),&FileDialog::add_filter);
- ObjectTypeDB::bind_method(_MD("set_filters","filters"),&FileDialog::set_filters);
- ObjectTypeDB::bind_method(_MD("get_filters"),&FileDialog::get_filters);
- ObjectTypeDB::bind_method(_MD("get_current_dir"),&FileDialog::get_current_dir);
- ObjectTypeDB::bind_method(_MD("get_current_file"),&FileDialog::get_current_file);
- ObjectTypeDB::bind_method(_MD("get_current_path"),&FileDialog::get_current_path);
- ObjectTypeDB::bind_method(_MD("set_current_dir","dir"),&FileDialog::set_current_dir);
- ObjectTypeDB::bind_method(_MD("set_current_file","file"),&FileDialog::set_current_file);
- ObjectTypeDB::bind_method(_MD("set_current_path","path"),&FileDialog::set_current_path);
- ObjectTypeDB::bind_method(_MD("set_mode","mode"),&FileDialog::set_mode);
- ObjectTypeDB::bind_method(_MD("get_mode"),&FileDialog::get_mode);
- ObjectTypeDB::bind_method(_MD("get_vbox:VBoxContainer"),&FileDialog::get_vbox);
- ObjectTypeDB::bind_method(_MD("set_access","access"),&FileDialog::set_access);
- ObjectTypeDB::bind_method(_MD("get_access"),&FileDialog::get_access);
- ObjectTypeDB::bind_method(_MD("set_show_hidden_files","show"),&FileDialog::set_show_hidden_files);
- ObjectTypeDB::bind_method(_MD("is_showing_hidden_files"),&FileDialog::is_showing_hidden_files);
- ObjectTypeDB::bind_method(_MD("_select_drive"),&FileDialog::_select_drive);
- ObjectTypeDB::bind_method(_MD("_make_dir"),&FileDialog::_make_dir);
- ObjectTypeDB::bind_method(_MD("_make_dir_confirm"),&FileDialog::_make_dir_confirm);
- ObjectTypeDB::bind_method(_MD("_update_file_list"),&FileDialog::update_file_list);
- ObjectTypeDB::bind_method(_MD("_update_dir"),&FileDialog::update_dir);
-
- ObjectTypeDB::bind_method(_MD("invalidate"),&FileDialog::invalidate);
+ ClassDB::bind_method(_MD("_unhandled_input"),&FileDialog::_unhandled_input);
+
+ ClassDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected);
+ ClassDB::bind_method(_MD("_tree_db_selected"),&FileDialog::_tree_dc_selected);
+ ClassDB::bind_method(_MD("_dir_entered"),&FileDialog::_dir_entered);
+ ClassDB::bind_method(_MD("_file_entered"),&FileDialog::_file_entered);
+ ClassDB::bind_method(_MD("_action_pressed"),&FileDialog::_action_pressed);
+ ClassDB::bind_method(_MD("_cancel_pressed"),&FileDialog::_cancel_pressed);
+ ClassDB::bind_method(_MD("_filter_selected"),&FileDialog::_filter_selected);
+ ClassDB::bind_method(_MD("_save_confirm_pressed"),&FileDialog::_save_confirm_pressed);
+
+ ClassDB::bind_method(_MD("clear_filters"),&FileDialog::clear_filters);
+ ClassDB::bind_method(_MD("add_filter","filter"),&FileDialog::add_filter);
+ ClassDB::bind_method(_MD("set_filters","filters"),&FileDialog::set_filters);
+ ClassDB::bind_method(_MD("get_filters"),&FileDialog::get_filters);
+ ClassDB::bind_method(_MD("get_current_dir"),&FileDialog::get_current_dir);
+ ClassDB::bind_method(_MD("get_current_file"),&FileDialog::get_current_file);
+ ClassDB::bind_method(_MD("get_current_path"),&FileDialog::get_current_path);
+ ClassDB::bind_method(_MD("set_current_dir","dir"),&FileDialog::set_current_dir);
+ ClassDB::bind_method(_MD("set_current_file","file"),&FileDialog::set_current_file);
+ ClassDB::bind_method(_MD("set_current_path","path"),&FileDialog::set_current_path);
+ ClassDB::bind_method(_MD("set_mode","mode"),&FileDialog::set_mode);
+ ClassDB::bind_method(_MD("get_mode"),&FileDialog::get_mode);
+ ClassDB::bind_method(_MD("get_vbox:VBoxContainer"),&FileDialog::get_vbox);
+ ClassDB::bind_method(_MD("set_access","access"),&FileDialog::set_access);
+ ClassDB::bind_method(_MD("get_access"),&FileDialog::get_access);
+ ClassDB::bind_method(_MD("set_show_hidden_files","show"),&FileDialog::set_show_hidden_files);
+ ClassDB::bind_method(_MD("is_showing_hidden_files"),&FileDialog::is_showing_hidden_files);
+ ClassDB::bind_method(_MD("_select_drive"),&FileDialog::_select_drive);
+ ClassDB::bind_method(_MD("_make_dir"),&FileDialog::_make_dir);
+ ClassDB::bind_method(_MD("_make_dir_confirm"),&FileDialog::_make_dir_confirm);
+ ClassDB::bind_method(_MD("_update_file_list"),&FileDialog::update_file_list);
+ ClassDB::bind_method(_MD("_update_dir"),&FileDialog::update_dir);
+
+ ClassDB::bind_method(_MD("invalidate"),&FileDialog::invalidate);
ADD_SIGNAL(MethodInfo("file_selected",PropertyInfo( Variant::STRING,"path")));
- ADD_SIGNAL(MethodInfo("files_selected",PropertyInfo( Variant::STRING_ARRAY,"paths")));
+ ADD_SIGNAL(MethodInfo("files_selected",PropertyInfo( Variant::POOL_STRING_ARRAY,"paths")));
ADD_SIGNAL(MethodInfo("dir_selected",PropertyInfo( Variant::STRING,"dir")));
BIND_CONSTANT( MODE_OPEN_FILE );
@@ -736,7 +739,7 @@ void FileDialog::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open one,Open many,Open folder,Open any,Save"),_SCS("set_mode"),_SCS("get_mode") );
ADD_PROPERTY( PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"),_SCS("set_access"),_SCS("get_access") );
- ADD_PROPERTY( PropertyInfo(Variant::STRING_ARRAY, "filters"),_SCS("set_filters"),_SCS("get_filters") );
+ ADD_PROPERTY( PropertyInfo(Variant::POOL_STRING_ARRAY, "filters"),_SCS("set_filters"),_SCS("get_filters") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "show_hidden_files"),_SCS("set_show_hidden_files"),_SCS("is_showing_hidden_files") );
}
@@ -761,7 +764,7 @@ FileDialog::FileDialog() {
VBoxContainer *vbc = memnew( VBoxContainer );
add_child(vbc);
- set_child_rect(vbc);
+
mode=MODE_SAVE_FILE;
set_title(RTR("Save a File"));
@@ -825,7 +828,7 @@ FileDialog::FileDialog() {
makedialog->set_title(RTR("Create Folder"));
VBoxContainer *makevb= memnew( VBoxContainer );
makedialog->add_child(makevb);
- makedialog->set_child_rect(makevb);
+
makedirname = memnew( LineEdit );
makevb->add_margin_child(RTR("Name:"),makedirname);
add_child(makedialog);
@@ -865,11 +868,11 @@ FileDialog::~FileDialog() {
void LineEditFileChooser::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("_browse"),&LineEditFileChooser::_browse);
- ObjectTypeDB::bind_method(_MD("_chosen"),&LineEditFileChooser::_chosen);
- ObjectTypeDB::bind_method(_MD("get_button:Button"),&LineEditFileChooser::get_button);
- ObjectTypeDB::bind_method(_MD("get_line_edit:LineEdit"),&LineEditFileChooser::get_line_edit);
- ObjectTypeDB::bind_method(_MD("get_file_dialog:FileDialog"),&LineEditFileChooser::get_file_dialog);
+ ClassDB::bind_method(_MD("_browse"),&LineEditFileChooser::_browse);
+ ClassDB::bind_method(_MD("_chosen"),&LineEditFileChooser::_chosen);
+ ClassDB::bind_method(_MD("get_button:Button"),&LineEditFileChooser::get_button);
+ ClassDB::bind_method(_MD("get_line_edit:LineEdit"),&LineEditFileChooser::get_line_edit);
+ ClassDB::bind_method(_MD("get_file_dialog:FileDialog"),&LineEditFileChooser::get_file_dialog);
}