]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dirdlg.cpp
Fix wxHtmlHelpData::SetTempDir() to behave correctly without trailing slash.
[wxWidgets.git] / src / gtk / dirdlg.cpp
CommitLineData
b50747ea
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/dirdlg.cpp
ff3e84ff 3// Purpose: native implementation of wxDirDialog
b50747ea 4// Author: Robert Roebling, Zbigniew Zagorski, Mart Raudsepp, Francesco Montorsi
b50747ea
RR
5// Copyright: (c) 1998 Robert Roebling, 2004 Zbigniew Zagorski, 2005 Mart Raudsepp
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
11
12
13
14/*
ff3e84ff 15 NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialog.
b50747ea
RR
16 Thus following code is very similar (even if not identic) to src/gtk/filedlg.cpp
17 If you find a problem in this code, remember to check also that file !
18*/
19
20
21
ff654490 22#if wxUSE_DIRDLG
b50747ea
RR
23
24#include "wx/dirdlg.h"
25
26#ifndef WX_PRECOMP
27 #include "wx/intl.h"
2f79f291 28 #include "wx/filedlg.h"
b50747ea
RR
29#endif
30
b50747ea
RR
31#include "wx/gtk/private.h"
32
b50747ea 33extern "C" {
5a7c1881 34static void gtk_dirdialog_response_callback(GtkWidget * WXUNUSED(w),
b50747ea 35 gint response,
ff3e84ff 36 wxDirDialog *dialog)
b50747ea 37{
b50747ea 38 if (response == GTK_RESPONSE_ACCEPT)
5a7c1881 39 dialog->GTKOnAccept();
a552d120 40 else // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
5a7c1881 41 dialog->GTKOnCancel();
b50747ea
RR
42}
43}
44
b50747ea 45//-----------------------------------------------------------------------------
ff3e84ff 46// wxDirDialog
b50747ea
RR
47//-----------------------------------------------------------------------------
48
ff654490 49IMPLEMENT_DYNAMIC_CLASS(wxDirDialog, wxDialog)
b50747ea 50
ff654490
VZ
51wxDirDialog::wxDirDialog(wxWindow* parent,
52 const wxString& title,
53 const wxString& defaultPath,
54 long style,
55 const wxPoint& pos,
56 const wxSize& WXUNUSED(sz),
57 const wxString& WXUNUSED(name))
e3f54c8f
VZ
58{
59 Create(parent, title, defaultPath, style, pos);
60}
61
62bool wxDirDialog::Create(wxWindow* parent,
63 const wxString& title,
64 const wxString& defaultPath,
65 long style,
66 const wxPoint& pos,
67 const wxSize& WXUNUSED(sz),
68 const wxString& WXUNUSED(name))
b50747ea 69{
ff654490
VZ
70 m_message = title;
71
cdc48273 72 parent = GetParentForModalDialog(parent, style);
ff654490
VZ
73
74 if (!PreCreation(parent, pos, wxDefaultSize) ||
75 !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
76 wxDefaultValidator, wxT("dirdialog")))
b50747ea 77 {
ff654490 78 wxFAIL_MSG( wxT("wxDirDialog creation failed") );
e3f54c8f 79 return false;
b50747ea 80 }
b50747ea 81
ff654490
VZ
82 GtkWindow* gtk_parent = NULL;
83 if (parent)
84 gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
85
86 m_widget = gtk_file_chooser_dialog_new(
87 wxGTK_CONV(m_message),
88 gtk_parent,
89 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
90 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
91 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
92 NULL);
9ff9d30c 93 g_object_ref(m_widget);
ff654490
VZ
94
95 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
96
97 // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically destroys
98 // the dialog when the user press ESC on the dialog: in that case a second call to
99 // ShowModal() would result in a bunch of Gtk-CRITICAL errors...
84f623f8 100 g_signal_connect (m_widget,
ff654490
VZ
101 "delete_event",
102 G_CALLBACK (gtk_widget_hide_on_delete),
103 (gpointer)this);
104
105 // local-only property could be set to false to allow non-local files to be loaded.
106 // In that case get/set_uri(s) should be used instead of get/set_filename(s) everywhere
107 // and the GtkFileChooserDialog should probably also be created with a backend,
d13b34d3 108 // e.g. "gnome-vfs", "default", ... (gtk_file_chooser_dialog_new_with_backend).
ff654490
VZ
109 // Currently local-only is kept as the default - true:
110 // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true);
111
112 g_signal_connect (m_widget, "response",
113 G_CALLBACK (gtk_dirdialog_response_callback), this);
114
115 if ( !defaultPath.empty() )
5a7c1881 116 SetPath(defaultPath);
c282e47d 117
e3f54c8f 118 return true;
b50747ea
RR
119}
120
5a7c1881 121void wxDirDialog::GTKOnAccept()
b50747ea 122{
5a7c1881
VZ
123 wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
124 m_selectedDirectory = wxString::FromUTF8(str);
125
126 // change to the directory where the user went if asked
127 if (HasFlag(wxDD_CHANGE_DIR))
128 {
7c211441 129 wxSetWorkingDirectory(m_selectedDirectory);
5a7c1881
VZ
130 }
131
ff654490 132 EndDialog(wxID_OK);
b50747ea
RR
133}
134
5a7c1881
VZ
135void wxDirDialog::GTKOnCancel()
136{
137 EndDialog(wxID_CANCEL);
138}
139
ff3e84ff 140void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
b50747ea
RR
141{
142 if (!m_wxwindow)
143 return;
ff654490
VZ
144
145 wxDirDialogBase::DoSetSize( x, y, width, height, sizeFlags );
b50747ea
RR
146}
147
ff3e84ff 148void wxDirDialog::SetPath(const wxString& dir)
b50747ea 149{
ff654490 150 if (wxDirExists(dir))
b50747ea 151 {
ff654490 152 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
c282e47d 153 wxGTK_CONV_FN(dir));
b50747ea 154 }
b50747ea
RR
155}
156
ff3e84ff 157wxString wxDirDialog::GetPath() const
b50747ea 158{
5a7c1881 159 return m_selectedDirectory;
b50747ea
RR
160}
161
162#endif // wxUSE_DIRDLG