summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2015-12-29 00:36:48 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2016-01-02 12:58:38 +0100
commit3ca800226ece276d1ff568650134e8857840bfbb (patch)
tree9358010e66f63e475c59013d5ab71f2a5fbe0808 /scene/gui
parent4dba503fc3bee79ceedd69738c02f2fcf5cad27f (diff)
FileDialog: keyboard shortcut to toggle "show hidden files"
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp7
-rw-r--r--scene/gui/control.h2
-rw-r--r--scene/gui/file_dialog.cpp41
-rw-r--r--scene/gui/file_dialog.h2
4 files changed, 51 insertions, 1 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index ec4886a6ac..e01f2f8e8e 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -862,6 +862,13 @@ bool Control::window_has_modal_stack() const {
return data.window->window->modal_stack.size();
}
+bool Control::is_window_modal_on_top() const {
+
+ if (window_has_modal_stack())
+ return data.window->window->modal_stack.back()->get()==this;
+ return false;
+}
+
void Control::_window_cancel_tooltip() {
window->tooltip=NULL;
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 09a4b48e6b..cc8c157b1e 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -270,6 +270,8 @@ public:
void set_custom_minimum_size(const Size2& p_custom);
Size2 get_custom_minimum_size() const;
+ bool is_window_modal_on_top() const;
+
bool is_window() const;
Control *get_window() const;
Control *get_parent_control() const;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 9179d3a4e1..2a16810444 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -56,7 +56,42 @@ void FileDialog::_notification(int p_what) {
//RID ci = get_canvas_item();
//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
- }
+ }
+
+ 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;
+ default: { handled=false; }
+ }
+
+ if (handled)
+ accept_event();
+ }
+ }
}
void FileDialog::set_enable_multiple_selection(bool p_enable) {
@@ -114,6 +149,8 @@ void FileDialog::_post_popup() {
else
tree->grab_focus();
+ set_process_unhandled_input(true);
+
}
void FileDialog::_action_pressed() {
@@ -628,6 +665,8 @@ 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);
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 370088b215..0f6cb14668 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -117,6 +117,8 @@ private:
void _update_drives();
+ void _unhandled_input(const InputEvent& p_event);
+
virtual void _post_popup();
protected: