-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding text editor functionality to text viewer. #868
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#pragma once | ||
|
||
#include "common.h" | ||
#include "hid.h" | ||
#include "ui.h" | ||
#include "touchcal.h" | ||
|
||
|
@@ -20,11 +21,16 @@ enum { | |
KEY_ESCAPE = 0x8A, | ||
KEY_SWITCH = 0x8B, | ||
KEY_UNICODE = 0x8C, | ||
KEY_UP = 0x8D, | ||
KEY_DOWN = 0x8E, | ||
KEY_CLIP = 0x8F, | ||
KEY_TXTBOX = 0xFF | ||
}; | ||
|
||
// special key strings | ||
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+" | ||
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+", "↑", "↓" | ||
// multiline special key stings | ||
#define SWKBD_ML_KEYSTR "", "DEL", "INS", "ENTER", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+", "↑", "↓" | ||
|
||
#define COLOR_SWKBD_NORMAL COLOR_GREY | ||
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY | ||
|
@@ -45,6 +51,13 @@ enum { | |
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '_', '#', '!', \ | ||
KEY_CAPS, ' ', KEY_NUMPAD, KEY_SPECIAL, KEY_LEFT, KEY_RIGHT | ||
|
||
#define SWKBD_KEYS_ML_ALPHABET \ | ||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-', KEY_BKSPC, \ | ||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '&', KEY_ENTER, \ | ||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '(', ')', '[', ']', \ | ||
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '_', '#', '!', \ | ||
KEY_CAPS, ' ', KEY_NUMPAD, KEY_SPECIAL, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN | ||
|
||
#define SWKBD_KEYS_SPECIAL \ | ||
'(', ')', '{', '}', '[', ']', \ | ||
'.', ',', '?', '!', '`', '\'', \ | ||
|
@@ -53,9 +66,9 @@ enum { | |
KEY_ALPHA, ' ', KEY_BKSPC | ||
|
||
#define SWKBD_KEYS_NUMPAD \ | ||
'7', '8', '9', 'F', 'E', \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the arrangement of these to be more consistent with e.g. calculators. |
||
'4', '5', '6', 'D', 'C', \ | ||
'3', '2', '1', 'B', 'A', \ | ||
'7', '8', '9', 'E', 'F', \ | ||
'4', '5', '6', 'C', 'D', \ | ||
'1', '2', '3', 'A', 'B', \ | ||
'0', '.', '_', KEY_LEFT, KEY_RIGHT, \ | ||
KEY_ALPHA, KEY_UNICODE, ' ', KEY_BKSPC | ||
|
||
|
@@ -68,12 +81,20 @@ enum { | |
6, 32, 123, 32, 32, 18, 18, 0, \ | ||
0 | ||
|
||
#define SWKBD_LAYOUT_ML_ALPHABET \ | ||
13, 32, 0, \ | ||
12, 51, 0, \ | ||
13, 0, \ | ||
12, 0, \ | ||
8, 32, 85, 32, 32, 18, 18, 18, 18, 0, \ | ||
0 | ||
|
||
#define SWKBD_LAYOUT_SPECIAL \ | ||
6, 0, \ | ||
6, 0, \ | ||
6, 0, \ | ||
6, 0, \ | ||
3, 32, 46, 32, 0, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was bothering me as well. |
||
3, 32, 47, 32, 0, \ | ||
0 | ||
|
||
#define SWKBD_LAYOUT_NUMPAD \ | ||
|
@@ -87,3 +108,7 @@ enum { | |
|
||
#define ShowKeyboardOrPrompt (TouchIsCalibrated() ? ShowKeyboard : ShowStringPrompt) | ||
bool PRINTF_ARGS(3) ShowKeyboard(char* inputstr, u32 max_size, const char *format, ...); | ||
|
||
// Exposing this to prevent rebuilds between keypresses in the ShowMultiLineKeyboard calling functions. | ||
bool BuildKeyboard(TouchBox* swkbd, const char* keys, const u8* layout, bool multi_line); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exposed to prevent rebuilds between keypresses in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of these Github comments should probably be code comments instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BlueRaja done. I went through and added code comments where I felt they were relevant. If you have any other concerns, please let me know. 😁 |
||
char ShowMultiLineKeyboard(const char* instructions, TouchBox* swkbd_alphabet, TouchBox* swkbd_special, TouchBox* swkbd_numpad, TouchBox** swkbd, TouchBox** swkbd_prev, u32* uppercase); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1225,7 +1225,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan | |
int n_opt = 0; | ||
int special = (special_opt) ? ++n_opt : -1; | ||
int hexviewer = ++n_opt; | ||
int textviewer = (filetype & TXT_GENERIC) ? ++n_opt : -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allowing for editing of empty files. |
||
int textviewer = (filetype & TXT_GENERIC || FileGetSize(file_path) == 0) ? ++n_opt : -1; | ||
int calcsha256 = ++n_opt; | ||
int calcsha1 = ++n_opt; | ||
int calccmac = (CheckCmacPath(file_path) == 0) ? ++n_opt : -1; | ||
|
@@ -1316,6 +1316,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan | |
} | ||
else if (user_select == textviewer) { // -> show in text viewer | ||
FileTextViewer(file_path, scriptable); | ||
GetDirContents(current_dir, current_path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary, I assume, to recalculate file sizes? |
||
return 0; | ||
} | ||
else if (user_select == calcsha256) { // -> calculate SHA-256 | ||
|
@@ -2340,7 +2341,7 @@ u32 HomeMoreMenu(char* current_path) { | |
char* sysinfo_txt = (char*) malloc(STD_BUFFER_SIZE); | ||
if (!sysinfo_txt) return 1; | ||
MyriaSysinfo(sysinfo_txt); | ||
MemTextViewer(sysinfo_txt, strnlen(sysinfo_txt, STD_BUFFER_SIZE), 1, false); | ||
MemTextViewer(sysinfo_txt, strnlen(sysinfo_txt, STD_BUFFER_SIZE), 1, false, 0, NULL); | ||
free(sysinfo_txt); | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to "Text Editor"/"Texteditor"/"Hex Editor"/"Hexeditor" guidance here...