Skip to content

Commit 4879826

Browse files
committed
add filechooser drop
1 parent 3a8ab5c commit 4879826

File tree

4 files changed

+99
-8
lines changed

4 files changed

+99
-8
lines changed

TODO

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,33 @@
22

33
try joanne's workspace ... need to be able to reset the image pair
44

5-
and editing a row doesn't always "take"
5+
rowview_reset_menu() just runs model_clear_edited() on every sub-row
6+
7+
in turn runs heapmodel_clear_edited()
8+
9+
image replace from file usually won't reset properly since it rewrites the
10+
formula and there's nothing to reset
11+
12+
- could use file chooser widget in bm-workspaces, what would it look like?
13+
14+
- ^V in an imagewindow swaps the image without rewriting the formula, could
15+
we do something like that for replace from file?
16+
17+
no, the result wouldn't be saved
18+
19+
- try
20+
21+
nip4 ~/lady-orig.ws
22+
23+
open A2, find A2.targets.image, right-click, replace from file, no file
24+
dialog appears
25+
26+
what stops replace from file on a dirty row?
27+
28+
- try a win build again now we have some fixes for font stuff
29+
30+
31+
632

733
- check all batch mode flags
834

src/heapmodel.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ heapmodel_real_update_heap(Heapmodel *heapmodel)
174174
static void *
175175
heapmodel_real_clear_edited(Heapmodel *heapmodel)
176176
{
177+
#ifdef DEBUG
178+
#endif /*DEBUG*/
179+
{
180+
HeapmodelClass *heapmodel_class = HEAPMODEL_GET_CLASS(heapmodel);
181+
182+
printf("heapmodel_real_clear_edited: %s::",
183+
G_OBJECT_CLASS_NAME(heapmodel_class));
184+
row_name_print(heapmodel->row);
185+
printf("\n");
186+
}
187+
177188
return NULL;
178189
}
179190

src/imagewindow.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,6 @@ imagewindow_paste_filename(const char *filename, void *user_data)
804804
{
805805
Imagewindow *win = IMAGEWINDOW(user_data);
806806

807-
printf("imagewindow_paste_filename:\n");
808-
809807
imagewindow_files_set(win, &filename, 1);
810808
imagewindow_open_current_file(win, GTK_STACK_TRANSITION_TYPE_ROTATE_LEFT);
811809

@@ -1272,8 +1270,6 @@ imagewindow_dnd_drop(GtkDropTarget *target,
12721270
{
12731271
Imagewindow *win = IMAGEWINDOW(user_data);
12741272

1275-
printf("imagewindow_dnd_drop: %g x %g\n", x, y);
1276-
12771273
return value_to_filename(value, imagewindow_paste_filename, win);
12781274
}
12791275

src/pathnameview.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* run the display for an arrow in a workspace
1+
/* run the display for a file chooser in a workspace
22
*/
33

44
/*
@@ -35,6 +35,18 @@
3535

3636
G_DEFINE_TYPE(Pathnameview, pathnameview, GRAPHICVIEW_TYPE)
3737

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+
3850
static void
3951
pathnameview_dispose(GObject *object)
4052
{
@@ -66,7 +78,7 @@ static void
6678
pathnameview_refresh(vObject *vobject)
6779
{
6880
Pathnameview *pathnameview = PATHNAMEVIEW(vobject);
69-
Pathname *pathname = PATHNAME(VOBJECT(vobject)->iobject);
81+
Pathname *pathname = PATHNAME(VOBJECT(pathnameview)->iobject);
7082

7183
#ifdef DEBUG
7284
printf("pathnameview_refresh: ");
@@ -115,7 +127,10 @@ pathnameview_clicked(GtkWidget *widget, Pathnameview *pathnameview)
115127
gtk_file_dialog_set_modal(dialog, TRUE);
116128

117129
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);
119134
gtk_file_dialog_set_initial_file(dialog, file);
120135
}
121136
else {
@@ -149,12 +164,55 @@ pathnameview_class_init(PathnameviewClass *class)
149164
vobject_class->refresh = pathnameview_refresh;
150165

151166
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);
152201
}
153202

154203
static void
155204
pathnameview_init(Pathnameview *pathnameview)
156205
{
157206
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);
158216
}
159217

160218
View *

0 commit comments

Comments
 (0)