Make note save status transient
This commit is contained in:
@@ -9,6 +9,7 @@ var conflict_panel: PanelContainer
|
||||
var applying_content := false
|
||||
var notes_service: Node
|
||||
var theme_service: Node
|
||||
var saved_status_timer: Timer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -28,6 +29,11 @@ func _ready() -> void:
|
||||
count_label = Label.new()
|
||||
Brand.apply_font(count_label)
|
||||
metadata_row.add_child(count_label)
|
||||
saved_status_timer = Timer.new()
|
||||
saved_status_timer.one_shot = true
|
||||
saved_status_timer.wait_time = 2.0
|
||||
saved_status_timer.timeout.connect(_clear_saved_status)
|
||||
add_child(saved_status_timer)
|
||||
|
||||
editor = TextEdit.new()
|
||||
editor.placeholder_text = "Write notes..."
|
||||
@@ -65,6 +71,7 @@ func _ready() -> void:
|
||||
|
||||
notes_service.content_changed.connect(_on_service_content_changed)
|
||||
notes_service.state_changed.connect(_on_service_state_changed)
|
||||
notes_service.save_succeeded.connect(_on_save_succeeded)
|
||||
theme_service.theme_changed.connect(_on_theme_changed)
|
||||
_refresh_from_service()
|
||||
_apply_theme()
|
||||
@@ -104,6 +111,8 @@ func _on_service_content_changed(value: String) -> void:
|
||||
|
||||
func _on_service_state_changed(_new_state: String) -> void:
|
||||
_refresh_metadata()
|
||||
if notes_service.state != "saved":
|
||||
saved_status_timer.stop()
|
||||
|
||||
|
||||
func _refresh_from_service() -> void:
|
||||
@@ -111,7 +120,8 @@ func _refresh_from_service() -> void:
|
||||
|
||||
|
||||
func _refresh_metadata() -> void:
|
||||
status_label.text = notes_service.status_text()
|
||||
if status_label.text != "Saved" or saved_status_timer.time_left <= 0.0:
|
||||
status_label.text = notes_service.status_text()
|
||||
count_label.text = "%s / %s" % [
|
||||
_format_count(editor.text.length()),
|
||||
_format_count(notes_service.MAX_CONTENT_LENGTH)
|
||||
@@ -119,7 +129,17 @@ func _refresh_metadata() -> void:
|
||||
conflict_panel.visible = notes_service.conflict_active
|
||||
status_label.add_theme_color_override(
|
||||
"font_color",
|
||||
Brand.AMBER if notes_service.state in ["dirty", "offline", "conflict"] else Brand.muted_color(theme_service.is_dark_mode()))
|
||||
Brand.AMBER if notes_service.state == "conflict" else Brand.muted_color(theme_service.is_dark_mode()))
|
||||
|
||||
|
||||
func _on_save_succeeded() -> void:
|
||||
status_label.text = "Saved"
|
||||
saved_status_timer.start()
|
||||
|
||||
|
||||
func _clear_saved_status() -> void:
|
||||
if status_label.text == "Saved":
|
||||
status_label.text = ""
|
||||
|
||||
|
||||
func _format_count(value: int) -> String:
|
||||
|
||||
Reference in New Issue
Block a user