diff --git a/README.md b/README.md index a167151..dccd831 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The Terminal is a Command line shell built into the kernel with an 8 entry comma ### Notepad -A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. Defaults to editing the file `records/notes`. Using the `edit` command in shell allows editing of any file. +A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. `Ctrl+S` saves and `Ctrl+O` opens a file by path (a path that doesn't exist starts a new note there). Defaults to editing the file `records/notes`. Using the `edit` command in shell allows editing of any file. Closing with `X` while there are unsaved changes asks whether to Save, Discard or Cancel. ### Files diff --git a/apps/notepad/notepad.c b/apps/notepad/notepad.c index ef6fe9a..188fbd7 100644 --- a/apps/notepad/notepad.c +++ b/apps/notepad/notepad.c @@ -22,7 +22,7 @@ static const vigil_api_t* api = 0; #define STATUS_ROWS 1 #define STATUS_TEXT_X 8 -#define STATUS_LINE_MAX 120 +#define STATUS_LINE_MAX 128 #define NOTE_FG GFX_WHITE #define NOTE_BG GFX_BLACK @@ -229,7 +229,7 @@ static void draw_status(void) { line[0] = '\0'; append_text(line, &pos, file_path); - append_text(line, &pos, " | Ctrl+S: save | "); + append_text(line, &pos, " | Ctrl+S: save Ctrl+O: open | "); api->kuitoa((uint32_t) length, number); append_text(line, &pos, number); @@ -562,6 +562,29 @@ static void notepad_open_file(const char* path) { open_file(path); } +// --- open prompt --- + +static void start_open_prompt(void) { + api->mouse_hide_cursor(); + + if (dirty) { + status_note = "unsaved changes - press Ctrl+S first"; + draw_status(); + return; + } + + const char* initial = ""; + if (api->kstrlen(file_path) < PROMPT_BUFFER_SIZE) { + initial = file_path; + } + + api->prompt_open("Open file (new path = new note):", initial, FS_MAX_PATH - 1, ""); +} + +static void notepad_prompt_done(const char* path) { + open_file(path); +} + // --- close dialog --- static const char* const close_labels[3] = { @@ -618,6 +641,8 @@ static void notepad_redraw(void) { static void notepad_handle_char(char c) { if (c == KEY_CTRL_S) { save_note(); + } else if (c == KEY_CTRL_O) { + start_open_prompt(); } else if (c == '\b') { backspace(); } else if (c == KEY_DELETE) { @@ -693,6 +718,7 @@ int app_entry(const vigil_api_t* kernel_api, app_t* out_app) { out_app->on_tick = notepad_update_cursor; out_app->on_click = notepad_handle_click; out_app->on_open_file = notepad_open_file; + out_app->on_prompt_done = notepad_prompt_done; out_app->on_close_request = notepad_close_request; out_app->on_dialog_done = notepad_dialog_done; out_app->icon = notepad_icon; diff --git a/apps/shell/shell.c b/apps/shell/shell.c index ee622d8..9c08004 100644 --- a/apps/shell/shell.c +++ b/apps/shell/shell.c @@ -368,7 +368,7 @@ void shell_handle_char(char c) { return; } - if (c == KEY_CTRL_S || c == KEY_ARROW_LEFT || c == KEY_ARROW_RIGHT || c == KEY_HOME || c == KEY_END || c == KEY_DELETE) { + if (c == KEY_CTRL_S || c == KEY_CTRL_O || c == KEY_ARROW_LEFT || c == KEY_ARROW_RIGHT || c == KEY_HOME || c == KEY_END || c == KEY_DELETE) { return; } diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index 1c2ad0c..941135e 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -165,6 +165,8 @@ static void keyboard_callback(struct registers regs) { if (ctrl_held) { if (lower == 's') { key_queue_push(KEY_CTRL_S); + } else if (lower == 'o') { + key_queue_push(KEY_CTRL_O); } return; } diff --git a/kernel/drivers/keyboard.h b/kernel/drivers/keyboard.h index ef38677..412ebb9 100644 --- a/kernel/drivers/keyboard.h +++ b/kernel/drivers/keyboard.h @@ -6,6 +6,7 @@ #define KEY_ESCAPE 27 #define KEY_CTRL_S 0x13 +#define KEY_CTRL_O 0x0f #define KEY_ARROW_UP 0x01 #define KEY_ARROW_DOWN 0x02