Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:IBBoard:desktop
nautilus
nautilus-pr1030.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File nautilus-pr1030.diff of Package nautilus
diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 0f6b5eff9de488038e39c881648d51eecdf6eabc..eb57a4bf8df88b86342649c49297319efacfcad5 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -1607,6 +1607,7 @@ const GActionEntry win_entries[] = { .name = "forward", .activate = action_forward }, { .name = "back-n", .activate = action_back_n, .parameter_type = "u" }, { .name = "forward-n", .activate = action_forward_n, .parameter_type = "u" }, + { .name = "backspaceup", .activate = action_up }, { .name = "up", .activate = action_up }, { .name = "down", .activate = action_down }, { .name = "current-location-menu", .activate = action_show_current_location_menu }, @@ -1674,6 +1675,7 @@ nautilus_window_initialize_actions (NautilusWindow *window) nautilus_application_set_accelerators (app, "win.bookmark-current-location", ACCELS ("<control>d", "AddFavorite")); nautilus_application_set_accelerator (app, "win.up", "<alt>Up"); nautilus_application_set_accelerator (app, "win.down", "<alt>Down"); + nautilus_application_set_accelerator (app, "win.backspaceup", "BackSpace"); nautilus_application_set_accelerators (app, "win.go-home", ACCELS ("<alt>Home", "HomePage", "Start")); nautilus_application_set_accelerator (app, "win.go-starred", "Favorites"); nautilus_application_set_accelerator (app, "win.tab-move-left", "<shift><control>Page_Up"); diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index aea6ddafdaea13de26f86f464ade211cb6cd300c..a49ac017c26e6272b84b7ecaf32f521f9fd14deb 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -426,8 +426,6 @@ hide_query_editor (NautilusWindowSlot *self) view = nautilus_window_slot_get_current_view (self); - g_signal_handlers_disconnect_by_data (self->query_editor, self); - nautilus_query_editor_set_query (self->query_editor, NULL); if (nautilus_view_is_searching (view)) @@ -491,15 +489,6 @@ show_query_editor (NautilusWindowSlot *self) } gtk_widget_grab_focus (GTK_WIDGET (self->query_editor)); - - g_signal_connect (self->query_editor, "changed", - G_CALLBACK (query_editor_changed_callback), self); - g_signal_connect (self->query_editor, "cancel", - G_CALLBACK (query_editor_cancel_callback), self); - g_signal_connect (self->query_editor, "activated", - G_CALLBACK (query_editor_activated_callback), self); - g_signal_connect (self->query_editor, "focus-view", - G_CALLBACK (query_editor_focus_view_callback), self); } static void @@ -874,6 +863,15 @@ nautilus_window_slot_constructed (GObject *object) gtk_box_append (GTK_BOX (self->vbox), extras_vbox); self->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ()); + g_signal_connect (self->query_editor, "changed", + G_CALLBACK (query_editor_changed_callback), self); + g_signal_connect (self->query_editor, "cancel", + G_CALLBACK (query_editor_cancel_callback), self); + g_signal_connect (self->query_editor, "activated", + G_CALLBACK (query_editor_activated_callback), self); + g_signal_connect (self->query_editor, "focus-view", + G_CALLBACK (query_editor_focus_view_callback), self); + /* We want to keep alive the query editor betwen additions and removals on the * UI, specifically when the toolbar adds or removes it */ g_object_ref_sink (self->query_editor); @@ -2611,14 +2611,6 @@ view_started_loading (NautilusWindowSlot *self, nautilus_window_slot_set_allow_stop (self, TRUE); } - /* Only grab focus if the menu isn't showing. Otherwise the menu disappears - * e.g. when the user toggles Show Hidden Files - */ - if (!nautilus_window_is_menu_visible (self->window)) - { - gtk_widget_grab_focus (GTK_WIDGET (self->window)); - } - nautilus_window_slot_set_loading (self, TRUE); } @@ -2637,6 +2629,14 @@ view_ended_loading (NautilusWindowSlot *self, self->needs_reload = FALSE; } + /* Only grab focus if the menu isn't showing. Otherwise the menu disappears + * e.g. when the user toggles Show Hidden Files + */ + if (!nautilus_window_is_menu_visible (self->window)) + { + gtk_widget_grab_focus (GTK_WIDGET (self->window)); + } + nautilus_window_slot_set_allow_stop (self, FALSE); nautilus_window_slot_set_loading (self, FALSE); diff --git a/data/org.gnome.nautilus.gschema.xml b/data/org.gnome.nautilus.gschema.xml index 0776bd658ed845aa03b9a61ad01b81a9615a8d62..91a0a4ce075027c7e2c39dbf9f22e9504ae56b9e 100644 --- a/data/org.gnome.nautilus.gschema.xml +++ b/data/org.gnome.nautilus.gschema.xml @@ -82,6 +82,11 @@ <summary>Always use the location entry, instead of the pathbar</summary> <description>If set to true, Files will always use a textual input entry for the location toolbar, instead of the pathbar.</description> </key> + <key type="b" name="type-ahead-search"> + <default>true</default> + <summary>Start searching on type ahead</summary> + <description>If set to true, typing on the files viewer will start searching. Otherwise it select first matching file.</description> + </key> <key name="recursive-search" enum="org.gnome.nautilus.SpeedTradeoff"> <default>'local-only'</default> <summary>Where to perform recursive search</summary> diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c index f41938b28732451daef6d550b33093734cd6486b..81fedd7f003fb447251a22779bd5e0912f3c3db3 100644 --- a/src/nautilus-files-view.c +++ b/src/nautilus-files-view.c @@ -9828,3 +9828,19 @@ nautilus_files_view_new (guint id, return view; } + +void +nautilus_files_view_get_sort_state(NautilusFilesView *view, + GQuark *sort_attribute, + gboolean *reversed, + gboolean *directories_first) +{ + NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view); + + g_autoptr(GVariant) value = nautilus_list_base_get_sort_state(priv->list_base); + const gchar *target_name; + g_variant_get(value, "(&sb)", &target_name, reversed); + *sort_attribute = g_quark_from_string(target_name); + *directories_first = g_settings_get_boolean(gtk_filechooser_preferences, + NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST); +} diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h index 428a419c0d0dcce594a92638f7ba72afbb679890..9e3bffd9fb7a4df534a3ee2985f3cad56210f407 100644 --- a/src/nautilus-files-view.h +++ b/src/nautilus-files-view.h @@ -162,4 +162,9 @@ void nautilus_files_view_update_context_menus (NautilusFilesV void nautilus_files_view_update_toolbar_menus (NautilusFilesView *view); void nautilus_files_view_update_actions_state (NautilusFilesView *view); +void nautilus_files_view_get_sort_state (NautilusFilesView *view, + GQuark *sort_attribute, + gboolean *reversed, + gboolean *directories_first); + G_END_DECLS diff --git a/src/nautilus-global-preferences.h b/src/nautilus-global-preferences.h index d39c0f144e059b01778769f8b026822f587be972..1d424944061c8bb52942f967391a8d7286a558f4 100644 --- a/src/nautilus-global-preferences.h +++ b/src/nautilus-global-preferences.h @@ -116,6 +116,7 @@ typedef enum /* Search behaviour */ #define NAUTILUS_PREFERENCES_RECURSIVE_SEARCH "recursive-search" +#define NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH "type-ahead-search" /* Context menu options */ #define NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY "show-delete-permanently" diff --git a/src/nautilus-preferences-window.c b/src/nautilus-preferences-window.c index aa55177639331df8bf27a5363673687594f603a6..ccef83f5aee8aa92dd423db49d06f104949d5134 100644 --- a/src/nautilus-preferences-window.c +++ b/src/nautilus-preferences-window.c @@ -42,6 +42,8 @@ "show_create_link_row" #define NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET \ "use_tree_view_row" +#define NAUTILUS_PREFERENCES_DIALOG_TYPE_AHEAD_WIDGET \ + "type_ahead_search" /* combo preferences */ #define NAUTILUS_PREFERENCES_DIALOG_OPEN_ACTION_COMBO \ @@ -361,6 +363,9 @@ nautilus_preferences_window_setup (GtkBuilder *builder) bind_builder_bool (builder, nautilus_preferences, NAUTILUS_PREFERENCES_DIALOG_DELETE_PERMANENTLY_WIDGET, NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY); + bind_builder_bool (builder, nautilus_preferences, + NAUTILUS_PREFERENCES_DIALOG_TYPE_AHEAD_WIDGET, + NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH); setup_detailed_date (builder); diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c index 191f12b5792ae0fd08ca0d60de27f47bf69ed8ff..e55c384e850c774311b58606045eb7d5755a20d9 100644 --- a/src/nautilus-query-editor.c +++ b/src/nautilus-query-editor.c @@ -732,6 +732,12 @@ nautilus_query_editor_set_query (NautilusQueryEditor *self, g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (self)); + /* Setting query to NULL causes reentry to set it to an empty query */ + if (self->change_frozen) { + g_set_object (&self->query, query); + return; + } + if (query != NULL) { text = nautilus_query_get_text (query); diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index a49ac017c26e6272b84b7ecaf32f521f9fd14deb..fc4d0b2dd26024cd8af47cf440bf45b2f784c568 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -38,6 +38,7 @@ #include "nautilus-view.h" #include "nautilus-window.h" #include "nautilus-x-content-bar.h" +#include "nautilus-list-base.h" #include <glib/gi18n.h> #include <adwaita.h> @@ -68,6 +69,10 @@ enum NUM_PROPERTIES }; + +/* In type ahead mode, clear entry if it did not change for a while */ +#define CLEAR_QUERY_EDITOR_TIMEOUT 1000 + struct _NautilusWindowSlot { GtkBox parent_instance; @@ -110,6 +115,7 @@ struct _NautilusWindowSlot /* Query editor */ NautilusQueryEditor *query_editor; NautilusQuery *pending_search_query; + guint clear_query_editor_timeout_id; /* Banner */ AdwBanner *banner; @@ -404,6 +410,48 @@ query_editor_focus_view_callback (NautilusQueryEditor *editor, } } +static GFile * +nautilus_window_slot_get_current_location(NautilusWindowSlot *self) +{ + if (self->pending_location != NULL) + { + return self->pending_location; + } + + return self->location; +} + +static gboolean +type_ahead_search (void) +{ + return g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_TYPE_AHEAD_SEARCH); +} + +static gboolean +clear_query_editor_timeout_callback (NautilusWindowSlot *self) +{ + nautilus_query_editor_set_query (self->query_editor, NULL); + self->clear_query_editor_timeout_id = 0; + return G_SOURCE_REMOVE; +} + +typedef struct { + GQuark sort_attribute; + gboolean directories_first; + gboolean reversed; +} FileCompareForTypeAheadContext; + +static int +file_compare_for_type_ahead (gconstpointer a, gconstpointer b, gpointer user_data) +{ + FileCompareForTypeAheadContext *ctx = user_data; + return nautilus_file_compare_for_sort_by_attribute_q(NAUTILUS_FILE(a), + NAUTILUS_FILE(b), + ctx->sort_attribute, + ctx->directories_first, + ctx->reversed); +} + static void query_editor_changed_callback (NautilusQueryEditor *editor, NautilusQuery *query, @@ -414,9 +462,53 @@ query_editor_changed_callback (NautilusQueryEditor *editor, view = nautilus_window_slot_get_current_view (self); - /* Setting search query may cause the view to load a new location. */ - nautilus_view_set_search_query (view, query); - nautilus_window_slot_set_location (self, nautilus_view_get_location (view)); + if (nautilus_window_slot_get_search_visible (self)) + { + /* Setting search query may cause the view to load a new location. */ + nautilus_view_set_search_query (view, query); + nautilus_window_slot_set_location (self, nautilus_view_get_location (view)); + } + else + { + /* Find all files with a display name that starts with the query, case insensitive. */ + GFile *location = nautilus_window_slot_get_current_location (self); + g_autoptr (NautilusDirectory) directory = nautilus_directory_get (location); + const gchar *text = nautilus_query_get_text (query); + g_autofree gchar *text_casefold = g_utf8_casefold (text, -1); + g_autofree gchar *text_collate = g_utf8_collate_key_for_filename (text_casefold, -1); + gsize text_len = strlen (text); + g_autolist (NautilusFile) files = nautilus_directory_get_file_list (directory); + g_autolist (NautilusFile) matches = NULL; + GList *l; + + for (l = files; l; l = l->next) + { + NautilusFile *file = NAUTILUS_FILE (l->data); + const gchar *name = nautilus_file_get_display_name(file); + g_autofree gchar *name_casefold = g_utf8_casefold(name, text_len); + g_autofree gchar *name_collate = g_utf8_collate_key_for_filename(name_casefold, -1); + + if (g_str_equal (name_collate, text_collate)) + { + matches = g_list_prepend (matches, nautilus_file_ref (file)); + } + } + + /* Select the first match */ + { + FileCompareForTypeAheadContext ctx; + nautilus_files_view_get_sort_state(NAUTILUS_FILES_VIEW(view), &ctx.sort_attribute, &ctx.reversed, &ctx.directories_first); + matches = g_list_sort_with_data(matches, file_compare_for_type_ahead, &ctx); + g_autolist(NautilusFile) selection = g_list_prepend(NULL, g_object_ref(matches->data)); + nautilus_view_set_selection (self->content_view, selection); + } + + /* Reset timeout that clears type ahead query */ + g_clear_handle_id (&self->clear_query_editor_timeout_id, g_source_remove); + self->clear_query_editor_timeout_id = g_timeout_add (CLEAR_QUERY_EDITOR_TIMEOUT, + G_SOURCE_FUNC (clear_query_editor_timeout_callback), + self); + } } static void @@ -454,17 +546,6 @@ hide_query_editor (NautilusWindowSlot *self) } } -static GFile * -nautilus_window_slot_get_current_location (NautilusWindowSlot *self) -{ - if (self->pending_location != NULL) - { - return self->pending_location; - } - - return self->location; -} - static void show_query_editor (NautilusWindowSlot *self) { @@ -602,7 +683,7 @@ nautilus_window_slot_handle_event (NautilusWindowSlot *self, state); } - if (retval) + if (retval && type_ahead_search ()) { nautilus_window_slot_set_search_visible (self, TRUE); } @@ -1962,6 +2043,9 @@ setup_view (NautilusWindowSlot *self, nautilus_window_slot_disconnect_content_view (self); + nautilus_query_editor_set_query (self->query_editor, NULL); + g_clear_handle_id (&self->clear_query_editor_timeout_id, g_source_remove); + self->new_content_view = view; nautilus_window_slot_connect_new_content_view (self); diff --git a/src/resources/ui/nautilus-preferences-window.ui b/src/resources/ui/nautilus-preferences-window.ui index 671fd708117bb346900b390bf2ccc261b2106fe4..2d815ab950a1c0ec0977d2e500a4c5f8f5657172 100644 --- a/src/resources/ui/nautilus-preferences-window.ui +++ b/src/resources/ui/nautilus-preferences-window.ui @@ -37,6 +37,21 @@ <property name="visible">True</property> </object> </child> + <child> + <object class="AdwActionRow"> + <property name="activatable_widget">type_ahead_search</property> + <property name="subtitle_lines">0</property> + <property name="title" translatable="yes">Search on type ahead</property> + <property name="title_lines">0</property> + <property name="use_underline">True</property> + <property name="visible">True</property> + <child> + <object class="GtkSwitch" id="type_ahead_search"> + <property name="valign">center</property> + </object> + </child> + </object> + </child> </object> </child> <child>
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor