EDIT: Further improvements to work-in-progress file UI

This commit is contained in:
Bobbi Webber-Manners 2020-09-01 23:46:43 -04:00
parent 778da1d8af
commit adea96fdb4

View File

@ -1,11 +1,11 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Simple text editor // Apple //e Enhanced text editor
// Supports Apple //e Auxiliary memory and RamWorks style expansions // Supports Apple //e Auxiliary memory and RamWorks style expansions
// Bobbi July-Aug 2020 // Bobbi July-Sept 2020
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//
// TODO: See GitHub issues!!! // See GitHub for open issues!!!
//
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Note: Use my fork of cc65 to get a flashing cursor!! // Note: Use my fork of cc65 to get a flashing cursor!!
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -1974,21 +1974,19 @@ struct tabent {
uint8_t type; uint8_t type;
} *entry; } *entry;
#define FILELINES 15 #define FILELINES 16
/* /*
* File chooser UI * Draw one line in file chooser UI
* TODO: Work in progress * i - index of file to draw
* first - index of first file on screen
* selected - index of currently selected file
* entries - total number of file entries in directory
*/ */
void file_ui_draw(uint16_t first, uint16_t selected, uint16_t entries) { void file_ui_draw(uint8_t i, uint8_t first, uint8_t selected, uint8_t entries) {
uint16_t i;
struct tabent *entry; struct tabent *entry;
uint16_t last = first + FILELINES; gotoxy(5, i - first + 5);
gotoxy(0,0); if (i < entries) {
getcwd(userentry, 74);
cprintf("Dir: %s", userentry);
for (i = first; i <= (last > entries ? entries : last); ++i) {
gotoxy(5, i - first + 4);
entry = (struct tabent*)iobuf + i; entry = (struct tabent*)iobuf + i;
sprintf(userentry, "%02x %s ", entry->type, entry->name); sprintf(userentry, "%02x %s ", entry->type, entry->name);
userentry[20] = '\0'; userentry[20] = '\0';
@ -1997,6 +1995,9 @@ void file_ui_draw(uint16_t first, uint16_t selected, uint16_t entries) {
cputs(userentry); cputs(userentry);
if (i == selected) if (i == selected)
revers(0); revers(0);
} else {
strcpy(userentry, " ");
cputs(userentry);
} }
} }
@ -2004,20 +2005,40 @@ void file_ui_draw(uint16_t first, uint16_t selected, uint16_t entries) {
* File chooser UI * File chooser UI
* TODO: Work in progress * TODO: Work in progress
*/ */
void file_ui(void) { void file_ui_draw_all(uint16_t first, uint16_t selected, uint16_t entries) {
uint16_t i;
uint16_t last = first + FILELINES;
for (i = first; i < last; ++i)
file_ui_draw(i, first, selected, entries);
}
/*
* File chooser UI
* Leaves file name in userentry[], or empty string if error/cancel
* TODO: Work in progress
*/
void file_ui(char *msg) {
struct tabent *entry; struct tabent *entry;
DIR *dp; DIR *dp;
struct dirent *ent; struct dirent *ent;
char c; char c;
uint16_t entries, current, first; uint16_t entries, current, first;
restart: restart:
clrscr();
gotoxy(0,0);
revers(1);
cprintf("%s", msg);
revers(0);
getcwd(userentry, 74);
gotoxy(0,2);
cprintf("Dir: %s", userentry);
entries = current = first = 0; entries = current = first = 0;
cutbuflen = 0; cutbuflen = 0;
entry = (struct tabent*)iobuf; entry = (struct tabent*)iobuf;
strcpy(entry->name, ".."); strcpy(entry->name, ".."); // Add fake '..' entry
entry->type = 0x0f; // Directory entry->type = 0x0f;
++entry; ++entry;
clrscr(); ++entries;
cursor(0); cursor(0);
dp = opendir("."); dp = opendir(".");
while (1) { while (1) {
@ -2030,8 +2051,9 @@ restart:
++entries; ++entries;
} }
closedir(dp); closedir(dp);
redraw:
file_ui_draw_all(first, current, entries);
while (1) { while (1) {
file_ui_draw(first, current, entries);
c = cgetc(); c = cgetc();
switch (c) { switch (c) {
case 0x0b: // Up case 0x0b: // Up
@ -2042,16 +2064,20 @@ restart:
first -= FILELINES; first -= FILELINES;
else else
first = 0; first = 0;
clrscr(); goto redraw;
} }
file_ui_draw(current, first, current, entries);
file_ui_draw(current + 1, first, current, entries);
break; break;
case 0x0a: // Down case 0x0a: // Down
if (current < entries) if (current < entries - 1)
++current; ++current;
if (current >= first + FILELINES) { if (current >= first + FILELINES) {
first += FILELINES; first += FILELINES;
clrscr(); goto redraw;
} }
file_ui_draw(current - 1, first, current, entries);
file_ui_draw(current, first, current, entries);
break; break;
case EOL: case EOL:
entry = (struct tabent*)iobuf + current; entry = (struct tabent*)iobuf + current;
@ -2075,21 +2101,37 @@ restart:
} }
break; break;
case 0x04: // ASCII text case 0x04: // ASCII text
cprintf("*** %s **** ASCII", entry->name); strcpy(userentry, entry->name);
goto done; goto done;
break; break;
default: default:
cprintf("*** %s **** NONASCII", entry->name); if (prompt_okay("Not a text file") != 0) {
strcpy(userentry, "");
goto done;
}
strcpy(userentry, entry->name);
goto done; goto done;
} }
return; break;
case ESC: case ESC:
cursor(1); strcpy(userentry, "");
goto done;
break;
default: // Any other key ... prompt for filename
if (prompt_for_name("Enter filename", 0) == 255)
goto restart; // ESC pressed
if (userentry[0] == '/') // Absolute path
goto done;
getcwd(replace, 74); // Otherwise relative path
strcat(replace, "/");
strcat(replace, userentry);
strcpy(userentry, replace);
strcpy(replace, "");
goto done; goto done;
} }
} }
done: done:
cgetc(); clrscr();
cursor(1); cursor(1);
} }
@ -2296,10 +2338,11 @@ int edit(char *fname) {
break; break;
case 0x80 + 'I': // OA-I "Insert file" case 0x80 + 'I': // OA-I "Insert file"
case 0x80 + 'i': case 0x80 + 'i':
if (prompt_for_name("File to insert", 1) == 255) file_ui("Insert File");
break; // ESC pressed if (strlen(userentry) == 0) {
if (strlen(userentry) == 0) draw_screen();
break; break;
}
mark_undo(); mark_undo();
if (load_file(userentry, 0, 0)) { if (load_file(userentry, 0, 0)) {
snprintf(iobuf, 80, "Can't open '%s'", userentry); snprintf(iobuf, 80, "Can't open '%s'", userentry);
@ -2311,10 +2354,11 @@ int edit(char *fname) {
case 0x80 + 'o': case 0x80 + 'o':
if (status[0]) if (status[0])
save(); save();
if (prompt_for_name("File to open", 1) == 255) file_ui("Open File");
break; // ESC pressed if (strlen(userentry) == 0) {
if (strlen(userentry) == 0) draw_screen();
break; break;
}
strcpy(filename, userentry); strcpy(filename, userentry);
if (load_file(filename, 1, 0)) { if (load_file(filename, 1, 0)) {
snprintf(userentry, 80, "Can't open '%s'", filename); snprintf(userentry, 80, "Can't open '%s'", filename);
@ -2530,9 +2574,6 @@ donehelp:
} else if ((c =='S') || (c == 's')) { // CA-S "Save all" } else if ((c =='S') || (c == 's')) { // CA-S "Save all"
save_all(); save_all();
draw_screen(); draw_screen();
} else if (c == '\\') { // TODO: TEMP DEBUG KEY
file_ui();
draw_screen();
} }
} }
else if ((c >= 0x20) && (c < 0x80) && (mode == SEL_NONE)) { else if ((c >= 0x20) && (c < 0x80) && (mode == SEL_NONE)) {