From e66b1a594a1fd8c551bf1fb1cbd047301d341552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sat, 24 Jun 2017 23:49:07 +0200 Subject: [PATCH] file-picker.linux: fixing open-file-dialog and save-file-dialog I had to use utf8 string>alien over utf8 encode because the latter doesnt null-terminate the string. --- extra/file-picker/linux/linux.factor | 40 +++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/extra/file-picker/linux/linux.factor b/extra/file-picker/linux/linux.factor index 9e7ff65ec4..66db140e52 100644 --- a/extra/file-picker/linux/linux.factor +++ b/extra/file-picker/linux/linux.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2014, 2015 John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types alien.data alien.strings alien.syntax -destructors file-picker gobject-introspection.standard-types -gtk.ffi io.encodings.string io.encodings.utf8 kernel system ; +USING: accessors alien.c-types alien.strings alien.syntax destructors +file-picker gobject-introspection.standard-types gtk.ffi +io.encodings.utf8 kernel locals namespaces system ui.gadgets.worlds ; IN: file-picker.linux ( title action -- dialog ) - [ - utf8 encode - f - GTK_FILE_CHOOSER_ACTION_OPEN - "Cancel" utf8 encode - GTK_RESPONSE_CANCEL gint - ] [ - utf8 encode - GTK_RESPONSE_ACCEPT gint - f - gtk_file_chooser_dialog_new - >k_widget_destroy - ] bi* ; +:: ( title action -- dialog ) + title utf8 string>alien + ! Current active window becomes the parent + world get handle>> window>> + GTK_FILE_CHOOSER_ACTION_OPEN + "Cancel" utf8 string>alien + GTK_RESPONSE_CANCEL + action utf8 string>alien + GTK_RESPONSE_ACCEPT + f + gtk_file_chooser_dialog_new >k_widget_destroy ; + : run-and-get-filename ( dialog -- path/f ) dup gtk_dialog_run GTK_RESPONSE_ACCEPT = [ - gtk_file_chooser_get_filename alien>native-string + gtk_file_chooser_get_filename utf8 alien>string ] [ drop f ] if ; @@ -53,6 +51,6 @@ M: linux save-file-dialog [ "Save File" "Save" dup t gtk_file_chooser_set_do_overwrite_confirmation - dup rot gtk_file_chooser_set_filename drop + dup rot utf8 string>alien gtk_file_chooser_set_filename drop run-and-get-filename ] with-destructors ;