Mercurial > geeqie.yaz
comparison src/ui_pathsel.c @ 719:ab4162fa9209
dest_change_dir(): rewrite to use g_build_filename(), g_path_get_dirname() and g_path_get_basename().
author | zas_ |
---|---|
date | Wed, 21 May 2008 09:30:53 +0000 |
parents | aae956e84de4 |
children | eda074e91ddd |
comparison
equal
deleted
inserted
replaced
718:7119e30971ec | 719:ab4162fa9209 |
---|---|
272 dd->path = g_strdup(path); | 272 dd->path = g_strdup(path); |
273 } | 273 } |
274 | 274 |
275 static void dest_change_dir(Dest_Data *dd, const gchar *path, gint retain_name) | 275 static void dest_change_dir(Dest_Data *dd, const gchar *path, gint retain_name) |
276 { | 276 { |
277 gchar *old_name = NULL; | 277 const gchar *old_name = NULL; |
278 gint s = 0; | 278 gchar *full_path; |
279 gchar *new_directory; | |
279 | 280 |
280 if (retain_name) | 281 if (retain_name) |
281 { | 282 { |
282 const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry)); | 283 const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry)); |
283 if (!isdir(buf)) | 284 |
284 { | 285 if (!isdir(buf)) old_name = filename_from_path(buf); |
285 if (path && strcmp(path, "/") == 0) | 286 } |
286 { | 287 |
287 old_name = g_strdup(filename_from_path(buf)); | 288 full_path = g_build_filename(path, old_name, NULL); |
288 } | |
289 else | |
290 { | |
291 old_name = g_strconcat("/", filename_from_path(buf), NULL); | |
292 s = 1; | |
293 } | |
294 } | |
295 } | |
296 | |
297 gtk_entry_set_text(GTK_ENTRY(dd->entry), path); | |
298 | |
299 dest_populate(dd, path); | |
300 | |
301 /* remember filename */ | |
302 if (old_name) | 289 if (old_name) |
303 { | 290 new_directory = g_path_get_dirname(full_path); |
304 gint pos = -1; | 291 else |
305 gtk_editable_insert_text(GTK_EDITABLE(dd->entry), old_name, -1, &pos); | 292 new_directory = g_strdup(full_path); |
306 gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(path) + s, strlen(path) + strlen(old_name)); | 293 |
307 g_free(old_name); | 294 gtk_entry_set_text(GTK_ENTRY(dd->entry), full_path); |
308 } | 295 |
296 dest_populate(dd, new_directory); | |
297 g_free(new_directory); | |
298 | |
299 if (old_name) | |
300 { | |
301 gchar *basename = g_path_get_basename(full_path); | |
302 | |
303 gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(full_path) - strlen(basename), strlen(full_path)); | |
304 g_free(basename); | |
305 } | |
306 | |
307 g_free(full_path); | |
309 } | 308 } |
310 | 309 |
311 /* | 310 /* |
312 *----------------------------------------------------------------------------- | 311 *----------------------------------------------------------------------------- |
313 * drag and drop | 312 * drag and drop |