diff --git a/addons/bbcode_edit.editor/.assets_for_readme/color_completion.gif b/.assets_for_readme/color_completion.gif similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/color_completion.gif rename to .assets_for_readme/color_completion.gif diff --git a/addons/bbcode_edit.editor/.assets_for_readme/color_completion.mp4 b/.assets_for_readme/color_completion.mp4 similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/color_completion.mp4 rename to .assets_for_readme/color_completion.mp4 diff --git a/addons/bbcode_edit.editor/.assets_for_readme/reference_completion.gif b/.assets_for_readme/reference_completion.gif similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/reference_completion.gif rename to .assets_for_readme/reference_completion.gif diff --git a/addons/bbcode_edit.editor/.assets_for_readme/reference_completion.mp4 b/.assets_for_readme/reference_completion.mp4 similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/reference_completion.mp4 rename to .assets_for_readme/reference_completion.mp4 diff --git a/addons/bbcode_edit.editor/.assets_for_readme/shortcuts.gif b/.assets_for_readme/shortcuts.gif similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/shortcuts.gif rename to .assets_for_readme/shortcuts.gif diff --git a/addons/bbcode_edit.editor/.assets_for_readme/shortcuts.mp4 b/.assets_for_readme/shortcuts.mp4 similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/shortcuts.mp4 rename to .assets_for_readme/shortcuts.mp4 diff --git a/addons/bbcode_edit.editor/.assets_for_readme/snippet.gif b/.assets_for_readme/snippet.gif similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/snippet.gif rename to .assets_for_readme/snippet.gif diff --git a/addons/bbcode_edit.editor/.assets_for_readme/snippet.mp4 b/.assets_for_readme/snippet.mp4 similarity index 100% rename from addons/bbcode_edit.editor/.assets_for_readme/snippet.mp4 rename to .assets_for_readme/snippet.mp4 diff --git a/.gitattributes b/.gitattributes index 1a97d66..d01486a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,8 +4,8 @@ # Only include the addons folder when downloading from the Asset Library. /** export-ignore /addons !export-ignore -/addons/bbcode_edit.editor !export-ignore -/addons/bbcode_edit.editor/** !export-ignore -/addons/bbcode_edit.editor/.assets_for_readme/*.mp4 export-ignore +/addons/bbcode_edit !export-ignore +/addons/bbcode_edit/** !export-ignore +/addons/bbcode_edit/.assets_for_readme/*.mp4 export-ignore /addons/any_icon.editor !export-ignore /addons/any_icon.editor/** !export-ignore \ No newline at end of file diff --git a/addons/bbcode_edit.editor/LICENCE.txt b/addons/bbcode_edit/LICENCE.txt similarity index 100% rename from addons/bbcode_edit.editor/LICENCE.txt rename to addons/bbcode_edit/LICENCE.txt diff --git a/addons/bbcode_edit.editor/README.md b/addons/bbcode_edit/README.md similarity index 86% rename from addons/bbcode_edit.editor/README.md rename to addons/bbcode_edit/README.md index 9f45a35..3ec6456 100644 --- a/addons/bbcode_edit.editor/README.md +++ b/addons/bbcode_edit/README.md @@ -11,22 +11,22 @@ in order to help format documentation comments. There are **shortcuts** to easily toggle some formattings: -![Using the keyboard to toggle bold, italic, underline, striketrough](/addons/bbcode_edit.editor/.assets_for_readme/shortcuts.gif) +![Using the keyboard to toggle bold, italic, underline, striketrough](/.assets_for_readme/shortcuts.gif) **Completion** for formatting tags, with some special completions implemented for specific tags: -![Advanced completion for color tag](/addons/bbcode_edit.editor/.assets_for_readme/color_completion.gif) +![Advanced completion for color tag](/.assets_for_readme/color_completion.gif) **Documentation references** are completed: -![Reference completion](/addons/bbcode_edit.editor/.assets_for_readme/reference_completion.gif) +![Reference completion](/.assets_for_readme/reference_completion.gif) Some useful **snippets** are included: -![A "Note" snippet, with the same formatting as the one used in the official documentation](/addons/bbcode_edit.editor/.assets_for_readme/snippet.gif) +![A "Note" snippet, with the same formatting as the one used in the official documentation](/.assets_for_readme/snippet.gif) ## Features / Roadmap @@ -84,17 +84,14 @@ You can download the addon: - On GitHub: `Code` → `Download ZIP`. - Through the editor: `AssetLib` → Search for "BBCodeEdit" -*By default, this readme is included, along with it's illustrations. If you don't want them, -do not download `addons/bbcode_edit.editor/README.md` nor `addons/bbcode_edit.editor/.assets_for_readme/*`* - -*You can also remove `addons/bbcode_edit.editor/completions_cd/builtin_classes_[godot versions that you don't use].txt`* +*You can remove `addons/bbcode_edit/doc_comment.editor/completions_cd/builtin_classes_[godot versions that you don't use].txt`* To edit shortcuts: - *If they don't show up* in the input map GUI: first restart the editor - modify them in the input map GUI - **restart** the editor to update the input map. -You can also exclude `*.editor/*` or `bbcode_edit.editor/` from your export presets, +You can also exclude `*.editor/*` or `bbcode_edit/doc_comment.editor/` from your export presets, because this addon is (for now[^editor_only]) script-editor-only. diff --git a/addons/bbcode_edit/doc_comment.editor/LICENCE.txt b/addons/bbcode_edit/doc_comment.editor/LICENCE.txt new file mode 100644 index 0000000..3e37514 --- /dev/null +++ b/addons/bbcode_edit/doc_comment.editor/LICENCE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Patou + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/addons/bbcode_edit.editor/bbcode_completion_icon.svg b/addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg similarity index 100% rename from addons/bbcode_edit.editor/bbcode_completion_icon.svg rename to addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg diff --git a/addons/bbcode_edit.editor/bbcode_completion_icon.svg.import b/addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg.import similarity index 60% rename from addons/bbcode_edit.editor/bbcode_completion_icon.svg.import rename to addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg.import index 180befb..d5a883c 100644 --- a/addons/bbcode_edit.editor/bbcode_completion_icon.svg.import +++ b/addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg.import @@ -3,7 +3,7 @@ importer="texture" type="CompressedTexture2D" uid="uid://bpwcspqlqm78h" -path="res://.godot/imported/bbcode_completion_icon.svg-e050b1e9fb923c5a17b0f52532042234.ctex" +path="res://.godot/imported/bbcode_completion_icon.svg-a242f72402b90907e6e67e820acf8aa8.ctex" metadata={ "has_editor_variant": true, "vram_texture": false @@ -11,14 +11,16 @@ metadata={ [deps] -source_file="res://addons/bbcode_edit.editor/bbcode_completion_icon.svg" -dest_files=["res://.godot/imported/bbcode_completion_icon.svg-e050b1e9fb923c5a17b0f52532042234.ctex"] +source_file="res://addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg" +dest_files=["res://.godot/imported/bbcode_completion_icon.svg-a242f72402b90907e6e67e820acf8aa8.ctex"] [params] compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -26,6 +28,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/addons/bbcode_edit.editor/bbcode_edit.gd b/addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd similarity index 97% rename from addons/bbcode_edit.editor/bbcode_edit.gd rename to addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd index 61dbf8f..93f4c3d 100644 --- a/addons/bbcode_edit.editor/bbcode_edit.gd +++ b/addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd @@ -15,14 +15,19 @@ enum CompletionKind { } -const Completions = preload("res://addons/bbcode_edit.editor/completions_db/completions.gd") -const Scraper = preload("res://addons/bbcode_edit.editor/editor_interface_scraper.gd") +const Completions = preload("res://addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd") +const Scraper = preload("res://addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd") +## @deprecated: Superseded by Tag Toggler const ACTION_TOGGLE_BOLD = &"bbcode_edit/toggle_bold" +## @deprecated: Superseded by Tag Toggler const ACTION_TOGGLE_ITALIC = &"bbcode_edit/toggle_italic" +## @deprecated: Superseded by Tag Toggler const ACTION_TOGGLE_UNDERLINE = &"bbcode_edit/toggle_underline" +## @deprecated: Superseded by Tag Toggler const ACTION_TOGGLE_STRIKE = &"bbcode_edit/toggle_strike" +## @deprecated: Superseded by Tag Toggler const TOGGLING_ACTIONS = { ACTION_TOGGLE_BOLD: "b", ACTION_TOGGLE_ITALIC: "i", @@ -30,7 +35,7 @@ const TOGGLING_ACTIONS = { ACTION_TOGGLE_STRIKE: "s", } -const BBCODE_COMPLETION_ICON = preload("res://addons/bbcode_edit.editor/bbcode_completion_icon.svg") +const BBCODE_COMPLETION_ICON = preload("res://addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg") const COLOR_PICKER_CONTAINER_PATH = ^"_BBCodeEditColorPicker" const COLOR_PICKER_PATH = ^"_BBCodeEditColorPicker/ColorPicker" @@ -664,6 +669,7 @@ func add_enums(enums: PackedStringArray) -> void: ) +## @deprecated: Superseded by bbcode_edit/tag_toggler sub-plugin func toggle_tag(tag: String) -> void: var prefix: String = "[" + tag + "]" var prefix_len: int = prefix.length() @@ -770,7 +776,7 @@ func _confirm_code_completion(replace: bool = false) -> void: match parts[0]: _COMMAND_COLOR_PICKER: if not has_node(^"BBCODE_EDIT_COLOR_PICKER"): - add_child(preload("res://addons/bbcode_edit.editor/color_picker.tscn").instantiate()) + add_child(preload("res://addons/bbcode_edit/doc_comment.editor/color_picker.tscn").instantiate()) var container: PopupPanel = get_node(COLOR_PICKER_CONTAINER_PATH) var picker: ColorPicker = get_node(COLOR_PICKER_PATH) @@ -866,12 +872,12 @@ func _gui_input(event: InputEvent) -> void: if event is InputEventKey or event is InputEventMouseButton: get_node(COLOR_PICKER_CONTAINER_PATH).free() - for action in TOGGLING_ACTIONS: - if is_action(event, action): - toggle_tag(TOGGLING_ACTIONS[action]) + #for action in TOGGLING_ACTIONS: + #if is_action(event, action): + #toggle_tag(TOGGLING_ACTIONS[action]) -func is_action(event: InputEvent, action: StringName) -> bool: +static func is_action(event: InputEvent, action: StringName) -> bool: return InputMap.has_action(action) and event.is_action(action, true) diff --git a/addons/bbcode_edit.editor/bbcode_edit.gd.uid b/addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/bbcode_edit.gd.uid rename to addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd.uid diff --git a/addons/bbcode_edit.editor/bbcode_edit_main.gd b/addons/bbcode_edit/doc_comment.editor/bbcode_edit_main.gd similarity index 95% rename from addons/bbcode_edit.editor/bbcode_edit_main.gd rename to addons/bbcode_edit/doc_comment.editor/bbcode_edit_main.gd index bc1de3c..6608591 100644 --- a/addons/bbcode_edit.editor/bbcode_edit_main.gd +++ b/addons/bbcode_edit/doc_comment.editor/bbcode_edit_main.gd @@ -2,9 +2,9 @@ extends EditorPlugin -const BBCodeEdit: GDScript = preload("res://addons/bbcode_edit.editor/bbcode_edit.gd") -const Completions = preload("res://addons/bbcode_edit.editor/completions_db/completions.gd") -const Scraper = preload("res://addons/bbcode_edit.editor/editor_interface_scraper.gd") +const BBCodeEdit: GDScript = preload("res://addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd") +const Completions = preload("res://addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd") +const Scraper = preload("res://addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd") const ADDON_NAME = "BBCode Editor" diff --git a/addons/bbcode_edit.editor/bbcode_edit_main.gd.uid b/addons/bbcode_edit/doc_comment.editor/bbcode_edit_main.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/bbcode_edit_main.gd.uid rename to addons/bbcode_edit/doc_comment.editor/bbcode_edit_main.gd.uid diff --git a/addons/bbcode_edit.editor/color_picker.tscn b/addons/bbcode_edit/doc_comment.editor/color_picker.tscn similarity index 100% rename from addons/bbcode_edit.editor/color_picker.tscn rename to addons/bbcode_edit/doc_comment.editor/color_picker.tscn diff --git a/addons/bbcode_edit.editor/completions_db/builtin_classes_4.3.txt b/addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.3.txt similarity index 100% rename from addons/bbcode_edit.editor/completions_db/builtin_classes_4.3.txt rename to addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.3.txt diff --git a/addons/bbcode_edit.editor/completions_db/builtin_classes_4.4.txt b/addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.4.txt similarity index 100% rename from addons/bbcode_edit.editor/completions_db/builtin_classes_4.4.txt rename to addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.4.txt diff --git a/addons/bbcode_edit.editor/completions_db/builtin_classes_4.5.txt b/addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.5.txt similarity index 100% rename from addons/bbcode_edit.editor/completions_db/builtin_classes_4.5.txt rename to addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_4.5.txt diff --git a/addons/bbcode_edit.editor/completions_db/completions.gd b/addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd similarity index 95% rename from addons/bbcode_edit.editor/completions_db/completions.gd rename to addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd index 4e25b84..43b454e 100644 --- a/addons/bbcode_edit.editor/completions_db/completions.gd +++ b/addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd @@ -1,10 +1,10 @@ extends Object -const GodotVersion = preload("res://addons/bbcode_edit.editor/completions_db/godot_version.gd") -const Scraper = preload("res://addons/bbcode_edit.editor/editor_interface_scraper.gd") +const GodotVersion = preload("res://addons/bbcode_edit/doc_comment.editor/completions_db/godot_version.gd") +const Scraper = preload("res://addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd") -const _BUILTIN_COMPLETIONS_PATH_BEGINING = "res://addons/bbcode_edit.editor/completions_db/builtin_classes_" +const _BUILTIN_COMPLETIONS_PATH_BEGINING = "res://addons/bbcode_edit/doc_comment.editor/completions_db/builtin_classes_" const DONT_ASK_TO_FETCH_SETTING_PATH = "addons/bbcode_edit/editor/dont_ask_to_fetch_builtin_classes" const equivalent_versions: Dictionary = { @@ -309,7 +309,7 @@ static func get_class_completions() -> ClassCompletions: static func fetch_builtin_classes() -> void: - EditorInterface.play_custom_scene("res://addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.tscn") + EditorInterface.play_custom_scene("res://addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.tscn") while EditorInterface.is_playing_scene(): await EditorInterface.get_base_control().get_tree().create_timer(0.1, true, false, true).timeout diff --git a/addons/bbcode_edit.editor/completions_db/completions.gd.uid b/addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/completions_db/completions.gd.uid rename to addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd.uid diff --git a/addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd b/addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd similarity index 85% rename from addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd rename to addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd index 14aac01..b0173a6 100644 --- a/addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd +++ b/addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd @@ -4,7 +4,7 @@ extends Node ## This has to be a scene. ## (In an EditorScript, editor specifc classes would polute the result) -const Completions = preload("res://addons/bbcode_edit.editor/completions_db/completions.gd") +const Completions = preload("res://addons/bbcode_edit/doc_comment.editor/completions_db/completions.gd") func _ready() -> void: diff --git a/addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd.uid b/addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd.uid rename to addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd.uid diff --git a/addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.tscn b/addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.tscn similarity index 67% rename from addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.tscn rename to addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.tscn index 7907fde..ec1d672 100644 --- a/addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.tscn +++ b/addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://blcco0wsttyck"] -[ext_resource type="Script" uid="uid://cociwvr6oq38v" path="res://addons/bbcode_edit.editor/completions_db/fetch_builtin_classes.gd" id="1_tk0nj"] +[ext_resource type="Script" uid="uid://cociwvr6oq38v" path="res://addons/bbcode_edit/doc_comment.editor/completions_db/fetch_builtin_classes.gd" id="1_tk0nj"] [node name="FetchClassDB" type="Node"] script = ExtResource("1_tk0nj") diff --git a/addons/bbcode_edit.editor/completions_db/godot_version.gd b/addons/bbcode_edit/doc_comment.editor/completions_db/godot_version.gd similarity index 100% rename from addons/bbcode_edit.editor/completions_db/godot_version.gd rename to addons/bbcode_edit/doc_comment.editor/completions_db/godot_version.gd diff --git a/addons/bbcode_edit.editor/completions_db/godot_version.gd.uid b/addons/bbcode_edit/doc_comment.editor/completions_db/godot_version.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/completions_db/godot_version.gd.uid rename to addons/bbcode_edit/doc_comment.editor/completions_db/godot_version.gd.uid diff --git a/addons/bbcode_edit.editor/editor_interface_scraper.gd b/addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd similarity index 100% rename from addons/bbcode_edit.editor/editor_interface_scraper.gd rename to addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd diff --git a/addons/bbcode_edit.editor/editor_interface_scraper.gd.uid b/addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd.uid similarity index 100% rename from addons/bbcode_edit.editor/editor_interface_scraper.gd.uid rename to addons/bbcode_edit/doc_comment.editor/editor_interface_scraper.gd.uid diff --git a/addons/bbcode_edit/doc_comment.editor/plugin.cfg b/addons/bbcode_edit/doc_comment.editor/plugin.cfg new file mode 100644 index 0000000..a3890a8 --- /dev/null +++ b/addons/bbcode_edit/doc_comment.editor/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="BBCodeEdit: Documentation comment completion" +description="A Godot addon that brings BBCode completion and QOL tools to the script editor in order to help formatting documentation comments." +author="Patou" +version="1.2.1" +script="bbcode_edit_main.gd" diff --git a/addons/bbcode_edit.editor/plugin.cfg b/addons/bbcode_edit/plugin.cfg similarity index 84% rename from addons/bbcode_edit.editor/plugin.cfg rename to addons/bbcode_edit/plugin.cfg index 2db739e..c029289 100644 --- a/addons/bbcode_edit.editor/plugin.cfg +++ b/addons/bbcode_edit/plugin.cfg @@ -1,6 +1,6 @@ [plugin] -name="BBCodeEdit (for script editor)" +name="BBCodeEdit" description="A Godot addon that brings BBCode completion and QOL tools to the script editor in order to help formatting documentation comments." author="Patou" version="1.2.1" diff --git a/addons/bbcode_edit/tag_toggler/LICENCE.txt b/addons/bbcode_edit/tag_toggler/LICENCE.txt new file mode 100644 index 0000000..3e37514 --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/LICENCE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Patou + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/addons/bbcode_edit/tag_toggler/plugin.cfg b/addons/bbcode_edit/tag_toggler/plugin.cfg new file mode 100644 index 0000000..d70b20f --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="BBCodeEdit: Tag Toggler" +description="Allow toggling BBCode tags everywhere." +author="Patou" +version="1.0" +script="tag_toggler_main.gd" diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler.gd b/addons/bbcode_edit/tag_toggler/tag_toggler.gd new file mode 100644 index 0000000..98cf220 --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler.gd @@ -0,0 +1,82 @@ +extends Object + + +# TODO make so that if it's surrounded by another tag it works too. +# exemple: [b][i]bold italic[/b][/i] → toggling b when selecting only the text would work. +static func toggle_tag(editor: TextEdit, tag: String) -> void: + var prefix: String = "[" + tag + "]" + var prefix_len: int = prefix.length() + var suffix: String = "[/" + tag + "]" + var suffix_len: int = suffix.length() + + var main_selection_from_column: int = editor.get_selection_from_column() + var main_selection_from_line: int = editor.get_selection_from_line() + var main_selection_to_column: int = editor.get_selection_to_column() + var main_selection_to_line: int = editor.get_selection_to_line() + var main_selection_end_line: String = editor.get_line(main_selection_to_line) + + if ( + main_selection_from_column >= prefix_len + and editor.get_line(main_selection_from_line).substr( + main_selection_from_column - prefix_len, + prefix_len + ) == prefix + and main_selection_to_column <= main_selection_end_line.length() - suffix_len + and main_selection_end_line.substr( + main_selection_to_column, + suffix_len + ) == suffix + ): + editor.begin_complex_operation() + editor.begin_multicaret_edit() + + for caret in editor.get_caret_count(): + if editor.multicaret_edit_ignore_caret(caret): + continue + + var initial_text: String = editor.get_selected_text(caret) + var initial_start_column: int = editor.get_selection_from_column(caret) + var initial_end_column: int = editor.get_selection_to_column(caret) + + editor.select( + editor.get_selection_from_line(caret), + initial_start_column - prefix_len, + editor.get_selection_to_line(caret), + initial_end_column + suffix_len, + caret + ) + editor.insert_text_at_caret(initial_text, caret) + editor.select( + editor.get_selection_from_line(caret), + initial_start_column - prefix_len, + editor.get_selection_to_line(caret), + initial_end_column - prefix_len, + caret + ) + + editor.end_multicaret_edit() + editor.end_complex_operation() + return + + editor.begin_complex_operation() + editor.begin_multicaret_edit() + + for caret in editor.get_caret_count(): + if editor.multicaret_edit_ignore_caret(caret): + continue + + var initial_start_column: int = editor.get_selection_from_column(caret) + var initial_end_column: int = editor.get_selection_to_column(caret) + + editor.insert_text_at_caret(prefix + editor.get_selected_text(caret) + suffix, caret) + + editor.select( + editor.get_selection_from_line(caret), + initial_start_column + prefix_len, + editor.get_selection_to_line(caret), + initial_end_column + prefix_len, + caret + ) + + editor.end_multicaret_edit() + editor.end_complex_operation() diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler.gd.uid b/addons/bbcode_edit/tag_toggler/tag_toggler.gd.uid new file mode 100644 index 0000000..d97f6ac --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler.gd.uid @@ -0,0 +1 @@ +uid://vbfluupq1gbw diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd b/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd new file mode 100644 index 0000000..bd0d777 --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd @@ -0,0 +1,121 @@ +@tool +extends Node + +const TagToggler = preload("res://addons/bbcode_edit/tag_toggler/tag_toggler.gd") + +const ACTION_TOGGLE_BOLD = &"bbcode_edit/toggle_bold" +const ACTION_TOGGLE_ITALIC = &"bbcode_edit/toggle_italic" +const ACTION_TOGGLE_UNDERLINE = &"bbcode_edit/toggle_underline" +const ACTION_TOGGLE_STRIKE = &"bbcode_edit/toggle_strike" + +const TOGGLING_ACTIONS = { + ACTION_TOGGLE_BOLD: "b", + ACTION_TOGGLE_ITALIC: "i", + ACTION_TOGGLE_UNDERLINE: "u", + ACTION_TOGGLE_STRIKE: "s", +} + +#var focused_editor: TextEdit = null + + +func _ready() -> void: + print("ready") + connect_to_window(get_window()) + connect_to_window(await get_current_focused_window()) + + +func disconnect_from(editor: TextEdit) -> void: + editor.gui_input.disconnect(_on_focused_editor_gui_input) + +func connect_to(editor: TextEdit) -> void: + if editor.gui_input.is_connected(_on_focused_editor_gui_input): + print_rich("[color=green]Skipping already connected TextEdit.") + return + editor.gui_input.connect(_on_focused_editor_gui_input.bind(editor)) + + +func connect_to_window(window: Window) -> void: + if window.gui_focus_changed.is_connected(_on_focus_changed): + print_rich("[color=green]Skipping already connected " + str(window)) + return + + print_rich("[color=green]Connecting to " + str(window)) + window.gui_focus_changed.connect(_on_focus_changed) + window.focus_exited.connect(_on_window_focus_exited.call_deferred) + _on_focus_changed(window.gui_get_focus_owner()) + + +func _on_window_focus_exited() -> void: + print_rich("[color=red]FOCUS LOST") + connect_to_window(await get_current_focused_window()) + + +func get_current_focused_window() -> Window: + if Engine.get_version_info().hex >= 0x04_05_00: # only in Godot 4.5 + var focused_window: Window = null + while focused_window == null: + await get_tree().process_frame + + focused_window = get_window().get_focused_window() # I know that + # calling the static method directly on Window would be more elegant, + # but it would cause a static analysis error on Godot 4.4 and before. + + print("attempting") + return focused_window + + print("Compatibility problem with Godot 4.4-") + + var windows := get_windows() + var focused_window: Window = null + while focused_window == null: + await get_tree().create_timer(0.2).timeout + + for window in windows: + #prints(window, window.has_focus()) + if window.has_focus(): + return window # I know that + # calling the static method directly on Window would be more elegant, + # but it would cause a static analysis error on Godot 4.4 and before. + + print("attempting") + return focused_window + +## @deprecated: Useless in Godot 4.5+ +func get_windows() -> Array[Window]: + var windows: Array[Window] = [] + var to_check: Array[Node] = [get_tree().root] + + while to_check: + var current_node: Node = to_check.pop_back() + if current_node is Window: + windows.push_back(current_node) + to_check.append_array(current_node.get_children()) + + return windows + +#func _process(_delta: float) -> void: + #print(Window.get_focused_window()) + +func _on_focus_changed(control: Control) -> void: + #if focused_editor: + #disconnect_from(focused_editor) + print("focus changed to", control) + if control is TextEdit: + print("connecting to: ", control) + connect_to(control) + + +func _on_focused_editor_gui_input(input_event: InputEvent, editor: TextEdit) -> void: + if not input_event.is_pressed() or input_event.is_echo(): + return + + print("gui input: ", editor) + for action in TOGGLING_ACTIONS: + if is_action(input_event, action): + print("TOGGLED BY THE TOGGLER") + TagToggler.toggle_tag(editor, TOGGLING_ACTIONS[action]) + + +# TODO Find some place to put this with the one of BBCodeEdit +static func is_action(event: InputEvent, action: StringName) -> bool: + return InputMap.has_action(action) and event.is_action(action, true) diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd.uid b/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd.uid new file mode 100644 index 0000000..67e024d --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd.uid @@ -0,0 +1 @@ +uid://dowgrccvxw60n diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd b/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd new file mode 100644 index 0000000..577bb33 --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd @@ -0,0 +1,22 @@ +@tool +extends EditorPlugin + + + +const ADDON_NAME = "BBCodeEdit: Tag Toggler" + + + + + + +func _enable_plugin() -> void: + print("Enabling ", ADDON_NAME) + add_autoload_singleton("TagToggler", "res://addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd") + print("Enabled ", ADDON_NAME) + + +func _disable_plugin() -> void: + print("Disabling ", ADDON_NAME) + remove_autoload_singleton("TagToggler") + print("Disabled ", ADDON_NAME) diff --git a/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd.uid b/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd.uid new file mode 100644 index 0000000..c7fa00d --- /dev/null +++ b/addons/bbcode_edit/tag_toggler/tag_toggler_main.gd.uid @@ -0,0 +1 @@ +uid://4wvml1anw6eh diff --git a/project.godot b/project.godot index 0b56ae7..c0b3646 100644 --- a/project.godot +++ b/project.godot @@ -13,12 +13,16 @@ config_version=5 config/name="BBCodeEdit" config/tags=PackedStringArray("addon") run/main_scene="res://test_export.tscn" -config/features=PackedStringArray("4.4", "GL Compatibility") +config/features=PackedStringArray("4.5", "GL Compatibility") config/icon="res://icon.png" +[autoload] + +TagToggler="*res://addons/bbcode_edit/tag_toggler/tag_toggler_auto_load.gd" + [editor_plugins] -enabled=PackedStringArray("res://addons/bbcode_edit.editor/plugin.cfg", "res://addons/explore-editor-theme/plugin.cfg") +enabled=PackedStringArray("res://addons/bbcode_edit/doc_comment.editor/plugin.cfg", "res://addons/bbcode_edit/tag_toggler/plugin.cfg", "res://addons/explore-editor-theme/plugin.cfg") [input] diff --git a/test_bbcode.tscn b/test_bbcode.tscn index 4794547..eceb066 100644 --- a/test_bbcode.tscn +++ b/test_bbcode.tscn @@ -7,6 +7,17 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 bbcode_enabled = true -text = "Press [b]Ctrl + C[/b]. +text = "test + + + +Press [b]Ctrl + C[/b]. Press [b ]Ctrl + C[/b]. -Press [color= red ]Ctrl + C[/color]." +[b][b]Press[/b][/b] [color= red ]Ctrl + C[/color]." + +[node name="TextEdit" type="TextEdit" parent="."] +layout_mode = 0 +offset_left = 300.0 +offset_top = 221.0 +offset_right = 525.0 +offset_bottom = 390.0 diff --git a/test_open_doc_named.gd b/test_open_doc_named.gd index 40b5970..432bcc4 100644 --- a/test_open_doc_named.gd +++ b/test_open_doc_named.gd @@ -1,4 +1,4 @@ -@icon("res://addons/bbcode_edit.editor/bbcode_completion_icon.svg") +@icon("res://addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg") class_name Named extends Node @@ -36,7 +36,7 @@ enum {OH, NO} const CONTANT_STRING = "ah" const CONTANT_INT = 5 ## [constant BbcodeEdit] -const BbcodeEdit = preload("res://addons/bbcode_edit.editor/bbcode_edit.gd") +const BbcodeEdit = preload("res://addons/bbcode_edit/doc_comment.editor/bbcode_edit.gd") ## Press [color= red ## ]Ctrl + C oh no[/color]. @@ -69,7 +69,7 @@ var obj: Node = Node.new() ## [member auto_translate_mode] [method add_child] ## Testazeiln,azlekj,azUPDATE3[color=aqua]azejnzaekj[/color] -## aaa[img width=32 height=10 color=red region=0,0,10,10 tootip=hello]res://addons/bbcode_edit.editor/bbcode_completion_icon.svg[/img]bbb +## aaa[img width=32 height=10 color=red region=0,0,10,10 tootip=hello]res://addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg[/img]bbb func doc_test()-> void: pass diff --git a/test_param.gd b/test_param.gd index 573aa81..5795796 100644 --- a/test_param.gd +++ b/test_param.gd @@ -1,4 +1,4 @@ -@icon("res://addons/bbcode_edit.editor/bbcode_completion_icon.svg") +@icon("res://addons/bbcode_edit/doc_comment.editor/bbcode_completion_icon.svg") extends Node