diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-04 21:31:29 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-06-04 21:31:47 -0300 |
commit | 007efb6a20dcaa9230f1cfdc1cda92db24c5510f (patch) | |
tree | db29be67ba32768ba96037d06c82cb8f1ac7f1c2 /tools/editor | |
parent | 279b7921e8dc8feb44a7650b983f6b3878a01d14 (diff) |
-customizable shortcuts in editor
-editor settings now save to .tres instead of .xml
-buttons can now hold a shortcut
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/editor_node.cpp | 54 | ||||
-rw-r--r-- | tools/editor/editor_settings.cpp | 141 | ||||
-rw-r--r-- | tools/editor/editor_settings.h | 13 | ||||
-rw-r--r-- | tools/editor/project_settings.cpp | 2 | ||||
-rw-r--r-- | tools/editor/settings_config_dialog.cpp | 197 | ||||
-rw-r--r-- | tools/editor/settings_config_dialog.h | 13 |
6 files changed, 381 insertions, 39 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 5d0617d8ab..72d5e496d9 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -188,10 +188,10 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { if (!p_event.key.mod.shift && !p_event.key.mod.command) _editor_select(EDITOR_SCRIPT); break; - case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break; + /* case KEY_F5: _menu_option_confirm((p_event.key.mod.control&&p_event.key.mod.shift)?RUN_PLAY_CUSTOM_SCENE:RUN_PLAY,true); break; case KEY_F6: _menu_option_confirm(RUN_PLAY_SCENE,true); break; //case KEY_F7: _menu_option_confirm(RUN_PAUSE,true); break; - case KEY_F8: _menu_option_confirm(RUN_STOP,true); break; + case KEY_F8: _menu_option_confirm(RUN_STOP,true); break;*/ case KEY_F11: { if (p_event.key.mod.shift) { if (p_event.key.mod.control) { @@ -1794,18 +1794,18 @@ void EditorNode::_edit_current() { PopupMenu *p=object_menu->get_popup(); p->clear(); - p->add_item(TTR("Copy Params"),OBJECT_COPY_PARAMS); - p->add_item(TTR("Set Params"),OBJECT_PASTE_PARAMS); + p->add_shortcut(ED_SHORTCUT("property_editor/copy_params",TTR("Copy Params")),OBJECT_COPY_PARAMS); + p->add_shortcut(ED_SHORTCUT("property_editor/paste_params",TTR("Paste Params")),OBJECT_PASTE_PARAMS); p->add_separator(); - p->add_item(TTR("Paste Resource"),RESOURCE_PASTE); + p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource",TTR("Paste Resource")),RESOURCE_PASTE); if (is_resource) { - p->add_item(TTR("Copy Resource"),RESOURCE_COPY); - p->add_item(TTR("Make Built-In"),RESOURCE_UNREF); + p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource",TTR("Copy Resource")),RESOURCE_COPY); + p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource",TTR("Make Built-In")),RESOURCE_UNREF); } p->add_separator(); - p->add_item(TTR("Make Sub-Resources Unique"),OBJECT_UNIQUE_RESOURCES); + p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique",TTR("Make Sub-Resources Unique")),OBJECT_UNIQUE_RESOURCES); p->add_separator(); - p->add_icon_item(gui_base->get_icon("Help","EditorIcons"),"Class Reference",OBJECT_REQUEST_HELP); + p->add_icon_shortcut(gui_base->get_icon("Help","EditorIcons"),ED_SHORTCUT("property_editor/open_help",TTR("Open in Help")),OBJECT_REQUEST_HELP); List<MethodInfo> methods; current_obj->get_method_list(&methods); @@ -4700,10 +4700,10 @@ void EditorNode::_update_layouts_menu() { overridden_default_layout=-1; editor_layouts->set_size(Vector2()); - editor_layouts->add_item(TTR("Save Layout"), SETTINGS_LAYOUT_SAVE); - editor_layouts->add_item(TTR("Delete Layout"), SETTINGS_LAYOUT_DELETE); + editor_layouts->add_shortcut(ED_SHORTCUT("layout/save",TTR("Save Layout")), SETTINGS_LAYOUT_SAVE); + editor_layouts->add_shortcut(ED_SHORTCUT("layout/load",TTR("Load Layout")), SETTINGS_LAYOUT_DELETE); editor_layouts->add_separator(); - editor_layouts->add_item(TTR("Default"), SETTINGS_LAYOUT_DEFAULT); + editor_layouts->add_shortcut(ED_SHORTCUT("property_editor/reset",TTR("Default")), SETTINGS_LAYOUT_DEFAULT); Ref<ConfigFile> config; config.instance(); @@ -5588,21 +5588,21 @@ EditorNode::EditorNode() { file_menu->set_tooltip(TTR("Operations with scene files.")); p=file_menu->get_popup(); - p->add_item(TTR("New Scene"),FILE_NEW_SCENE); - p->add_item(TTR("New Inherited Scene.."),FILE_NEW_INHERITED_SCENE); - p->add_item(TTR("Open Scene.."),FILE_OPEN_SCENE,KEY_MASK_CMD+KEY_O); + p->add_shortcut(ED_SHORTCUT("editor/new_scene",TTR("New Scene")),FILE_NEW_SCENE); + p->add_shortcut(ED_SHORTCUT("editor/new_inherited_scene",TTR("New Inherited Scene..")),FILE_NEW_INHERITED_SCENE); + p->add_shortcut(ED_SHORTCUT("editor/open_scene",TTR("Open Scene.."),KEY_MASK_CMD+KEY_O),FILE_OPEN_SCENE); p->add_separator(); - p->add_item(TTR("Save Scene"),FILE_SAVE_SCENE,KEY_MASK_CMD+KEY_S); - p->add_item(TTR("Save Scene As.."),FILE_SAVE_AS_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S); + p->add_shortcut(ED_SHORTCUT("editor/save_scene",TTR("Save Scene"),KEY_MASK_CMD+KEY_S),FILE_SAVE_SCENE); + p->add_shortcut(ED_SHORTCUT("editor/save_scene_as",TTR("Save Scene As.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S),FILE_SAVE_AS_SCENE); p->add_separator(); - p->add_item(TTR("Close Scene"),FILE_CLOSE,KEY_MASK_SHIFT+KEY_MASK_CTRL+KEY_W); + p->add_shortcut(ED_SHORTCUT("editor/close_scene",TTR("Close Scene"),KEY_MASK_SHIFT+KEY_MASK_CTRL+KEY_W),FILE_CLOSE); p->add_separator(); - p->add_item(TTR("Close Goto Prev. Scene"),FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P); + //p->add_shortcut(ED_SHORTCUT("editor/save_scene",TTR("Close Goto Prev. Scene")),FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P); p->add_submenu_item(TTR("Open Recent"),"RecentScenes",FILE_OPEN_RECENT); p->add_separator(); - p->add_item(TTR("Quick Open Scene.."),FILE_QUICK_OPEN_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O); - p->add_item(TTR("Quick Open Script.."),FILE_QUICK_OPEN_SCRIPT,KEY_MASK_ALT+KEY_MASK_CMD+KEY_O); - p->add_item(TTR("Quick Search File.."),FILE_QUICK_OPEN_FILE,KEY_MASK_ALT+KEY_MASK_CMD+KEY_P); + p->add_shortcut(ED_SHORTCUT("editor/quick_open_scene",TTR("Quick Open Scene.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCENE); + p->add_shortcut(ED_SHORTCUT("editor/quick_open_script",TTR("Quick Open Script.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCRIPT); + p->add_shortcut(ED_SHORTCUT("editor/quick_filter_files",TTR("Quick Filter Files.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_P),FILE_QUICK_OPEN_FILE); p->add_separator(); PopupMenu *pm_export = memnew(PopupMenu ); @@ -5733,7 +5733,8 @@ EditorNode::EditorNode() { play_button->set_icon(gui_base->get_icon("MainPlay","EditorIcons")); play_button->set_focus_mode(Control::FOCUS_NONE); play_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY)); - play_button->set_tooltip(TTR("Play the project (F5).")); + play_button->set_tooltip(TTR("Play the project.")); + play_button->set_shortcut(ED_SHORTCUT("editor/play",TTR("Play"),KEY_F5)); @@ -5746,6 +5747,7 @@ EditorNode::EditorNode() { pause_button->set_tooltip(TTR("Pause the scene")); pause_button->set_disabled(true); play_hb->add_child(pause_button); + pause_button->set_shortcut(ED_SHORTCUT("editor/pause_scene",TTR("Pause Scene"),KEY_F7)); stop_button = memnew( ToolButton ); @@ -5754,7 +5756,8 @@ EditorNode::EditorNode() { stop_button->set_focus_mode(Control::FOCUS_NONE); stop_button->set_icon(gui_base->get_icon("MainStop","EditorIcons")); stop_button->connect("pressed", this,"_menu_option",make_binds(RUN_STOP)); - stop_button->set_tooltip(TTR("Stop the scene (F8).")); + stop_button->set_tooltip(TTR("Stop the scene.")); + stop_button->set_shortcut(ED_SHORTCUT("editor/stop",TTR("Stop"),KEY_F8)); run_native = memnew( EditorRunNative); play_hb->add_child(run_native); @@ -5774,7 +5777,8 @@ EditorNode::EditorNode() { play_scene_button->set_focus_mode(Control::FOCUS_NONE); play_scene_button->set_icon(gui_base->get_icon("PlayScene","EditorIcons")); play_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_SCENE)); - play_scene_button->set_tooltip(TTR("Play the edited scene (F6).")); + play_scene_button->set_tooltip(TTR("Play the edited scene.")); + play_scene_button->set_shortcut(ED_SHORTCUT("editor/play_scene",TTR("Play Scene"),KEY_F6)); play_custom_scene_button = memnew( ToolButton ); play_hb->add_child(play_custom_scene_button); diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 93b3369aaf..9dd00688c9 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -45,6 +45,7 @@ #include "io/file_access_memory.h" #include "io/translation_loader_po.h" #include "io/compression.h" +#include "os/keyboard.h" Ref<EditorSettings> EditorSettings::singleton=NULL; @@ -57,6 +58,26 @@ EditorSettings *EditorSettings::get_singleton() { bool EditorSettings::_set(const StringName& p_name, const Variant& p_value) { _THREAD_SAFE_METHOD_ + + if (p_name.operator String()=="shortcuts") { + + Array arr=p_value; + ERR_FAIL_COND_V(arr.size() && arr.size()&1,true); + print_line("shortcuts: "+Variant(arr).get_construct_string()); + for(int i=0;i<arr.size();i+=2) { + + String name = arr[i]; + InputEvent shortcut = arr[i+1]; + + Ref<ShortCut> sc; + sc.instance(); + sc->set_shortcut(shortcut); + add_shortcut(name,sc); + } + + return true; + } + if (p_value.get_type()==Variant::NIL) props.erase(p_name); else { @@ -74,6 +95,25 @@ bool EditorSettings::_get(const StringName& p_name,Variant &r_ret) const { _THREAD_SAFE_METHOD_ + if (p_name.operator String()=="shortcuts") { + + Array arr; + for (const Map<String,Ref<ShortCut> >::Element *E=shortcuts.front();E;E=E->next()) { + + Ref<ShortCut> sc=E->get(); + if (!sc->has_meta("original")) + continue; //this came from settings but is not any longer used + + InputEvent original = sc->get_meta("original"); + if (sc->is_shortcut(original) || (original.type==InputEvent::NONE && sc->get_shortcut().type==InputEvent::NONE)) + continue; //not changed from default, don't save + arr.push_back(E->key()); + arr.push_back(sc->get_shortcut()); + } + r_ret=arr; + return true; + } + const VariantContainer *v=props.getptr(p_name); if (!v) return false; @@ -126,6 +166,8 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back( pi ); } + + p_list->push_back(PropertyInfo(Variant::ARRAY,"shortcuts",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); //do not edit } bool EditorSettings::has(String p_var) const { @@ -173,7 +215,7 @@ void EditorSettings::create() { String config_path; String config_dir; - String config_file="editor_settings.xml"; + //String config_file="editor_settings.xml"; Ref<ConfigFile> extra_config = memnew(ConfigFile); String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); @@ -263,17 +305,26 @@ void EditorSettings::create() { // path at least is validated, so validate config file - config_file_path = config_path+"/"+config_dir+"/"+config_file; + config_file_path = config_path+"/"+config_dir+"/editor_settings.tres"; - if (!dir->file_exists(config_file)) { - memdelete(dir); - WARN_PRINT("Config file does not exist, creating."); - goto fail; + String open_path = config_file_path; + + if (!dir->file_exists("editor_settings.tres")) { + + open_path = config_path+"/"+config_dir+"/editor_settings.xml"; + + if (!dir->file_exists("editor_settings.xml")) { + + memdelete(dir); + WARN_PRINT("Config file does not exist, creating."); + goto fail; + } } memdelete(dir); - singleton = ResourceLoader::load(config_file_path,"EditorSettings"); + singleton = ResourceLoader::load(open_path,"EditorSettings"); + if (singleton.is_null()) { WARN_PRINT("Could not open config file."); goto fail; @@ -865,6 +916,42 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { return false; } + +void EditorSettings::add_shortcut(const String& p_name, Ref<ShortCut> &p_shortcut) { + + shortcuts[p_name]=p_shortcut; +} + +bool EditorSettings::is_shortcut(const String&p_name, const InputEvent &p_event) const{ + + const Map<String,Ref<ShortCut> >::Element *E=shortcuts.find(p_name); + if (!E) { + ERR_EXPLAIN("Unknown Shortcut: "+p_name); + ERR_FAIL_V(false); + } + + return E->get()->is_shortcut(p_event); + +} + +Ref<ShortCut> EditorSettings::get_shortcut(const String&p_name) const{ + + const Map<String,Ref<ShortCut> >::Element *E=shortcuts.find(p_name); + if (!E) + return Ref<ShortCut>(); + + return E->get(); +} + +void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) { + + for (const Map<String,Ref<ShortCut> >::Element*E=shortcuts.front();E;E=E->next()) { + + r_shortcuts->push_back(E->key()); + } +} + + void EditorSettings::_bind_methods() { ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase); @@ -920,4 +1007,44 @@ EditorSettings::~EditorSettings() { // singleton=NULL; } +Ref<ShortCut> ED_GET_SHORTCUT(const String& p_path) { + + Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path); + if (!sc.is_valid()) { + ERR_EXPLAIN("Used ED_GET_SHORTCUT with invalid shortcut: "+p_path); + ERR_FAIL_COND_V(!sc.is_valid(),sc); + } + + return sc; +} + +Ref<ShortCut> ED_SHORTCUT(const String& p_path,const String& p_name,uint32_t p_keycode) { + + InputEvent ie; + if (p_keycode) { + ie.type=InputEvent::KEY; + ie.key.unicode=p_keycode&KEY_CODE_MASK; + ie.key.scancode=p_keycode&KEY_CODE_MASK; + ie.key.mod.shift=bool(p_keycode&KEY_MASK_SHIFT); + ie.key.mod.alt=bool(p_keycode&KEY_MASK_ALT); + ie.key.mod.control=bool(p_keycode&KEY_MASK_CTRL); + ie.key.mod.meta=bool(p_keycode&KEY_MASK_META); + } + + Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path); + if (sc.is_valid()) { + + sc->set_name(p_name); //keep name (the ones that come from disk have no name) + sc->set_meta("original",ie); //to compare against changes + return sc; + } + + sc.instance(); + sc->set_name(p_name); + sc->set_shortcut(ie); + sc->set_meta("original",ie); //to compare against changes + EditorSettings::get_singleton()->add_shortcut(p_path,sc); + + return sc; +} diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h index 879c97c349..60333b5811 100644 --- a/tools/editor/editor_settings.h +++ b/tools/editor/editor_settings.h @@ -35,6 +35,8 @@ #include "os/thread_safe.h" #include "core/io/config_file.h" #include "translation.h" +#include "scene/gui/input_action.h" + class EditorPlugin; class EditorSettings : public Resource { @@ -95,6 +97,8 @@ private: Vector<Ref<Translation> > translations; + Map<String,Ref<ShortCut> > shortcuts; + protected: static void _bind_methods(); @@ -142,6 +146,11 @@ public: bool save_text_editor_theme(); bool save_text_editor_theme_as(String p_file); + void add_shortcut(const String& p_name,Ref<ShortCut>& p_shortcut); + bool is_shortcut(const String&p_name,const InputEvent& p_event) const; + Ref<ShortCut> get_shortcut(const String&p_name) const; + void get_shortcut_list(List<String> *r_shortcuts); + EditorSettings(); ~EditorSettings(); @@ -152,4 +161,8 @@ public: #define EDITOR_DEF(m_var,m_val) _EDITOR_DEF(m_var,Variant(m_val)) Variant _EDITOR_DEF( const String& p_var, const Variant& p_default); +#define ED_IS_SHORTCUT(p_name,p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name,p_ev)) +Ref<ShortCut> ED_SHORTCUT(const String& p_path,const String& p_name,uint32_t p_keycode=0); +Ref<ShortCut> ED_GET_SHORTCUT(const String& p_path); + #endif // EDITOR_SETTINGS_H diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 1f49f2a9fc..86f1ae6f9f 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -330,7 +330,7 @@ void ProjectSettings::_add_item(int p_item){ press_a_key_label->set_text(TTR("Press a Key..")); last_wait_for_key=InputEvent(); - press_a_key->popup_centered(Size2(250,80)); + press_a_key->popup_centered(Size2(250,80)*EDSCALE); press_a_key->grab_focus(); } break; case InputEvent::MOUSE_BUTTON: { diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp index 79bcaa4dae..e1a2ea162e 100644 --- a/tools/editor/settings_config_dialog.cpp +++ b/tools/editor/settings_config_dialog.cpp @@ -31,6 +31,9 @@ #include "scene/gui/margin_container.h" #include "globals.h" #include "editor_file_system.h" +#include "editor_node.h" +#include "os/keyboard.h" + void EditorSettingsDialog::ok_pressed() { if (!EditorSettings::get_singleton()) @@ -79,6 +82,7 @@ void EditorSettingsDialog::popup_edit_settings() { search_box->select_all(); search_box->grab_focus(); + _update_shortcuts(); popup_centered_ratio(0.7); } @@ -101,11 +105,171 @@ void EditorSettingsDialog::_notification(int p_what) { } } + +void EditorSettingsDialog::_update_shortcuts() { + + shortcuts->clear(); + + List<String> slist; + EditorSettings::get_singleton()->get_shortcut_list(&slist); + TreeItem *root = shortcuts->create_item(); + + Map<String,TreeItem*> sections; + + for(List<String>::Element *E=slist.front();E;E=E->next()) { + + Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(E->get()); + if (!sc->has_meta("original")) + continue; + + InputEvent original = sc->get_meta("original"); + + String section_name = E->get().get_slice("/",0); + + TreeItem *section; + + if (sections.has(section_name)) { + section=sections[section_name]; + } else { + section = shortcuts->create_item(root); + section->set_text(0,section_name.capitalize()); + + sections[section_name]=section; + section->set_custom_bg_color(0,get_color("prop_subsection","Editor")); + section->set_custom_bg_color(1,get_color("prop_subsection","Editor")); + + } + + TreeItem *item = shortcuts->create_item(section); + + + item->set_text(0,sc->get_name()); + item->set_text(1,sc->get_as_text()); + if (!sc->is_shortcut(original) && !(sc->get_shortcut().type==InputEvent::NONE && original.type==InputEvent::NONE)) { + item->add_button(1,get_icon("Reload","EditorIcons"),2); + } + item->add_button(1,get_icon("Edit","EditorIcons"),0); + item->add_button(1,get_icon("Close","EditorIcons"),1); + item->set_tooltip(0,E->get()); + item->set_metadata(0,E->get()); + } + + + + +} + +void EditorSettingsDialog::_shortcut_button_pressed(Object* p_item,int p_column,int p_idx) { + + TreeItem *ti=p_item->cast_to<TreeItem>(); + ERR_FAIL_COND(!ti); + + String item = ti->get_metadata(0); + Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(item); + + if (p_idx==0) { + press_a_key_label->set_text(TTR("Press a Key..")); + last_wait_for_key=InputEvent(); + press_a_key->popup_centered(Size2(250,80)*EDSCALE); + press_a_key->grab_focus(); + press_a_key->get_ok()->set_focus_mode(FOCUS_NONE); + press_a_key->get_cancel()->set_focus_mode(FOCUS_NONE); + shortcut_configured=item; + + } else if (p_idx==1) {//erase + if (!sc.is_valid()) + return; //pointless, there is nothing + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Erase Shortcut"); + ur->add_do_method(sc.ptr(),"set_shortcut",InputEvent()); + ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut()); + ur->add_do_method(this,"_update_shortcuts"); + ur->add_undo_method(this,"_update_shortcuts"); + ur->add_do_method(this,"_settings_changed"); + ur->add_undo_method(this,"_settings_changed"); + ur->commit_action(); + } else if (p_idx==2) {//revert to original + if (!sc.is_valid()) + return; //pointless, there is nothing + + InputEvent original = sc->get_meta("original"); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Restore Shortcut"); + ur->add_do_method(sc.ptr(),"set_shortcut",original); + ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut()); + ur->add_do_method(this,"_update_shortcuts"); + ur->add_undo_method(this,"_update_shortcuts"); + ur->add_do_method(this,"_settings_changed"); + ur->add_undo_method(this,"_settings_changed"); + ur->commit_action(); + } +} + + +void EditorSettingsDialog::_wait_for_key(const InputEvent& p_event) { + + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode!=0) { + + last_wait_for_key=p_event; + String str=keycode_get_string(p_event.key.scancode).capitalize(); + if (p_event.key.mod.meta) + str=TTR("Meta+")+str; + if (p_event.key.mod.shift) + str=TTR("Shift+")+str; + if (p_event.key.mod.alt) + str=TTR("Alt+")+str; + if (p_event.key.mod.control) + str=TTR("Control+")+str; + + + press_a_key_label->set_text(str); + press_a_key->accept_event(); + + } +} + + + + +void EditorSettingsDialog::_press_a_key_confirm() { + + if (last_wait_for_key.type!=InputEvent::KEY) + return; + + InputEvent ie; + ie.type=InputEvent::KEY; + ie.key.scancode=last_wait_for_key.key.scancode; + ie.key.mod=last_wait_for_key.key.mod; + + Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(shortcut_configured); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Shortcut '"+shortcut_configured+"'"); + ur->add_do_method(sc.ptr(),"set_shortcut",ie); + ur->add_undo_method(sc.ptr(),"set_shortcut",sc->get_shortcut()); + ur->add_do_method(this,"_update_shortcuts"); + ur->add_undo_method(this,"_update_shortcuts"); + ur->add_do_method(this,"_settings_changed"); + ur->add_undo_method(this,"_settings_changed"); + ur->commit_action(); + + + +} + void EditorSettingsDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_settings_save"),&EditorSettingsDialog::_settings_save); ObjectTypeDB::bind_method(_MD("_settings_changed"),&EditorSettingsDialog::_settings_changed); ObjectTypeDB::bind_method(_MD("_clear_search_box"),&EditorSettingsDialog::_clear_search_box); + ObjectTypeDB::bind_method(_MD("_shortcut_button_pressed"),&EditorSettingsDialog::_shortcut_button_pressed); + ObjectTypeDB::bind_method(_MD("_update_shortcuts"),&EditorSettingsDialog::_update_shortcuts); + ObjectTypeDB::bind_method(_MD("_press_a_key_confirm"),&EditorSettingsDialog::_press_a_key_confirm); + ObjectTypeDB::bind_method(_MD("_wait_for_key"),&EditorSettingsDialog::_wait_for_key); + } EditorSettingsDialog::EditorSettingsDialog() { @@ -145,13 +309,34 @@ EditorSettingsDialog::EditorSettingsDialog() { vbc = memnew( VBoxContainer ); tabs->add_child(vbc); - vbc->set_name(TTR("Plugins")); - - hbc = memnew( HBoxContainer ); - vbc->add_child(hbc); - hbc->add_child( memnew( Label(TTR("Plugin List:")+" ") )); - hbc->add_spacer(); + vbc->set_name(TTR("Shortcuts")); + + shortcuts = memnew( Tree ); + vbc->add_margin_child("Shortcut List:",shortcuts,true); + shortcuts->set_columns(2); + shortcuts->set_hide_root(true); + //shortcuts->set_hide_folding(true); + shortcuts->set_column_titles_visible(true); + shortcuts->set_column_title(0,"Name"); + shortcuts->set_column_title(1,"Binding"); + shortcuts->connect("button_pressed",this,"_shortcut_button_pressed"); + + press_a_key = memnew( ConfirmationDialog ); + press_a_key->set_focus_mode(FOCUS_ALL); + add_child(press_a_key); + + l = memnew( Label ); + l->set_text(TTR("Press a Key..")); + l->set_area_as_parent_rect(); + l->set_align(Label::ALIGN_CENTER); + l->set_margin(MARGIN_TOP,20); + l->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,30); + press_a_key_label=l; + press_a_key->add_child(l); + press_a_key->connect("input_event",this,"_wait_for_key"); + press_a_key->connect("confirmed",this,"_press_a_key_confirm"); //Button *load = memnew( Button ); + //load->set_text("Load.."); //hbc->add_child(load); diff --git a/tools/editor/settings_config_dialog.h b/tools/editor/settings_config_dialog.h index 5085132108..c930de6a77 100644 --- a/tools/editor/settings_config_dialog.h +++ b/tools/editor/settings_config_dialog.h @@ -50,6 +50,13 @@ class EditorSettingsDialog : public AcceptDialog { Timer *timer; + Tree *shortcuts; + + ConfirmationDialog *press_a_key; + Label *press_a_key_label; + InputEvent last_wait_for_key; + String shortcut_configured; + virtual void cancel_pressed(); virtual void ok_pressed(); @@ -59,8 +66,14 @@ class EditorSettingsDialog : public AcceptDialog { void _notification(int p_what); + void _press_a_key_confirm(); + void _wait_for_key(const InputEvent& p_event); + void _clear_search_box(); + void _update_shortcuts(); + void _shortcut_button_pressed(Object* p_item,int p_column,int p_idx); + protected: static void _bind_methods(); |