filechooser.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_GTKUTIL_FILECHOOSER_H)
00023 #define INCLUDED_GTKUTIL_FILECHOOSER_H
00024 
00025 #include <string>
00026 #include "radiant_i18n.h"
00027 
00030 
00031 typedef struct _GtkWidget GtkWidget;
00032 const char* file_dialog (GtkWidget *parent, bool open, const std::string& title, const std::string& path = "",
00033         const std::string& pattern = "");
00034 
00035 namespace gtkutil
00036 {
00037 
00038     class FileChooser
00039     {
00040         public:
00049             class Preview
00050             {
00051                 public:
00052                     // Retrieve the preview widget for packing into the dialog
00053                     virtual GtkWidget* getPreviewWidget () = 0;
00054 
00060                     virtual void onFileSelectionChanged (const std::string& newFileName, FileChooser& fileChooser) = 0;
00061             };
00062 
00063         private:
00064             // Parent widget
00065             GtkWidget* _parent;
00066 
00067             GtkWidget* _dialog;
00068 
00069             // Window title
00070             std::string _title;
00071 
00072             std::string _path;
00073             std::string _file;
00074 
00075             std::string _pattern;
00076 
00077             std::string _defaultExt;
00078 
00079             // Open or save dialog
00080             bool _open;
00081 
00082             // The optional preview object
00083             Preview* _preview;
00084 
00085         public:
00097             FileChooser (GtkWidget* parent, const std::string& title, bool open, bool browseFolders,
00098                     const std::string& pattern = "", const std::string& defaultExt = "");
00099 
00100             virtual ~FileChooser ();
00101 
00102             // Lets the dialog start at a certain path
00103             void setCurrentPath (const std::string& path);
00104 
00105             // Pre-fills the currently selected file
00106             void setCurrentFile (const std::string& file);
00107 
00113             void attachPreview (Preview* preview);
00114 
00119             virtual std::string getSelectedFileName ();
00120 
00127             virtual std::string display ();
00128 
00129             // Public function for Preview objects. These must set the "active" state
00130             // of the preview when the onFileSelectionChange() signal is emitted.
00131             void setPreviewActive (bool active);
00132 
00133         private:
00134             // GTK callback for updating the preview widget
00135             static void onUpdatePreview (GtkFileChooser* chooser, FileChooser* self);
00136     };
00137 
00138 } // namespace gtkutil
00139 
00140 
00141 #endif

Generated by  doxygen 1.6.2