commit 00742a530748777c1e68549af07a5ecda60bfe2b
parent 646f1a76ed70ab1399532653136f7e4bc7466ef7
Author: Claudio Alessi <smoppy@gmail.com>
Date: Wed, 13 Apr 2016 22:59:40 +0200
Remove cloneitem().
By thinking further, we may have a widget with a list to switch between views,
in this case it's needed to clone the selected item in order to mantain the
data, regardless of the state of the previous view. But for now we're stuck
with a views hierachy, so it's safe to only take a reference to the selected
item of the previous view, because it cannot be destroyed prematurely.
Diffstat:
M | myadm.c | | | 25 | +------------------------ |
1 file changed, 1 insertion(+), 24 deletions(-)
diff --git a/myadm.c b/myadm.c
@@ -86,7 +86,6 @@ void cleanup(void);
void cleanupfields(Field **fields);
void cleanupitems(Item **items);
void cleanupview(View *v);
-Item *cloneitem(Item *item);
void detach(View *v);
void detachfield(Field *f, Field **ff);
void detachitem(Item *i, Item **ii);
@@ -200,8 +199,6 @@ cleanupview(View *v) {
cleanupfields(&v->fields);
if(v->form)
stfl_free(v->form);
- if(v->choice)
- cleanupitems(&v->choice);
free(v);
}
@@ -231,26 +228,6 @@ cleanupitems(Item **items) {
}
}
-Item *
-cloneitem(Item *item) {
- Item *ic;
- int i;
-
- if(!item)
- return NULL;
-
- ic = ecalloc(1, sizeof(Item));
- ic->cols = ecalloc(item->ncols, sizeof(char *));
- ic->lens = ecalloc(item->ncols, sizeof(int));
- ic->ncols = item->ncols;
- for(i = 0; i < item->ncols; ++i) {
- ic->cols[i] = ecalloc(item->lens[i], sizeof(char));
- ic->lens[i] = item->lens[i];
- memcpy(ic->cols[i], item->cols[i], item->lens[i]);
- }
- return ic;
-}
-
void
detach(View *v) {
View **tv;
@@ -485,7 +462,7 @@ newaview(const char *name, void (*func)(void)) {
v = ecalloc(1, sizeof(View));
v->mode = ecalloc(1, sizeof(Mode));
v->mode->name = ecalloc(strlen(name)+1, sizeof(char));
- v->choice = cloneitem(getitem(0));
+ v->choice = getitem(0);
strcpy(v->mode->name, name);
v->mode->func = func;
attach(v);