123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815 |
- /*************************************************************************/
- /* file_dialog.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* http://www.godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2014 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 */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /*************************************************************************/
- #include "file_dialog.h"
- #include "scene/gui/label.h"
- #include "print_string.h"
- #include "os/keyboard.h"
- #include "tools/editor/editor_settings.h"
- FileDialog::GetIconFunc FileDialog::get_icon_func=NULL;
- FileDialog::GetIconFunc FileDialog::get_large_icon_func=NULL;
- FileDialog::RegisterFunc FileDialog::register_func=NULL;
- FileDialog::RegisterFunc FileDialog::unregister_func=NULL;
- VBoxContainer *FileDialog::get_vbox() {
- return vbox;
- }
- void FileDialog::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_DRAW) {
- //RID ci = get_canvas_item();
- //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
- }
- }
- void FileDialog::set_enable_multiple_selection(bool p_enable) {
- tree->set_select_mode(p_enable?Tree::SELECT_MULTI : Tree::SELECT_SINGLE);
- };
- Vector<String> FileDialog::get_selected_files() const {
- Vector<String> list;
- TreeItem* item = tree->get_root();
- while ( (item = tree->get_next_selected(item)) ) {
- list.push_back(dir_access->get_current_dir().plus_file(item->get_text(0)));
- };
- return list;
- };
- void FileDialog::update_dir() {
-
- dir->set_text(dir_access->get_current_dir());
- }
- void FileDialog::_dir_entered(String p_dir) {
-
-
- dir_access->change_dir(p_dir);
- file->set_text("");
- invalidate();
- update_dir();
- }
- void FileDialog::_file_entered(const String& p_file) {
- _action_pressed();
- }
- void FileDialog::_save_confirm_pressed() {
-
- String f=dir_access->get_current_dir().plus_file(file->get_text());
- emit_signal("file_selected",f);
- hide();
- }
- void FileDialog::_post_popup() {
- ConfirmationDialog::_post_popup();
- if (invalidated) {
- update_file_list();
- invalidated=false;
- }
- if (mode==MODE_SAVE_FILE)
- file->grab_focus();
- else
- tree->grab_focus();
- }
- void FileDialog::_action_pressed() {
-
- if (mode==MODE_OPEN_FILES) {
- TreeItem *ti=tree->get_next_selected(NULL);
- String fbase=dir_access->get_current_dir();
- DVector<String> files;
- while(ti) {
- files.push_back( fbase.plus_file(ti->get_text(0)) );
- ti=tree->get_next_selected(ti);
- }
- if (files.size()) {
- emit_signal("files_selected",files);
- hide();
- }
- return;
- }
- String f=dir_access->get_current_dir().plus_file(file->get_text());
-
- if (mode==MODE_OPEN_FILE && dir_access->file_exists(f)) {
- emit_signal("file_selected",f);
- hide();
- }
- if (mode==MODE_OPEN_DIR) {
- String path=dir_access->get_current_dir();
- /*if (tree->get_selected()) {
- Dictionary d = tree->get_selected()->get_metadata(0);
- if (d["dir"]) {
- path=path+"/"+String(d["name"]);
- }
- }*/
- path=path.replace("\\","/");
- emit_signal("dir_selected",path);
- hide();
- }
- if (mode==MODE_SAVE_FILE) {
-
- bool valid=false;
- if (filter->get_selected()==filter->get_item_count()-1) {
- valid=true; //match none
- } else if (filters.size()>1 && filter->get_selected()==0) {
- // match all filters
- for (int i=0;i<filters.size();i++) {
- String flt=filters[i].get_slice(";",0);
- for (int j=0;j<flt.get_slice_count(",");j++) {
- String str = flt.get_slice(",",j).strip_edges();
- if (f.match(str)) {
- valid=true;
- break;
- }
- }
- if (valid)
- break;
- }
- } else {
- int idx=filter->get_selected();
- if (filters.size()>1)
- idx--;
- if (idx>=0 && idx<filters.size()) {
- String flt=filters[idx].get_slice(";",0);
- int filterSliceCount=flt.get_slice_count(",");
- for (int j=0;j<filterSliceCount;j++) {
- String str = (flt.get_slice(",",j).strip_edges());
- if (f.match(str)) {
- valid=true;
- break;
- }
- }
- if (!valid && filterSliceCount>0) {
- String str = (flt.get_slice(",",0).strip_edges());
- f+=str.substr(1, str.length()-1);
- file->set_text(f.get_file());
- valid=true;
- }
- } else {
- valid=true;
- }
- }
- if (!valid) {
- exterr->popup_centered_minsize(Size2(250,80));
- return;
- }
- if (dir_access->file_exists(f)) {
- confirm_save->set_text("File Exists, Overwrite?");
- confirm_save->popup_centered(Size2(200,80));
- } else {
-
- emit_signal("file_selected",f);
- hide();
- }
- }
- }
- void FileDialog::_cancel_pressed() {
- file->set_text("");
- invalidate();
- hide();
- }
- void FileDialog::_tree_selected() {
-
- TreeItem *ti=tree->get_selected();
- if (!ti)
- return;
- Dictionary d=ti->get_metadata(0);
-
- if (!d["dir"]) {
-
- file->set_text(d["name"]);
- }
-
- }
- void FileDialog::_tree_dc_selected() {
-
- TreeItem *ti=tree->get_selected();
- if (!ti)
- return;
-
- Dictionary d=ti->get_metadata(0);
- if (d["dir"]) {
-
- dir_access->change_dir(d["name"]);
- if (mode==MODE_OPEN_FILE || mode==MODE_OPEN_FILES || mode==MODE_OPEN_DIR)
- file->set_text("");
- call_deferred("_update_file_list");
- call_deferred("_update_dir");
- } else {
-
- _action_pressed();
- }
- }
- void FileDialog::update_file_list() {
-
- tree->clear();
- dir_access->list_dir_begin();
-
- TreeItem *root = tree->create_item();
- Ref<Texture> folder = get_icon("folder");
- List<String> files;
- List<String> dirs;
-
- bool isdir;
- bool ishidden;
- bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files");
- String item;
- while ((item=dir_access->get_next(&isdir))!="") {
- ishidden = dir_access->current_is_hidden();
- if (show_hidden || !ishidden) {
- if (!isdir)
- files.push_back(item);
- else
- dirs.push_back(item);
- }
- }
-
- dirs.sort_custom<NoCaseComparator>();
- files.sort_custom<NoCaseComparator>();
-
- while(!dirs.empty()) {
-
- 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();
-
- }
-
- dirs.clear();
-
- List<String> patterns;
- // build filter
- if (filter->get_selected()==filter->get_item_count()-1) {
-
- // match all
- } else if (filters.size()>1 && filter->get_selected()==0) {
- // match all filters
- for (int i=0;i<filters.size();i++) {
-
- String f=filters[i].get_slice(";",0);
- for (int j=0;j<f.get_slice_count(",");j++) {
-
- patterns.push_back(f.get_slice(",",j).strip_edges());
- }
- }
- } else {
- int idx=filter->get_selected();
- if (filters.size()>1)
- idx--;
-
- if (idx>=0 && idx<filters.size()) {
-
- String f=filters[idx].get_slice(";",0);
- for (int j=0;j<f.get_slice_count(",");j++) {
-
- patterns.push_back(f.get_slice(",",j).strip_edges());
- }
- }
- }
- String base_dir = dir_access->get_current_dir();
-
-
- while(!files.empty()) {
-
- bool match=patterns.empty();
-
- for(List<String>::Element *E=patterns.front();E;E=E->next()) {
-
- if (files.front()->get().matchn(E->get())) {
-
- match=true;
- break;
- }
- }
-
- if (match) {
- TreeItem *ti=tree->create_item(root);
- ti->set_text(0,files.front()->get());
- if (get_icon_func) {
- Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
- ti->set_icon(0,icon);
- }
- if (mode==MODE_OPEN_DIR) {
- ti->set_custom_color(0,get_color("files_disabled"));
- ti->set_selectable(0,false);
- }
- Dictionary d;
- d["name"]=files.front()->get();
- d["dir"]=false;
- ti->set_metadata(0,d);
-
- if (file->get_text()==files.front()->get())
- ti->select(0);
- }
-
- files.pop_front();
- }
-
- if (tree->get_root() && tree->get_root()->get_children())
- tree->get_root()->get_children()->select(0);
-
- files.clear();
-
- }
- void FileDialog::_filter_selected(int) {
-
- update_file_list();
- }
- void FileDialog::update_filters() {
-
- filter->clear();
-
- if (filters.size()>1) {
- String all_filters;
- const int max_filters=5;
-
- for(int i=0;i<MIN( max_filters, filters.size()) ;i++) {
- String flt=filters[i].get_slice(";",0);
- if (i>0)
- all_filters+=",";
- all_filters+=flt;
- }
- if (max_filters<filters.size())
- all_filters+=", ...";
-
- filter->add_item("All Recognized ( "+all_filters+" )");
- }
- for(int i=0;i<filters.size();i++) {
-
- String flt=filters[i].get_slice(";",0).strip_edges();
- String desc=filters[i].get_slice(";",1).strip_edges();
- if (desc.length())
- filter->add_item(desc+" ( "+flt+" )");
- else
- filter->add_item("( "+flt+" )");
- }
-
- filter->add_item("All Files (*)");
-
- }
- void FileDialog::clear_filters() {
-
- filters.clear();
- update_filters();
- invalidate();
- }
- void FileDialog::add_filter(const String& p_filter) {
-
- filters.push_back(p_filter);
- update_filters();
- invalidate();
-
- }
- String FileDialog::get_current_dir() const {
-
- return dir->get_text();
- }
- String FileDialog::get_current_file() const {
-
- return file->get_text();
- }
- String FileDialog::get_current_path() const {
-
- return dir->get_text().plus_file(file->get_text());
- }
- void FileDialog::set_current_dir(const String& p_dir) {
-
- dir_access->change_dir(p_dir);
- update_dir();
- invalidate();
-
- }
- void FileDialog::set_current_file(const String& p_file) {
-
- file->set_text(p_file);
- update_dir();
- invalidate();
- int lp = p_file.find_last(".");
- if (lp!=-1) {
- file->select(0,lp);
- file->grab_focus();
- }
-
- }
- void FileDialog::set_current_path(const String& p_path) {
-
- if (!p_path.size())
- return;
- int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") );
- if (pos==-1) {
-
- set_current_file(p_path);
- } else {
-
- String dir=p_path.substr(0,pos);
- String file=p_path.substr(pos+1,p_path.length());
- set_current_dir(dir);
- set_current_file(file);
- }
- }
- void FileDialog::set_mode(Mode p_mode) {
-
- mode=p_mode;
- switch(mode) {
-
- case MODE_OPEN_FILE: get_ok()->set_text("Open"); set_title("Open a File"); makedir->hide(); break;
- case MODE_OPEN_FILES: get_ok()->set_text("Open"); set_title("Open File(s)"); makedir->hide(); break;
- case MODE_SAVE_FILE: get_ok()->set_text("Save"); set_title("Save a File"); makedir->show(); break;
- case MODE_OPEN_DIR: get_ok()->set_text("Open"); set_title("Open a Directory"); makedir->show(); break;
- }
- if (mode==MODE_OPEN_FILES) {
- tree->set_select_mode(Tree::SELECT_MULTI);
- } else {
- tree->set_select_mode(Tree::SELECT_SINGLE);
- }
- }
- FileDialog::Mode FileDialog::get_mode() const {
-
- return mode;
- }
- void FileDialog::set_access(Access p_access) {
- ERR_FAIL_INDEX(p_access,3);
- if (access==p_access)
- return;
- memdelete( dir_access );
- switch(p_access) {
- case ACCESS_FILESYSTEM: {
- dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- } break;
- case ACCESS_RESOURCES: {
- dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- } break;
- case ACCESS_USERDATA: {
- dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA);
- } break;
- }
- access=p_access;
- _update_drives();
- invalidate();
- update_filters();
- update_dir();
- }
- void FileDialog::invalidate() {
- if (is_visible()) {
- update_file_list();
- invalidated=false;
- } else {
- invalidated=true;
- }
- }
- FileDialog::Access FileDialog::get_access() const{
- return access;
- }
- void FileDialog::_make_dir_confirm() {
- Error err = dir_access->make_dir( makedirname->get_text() );
- if (err==OK) {
- dir_access->change_dir(makedirname->get_text());
- invalidate();
- update_filters();
- update_dir();
- } else {
- mkdirerr->popup_centered_minsize(Size2(250,50));
- }
- }
- void FileDialog::_make_dir() {
- makedialog->popup_centered_minsize(Size2(250,80));
- makedirname->grab_focus();
- }
- void FileDialog::_select_drive(int p_idx) {
- String d = drives->get_item_text(p_idx);
- dir_access->change_dir(d);
- file->set_text("");
- invalidate();
- update_dir();
- }
- void FileDialog::_update_drives() {
- int dc = dir_access->get_drive_count();
- if (dc==0 || access!=ACCESS_FILESYSTEM) {
- drives->hide();
- } else {
- drives->clear();
- drives->show();
- int current=-1;
- String abspath = dir_access->get_current_dir();
- for(int i=0;i<dir_access->get_drive_count();i++) {
- String d = dir_access->get_drive(i);
- if (abspath.begins_with(d))
- current=i;
- drives->add_item(dir_access->get_drive(i));
- }
- if (current!=-1)
- drives->select(current);
- }
- }
- void FileDialog::_bind_methods() {
-
- 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("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("_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);
- ADD_SIGNAL(MethodInfo("file_selected",PropertyInfo( Variant::STRING,"path")));
- ADD_SIGNAL(MethodInfo("files_selected",PropertyInfo( Variant::STRING_ARRAY,"paths")));
- ADD_SIGNAL(MethodInfo("dir_selected",PropertyInfo( Variant::STRING,"dir")));
- BIND_CONSTANT( MODE_OPEN_FILE );
- BIND_CONSTANT( MODE_OPEN_FILES );
- BIND_CONSTANT( MODE_OPEN_DIR );
- BIND_CONSTANT( MODE_SAVE_FILE );
- BIND_CONSTANT( ACCESS_RESOURCES );
- BIND_CONSTANT( ACCESS_USERDATA );
- BIND_CONSTANT( ACCESS_FILESYSTEM );
- }
- FileDialog::FileDialog() {
-
- VBoxContainer *vbc = memnew( VBoxContainer );
- add_child(vbc);
- set_child_rect(vbc);
- mode=MODE_SAVE_FILE;
- set_title("Save a File");
-
- dir = memnew(LineEdit);
- HBoxContainer *pathhb = memnew( HBoxContainer );
- pathhb->add_child(dir);
- dir->set_h_size_flags(SIZE_EXPAND_FILL);
- drives = memnew( OptionButton );
- pathhb->add_child(drives);
- drives->connect("item_selected",this,"_select_drive");
- makedir = memnew( Button );
- makedir->set_text("Create Folder");
- makedir->connect("pressed",this,"_make_dir");
- pathhb->add_child(makedir);
-
- vbc->add_margin_child("Path:",pathhb);
-
- tree = memnew(Tree);
- tree->set_hide_root(true);
- vbc->add_margin_child("Directories & Files:",tree,true);
-
- file = memnew(LineEdit);
- //add_child(file);
- vbc->add_margin_child("File:",file);
-
- filter = memnew( OptionButton );
- //add_child(filter);
- vbc->add_margin_child("Filter:",filter);
- filter->set_clip_text(true);//too many extensions overflow it
- dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- access=ACCESS_RESOURCES;
- _update_drives();
-
- connect("confirmed", this,"_action_pressed");
- //cancel->connect("pressed", this,"_cancel_pressed");
- tree->connect("cell_selected", this,"_tree_selected",varray(),CONNECT_DEFERRED);
- tree->connect("item_activated", this,"_tree_db_selected",varray());
- dir->connect("text_entered", this,"_dir_entered");
- file->connect("text_entered", this,"_file_entered");
- filter->connect("item_selected", this,"_filter_selected");
-
- confirm_save = memnew( ConfirmationDialog );
- confirm_save->set_as_toplevel(true);
- add_child(confirm_save);
-
- confirm_save->connect("confirmed", this,"_save_confirm_pressed");
- makedialog = memnew( ConfirmationDialog );
- makedialog->set_title("Create Folder");
- VBoxContainer *makevb= memnew( VBoxContainer );
- makedialog->add_child(makevb);
- makedialog->set_child_rect(makevb);
- makedirname = memnew( LineEdit );
- makevb->add_margin_child("Name:",makedirname);
- add_child(makedialog);
- makedialog->register_text_enter(makedirname);
- makedialog->connect("confirmed",this,"_make_dir_confirm");
- mkdirerr = memnew( AcceptDialog );
- mkdirerr->set_text("Could not create folder.");
- add_child(mkdirerr);
- exterr = memnew( AcceptDialog );
- exterr->set_text("Must use a valid extension.");
- add_child(exterr);
- //update_file_list();
- update_filters();
- update_dir();
- set_hide_on_ok(false);
- vbox=vbc;
- invalidated=true;
- if (register_func)
- register_func(this);
-
- }
- FileDialog::~FileDialog() {
-
- if (unregister_func)
- unregister_func(this);
- memdelete(dir_access);
- }
- 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);
- }
- void LineEditFileChooser::_chosen(const String& p_text){
- line_edit->set_text(p_text);
- line_edit->emit_signal("text_entered",p_text);
- }
- void LineEditFileChooser::_browse() {
- dialog->popup_centered_ratio();
- }
- LineEditFileChooser::LineEditFileChooser() {
- line_edit = memnew( LineEdit );
- add_child(line_edit);
- line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
- button = memnew( Button );
- button->set_text(" .. ");
- add_child(button);
- button->connect("pressed",this,"_browse");
- dialog = memnew( FileDialog);
- add_child(dialog);
- dialog->connect("file_selected",this,"_chosen");
- dialog->connect("dir_selected",this,"_chosen");
- dialog->connect("files_selected",this,"_chosen");
- }
|