diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/editor/editor_file_system.cpp | 7 | ||||
-rw-r--r-- | tools/editor/editor_file_system.h | 1 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 1 | ||||
-rw-r--r-- | tools/editor/editor_resource_preview.cpp | 34 | ||||
-rw-r--r-- | tools/editor/editor_resource_preview.h | 4 | ||||
-rw-r--r-- | tools/editor/plugins/canvas_item_editor_plugin.cpp | 47 | ||||
-rw-r--r-- | tools/editor/quick_open.cpp | 74 | ||||
-rw-r--r-- | tools/editor/quick_open.h | 3 | ||||
-rw-r--r-- | tools/editor/scenes_dock.cpp | 25 | ||||
-rw-r--r-- | tools/editor/scenes_dock.h | 2 |
10 files changed, 158 insertions, 40 deletions
diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp index 1f414f80a0..cb7cefea26 100644 --- a/tools/editor/editor_file_system.cpp +++ b/tools/editor/editor_file_system.cpp @@ -34,6 +34,7 @@ #include "editor_node.h" #include "io/resource_saver.h" #include "editor_settings.h" +#include "editor_resource_preview.h" EditorFileSystem *EditorFileSystem::singleton=NULL; @@ -848,6 +849,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S continue; } + if (_check_meta_sources(p_dir->files[i]->meta)) { ItemAction ia; ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; @@ -858,6 +860,8 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S } else { p_dir->files[i]->meta.sources_changed=false; } + + EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i)); } for(int i=0;i<p_dir->subdirs.size();i++) { @@ -1328,6 +1332,7 @@ void EditorFileSystem::update_file(const String& p_file) { fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file); fs->files[cpos]->meta=_get_meta(p_file); + EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file); call_deferred("emit_signal","filesystem_changed"); //update later } @@ -1341,6 +1346,8 @@ void EditorFileSystem::_bind_methods() { } + + EditorFileSystem::EditorFileSystem() { diff --git a/tools/editor/editor_file_system.h b/tools/editor/editor_file_system.h index b96e947569..fb768fb358 100644 --- a/tools/editor/editor_file_system.h +++ b/tools/editor/editor_file_system.h @@ -236,6 +236,7 @@ public: EditorFileSystemDirectory *get_path(const String& p_path); String get_file_type(const String& p_file) const; EditorFileSystemDirectory* find_file(const String& p_file,int* r_index) const; + EditorFileSystem(); ~EditorFileSystem(); }; diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 2bba97251d..ae632ab381 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -2846,6 +2846,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { if (mt!=E->get()->get_last_modified_time()) { E->get()->reload_from_file(); } + } diff --git a/tools/editor/editor_resource_preview.cpp b/tools/editor/editor_resource_preview.cpp index 8975c0ec35..750a172d1e 100644 --- a/tools/editor/editor_resource_preview.cpp +++ b/tools/editor/editor_resource_preview.cpp @@ -66,16 +66,20 @@ void EditorResourcePreview::_preview_ready(const String& p_str,const Ref<Texture String path = p_str; uint32_t hash=0; + uint64_t modified_time=0; if (p_str.begins_with("ID:")) { hash=p_str.get_slicec(':',2).to_int(); path="ID:"+p_str.get_slicec(':',1); + } else { + modified_time = FileAccess::get_modified_time(path); } Item item; item.order=order++; item.preview=p_texture; item.last_hash=hash; + item.modified_time=modified_time; cache[path]=item; @@ -263,6 +267,8 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource>& p preview_mutex->lock(); String path_id = "ID:"+itos(p_res->get_instance_ID()); + + if (cache.has(path_id) && cache[path_id].last_hash==p_res->hash_edited_version()) { cache[path_id].order=order++; @@ -272,6 +278,8 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource>& p } + cache.erase(path_id); //erase if exists, since it will be regen + //print_line("send to thread "+p_path); QueueItem item; item.function=p_receiver_func; @@ -322,6 +330,32 @@ EditorResourcePreview* EditorResourcePreview::get_singleton() { void EditorResourcePreview::_bind_methods() { ObjectTypeDB::bind_method("_preview_ready",&EditorResourcePreview::_preview_ready); + ObjectTypeDB::bind_method(_MD("check_for_invalidation","path"),&EditorResourcePreview::check_for_invalidation); + + + ADD_SIGNAL(MethodInfo("preview_invalidated",PropertyInfo(Variant::STRING,"path"))); +} + +bool EditorResourcePreview::check_for_invalidation(const String& p_path) { + + preview_mutex->lock(); + + bool call_invalidated=false; + if (cache.has(p_path)) { + + uint64_t modified_time = FileAccess::get_modified_time(p_path); + if (modified_time!=cache[p_path].modified_time) { + cache.erase(p_path); + call_invalidated=true; + } + } + + preview_mutex->unlock(); + + if (call_invalidated) {//do outside mutex + call_deferred("emit_signal","preview_invalidated",p_path); + } + } EditorResourcePreview::EditorResourcePreview() { diff --git a/tools/editor/editor_resource_preview.h b/tools/editor/editor_resource_preview.h index 63dc5c3dd3..fed8f129ed 100644 --- a/tools/editor/editor_resource_preview.h +++ b/tools/editor/editor_resource_preview.h @@ -93,6 +93,7 @@ class EditorResourcePreview : public Node { Ref<Texture> preview; int order; uint32_t last_hash; + uint64_t modified_time; }; int order; @@ -106,6 +107,8 @@ class EditorResourcePreview : public Node { void _thread(); Vector<Ref<EditorResourcePreviewGenerator> > preview_generators; + + protected: static void _bind_methods(); @@ -118,6 +121,7 @@ public: void queue_edited_resource_preview(const Ref<Resource>& p_path, Object* p_receiver, const StringName& p_receiver_func, const Variant& p_userdata); void add_preview_generator(const Ref<EditorResourcePreviewGenerator>& p_generator); + bool check_for_invalidation(const String& p_path); EditorResourcePreview(); ~EditorResourcePreview(); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 81601a81a7..caa09fba35 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -3374,25 +3374,25 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { PopupMenu *p; p = edit_menu->get_popup(); - p->add_check_item(TTR("Use Snap"),SNAP_USE); - p->add_check_item(TTR("Show Grid"),SNAP_SHOW_GRID); - p->add_check_item(TTR("Use Rotation Snap"),SNAP_USE_ROTATION); - p->add_check_item(TTR("Snap Relative"),SNAP_RELATIVE); - p->add_item(TTR("Configure Snap.."),SNAP_CONFIGURE); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_snap", TTR("Use Snap")), SNAP_USE); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid")), SNAP_SHOW_GRID); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_relative", TTR("Snap Relative")), SNAP_RELATIVE); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap..")), SNAP_CONFIGURE); p->add_separator(); - p->add_check_item(TTR("Use Pixel Snap"),SNAP_USE_PIXEL); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_pixel_snap", TTR("Use Pixel Snap")), SNAP_USE_PIXEL); p->add_separator(); - p->add_item(TTR("Expand to Parent"),EXPAND_TO_PARENT,KEY_MASK_CMD|KEY_P); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/expand_to_parent", TTR("Expand to Parent"), KEY_MASK_CMD | KEY_P), EXPAND_TO_PARENT); p->add_separator(); p->add_submenu_item(TTR("Skeleton.."),"skeleton"); PopupMenu *p2 = memnew(PopupMenu); p->add_child(p2); p2->set_name("skeleton"); - p2->add_item(TTR("Make Bones"),SKELETON_MAKE_BONES,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_B); - p2->add_item(TTR("Clear Bones"),SKELETON_CLEAR_BONES); + p2->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_make_bones", TTR("Make Bones"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B ),SKELETON_MAKE_BONES); + p2->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_bones", TTR("Clear Bones")), SKELETON_CLEAR_BONES); p2->add_separator(); - p2->add_item(TTR("Make IK Chain"),SKELETON_SET_IK_CHAIN); - p2->add_item(TTR("Clear IK Chain"),SKELETON_CLEAR_IK_CHAIN); + p2->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN); + p2->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN); p2->connect("item_pressed", this,"_popup_callback"); @@ -3409,13 +3409,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p = view_menu->get_popup(); - p->add_item(TTR("Zoom In"),ZOOM_IN); - p->add_item(TTR("Zoom Out"),ZOOM_OUT); - p->add_item(TTR("Zoom Reset"),ZOOM_RESET); - p->add_item(TTR("Zoom Set.."),ZOOM_SET); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_in", TTR("Zoom In")), ZOOM_IN); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_out", TTR("Zoom Out")), ZOOM_OUT); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset")), ZOOM_RESET); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_set", TTR("Zoom Set..")), ZOOM_SET); p->add_separator(); - p->add_item(TTR("Center Selection"), VIEW_CENTER_TO_SELECTION, KEY_F); - p->add_item(TTR("Frame Selection"), VIEW_FRAME_TO_SELECTION, KEY_MASK_CMD|KEY_F); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_CMD | KEY_F), VIEW_FRAME_TO_SELECTION); anchor_menu = memnew( MenuButton ); anchor_menu->set_text(TTR("Anchor")); @@ -3458,7 +3458,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_insert_button = memnew( Button ); key_insert_button->set_focus_mode(FOCUS_NONE); key_insert_button->connect("pressed",this,"_popup_callback",varray(ANIM_INSERT_KEY)); - key_insert_button->set_tooltip(TTR("Insert Keys (Ins)")); + key_insert_button->set_tooltip(TTR("Insert Keys")); + key_insert_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key", TTR("Insert Key"), KEY_INSERT)); animation_hb->add_child(key_insert_button); @@ -3469,12 +3470,12 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p = animation_menu->get_popup(); - p->add_item(TTR("Insert Key"),ANIM_INSERT_KEY,KEY_INSERT); - p->add_item(TTR("Insert Key (Existing Tracks)"),ANIM_INSERT_KEY_EXISTING,KEY_MASK_CMD+KEY_INSERT); + p->add_shortcut(ED_GET_SHORTCUT("canvas_item_editor/anim_insert_key"), ANIM_INSERT_KEY); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_insert_key_existing_tracks", TTR("Insert Key (Existing Tracks)"), KEY_MASK_CMD+KEY_INSERT), ANIM_INSERT_KEY_EXISTING); p->add_separator(); - p->add_item(TTR("Copy Pose"),ANIM_COPY_POSE); - p->add_item(TTR("Paste Pose"),ANIM_PASTE_POSE); - p->add_item(TTR("Clear Pose"),ANIM_CLEAR_POSE,KEY_MASK_SHIFT|KEY_K); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_copy_pose", TTR("Copy Pose")), ANIM_COPY_POSE); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_paste_pose", TTR("Paste Pose")), ANIM_PASTE_POSE); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/anim_clear_pose", TTR("Clear Pose"), KEY_MASK_SHIFT | KEY_K), ANIM_CLEAR_POSE); snap_dialog = memnew( SnapDialog ); snap_dialog->connect("confirmed",this,"_snap_changed"); diff --git a/tools/editor/quick_open.cpp b/tools/editor/quick_open.cpp index fc2a2241ab..adb08b65d6 100644 --- a/tools/editor/quick_open.cpp +++ b/tools/editor/quick_open.cpp @@ -109,16 +109,16 @@ void EditorQuickOpen::_sbox_input(const InputEvent& p_ie) { } -void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { +void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String, Ref<Texture> > > &list) { if (!add_directories) { for(int i=0;i<efsd->get_subdir_count();i++) { - _parse_fs(efsd->get_subdir(i)); + _parse_fs(efsd->get_subdir(i), list); } } - TreeItem *root = search_options->get_root(); + String search_text = search_box->get_text(); if (add_directories) { String path = efsd->get_path(); @@ -126,11 +126,26 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { path+="/"; if (path!="res://") { path=path.substr(6,path.length()); - if (search_box->get_text().is_subsequence_ofi(path)) { - TreeItem *ti = search_options->create_item(root); - ti->set_text(0,path); - Ref<Texture> icon = get_icon("folder","FileDialog"); - ti->set_icon(0,icon); + if (search_text.is_subsequence_ofi(path)) { + Pair< String, Ref<Texture> > pair; + pair.first = path; + pair.second = get_icon("folder", "FileDialog"); + if (list.size() > 0) { + + float this_sim = search_text.to_lower().similarity(path.to_lower()); + float other_sim = search_text.to_lower().similarity(list[0].first.to_lower()); + int pos = 1; + + while (pos < list.size() && this_sim < other_sim) { + other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower()); + } + + pos = this_sim > other_sim ? pos - 1 : pos; + list.insert(pos, pair); + + } else { + list.push_back(pair); + } } } } @@ -138,12 +153,29 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { String file = efsd->get_file_path(i); file=file.substr(6,file.length()); - if (ObjectTypeDB::is_type(efsd->get_file_type(i),base_type) && (search_box->get_text().is_subsequence_ofi(file))) { - TreeItem *ti = search_options->create_item(root); - ti->set_text(0,file); - Ref<Texture> icon = get_icon( (has_icon(efsd->get_file_type(i),ei)?efsd->get_file_type(i):ot),ei); - ti->set_icon(0,icon); + if (ObjectTypeDB::is_type(efsd->get_file_type(i),base_type) && (search_text.is_subsequence_ofi(file))) { + Pair< String, Ref<Texture> > pair; + pair.first = file; + pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei); + + if (list.size() > 0) { + + float this_sim = search_text.to_lower().similarity(file.to_lower()); + float other_sim = search_text.to_lower().similarity(list[0].first.to_lower()); + int pos = 1; + + while (pos < list.size() && this_sim < other_sim) { + other_sim = search_text.to_lower().similarity(list[pos++].first.to_lower()); + } + + pos = this_sim > other_sim ? pos - 1 : pos; + list.insert(pos, pair); + + } else { + + list.push_back(pair); + } } } @@ -151,7 +183,7 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { if (add_directories) { for(int i=0;i<efsd->get_subdir_count();i++) { - _parse_fs(efsd->get_subdir(i)); + _parse_fs(efsd->get_subdir(i), list); } } @@ -159,10 +191,20 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd) { void EditorQuickOpen::_update_search() { - search_options->clear(); TreeItem *root = search_options->create_item(); - _parse_fs(EditorFileSystem::get_singleton()->get_filesystem()); + EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_filesystem(); + Vector< Pair< String, Ref<Texture> > > list; + + _parse_fs(efsd, list); + + //String best_match = list[0]; + + for (int i = 0; i < list.size(); i++) { + TreeItem *ti = search_options->create_item(root); + ti->set_text(0, list[i].first); + ti->set_icon(0, list[i].second); + } if (root->get_children()) { TreeItem *ti = root->get_children(); diff --git a/tools/editor/quick_open.h b/tools/editor/quick_open.h index 520f7e569d..45527090b7 100644 --- a/tools/editor/quick_open.h +++ b/tools/editor/quick_open.h @@ -32,6 +32,7 @@ #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" #include "editor_file_system.h" +#include "pair.h" class EditorQuickOpen : public ConfirmationDialog { OBJ_TYPE(EditorQuickOpen,ConfirmationDialog ) @@ -47,7 +48,7 @@ class EditorQuickOpen : public ConfirmationDialog { void _update_search(); void _sbox_input(const InputEvent& p_ie); - void _parse_fs(EditorFileSystemDirectory *efsd); + void _parse_fs(EditorFileSystemDirectory *efsd, Vector< Pair< String,Ref <Texture> > > &list); void _confirmed(); diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp index 0df4dfacc1..fa7c898f91 100644 --- a/tools/editor/scenes_dock.cpp +++ b/tools/editor/scenes_dock.cpp @@ -189,6 +189,7 @@ void ScenesDock::_notification(int p_what) { initialized=true; EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_fs_changed"); + EditorResourcePreview::get_singleton()->connect("preview_invalidated",this,"_preview_invalidated"); button_reload->set_icon( get_icon("Reload","EditorIcons")); button_favorite->set_icon( get_icon("Favorites","EditorIcons")); @@ -663,6 +664,27 @@ void ScenesDock::_go_to_dir(const String& p_dir){ } + +void ScenesDock::_preview_invalidated(const String& p_path) { + + if (p_path.get_base_dir()==path && search_box->get_text()==String() && file_list_vb->is_visible()) { + + + for(int i=0;i<files->get_item_count();i++) { + + if (files->get_item_metadata(i)==p_path) { + //re-request preview + Array udata; + udata.resize(2); + udata[0]=i; + udata[1]=files->get_item_text(i); + EditorResourcePreview::get_singleton()->queue_resource_preview(p_path,this,"_thumbnail_done",udata); + break; + } + } + } +} + void ScenesDock::_fs_changed() { button_hist_prev->set_disabled(history_pos==0); @@ -1620,6 +1642,9 @@ void ScenesDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("drop_data_fw"), &ScenesDock::drop_data_fw); ObjectTypeDB::bind_method(_MD("_files_list_rmb_select"),&ScenesDock::_files_list_rmb_select); + ObjectTypeDB::bind_method(_MD("_preview_invalidated"),&ScenesDock::_preview_invalidated); + + ADD_SIGNAL(MethodInfo("instance")); ADD_SIGNAL(MethodInfo("open")); diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h index ed24711abb..0973fce250 100644 --- a/tools/editor/scenes_dock.h +++ b/tools/editor/scenes_dock.h @@ -168,6 +168,8 @@ class ScenesDock : public VBoxContainer { bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); + void _preview_invalidated(const String& p_path); + protected: void _notification(int p_what); static void _bind_methods(); |