Avoid warnings about not checking chdir() result in wxGTK.

Give error if changing directory when wxFD_CHANGE_DIR or wxDIRP_CHANGE_DIR
flags are used, this is a good idea generally speaking and it also avoids
warnings about not checking chdir() return value that we got under Ubuntu.

This is the backport of 3f6741a770 from master
with the changes of cb06ecb9eb and
de27f4b08f too.
This commit is contained in:
Vadim Zeitlin
2015-02-12 21:56:32 +00:00
parent feef92f3e2
commit 84f6686e39
2 changed files with 17 additions and 2 deletions

View File

@@ -15,6 +15,7 @@
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/msgdlg.h"
#endif
@@ -81,7 +82,11 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog)
{
// Use chdir to not care about filename encodings
wxGtkString folder(g_path_get_dirname(filename));
chdir(folder);
if ( chdir(folder) != 0 )
{
wxLogSysError(_("Changing current directory to \"%s\" failed"),
wxString::FromUTF8(folder));
}
}
wxCommandEvent event(wxEVT_BUTTON, wxID_OK);

View File

@@ -18,6 +18,10 @@
#if wxUSE_FILEPICKERCTRL
#ifndef WX_PRECOMP
#include "wx/log.h"
#endif
#include "wx/filepicker.h"
#include "wx/tooltip.h"
@@ -180,7 +184,13 @@ static void file_set(GtkFileChooser* widget, wxDirButton* p)
// thus we need to make sure the current working directory is updated if wxDIRP_CHANGE_DIR
// style was given.
if (p->HasFlag(wxDIRP_CHANGE_DIR))
chdir(filename);
{
if ( chdir(filename) != 0 )
{
wxLogSysError(_("Changing current directory to \"%s\" failed"),
wxString::FromUTF8(filename));
}
}
// ...and fire an event
wxFileDirPickerEvent event(wxEVT_DIRPICKER_CHANGED, p, p->GetId(), p->GetPath());