Changeset 09ceee3


Ignore:
Timestamp:
Sep 18, 2010, 5:07:40 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
2ec737f
Parents:
4811422
git-author:
David Benjamin <davidben@mit.edu> (08/15/10 19:15:19)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:40)
Message:
Add a command-line to the viewwin

It's triggered via popless:start-command.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rfc5eef4 r09ceee3  
    998998                  "exits the popless window",
    999999                  "", ""),
     1000
     1001  OWLCMD_ARGS_CTX("popless:start-command", owl_viewwin_start_command,
     1002                  OWL_CTX_POPLESS,
     1003                  "starts a command line in the popless",
     1004                  "popless:start-command [initial-value]",
     1005                  "Initializes the command field to initial-value"),
    10001006
    10011007  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
  • keys.c

    r818f19c r09ceee3  
    211211  BIND_CMD("C-c",         "popless:quit", "");
    212212  BIND_CMD("C-g",         "popless:quit", "");
     213
     214  BIND_CMD(":",           "popless:start-command",  "start a new command");
     215  BIND_CMD("M-x",         "popless:start-command",  "start a new command");
    213216
    214217  BIND_CMD("C-l",         "redisplay", "");
  • owl.h

    rfc5eef4 r09ceee3  
    414414  owl_window *status;
    415415  gulong sig_status_redraw_id;
     416  owl_window *cmdwin;
     417  owl_editwin *cmdline;
    416418} owl_viewwin;
    417419 
  • viewwin.c

    r6a35938 r09ceee3  
    6161  v->content = owl_window_new(v->window);
    6262  v->status = owl_window_new(v->window);
     63  v->cmdwin = NULL;
    6364
    6465  v->sig_content_redraw_id =
     
    8485  owl_window_get_position(v->window, &lines, &cols, NULL, NULL);
    8586  owl_window_set_position(v->content, lines - BOTTOM_OFFSET, cols, 0, 0);
     87  /* Only one of these will be visible at a time: */
    8688  owl_window_set_position(v->status, BOTTOM_OFFSET, cols, lines - BOTTOM_OFFSET, 0);
     89  if (v->cmdwin)
     90    owl_window_set_position(v->cmdwin, BOTTOM_OFFSET, cols, lines - BOTTOM_OFFSET, 0);
    8791}
    8892
     
    136140  }
    137141  wattroff(curswin, A_REVERSE);
     142}
     143
     144char *owl_viewwin_start_command(owl_viewwin *v, int argc, const char *const *argv, const char *buff)
     145{
     146  owl_editwin *tw;
     147  owl_context *ctx;
     148
     149  buff = skiptokens(buff, 1);
     150
     151  tw = owl_viewwin_set_typwin_active(v, owl_global_get_cmd_history(&g));
     152  owl_editwin_set_locktext(tw, ":");
     153
     154  owl_editwin_insert_string(tw, buff);
     155
     156  ctx = owl_editcontext_new(OWL_CTX_EDITLINE, tw, "editline");
     157  ctx->deactivate_cb = owl_viewwin_deactivate_editcontext;
     158  ctx->cbdata = v;
     159  owl_global_push_context_obj(&g, ctx);
     160  owl_editwin_set_callback(tw, owl_callback_command);
     161
     162  return NULL;
     163}
     164
     165void owl_viewwin_deactivate_editcontext(owl_context *ctx) {
     166  owl_viewwin *v = ctx->cbdata;
     167  owl_viewwin_set_typwin_inactive(v);
     168}
     169
     170owl_editwin *owl_viewwin_set_typwin_active(owl_viewwin *v, owl_history *hist) {
     171  int lines, cols;
     172  if (v->cmdwin || v->cmdline)
     173    return NULL;
     174  /* Create the command line. */
     175  v->cmdwin = owl_window_new(v->window);
     176  owl_viewwin_layout(v);
     177  owl_window_get_position(v->cmdwin, &lines, &cols, NULL, NULL);
     178  v->cmdline = owl_editwin_new(v->cmdwin, lines, cols, OWL_EDITWIN_STYLE_ONELINE, hist);
     179  /* Swap out the bottom window. */
     180  owl_window_hide(v->status);
     181  owl_window_show(v->cmdwin);
     182  return v->cmdline;
     183}
     184
     185void owl_viewwin_set_typwin_inactive(owl_viewwin *v) {
     186  if (v->cmdwin) {
     187    /* Swap out the bottom window. */
     188    owl_window_hide(v->cmdwin);
     189    owl_window_show(v->status);
     190    /* Destroy the window itself. */
     191    owl_window_unlink(v->cmdwin);
     192    g_object_unref(v->cmdwin);
     193    v->cmdwin = NULL;
     194  }
     195  if (v->cmdline) {
     196    owl_editwin_unref(v->cmdline);
     197    v->cmdline = NULL;
     198  }
    138199}
    139200
     
    282343    v->onclose_hook_data = NULL;
    283344  }
     345  owl_viewwin_set_typwin_inactive(v);
    284346  /* TODO: This is far too tedious. owl_viewwin should own v->window
    285347   * and just unlink it in one go. Signals should also go away for
Note: See TracChangeset for help on using the changeset viewer.