Skip to content

Commit

Permalink
Added plain-text fallback editor
Browse files Browse the repository at this point in the history
  • Loading branch information
macarooni-man committed Feb 3, 2025
1 parent 270335f commit a526dcd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5922,7 +5922,7 @@ def fix_empty_properties(name):

# Recursively gathers all config files with a specific depth (default 3)
# Returns {"dir1": ['match1', 'match2', 'match3', ...]}
valid_config_formats = ['properties', 'yml', 'yaml', 'tml', 'toml', 'json', 'json5', 'ini']
valid_config_formats = ['properties', 'yml', 'yaml', 'tml', 'toml', 'json', 'json5', 'ini', 'txt']
def gather_config_files(name: str, max_depth: int = 3) -> dict[str, list[str]]:
root = server_path(name)
excludes = ['version_history.json', 'version_list.json', 'usercache.json', 'banned-players.json', 'banned-ips.json', 'whitelist.json', 'ops.json', server_ini]
Expand Down
44 changes: 35 additions & 9 deletions source/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23405,6 +23405,12 @@ def on_text(self, *args):
self.cursor_color = (0.939, 0.541, 0.254, 1)
self.selection_color = (0.889, 0.511, 0.254, 0.4)

# Plain-text detection
elif self.get_type(self.text) is None:
self.foreground_color = (0.7, 0.7, 1, 1)
self.cursor_color = (0.7, 0.7, 1, 1)
self.selection_color = (0.7, 0.7, 1, 0.4)

self.last_color = self.foreground_color
self.original_text = str(self.text)
self.search.text = str(self.text)
Expand Down Expand Up @@ -23846,10 +23852,10 @@ def configure(self):

def render_line(self, data: dict):
self._data = data
key = data['key']
max_line_count = len(self._screen.line_list)

# Determines if the line is skip-able when scrolling
self.is_comment = data['is_comment']
self.inactive = data['inactive']
self.line_matched = data['line_matched']
self._finished_rendering = False
Expand All @@ -23875,22 +23881,22 @@ def render_line(self, data: dict):
self.key_label.__translate__ = False
self.key_label.max_lines = 1
self.key_label.markup = True
self.key_label.text = key
self.key_label.original_text = key
self.key_label.text = ''
self.key_label.original_text = ''
self.key_label.font_name = self.font_name
self.key_label.font_size = self.font_size
self.key_label.default_color = "#5E6BFF"
self.key_label.color = self.key_label.default_color
self.key_label.size_hint_max_y = 50
self.key_label.pos_hint = {'center_y': 0.5}
self.key_label.text_size[0] = 600 if key.startswith('#') else 260
self.key_label.text_size[0] = 0
self.key_label.opacity = 1

# Show eq character
self.eq_label.text = self.eq_character
self.eq_label.font_name = self.font_name
self.eq_label.font_size = self.font_size
self.eq_label.color = (1, 1, 1, 1)
self.eq_label.color = (0, 0, 0, 0)
self.eq_label.opacity = 0.5
self.eq_label.pos_hint = {'center_y': 0.5}

Expand Down Expand Up @@ -24476,11 +24482,16 @@ def load_file(self):
for line in self.read_from_disk():
line = line.strip()

key = ''
value = line.rstrip()
data = {
'key': '',
'value': line,
'original_value': line,
'is_comment': False,
'inactive': False,
'line_matched': False
}

line = (key, value)
self.insert_line(line, refresh=False)
self.insert_line(data, refresh=False)

return self.line_list

Expand Down Expand Up @@ -24777,6 +24788,21 @@ def show_controls():
)
float_layout.add_widget(self.controls_button)

# Edit in plain text mode for fallback
class ServerTextEditScreen(EditorRoot):

class EditorLine(EditorRoot.EditorLine):
def configure(self):
self.eq_character = ':'
self.eq_spacing = (1.05, 0.67)

@staticmethod
def get_type(value: str):

# Define custom behavior for determining data types

return None

# Edit all *.properties/INI files
class ServerPropertiesEditScreen(EditorRoot):
class EditorLine(EditorRoot.EditorLine):
Expand Down

0 comments on commit a526dcd

Please sign in to comment.