Implement a fill-with menu item

This new option fills the entire marked region with copies of the current cell.
  Implements #35.
This commit is contained in:
Glen Whitney 2019-07-27 04:08:42 -04:00
parent 8b95dec96d
commit 39c12c08e0
6 changed files with 31 additions and 6 deletions

View File

@ -150,6 +150,7 @@ void freecellcontents(Cell *faded)
void copycell(Cell *to, const Cell *fromcell)
{
assert(to != NULLCELL);
if (to == fromcell) return;
freecellcontents(to);
if (fromcell != NULLCELL) {

View File

@ -1201,6 +1201,19 @@ static int do_fill(Sheet *sheet)
}
/*}}}*/
/* fill the entire marked region using the current cell */
void fillwith(Sheet *she)
{
do_mark(she, GET_MARK_ALL);
Cell *src = curcell(she);
Location dest;
bool scan_labels = (src != NULLCELL && getlabel(src) != (const char*)0);
/* the following is safe since we have handled copying a cell to itself */
for (ALL_LOCS_IN_REGION(she, dest)) copycelltosheet(src, she, dest);
if (scan_labels) cachelabels(she);
forceupdate(she);
}
/* do_sort -- sort block */ /*{{{*/
static int do_sort(Sheet *sheet)
{
@ -1515,6 +1528,7 @@ int do_sheetcmd(Sheet *cursheet, Key c, int moveonly)
case BLOCK_MOVE: do_move(cursheet,0,0); redraw_sheet(cursheet); break;
case BLOCK_COPY: do_move(cursheet,1,0); redraw_sheet(cursheet); break;
case BLOCK_FILL: do_fill(cursheet); redraw_sheet(cursheet); break;
case FILL_BLOCK: fillwith(cursheet); redraw_sheet(cursheet); break;
case BLOCK_SORT: do_sort(cursheet); redraw_sheet(cursheet); break;
case BLOCK_MIRROR: do_mirror(cursheet); redraw_sheet(cursheet); break;
case ADJUST_LEFT:

View File

@ -80,7 +80,8 @@ typedef enum {
K_ABOUT = -54,
K_HELP = -55,
K_DUMPCELL = -56,
ADJUST_UNDERLINE = -57
ADJUST_UNDERLINE = -57,
FILL_BLOCK = -58
} Key;
extern int do_sheetcmd(Sheet *cursheet, Key c, int moveonly);
@ -89,6 +90,7 @@ extern void moveto(Sheet *sheet, int x, int y, int z);
extern void movetoloc(Sheet *sheet, const Location dest);
extern void relmoveto(Sheet *sheet, int x, int y, int z);
extern void do_mark(Sheet *cursheet, MarkState ms);
void fillwith(Sheet *she);
#ifdef __cplusplus
}

View File

@ -46,18 +46,20 @@ int max_eval;
/*}}}*/
/* copycelltosheet -- copy a cell into a sheet*/ /*{{{*/
static void copycelltosheet(const Cell *fromcell,
Sheet *sheet2, const Location to)
void copycelltosheet(const Cell *fromcell, Sheet *sheet2, const Location to)
{
assert(sheet2 != (Sheet*)0);
Cell *tocell = safe_cell_at(sheet2, to);
if (fromcell == tocell) return;
freecellofsheet(sheet2, to);
if (fromcell != NULLCELL)
/* copy first cell to second */ /*{{{*/
{
sheet2->changed = 1;
Cell *tocell = initcellofsheet(sheet2, to);
copycell(tocell, fromcell);
Cell *alsotocell = initcellofsheet(sheet2, to);
assert(tocell == NULLCELL || tocell == alsotocell);
copycell(alsotocell, fromcell);
}
/*}}}*/
}

View File

@ -73,6 +73,7 @@ extern int max_eval;
void initialize_sheet(Sheet *sheet);
void resize(Sheet *sheet, int x, int y, int z);
Cell *initcellofsheet(Sheet *sheet, const Location at);
void copycelltosheet(const Cell *fromcell, Sheet *sheet2, const Location to);
Cell *safe_cell_at(Sheet *sheet, const Location at);
Cell *curcell(Sheet *sheet);
void cachelabels(Sheet *sheet);

View File

@ -428,6 +428,11 @@ table->redraw();} open
user_data BLOCK_FILL
xywh {0 0 36 21} shortcut 0x90066
}
MenuItem {} {
label {FillWith}
user_data FILL_BLOCK
xywh {0 0 36 30}
}
MenuItem {} {
label {C&lear}
user_data BLOCK_CLEAR