static void thunar_location_entry_activate (GtkWidget *path_entry, ThunarLocationEntry *location_entry) { ThunarFile *file; GError *error = NULL; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (location_entry->path_entry == path_entry); /* determine the current file from the path entry */ file = thunar_path_entry_get_current_file (THUNAR_PATH_ENTRY (path_entry)); if (G_LIKELY (file != NULL)) { /* check if we have a new directory or a file to launch */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } else { /* try to launch the selected file */ if (!thunar_file_launch (file, path_entry, &error)) { thunar_dialogs_show_error (path_entry, error, _("Failed to launch \"%s\""), thunar_file_get_display_name (file)); g_error_free (error); } /* be sure to reset the current file of the path entry */ if (G_LIKELY (location_entry->current_directory != NULL)) thunar_path_entry_set_current_file (THUNAR_PATH_ENTRY (path_entry), location_entry->current_directory); } } }
/** * thunar_location_bar_request_entry * @bar : The #ThunarLocationBar * @initial_text : The initial text to be placed inside the entry, or NULL to * use the path of the current directory. * * Makes the location bar display an entry with the given text and places the cursor * accordingly. If the currently displayed location widget is a path bar, it will be * temporarily swapped for an entry widget and swapped back once the user completed * (or aborted) the input. */ void thunar_location_bar_request_entry (ThunarLocationBar *bar, const gchar *initial_text) { GtkWidget *child; child = gtk_bin_get_child (GTK_BIN (bar)); _thunar_return_if_fail (child != NULL && GTK_IS_WIDGET (child)); if (THUNAR_IS_LOCATION_ENTRY (child)) { /* already have an entry */ thunar_location_entry_accept_focus (THUNAR_LOCATION_ENTRY (child), initial_text); } else { /* not an entry => temporarily replace it */ child = thunar_location_bar_install_widget (bar, THUNAR_TYPE_LOCATION_ENTRY); thunar_location_entry_accept_focus (THUNAR_LOCATION_ENTRY (child), initial_text); } g_signal_connect (child, "edit-done", G_CALLBACK (thunar_location_bar_on_enry_edit_done), bar); }
static void thunar_location_entry_item_activated (GtkWidget *item, ThunarLocationEntry *location_entry) { ThunarVfsVolume *volume; ThunarFile *file; GtkWidget *window; GError *error = NULL; _thunar_return_if_fail (GTK_IS_MENU_ITEM (item)); _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); /* determine the toplevel window */ window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry)); /* check if the item corresponds to a volume */ volume = g_object_get_data (G_OBJECT (item), "thunar-vfs-volume"); if (G_UNLIKELY (volume != NULL)) { /* check if the volume isn't already mounted */ if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume))) { /* try to mount the volume */ if (!thunar_vfs_volume_mount (volume, window, &error)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } /* try to determine the mount point of the volume */ file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (volume), &error); if (G_UNLIKELY (file == NULL)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to determine the mount point for %s"), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } else { /* determine the file from the item */ file = g_object_get_data (G_OBJECT (item), "thunar-file"); if (G_LIKELY (file != NULL)) g_object_ref (G_OBJECT (file)); } /* check if we have a file object now */ if (G_LIKELY (file != NULL)) { /* make sure that this is actually a directory */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } /* cleanup */ g_object_unref (G_OBJECT (file)); } }
static void thunar_location_entry_button_clicked (GtkWidget *button, ThunarLocationEntry *location_entry) { ThunarShortcutsModel *model; ThunarIconFactory *icon_factory; ThunarVfsVolume *volume; GtkIconTheme *icon_theme; const gchar *icon_name; GtkTreeIter iter; ThunarFile *file; GtkWidget *image; GtkWidget *item; GtkWidget *menu; GdkPixbuf *icon; gint icon_size; gint width; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); /* allocate a new menu */ menu = gtk_menu_new (); /* determine the icon theme and factory */ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (button)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* determine the icon size for menus */ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_size, &icon_size); /* load the menu items from the shortcuts model */ model = thunar_shortcuts_model_get_default (); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) { do { /* determine the file and volume for the item */ gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_FILE, &file, THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume, -1); /* check if we have a separator here */ if (G_UNLIKELY (file == NULL && volume == NULL)) { /* generate a separator the menu */ item = gtk_separator_menu_item_new (); } else if (G_UNLIKELY (volume != NULL)) { /* generate an image menu item for the volume */ item = gtk_image_menu_item_new_with_label (thunar_vfs_volume_get_name (volume)); /* load the icon for the volume */ icon_name = thunar_vfs_volume_lookup_icon_name (volume, icon_theme); icon = thunar_icon_factory_load_icon (icon_factory, icon_name, icon_size, NULL, FALSE); if (G_LIKELY (icon != NULL)) { /* generate an image for the menu item */ image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } } else { /* generate an image menu item for the file */ item = gtk_image_menu_item_new_with_label (thunar_file_get_display_name (file)); /* load the icon for the file and generate the image for the menu item */ icon = thunar_icon_factory_load_file_icon (icon_factory, file, THUNAR_FILE_ICON_STATE_DEFAULT, icon_size); image = gtk_image_new_from_pixbuf (icon); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); g_object_unref (G_OBJECT (icon)); gtk_widget_show (image); } /* connect the file and volume to the item */ g_object_set_data_full (G_OBJECT (item), I_("thunar-vfs-volume"), volume, g_object_unref); g_object_set_data_full (G_OBJECT (item), I_("thunar-file"), file, g_object_unref); /* append the new item to the menu */ g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (thunar_location_entry_item_activated), location_entry); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); } /* make sure the menu has atleast the same width as the location entry */ width = GTK_WIDGET (location_entry)->allocation.width - 2 * gtk_container_get_border_width (GTK_CONTAINER (location_entry)); if (G_LIKELY (menu->allocation.width < width)) gtk_widget_set_size_request (menu, width, -1); /* select the first visible or selectable item in the menu */ gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), TRUE); /* enable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* run the menu, taking ownership over the menu object */ thunar_gtk_menu_run (GTK_MENU (menu), button, menu_position, location_entry, 1, gtk_get_current_event_time ()); /* disable the button, making sure that we do not recurse on the "clicked" signal by temporarily blocking the handler */ g_signal_handlers_block_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); g_signal_handlers_unblock_by_func (G_OBJECT (button), G_CALLBACK (thunar_location_entry_button_clicked), location_entry); /* clean up */ g_object_unref (G_OBJECT (icon_factory)); g_object_unref (G_OBJECT (model)); }