示例#1
0
gboolean on_dir_tree_view_button_press( GtkWidget* view,
                                        GdkEventButton* evt,
                                        PtkFileBrowser* browser )
{
    if ( evt->type == GDK_BUTTON_PRESS && evt->button == 3 )
    {
        GtkTreeModel * model;
        GtkTreePath* tree_path;
        GtkTreeIter it;

        model = gtk_tree_view_get_model( GTK_TREE_VIEW( view ) );
        if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( view ),
                                            evt->x, evt->y, &tree_path, NULL, NULL, NULL ) )
        {
            if ( gtk_tree_model_get_iter( model, &it, tree_path ) )
            {
                VFSFileInfo * file;
                gtk_tree_model_get( model, &it,
                                    COL_DIR_TREE_INFO,
                                    &file, -1 );
                if ( file )
                {
                    GtkWidget * popup;
                    char* file_path;
                    GList* sel_files;
                    char* dir_name;
                    file_path = ptk_dir_view_get_dir_path( model, &it );

                    sel_files = g_list_prepend( NULL, vfs_file_info_ref(file) );
                    dir_name = g_path_get_dirname( file_path );
                    popup = ptk_file_menu_new(
                                file_path, file,
                                dir_name, sel_files, browser );
                    g_free( dir_name );
                    g_free( file_path );
                    gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                                    NULL, NULL, 3, evt->time );

                    vfs_file_info_unref( file );
                }
            }
            gtk_tree_path_free( tree_path );
        }
    }
    return FALSE;
}
示例#2
0
gboolean on_dir_tree_view_key_press( GtkWidget* view,
                                     GdkEventKey* evt,
                                     PtkFileBrowser* browser )
{
    VFSFileInfo* file;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GtkTreeSelection *select = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    
    if(!gtk_tree_selection_get_selected(select, &model, &iter))
        return FALSE;

    int keymod = ( evt->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK |
            GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ) );

    GtkTreePath *path = gtk_tree_model_get_path(model, &iter);

    switch( evt->keyval ) {
    case GDK_KEY_Left:
        if(gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_collapse_row(GTK_TREE_VIEW(view), path);
        } else if(gtk_tree_path_up(path)) {
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        } else {
            gtk_tree_path_free( path );
            return FALSE;
        }
        break;
    case GDK_KEY_Right:
        if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_expand_row(GTK_TREE_VIEW(view), path, FALSE);
        } else {
            gtk_tree_path_down(path);
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        }
        break;
    case GDK_KEY_F10:
    case GDK_KEY_Menu:
        if ( evt->keyval == GDK_KEY_F10 && keymod != GDK_SHIFT_MASK )
        {
            gtk_tree_path_free( path );
            return FALSE;
        }

        char* dir_path = ptk_dir_tree_view_get_selected_dir(
                                        GTK_TREE_VIEW( view ) );
        if ( ptk_file_browser_chdir( browser, dir_path,
                                    PTK_FB_CHDIR_ADD_HISTORY ) )
        {
            /* show right-click menu
             * This simulates a right-click in the file list when
             * no files are selected (even if some are) since
             * actions are to be taken on the dir itself. */
            GtkWidget* popup = ptk_file_menu_new( NULL, browser,
                                                  NULL, NULL,
                                                  dir_path, NULL );
            if ( popup )
                gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                            NULL, NULL, 3, 0 );
        }

        /* this old method operates on the wrong files
        gtk_tree_model_get( gtk_tree_view_get_model( GTK_TREE_VIEW( view ) ),
                            &iter,
                            COL_DIR_TREE_INFO,
                            &file, -1 );
        if ( file )
        {
            GtkWidget * popup;
            char* file_path;
            GList* sel_files;
            char* dir_name;
            file_path = ptk_dir_view_get_dir_path(
                    gtk_tree_view_get_model( GTK_TREE_VIEW( view ) ), &iter );

            sel_files = g_list_prepend( NULL, vfs_file_info_ref(file) );
            dir_name = g_path_get_dirname( file_path );
            popup = ptk_file_menu_new( NULL, browser,
                        file_path, file,
                        dir_name, sel_files );
            g_free( dir_name );
            g_free( file_path );
            if ( popup )
                gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                            NULL, NULL, 3, evt->time );

            vfs_file_info_unref( file );
        }
        */
        break;
    default:
        gtk_tree_path_free( path );
        return FALSE;
    }
    gtk_tree_path_free( path );
    return TRUE;
}
示例#3
0
gboolean on_dir_tree_view_key_press( GtkWidget* view,
                                     GdkEventKey* evt,
                                     PtkFileBrowser* browser )
{
    VFSFileInfo* file;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GtkTreeSelection *select = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    
    if(!gtk_tree_selection_get_selected(select, &model, &iter))
        return FALSE;

    int keymod = ( evt->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK |
            GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ) );

    GtkTreePath *path = gtk_tree_model_get_path(model, &iter);

    switch( evt->keyval ) {
    case GDK_KEY_Left:
        if(gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_collapse_row(GTK_TREE_VIEW(view), path);
        } else if(gtk_tree_path_up(path)) {
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        } else {
            gtk_tree_path_free( path );
            return FALSE;
        }
        break;
    case GDK_KEY_Right:
        if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_expand_row(GTK_TREE_VIEW(view), path, FALSE);
        } else {
            gtk_tree_path_down(path);
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        }
        break;
    case GDK_KEY_F10:
    case GDK_KEY_Menu:
        if ( evt->keyval == GDK_KEY_F10 && keymod != GDK_SHIFT_MASK )
        {
            gtk_tree_path_free( path );
            return FALSE;
        }
        gtk_tree_model_get( gtk_tree_view_get_model( GTK_TREE_VIEW( view ) ),
                            &iter,
                            COL_DIR_TREE_INFO,
                            &file, -1 );
        if ( file )
        {
            GtkWidget * popup;
            char* file_path;
            GList* sel_files;
            char* dir_name;
            file_path = ptk_dir_view_get_dir_path(
                    gtk_tree_view_get_model( GTK_TREE_VIEW( view ) ), &iter );

            sel_files = g_list_prepend( NULL, vfs_file_info_ref(file) );
            dir_name = g_path_get_dirname( file_path );
            popup = ptk_file_menu_new( NULL, browser,
                        file_path, file,
                        dir_name, sel_files );
            g_free( dir_name );
            g_free( file_path );
            if ( popup )
                gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                            NULL, NULL, 3, evt->time );

            vfs_file_info_unref( file );
        }
        break;
    default:
        gtk_tree_path_free( path );
        return FALSE;
    }
    gtk_tree_path_free( path );
    return TRUE;
}
示例#4
0
gboolean on_dir_tree_view_button_press( GtkWidget* view,
                                        GdkEventButton* evt,
                                        PtkFileBrowser* browser )
{
    GtkTreeModel* model;
    GtkTreePath* tree_path;
    GtkTreeViewColumn* tree_col;
    GtkTreeIter it;

    if ( evt->type == GDK_BUTTON_PRESS &&
                                    ( evt->button == 1 || evt->button == 3 ) )
    {
        // middle click 2 handled in ptk-file-browser.c on_dir_tree_button_press
        model = gtk_tree_view_get_model( GTK_TREE_VIEW( view ) );
        if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( view ),
                                            evt->x, evt->y, &tree_path,
                                            &tree_col, NULL, NULL ) )
        {
            if ( gtk_tree_model_get_iter( model, &it, tree_path ) )
            {

                gtk_tree_view_set_cursor( GTK_TREE_VIEW( view ),
                                                            tree_path,
                                                            tree_col, FALSE );

                if ( evt->button == 3 )
                {
                    // right click
                    char* dir_path = ptk_dir_tree_view_get_selected_dir(
                                                    GTK_TREE_VIEW( view ) );
                    if ( ptk_file_browser_chdir( browser, dir_path,
                                                PTK_FB_CHDIR_ADD_HISTORY ) )
                    {
                        /* show right-click menu
                         * This simulates a right-click in the file list when
                         * no files are selected (even if some are) since
                         * actions are to be taken on the dir itself. */
                        GtkWidget* popup = ptk_file_menu_new( NULL, browser,
                                                              NULL, NULL,
                                                              dir_path, NULL );
                        if ( popup )
                            gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                                        NULL, NULL, 3, 0 );
                        gtk_tree_path_free( tree_path );
                        return TRUE;
                    }
                }
                else
                    gtk_tree_view_row_activated( GTK_TREE_VIEW( view ),
                                                                tree_path,
                                                                tree_col );
            }
            gtk_tree_path_free( tree_path );
        }
    }
    else if ( evt->type == GDK_2BUTTON_PRESS && evt->button == 1 )
    {
        // double click - expand/collapse
        if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( view ),
                                            evt->x, evt->y, &tree_path,
                                            NULL, NULL, NULL ) )
        {
            if ( gtk_tree_view_row_expanded( GTK_TREE_VIEW( view ),
                                                                tree_path ) )
                gtk_tree_view_collapse_row( GTK_TREE_VIEW( view ), tree_path );
            else
                gtk_tree_view_expand_row( GTK_TREE_VIEW( view ), tree_path,
                                                                FALSE );
            gtk_tree_path_free( tree_path );
            return TRUE;
        }
    }
    return FALSE;
}
示例#5
0
gboolean on_dir_tree_view_button_press( GtkWidget* view,
                                        GdkEventButton* evt,
                                        PtkFileBrowser* browser )
{
    GtkTreeModel* model;
    GtkTreePath* tree_path;
    GtkTreeViewColumn* tree_col;
    GtkTreeIter it;

    if ( evt->type == GDK_BUTTON_PRESS &&
                                    ( evt->button == 1 || evt->button == 3 ) )
    {
        // middle click 2 handled in ptk-file-browser.c on_dir_tree_button_press
        model = gtk_tree_view_get_model( GTK_TREE_VIEW( view ) );
        if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( view ),
                                            evt->x, evt->y, &tree_path,
                                            &tree_col, NULL, NULL ) )
        {
            if ( gtk_tree_model_get_iter( model, &it, tree_path ) )
            {
                gtk_tree_view_set_cursor( GTK_TREE_VIEW( view ),
                                                            tree_path,
                                                            tree_col, FALSE );
                gtk_tree_view_row_activated( GTK_TREE_VIEW( view ),
                                                            tree_path,
                                                            tree_col );
                if ( evt->button == 3 )
                {
                    // right click
                    VFSFileInfo * file;
                    gtk_tree_model_get( model, &it,
                                        COL_DIR_TREE_INFO,
                                        &file, -1 );
                    if ( file )
                    {
                        GtkWidget * popup;
                        char* file_path;
                        GList* sel_files;
                        char* dir_name;
                        file_path = ptk_dir_view_get_dir_path( model, &it );

                        sel_files = g_list_prepend( NULL, vfs_file_info_ref(file) );
                        dir_name = g_path_get_dirname( file_path );
                        /* FIXME: New|Tab Here and New|File etc work on the
                         * wrong location because dir_name is really incorrect.
                         * But if set to cur dir it breaks Copy, etc. */
                        popup = ptk_file_menu_new( NULL, browser,
                                    file_path, file,
                                    dir_name, sel_files );
                        g_free( dir_name );
                        g_free( file_path );
                        if ( popup )
                            gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
                                        NULL, NULL, 3, evt->time );

                        vfs_file_info_unref( file );
                        gtk_tree_path_free( tree_path );
                        return TRUE;
                    }
                }
            }
            gtk_tree_path_free( tree_path );
        }
    }
    else if ( evt->type == GDK_2BUTTON_PRESS && evt->button == 1 )
    {
        // double click - expand/collapse
        if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( view ),
                                            evt->x, evt->y, &tree_path,
                                            NULL, NULL, NULL ) )
        {
            if ( gtk_tree_view_row_expanded( GTK_TREE_VIEW( view ),
                                                                tree_path ) )
                gtk_tree_view_collapse_row( GTK_TREE_VIEW( view ), tree_path );
            else
                gtk_tree_view_expand_row( GTK_TREE_VIEW( view ), tree_path,
                                                                FALSE );
            gtk_tree_path_free( tree_path );
            return TRUE;
        }
    }
    return FALSE;
}