1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include "tile.h"
static void
win_place(Tile *col, Text *tag, Text *body) {
Tile *win;
int max, min;
findplace(col, &min, &max);
win = tile_new(V, min, max, tagheight, col, tag, body);
list_add(col, win);
assert(ISWIN(win));
}
/* Free the resources tied up by 'win'. Return 0 for success. */
int
win_del(Tile *w)
{
if(!w)
return 0;
assert(ISWIN(w));
if ( view_delete(w->body) || view_delete(w->tag) )
return -1;
else {
free(w->body);
free(w->tag);
tile_del(w);
free(w);
return 0;
}
}
/* Return the window associated with 'tile', or 0. */
Tile*
tile_win(Tile*tile) {
return (tile && tile->body) ? tile : 0;
}
/* clone 'win' */
void
win_clone(Tile *win) {
win_place(win->up, view_text(win->tag), view_text(win->body));
}
/* Create a window to represent 'path' */
void
win_new(char*path, Text*tag, Text*body) {
win_place(findcol(path), tag, body);
}
/* Add some text to w's tag representing the current selection */
void
win_anchor(Tile*w, char *arg)
{
char buf[80];
ulong p;
Text *t;
assert(ISWIN(w));
if(arg) {
/* line address */
Range sel;
int line;
View *v;
v = w->body;
sel = view_getsel(v);
t = view_text(v);
line = text_linenumber(t, sel.p0);
sprintf(buf, " :%d,.", line);
} else {
/* character address */
sprintf(buf, " :#%lu,.", view_getsel(w->body).p0);
}
/* append 'buf' to 't' */
t = view_text(w->tag);
p = text_length(t);
text_replaceutf(t, range(p,p), buf);
}
|