2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* file_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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"
|
2015-03-21 18:33:32 +01:00
|
|
|
#include "os/keyboard.h"
|
2015-03-23 15:31:03 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
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) {
|
2015-12-04 19:33:30 +01:00
|
|
|
|
|
|
|
if (p_what==NOTIFICATION_ENTER_TREE) {
|
|
|
|
|
2015-12-26 17:55:48 +01:00
|
|
|
refresh->set_icon(get_icon("reload"));
|
2015-12-04 19:33:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_what==NOTIFICATION_DRAW) {
|
|
|
|
|
|
|
|
//RID ci = get_canvas_item();
|
|
|
|
//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
2015-12-29 00:36:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what==NOTIFICATION_POPUP_HIDE) {
|
|
|
|
|
|
|
|
set_process_unhandled_input(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_unhandled_input(const InputEvent& p_event) {
|
|
|
|
|
|
|
|
if (p_event.type==InputEvent::KEY && is_window_modal_on_top()) {
|
|
|
|
|
|
|
|
const InputEventKey &k=p_event.key;
|
|
|
|
|
|
|
|
if (k.pressed) {
|
|
|
|
|
|
|
|
bool handled=true;
|
|
|
|
|
|
|
|
switch (k.scancode) {
|
|
|
|
|
|
|
|
case KEY_H: {
|
|
|
|
|
|
|
|
if (k.mod.command) {
|
|
|
|
set_show_hidden_files(!show_hidden_files);
|
|
|
|
} else {
|
|
|
|
handled=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2016-01-15 21:19:16 +01:00
|
|
|
case KEY_F5: {
|
|
|
|
|
|
|
|
invalidate();
|
|
|
|
} break;
|
2015-12-29 00:36:48 +01:00
|
|
|
default: { handled=false; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled)
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dir->set_text(dir_access->get_current_dir());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_dir_entered(String p_dir) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dir_access->change_dir(p_dir);
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
update_dir();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_file_entered(const String& p_file) {
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
_action_pressed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_save_confirm_pressed() {
|
|
|
|
String f=dir_access->get_current_dir().plus_file(file->get_text());
|
|
|
|
emit_signal("file_selected",f);
|
2016-03-09 00:00:52 +01:00
|
|
|
hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2015-12-29 00:36:48 +01:00
|
|
|
set_process_unhandled_input(true);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_action_pressed() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-14 16:03:18 +01:00
|
|
|
if ((mode==MODE_OPEN_ANY || mode==MODE_OPEN_FILE) && dir_access->file_exists(f)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal("file_selected",f);
|
|
|
|
hide();
|
2016-03-14 16:03:18 +01:00
|
|
|
}else if (mode==MODE_OPEN_ANY || mode==MODE_OPEN_DIR) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String path=dir_access->get_current_dir();
|
2016-09-19 05:27:53 +02:00
|
|
|
|
|
|
|
path=path.replace("\\","/");
|
|
|
|
|
|
|
|
if (TreeItem* item = tree->get_selected()) {
|
|
|
|
Dictionary d = item->get_metadata(0);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (d["dir"]) {
|
2016-09-19 05:27:53 +02:00
|
|
|
path=path.plus_file(d["name"]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-09-19 05:27:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal("dir_selected",path);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode==MODE_SAVE_FILE) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-10 05:18:27 +02:00
|
|
|
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);
|
2015-01-15 00:02:51 +01:00
|
|
|
int filterSliceCount=flt.get_slice_count(",");
|
|
|
|
for (int j=0;j<filterSliceCount;j++) {
|
2014-04-10 05:18:27 +02:00
|
|
|
|
|
|
|
String str = (flt.get_slice(",",j).strip_edges());
|
|
|
|
if (f.match(str)) {
|
|
|
|
valid=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 00:02:51 +01:00
|
|
|
|
|
|
|
if (!valid && filterSliceCount>0) {
|
|
|
|
String str = (flt.get_slice(",",0).strip_edges());
|
|
|
|
f+=str.substr(1, str.length()-1);
|
2015-01-16 13:48:28 +01:00
|
|
|
file->set_text(f.get_file());
|
2015-01-15 00:02:51 +01:00
|
|
|
valid=true;
|
|
|
|
}
|
2014-04-10 05:18:27 +02:00
|
|
|
} else {
|
|
|
|
valid=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
|
|
|
|
exterr->popup_centered_minsize(Size2(250,80));
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (dir_access->file_exists(f)) {
|
2016-06-07 22:24:32 +02:00
|
|
|
confirm_save->set_text(RTR("File Exists, Overwrite?"));
|
2014-02-10 02:10:30 +01:00
|
|
|
confirm_save->popup_centered(Size2(200,80));
|
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-04-10 05:18:27 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_signal("file_selected",f);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_cancel_pressed() {
|
|
|
|
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_tree_selected() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *ti=tree->get_selected();
|
|
|
|
if (!ti)
|
|
|
|
return;
|
|
|
|
Dictionary d=ti->get_metadata(0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!d["dir"]) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
file->set_text(d["name"]);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_tree_dc_selected() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *ti=tree->get_selected();
|
|
|
|
if (!ti)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Dictionary d=ti->get_metadata(0);
|
|
|
|
|
|
|
|
if (d["dir"]) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dir_access->change_dir(d["name"]);
|
2016-03-14 16:03:18 +01:00
|
|
|
if (mode==MODE_OPEN_FILE || mode==MODE_OPEN_FILES || mode==MODE_OPEN_DIR || mode==MODE_OPEN_ANY)
|
2014-02-10 02:10:30 +01:00
|
|
|
file->set_text("");
|
|
|
|
call_deferred("_update_file_list");
|
|
|
|
call_deferred("_update_dir");
|
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_action_pressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::update_file_list() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->clear();
|
|
|
|
dir_access->list_dir_begin();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *root = tree->create_item();
|
|
|
|
Ref<Texture> folder = get_icon("folder");
|
|
|
|
List<String> files;
|
|
|
|
List<String> dirs;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool isdir;
|
2015-03-21 18:33:32 +01:00
|
|
|
bool ishidden;
|
2015-03-23 15:31:03 +01:00
|
|
|
bool show_hidden = show_hidden_files;
|
2014-02-10 02:10:30 +01:00
|
|
|
String item;
|
2015-03-21 18:33:32 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
while ((item=dir_access->get_next(&isdir))!="") {
|
2015-03-21 18:33:32 +01:00
|
|
|
|
|
|
|
ishidden = dir_access->current_is_hidden();
|
|
|
|
|
|
|
|
if (show_hidden || !ishidden) {
|
|
|
|
if (!isdir)
|
|
|
|
files.push_back(item);
|
|
|
|
else
|
|
|
|
dirs.push_back(item);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-18 17:49:58 +02:00
|
|
|
if (dirs.find("..")==NULL) {
|
|
|
|
//may happen if lacking permissions
|
|
|
|
dirs.push_back("..");
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dirs.sort_custom<NoCaseComparator>();
|
|
|
|
files.sort_custom<NoCaseComparator>();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
while(!dirs.empty()) {
|
2016-09-19 05:27:53 +02:00
|
|
|
String& dir_name = dirs.front()->get();
|
|
|
|
TreeItem *ti=tree->create_item(root);
|
|
|
|
ti->set_text(0,dir_name+"/");
|
|
|
|
ti->set_icon(0,folder);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-09-19 05:27:53 +02:00
|
|
|
Dictionary d;
|
|
|
|
d["name"]=dir_name;
|
|
|
|
d["dir"]=true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-09-19 05:27:53 +02:00
|
|
|
ti->set_metadata(0,d);
|
|
|
|
|
|
|
|
dirs.pop_front();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dirs.clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
List<String> patterns;
|
|
|
|
// build filter
|
|
|
|
if (filter->get_selected()==filter->get_item_count()-1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
// match all
|
2014-02-10 02:10:30 +01:00
|
|
|
} else if (filters.size()>1 && filter->get_selected()==0) {
|
|
|
|
// match all filters
|
|
|
|
for (int i=0;i<filters.size();i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String f=filters[i].get_slice(";",0);
|
|
|
|
for (int j=0;j<f.get_slice_count(",");j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
patterns.push_back(f.get_slice(",",j).strip_edges());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int idx=filter->get_selected();
|
|
|
|
if (filters.size()>1)
|
|
|
|
idx--;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (idx>=0 && idx<filters.size()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String f=filters[idx].get_slice(";",0);
|
|
|
|
for (int j=0;j<f.get_slice_count(",");j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
patterns.push_back(f.get_slice(",",j).strip_edges());
|
2016-03-09 00:00:52 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String base_dir = dir_access->get_current_dir();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
while(!files.empty()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool match=patterns.empty();
|
2016-11-15 14:36:41 +01:00
|
|
|
String match_str;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
for(List<String>::Element *E=patterns.front();E;E=E->next()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (files.front()->get().matchn(E->get())) {
|
2016-11-15 14:36:41 +01:00
|
|
|
match_str=E->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
match=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-11-15 14:36:41 +01:00
|
|
|
if (file->get_text()==files.front()->get() || match_str==files.front()->get())
|
2014-02-10 02:10:30 +01:00
|
|
|
ti->select(0);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
files.pop_front();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-11-15 14:36:41 +01:00
|
|
|
if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected()==NULL)
|
2014-02-10 02:10:30 +01:00
|
|
|
tree->get_root()->get_children()->select(0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
files.clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::_filter_selected(int) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
update_file_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::update_filters() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
filter->clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (filters.size()>1) {
|
|
|
|
String all_filters;
|
|
|
|
|
|
|
|
const int max_filters=5;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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+=", ...";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-07 22:24:32 +02:00
|
|
|
filter->add_item(RTR("All Recognized")+" ( "+all_filters+" )");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
for(int i=0;i<filters.size();i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String flt=filters[i].get_slice(";",0).strip_edges();
|
|
|
|
String desc=filters[i].get_slice(";",1).strip_edges();
|
|
|
|
if (desc.length())
|
2016-07-17 01:58:28 +02:00
|
|
|
filter->add_item(String(XL_MESSAGE(desc))+" ( "+flt+" )");
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
|
|
|
filter->add_item("( "+flt+" )");
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-07 22:24:32 +02:00
|
|
|
filter->add_item(RTR("All Files (*)"));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::clear_filters() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
filters.clear();
|
|
|
|
update_filters();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
void FileDialog::add_filter(const String& p_filter) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
filters.push_back(p_filter);
|
|
|
|
update_filters();
|
|
|
|
invalidate();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-07-17 01:58:28 +02:00
|
|
|
void FileDialog::set_filters(const Vector<String>& p_filters){
|
|
|
|
filters=p_filters;
|
|
|
|
update_filters();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> FileDialog::get_filters() const{
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String FileDialog::get_current_dir() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
|
|
|
return dir->get_text();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
String FileDialog::get_current_file() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return file->get_text();
|
|
|
|
}
|
|
|
|
String FileDialog::get_current_path() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return dir->get_text().plus_file(file->get_text());
|
|
|
|
}
|
|
|
|
void FileDialog::set_current_dir(const String& p_dir) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dir_access->change_dir(p_dir);
|
|
|
|
update_dir();
|
|
|
|
invalidate();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void FileDialog::set_current_file(const String& p_file) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
file->set_text(p_file);
|
|
|
|
update_dir();
|
|
|
|
invalidate();
|
|
|
|
int lp = p_file.find_last(".");
|
|
|
|
if (lp!=-1) {
|
|
|
|
file->select(0,lp);
|
|
|
|
file->grab_focus();
|
|
|
|
}
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void FileDialog::set_current_path(const String& p_path) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!p_path.size())
|
|
|
|
return;
|
|
|
|
int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") );
|
|
|
|
if (pos==-1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
set_current_file(p_path);
|
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
mode=p_mode;
|
|
|
|
switch(mode) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-07 22:24:32 +02:00
|
|
|
case MODE_OPEN_FILE: get_ok()->set_text(RTR("Open")); set_title(RTR("Open a File")); makedir->hide(); break;
|
|
|
|
case MODE_OPEN_FILES: get_ok()->set_text(RTR("Open")); set_title(RTR("Open File(s)")); makedir->hide(); break;
|
|
|
|
case MODE_OPEN_DIR: get_ok()->set_text(RTR("Open")); set_title(RTR("Open a Directory")); makedir->show(); break;
|
|
|
|
case MODE_OPEN_ANY: get_ok()->set_text(RTR("Open")); set_title(RTR("Open a File or Directory")); makedir->show(); break;
|
|
|
|
case MODE_SAVE_FILE: get_ok()->set_text(RTR("Save")); set_title(RTR("Save a File")); makedir->show(); break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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));
|
|
|
|
}
|
2016-05-01 11:38:24 +02:00
|
|
|
makedirname->set_text(""); // reset label
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FileDialog::_make_dir() {
|
|
|
|
|
|
|
|
makedialog->popup_centered_minsize(Size2(250,80));
|
2014-02-13 22:03:28 +01:00
|
|
|
makedirname->grab_focus();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
for(int i=0;i<dir_access->get_drive_count();i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
String d = dir_access->get_drive(i);
|
2014-02-10 02:10:30 +01:00
|
|
|
drives->add_item(dir_access->get_drive(i));
|
|
|
|
}
|
|
|
|
|
2015-05-20 02:36:35 +02:00
|
|
|
drives->select(dir_access->get_current_drive());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-06 23:35:31 +01:00
|
|
|
bool FileDialog::default_show_hidden_files=false;
|
2015-03-23 15:31:03 +01:00
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void FileDialog::_bind_methods() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
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 );
|
2016-03-14 16:03:18 +01:00
|
|
|
BIND_CONSTANT( MODE_OPEN_ANY );
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
BIND_CONSTANT( MODE_SAVE_FILE );
|
|
|
|
|
|
|
|
BIND_CONSTANT( ACCESS_RESOURCES );
|
|
|
|
BIND_CONSTANT( ACCESS_USERDATA );
|
|
|
|
BIND_CONSTANT( ACCESS_FILESYSTEM );
|
|
|
|
|
2016-07-17 01:58:28 +02:00
|
|
|
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::BOOL, "show_hidden_files"),_SCS("set_show_hidden_files"),_SCS("is_showing_hidden_files") );
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-23 15:31:03 +01:00
|
|
|
void FileDialog::set_show_hidden_files(bool p_show) {
|
|
|
|
show_hidden_files=p_show;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileDialog::is_showing_hidden_files() const {
|
|
|
|
return show_hidden_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileDialog::set_default_show_hidden_files(bool p_show) {
|
|
|
|
default_show_hidden_files=p_show;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
FileDialog::FileDialog() {
|
2015-03-23 15:31:03 +01:00
|
|
|
|
2015-05-14 23:50:15 +02:00
|
|
|
show_hidden_files=default_show_hidden_files;
|
2015-03-23 15:31:03 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
VBoxContainer *vbc = memnew( VBoxContainer );
|
|
|
|
add_child(vbc);
|
|
|
|
set_child_rect(vbc);
|
|
|
|
|
|
|
|
mode=MODE_SAVE_FILE;
|
2016-06-07 22:24:32 +02:00
|
|
|
set_title(RTR("Save a File"));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
dir = memnew(LineEdit);
|
|
|
|
HBoxContainer *pathhb = memnew( HBoxContainer );
|
|
|
|
pathhb->add_child(dir);
|
|
|
|
dir->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2015-12-04 19:33:30 +01:00
|
|
|
refresh = memnew( ToolButton );
|
|
|
|
refresh->connect("pressed",this,"_update_file_list");
|
|
|
|
pathhb->add_child(refresh);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
drives = memnew( OptionButton );
|
|
|
|
pathhb->add_child(drives);
|
|
|
|
drives->connect("item_selected",this,"_select_drive");
|
|
|
|
|
|
|
|
makedir = memnew( Button );
|
2016-06-07 22:24:32 +02:00
|
|
|
makedir->set_text(RTR("Create Folder"));
|
2014-02-10 02:10:30 +01:00
|
|
|
makedir->connect("pressed",this,"_make_dir");
|
|
|
|
pathhb->add_child(makedir);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-07 22:24:32 +02:00
|
|
|
vbc->add_margin_child(RTR("Path:"),pathhb);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
tree = memnew(Tree);
|
|
|
|
tree->set_hide_root(true);
|
2016-06-07 22:24:32 +02:00
|
|
|
vbc->add_margin_child(RTR("Directories & Files:"),tree,true);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
file = memnew(LineEdit);
|
|
|
|
//add_child(file);
|
2016-06-07 22:24:32 +02:00
|
|
|
vbc->add_margin_child(RTR("File:"),file);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
filter = memnew( OptionButton );
|
|
|
|
//add_child(filter);
|
2016-06-07 22:24:32 +02:00
|
|
|
vbc->add_margin_child(RTR("Filter:"),filter);
|
2014-02-10 02:10:30 +01:00
|
|
|
filter->set_clip_text(true);//too many extensions overflow it
|
|
|
|
|
|
|
|
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
access=ACCESS_RESOURCES;
|
|
|
|
_update_drives();
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
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");
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
confirm_save = memnew( ConfirmationDialog );
|
|
|
|
confirm_save->set_as_toplevel(true);
|
|
|
|
add_child(confirm_save);
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
confirm_save->connect("confirmed", this,"_save_confirm_pressed");
|
|
|
|
|
|
|
|
makedialog = memnew( ConfirmationDialog );
|
2016-06-07 22:24:32 +02:00
|
|
|
makedialog->set_title(RTR("Create Folder"));
|
2014-02-10 02:10:30 +01:00
|
|
|
VBoxContainer *makevb= memnew( VBoxContainer );
|
|
|
|
makedialog->add_child(makevb);
|
|
|
|
makedialog->set_child_rect(makevb);
|
|
|
|
makedirname = memnew( LineEdit );
|
2016-06-07 22:24:32 +02:00
|
|
|
makevb->add_margin_child(RTR("Name:"),makedirname);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(makedialog);
|
|
|
|
makedialog->register_text_enter(makedirname);
|
|
|
|
makedialog->connect("confirmed",this,"_make_dir_confirm");
|
|
|
|
mkdirerr = memnew( AcceptDialog );
|
2016-06-07 22:24:32 +02:00
|
|
|
mkdirerr->set_text(RTR("Could not create folder."));
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(mkdirerr);
|
|
|
|
|
2014-04-10 05:18:27 +02:00
|
|
|
exterr = memnew( AcceptDialog );
|
2016-06-07 22:24:32 +02:00
|
|
|
exterr->set_text(RTR("Must use a valid extension."));
|
2014-04-10 05:18:27 +02:00
|
|
|
add_child(exterr);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//update_file_list();
|
|
|
|
update_filters();
|
|
|
|
update_dir();
|
|
|
|
|
|
|
|
set_hide_on_ok(false);
|
|
|
|
vbox=vbc;
|
|
|
|
|
|
|
|
|
|
|
|
invalidated=true;
|
|
|
|
if (register_func)
|
|
|
|
register_func(this);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FileDialog::~FileDialog() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (unregister_func)
|
|
|
|
unregister_func(this);
|
|
|
|
memdelete(dir_access);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LineEditFileChooser::_bind_methods() {
|
|
|
|
|
2017-01-03 03:03:46 +01:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
2016-03-14 16:03:18 +01:00
|
|
|
|