diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-01-07 07:50:26 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-01-07 07:50:26 +0100 |
commit | a0c39a4b333a2f05c9bb2ccf1be71ac8e18fc9a9 (patch) | |
tree | 65adefee4110375ba3653c1b952217dbf1ea4390 | |
parent | c874ad3f52d383ea189f1cd70f07fb01b21e491f (diff) | |
parent | 3ca800226ece276d1ff568650134e8857840bfbb (diff) |
Merge pull request #3191 from neikeq/filedialog_hotkeys
Add keyboard shortcut to toggle "show hidden files" in FileDialog
-rw-r--r-- | scene/gui/control.cpp | 7 | ||||
-rw-r--r-- | scene/gui/control.h | 2 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 41 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 2 | ||||
-rw-r--r-- | tools/editor/editor_file_dialog.cpp | 45 | ||||
-rw-r--r-- | tools/editor/editor_file_dialog.h | 2 |
6 files changed, 97 insertions, 2 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 23a7ae00da..34864d68ec 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 280e88e85d..0ead632aab 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 955a02d0f9..5b57395e58 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 491655e4ce..b71a157fa7 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: diff --git a/tools/editor/editor_file_dialog.cpp b/tools/editor/editor_file_dialog.cpp index 28a9b63412..22cd3845e1 100644 --- a/tools/editor/editor_file_dialog.cpp +++ b/tools/editor/editor_file_dialog.cpp @@ -53,13 +53,52 @@ void EditorFileDialog::_notification(int p_what) { //RID ci = get_canvas_item(); //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); + } else if (p_what==NOTIFICATION_POPUP_HIDE) { + + set_process_unhandled_input(false); + } else if (p_what==EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - set_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); + bool show_hidden=EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"); + if (show_hidden_files!=show_hidden) + set_show_hidden_files(show_hidden); set_display_mode((DisplayMode)EditorSettings::get_singleton()->get("file_dialog/display_mode").operator int()); } } +void EditorFileDialog::_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) { + + bool show=!show_hidden_files; + set_show_hidden_files(show); + EditorSettings::get_singleton()->set("file_dialog/show_hidden_files",show); + } else { + handled=false; + } + + } break; + default: { handled=false; } + } + + if (handled) + accept_event(); + } + } +} + void EditorFileDialog::set_enable_multiple_selection(bool p_enable) { item_list->set_select_mode(p_enable?ItemList::SELECT_MULTI:ItemList::SELECT_SINGLE); @@ -151,6 +190,8 @@ void EditorFileDialog::_post_popup() { _update_favorites(); } + set_process_unhandled_input(true); + } void EditorFileDialog::_thumbnail_result(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata) { @@ -1049,6 +1090,8 @@ EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const{ void EditorFileDialog::_bind_methods() { + ObjectTypeDB::bind_method(_MD("_unhandled_input"),&EditorFileDialog::_unhandled_input); + ObjectTypeDB::bind_method(_MD("_item_selected"),&EditorFileDialog::_item_selected); ObjectTypeDB::bind_method(_MD("_item_db_selected"),&EditorFileDialog::_item_dc_selected); ObjectTypeDB::bind_method(_MD("_dir_entered"),&EditorFileDialog::_dir_entered); diff --git a/tools/editor/editor_file_dialog.h b/tools/editor/editor_file_dialog.h index db3201e5c4..3590964a51 100644 --- a/tools/editor/editor_file_dialog.h +++ b/tools/editor/editor_file_dialog.h @@ -176,6 +176,8 @@ private: void _thumbnail_done(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata); void _request_single_thumbnail(const String& p_path); + void _unhandled_input(const InputEvent& p_event); + protected: void _notification(int p_what); |