From 4772f80e50f33bd6f73338f59113bb4cde73fcb1 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Wed, 27 Jun 2018 22:18:16 -0600 Subject: [PATCH] removed current_preset_index, moved createStore --- src/store.js | 15 ++++++++++--- src/ui.js | 59 +++++++++++++++++++++++----------------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/store.js b/src/store.js index 00d19b2f..caf622e8 100644 --- a/src/store.js +++ b/src/store.js @@ -63,12 +63,12 @@ var OldFileStoreDriver = { localforage.defineDriver(OldFileStoreDriver); // copy localStorage to new driver -function copyFromOldStorageFormat(platform_id, newstore) { - var alreadyMigratedKey = "__migrated_" + platform_id; +function copyFromOldStorageFormat(platformid, newstore) { + var alreadyMigratedKey = "__migrated_" + platformid; //localStorage.removeItem(alreadyMigratedKey); if (localStorage.getItem(alreadyMigratedKey)) return; - var oldstore = new OldFileStore(localStorage, platform_id + '/'); + var oldstore = new OldFileStore(localStorage, platformid + '/'); var keys = oldstore.getFiles(''); // no files to convert? if (keys.length == 0) { @@ -100,3 +100,12 @@ function copyFromOldStorageFormat(platform_id, newstore) { } migrateNext(); // start the conversion } + +function createNewPersistentStore(platformid) { + store = localforage.createInstance({ + name: platformid, + version: "2.0" + }); + copyFromOldStorageFormat(platformid, store); + return store; +} diff --git a/src/ui.js b/src/ui.js index ac1483d6..d411bac5 100644 --- a/src/ui.js +++ b/src/ui.js @@ -82,8 +82,8 @@ var TOOL_TO_SOURCE_STYLE = { var worker = new Worker("./src/worker/workermain.js"); var editor; var current_output; -var current_preset_index = -1; -var current_preset_id; +var current_preset_entry; +var current_file_id; var assemblyfile; var sourcefile; var symbolmap; @@ -147,10 +147,10 @@ function inspectVariable(ed, name) { } function getCurrentPresetTitle() { - if (current_preset_index < 0) + if (!current_preset_entry) return "ROM"; else - return PRESETS[current_preset_index].title || PRESETS[current_preset_index].name || "ROM"; + return current_preset_entry.title || current_preset_entry.name || "ROM"; } function setLastPreset(id) { @@ -160,11 +160,11 @@ function setLastPreset(id) { } } -function updatePreset(current_preset_id, text) { +function updatePreset(fileid, text) { // TODO: do we have to save all Verilog thingies? if (text.trim().length && - (originalFileID != current_preset_id || text != originalText || platform_id=='verilog')) { - store.setItem(current_preset_id, text); + (originalFileID != fileid || text != originalText || platform_id=='verilog')) { + store.setItem(fileid, text); } } @@ -179,18 +179,18 @@ function loadCode(text, fileid) { originalText = text; } -function loadFile(fileid, filename, index) { - current_preset_id = fileid; - current_preset_index = index; +function loadFile(fileid, filename, preset) { + current_file_id = fileid; + current_preset_entry = preset; store.getItem(fileid, function(err, text) { if (err) console.log(err); if (!text) text = ''; if (text) { loadCode(text, fileid); - } else if (!text && index >= 0) { + } else if (!text && preset) { if (filename.indexOf('.') <= 0) - filename += ".a"; - console.log("Loading preset", fileid, filename, index, PRESETS[index]); + filename += ".a"; // TODO? + console.log("Loading preset", fileid, filename, preset); if (text.length == 0) { console.log("Fetching", filename); $.get( filename, function( text ) { @@ -224,10 +224,10 @@ function loadPreset(preset_id) { index = (index + PRESETS.length) % PRESETS.length; if (index >= 0) { // load the preset - loadFile(preset_id, "presets/" + platform_id + "/" + PRESETS[index].id, index); + loadFile(preset_id, "presets/" + platform_id + "/" + PRESETS[index].id, PRESETS[index]); } else { // no preset found? load local - loadFile(preset_id, "local/" + platform_id + "/" + preset_id, -1); + loadFile(preset_id, "local/" + platform_id + "/" + preset_id); } } @@ -290,7 +290,7 @@ function handleFileUpload(files) { } function getCurrentFilename() { - var toks = current_preset_id.split("/"); + var toks = current_file_id.split("/"); return toks[toks.length-1]; } @@ -318,9 +318,9 @@ function _shareFile(e) { } function _resetPreset(e) { - if (current_preset_index < 0) { + if (!current_preset_entry) { alert("Can only reset built-in file examples.") - } else if (confirm("Reset '" + PRESETS[current_preset_index].name + "' to default?")) { + } else if (confirm("Reset '" + current_preset_entry.name + "' to default?")) { qs['reset'] = '1'; gotoNewLocation(); } @@ -348,7 +348,7 @@ function populateExamples(sel) { for (var i=0; i").val(preset.id).text(name).attr('selected',preset.id==current_preset_id)); + sel.append($("