|
1 | | -/* run the display for an arrow in a workspace |
| 1 | +/* run the display for a file chooser in a workspace |
2 | 2 | */ |
3 | 3 |
|
4 | 4 | /* |
|
35 | 35 |
|
36 | 36 | G_DEFINE_TYPE(Pathnameview, pathnameview, GRAPHICVIEW_TYPE) |
37 | 37 |
|
| 38 | +/* GTypes we handle in copy/paste and drag/drop paste ... these are in the |
| 39 | + * order we try, so a GFile is preferred to a simple string. |
| 40 | + * |
| 41 | + * gnome file manager pastes as GdkFileList, GFile, gchararray |
| 42 | + * print-screen button pastes as GdkTexture, GdkPixbuf |
| 43 | + * |
| 44 | + * Created in _class_init(), since some of these types are only defined at |
| 45 | + * runtime. |
| 46 | + */ |
| 47 | +static GType *pathnameview_supported_types; |
| 48 | +static int pathnameview_n_supported_types; |
| 49 | + |
38 | 50 | static void |
39 | 51 | pathnameview_dispose(GObject *object) |
40 | 52 | { |
@@ -66,7 +78,7 @@ static void |
66 | 78 | pathnameview_refresh(vObject *vobject) |
67 | 79 | { |
68 | 80 | Pathnameview *pathnameview = PATHNAMEVIEW(vobject); |
69 | | - Pathname *pathname = PATHNAME(VOBJECT(vobject)->iobject); |
| 81 | + Pathname *pathname = PATHNAME(VOBJECT(pathnameview)->iobject); |
70 | 82 |
|
71 | 83 | #ifdef DEBUG |
72 | 84 | printf("pathnameview_refresh: "); |
@@ -115,7 +127,10 @@ pathnameview_clicked(GtkWidget *widget, Pathnameview *pathnameview) |
115 | 127 | gtk_file_dialog_set_modal(dialog, TRUE); |
116 | 128 |
|
117 | 129 | if (pathname->value) { |
118 | | - g_autoptr(GFile) file = g_file_new_for_path(pathname->value); |
| 130 | + char name[VIPS_PATH_MAX]; |
| 131 | + |
| 132 | + expand_variables(pathname->value, name); |
| 133 | + g_autoptr(GFile) file = g_file_new_for_path(name); |
119 | 134 | gtk_file_dialog_set_initial_file(dialog, file); |
120 | 135 | } |
121 | 136 | else { |
@@ -149,12 +164,55 @@ pathnameview_class_init(PathnameviewClass *class) |
149 | 164 | vobject_class->refresh = pathnameview_refresh; |
150 | 165 |
|
151 | 166 | view_class->link = pathnameview_link; |
| 167 | + |
| 168 | + // the gtypes we support ... anything we can turn into a path |
| 169 | + GType supported_types[] = { |
| 170 | + G_TYPE_FILE, |
| 171 | + G_TYPE_STRING, |
| 172 | + }; |
| 173 | + |
| 174 | + pathnameview_n_supported_types = VIPS_NUMBER(supported_types); |
| 175 | + pathnameview_supported_types = |
| 176 | + VIPS_ARRAY(NULL, pathnameview_n_supported_types + 1, GType); |
| 177 | + for (int i = 0; i < pathnameview_n_supported_types; i++) |
| 178 | + pathnameview_supported_types[i] = supported_types[i]; |
| 179 | +} |
| 180 | + |
| 181 | +static gboolean |
| 182 | +pathnameview_paste_filename(const char *filename, void *user_data) |
| 183 | +{ |
| 184 | + Pathnameview *pathnameview = PATHNAMEVIEW(user_data); |
| 185 | + Pathname *pathname = PATHNAME(VOBJECT(pathnameview)->iobject); |
| 186 | + |
| 187 | + VIPS_SETSTR(pathname->value, filename); |
| 188 | + classmodel_update_view(CLASSMODEL(pathname)); |
| 189 | + symbol_recalculate_all(); |
| 190 | + |
| 191 | + return TRUE; |
| 192 | +} |
| 193 | + |
| 194 | +static gboolean |
| 195 | +pathnameview_dnd_drop(GtkDropTarget *target, |
| 196 | + const GValue *value, double x, double y, gpointer user_data) |
| 197 | +{ |
| 198 | + Pathnameview *pathnameview = PATHNAMEVIEW(user_data); |
| 199 | + |
| 200 | + return value_to_filename(value, pathnameview_paste_filename, pathnameview); |
152 | 201 | } |
153 | 202 |
|
154 | 203 | static void |
155 | 204 | pathnameview_init(Pathnameview *pathnameview) |
156 | 205 | { |
157 | 206 | gtk_widget_init_template(GTK_WIDGET(pathnameview)); |
| 207 | + |
| 208 | + GtkEventController *controller = GTK_EVENT_CONTROLLER( |
| 209 | + gtk_drop_target_new(G_TYPE_INVALID, GDK_ACTION_COPY)); |
| 210 | + gtk_drop_target_set_gtypes(GTK_DROP_TARGET(controller), |
| 211 | + pathnameview_supported_types, |
| 212 | + pathnameview_n_supported_types); |
| 213 | + g_signal_connect(controller, "drop", |
| 214 | + G_CALLBACK(pathnameview_dnd_drop), pathnameview); |
| 215 | + gtk_widget_add_controller(GTK_WIDGET(pathnameview), controller); |
158 | 216 | } |
159 | 217 |
|
160 | 218 | View * |
|
0 commit comments