Merge pull request #30

Fixed the bug that didn't update the status bar when the use entered any new text.
This commit is contained in:
Gustavo Henrique Miranda 2025-07-08 00:49:52 -03:00 committed by GitHub
commit cc723bdbbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 29 deletions

View File

@ -34,7 +34,6 @@ class EditEntryScreen(Screen):
] ]
def __init__(self, diary_id: int = 1): def __init__(self, diary_id: int = 1):
print("DEBUG: EditEntryScreen INIT")
super().__init__() super().__init__()
self.diary_id = diary_id self.diary_id = diary_id
self.diary_name = f"Diary {diary_id}" self.diary_name = f"Diary {diary_id}"
@ -136,7 +135,6 @@ class EditEntryScreen(Screen):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
print("DEBUG: EditEntryScreen COMPOSE", getattr(self, 'sidebar_visible', None))
yield self.header yield self.header
yield Horizontal( yield Horizontal(
self.main, self.main,
@ -233,7 +231,10 @@ class EditEntryScreen(Screen):
current_entry = self.entries[self.current_entry_index] current_entry = self.entries[self.current_entry_index]
entry_text = f"Entry: \\[{self.current_entry_index + 1}/{len(self.entries)}] {current_entry.title}" entry_text = f"Entry: \\[{self.current_entry_index + 1}/{len(self.entries)}] {current_entry.title}"
self.entry_info.update(entry_text) self.entry_info.update(entry_text)
self._update_status_indicator("Saved", "saved") if self.has_unsaved_changes:
self._update_status_indicator("Not Saved", "not-saved")
else:
self._update_status_indicator("Saved", "saved")
def _save_current_state(self): def _save_current_state(self):
"""Saves the current state before navigating""" """Saves the current state before navigating"""
@ -339,7 +340,6 @@ class EditEntryScreen(Screen):
def action_toggle_sidebar(self): def action_toggle_sidebar(self):
"""Toggles the sidebar visibility""" """Toggles the sidebar visibility"""
try: try:
print("DEBUG: TOGGLE SIDEBAR", self.sidebar_visible)
self.sidebar_visible = not self.sidebar_visible self.sidebar_visible = not self.sidebar_visible
if self.sidebar_visible: if self.sidebar_visible:
@ -348,13 +348,7 @@ class EditEntryScreen(Screen):
# Automatically focus the sidebar when opening # Automatically focus the sidebar when opening
self.sidebar_focused = True self.sidebar_focused = True
self.photo_list.focus() self.photo_list.focus()
# Notification when opening the sidebar for the first time self._sidebar_opened_once = True
if not self._sidebar_opened_once:
self.notify(
"Sidebar opened and focused! Use the shortcuts shown in the help panel.",
severity="info"
)
self._sidebar_opened_once = True
else: else:
self.sidebar.display = False self.sidebar.display = False
self.sidebar_focused = False # Reset focus when hiding self.sidebar_focused = False # Reset focus when hiding
@ -372,15 +366,12 @@ class EditEntryScreen(Screen):
def action_toggle_focus(self): def action_toggle_focus(self):
"""Toggles focus between editor and sidebar""" """Toggles focus between editor and sidebar"""
print("DEBUG: TOGGLE FOCUS called", self.sidebar_visible, self.sidebar_focused)
if not self.sidebar_visible: if not self.sidebar_visible:
# If sidebar is not visible, show it and focus it # If sidebar is not visible, show it and focus it
print("DEBUG: Sidebar not visible, opening it")
self.action_toggle_sidebar() self.action_toggle_sidebar()
return return
self.sidebar_focused = not self.sidebar_focused self.sidebar_focused = not self.sidebar_focused
print("DEBUG: Sidebar focused changed to", self.sidebar_focused)
if self.sidebar_focused: if self.sidebar_focused:
self.photo_list.focus() self.photo_list.focus()
else: else:
@ -757,24 +748,34 @@ class EditEntryScreen(Screen):
self.photo_info.update(photo_details) self.photo_info.update(photo_details)
def on_text_area_changed(self, event) -> None: def on_text_area_changed(self, event) -> None:
"""Detects text changes and shows photo tooltips""" """Detects text changes and updates status"""
if (hasattr(self, 'text_entry') and not self.text_entry.read_only and # Skip if we're currently updating the display
not getattr(self, '_updating_display', False) and hasattr(self, '_original_content')): if getattr(self, '_updating_display', False):
current_content = self.text_entry.text return
# Skip if text area is read-only
if not hasattr(self, 'text_entry') or self.text_entry.read_only:
return
# Skip if we don't have original content to compare against
if not hasattr(self, '_original_content'):
return
current_content = self.text_entry.text
# Check if content has changed
if current_content != self._original_content:
if not self.has_unsaved_changes:
self.has_unsaved_changes = True
self._update_sub_header()
else:
if self.has_unsaved_changes:
self.has_unsaved_changes = False
self._update_sub_header()
# Check for a photo reference pattern
# self._check_photo_reference(current_content) # Temporarily disabled
if current_content != self._original_content:
if not self.has_unsaved_changes:
self.has_unsaved_changes = True
self._update_sub_header()
else:
if self.has_unsaved_changes:
self.has_unsaved_changes = False
self._update_sub_header()
def on_focus(self, event) -> None: def on_focus(self, event) -> None:
"""Captures focus changes to update footer""" """Captures focus changes to update footer"""
@ -982,7 +983,6 @@ class EditEntryScreen(Screen):
self.notify(f"Error updating entry: {str(e)}") self.notify(f"Error updating entry: {str(e)}")
def on_key(self, event): def on_key(self, event):
# Sidebar contextual shortcuts # Sidebar contextual shortcuts
if self.sidebar_focused and self.sidebar_visible: if self.sidebar_focused and self.sidebar_visible: