예제 #1
0
int
clip_GTK_ENTRYCOMPLETIONINSERTPREFIX(ClipMachine * ClipMachineMemory)
{
   C_object *ccompletion = _fetch_co_arg(ClipMachineMemory);

   CHECKCOBJ(ccompletion, GTK_IS_ENTRY_COMPLETION(ccompletion->object));

   gtk_entry_completion_insert_prefix(GTK_ENTRY_COMPLETION(ccompletion->object));

   return 0;
 err:
   return 1;
}
예제 #2
0
static gboolean fm_path_entry_key_press(GtkWidget   *widget, GdkEventKey *event, gpointer user_data)
{
    FmPathEntry *entry = FM_PATH_ENTRY(widget);
    FmPathEntryPrivate *priv  = FM_PATH_ENTRY_GET_PRIVATE(entry);
    char* text;
    int pos;
    switch( event->keyval )
    {
    case GDK_Tab:
        {
            gtk_entry_completion_insert_prefix(priv->completion);
            gtk_editable_set_position(GTK_EDITABLE(entry), -1);
            return TRUE;
        }
    }
    return FALSE;
}
예제 #3
0
static VALUE
rg_insert_prefix(VALUE self)
{
    gtk_entry_completion_insert_prefix(_SELF(self));
    return self;
}
예제 #4
0
static gboolean
on_key_press( GtkWidget *entry, GdkEventKey* evt, EntryData* edata )
{    
    int keymod = ( evt->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK |
                 GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ) );
                 
    if( evt->keyval == GDK_KEY_Tab && !keymod )
    {
        gtk_entry_completion_insert_prefix( gtk_entry_get_completion(GTK_ENTRY(entry)) );
        gtk_editable_set_position( (GtkEditable*)entry, -1 );
        return TRUE;
    }
    else if ( ( evt->keyval == GDK_KEY_Up || evt->keyval == GDK_KEY_Down ) && !keymod )
    {
        const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
        if ( text[0] != '$' && text[0] != '+' && text[0] != '&' && text[0] != '!' 
                                                            && text[0] != '\0' )
            return FALSE;  // pass non-command arrows to completion
        
        char* line = NULL;
        GList* l;
        if ( evt->keyval == GDK_KEY_Up )
        {
            if ( edata->current )
            {
                if ( text[0] != '\0' && strcmp( edata->current->data, text ) )
                {
                    if ( edata->editing )
                        g_free( edata->editing );
                    edata->editing = g_strdup( text );
                    l = g_list_last( edata->history );
                    line = (char*)l->data;
                    edata->current = l;
                }
                else if ( edata->current->prev )
                {
                    line = (char*)edata->current->prev->data;
                    edata->current = edata->current->prev;
                }
            }
            else if ( edata->history )
            {
                if ( edata->editing && ( text[0] == '\0' || !strcmp( text, "$ " ) ) )
                    line = edata->editing;
                else
                {
                    l = g_list_last( edata->history );
                    line = (char*)l->data;
                    edata->current = l;
                    
                    if ( text[0] != '\0' && strcmp( text, "$ " ) )
                    {
                        if ( edata->editing )
                            g_free( edata->editing );
                        edata->editing = g_strdup( text );
                    }
                }
            }
        }
        else  // GDK_Down
        {
            if ( edata->current && edata->current->next )
            {
                if ( strcmp( edata->current->data, text ) )
                {
                    if ( text[0] != '\0' )
                    {
                        if ( edata->editing )
                            g_free( edata->editing );
                        edata->editing = strdup( text );
                    }
                    line = "$ ";
                    edata->current = NULL;
                }
                else
                {
                    line = (char*)edata->current->next->data;
                    edata->current = edata->current->next;
                }
            }
            else if ( !strcmp( text, "$ " ) || text[0] == '\0' )
            {
                if ( edata->editing && strcmp( text, edata->editing ) )
                    line = edata->editing;
                else
                    line = "$ ";
                edata->current = NULL;
            }
            else
            {
                if ( edata->current && !strcmp( text, edata->current->data ) )
                    line = edata->editing ? edata->editing : "$ ";
                else
                {
                    if ( edata->editing )
                        g_free( edata->editing );
                    edata->editing = strdup( text );
                    line = "$ ";
                }
                edata->current = NULL;
            }
        }
        if ( line )
        {
            gtk_entry_set_text( GTK_ENTRY( entry ), line );
            gtk_editable_set_position( (GtkEditable*)entry, -1 );
        }
        return TRUE;
    }
    else if ( evt->keyval == GDK_KEY_Escape && !keymod )
    {
        const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
        if ( text[0] == '$' || text[0] == '+' || text[0] == '&'
                    || text[0] == '!' || text[0] == '\0' || text[0] == ' ' )
        {
            const char* line;
            const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
            const char* cwd = ptk_file_browser_get_cwd( edata->browser );
            if ( !strcmp( text, "$ " ) || text[0] == '\0' )
                line = cwd;
            /*
            else if ( !strcmp( text, cwd ) )
            {
                if ( edata->editing && strcmp( text, edata->editing ) )
                    line = edata->editing;
                else
                    line = "$ ";
            }
            */
            else
            {
                if ( edata->editing )
                    g_free( edata->editing );
                edata->editing = strdup( text );
                line = "$ ";
            }
            gtk_entry_set_text( GTK_ENTRY( entry ), line );
            gtk_editable_set_position( (GtkEditable*)entry, -1 );
            edata->current = NULL;
            return TRUE;   
        }
    }
    else if ( evt->keyval == GDK_KEY_BackSpace && keymod == 1 ) // shift
    {
        gtk_entry_set_text( GTK_ENTRY( entry ), "" );
        return TRUE;
    }
    return FALSE;
}