Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027.
This commit is contained in:
@ -45,7 +45,6 @@ VBoxContainer *FileDialog::get_vbox() {
|
||||
}
|
||||
|
||||
void FileDialog::_theme_changed() {
|
||||
|
||||
Color font_color = vbox->get_theme_color("font_color", "ToolButton");
|
||||
Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton");
|
||||
Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton");
|
||||
@ -64,15 +63,12 @@ void FileDialog::_theme_changed() {
|
||||
}
|
||||
|
||||
void FileDialog::_notification(int p_what) {
|
||||
|
||||
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||
if (!is_visible()) {
|
||||
|
||||
set_process_unhandled_input(false);
|
||||
}
|
||||
}
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog"));
|
||||
refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog"));
|
||||
show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog"));
|
||||
@ -81,18 +77,13 @@ void FileDialog::_notification(int p_what) {
|
||||
}
|
||||
|
||||
void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
|
||||
Ref<InputEventKey> k = p_event;
|
||||
if (k.is_valid() && has_focus()) {
|
||||
|
||||
if (k->is_pressed()) {
|
||||
|
||||
bool handled = true;
|
||||
|
||||
switch (k->get_keycode()) {
|
||||
|
||||
case KEY_H: {
|
||||
|
||||
if (k->get_command()) {
|
||||
set_show_hidden_files(!show_hidden_files);
|
||||
} else {
|
||||
@ -101,11 +92,9 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
|
||||
} break;
|
||||
case KEY_F5: {
|
||||
|
||||
invalidate();
|
||||
} break;
|
||||
case KEY_BACKSPACE: {
|
||||
|
||||
_dir_entered("..");
|
||||
} break;
|
||||
default: {
|
||||
@ -120,17 +109,14 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
}
|
||||
|
||||
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)));
|
||||
};
|
||||
|
||||
@ -138,7 +124,6 @@ Vector<String> FileDialog::get_selected_files() const {
|
||||
};
|
||||
|
||||
void FileDialog::update_dir() {
|
||||
|
||||
dir->set_text(dir_access->get_current_dir(false));
|
||||
|
||||
if (drives->is_visible()) {
|
||||
@ -150,7 +135,6 @@ void FileDialog::update_dir() {
|
||||
}
|
||||
|
||||
void FileDialog::_dir_entered(String p_dir) {
|
||||
|
||||
dir_access->change_dir(p_dir);
|
||||
file->set_text("");
|
||||
invalidate();
|
||||
@ -158,7 +142,6 @@ void FileDialog::_dir_entered(String p_dir) {
|
||||
}
|
||||
|
||||
void FileDialog::_file_entered(const String &p_file) {
|
||||
|
||||
_action_pressed();
|
||||
}
|
||||
|
||||
@ -169,7 +152,6 @@ void FileDialog::_save_confirm_pressed() {
|
||||
}
|
||||
|
||||
void FileDialog::_post_popup() {
|
||||
|
||||
ConfirmationDialog::_post_popup();
|
||||
if (invalidated) {
|
||||
update_file_list();
|
||||
@ -192,15 +174,12 @@ void FileDialog::_post_popup() {
|
||||
}
|
||||
|
||||
void FileDialog::_action_pressed() {
|
||||
|
||||
if (mode == FILE_MODE_OPEN_FILES) {
|
||||
|
||||
TreeItem *ti = tree->get_next_selected(nullptr);
|
||||
String fbase = dir_access->get_current_dir();
|
||||
|
||||
Vector<String> files;
|
||||
while (ti) {
|
||||
|
||||
files.push_back(fbase.plus_file(ti->get_text(0)));
|
||||
ti = tree->get_next_selected(ti);
|
||||
}
|
||||
@ -219,7 +198,6 @@ void FileDialog::_action_pressed() {
|
||||
emit_signal("file_selected", f);
|
||||
hide();
|
||||
} else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) {
|
||||
|
||||
String path = dir_access->get_current_dir();
|
||||
|
||||
path = path.replace("\\", "/");
|
||||
@ -236,7 +214,6 @@ void FileDialog::_action_pressed() {
|
||||
}
|
||||
|
||||
if (mode == FILE_MODE_SAVE_FILE) {
|
||||
|
||||
bool valid = false;
|
||||
|
||||
if (filter->get_selected() == filter->get_item_count() - 1) {
|
||||
@ -244,10 +221,8 @@ void FileDialog::_action_pressed() {
|
||||
} 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;
|
||||
@ -262,11 +237,9 @@ void FileDialog::_action_pressed() {
|
||||
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;
|
||||
@ -286,7 +259,6 @@ void FileDialog::_action_pressed() {
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
|
||||
exterr->popup_centered(Size2(250, 80));
|
||||
return;
|
||||
}
|
||||
@ -295,7 +267,6 @@ void FileDialog::_action_pressed() {
|
||||
confirm_save->set_text(RTR("File Exists, Overwrite?"));
|
||||
confirm_save->popup_centered(Size2(200, 80));
|
||||
} else {
|
||||
|
||||
emit_signal("file_selected", f);
|
||||
hide();
|
||||
}
|
||||
@ -303,14 +274,12 @@ void FileDialog::_action_pressed() {
|
||||
}
|
||||
|
||||
void FileDialog::_cancel_pressed() {
|
||||
|
||||
file->set_text("");
|
||||
invalidate();
|
||||
hide();
|
||||
}
|
||||
|
||||
bool FileDialog::_is_open_should_be_disabled() {
|
||||
|
||||
if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE)
|
||||
return false;
|
||||
|
||||
@ -333,14 +302,12 @@ bool FileDialog::_is_open_should_be_disabled() {
|
||||
}
|
||||
|
||||
void FileDialog::_go_up() {
|
||||
|
||||
dir_access->change_dir("..");
|
||||
update_file_list();
|
||||
update_dir();
|
||||
}
|
||||
|
||||
void FileDialog::deselect_items() {
|
||||
|
||||
// Clear currently selected items in file manager.
|
||||
tree->deselect_all();
|
||||
|
||||
@ -349,7 +316,6 @@ void FileDialog::deselect_items() {
|
||||
get_ok()->set_disabled(_is_open_should_be_disabled());
|
||||
|
||||
switch (mode) {
|
||||
|
||||
case FILE_MODE_OPEN_FILE:
|
||||
case FILE_MODE_OPEN_FILES:
|
||||
get_ok()->set_text(RTR("Open"));
|
||||
@ -370,14 +336,12 @@ void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selec
|
||||
}
|
||||
|
||||
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"]);
|
||||
} else if (mode == FILE_MODE_OPEN_DIR) {
|
||||
get_ok()->set_text(RTR("Select This Folder"));
|
||||
@ -387,7 +351,6 @@ void FileDialog::_tree_selected() {
|
||||
}
|
||||
|
||||
void FileDialog::_tree_item_activated() {
|
||||
|
||||
TreeItem *ti = tree->get_selected();
|
||||
if (!ti)
|
||||
return;
|
||||
@ -395,14 +358,12 @@ void FileDialog::_tree_item_activated() {
|
||||
Dictionary d = ti->get_metadata(0);
|
||||
|
||||
if (d["dir"]) {
|
||||
|
||||
dir_access->change_dir(d["name"]);
|
||||
if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY)
|
||||
file->set_text("");
|
||||
call_deferred("_update_file_list");
|
||||
call_deferred("_update_dir");
|
||||
} else {
|
||||
|
||||
_action_pressed();
|
||||
}
|
||||
}
|
||||
@ -421,7 +382,6 @@ void FileDialog::update_file_name() {
|
||||
}
|
||||
|
||||
void FileDialog::update_file_list() {
|
||||
|
||||
tree->clear();
|
||||
|
||||
// Scroll back to the top after opening a directory
|
||||
@ -439,7 +399,6 @@ void FileDialog::update_file_list() {
|
||||
String item;
|
||||
|
||||
while ((item = dir_access->get_next()) != "") {
|
||||
|
||||
if (item == "." || item == "..")
|
||||
continue;
|
||||
|
||||
@ -475,15 +434,12 @@ void FileDialog::update_file_list() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -493,10 +449,8 @@ void FileDialog::update_file_list() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -505,12 +459,10 @@ void FileDialog::update_file_list() {
|
||||
String base_dir = dir_access->get_current_dir();
|
||||
|
||||
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;
|
||||
@ -523,7 +475,6 @@ void FileDialog::update_file_list() {
|
||||
ti->set_text(0, files.front()->get());
|
||||
|
||||
if (get_icon_func) {
|
||||
|
||||
Ref<Texture2D> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
|
||||
ti->set_icon(0, icon);
|
||||
}
|
||||
@ -549,13 +500,11 @@ void FileDialog::update_file_list() {
|
||||
}
|
||||
|
||||
void FileDialog::_filter_selected(int) {
|
||||
|
||||
update_file_name();
|
||||
update_file_list();
|
||||
}
|
||||
|
||||
void FileDialog::update_filters() {
|
||||
|
||||
filter->clear();
|
||||
|
||||
if (filters.size() > 1) {
|
||||
@ -576,7 +525,6 @@ void FileDialog::update_filters() {
|
||||
filter->add_item(RTR("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())
|
||||
@ -589,13 +537,11 @@ void FileDialog::update_filters() {
|
||||
}
|
||||
|
||||
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();
|
||||
@ -612,25 +558,20 @@ Vector<String> FileDialog::get_filters() const {
|
||||
}
|
||||
|
||||
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();
|
||||
@ -642,15 +583,12 @@ void FileDialog::set_current_file(const String &p_file) {
|
||||
}
|
||||
}
|
||||
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);
|
||||
@ -667,12 +605,10 @@ bool FileDialog::is_mode_overriding_title() const {
|
||||
}
|
||||
|
||||
void FileDialog::set_file_mode(FileMode p_mode) {
|
||||
|
||||
ERR_FAIL_INDEX((int)p_mode, 5);
|
||||
|
||||
mode = p_mode;
|
||||
switch (mode) {
|
||||
|
||||
case FILE_MODE_OPEN_FILE:
|
||||
get_ok()->set_text(RTR("Open"));
|
||||
if (mode_overrides_title)
|
||||
@ -713,27 +649,22 @@ void FileDialog::set_file_mode(FileMode p_mode) {
|
||||
}
|
||||
|
||||
FileDialog::FileMode FileDialog::get_file_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;
|
||||
}
|
||||
@ -745,7 +676,6 @@ void FileDialog::set_access(Access p_access) {
|
||||
}
|
||||
|
||||
void FileDialog::invalidate() {
|
||||
|
||||
if (is_visible()) {
|
||||
update_file_list();
|
||||
invalidated = false;
|
||||
@ -755,12 +685,10 @@ void FileDialog::invalidate() {
|
||||
}
|
||||
|
||||
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());
|
||||
@ -774,13 +702,11 @@ void FileDialog::_make_dir_confirm() {
|
||||
}
|
||||
|
||||
void FileDialog::_make_dir() {
|
||||
|
||||
makedialog->popup_centered(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("");
|
||||
@ -789,7 +715,6 @@ void FileDialog::_select_drive(int p_idx) {
|
||||
}
|
||||
|
||||
void FileDialog::_update_drives() {
|
||||
|
||||
int dc = dir_access->get_drive_count();
|
||||
if (dc == 0 || access != ACCESS_FILESYSTEM) {
|
||||
drives->hide();
|
||||
@ -814,7 +739,6 @@ void FileDialog::_update_drives() {
|
||||
bool FileDialog::default_show_hidden_files = false;
|
||||
|
||||
void FileDialog::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed);
|
||||
@ -884,7 +808,6 @@ void FileDialog::set_default_show_hidden_files(bool p_show) {
|
||||
}
|
||||
|
||||
FileDialog::FileDialog() {
|
||||
|
||||
show_hidden_files = default_show_hidden_files;
|
||||
|
||||
mode_overrides_title = true;
|
||||
@ -1002,7 +925,6 @@ FileDialog::FileDialog() {
|
||||
}
|
||||
|
||||
FileDialog::~FileDialog() {
|
||||
|
||||
if (unregister_func)
|
||||
unregister_func(this);
|
||||
memdelete(dir_access);
|
||||
|
||||
Reference in New Issue
Block a user