extends Control @onready var time_label: Label = %TimeLabel @onready var start_button: Button = %StartButton @onready var task_name_line_edit: LineEdit = %TaskNameLineEdit @onready var time_entries_items_tree: TimeEntriesItemsTree = %TimeEntriesItemsTree @onready var timer: Timer = %Timer @onready var tasks_button: Button = %TasksButton @onready var settings_button: Button = %SettingsButton @onready var previous_tasks_window: Window = %PreviousTasksWindow @onready var settings_window: Window = %SettingsWindow @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer var config: ConfigManager = preload("res://config_manager.tres") func _ready() -> void: config.file_changed.connect(set_initial_state) config.theme_changed.connect( func theme_changed() -> void: theme = config.them ) get_tree().set_auto_accept_quit(false) previous_tasks_window.hide() settings_window.hide() timer.timeout.connect( func on_timer_timeout() -> void: config.timesheet.update() time_label.text = config.timesheet.get_period() var total_elapsed: int = config.timesheet.get_total_elapsed_seconds() time_entries_items_tree.set_time_elapsed(total_elapsed) ) start_button.tooltip_text = tr(Consts.START) start_button.toggle_mode = true start_button.toggled.connect( func start(is_on: bool) -> void: if config.sound_fx_on: audio_stream_player.play() if is_on: config.timesheet.start_entry(task_name_line_edit.text) set_button_as_started() else: config.timesheet.close_entry() set_button_as_stopped() ) task_name_line_edit.text = config.last_task_name task_name_line_edit.text_changed.connect( func(new_text: String) -> void: config.last_task_name = new_text ) time_entries_items_tree.item_selected.connect( func item_selected() -> void: task_name_line_edit.text = time_entries_items_tree.get_current_text() ) tasks_button.toggle_mode = true tasks_button.toggled.connect( func tasks_toggled(is_on: bool) -> void: previous_tasks_window.visible = is_on ) previous_tasks_window.close_requested.connect( func close() -> void: tasks_button.set_pressed_no_signal(false) previous_tasks_window.hide() ) settings_button.toggle_mode = true settings_button.toggled.connect( func settings_toggled(is_on: bool) -> void: settings_window.visible = is_on ) settings_window.close_requested.connect( func close() -> void: settings_button.set_pressed_no_signal(false) settings_window.hide() ) func set_button_as_started() -> void: time_entries_items_tree.set_current_item(config.timesheet.current_entry.name) start_button.tooltip_text = tr(Consts.STOP) start_button.theme_type_variation = Consts.THEME_OVERRIDE_STOP timer.start() func set_button_as_stopped() -> void: start_button.tooltip_text = tr(Consts.START) time_label.text = Consts.NO_TIME start_button.theme_type_variation = Consts.THEME_OVERRIDE_START timer.stop() func set_initial_state() -> void: if config.timesheet.current_entry != null and config.timesheet.current_entry.closed == false: start_button.set_pressed_no_signal(true) set_button_as_started() func _notification(what: int) -> void: if what == NOTIFICATION_WM_CLOSE_REQUEST: get_tree().quit() ## Unused; if a manual quit button is added, this would be used func quit() -> void: get_tree().notification(NOTIFICATION_WM_CLOSE_REQUEST)