Commit 552de99a authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Initial work on open with tab with multple selected files. (#343930) Patch

2008-02-20  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-mime-application-chooser.[ch]:
        * libnautilus-private/nautilus-open-with-dialog.[ch]:
        * src/file-manager/fm-directory-view.c:
        * src/file-manager/fm-properties-window.c:
	Initial work on open with tab with multple selected
	files. (#343930)
	Patch from Cosimo Cecchi


svn path=/trunk/; revision=13782
parent e218446d
2008-02-20 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-mime-application-chooser.[ch]:
* libnautilus-private/nautilus-open-with-dialog.[ch]:
* src/file-manager/fm-directory-view.c:
* src/file-manager/fm-properties-window.c:
Initial work on open with tab with multple selected
files. (#343930)
Patch from Cosimo Cecchi
2008-02-20 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
......
......@@ -69,6 +69,8 @@ struct _NautilusMimeApplicationChooserDetails {
GtkWidget *entry;
GtkWidget *treeview;
GtkWidget *remove_button;
gboolean for_multiple_files;
GtkListStore *model;
GtkCellRenderer *toggle_renderer;
......@@ -307,8 +309,13 @@ add_clicked_cb (GtkButton *button,
chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (user_data);
dialog = nautilus_add_application_dialog_new (chooser->details->uri,
chooser->details->orig_mime_type);
if (chooser->details->for_multiple_files) {
dialog = nautilus_add_application_dialog_new_for_multiple_files (chooser->details->extension,
chooser->details->orig_mime_type);
} else {
dialog = nautilus_add_application_dialog_new (chooser->details->uri,
chooser->details->orig_mime_type);
}
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_widget_get_screen (GTK_WIDGET (chooser)));
gtk_widget_show (dialog);
......@@ -363,6 +370,7 @@ nautilus_mime_application_chooser_instance_init (NautilusMimeApplicationChooser
chooser->details = g_new0 (NautilusMimeApplicationChooserDetails, 1);
chooser->details->for_multiple_files = FALSE;
gtk_container_set_border_width (GTK_CONTAINER (chooser), 8);
gtk_box_set_spacing (GTK_BOX (chooser), 0);
gtk_box_set_homogeneous (GTK_BOX (chooser), FALSE);
......@@ -584,6 +592,31 @@ refresh_model (NautilusMimeApplicationChooser *chooser)
eel_g_object_list_free (applications);
}
static void
set_extension_and_description (NautilusMimeApplicationChooser *chooser,
const char *extension,
const char *mime_type)
{
chooser->details->extension = g_strdup (extension);
if (extension != NULL &&
g_content_type_is_unknown (mime_type)) {
chooser->details->content_type = g_strdup_printf ("application/x-extension-%s", extension);
/* the %s here is a file extension */
chooser->details->type_description =
g_strdup_printf (_("%s document"), extension);
} else {
char *description;
chooser->details->content_type = g_strdup (mime_type);
description = g_content_type_get_description (mime_type);
if (description == NULL) {
description = g_strdup (_("Unknown"));
}
chooser->details->type_description = description;
}
}
static gboolean
set_uri_and_type (NautilusMimeApplicationChooser *chooser,
const char *uri,
......@@ -600,29 +633,12 @@ set_uri_and_type (NautilusMimeApplicationChooser *chooser,
file = g_file_new_for_uri (uri);
name = g_file_get_basename (file);
g_object_unref (file);
chooser->details->orig_mime_type = g_strdup (mime_type);
extension = get_extension (name);
if (extension != NULL &&
g_content_type_is_unknown (mime_type)) {
chooser->details->extension = g_strdup (extension);
chooser->details->content_type = g_strdup_printf ("application/x-extension-%s", extension);
/* the %s here is a file extension */
chooser->details->type_description =
g_strdup_printf (_("%s document"), extension);
} else {
char *description;
chooser->details->content_type = g_strdup (mime_type);
description = g_content_type_get_description (mime_type);
if (description == NULL) {
description = g_strdup (_("Unknown"));
}
chooser->details->orig_mime_type = g_strdup (mime_type);
chooser->details->type_description = description;
}
extension = get_extension (name);
set_extension_and_description (NAUTILUS_MIME_APPLICATION_CHOOSER (chooser),
extension, mime_type);
g_free (extension);
/* first %s is filename, second %s is mime-type description */
......@@ -641,6 +657,49 @@ set_uri_and_type (NautilusMimeApplicationChooser *chooser,
return TRUE;
}
static gboolean
set_uri_and_type_for_multiple_files (NautilusMimeApplicationChooser *chooser,
GList *uris,
const char *mime_type)
{
char *label;
char *extension;
char *name;
GFile *file;
GList *iter;
chooser->details->for_multiple_files = TRUE;
chooser->details->uri = NULL;
chooser->details->orig_mime_type = g_strdup (mime_type);
extension = NULL;
iter = uris;
while (extension == NULL && iter != NULL) {
g_free (extension);
file = g_file_new_for_uri ((const char *) uris->data);
name = g_file_get_basename (file);
extension = get_extension (name);
iter = iter->next;
g_free (name);
g_object_unref (file);
}
set_extension_and_description (NAUTILUS_MIME_APPLICATION_CHOOSER (chooser),
extension, mime_type);
g_free (extension);
label = g_strdup_printf (_("Open all files of type \"%s\" with:"),
chooser->details->type_description);
gtk_label_set_markup (GTK_LABEL (chooser->details->label), label);
g_free (label);
refresh_model (chooser);
return TRUE;
}
GtkWidget *
nautilus_mime_application_chooser_new (const char *uri,
const char *mime_type)
......@@ -654,6 +713,20 @@ nautilus_mime_application_chooser_new (const char *uri,
return chooser;
}
GtkWidget *
nautilus_mime_application_chooser_new_for_multiple_files (GList *uris,
const char *mime_type)
{
GtkWidget *chooser;
chooser = gtk_widget_new (NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER, NULL);
set_uri_and_type_for_multiple_files (NAUTILUS_MIME_APPLICATION_CHOOSER (chooser),
uris, mime_type);
return chooser;
}
GType
nautilus_mime_application_chooser_get_type (void)
{
......
......@@ -49,5 +49,7 @@ struct _NautilusMimeApplicationChooserClass {
GType nautilus_mime_application_chooser_get_type (void);
GtkWidget* nautilus_mime_application_chooser_new (const char *uri,
const char *mime_type);
GtkWidget* nautilus_mime_application_chooser_new_for_multiple_files (GList *uris,
const char *mime_type);
#endif /* NAUTILUS_MIME_APPLICATION_CHOOSER_H */
......@@ -887,20 +887,31 @@ get_extension (const char *basename)
static void
set_uri_and_type (NautilusOpenWithDialog *dialog,
const char *uri,
const char *mime_type)
const char *mime_type,
const char *passed_extension)
{
char *label;
char *name;
char *emname;
GFile *file;
char *extension;
char *name, *extension;
const char *description;
file = g_file_new_for_uri (uri);
name = g_file_get_basename (file);
g_object_unref (file);
extension = get_extension (name);
name = NULL;
extension = NULL;
if (uri != NULL) {
GFile *file;
file = g_file_new_for_uri (uri);
name = g_file_get_basename (file);
g_object_unref (file);
}
if (passed_extension == NULL && name != NULL) {
extension = get_extension (name);
} else {
extension = g_strdup (passed_extension);
}
if (extension != NULL &&
g_content_type_is_unknown (mime_type)) {
dialog->details->extension = g_strdup (extension);
......@@ -919,9 +930,14 @@ set_uri_and_type (NautilusOpenWithDialog *dialog,
}
g_free (extension);
emname = g_strdup_printf ("<i>%s</i>", name);
label = g_strdup_printf (_("Open %s and other files of type \"%s\" with:"), emname, dialog->details->type_description);
g_free (emname);
if (name != NULL) {
emname = g_strdup_printf ("<i>%s</i>", name);
label = g_strdup_printf (_("Open %s and other files of type \"%s\" with:"), emname, dialog->details->type_description);
g_free (emname);
} else {
label = g_strdup_printf (_("Open all files of type \"%s\" with:"),
dialog->details->type_description);
}
gtk_label_set_markup (GTK_LABEL (dialog->details->label), label);
......@@ -931,13 +947,14 @@ set_uri_and_type (NautilusOpenWithDialog *dialog,
GtkWidget *
nautilus_open_with_dialog_new (const char *uri,
const char *mime_type)
const char *mime_type,
const char *extension)
{
GtkWidget *dialog;
dialog = gtk_widget_new (NAUTILUS_TYPE_OPEN_WITH_DIALOG, NULL);
set_uri_and_type (NAUTILUS_OPEN_WITH_DIALOG (dialog), uri, mime_type);
set_uri_and_type (NAUTILUS_OPEN_WITH_DIALOG (dialog), uri, mime_type, extension);
return dialog;
}
......@@ -948,7 +965,22 @@ nautilus_add_application_dialog_new (const char *uri,
{
NautilusOpenWithDialog *dialog;
dialog = NAUTILUS_OPEN_WITH_DIALOG (nautilus_open_with_dialog_new (uri, mime_type));
dialog = NAUTILUS_OPEN_WITH_DIALOG (nautilus_open_with_dialog_new (uri, mime_type, NULL));
gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog->details->open_label),
_("_Add"));
gtk_window_set_title (GTK_WINDOW (dialog), _("Add Application"));
return GTK_WIDGET (dialog);
}
GtkWidget*
nautilus_add_application_dialog_new_for_multiple_files (const char *extension,
const char *mime_type)
{
NautilusOpenWithDialog *dialog;
dialog = NAUTILUS_OPEN_WITH_DIALOG (nautilus_open_with_dialog_new (NULL, mime_type, extension));
gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog->details->open_label),
_("_Add"));
......
......@@ -52,9 +52,12 @@ struct _NautilusOpenWithDialogClass {
GType nautilus_open_with_dialog_get_type (void);
GtkWidget* nautilus_open_with_dialog_new (const char *uri,
const char *mime_type);
const char *mime_type,
const char *extension);
GtkWidget* nautilus_add_application_dialog_new (const char *uri,
const char *mime_type);
GtkWidget* nautilus_add_application_dialog_new_for_multiple_files (const char *extension,
const char *mime_type);
......
......@@ -849,7 +849,7 @@ choose_program (FMDirectoryView *view,
uri = nautilus_file_get_uri (file);
mime_type = nautilus_file_get_mime_type (file);
dialog = nautilus_open_with_dialog_new (uri, mime_type);
dialog = nautilus_open_with_dialog_new (uri, mime_type, NULL);
g_object_set_data_full (G_OBJECT (dialog),
"directory-view:file",
g_object_ref (file),
......
......@@ -286,7 +286,7 @@ is_multi_file_window (FMPropertiesWindow *window)
count = 0;
for (l = window->details->original_files; l != NULL; l = l->next) {
if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
count++;
if (count > 1) {
return TRUE;
......@@ -4703,23 +4703,44 @@ file_changed_callback (NautilusFile *file, gpointer user_data)
}
}
static gboolean
is_a_special_file (NautilusFile *file)
{
if (file == NULL ||
NAUTILUS_IS_DESKTOP_ICON_FILE (file) ||
nautilus_file_is_nautilus_link (file)) {
return TRUE;
}
return FALSE;
}
static gboolean
should_show_open_with (FMPropertiesWindow *window)
{
NautilusFile *file;
if (is_multi_file_window (window)) {
return FALSE;
}
/* Don't show open with tab for desktop special icons (trash, etc)
* or desktop files. We don't get the open-with menu for these anyway.
*/
file = get_original_file (window);
if (file == NULL ||
NAUTILUS_IS_DESKTOP_ICON_FILE (file) ||
nautilus_file_is_nautilus_link (file)) {
return FALSE;
if (!file_list_attributes_identical (window->details->original_files,
"mime_type")) {
return FALSE;
} else {
/* Don't show open with tab for desktop special icons (trash, etc)
* or desktop files. We don't get the open-with menu for these anyway.
*/
GList *l;
for (l = window->details->original_files; l; l = l->next) {
if (is_a_special_file (NAUTILUS_FILE (l->data))) {
return FALSE;
}
}
}
} else {
file = get_original_file (window);
if (is_a_special_file (file)) {
return FALSE;
}
}
return TRUE;
}
......@@ -4728,21 +4749,30 @@ static void
create_open_with_page (FMPropertiesWindow *window)
{
GtkWidget *vbox;
char *uri;
char *mime_type;
char *uri;
mime_type = nautilus_file_get_mime_type (get_target_file (window));
uri = nautilus_file_get_uri (get_target_file (window));
if (!is_multi_file_window (window)) {
uri = nautilus_file_get_uri (get_target_file (window));
if (uri == NULL) {
return;
}
vbox = nautilus_mime_application_chooser_new (uri, mime_type);
if (uri == NULL) {
return;
g_free (uri);
} else {
GList *uris;
uris = window->details->original_files;
if (uris == NULL) {
return;
}
vbox = nautilus_mime_application_chooser_new_for_multiple_files (uris, mime_type);
}
mime_type = nautilus_file_get_mime_type (get_target_file (window));
vbox = nautilus_mime_application_chooser_new (uri, mime_type);
gtk_widget_show (vbox);
g_free (uri);
g_free (mime_type);
gtk_notebook_append_page (window->details->notebook,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment