@ -55,14 +55,14 @@ main :: proc() {
// Load files from command line arguments
if len(args) > 1 {
for filename in args {
open_file (&app, filename)
create_file_buffer (&app, filename)
}
} else {
open_file (&app)
create_file_buffer (&app)
}
if len(app.files) == 0 {
fmt.println("N o files could be loaded")
log.error("n o files could be loaded")
rl.CloseWindow()
return
}
@ -79,8 +79,8 @@ main :: proc() {
rl.ClearBackground(app.config.colours.background)
for file in app.files {
if file.finished_saving && thread.is_done(file .thread) {
thread.destroy(file .thread)
if app.thread_finished && thread.is_done(app .thread) {
thread.destroy(app .thread)
}
}
@ -263,18 +263,10 @@ main :: proc() {
// Handle keyboard shortcuts
if rl.IsKeyDown(.LEFT_CONTROL) || rl.IsKeyDown(.RIGHT_CONTROL) {
if rl.IsKeyPressed(.S) {
current_file .thread = thread.create_and_start_with_poly_data2(&app, current_file, save_file)
app .thread = thread.create_and_start_with_poly_data2(&app, current_file, save_file)
}
if rl.IsKeyPressed(.O) {
app.file_dialog_open = true
result := file_dialog.show_open_file_dialog()
app.file_dialog_open = false
if !result.success {
log.error(result.error_message)
}
defer file_dialog.destroy_result(&result)
open_file(&app, result.file_path)
app.thread = thread.create_and_start_with_poly_data(&app, open_file)
}
if rl.IsKeyPressed(.A) {
select_all(current_file)
@ -333,7 +325,9 @@ load_fonts :: proc(app: ^App) {
app.line_height = app.fonts[app.current_font_index].size + 4
}
open_file :: proc(app: ^App, filename: string = "") {
create_file_buffer :: proc(app: ^App, filename: string = "") -> (ok: bool) {
ok = false
buffer: File_Buffer
if len(filename) == 0 {
buffer = File_Buffer{
@ -362,6 +356,31 @@ open_file :: proc(app: ^App, filename: string = "") {
}
append(&app.files, buffer)
ok = true
return
}
open_file :: proc(app: ^App) {
app.file_dialog_open = true
result: file_dialog.Result
result = file_dialog.show_open_file_dialog()
app.file_dialog_open = false
if !result.success {
log.error(result.error_message)
return
}
defer file_dialog.destroy_result(&result)
ok := create_file_buffer(app, result.file_path)
if !ok {
log.error("failed ot create file buffer")
return
}
app.active_tab+=1
return
}
get_wrapped_lines :: proc(content: string, font: ^FontConfig, max_width: f32) -> []WrappedLine {
@ -866,7 +885,7 @@ move_cursor_to_end_of_line :: proc(file: ^File_Buffer) {
}
save_file :: proc(app: ^App, file: ^File_Buffer) {
file.finished_saving = false
app.thread_finished = false
if len(file.filename) == 0 {
app.file_dialog_open = true
result := file_dialog.show_save_file_dialog()
@ -885,6 +904,6 @@ save_file :: proc(app: ^App, file: ^File_Buffer) {
log.error("failed to save file, \"", file.filename, "\"", sep="") // TODO: Show popup window that displays this to the user
return
}
file.finished_saving = true
app.thread_finished = true
}