mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-24 18:25:50 +00:00
query-editor: Make type final
It’s not derived anywhere, and thus it shouldn’t be derivable.
This commit is contained in:
parent
485b746620
commit
3cf82d89da
|
@ -37,8 +37,10 @@
|
|||
#include "nautilus-mime-actions.h"
|
||||
#include "nautilus-ui-utilities.h"
|
||||
|
||||
typedef struct
|
||||
struct _NautilusQueryEditor
|
||||
{
|
||||
GtkBox parent_instance;
|
||||
|
||||
GtkWidget *entry;
|
||||
GtkWidget *popover;
|
||||
GtkWidget *label;
|
||||
|
@ -52,7 +54,7 @@ typedef struct
|
|||
GFile *location;
|
||||
|
||||
NautilusQuery *query;
|
||||
} NautilusQueryEditorPrivate;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -78,23 +80,20 @@ static void entry_changed_cb (GtkWidget *entry,
|
|||
NautilusQueryEditor *editor);
|
||||
static void nautilus_query_editor_changed (NautilusQueryEditor *editor);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_BOX);
|
||||
G_DEFINE_TYPE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_BOX);
|
||||
|
||||
static gboolean
|
||||
settings_search_is_recursive (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusFile *file;
|
||||
gboolean recursive;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (!priv->location)
|
||||
if (editor->location == NULL)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
file = nautilus_file_get (priv->location);
|
||||
file = nautilus_file_get (editor->location);
|
||||
|
||||
if (nautilus_file_is_remote (file))
|
||||
{
|
||||
|
@ -114,20 +113,17 @@ settings_search_is_recursive (NautilusQueryEditor *editor)
|
|||
static void
|
||||
update_information_label (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
gboolean fts_sensitive = TRUE;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (priv->location)
|
||||
if (editor->location)
|
||||
{
|
||||
NautilusFile *file;
|
||||
g_autoptr (NautilusFile) file = NULL;
|
||||
gchar *label;
|
||||
gchar *uri;
|
||||
g_autofree gchar *uri = NULL;
|
||||
|
||||
file = nautilus_file_get (priv->location);
|
||||
file = nautilus_file_get (editor->location);
|
||||
label = NULL;
|
||||
uri = g_file_get_uri (priv->location);
|
||||
uri = g_file_get_uri (editor->location);
|
||||
|
||||
if (nautilus_file_is_other_locations (file))
|
||||
{
|
||||
|
@ -150,14 +146,11 @@ update_information_label (NautilusQueryEditor *editor)
|
|||
label = _("Only searching the current folder");
|
||||
}
|
||||
|
||||
nautilus_search_popover_set_fts_sensitive (NAUTILUS_SEARCH_POPOVER (priv->popover),
|
||||
nautilus_search_popover_set_fts_sensitive (NAUTILUS_SEARCH_POPOVER (editor->popover),
|
||||
fts_sensitive);
|
||||
|
||||
gtk_widget_set_visible (priv->label, label != NULL);
|
||||
gtk_label_set_label (GTK_LABEL (priv->label), label);
|
||||
|
||||
g_free (uri);
|
||||
nautilus_file_unref (file);
|
||||
gtk_widget_set_visible (editor->label, label != NULL);
|
||||
gtk_label_set_label (GTK_LABEL (editor->label), label);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,20 +159,17 @@ recursive_search_preferences_changed (GSettings *settings,
|
|||
gchar *key,
|
||||
NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
gboolean recursive;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (!priv->location || !priv->query)
|
||||
if (!editor->location || !editor->query)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
recursive = settings_search_is_recursive (editor);
|
||||
if (recursive != nautilus_query_get_recursive (priv->query))
|
||||
if (recursive != nautilus_query_get_recursive (editor->query))
|
||||
{
|
||||
nautilus_query_set_recursive (priv->query, recursive);
|
||||
nautilus_query_set_recursive (editor->query, recursive);
|
||||
nautilus_query_editor_changed (editor);
|
||||
}
|
||||
|
||||
|
@ -190,12 +180,12 @@ recursive_search_preferences_changed (GSettings *settings,
|
|||
static void
|
||||
nautilus_query_editor_dispose (GObject *object)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
|
||||
editor = NAUTILUS_QUERY_EDITOR (object);
|
||||
|
||||
g_clear_object (&priv->location);
|
||||
g_clear_object (&priv->query);
|
||||
g_clear_object (&editor->location);
|
||||
g_clear_object (&editor->query);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (nautilus_preferences,
|
||||
recursive_search_preferences_changed,
|
||||
|
@ -207,15 +197,15 @@ nautilus_query_editor_dispose (GObject *object)
|
|||
static void
|
||||
nautilus_query_editor_grab_focus (GtkWidget *widget)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (widget));
|
||||
editor = NAUTILUS_QUERY_EDITOR (widget);
|
||||
|
||||
if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (priv->entry))
|
||||
if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (editor->entry))
|
||||
{
|
||||
/* avoid selecting the entry text */
|
||||
gtk_widget_grab_focus (priv->entry);
|
||||
gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1);
|
||||
gtk_widget_grab_focus (editor->entry);
|
||||
gtk_editable_set_position (GTK_EDITABLE (editor->entry), -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,21 +215,21 @@ nautilus_query_editor_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
|
||||
editor = NAUTILUS_QUERY_EDITOR (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LOCATION:
|
||||
{
|
||||
g_value_set_object (value, priv->location);
|
||||
g_value_set_object (value, editor->location);
|
||||
}
|
||||
break;
|
||||
|
||||
case PROP_QUERY:
|
||||
{
|
||||
g_value_set_object (value, priv->query);
|
||||
g_value_set_object (value, editor->query);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -280,12 +270,12 @@ nautilus_query_editor_set_property (GObject *object,
|
|||
static void
|
||||
nautilus_query_editor_finalize (GObject *object)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
|
||||
editor = NAUTILUS_QUERY_EDITOR (object);
|
||||
|
||||
g_clear_object (&priv->date_range_tag);
|
||||
g_clear_object (&priv->mime_types_tag);
|
||||
g_clear_object (&editor->date_range_tag);
|
||||
g_clear_object (&editor->mime_types_tag);
|
||||
|
||||
G_OBJECT_CLASS (nautilus_query_editor_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -309,7 +299,7 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
|
|||
g_signal_new ("changed",
|
||||
G_TYPE_FROM_CLASS (class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (NautilusQueryEditorClass, changed),
|
||||
0,
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE, 2, NAUTILUS_TYPE_QUERY, G_TYPE_BOOLEAN);
|
||||
|
@ -318,7 +308,7 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
|
|||
g_signal_new ("cancel",
|
||||
G_TYPE_FROM_CLASS (class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (NautilusQueryEditorClass, cancel),
|
||||
0,
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
@ -327,7 +317,7 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
|
|||
g_signal_new ("activated",
|
||||
G_TYPE_FROM_CLASS (class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (NautilusQueryEditorClass, activated),
|
||||
0,
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
@ -363,49 +353,40 @@ nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
|
|||
GFile *
|
||||
nautilus_query_editor_get_location (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor), NULL);
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
return g_object_ref (priv->location);
|
||||
return g_object_ref (editor->location);
|
||||
}
|
||||
|
||||
static void
|
||||
create_query (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQuery *query;
|
||||
NautilusFile *file;
|
||||
g_autoptr (NautilusFile) file = NULL;
|
||||
gboolean recursive;
|
||||
gboolean fts_enabled;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
g_return_if_fail (editor->query == NULL);
|
||||
|
||||
g_return_if_fail (!priv->query);
|
||||
fts_enabled = nautilus_search_popover_get_fts_enabled (NAUTILUS_SEARCH_POPOVER (editor->popover));
|
||||
|
||||
fts_enabled = nautilus_search_popover_get_fts_enabled (NAUTILUS_SEARCH_POPOVER (priv->popover));
|
||||
|
||||
if (priv->location == NULL)
|
||||
if (editor->location == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
file = nautilus_file_get (priv->location);
|
||||
file = nautilus_file_get (editor->location);
|
||||
query = nautilus_query_new ();
|
||||
|
||||
nautilus_query_set_search_content (query, fts_enabled);
|
||||
|
||||
recursive = settings_search_is_recursive (editor);
|
||||
|
||||
nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (priv->entry)));
|
||||
nautilus_query_set_location (query, priv->location);
|
||||
nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (editor->entry)));
|
||||
nautilus_query_set_location (query, editor->location);
|
||||
nautilus_query_set_recursive (query, recursive);
|
||||
|
||||
nautilus_query_editor_set_query (editor, query);
|
||||
|
||||
nautilus_file_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -419,26 +400,26 @@ static void
|
|||
entry_changed_cb (GtkWidget *entry,
|
||||
NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
gchar *text;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (priv->change_frozen)
|
||||
if (editor->change_frozen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!priv->query)
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
|
||||
else
|
||||
{
|
||||
g_autofree gchar *text = NULL;
|
||||
|
||||
text = g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->entry)));
|
||||
text = g_strstrip (text);
|
||||
|
||||
nautilus_query_set_text (editor->query, text);
|
||||
}
|
||||
|
||||
nautilus_query_set_text (priv->query, text);
|
||||
nautilus_query_editor_changed (editor);
|
||||
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -459,46 +440,34 @@ nautilus_query_editor_init (NautilusQueryEditor *editor)
|
|||
editor);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
entry_key_press_event_cb (GtkWidget *widget,
|
||||
GdkEventKey *event,
|
||||
NautilusQueryEditor *editor)
|
||||
{
|
||||
if (event->keyval == GDK_KEY_Down )
|
||||
{
|
||||
gtk_widget_grab_focus (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
search_popover_date_range_changed_cb (NautilusSearchPopover *popover,
|
||||
GPtrArray *date_range,
|
||||
NautilusQueryEditor *editor)
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
|
||||
if (!priv->query)
|
||||
editor = NAUTILUS_QUERY_EDITOR (user_data);
|
||||
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
|
||||
gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
|
||||
priv->date_range_tag);
|
||||
gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (editor->entry),
|
||||
editor->date_range_tag);
|
||||
if (date_range)
|
||||
{
|
||||
g_autofree gchar *text_for_date_range = NULL;
|
||||
|
||||
text_for_date_range = get_text_for_date_range (date_range, TRUE);
|
||||
gd_tagged_entry_tag_set_label (priv->date_range_tag,
|
||||
gd_tagged_entry_tag_set_label (editor->date_range_tag,
|
||||
text_for_date_range);
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
|
||||
GD_TAGGED_ENTRY_TAG (priv->date_range_tag));
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (editor->entry),
|
||||
GD_TAGGED_ENTRY_TAG (editor->date_range_tag));
|
||||
}
|
||||
|
||||
nautilus_query_set_date_range (priv->query, date_range);
|
||||
nautilus_query_set_date_range (editor->query, date_range);
|
||||
|
||||
nautilus_query_editor_changed (editor);
|
||||
}
|
||||
|
@ -507,19 +476,20 @@ static void
|
|||
search_popover_mime_type_changed_cb (NautilusSearchPopover *popover,
|
||||
gint mimetype_group,
|
||||
const gchar *mimetype,
|
||||
NautilusQueryEditor *editor)
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
GList *mimetypes = NULL;
|
||||
NautilusQueryEditor *editor;
|
||||
g_autoptr (GList) mimetypes = NULL;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
|
||||
if (!priv->query)
|
||||
editor = NAUTILUS_QUERY_EDITOR (user_data);
|
||||
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
|
||||
gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
|
||||
priv->mime_types_tag);
|
||||
gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (editor->entry),
|
||||
editor->mime_types_tag);
|
||||
/* group 0 is anything */
|
||||
if (mimetype_group == 0)
|
||||
{
|
||||
|
@ -528,10 +498,10 @@ search_popover_mime_type_changed_cb (NautilusSearchPopover *popover,
|
|||
else if (mimetype_group > 0)
|
||||
{
|
||||
mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
|
||||
gd_tagged_entry_tag_set_label (priv->mime_types_tag,
|
||||
gd_tagged_entry_tag_set_label (editor->mime_types_tag,
|
||||
nautilus_mime_types_group_get_name (mimetype_group));
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
|
||||
GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (editor->entry),
|
||||
GD_TAGGED_ENTRY_TAG (editor->mime_types_tag));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -539,31 +509,30 @@ search_popover_mime_type_changed_cb (NautilusSearchPopover *popover,
|
|||
|
||||
mimetypes = g_list_append (NULL, (gpointer) mimetype);
|
||||
display_name = g_content_type_get_description (mimetype);
|
||||
gd_tagged_entry_tag_set_label (priv->mime_types_tag, display_name);
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
|
||||
GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
|
||||
gd_tagged_entry_tag_set_label (editor->mime_types_tag, display_name);
|
||||
gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (editor->entry),
|
||||
GD_TAGGED_ENTRY_TAG (editor->mime_types_tag));
|
||||
}
|
||||
nautilus_query_set_mime_types (priv->query, mimetypes);
|
||||
nautilus_query_set_mime_types (editor->query, mimetypes);
|
||||
|
||||
nautilus_query_editor_changed (editor);
|
||||
|
||||
g_list_free (mimetypes);
|
||||
}
|
||||
|
||||
static void
|
||||
search_popover_time_type_changed_cb (NautilusSearchPopover *popover,
|
||||
NautilusQuerySearchType data,
|
||||
NautilusQueryEditor *editor)
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
|
||||
if (!priv->query)
|
||||
editor = NAUTILUS_QUERY_EDITOR (user_data);
|
||||
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
|
||||
nautilus_query_set_search_type (priv->query, data);
|
||||
nautilus_query_set_search_type (editor->query, data);
|
||||
|
||||
nautilus_query_editor_changed (editor);
|
||||
}
|
||||
|
@ -573,19 +542,16 @@ search_popover_fts_changed_cb (GObject *popover,
|
|||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
editor = user_data;
|
||||
editor = NAUTILUS_QUERY_EDITOR (user_data);
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
|
||||
|
||||
if (!priv->query)
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
|
||||
nautilus_query_set_search_content (priv->query,
|
||||
nautilus_query_set_search_content (editor->query,
|
||||
nautilus_search_popover_get_fts_enabled (NAUTILUS_SEARCH_POPOVER (popover)));
|
||||
|
||||
nautilus_query_editor_changed (editor);
|
||||
|
@ -594,51 +560,40 @@ search_popover_fts_changed_cb (GObject *popover,
|
|||
static void
|
||||
entry_tag_clicked (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->dropdown_button),
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->dropdown_button),
|
||||
TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_query_editor_show_popover (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor));
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->dropdown_button),
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->dropdown_button),
|
||||
TRUE);
|
||||
gtk_widget_grab_focus (GTK_WIDGET (priv->popover));
|
||||
gtk_widget_grab_focus (GTK_WIDGET (editor->popover));
|
||||
}
|
||||
|
||||
static void
|
||||
entry_tag_close_button_clicked (NautilusQueryEditor *editor,
|
||||
GdTaggedEntryTag *tag)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (tag == priv->mime_types_tag)
|
||||
if (tag == editor->mime_types_tag)
|
||||
{
|
||||
nautilus_search_popover_reset_mime_types (NAUTILUS_SEARCH_POPOVER (priv->popover));
|
||||
nautilus_search_popover_reset_mime_types (NAUTILUS_SEARCH_POPOVER (editor->popover));
|
||||
}
|
||||
else
|
||||
{
|
||||
nautilus_search_popover_reset_date_range (NAUTILUS_SEARCH_POPOVER (priv->popover));
|
||||
nautilus_search_popover_reset_date_range (NAUTILUS_SEARCH_POPOVER (editor->popover));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
setup_widgets (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *vbox;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
/* vertical box that holds the search entry and the label below */
|
||||
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
||||
gtk_container_add (GTK_CONTAINER (editor), vbox);
|
||||
|
@ -649,58 +604,60 @@ setup_widgets (NautilusQueryEditor *editor)
|
|||
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
||||
|
||||
/* create the search entry */
|
||||
priv->entry = GTK_WIDGET (gd_tagged_entry_new ());
|
||||
gtk_widget_set_hexpand (priv->entry, TRUE);
|
||||
editor->entry = GTK_WIDGET (gd_tagged_entry_new ());
|
||||
gtk_widget_set_hexpand (editor->entry, TRUE);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (hbox), priv->entry);
|
||||
gtk_container_add (GTK_CONTAINER (hbox), editor->entry);
|
||||
|
||||
priv->mime_types_tag = gd_tagged_entry_tag_new (NULL);
|
||||
priv->date_range_tag = gd_tagged_entry_tag_new (NULL);
|
||||
editor->mime_types_tag = gd_tagged_entry_tag_new (NULL);
|
||||
editor->date_range_tag = gd_tagged_entry_tag_new (NULL);
|
||||
|
||||
g_signal_connect_swapped (priv->entry,
|
||||
g_signal_connect_swapped (editor->entry,
|
||||
"tag-clicked",
|
||||
G_CALLBACK (entry_tag_clicked),
|
||||
editor);
|
||||
g_signal_connect_swapped (priv->entry,
|
||||
g_signal_connect_swapped (editor->entry,
|
||||
"tag-button-clicked",
|
||||
G_CALLBACK (entry_tag_close_button_clicked),
|
||||
editor);
|
||||
|
||||
/* additional information label */
|
||||
priv->label = gtk_label_new (NULL);
|
||||
gtk_widget_set_no_show_all (priv->label, TRUE);
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (priv->label), "dim-label");
|
||||
editor->label = gtk_label_new (NULL);
|
||||
gtk_widget_set_no_show_all (editor->label, TRUE);
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (editor->label), "dim-label");
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (vbox), priv->label);
|
||||
gtk_container_add (GTK_CONTAINER (vbox), editor->label);
|
||||
|
||||
/* setup the search popover */
|
||||
priv->popover = nautilus_search_popover_new ();
|
||||
editor->popover = nautilus_search_popover_new ();
|
||||
|
||||
g_signal_connect (priv->popover, "show", (GCallback) gtk_widget_grab_focus, NULL);
|
||||
g_signal_connect_swapped (priv->popover, "closed", (GCallback) gtk_widget_grab_focus, editor);
|
||||
g_signal_connect (editor->popover, "show",
|
||||
G_CALLBACK (gtk_widget_grab_focus), NULL);
|
||||
g_signal_connect_swapped (editor->popover, "closed",
|
||||
G_CALLBACK (gtk_widget_grab_focus), editor);
|
||||
|
||||
g_object_bind_property (editor, "query",
|
||||
priv->popover, "query",
|
||||
editor->popover, "query",
|
||||
G_BINDING_DEFAULT);
|
||||
|
||||
/* setup the filter menu button */
|
||||
priv->dropdown_button = gtk_menu_button_new ();
|
||||
gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->dropdown_button), priv->popover);
|
||||
gtk_container_add (GTK_CONTAINER (hbox), priv->dropdown_button);
|
||||
editor->dropdown_button = gtk_menu_button_new ();
|
||||
gtk_menu_button_set_popover (GTK_MENU_BUTTON (editor->dropdown_button), editor->popover);
|
||||
gtk_container_add (GTK_CONTAINER (hbox), editor->dropdown_button);
|
||||
|
||||
g_signal_connect (priv->entry, "activate",
|
||||
g_signal_connect (editor->entry, "activate",
|
||||
G_CALLBACK (entry_activate_cb), editor);
|
||||
g_signal_connect (priv->entry, "search-changed",
|
||||
g_signal_connect (editor->entry, "search-changed",
|
||||
G_CALLBACK (entry_changed_cb), editor);
|
||||
g_signal_connect (priv->entry, "stop-search",
|
||||
g_signal_connect (editor->entry, "stop-search",
|
||||
G_CALLBACK (nautilus_query_editor_on_stop_search), editor);
|
||||
g_signal_connect (priv->popover, "date-range",
|
||||
g_signal_connect (editor->popover, "date-range",
|
||||
G_CALLBACK (search_popover_date_range_changed_cb), editor);
|
||||
g_signal_connect (priv->popover, "mime-type",
|
||||
g_signal_connect (editor->popover, "mime-type",
|
||||
G_CALLBACK (search_popover_mime_type_changed_cb), editor);
|
||||
g_signal_connect (priv->popover, "time-type",
|
||||
g_signal_connect (editor->popover, "time-type",
|
||||
G_CALLBACK (search_popover_time_type_changed_cb), editor);
|
||||
g_signal_connect (priv->popover, "notify::fts-enabled",
|
||||
g_signal_connect (editor->popover, "notify::fts-enabled",
|
||||
G_CALLBACK (search_popover_fts_changed_cb), editor);
|
||||
|
||||
/* show everything */
|
||||
|
@ -710,54 +667,48 @@ setup_widgets (NautilusQueryEditor *editor)
|
|||
static void
|
||||
nautilus_query_editor_changed (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (priv->change_frozen)
|
||||
if (editor->change_frozen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_signal_emit (editor, signals[CHANGED], 0, priv->query, TRUE);
|
||||
g_signal_emit (editor, signals[CHANGED], 0, editor->query, TRUE);
|
||||
}
|
||||
|
||||
NautilusQuery *
|
||||
nautilus_query_editor_get_query (NautilusQueryEditor *editor)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor), NULL);
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
|
||||
if (editor == NULL || priv->entry == NULL || priv->query == NULL)
|
||||
if (editor->entry == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return priv->query;
|
||||
return editor->query;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
nautilus_query_editor_new (void)
|
||||
{
|
||||
GtkWidget *editor;
|
||||
NautilusQueryEditor *editor;
|
||||
|
||||
editor = g_object_new (NAUTILUS_TYPE_QUERY_EDITOR, NULL);
|
||||
setup_widgets (NAUTILUS_QUERY_EDITOR (editor));
|
||||
|
||||
return editor;
|
||||
setup_widgets (editor);
|
||||
|
||||
return GTK_WIDGET (editor);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_query_editor_set_location (NautilusQueryEditor *editor,
|
||||
GFile *location)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
NautilusDirectory *directory;
|
||||
g_autoptr (NautilusDirectory) directory = NULL;
|
||||
NautilusDirectory *base_model;
|
||||
gboolean should_notify;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor));
|
||||
|
||||
/* The client could set us a location that is actually a search directory,
|
||||
* like what happens with the slot when updating the query editor location.
|
||||
|
@ -766,25 +717,23 @@ nautilus_query_editor_set_location (NautilusQueryEditor *editor,
|
|||
directory = nautilus_directory_get (location);
|
||||
if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
|
||||
{
|
||||
GFile *real_location;
|
||||
g_autoptr (GFile) real_location = NULL;
|
||||
|
||||
base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
|
||||
real_location = nautilus_directory_get_location (base_model);
|
||||
|
||||
should_notify = g_set_object (&priv->location, real_location);
|
||||
|
||||
g_object_unref (real_location);
|
||||
should_notify = g_set_object (&editor->location, real_location);
|
||||
}
|
||||
else
|
||||
{
|
||||
should_notify = g_set_object (&priv->location, location);
|
||||
should_notify = g_set_object (&editor->location, location);
|
||||
}
|
||||
|
||||
if (!priv->query)
|
||||
if (editor->query == NULL)
|
||||
{
|
||||
create_query (editor);
|
||||
}
|
||||
nautilus_query_set_location (priv->query, priv->location);
|
||||
nautilus_query_set_location (editor->query, editor->location);
|
||||
|
||||
update_information_label (editor);
|
||||
|
||||
|
@ -792,19 +741,16 @@ nautilus_query_editor_set_location (NautilusQueryEditor *editor,
|
|||
{
|
||||
g_object_notify (G_OBJECT (editor), "location");
|
||||
}
|
||||
|
||||
g_clear_object (&directory);
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_query_editor_set_query (NautilusQueryEditor *editor,
|
||||
nautilus_query_editor_set_query (NautilusQueryEditor *self,
|
||||
NautilusQuery *query)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
char *text = NULL;
|
||||
char *current_text = NULL;
|
||||
g_autofree char *text = NULL;
|
||||
g_autofree char *current_text = NULL;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (self));
|
||||
|
||||
if (query != NULL)
|
||||
{
|
||||
|
@ -816,44 +762,40 @@ nautilus_query_editor_set_query (NautilusQueryEditor *editor,
|
|||
text = g_strdup ("");
|
||||
}
|
||||
|
||||
priv->change_frozen = TRUE;
|
||||
self->change_frozen = TRUE;
|
||||
|
||||
current_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
|
||||
current_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry)));
|
||||
current_text = g_strstrip (current_text);
|
||||
if (!g_str_equal (current_text, text))
|
||||
{
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
|
||||
gtk_entry_set_text (GTK_ENTRY (self->entry), text);
|
||||
}
|
||||
g_free (current_text);
|
||||
|
||||
if (g_set_object (&priv->query, query))
|
||||
if (g_set_object (&self->query, query))
|
||||
{
|
||||
g_object_notify (G_OBJECT (editor), "query");
|
||||
g_object_notify (G_OBJECT (self), "query");
|
||||
}
|
||||
|
||||
priv->change_frozen = FALSE;
|
||||
|
||||
g_free (text);
|
||||
self->change_frozen = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_query_editor_set_text (NautilusQueryEditor *editor,
|
||||
nautilus_query_editor_set_text (NautilusQueryEditor *self,
|
||||
const gchar *text)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (editor);
|
||||
g_return_if_fail (NAUTILUS_IS_QUERY_EDITOR (self));
|
||||
g_return_if_fail (text != NULL);
|
||||
|
||||
/* The handler of the entry will take care of everything */
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
|
||||
gtk_entry_set_text (GTK_ENTRY (self->entry), text);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_query_editor_handle_event (NautilusQueryEditor *self,
|
||||
GdkEvent *event)
|
||||
{
|
||||
NautilusQueryEditorPrivate *priv;
|
||||
g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (self), GDK_EVENT_PROPAGATE);
|
||||
g_return_val_if_fail (event != NULL, GDK_EVENT_PROPAGATE);
|
||||
|
||||
priv = nautilus_query_editor_get_instance_private (self);
|
||||
|
||||
return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (priv->entry), event);
|
||||
return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (self->entry), event);
|
||||
}
|
||||
|
|
|
@ -27,18 +27,7 @@
|
|||
|
||||
#define NAUTILUS_TYPE_QUERY_EDITOR nautilus_query_editor_get_type()
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (NautilusQueryEditor, nautilus_query_editor, NAUTILUS, QUERY_EDITOR, GtkBox)
|
||||
|
||||
struct _NautilusQueryEditorClass
|
||||
{
|
||||
GtkBoxClass parent_class;
|
||||
|
||||
void (* changed) (NautilusQueryEditor *editor,
|
||||
NautilusQuery *query,
|
||||
gboolean reload);
|
||||
void (* cancel) (NautilusQueryEditor *editor);
|
||||
void (* activated) (NautilusQueryEditor *editor);
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE (NautilusQueryEditor, nautilus_query_editor, NAUTILUS, QUERY_EDITOR, GtkBox)
|
||||
|
||||
GtkWidget *nautilus_query_editor_new (void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue