Files
Upsilon/apps/code/script_store.h
Léa Saviot a19377ad5e [code] Default numbered script names (e.g. script1.py)
When the script name is empty after renaming a script, a default new name is
given. We look for the first available scriptI.py name, with 0<I<100.

Change-Id: If17f1df95c552320c0412ce652e7ae7e0cfd9cbc
2017-11-17 11:59:50 +01:00

50 lines
1.4 KiB
C++

#ifndef CODE_SCRIPT_STORE_H
#define CODE_SCRIPT_STORE_H
#include "script.h"
#include "script_template.h"
#include <escher/accordion.h>
#include <python/port/port.h>
namespace Code {
class ScriptStore : public MicroPython::ScriptProvider {
public:
enum class EditableZone {
None,
Name,
Content
};
static constexpr char k_scriptExtension[] = ".py";
static constexpr char k_defaultScriptName[] = "script.py";
ScriptStore();
const Script scriptAtIndex(int index, EditableZone zone = EditableZone::None);
const Script scriptNamed(const char * name);
int numberOfScripts();
bool addNewScript();
bool renameScriptAtIndex(int index, const char * newName);
void switchAutoImportAtIndex(int index);
void deleteScriptAtIndex(int index);
void deleteAllScripts();
/* MicroPython::ScriptProvider */
const char * contentOfScript(const char * name) override;
private:
static constexpr size_t k_scriptDataSize = 1024;
bool addScriptFromTemplate(const ScriptTemplate * scriptTemplate);
bool copyStaticScriptOnFreeSpace(const ScriptTemplate * scriptTemplate);
int accordionIndexOfScriptAtIndex(int index) const;
int accordionIndexOfMarkersOfScriptAtIndex(int index) const;
int accordionIndexOfNameOfScriptAtIndex(int index) const;
int accordionIndexOfContentOfScriptAtIndex(int index) const;
char m_scriptData[k_scriptDataSize];
Accordion m_accordion;
};
}
#endif