Index: main.c =================================================================== --- main.c (révision 19615) +++ main.c (copie de travail) @@ -24,6 +24,7 @@ #endif #include +#include #ifdef HAVE_STDLIB_H #include #endif @@ -40,6 +41,9 @@ ThunarVfsPath *path; ThunarFile *file = NULL; GError *error = NULL; + int i, num_open_window = 0; + char cwd[PATH_MAX]; + char real_path[PATH_MAX]; /* setup translation domain */ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); @@ -73,29 +77,58 @@ /* use the Thunar icon as default for new windows */ gtk_window_set_default_icon_name ("Thunar"); - path = (argc > 1) ? thunar_vfs_path_new (argv[1], &error) : thunar_vfs_path_get_for_home (); - if (G_LIKELY (path != NULL)) + /* if no argument, open current directory */ + if(argc == 1) + { + /* get current directory */ + getcwd(cwd, sizeof(cwd)); + argc++; + argv[1] = cwd; + } + + /* open files or folders specified from command line */ + for (i = 1; i < argc; i++) { - file = thunar_file_get_for_path (path, &error); - thunar_vfs_path_unref (path); + /* get real path */ + if(realpath(argv[i], real_path) == NULL) + { + fprintf(stderr, "%s: Failed to open `%s': ", + argv[0], argv[i]); + perror(NULL); + continue; + } + + path = thunar_vfs_path_new (real_path, &error); + if (G_LIKELY (path != NULL)) + { + file = thunar_file_get_for_path(path, &error); + thunar_vfs_path_unref (path); + } + + if (path == NULL || file == NULL) + { + fprintf (stderr, "%s: Failed to open `%s': %s\n", + argv[0], argv[i], + error->message); + g_error_free (error); + continue; + } + else + { + /* open the new window */ + thunar_application_open_window (application, file, NULL); + num_open_window++; + } + + g_object_unref (G_OBJECT (file)); } - if (path == NULL || file == NULL) + /* run gtk_main if at least one window was opened */ + if(num_open_window > 0) { - fprintf (stderr, "%s: Failed to open `%s': %s\n", - argv[0], (argc > 1) ? argv[1] : xfce_get_homedir (), - error->message); - g_error_free (error); - return EXIT_FAILURE; + gtk_main (); } - /* open the first window */ - thunar_application_open_window (application, file, NULL); - - g_object_unref (G_OBJECT (file)); - - gtk_main (); - /* release the application reference */ g_object_unref (G_OBJECT (application));