Implement PRGEDIT,PRGGET$()
This commit is contained in:
@@ -3158,6 +3158,22 @@ class BuiltinFunction
|
|||||||
auto dialog = new Dialog(p);
|
auto dialog = new Dialog(p);
|
||||||
p.project.result = cast(DialogResult)dialog.show(text, cast(SelectionType)selType, cast(wstring)cap, cast(int)timeout);
|
p.project.result = cast(DialogResult)dialog.show(text, cast(SelectionType)selType, cast(wstring)cap, cast(int)timeout);
|
||||||
}
|
}
|
||||||
|
static void PRGEDIT(PetitComputer p, int slot)
|
||||||
|
{
|
||||||
|
PRGEDIT(p, slot, 1);
|
||||||
|
}
|
||||||
|
static void PRGEDIT(PetitComputer p, int slot, int line)
|
||||||
|
{
|
||||||
|
if (slot < 0 || p.program.slotSize <= slot)
|
||||||
|
throw new OutOfRange("PRGEDIT", 1);
|
||||||
|
if (line < -1 || line == 0)
|
||||||
|
throw new OutOfRange("PRGEDIT"/*, 2*/);
|
||||||
|
p.program.edit(slot, line);
|
||||||
|
}
|
||||||
|
static wstring PRGGET(PetitComputer p)
|
||||||
|
{
|
||||||
|
return p.program.get();
|
||||||
|
}
|
||||||
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
//alias void function(PetitComputer, Value[], Value[]) BuiltinFunc;
|
||||||
static BuiltinFunctions[wstring] builtinFunctions;
|
static BuiltinFunctions[wstring] builtinFunctions;
|
||||||
static wstring getBasicName(BFD)(const wstring def)
|
static wstring getBasicName(BFD)(const wstring def)
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
module otya.smilebasic.program;
|
module otya.smilebasic.program;
|
||||||
|
import std.range;
|
||||||
import std.container;
|
import std.container;
|
||||||
|
|
||||||
struct Slot
|
struct Slot
|
||||||
{
|
{
|
||||||
DList!wstring program;
|
DList!wstring program;
|
||||||
|
DList!wstring.Range range;
|
||||||
void load(wstring data)
|
void load(wstring data)
|
||||||
{
|
{
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
@@ -12,6 +14,11 @@ struct Slot
|
|||||||
{
|
{
|
||||||
program.insertBack(l ~ '\n');
|
program.insertBack(l ~ '\n');
|
||||||
}
|
}
|
||||||
|
if (program.back == "\n")
|
||||||
|
{
|
||||||
|
program.removeBack();
|
||||||
|
}
|
||||||
|
range = program[];
|
||||||
}
|
}
|
||||||
wchar[] text()
|
wchar[] text()
|
||||||
{
|
{
|
||||||
@@ -40,16 +47,55 @@ struct Slot
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
void currentLine(int line)
|
||||||
|
{
|
||||||
|
if (line == -1)
|
||||||
|
{
|
||||||
|
//range = DList!wstring.Range(program._last);
|
||||||
|
range = program[];
|
||||||
|
while (!range.empty)
|
||||||
|
{
|
||||||
|
auto old = range.save;
|
||||||
|
range.popFront();
|
||||||
|
if (range.empty)
|
||||||
|
{
|
||||||
|
range = old;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
range = program[];
|
||||||
|
range.popFrontN(line - 1);
|
||||||
|
}
|
||||||
|
wstring get()
|
||||||
|
{
|
||||||
|
if (range.empty)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
auto a = range.front;
|
||||||
|
range.popFront();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
Slot[] slot;
|
Slot[] slot;
|
||||||
int currentSlot;
|
int currentSlot;
|
||||||
int currentLine = 1;
|
|
||||||
int slotSize = 4;
|
int slotSize = 4;
|
||||||
this()
|
this()
|
||||||
{
|
{
|
||||||
slot = new Slot[5];
|
slot = new Slot[5];
|
||||||
}
|
}
|
||||||
|
void edit(int slot, int line)
|
||||||
|
{
|
||||||
|
this.currentSlot = slot;
|
||||||
|
this.slot[slot].currentLine = line;
|
||||||
|
}
|
||||||
|
wstring get()
|
||||||
|
{
|
||||||
|
return this.slot[currentSlot].get;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user