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 file_path_file_dialog: FileDialog = %FilePathFileDialog @onready var file_path_line_edit: LineEdit = %FilePathLineEdit @onready var file_path_button: Button = %FilePathButton @onready var theme_path_file_dialog: FileDialog = %ThemePathFileDialog @onready var theme_path_button: Button = %ThemePathButton @onready var sound_check_box: CheckBox = %SoundCheckBox @onready var attributions_rich_text_label: RichTextLabel = %AttributionsRichTextLabel @onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer @onready var open_data_dir_button: Button = %OpenDataDirButton var timesheet: TimeSheet var config: ConfigManager = preload("res://config_manager.tres") func _init() -> void: if config.theme_path: var new_theme: Theme = ResourceLoader.load(config.theme_path, "Theme") if new_theme != null: theme = new_theme func _ready() -> void: get_tree().set_auto_accept_quit(false) var _root := time_entries_items_tree.create_item() file_path_button.pressed.connect( file_path_file_dialog.popup_centered ) file_path_file_dialog.file_selected.connect(set_current_file) file_path_line_edit.text_submitted.connect(set_current_file) theme_path_button.pressed.connect( theme_path_file_dialog.popup_centered ) theme_path_file_dialog.file_selected.connect( func theme_selected(theme_path: String) -> void: var new_theme: Theme = ResourceLoader.load(theme_path, "Theme") if new_theme != null: theme = new_theme config.theme_path = theme_path ) theme_path_file_dialog.hide() file_path_file_dialog.hide() previous_tasks_window.hide() settings_window.hide() timer.timeout.connect( func on_timer_timeout() -> void: timesheet.update() time_label.text = timesheet.get_period() var total_elapsed: int = 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 sound_check_box.button_pressed: audio_stream_player.play() if is_on: timesheet.start_entry(task_name_line_edit.text) set_button_as_started() else: 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() ) sound_check_box.button_pressed = config.sound_fx_on sound_check_box.toggled.connect( func sound_toggle(is_on: bool) -> void: config.sound_fx_on = is_on ) open_data_dir_button.pressed.connect( OS.shell_open.bind(OS.get_user_data_dir()) ) attributions_rich_text_label.meta_clicked.connect(OS.shell_open) set_current_file(config.current_file) func set_button_as_started() -> void: time_entries_items_tree.set_current_item(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() ## Changes the data file path, and loads the new path func set_current_file(new_current_file: String) -> void: timesheet = TimeSheet.restore(new_current_file) if timesheet == null: return config.current_file = new_current_file for entry_name in timesheet.entries_names: time_entries_items_tree.append_name_to_tree(entry_name, timesheet.entries_names[entry_name]) if timesheet.current_entry != null and timesheet.current_entry.closed == false: start_button.set_pressed_no_signal(true) set_button_as_started() file_path_file_dialog.current_path = config.current_file file_path_file_dialog.current_dir = config.current_file.get_base_dir() file_path_line_edit.text = config.current_file 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)