EDIT: Improved status display when cut/paste using CLIPBOARD file

This commit is contained in:
Bobbi Webber-Manners
2020-08-17 10:45:52 -04:00
parent d979b64adc
commit 7d07a861bb

View File

@@ -751,15 +751,20 @@ uint8_t open_new_aux_bank(uint8_t partnum) {
/* /*
* Spinner while loading / saving * Spinner while loading / saving
* TODO: THIS IS NOT REALLY SAFE IF FILENAME IS TOO LONG!!!!!!! * saving - 1 if we are saving, 0 if we are loading
* copymode - 1 if this is cut/paste, 0 otherwise
*/ */
void spinner(uint32_t sz, uint8_t saving) { void spinner(uint32_t sz, uint8_t saving, uint8_t copymode) {
static char chars[] = "|/-\\"; static char chars[] = "|/-\\";
static char buf[80] = ""; static char buf[80] = "";
static uint8_t i = 0; static uint8_t i = 0;
gotoxy(0, PROMPT_ROW); gotoxy(0, PROMPT_ROW);
snprintf(buf, 80, "%s '%s': %c [%lu]", if (copymode)
(saving ? "Saving" : "Opening"), filename, chars[(i++) % 4], sz); snprintf(buf, 80, "%s clipboard: %c [%lu]",
(saving ? "Copying to" : "Pasting from"), chars[(i++) % 4], sz);
else
snprintf(buf, 80, "%s '%s': %c [%lu]",
(saving ? "Saving" : "Opening"), filename, chars[(i++) % 4], sz);
revers(1); revers(1);
cprintf("%s", buf); cprintf("%s", buf);
cclear(79 - strlen(buf)); cclear(79 - strlen(buf));
@@ -773,12 +778,12 @@ void draw_screen(void);
* Load a file from disk into the gapbuf * Load a file from disk into the gapbuf
* filename - name of file to load * filename - name of file to load
* replace - if 1, replace old file. * replace - if 1, replace old file.
* initialcol - initial screen column * copymode - if 1, then load from CLIPBOARD
* Returns 0 on success * Returns 0 on success
* 1 if file can't be opened * 1 if file can't be opened
*/ */
#pragma code-name (push, "LC") #pragma code-name (push, "LC")
uint8_t load_file(char *fname, uint8_t replace) { uint8_t load_file(char *fname, uint8_t replace, uint8_t copymode) {
uint8_t partctr = 0; uint8_t partctr = 0;
uint8_t col; uint8_t col;
char *p; char *p;
@@ -808,7 +813,7 @@ uint8_t load_file(char *fname, uint8_t replace) {
goto done; goto done;
} }
#endif #endif
spinner(DATASIZE(), 0); spinner(DATASIZE(), 0, copymode);
s = fread(p, 1, IOSZ, fp); s = fread(p, 1, IOSZ, fp);
cont = (s == IOSZ ? 1 : 0); cont = (s == IOSZ ? 1 : 0);
for (i = 0; i < s; ++i) { for (i = 0; i < s; ++i) {
@@ -842,19 +847,10 @@ uint8_t load_file(char *fname, uint8_t replace) {
set_gapbuf(gapbegin++, p[i]); set_gapbuf(gapbegin++, p[i]);
++col; ++col;
} }
#ifdef AUXMEM
// Will never happen in replace mode because
// we will have already opened a new bank
if (FREESPACE() < IOSZ * 2) { if (FREESPACE() < IOSZ * 2) {
show_error("File truncated"); show_error("File truncated");
goto done; goto done;
} }
#else
if (FREESPACE() < IOSZ * 2) {
show_error("File truncated");
goto done;
}
#endif
} }
} while (cont); } while (cont);
done: done:
@@ -915,7 +911,7 @@ uint8_t save_file(uint8_t copymode, uint8_t append) {
else else
sz = DATASIZE(); sz = DATASIZE();
for (i = 0; i < sz / IOSZ; ++i) { for (i = 0; i < sz / IOSZ; ++i) {
spinner(i * IOSZ, 1); spinner(i * IOSZ, 1, copymode);
#ifdef AUXMEM #ifdef AUXMEM
for (j = 0; j < IOSZ; ++j) for (j = 0; j < IOSZ; ++j)
iobuf[j] = get_gapbuf(p++); iobuf[j] = get_gapbuf(p++);
@@ -927,7 +923,7 @@ uint8_t save_file(uint8_t copymode, uint8_t append) {
p += IOSZ; p += IOSZ;
#endif #endif
} }
spinner(i * IOSZ, 1); spinner(i * IOSZ, 1, copymode);
#ifdef AUXMEM #ifdef AUXMEM
for (j = 0; j < sz - (IOSZ * i); ++j) for (j = 0; j < sz - (IOSZ * i); ++j)
iobuf[j] = get_gapbuf(p++); iobuf[j] = get_gapbuf(p++);
@@ -1930,6 +1926,7 @@ void order_selection(void) {
/* /*
* Main editor routine * Main editor routine
* fname - filename to open or ""
*/ */
int edit(char *fname) { int edit(char *fname) {
char c; char c;
@@ -1939,7 +1936,7 @@ int edit(char *fname) {
if (fname) { if (fname) {
strcpy(filename, fname); strcpy(filename, fname);
cprintf("Loading file %s ", filename); cprintf("Loading file %s ", filename);
if (load_file(filename, 1)) { if (load_file(filename, 1, 0)) {
snprintf(userentry, 80, "Can't load '%s'", filename); snprintf(userentry, 80, "Can't load '%s'", filename);
show_error(userentry); show_error(userentry);
strcpy(filename, ""); strcpy(filename, "");
@@ -2083,7 +2080,7 @@ int edit(char *fname) {
__asm__("sta $c073"); // Set aux bank back to 0 __asm__("sta $c073"); // Set aux bank back to 0
gapbegin += cutbuflen; gapbegin += cutbuflen;
} else { } else {
if (load_file("CLIPBOARD", 0)) if (load_file("CLIPBOARD", 0, 1))
show_error("Can't open CLIPBOARD"); show_error("Can't open CLIPBOARD");
} }
startsel = endsel = 65535U; startsel = endsel = 65535U;
@@ -2124,7 +2121,7 @@ int edit(char *fname) {
break; // ESC pressed break; // ESC pressed
if (strlen(userentry) == 0) if (strlen(userentry) == 0)
break; break;
if (load_file(userentry, 0)) { if (load_file(userentry, 0, 0)) {
snprintf(iobuf, 80, "Can't open '%s'", userentry); snprintf(iobuf, 80, "Can't open '%s'", userentry);
show_error(iobuf); show_error(iobuf);
} }
@@ -2139,7 +2136,7 @@ int edit(char *fname) {
if (strlen(userentry) == 0) if (strlen(userentry) == 0)
break; break;
strcpy(filename, userentry); strcpy(filename, userentry);
if (load_file(filename, 1)) { if (load_file(filename, 1, 0)) {
snprintf(userentry, 80, "Can't open '%s'", filename); snprintf(userentry, 80, "Can't open '%s'", filename);
show_error(userentry); show_error(userentry);
strcpy(filename, ""); strcpy(filename, "");