-
Notifications
You must be signed in to change notification settings - Fork 0
Modes structure guide
In Text Forge, modes enable interaction with various types of files. Modes are located in the modes/ folder, each within its own dedicated folder. Currently, Text Forge uses this structure for every mode.
modes/
mode_name/
mode.cfg
mode.gd
In this file, the mode information is specified, including syntax-highlighting. Each mode must have a mode.cfg file with the following structure (all keys are required):
[mode]
name="Example"
description="This is an example mode"
author="Text Forge Team"
version="1.0.0"
extensions=["example", "ex", "xmlp"]
[highlighter]
; This example highlighter is for python
; Alpha for colors is mandatory
number_color = Color(0.85, 1, 0.7, 1)
symbol_color = Color(0.7, 0.8, 1, 1)
function_color = Color(0.35, 0.7, 1, 1)
member_variable_color = Color(0.8, 0.85, 1, 1)
keyword_colors = Dictionary[Color, PackedStringArray]({
Color(1, 0.45, 0.55, 1): PackedStringArray("def", "class", "lambda", "return", "yield", "try", "except", "finally", "raise"),
Color(1, 0.6, 0.85, 1): PackedStringArray("if", "elif", "else", "for", "while", "break", "continue", "pass", "with", "as", "assert"),
Color(1, 0.7, 0.5, 1): PackedStringArray("import", "from", "global", "nonlocal", "del", "and", "or", "not", "in", "is"),
Color(0.9, 0.8, 0.6, 1): PackedStringArray("True", "False", "None")
})
member_keyword_colors = Dictionary[Color, PackedStringArray]({})
code_regions = Dictionary[Color, PackedStringArray]({
Color(1, 0.92, 0.64, 1): PackedStringArray("\"", "\"", "n"),
Color(1, 0.92, 0.64, 1): PackedStringArray("\'", "\'", "n"),
Color(0.8, 0.81, 0.82, 0.5): PackedStringArray("#", "", "y")
})
Modes are selected based on file extensions. If no suitable mode is found, the editor uses a pseudo-mode based on UTF-8. If more than one suitable mode exists, the priority is given to the mode that has been in use so far. If that mode is not compatible, a menu containing compatible modes is displayed to the user, showing the mode name and its description.
This script handle any functionality for mode, this script should extends Node and have these functions:
func load_file(path: String) -> String
func save_file(path: String) -> void
func auto_format() -> void
Modes can transfer data within editor using Global autoload, it's a API between all part of project and internal API for editor.
This is a good start template for mode.gd:
extends Node
# You should load and parse your file here and return the content as string
func load_file(path: String) -> String:
return ""
# This function is for saving, to get current text in editor use "Global.get_editor_text()"
func save_file(path: String) -> void:
pass
# Here you can have auto formatting option (or havn't), this function is accessible using Ctrl+Alt+F.
# Get current text: Global.get_editor_text()
# Set text: Global.set_editor_text()
# Access to editor node: Global.get_editor()
# Note: If you are applying your edits in multiple steps, use Global.get_editor().begin_complex_operation() and Global.get_editor().end_complex_operation()
# If you want ignore auto formatting, use "pass" inside function, DON'T REMOVE THIS FUNCTION
# This is an example formatter with remove white spaces from both left and right sides of all lines
func auto_format() -> void:
var content := Global.get_editor_text()
var lines := content.split("\n")
for i in lines.size():
var line := lines[i].strip_edges()
Global.set_editor_text("\n".join(lines))