# HG changeset patch # User Matti Hamalainen # Date 1530846867 -10800 # Node ID 6429d0b757cdc1acb463756935b88999e3da83fa # Parent 73a8773466ae0fe828056dd0e854a5d130e811fa Implement quick save/load ("S"/"L") via browser local storage. diff -r 73a8773466ae -r 6429d0b757cd events.pde --- a/events.pde Fri Jul 06 05:29:26 2018 +0300 +++ b/events.pde Fri Jul 06 06:14:27 2018 +0300 @@ -803,23 +803,7 @@ redo_undo(); refresh(); } - if (g_data[int('S')] == 1) { - g_data[int('S')] = 0; - String sname = g_spare ? sfilename : filename; - if (sname) { - if (g_iconmode == 0) { - message(g_spare ? "Spare page|saved" : "Page saved"); - mpSaveNativeImage(sname); - } - - } else { - message("No filename!"); - message("*"); - g_data[int('S')] = 0; - g_data[int('s')] = 0; - } - } if (machine == SPECTRUM) { if (g_data[int('i')] == 1) { @@ -847,7 +831,52 @@ g_data[int('s')] = 0; saveas = true; } + + if (g_data[int('S')] == 1) + { + g_data[int('S')] = 0; + g_data[int('s')] = 0; + + if (mpHaveLocalStorage()) + { + var fdata = mpGetNativeImage(); + if (fdata != null) + { + var fstr = JSON.stringify(fdata); + localStorage.setItem("MPIMAGE_DATA", fstr); + message("Saved to lstorage"); + } + else + message("ERROR"); + } + else + message("Lstorage/save|not available"); + } + if (g_data[int('L')] == 1) { g_data[int('L')] = 0; + if (mpHaveLocalStorage()) + { + var fstr = localStorage.getItem("MPIMAGE_DATA"); + if (fstr != null && typeof(fstr) == "string") + { + var fdata = JSON.parse(fstr); + if (typeof(fdata) == "object" && + Array.isArray(fdata)) + { + int res = mpSetNativeImage(fdata, false); + if (res != 0) + message("Wrong machine"); + else + message("Loaded lstorage"); + } + else + message("Invalid data in lstorage"); + } + else + message("No data in lstorage"); + } + else + message("Lstorage/load|not available"); } }