#include "core.h"
+static int do_doc_destroy(struct doc *d);
+
static int do_doc_add_view(struct doc *d, struct command *c, int size)
{
struct docview *g;
return comm_call7(ci->comm2, "callback:vmark", ci->focus,
0, m, NULL, 0, NULL, m2);
}
+ if (strcmp(ci->key, "doc:destroy") == 0)
+ return do_doc_destroy(dd->doc);
ret = key_lookup(dd->doc->map, ci);
ret = ret ?: key_lookup(doc_default_cmd, ci);
doc_set_name(d, name);
p = doc_attach_view(parent, d->home, NULL);
if (!p) {
- doc_destroy(d);
+ do_doc_destroy(d);
return p;
}
doc_replace(p, NULL, text, &first);
DEF_CMD(docs_bury)
{
- struct doc *d = doc_from_pane(ci->home);
-
- doc_destroy(d);
+ doc_destroy(ci->home);
return 1;
}
docs_attach(d);
}
-int doc_destroy(struct doc *d)
+static int do_doc_destroy(struct doc *d)
{
/* If there are no views on the document, then unlink from
* the documents list and destroy it.
*/
int i;
+ struct cmd_info ci = {0};
d->deleting = 1;
if (d == d->ed->docs)
for (i = 0; i < d->nviews; i++)
if (d->views[i].notify)
/* still in use */
- return 0;
+ return -1;
if (d == d->ed->docs)
- return 0;
+ return -1;
docs_release(d);
- call3("doc:destroy", d->home, 0, 0);
+ ci.home = ci.focus = d->home;
+ ci.key = "doc:destroy";
+ key_lookup(d->map, &ci);
+
pane_close(d->home);
free(d->views);
free(d);
return 1;
}
+
+int doc_destroy(struct pane *p)
+{
+ return call3("doc:destroy", p, 0, 0);
+}
void doc_set_name(struct doc *d, char *name);
struct pane *doc_find(struct editor *ed, char *name);
void doc_promote(struct doc *d);
-int doc_destroy(struct doc *d);
+int doc_destroy(struct pane *p);
struct pane *render_attach(char *name, struct pane *parent);
struct popup_info *ppi = p->data;
if (strcmp(ci->key, "Close") == 0) {
- if (ppi->doc)
- doc_destroy(ppi->doc);
free(ppi);
return 1;
}
if (strcmp(ci->key, "popup:Abort") == 0) {
pane_focus(ppi->target);
call3("Abort", ppi->target, 0, NULL);
+ if (ppi->doc) {
+ /* FIXME make this doc auto-close */
+ ppi->doc = NULL;
+ doc_destroy(ci->focus);
+ }
pane_close(ppi->popup);
return 1;
}
key_handle_focus(&ci2);
if (ppi->doc)
free(ci2.str);
+ if (ppi->doc) {
+ /* FIXME make this doc auto-close */
+ ppi->doc = NULL;
+ doc_destroy(ci->focus);
+ }
pane_close(ppi->popup);
return 1;
}