~ubuntu-branches/ubuntu/quantal/libfm/quantal

« back to all changes in this revision

Viewing changes to src/gtk/fm-file-menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-02-21 21:55:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110221215543-m7gn2snkhpk1kk9u
Tags: 0.1.15+git-3625952cea-0ubuntu1
* New upstream snapshot (2011-02-15)
 - Use x-schemas-handler (LP: #683922)
* debian/patches/
 - 90_add_gobject_link.patch: Remove, merged upstream.
 - 02-libfm-0.1.14-API-changes.patch: Refresh.
 - 03_disable_deprecated_gio_module.patch: Refresh.
 - 04_fix_docs_linker.patch: Fix DSO linking in docs/.
* debian/libfm0.install:
 - Remove usr/lib/libfm/gnome-terminal, dropped upstream.
 - Remove gio module, dropped upstream.
* debian/rules:
 - Add --enable-gtk-doc to configure.
* debian/libfm-gtk0.symbols:
 - Update with new symbols.
* debian/apport/source_libfm.py
 - Fix location of pcmanfm config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "fm-gtk-utils.h"
38
38
#include "fm-app-chooser-dlg.h"
39
39
#include "fm-archiver.h"
 
40
#include "fm-app-info.h"
 
41
#include "fm-gtk-file-launcher.h"
40
42
 
41
43
static void on_open(GtkAction* action, gpointer user_data);
42
44
static void on_open_with_app(GtkAction* action, gpointer user_data);
98
100
 
99
101
void fm_file_menu_destroy(FmFileMenu* menu)
100
102
{
 
103
    if(menu->parent)
 
104
        g_object_unref(menu->parent);
 
105
 
101
106
    if(menu->menu)
102
107
        gtk_widget_destroy(menu->menu);
103
108
 
112
117
    g_slice_free(FmFileMenu, menu);
113
118
}
114
119
 
115
 
FmFileMenu* fm_file_menu_new_for_file(FmFileInfo* fi, FmPath* cwd, gboolean auto_destroy)
 
120
FmFileMenu* fm_file_menu_new_for_file(GtkWindow* parent, FmFileInfo* fi, FmPath* cwd, gboolean auto_destroy)
116
121
{
117
122
    FmFileMenu* menu;
118
123
    FmFileInfoList* files = fm_file_info_list_new();
119
124
    fm_list_push_tail(files, fi);
120
 
    menu = fm_file_menu_new_for_files(files, cwd, auto_destroy);
 
125
    menu = fm_file_menu_new_for_files(parent, files, cwd, auto_destroy);
121
126
    fm_list_unref(files);
122
127
    return menu;
123
128
}
124
129
 
125
 
FmFileMenu* fm_file_menu_new_for_files(FmFileInfoList* files, FmPath* cwd, gboolean auto_destroy)
 
130
FmFileMenu* fm_file_menu_new_for_files(GtkWindow* parent, FmFileInfoList* files, FmPath* cwd, gboolean auto_destroy)
126
131
{
127
132
    GtkWidget* menu;
128
133
    GtkUIManager* ui;
133
138
    FmFileMenu* data = g_slice_new0(FmFileMenu);
134
139
    GString* xml;
135
140
 
 
141
    data->parent = g_object_ref(parent); /* FIXME: is this really needed? */
 
142
    /* FIXME: should we connect to "destroy" signal of parent and set data->parent to NULL when
 
143
     * it's detroyed? */
136
144
    data->file_infos = fm_list_ref(files);
137
145
 
138
146
    /* check if the files are of the same type */
302
310
    if( ! menu->menu )
303
311
    {
304
312
        menu->menu = gtk_ui_manager_get_widget(menu->ui, "/popup");
 
313
        gtk_menu_attach_to_widget(GTK_MENU(menu->menu), GTK_WIDGET(menu->parent), NULL);
 
314
 
305
315
        if(menu->auto_destroy)
 
316
        {
306
317
            g_signal_connect_swapped(menu->menu, "selection-done",
307
318
                            G_CALLBACK(fm_file_menu_destroy), menu);
 
319
        }
308
320
    }
309
321
    return menu->menu;
310
322
}
314
326
    FmFileMenu* data = (FmFileMenu*)user_data;
315
327
    GList* l = fm_list_peek_head_link(data->file_infos);
316
328
    GError* err = NULL;
317
 
    fm_launch_files_simple(GTK_WINDOW(gtk_widget_get_toplevel(data->menu)), NULL, l, data->folder_func, data->folder_func_data);
 
329
    fm_launch_files_simple(data->parent, NULL, l, data->folder_func, data->folder_func_data);
318
330
}
319
331
 
320
332
static void open_with_app(FmFileMenu* data, GAppInfo* app)
339
351
    gdk_app_launch_context_set_timestamp(ctx, gtk_get_current_event_time());
340
352
 
341
353
    /* FIXME: error handling. */
342
 
    g_app_info_launch_uris(app, uris, ctx, NULL);
 
354
    fm_app_info_launch_uris(app, uris, ctx, NULL);
343
355
    g_object_unref(ctx);
344
356
 
345
357
    g_list_foreach(uris, (GFunc)g_free, NULL);
367
379
    else
368
380
        mime_type = NULL;
369
381
 
370
 
    app = fm_choose_app_for_mime_type(NULL, mime_type, TRUE);
 
382
    app = fm_choose_app_for_mime_type(data->parent, mime_type, TRUE);
371
383
 
372
384
    if(app)
373
385
    {
374
386
        open_with_app(data, app);
 
387
        /* add the app to apps that support this file type. */
 
388
        if(mime_type)
 
389
            g_app_info_add_supports_type(app, mime_type->type, NULL);
 
390
        /* FIXME: what to do if mime_type is NULL? */
375
391
        g_object_unref(app);
376
392
    }
377
393
}
381
397
    FmFileMenu* data = (FmFileMenu*)user_data;
382
398
    FmPathList* files;
383
399
    files = fm_path_list_new_from_file_info_list(data->file_infos);
384
 
    fm_clipboard_cut_files(data->menu, files);
 
400
    fm_clipboard_cut_files(data->parent, files);
385
401
    fm_list_unref(files);
386
402
}
387
403
 
390
406
    FmFileMenu* data = (FmFileMenu*)user_data;
391
407
    FmPathList* files;
392
408
    files = fm_path_list_new_from_file_info_list(data->file_infos);
393
 
    fm_clipboard_copy_files(data->menu, files);
 
409
    fm_clipboard_copy_files(data->parent, files);
394
410
    fm_list_unref(files);
395
411
}
396
412
 
405
421
    FmFileMenu* data = (FmFileMenu*)user_data;
406
422
    FmPathList* files;
407
423
    files = fm_path_list_new_from_file_info_list(data->file_infos);
408
 
    fm_trash_or_delete_files(files);
 
424
    fm_trash_or_delete_files(data->parent, files);
409
425
    fm_list_unref(files);
410
426
}
411
427
 
414
430
    FmFileMenu* data = (FmFileMenu*)user_data;
415
431
    FmPathList* files;
416
432
    files = fm_path_list_new_from_file_info_list(data->file_infos);
417
 
    fm_untrash_files(files);
 
433
    fm_untrash_files(data->parent, files);
418
434
    fm_list_unref(files);
419
435
}
420
436
 
423
439
    FmFileMenu* data = (FmFileMenu*)user_data;
424
440
    FmFileInfo* fi = fm_list_peek_head(data->file_infos);
425
441
    if(fi)
426
 
        fm_rename_file(fi->path);
427
 
    /* FIXME: is it ok to only rename the first selected file here. */
428
 
/*
429
 
    FmPathList* files;
430
 
    files = fm_path_list_new_from_file_info_list(data->file_infos);
431
 
    if( !fm_list_is_empty(files) )
432
 
        fm_delete_files(files);
433
 
    fm_list_unref(files);
434
 
*/
 
442
        fm_rename_file(data->parent, fi->path);
 
443
    /* FIXME: is it ok to only rename the first selected file here? */
435
444
}
436
445
 
437
446
void on_compress(GtkAction* action, gpointer user_data)
482
491
void on_prop(GtkAction* action, gpointer user_data)
483
492
{
484
493
    FmFileMenu* data = (FmFileMenu*)user_data;
485
 
    fm_show_file_properties(data->file_infos);
 
494
    fm_show_file_properties(data->parent, data->file_infos);
486
495
}
487
496
 
488
497
gboolean fm_file_menu_is_single_file_type(FmFileMenu* menu)