Claened up MatMAker's FileDialog.

This commit is contained in:
Relintai 2022-06-13 20:57:24 +02:00
parent 18694c27b9
commit a276ee47e8
4 changed files with 106 additions and 1419 deletions

View File

@ -1,36 +0,0 @@
void construct() {
Button *favbutton = memnew(Button);
favbutton->set_name("FavButton");
favbutton->set_name("FavButton");
//favbutton->set("name", FavButton));
favbutton->set_filename("res://addons/mat_maker_gd/windows/file_dialog/fav_button.tscn");
//favbutton->set("filename", "res://addons/mat_maker_gd/windows/file_dialog/fav_button.tscn");
favbutton->set_margin_right(12);
//favbutton->set("margin_right", 12);
favbutton->set_margin_bottom(20);
//favbutton->set("margin_bottom", 20);
favbutton->set_rect_size(Vector2(12, 20));
//favbutton->set("rect_size", Vector2(12, 20));
//favbutton property icon TYPE_OBJECT value: [AtlasTexture:36836]
Ref<AtlasTexture> favbutton_prop_icon;
favbutton_prop_icon.instance();
favbutton->set_icon(favbutton_prop_icon);
//favbutton->set("icon", favbutton_prop_icon);
favbutton->set_flat(True);
//favbutton->set("flat", True);
//favbutton property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False}
}

View File

@ -1,134 +1,107 @@
#include "file_dialog.h"
#include "core/variant.h"
#include "left_panel.h"
#include "scene/gui/option_button.h"
#include "scene/gui/split_container.h"
Variant FileDialog::get_Variant() {
return Variant;
#include "core/os/os.h"
String MatMakerFileDialog::get_full_current_dir() {
String prefix = "";
if (_volume_option != nullptr && _volume_option->is_visible()) {
prefix = _volume_option->get_item_text(_volume_option->get_selected());
}
return prefix + get_current_dir();
}
void FileDialog::set_Variant(const Variant &val) {
Variant = val;
void MatMakerFileDialog::_on_FileDialog_file_selected(const String &path) {
_left_panel->add_recent(get_full_current_dir());
Array arr;
arr.push_back(path);
emit_signal("return_paths", arr);
}
Variant FileDialog::get_Variant() {
return Variant;
void MatMakerFileDialog::_on_FileDialog_files_selected(const PoolStringArray &paths) {
_left_panel->add_recent(get_full_current_dir());
emit_signal("return_paths", paths);
}
void FileDialog::set_Variant(const Variant &val) {
Variant = val;
void MatMakerFileDialog::_on_FileDialog_dir_selected(const String &dir) {
Array arr;
arr.push_back(dir);
emit_signal("return_paths", arr);
}
//tool;
Variant = null;
Variant = null;
signal return_paths(path_list);
void FileDialog::_ready() {
Variant = get_child(3);
Variant = HSplitContainer.new();
add_child(hbox);
remove_child(vbox);
left_panel = preload("res://addons/mat_maker_gd/windows/file_dialog/left_panel.tscn").instance();
hbox.add_child(left_panel);
left_panel.connect("open_directory", self, "set_current_dir");
hbox.add_child(vbox);
vbox.size_flags_horizontal = SIZE_EXPAND_FILL;
//var fav_button = preload("res://addons/mat_maker_gd/windows/file_dialog/fav_button.tscn").instance();
vbox.get_child(0).add_child(fav_button);
fav_button.connect("pressed", self, "add_favorite");
if (OS.get_name() == "Windows") {
volume_option = vbox.get_child(0).get_child(3);
if (! volume_option is OptionButton) {
volume_option = null;
void MatMakerFileDialog::_on_FileDialog_popup_hide() {
emit_signal("return_paths", Array());
}
Array MatMakerFileDialog::select_files() {
popup_centered();
Variant = yield(self, "return_paths");
queue_free();
return result;
}
void MatMakerFileDialog::add_favorite() {
_left_panel->add_favorite(get_full_current_dir());
}
String FileDialog::get_full_current_dir() {
Variant = "";
if (volume_option != null && volume_option.visible) {
prefix = volume_option.get_item_text(volume_option.selected);
MatMakerFileDialog::MatMakerFileDialog() {
_left_panel = nullptr;
_volume_option = nullptr;
}
return prefix+get_current_dir();
MatMakerFileDialog::~MatMakerFileDialog() {
}
void MatMakerFileDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_POSTINITIALIZE) {
Control *vbox = Object::cast_to<Control>(get_child(3));
HSplitContainer *hbox = memnew(HSplitContainer);
add_child(hbox);
remove_child(vbox);
void FileDialog::_on_FileDialog_file_selected(const Variant &path) {
left_panel.add_recent(get_full_current_dir());
emit_signal("return_paths", [ path ]);
_left_panel = memnew(LeftPanel);
hbox->add_child(_left_panel);
_left_panel->connect("open_directory", this, "set_current_dir");
hbox->add_child(vbox);
vbox->set_h_size_flags(SIZE_EXPAND_FILL);
Button *fav_button = memnew(Button);
fav_button->set_text("F");
fav_button->set_tooltip("Favorite");
vbox->get_child(0)->add_child(fav_button);
fav_button->connect("pressed", this, "add_favorite");
if (OS::get_singleton()->get_name() == "Windows") {
_volume_option = Object::cast_to<OptionButton>(vbox->get_child(0)->get_child(3));
}
connect("dir_selected", this, "_on_FileDialog_dir_selected");
connect("file_selected", this, "_on_FileDialog_file_selected");
connect("files_selected", this, "_on_FileDialog_files_selected");
connect("popup_hide", this, "_on_FileDialog_popup_hide");
}
}
void MatMakerFileDialog::_bind_methods() {
ADD_SIGNAL(MethodInfo("return_paths", PropertyInfo(Variant::ARRAY, "path_list")));
void FileDialog::_on_FileDialog_files_selected(const Variant &paths) {
left_panel.add_recent(get_full_current_dir());
emit_signal("return_paths", paths);
ClassDB::bind_method(D_METHOD("get_full_current_dir"), &MatMakerFileDialog::get_full_current_dir);
ClassDB::bind_method(D_METHOD("_on_FileDialog_file_selected", "path"), &MatMakerFileDialog::_on_FileDialog_file_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_files_selected", "paths"), &MatMakerFileDialog::_on_FileDialog_files_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_dir_selected", "dir"), &MatMakerFileDialog::_on_FileDialog_dir_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_popup_hide"), &MatMakerFileDialog::_on_FileDialog_popup_hide);
ClassDB::bind_method(D_METHOD("select_files"), &MatMakerFileDialog::select_files);
ClassDB::bind_method(D_METHOD("add_favorite"), &MatMakerFileDialog::add_favorite);
}
void FileDialog::_on_FileDialog_dir_selected(const Variant &dir) {
emit_signal("return_paths", [ dir ]);
}
void FileDialog::_on_FileDialog_popup_hide() {
emit_signal("return_paths", [ ]);
}
Array FileDialog::select_files() {
popup_centered();
Variant = yield(self, "return_paths");
queue_free();
return result;
}
void FileDialog::add_favorite() {
left_panel.add_favorite(get_full_current_dir());
}
}
FileDialog::FileDialog() {
= null;
= null;
}
FileDialog::~FileDialog() {
}
static void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_Variant"), &FileDialog::get_Variant);
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &FileDialog::set_Variant);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
ClassDB::bind_method(D_METHOD("get_Variant"), &FileDialog::get_Variant);
ClassDB::bind_method(D_METHOD("set_Variant", "value"), &FileDialog::set_Variant);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "Variant", PROPERTY_HINT_RESOURCE_TYPE, "Variant"), "set_Variant", "get_Variant");
ClassDB::bind_method(D_METHOD("_ready"), &FileDialog::_ready);
ClassDB::bind_method(D_METHOD("get_full_current_dir"), &FileDialog::get_full_current_dir);
ClassDB::bind_method(D_METHOD("_on_FileDialog_file_selected", "path"), &FileDialog::_on_FileDialog_file_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_files_selected", "paths"), &FileDialog::_on_FileDialog_files_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_dir_selected", "dir"), &FileDialog::_on_FileDialog_dir_selected);
ClassDB::bind_method(D_METHOD("_on_FileDialog_popup_hide"), &FileDialog::_on_FileDialog_popup_hide);
ClassDB::bind_method(D_METHOD("select_files"), &FileDialog::select_files);
ClassDB::bind_method(D_METHOD("add_favorite"), &FileDialog::add_favorite);
}

View File

@ -1,38 +1,38 @@
#ifndef FILE_DIALOG_H
#define FILE_DIALOG_H
#ifndef MAT_MAKER_FILE_DIALOG_H
#define MAT_MAKER_FILE_DIALOG_H
#include "core/ustring.h"
#include "core/variant.h"
class FileDialog : public FileDialog {
GDCLASS(FileDialog, FileDialog);
#include "scene/gui/file_dialog.h"
public:
class LeftPanel;
class OptionButton;
Variant get_Variant();
void set_Variant(const Variant &val);
class MatMakerFileDialog : public FileDialog {
GDCLASS(MatMakerFileDialog, FileDialog);
Variant get_Variant();
void set_Variant(const Variant &val);
public:
String get_full_current_dir();
void _ready();
String get_full_current_dir();
void _on_FileDialog_file_selected(const Variant &path);
void _on_FileDialog_files_selected(const Variant &paths);
void _on_FileDialog_dir_selected(const Variant &dir);
void _on_FileDialog_popup_hide();
Array select_files();
void add_favorite();
void _on_FileDialog_file_selected(const String &path);
void _on_FileDialog_files_selected(const PoolStringArray &paths);
void _on_FileDialog_dir_selected(const String &dir);
void _on_FileDialog_popup_hide();
FileDialog();
~FileDialog();
Array select_files();
void add_favorite();
protected:
static void _bind_methods();
MatMakerFileDialog();
~MatMakerFileDialog();
//tool
Variant = null;
Variant = null;
signal return_paths(path_list);
protected:
void _notification(int p_what);
static void _bind_methods();
LeftPanel *_left_panel;
OptionButton *_volume_option;
};
#endif