コード例 #1
0
static gboolean entry_keypress_cb(GtkWidget *entry, GdkEventKey *event, gpointer user_data)
{
    static gboolean terminal = FALSE; /* Run in a terminal?      */
    gchar *cmd               = NULL;  /* command line to execute */
    XFCommand *hitem         = NULL;  /* history item data       */
    
    switch (event->keyval) {
        case GDK_Down:
            scroll_history(TRUE,1);
            if (Curr) {
                hitem = (XFCommand *) Curr->data;
                terminal = hitem->in_terminal;
                gtk_entry_set_text(GTK_ENTRY(entry), hitem->command);
            }
            return TRUE;
        case GDK_Up:
            scroll_history(FALSE,1);
            if (Curr) {
                hitem = (XFCommand *) Curr->data;
                terminal = hitem->in_terminal;
                gtk_entry_set_text(GTK_ENTRY(entry), hitem->command);
            }
            return TRUE;
        case GDK_Return:
            cmd = gtk_entry_get_text(GTK_ENTRY(entry));
            
            if ((event->state) & GDK_CONTROL_MASK) {
                terminal = TRUE;
            }

            if (do_run(cmd, terminal)) {
                put_history(cmd, terminal, History);      /* save this cmdline to history       */
                History  = get_history();                 /* reload modified history            */
                Curr     = NULL;                          /* reset current history item pointer */
                terminal = FALSE;                         /* Reset run in term flag             */
                gtk_entry_set_text(GTK_ENTRY(entry), ""); /* clear the entry                    */
            }
            return TRUE;
        default:
            /* hand over to default signal handler */
            return FALSE;
    }                           
}
コード例 #2
0
ファイル: glui_commandline.cpp プロジェクト: 4ian/GD
int    GLUI_CommandLine::special_handler( int key,int modifiers )
{
  if ( NOT glui )
    return false;
  
  if ( debug )
    printf( "CMD_TEXT SPECIAL:%d - mod:%d   subs:%d/%d  ins:%d  sel:%d/%d\n", 
	    key, modifiers, substring_start, substring_end,insertion_pt,
	    sel_start, sel_end );	 

  if ( key == GLUT_KEY_UP )  // PREVIOUS HISTORY
  {
    scroll_history(-1);
  }
  else if ( key == GLUT_KEY_DOWN )  // NEXT HISTORY
  {
    scroll_history(+1);
  }
  else {
    return Super::special_handler( key, modifiers );
  }
  return false;
}