From 18796d59371ed5d0ab8ede5526ce2ec9cc88a30d Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Mon, 29 Sep 2008 15:40:20 -0400 Subject: [PATCH] Add 'remove' subcommand for 'layout' The new subcommand removes the specified layout (or the current layout if none is specified). Closes feature request #22736. --- src/display.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- src/process.c | 15 +++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/display.c b/src/display.c index 47563cc..a65b030 100644 --- a/src/display.c +++ b/src/display.c @@ -4637,7 +4637,7 @@ ShowLayouts(where) int where; { char buf[1024]; - char *s, *ss; + char *s, *ss; if (!display) return; @@ -4650,17 +4650,49 @@ int where; where = D_layout->lay_number; ss = AddLayoutsInfo(buf, sizeof(buf), where); s = buf + strlen(buf); - if (ss - buf > D_width / 2) - { - ss -= D_width / 2; + if (ss - buf > D_width / 2) + { + ss -= D_width / 2; if (s - ss < D_width) { ss = s - D_width; - if (ss < buf) - ss = buf; + if (ss < buf) + ss = buf; } - } - else - ss = buf; - Msg(0, "%s", ss); + } + else + ss = buf; + Msg(0, "%s", ss); +} + +void +RemoveLayout(lay) +struct layout *lay; +{ + struct layout **layp = &layouts; + + for (; *layp; layp = &(*layp)->lay_next) + { + if (*layp == lay) + { + *layp = lay->lay_next; + break; + } + } + laytab[lay->lay_number] = (struct layout *)0; + + if (display && D_layout == lay) + D_layout = (struct layout *)0; + + FreeLayoutCv(&lay->lay_canvas); + + if (lay->lay_title) + free(lay->lay_title); + free(lay); + + if (layouts) + LoadLayout((display && D_layout) ? D_layout : *layp ? *layp : layouts, + display ? &D_canvas : (struct canvas *)0); + Activate(0); } + diff --git a/src/process.c b/src/process.c index 001007d..f1a9353 100644 --- a/src/process.c +++ b/src/process.c @@ -4209,6 +4209,21 @@ int key; { ShowLayouts(-1); } + else if (!strcmp(args[0], "remove")) + { + struct layout *lay = display ? D_layout : layouts; + if (args[1]) + { + lay = layouts ? FindLayout(args[1]) : (struct layout *)0; + if (!lay) + { + Msg(0, "unknown layout '%s'", args[1]); + break; + } + } + if (lay) + RemoveLayout(lay); + } else Msg(0, "unknown layout subcommand"); break; -- 2.11.4.GIT