On 10/25/2017 12:43 AM, rbd wrote:
> 
> 
> Hi all,
> 
> I have done some further experimentation with regard to my 
> GtkFileChooser problem and discovered that the piece of my code that 
> seems to be triggering this problem is the call to 
> gtk_file_chooser_set_current_name() -- if I remove that then I do not 
> get the error described in my last message.
> 
> Looking closer at the documentation I see a statement that says this 
> function should not be used when an existing file is being specified, so 
> I will take responsibility for ignoring that warning. I have to say, 
> however, that this seems to me to be an unacceptable restriction -- why 
> shouldn't I be able to initialize the text entry field at the top of the 
> dialog to a completely clear and unambiguous presentation of the default 
> name that will be returned by the dialog? And, why does a 
> GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER dialog which is supposedly 
> designed to work with either pre-existing or yet-to-be-created 
> filesystem objects (i) try to create something that already exists and 
> then (ii) complain when that creation attempt fails, whether or not I 
> call gtk_file_chooser_set_current_name() to set the text entry field?
> 
> I have noticed other inconsistent and weird behavior in the UI of this 
> widget through my further experimentation today:
> 
> (1) When I do use gtk_file_chooser_set_current_name() to initialize the 
> text entry field as shown in my original code, when I click the dialog's 
> OK response button I get the error I have described. But if instead of 
> clicking that button I activate the cursor in the text entry field and 
> hit RETURN (without making any change to that field), everything works 
> fine. Why is only clicking the OK button problematic?
> 
> (2) Independently of whether or not I use 
> gtk_file_chooser_set_current_name() to initialize the text entry field 
> to the name of a pre-existing current working directory (CWD), I have 
> noticed that the OK response button will often be grayed out (and hence 
> unclickable) even when the final path component of that CWD is selected 
> in the dialog's large directory contents subwindow when the dialog is 
> first mapped. Often I can fix this only by clicking on different 
> directory contents subwindow objects (i.e., other subdirectories), 
> perhaps several times, and then re-clicking on the subdirectory object 
> which corresponds to my CWD (and which was originally selected). Only 
> then does the OK response button get activated and become clickable.
> 
> I can appreciate that this widget may require a complicated 
> implementation, and that in particular it may be difficult to properly 
> correlate the text entry field with the directory contents subwindow. I 
> have to say, however, that I think it would be worthwhile to get rid of 
> the confusing limitations and behaviors noted above.
> 
> If there is further documentation on these issues somewhere that would 
> help me to understand and avoid them better I would very much like to 
> see it.
> 
> Thanks!
> 
> Roger Davis
> Univ. of Hawaii
> 

Hi,
i recall having struggled with a file chooser some years ago,
but after some iterations got something that worked for me
for simple file operations. It was however impossible at that
time to tell the file chooser to open a file OR a dir so i ended
reinventing the wheel and wrote my own file chooser widget
( if you are interested in that drop a mail, but it is a lot 
of code, some 1000+ lines).
Nonetheless attached inline you will find a copy of what did
work for me in the hope that it helps you. This is for gtk 2.0 tough
and maybe needs some adaptations.

Ciao,
Tito

/*
*
* Gtk+2.x  Utility routines: File selection widget.
* Copyright (C) 2002-2009 by <tito-wo...@tiscali.it>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Please read the COPYING and README file!!!
*
* Report bugs to <tito-wo...@tiscali.it>
*
*/

/*#################################### File Selection Widget 
#####################################################*/

#include <stdio.h>
#include <gtk/gtk.h>
#include "mylib.h"
#include "mygtk.h"

/*
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
*/

char *file_chooser(const char *title, GtkFileChooserAction fs_action, gboolean 
local_only, gboolean show_hidden, 
                                        const char *name, const char *folder, 
const char *shortcut_folder)
{
        GtkWidget *dialog;
        char *tmp;
        char *filename = NULL;;

        tmp = g_locale_to_utf8((title) ? title : "", -1,NULL,NULL,NULL);

        dialog = gtk_file_chooser_dialog_new (tmp,
                                                NULL, /*parent_window*/
                                                fs_action,
                                                GTK_STOCK_CANCEL, 
GTK_RESPONSE_CANCEL,
                                                GTK_STOCK_OPEN, 
GTK_RESPONSE_ACCEPT,
                                                NULL);
        XFREE(tmp);
        gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), local_only);
        gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), show_hidden);
        /* Returns a GsList *, not a char * */
        /*gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), 
select_multiple);*/

        if (name) {
                tmp = g_locale_to_utf8((name), -1, NULL, NULL, NULL);
                gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), 
tmp);
                XFREE(tmp);     
        }
        
        if (folder) {
                tmp = g_locale_to_utf8((folder), -1, NULL, NULL, NULL);
                gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), 
tmp);
                XFREE(tmp);
        }

        if (shortcut_folder) {
                tmp = g_locale_to_utf8((shortcut_folder), -1, NULL, NULL, NULL);
                gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), 
tmp, NULL);
                XFREE(tmp);
        }

        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
                filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER 
(dialog));
        }
        if (G_IS_OBJECT (dialog)) {
                gtk_widget_destroy (dialog);
        }
        return filename;
}

char *default_file_chooser(const char *title, GtkFileChooserAction fs_action)
{
        return file_chooser(title, fs_action, FALSE, TRUE, NULL, NULL, NULL);
}

/*############################### End of File Selection Widget 
#####################################################*/
  
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to