Path: blob/master/editor/file_system/dependency_editor.h
21052 views
/**************************************************************************/1/* dependency_editor.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/gui/dialogs.h"3334class EditorFileDialog;35class EditorFileSystemDirectory;36class ItemList;37class PopupMenu;38class Tree;39class TreeItem;40class VBoxContainer;41class LineEdit;42class MenuButton;4344enum class DependencyEditorSortBy {45TYPE,46TYPE_REVERSE,47NAME,48NAME_REVERSE,49PATH,50PATH_REVERSE,51MAX,52};5354enum class Column {55TYPE,56NAME,57PATH,58MAX,59};6061class DependencyEditor : public AcceptDialog {62GDCLASS(DependencyEditor, AcceptDialog);6364Tree *tree = nullptr;65Button *fixdeps = nullptr;66Label *warning_label = nullptr;67LineEdit *filter = nullptr;68MenuButton *menu_sort = nullptr;6970EditorFileDialog *search = nullptr;7172DependencyEditorSortBy sort_by = DependencyEditorSortBy::PATH;73String replacing;74String editing;75List<String> missing;7677void _fix_and_find(EditorFileSystemDirectory *efsd, HashMap<String, HashMap<String, String>> &candidates);7879void _searched(const String &p_path);80void _load_pressed(Object *p_item, int p_cell, int p_button, MouseButton p_mouse_button);81List<String> _filter_deps(const List<String> &p_deps);82void _fix_all();83void _update_list();8485void _update_menu_sort();86void _sort_option_selected(int p_id);87void _update_file();8889protected:90void _notification(int p_what);9192public:93void edit(const String &p_path);94DependencyEditor();95};9697class DependencyEditorOwners : public AcceptDialog {98GDCLASS(DependencyEditorOwners, AcceptDialog);99100Label *owners_count = nullptr;101Label *empty = nullptr;102MarginContainer *owners_mc = nullptr;103ItemList *owners = nullptr;104PopupMenu *file_options = nullptr;105String editing;106107void _fill_owners(EditorFileSystemDirectory *efsd);108109void _list_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);110void _select_file(int p_idx);111void _empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);112void _file_option(int p_option);113114private:115enum FileMenu {116FILE_MENU_OPEN,117};118119public:120void show(const String &p_path);121DependencyEditorOwners();122};123124class DependencyRemoveDialog : public ConfirmationDialog {125GDCLASS(DependencyRemoveDialog, ConfirmationDialog);126127Label *text = nullptr;128Tree *owners = nullptr;129VBoxContainer *vb_owners = nullptr;130ItemList *files_to_delete_list = nullptr;131132HashMap<String, String> all_remove_files;133Vector<String> dirs_to_delete;134Vector<String> files_to_delete;135136struct RemovedDependency {137String file;138String file_type;139String dependency;140String dependency_folder;141142bool operator<(const RemovedDependency &p_other) const {143if (dependency_folder.is_empty() != p_other.dependency_folder.is_empty()) {144return p_other.dependency_folder.is_empty();145} else {146return dependency < p_other.dependency;147}148}149};150151LocalVector<StringName> path_project_settings;152153void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder);154void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed);155void _find_localization_remaps_of_removed_files(Vector<RemovedDependency> &p_removed);156void _build_removed_dependency_tree(const Vector<RemovedDependency> &p_removed);157void _show_files_to_delete_list();158159void ok_pressed() override;160161static void _bind_methods();162163public:164void show(const Vector<String> &p_folders, const Vector<String> &p_files);165DependencyRemoveDialog();166};167168class DependencyErrorDialog : public ConfirmationDialog {169GDCLASS(DependencyErrorDialog, ConfirmationDialog);170171StringName icon_name_fail;172StringName icon_name_check;173174String for_file;175176TreeItem *replacing_item = nullptr;177bool errors_fixed = false;178179Tree *files = nullptr;180181EditorFileDialog *replacement_file_dialog = nullptr;182DependencyEditor *deps_editor = nullptr;183184void ok_pressed() override;185186void _on_files_button_clicked(TreeItem *p_item, int p_column, int p_id, MouseButton p_button);187void _on_replacement_file_selected(const String &p_path);188void _check_for_resolved();189190public:191void show(const String &p_for_file, const HashMap<String, HashSet<String>> &p_report);192193DependencyErrorDialog();194};195196class OrphanResourcesDialog : public ConfirmationDialog {197GDCLASS(OrphanResourcesDialog, ConfirmationDialog);198199DependencyEditor *dep_edit = nullptr;200Tree *files = nullptr;201ConfirmationDialog *delete_confirm = nullptr;202void ok_pressed() override;203204bool _fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent);205206List<String> paths;207void _find_to_delete(TreeItem *p_item, List<String> &r_paths);208void _delete_confirm();209void _button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);210211void refresh();212213public:214void show();215OrphanResourcesDialog();216};217218219