- reaktor_tree: nodes in depth-first order, drawn as a list (only visible rows), with chevrons and icons; Right and Left open, close and step in and out. - Fields: a growing heap buffer (.heap, .heap_cap), line numbers, and reaktor_field_select to focus a field and select text. Notepad opens files of any size and gets a find bar (Ctrl+F, F3). - reaktor_spinner steps through any list of values in the property chrome. - reaktor_date_pick and reaktor_time_pick: segmented fields in the language's date order, opening wheels in a flyout. Locale gains LLLL (date.months.standalone) and reaktor_format_pattern. - Lists with .drag and .dropped reorder rows and move them between lists. - An undo stack per window: steps, merge keys, groups, labels, a saved mark; Ctrl+Z and Ctrl+Y when no field is being edited. launchtest gains tree-keys, field-find, spin-keys, date-keys and undo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
2.6 KiB
C
124 lines
2.6 KiB
C
#include "internal.h"
|
|
|
|
static void
|
|
undo_free(undo_stack *u, int from)
|
|
{
|
|
while (u->n > from) {
|
|
reaktor_undo_step *s = &u->step[--u->n];
|
|
|
|
if (s->free) s->free(s->data);
|
|
}
|
|
if (u->top > u->n) u->top = u->n;
|
|
if (u->saved > u->n) u->saved = -1;
|
|
}
|
|
|
|
void
|
|
reaktor_undo_push(App *app, const reaktor_undo_step *s)
|
|
{
|
|
undo_stack *u = &app->undo;
|
|
unsigned group;
|
|
|
|
if (!s || !s->undo || !s->redo) return;
|
|
undo_free(u, u->top);
|
|
if (u->n == u->cap) {
|
|
int cap = u->cap ? u->cap * 2 : 32;
|
|
reaktor_undo_step *step = (reaktor_undo_step *)SDL_realloc(u->step, (size_t)cap * sizeof *step);
|
|
unsigned *grp = (unsigned *)SDL_realloc(u->group, (size_t)cap * sizeof *grp);
|
|
|
|
if (step) u->step = step;
|
|
if (grp) u->group = grp;
|
|
if (!step || !grp) {
|
|
if (s->free) s->free(s->data);
|
|
return;
|
|
}
|
|
u->cap = cap;
|
|
}
|
|
if (u->depth)
|
|
group = u->open;
|
|
else if (s->merge && u->n && u->step[u->n - 1].merge == s->merge && u->saved != u->n)
|
|
group = u->group[u->n - 1];
|
|
else
|
|
group = ++u->next;
|
|
u->step[u->n] = *s;
|
|
u->group[u->n] = group;
|
|
u->top = ++u->n;
|
|
}
|
|
|
|
void
|
|
reaktor_undo_group(App *app, int begin)
|
|
{
|
|
undo_stack *u = &app->undo;
|
|
|
|
if (begin && u->depth++ == 0) u->open = ++u->next;
|
|
if (!begin && u->depth > 0) u->depth--;
|
|
}
|
|
|
|
int
|
|
reaktor_undo(App *app)
|
|
{
|
|
undo_stack *u = &app->undo;
|
|
unsigned group;
|
|
|
|
if (u->top == 0) return 0;
|
|
group = u->group[u->top - 1];
|
|
while (u->top > 0 && u->group[u->top - 1] == group) {
|
|
reaktor_undo_step *s = &u->step[--u->top];
|
|
|
|
s->undo(s->data);
|
|
}
|
|
app->dirty = 1;
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
reaktor_redo(App *app)
|
|
{
|
|
undo_stack *u = &app->undo;
|
|
unsigned group;
|
|
|
|
if (u->top == u->n) return 0;
|
|
group = u->group[u->top];
|
|
while (u->top < u->n && u->group[u->top] == group) {
|
|
reaktor_undo_step *s = &u->step[u->top++];
|
|
|
|
s->redo(s->data);
|
|
}
|
|
app->dirty = 1;
|
|
return 1;
|
|
}
|
|
|
|
const char *
|
|
reaktor_undo_label(App *app)
|
|
{
|
|
return app->undo.top > 0 ? app->undo.step[app->undo.top - 1].label : NULL;
|
|
}
|
|
|
|
const char *
|
|
reaktor_redo_label(App *app)
|
|
{
|
|
return app->undo.top < app->undo.n ? app->undo.step[app->undo.top].label : NULL;
|
|
}
|
|
|
|
void
|
|
reaktor_undo_saved(App *app)
|
|
{
|
|
app->undo.saved = app->undo.top;
|
|
}
|
|
|
|
int
|
|
reaktor_undo_dirty(App *app)
|
|
{
|
|
return app->undo.top != app->undo.saved;
|
|
}
|
|
|
|
void
|
|
reaktor_undo_clear(App *app)
|
|
{
|
|
undo_stack *u = &app->undo;
|
|
|
|
undo_free(u, 0);
|
|
SDL_free(u->step);
|
|
SDL_free(u->group);
|
|
SDL_zerop(u);
|
|
}
|