1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright (C) 2023 The GNOME project contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <glib/gi18n.h>
#include "nautilus-new-folder-dialog.h"
#include "nautilus-filename-validator.h"
struct _NautilusNewFolderDialog
{
AdwDialog parent_instance;
NautilusFilenameValidator *validator;
GtkWidget *name_entry;
gboolean with_selection;
NewFolderCallback callback;
gpointer callback_data;
};
G_DEFINE_FINAL_TYPE (NautilusNewFolderDialog, nautilus_new_folder_dialog, ADW_TYPE_DIALOG)
static void
on_feedback_changed (NautilusNewFolderDialog *self)
{
if (nautilus_filename_validator_get_has_feedback (self->validator))
{
gtk_widget_add_css_class (self->name_entry, "warning");
}
else
{
gtk_widget_remove_css_class (self->name_entry, "warning");
}
}
static void
on_name_accepted (NautilusNewFolderDialog *self)
{
g_autofree char *name = nautilus_filename_validator_get_new_name (self->validator);
self->callback (name, self->with_selection, self->callback_data);
adw_dialog_close (ADW_DIALOG (self));
}
NautilusNewFolderDialog *
nautilus_new_folder_dialog_new (GtkWidget *parent,
NautilusDirectory *destination_directory,
gboolean with_selection,
gchar *initial_name,
NewFolderCallback callback,
gpointer callback_data)
{
NautilusNewFolderDialog *self = g_object_new (NAUTILUS_TYPE_NEW_FOLDER_DIALOG,
NULL);
nautilus_filename_validator_set_containing_directory (self->validator,
destination_directory);
self->with_selection = with_selection;
self->callback = callback;
self->callback_data = callback_data;
if (initial_name != NULL)
{
gtk_editable_set_text (GTK_EDITABLE (self->name_entry), initial_name);
}
adw_dialog_present (ADW_DIALOG (self), parent);
return self;
}
static void
nautilus_new_folder_dialog_init (NautilusNewFolderDialog *self)
{
g_type_ensure (NAUTILUS_TYPE_FILENAME_VALIDATOR);
gtk_widget_init_template (GTK_WIDGET (self));
}
static void
nautilus_new_folder_dialog_dispose (GObject *object)
{
gtk_widget_dispose_template (GTK_WIDGET (object), NAUTILUS_TYPE_NEW_FOLDER_DIALOG);
G_OBJECT_CLASS (nautilus_new_folder_dialog_parent_class)->dispose (object);
}
static void
nautilus_new_folder_dialog_finalize (GObject *object)
{
G_OBJECT_CLASS (nautilus_new_folder_dialog_parent_class)->finalize (object);
}
static void
nautilus_new_folder_dialog_class_init (NautilusNewFolderDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = nautilus_new_folder_dialog_dispose;
object_class->finalize = nautilus_new_folder_dialog_finalize;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/nautilus/ui/nautilus-new-folder-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, NautilusNewFolderDialog, name_entry);
gtk_widget_class_bind_template_child (widget_class, NautilusNewFolderDialog, validator);
gtk_widget_class_bind_template_callback (widget_class, on_feedback_changed);
gtk_widget_class_bind_template_callback (widget_class, on_name_accepted);
gtk_widget_class_bind_template_callback (widget_class, nautilus_filename_validator_try_accept);
gtk_widget_class_bind_template_callback (widget_class, nautilus_filename_validator_validate);
}
|