diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/caja-desktop-window.c | 3 | ||||
| -rw-r--r-- | src/caja-file-management-properties.c | 4 | ||||
| -rw-r--r-- | src/caja-navigation-window-pane.c | 26 | ||||
| -rw-r--r-- | src/file-manager/fm-desktop-icon-view.c | 8 | ||||
| -rw-r--r-- | src/file-manager/fm-icon-container.c | 88 | ||||
| -rw-r--r-- | src/file-manager/fm-icon-view.c | 125 | ||||
| -rw-r--r-- | src/file-manager/fm-icon-view.h | 12 | ||||
| -rw-r--r-- | src/file-manager/fm-list-view.c | 69 |
8 files changed, 327 insertions, 8 deletions
diff --git a/src/caja-desktop-window.c b/src/caja-desktop-window.c index 662c2472..72a2bcab 100644 --- a/src/caja-desktop-window.c +++ b/src/caja-desktop-window.c @@ -116,6 +116,7 @@ caja_desktop_window_init (CajaDesktopWindow *window) gtk_widget_hide (CAJA_WINDOW (window)->details->statusbar); gtk_widget_hide (CAJA_WINDOW (window)->details->menubar); + gtk_window_set_decorated (GTK_WINDOW (window), FALSE); /* Don't allow close action on desktop */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; @@ -238,7 +239,7 @@ caja_desktop_window_new (CajaApplication *application, gtk_layer_init_for_window (gtkwin); /* Order below normal windows */ - gtk_layer_set_layer (gtkwin, GTK_LAYER_SHELL_LAYER_BOTTOM); + gtk_layer_set_layer (gtkwin, GTK_LAYER_SHELL_LAYER_BACKGROUND); gtk_layer_set_namespace (gtkwin, "desktop"); diff --git a/src/caja-file-management-properties.c b/src/caja-file-management-properties.c index ba76ebda..6606c834 100644 --- a/src/caja-file-management-properties.c +++ b/src/caja-file-management-properties.c @@ -61,6 +61,7 @@ #define CAJA_FILE_MANAGEMENT_PROPERTIES_FOLDERS_FIRST_WIDGET "sort_folders_first_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_COMPACT_LAYOUT_WIDGET "compact_layout_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_LABELS_BESIDE_ICONS_WIDGET "labels_beside_icons_checkbutton" +#define CAJA_FILE_MANAGEMENT_PROPERTIES_DISPLAY_GIT_BRANCH_WIDGET "display_git_branch_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_ALL_COLUMNS_SAME_WIDTH "all_columns_same_width_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_ALWAYS_USE_BROWSER_WIDGET "always_use_browser_checkbutton" #define CAJA_FILE_MANAGEMENT_PROPERTIES_TRASH_CONFIRM_WIDGET "trash_confirm_checkbutton" @@ -1106,6 +1107,9 @@ caja_file_management_properties_dialog_setup (GtkBuilder *builder, GtkWindow *wi bind_builder_bool (builder, caja_icon_view_preferences, CAJA_FILE_MANAGEMENT_PROPERTIES_LABELS_BESIDE_ICONS_WIDGET, CAJA_PREFERENCES_ICON_VIEW_LABELS_BESIDE_ICONS); + bind_builder_bool (builder, caja_icon_view_preferences, + CAJA_FILE_MANAGEMENT_PROPERTIES_DISPLAY_GIT_BRANCH_WIDGET, + CAJA_PREFERENCES_ICON_VIEW_DISPLAY_GIT_BRANCH); bind_builder_bool (builder, caja_compact_view_preferences, CAJA_FILE_MANAGEMENT_PROPERTIES_ALL_COLUMNS_SAME_WIDTH, CAJA_PREFERENCES_COMPACT_VIEW_ALL_COLUMNS_SAME_WIDTH); diff --git a/src/caja-navigation-window-pane.c b/src/caja-navigation-window-pane.c index 19669411..5e870d45 100644 --- a/src/caja-navigation-window-pane.c +++ b/src/caja-navigation-window-pane.c @@ -26,6 +26,7 @@ #include <libcaja-private/caja-global-preferences.h> #include <libcaja-private/caja-window-slot-info.h> +#include <libcaja-private/caja-window-info.h> #include <libcaja-private/caja-view-factory.h> #include <libcaja-private/caja-entry.h> @@ -139,6 +140,31 @@ search_bar_activate_callback (CajaSearchBar *bar, caja_query_set_location (query, current_uri); g_free (current_uri); } + + /* Set hidden files visibility based on current window setting */ + { + CajaWindow *window; + CajaWindowShowHiddenFilesMode mode; + gboolean show_hidden_files = FALSE; + + window = slot->pane->window; + mode = caja_window_info_get_hidden_files_mode (CAJA_WINDOW_INFO (window)); + + if (mode == CAJA_WINDOW_SHOW_HIDDEN_FILES_ENABLE) + { + show_hidden_files = TRUE; + } + else if (mode == CAJA_WINDOW_SHOW_HIDDEN_FILES_DEFAULT) + { + show_hidden_files = g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_SHOW_HIDDEN_FILES); + } + + CajaSearchEngine *engine = caja_search_directory_get_engine (search_directory); + if (engine) { + caja_search_engine_set_show_hidden_files (engine, show_hidden_files); + } + } + caja_search_directory_set_query (search_directory, query); g_object_unref (query); } diff --git a/src/file-manager/fm-desktop-icon-view.c b/src/file-manager/fm-desktop-icon-view.c index 954c26de..1e08b7cf 100644 --- a/src/file-manager/fm-desktop-icon-view.c +++ b/src/file-manager/fm-desktop-icon-view.c @@ -89,6 +89,7 @@ static gboolean real_supports_auto_layout (FMIconView static gboolean real_supports_scaling (FMIconView *view); static gboolean real_supports_keep_aligned (FMIconView *view); static gboolean real_supports_labels_beside_icons (FMIconView *view); +static gboolean real_supports_display_git_branch (FMIconView *view); static void real_merge_menus (FMDirectoryView *view); static void real_update_menus (FMDirectoryView *view); static gboolean real_supports_zooming (FMDirectoryView *view); @@ -336,6 +337,7 @@ fm_desktop_icon_view_class_init (FMDesktopIconViewClass *class) FM_ICON_VIEW_CLASS (class)->supports_scaling = real_supports_scaling; FM_ICON_VIEW_CLASS (class)->supports_keep_aligned = real_supports_keep_aligned; FM_ICON_VIEW_CLASS (class)->supports_labels_beside_icons = real_supports_labels_beside_icons; + FM_ICON_VIEW_CLASS (class)->supports_display_git_branch = real_supports_display_git_branch; } /*This code is only reached when running on x11*/ @@ -920,6 +922,12 @@ real_supports_labels_beside_icons (FMIconView *view) } static gboolean +real_supports_display_git_branch (FMIconView *view) +{ + return FALSE; +} + +static gboolean real_supports_zooming (FMDirectoryView *view) { /* Can't zoom on the desktop, because doing so would cause all diff --git a/src/file-manager/fm-icon-container.c b/src/file-manager/fm-icon-container.c index c83cf783..8054c2da 100644 --- a/src/file-manager/fm-icon-container.c +++ b/src/file-manager/fm-icon-container.c @@ -34,6 +34,7 @@ #include <libcaja-private/caja-thumbnails.h> #include <libcaja-private/caja-desktop-icon-file.h> +#include <libcaja-private/caja-icon-private.h> #include "fm-icon-container.h" G_DEFINE_TYPE (FMIconContainer, fm_icon_container, CAJA_TYPE_ICON_CONTAINER); @@ -295,6 +296,67 @@ fm_icon_container_get_icon_text_attribute_names (CajaIconContainer *container, return attributes; } +/** + * Parse a .git directory/file to determine repository branch name + **/ +static char * +get_git_branch (const char *git_path) { + gchar *head_content = NULL; + gchar *branch_name = NULL; + gchar *head_path = NULL; + + if (g_file_test (git_path, G_FILE_TEST_IS_REGULAR)) + { + /* It's a file, thus we are probably dealing with a submodule, so read it to resolve the real git dir */ + gchar *contents = NULL; + if (g_file_get_contents (git_path, &contents, NULL, NULL) && contents) + { + const char *git_dir_prefix = "gitdir: "; + if (g_str_has_prefix (contents, git_dir_prefix)) + { + size_t git_dir_prefix_len = strlen (git_dir_prefix); + gchar *relative = g_strstrip (contents + git_dir_prefix_len); + gchar *base = g_path_get_dirname (git_path); + g_free (git_path); + git_path = g_build_filename (base, relative, NULL); + g_free (base); + } + g_free (contents); + } + } + + /* Extract the current git branch name of the repository from file HEAD within .git directory */ + if (g_file_test (git_path, G_FILE_TEST_IS_DIR)) + { + head_path = g_build_filename (git_path, "HEAD", NULL); + if (g_file_get_contents (head_path, &head_content, NULL, NULL)) + { + g_strstrip (head_content); + if (g_str_has_prefix (head_content, "ref: ")) + { + gchar **parts = g_strsplit (head_content, "/", -1); + if (parts != NULL) + { + branch_name = g_strdup (parts[g_strv_length(parts) - 1]); + g_strchomp (branch_name); + g_strfreev (parts); + } + } + else + { + /* Repository is in a detached HEAD state */ + branch_name = g_strdup_printf (_("detached: %.7s"), head_content); + } + } + } + + g_free (head_content); + g_free (head_path); + + /* branch_name is a newly allocated string, so the caller is responsible for freeing it */ + return branch_name; +} + /* This callback returns the text, both the editable part, and the * part below that is not editable. */ @@ -398,6 +460,32 @@ fm_icon_container_get_icon_text (CajaIconContainer *container, if (j == 0) { *additional_text = NULL; + if (container->details->display_git_branch == CAJA_DISPLAY_GIT_BRANCH_ENABLED) + { + /* If we have a directory, check if it's a git repository or submodule */ + GFileType file_type = caja_file_get_file_type (file); + if (file_type == G_FILE_TYPE_DIRECTORY) + { + GFile *location = caja_file_get_location (file); + char *path = g_file_get_path (location); + if (path != NULL) + { + char *git_path = g_build_path (G_DIR_SEPARATOR_S, path, ".git", NULL); + if (git_path != NULL && G_UNLIKELY(g_file_test (git_path, G_FILE_TEST_EXISTS))) + { + char *branch = get_git_branch (git_path); + if (branch != NULL) + { + *additional_text = g_strdup_printf ("[%s]", branch); + g_free (branch); + } + } + g_free (git_path); + g_free (path); + } + g_object_unref (location); + } + } } else if (j == 1) { diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index 83517273..c17bedf6 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -38,6 +38,7 @@ #include <sys/wait.h> #include <eel/eel-background.h> +#include <eel/eel-canvas.h> #include <eel/eel-glib-extensions.h> #include <eel/eel-gtk-extensions.h> #include <eel/eel-gtk-macros.h> @@ -48,11 +49,14 @@ #include <libcaja-private/caja-clipboard-monitor.h> #include <libcaja-private/caja-directory-background.h> #include <libcaja-private/caja-directory.h> +#include <libcaja-private/caja-search-directory.h> #include <libcaja-private/caja-dnd.h> #include <libcaja-private/caja-file-utilities.h> #include <libcaja-private/caja-ui-utilities.h> #include <libcaja-private/caja-global-preferences.h> +#include <libcaja-private/caja-icon-canvas-item.h> #include <libcaja-private/caja-icon-container.h> +#include <libcaja-private/caja-icon-private.h> #include <libcaja-private/caja-icon-dnd.h> #include <libcaja-private/caja-link.h> #include <libcaja-private/caja-metadata.h> @@ -201,6 +205,7 @@ static void default_sort_in_reverse_order_changed_callback (gpointer callback_da static void default_use_tighter_layout_changed_callback (gpointer callback_data); static void default_zoom_level_changed_callback (gpointer callback_data); static void labels_beside_icons_changed_callback (gpointer callback_data); +static void display_git_branch_changed_callback (gpointer callback_data); static void all_columns_same_width_changed_callback (gpointer callback_data); static void fm_icon_view_iface_init (CajaViewIface *iface); @@ -265,6 +270,9 @@ fm_icon_view_finalize (GObject *object) g_signal_handlers_disconnect_by_func (caja_icon_view_preferences, labels_beside_icons_changed_callback, icon_view); + g_signal_handlers_disconnect_by_func (caja_icon_view_preferences, + display_git_branch_changed_callback, + icon_view); g_signal_handlers_disconnect_by_func (caja_compact_view_preferences, default_zoom_level_changed_callback, icon_view); @@ -706,6 +714,16 @@ fm_icon_view_supports_labels_beside_icons (FMIconView *view) } static gboolean +fm_icon_view_supports_display_git_branch (FMIconView *view) +{ + g_return_val_if_fail (FM_IS_ICON_VIEW (view), FALSE); + + return EEL_CALL_METHOD_WITH_RETURN_VALUE + (FM_ICON_VIEW_CLASS, view, + supports_display_git_branch, (view)); +} + +static gboolean fm_icon_view_supports_tighter_layout (FMIconView *view) { return !fm_icon_view_is_compact (view); @@ -1184,6 +1202,14 @@ real_supports_labels_beside_icons (FMIconView *view) } static gboolean +real_supports_display_git_branch (FMIconView *view) +{ + g_return_val_if_fail (FM_IS_ICON_VIEW (view), TRUE); + + return TRUE; +} + +static gboolean set_sort_reversed (FMIconView *icon_view, gboolean new_value) { if (icon_view->details->sort_reversed == new_value) @@ -1283,6 +1309,31 @@ set_labels_beside_icons (FMIconView *icon_view) } static void +set_display_git_branch (FMIconView *icon_view) +{ + gboolean git_branch; + + if (fm_icon_view_supports_display_git_branch (icon_view)) + { + git_branch = fm_icon_view_is_compact (icon_view) || + g_settings_get_boolean (caja_icon_view_preferences, CAJA_PREFERENCES_ICON_VIEW_DISPLAY_GIT_BRANCH); + + if (git_branch) + { + caja_display_git_branch_enable + (get_icon_container (icon_view), + CAJA_DISPLAY_GIT_BRANCH_ENABLED); + } + else + { + caja_display_git_branch_enable + (get_icon_container (icon_view), + CAJA_DISPLAY_GIT_BRANCH_DISABLED); + } + } +} + +static void set_columns_same_width (FMIconView *icon_view) { gboolean all_columns_same_width; @@ -1383,6 +1434,7 @@ fm_icon_view_begin_loading (FMDirectoryView *view) fm_icon_view_get_directory_tighter_layout (icon_view, file)); set_labels_beside_icons (icon_view); + set_display_git_branch (icon_view); set_columns_same_width (icon_view); /* We must set auto-layout last, because it invokes the layout_changed @@ -2903,6 +2955,18 @@ labels_beside_icons_changed_callback (gpointer callback_data) } static void +display_git_branch_changed_callback (gpointer callback_data) +{ + FMIconView *icon_view; + + g_return_if_fail (FM_IS_ICON_VIEW (callback_data)); + + icon_view = FM_ICON_VIEW (callback_data); + + set_display_git_branch (icon_view); +} + +static void all_columns_same_width_changed_callback (gpointer callback_data) { FMIconView *icon_view; @@ -3054,6 +3118,58 @@ focus_in_event_callback (GtkWidget *widget, GdkEventFocus *event, gpointer user_ return FALSE; } +static gboolean +icon_container_query_tooltip_callback (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + FMIconView *icon_view) +{ + CajaIconContainer *icon_container; + EelCanvasItem *item; + CajaFile *file; + char *location_text; + + /* Only show tooltips in search directories */ + if (!CAJA_IS_SEARCH_DIRECTORY (fm_directory_view_get_model (FM_DIRECTORY_VIEW (icon_view)))) + { + return FALSE; + } + + icon_container = CAJA_ICON_CONTAINER (widget); + + /* Get the canvas item at the cursor position */ + item = eel_canvas_get_item_at (EEL_CANVAS (icon_container), x, y); + if (item == NULL || !CAJA_IS_ICON_CANVAS_ITEM (item)) + { + return FALSE; + } + + /* Get the file from the canvas item's user_data */ + CajaIcon *icon = CAJA_ICON_CANVAS_ITEM (item)->user_data; + file = CAJA_FILE (icon->data); + if (file == NULL) + { + return FALSE; + } + + /* Get the location attribute */ + location_text = caja_file_get_string_attribute_with_default (file, "location"); + if (location_text == NULL || location_text[0] == '\0') + { + g_free (location_text); + return FALSE; + } + + /* Set tooltip text with file location */ + gtk_tooltip_set_text (tooltip, location_text); + + g_free (location_text); + + return TRUE; +} + static CajaIconContainer * create_icon_container (FMIconView *icon_view) { @@ -3062,9 +3178,12 @@ create_icon_container (FMIconView *icon_view) icon_container = fm_icon_container_new (icon_view); gtk_widget_set_can_focus (GTK_WIDGET (icon_container), TRUE); + gtk_widget_set_has_tooltip (GTK_WIDGET (icon_container), TRUE); g_signal_connect_object (icon_container, "focus_in_event", G_CALLBACK (focus_in_event_callback), icon_view, 0); + g_signal_connect_object (icon_container, "query-tooltip", + G_CALLBACK (icon_container_query_tooltip_callback), icon_view, 0); g_signal_connect_object (icon_container, "activate", G_CALLBACK (icon_container_activate_callback), icon_view, 0); g_signal_connect_object (icon_container, "activate_alternate", @@ -3293,6 +3412,7 @@ fm_icon_view_class_init (FMIconViewClass *klass) klass->supports_manual_layout = real_supports_manual_layout; klass->supports_keep_aligned = real_supports_keep_aligned; klass->supports_labels_beside_icons = real_supports_labels_beside_icons; + klass->supports_display_git_branch = real_supports_display_git_branch; klass->get_directory_auto_layout = fm_icon_view_real_get_directory_auto_layout; klass->get_directory_sort_by = fm_icon_view_real_get_directory_sort_by; klass->get_directory_sort_reversed = fm_icon_view_real_get_directory_sort_reversed; @@ -3389,7 +3509,10 @@ fm_icon_view_init (FMIconView *icon_view) "changed::" CAJA_PREFERENCES_ICON_VIEW_LABELS_BESIDE_ICONS, G_CALLBACK (labels_beside_icons_changed_callback), icon_view); - + g_signal_connect_swapped (caja_icon_view_preferences, + "changed::" CAJA_PREFERENCES_ICON_VIEW_DISPLAY_GIT_BRANCH, + G_CALLBACK (display_git_branch_changed_callback), + icon_view); g_signal_connect_swapped (caja_compact_view_preferences, "changed::" CAJA_PREFERENCES_COMPACT_VIEW_DEFAULT_ZOOM_LEVEL, G_CALLBACK (default_zoom_level_changed_callback), diff --git a/src/file-manager/fm-icon-view.h b/src/file-manager/fm-icon-view.h index dfd2a171..c8c8c2f7 100644 --- a/src/file-manager/fm-icon-view.h +++ b/src/file-manager/fm-icon-view.h @@ -108,17 +108,17 @@ struct FMIconViewClass */ gboolean (* supports_scaling) (FMIconView *view); - /* supports_auto_layout is a function pointer that subclasses may - * override to control whether snap-to-grid mode - * should be enabled. The default implementation returns FALSE. + /* */ gboolean (* supports_keep_aligned) (FMIconView *view); - /* supports_auto_layout is a function pointer that subclasses may - * override to control whether snap-to-grid mode - * should be enabled. The default implementation returns FALSE. + /* */ gboolean (* supports_labels_beside_icons) (FMIconView *view); + + /* + */ + gboolean (* supports_display_git_branch) (FMIconView *view); }; /* GObject support */ diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c index b5a61459..57b5862c 100644 --- a/src/file-manager/fm-list-view.c +++ b/src/file-manager/fm-list-view.c @@ -48,6 +48,7 @@ #include <libcaja-private/caja-column-utilities.h> #include <libcaja-private/caja-debug-log.h> #include <libcaja-private/caja-directory-background.h> +#include <libcaja-private/caja-search-directory.h> #include <libcaja-private/caja-dnd.h> #include <libcaja-private/caja-file-dnd.h> #include <libcaja-private/caja-file-utilities.h> @@ -1640,6 +1641,70 @@ focus_in_event_callback (GtkWidget *widget, GdkEventFocus *event, gpointer user_ return FALSE; } +static gboolean +tree_view_query_tooltip_callback (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard_tip, + GtkTooltip *tooltip, + FMListView *list_view) +{ + GtkTreeView *tree_view; + GtkTreePath *path; + GtkTreeModel *model; + GtkTreeIter iter; + CajaFile *file; + char *location_text; + + /* Only show tooltips in search directories */ + if (!CAJA_IS_SEARCH_DIRECTORY (fm_directory_view_get_model (FM_DIRECTORY_VIEW (list_view)))) + { + return FALSE; + } + + tree_view = GTK_TREE_VIEW (widget); + + /* Get the tree path at the cursor position */ + if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL)) + { + return FALSE; + } + + model = gtk_tree_view_get_model (tree_view); + if (!gtk_tree_model_get_iter (model, &iter, path)) + { + gtk_tree_path_free (path); + return FALSE; + } + + /* Get the file from the model */ + gtk_tree_model_get (model, &iter, FM_LIST_MODEL_FILE_COLUMN, &file, -1); + if (file == NULL) + { + gtk_tree_path_free (path); + return FALSE; + } + + /* Get the location attribute */ + location_text = caja_file_get_string_attribute_with_default (file, "location"); + if (location_text == NULL || location_text[0] == '\0') + { + g_free (location_text); + caja_file_unref (file); + gtk_tree_path_free (path); + return FALSE; + } + + /* Set tooltip text with file location */ + gtk_tooltip_set_text (tooltip, location_text); + + g_free (location_text); + caja_file_unref (file); + gtk_tree_path_free (path); + + return TRUE; +} + static gint get_icon_scale_callback (FMListModel *model, FMListView *view) @@ -1664,6 +1729,8 @@ create_and_set_up_tree_view (FMListView *view) NULL); gtk_tree_view_set_enable_search (view->details->tree_view, TRUE); + gtk_widget_set_has_tooltip (GTK_WIDGET (view->details->tree_view), TRUE); + /* Don't handle backspace key. It's used to open the parent folder. */ binding_set = gtk_binding_set_by_class (GTK_WIDGET_GET_CLASS (view->details->tree_view)); gtk_binding_entry_remove (binding_set, GDK_KEY_BackSpace, 0); @@ -1723,6 +1790,8 @@ create_and_set_up_tree_view (FMListView *view) g_signal_connect_object (view->details->tree_view, "focus_in_event", G_CALLBACK(focus_in_event_callback), view, 0); + g_signal_connect_object (view->details->tree_view, "query-tooltip", + G_CALLBACK (tree_view_query_tooltip_callback), view, 0); view->details->model = g_object_new (FM_TYPE_LIST_MODEL, NULL); gtk_tree_view_set_model (view->details->tree_view, GTK_TREE_MODEL (view->details->model)); |
