]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/gtkutil/filechooser.cpp
-DGTK_DISABLE_SINGLE_INCLUDES
[xonotic/netradiant.git] / libs / gtkutil / filechooser.cpp
index d65d310ca567dc3eac3d47da95ccb6b946f37b56..177e752eee7a9fb31d6d0d8ef774d7ae14aebaa6 100644 (file)
 
 #include <list>
 #include <vector>
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtkfilechooser.h>
-#include <gtk/gtkfilechooserdialog.h>
-#include <gtk/gtkstock.h>
+#include <gtk/gtk.h>
+#include <uilib/uilib.h>
 
 #include "string/string.h"
 #include "stream/stringstream.h"
@@ -59,9 +56,9 @@ struct filetype_copy_t
        filetype_copy_t( const filetype_pair_t& other )
                : m_moduleName( other.m_moduleName ), m_name( other.m_type.name ), m_pattern( other.m_type.pattern ){
        }
-       CopiedString m_moduleName;
-       CopiedString m_name;
-       CopiedString m_pattern;
+       std::string m_moduleName;
+       std::string m_name;
+       std::string m_pattern;
 };
 
 typedef std::list<filetype_copy_t> Types;
@@ -90,8 +87,8 @@ class GTKMasks
 {
 const FileTypeList& m_types;
 public:
-std::vector<CopiedString> m_filters;
-std::vector<CopiedString> m_masks;
+std::vector<std::string> m_filters;
+std::vector<std::string> m_masks;
 
 GTKMasks( const FileTypeList& types ) : m_types( types ){
        m_masks.reserve( m_types.size() );
@@ -113,7 +110,7 @@ GTKMasks( const FileTypeList& types ) : m_types( types ){
 }
 
 filetype_pair_t GetTypeForGTKMask( const char *mask ) const {
-       std::vector<CopiedString>::const_iterator j = m_masks.begin();
+       std::vector<std::string>::const_iterator j = m_masks.begin();
        for ( FileTypeList::const_iterator i = m_types.begin(); i != m_types.end(); ++i, ++j )
        {
                if ( string_equal( ( *j ).c_str(), mask ) ) {
@@ -170,22 +167,12 @@ const char* file_dialog_show( GtkWidget* parent, bool open, const char* title, c
        if ( path != 0 && !string_empty( path ) ) {
                ASSERT_MESSAGE( path_is_absolute( path ), "file_dialog_show: path not absolute: " << makeQuoted( path ) );
 
-               Array<char> new_path( strlen( path ) + 1 );
+               std::string new_path(path);
+               std::replace(new_path.begin(), new_path.end(), '/', G_DIR_SEPARATOR);
+               if ( !new_path.empty() && new_path.back() == G_DIR_SEPARATOR )
+                       new_path.pop_back();
 
-               // copy path, replacing dir separators as appropriate
-               Array<char>::iterator w = new_path.begin();
-               for ( const char* r = path; *r != '\0'; ++r )
-               {
-                       *w++ = ( *r == '/' ) ? G_DIR_SEPARATOR : *r;
-               }
-               // remove separator from end of path if required
-               if ( *( w - 1 ) == G_DIR_SEPARATOR ) {
-                       --w;
-               }
-               // terminate string
-               *w = '\0';
-
-               gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.data() );
+               gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), new_path.c_str() );
        }
 
        // we should add all important paths as shortcut folder...
@@ -243,7 +230,7 @@ const char* file_dialog_show( GtkWidget* parent, bool open, const char* title, c
        return g_file_dialog_file;
 }
 
-char* dir_dialog( GtkWidget* parent, const char* title, const char* path ){
+char* dir_dialog( ui::Widget parent, const char* title, const char* path ){
        GtkWidget* dialog = gtk_file_chooser_dialog_new( title,
                                                                                                         GTK_WINDOW( parent ),
                                                                                                         GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
@@ -268,15 +255,15 @@ char* dir_dialog( GtkWidget* parent, const char* title, const char* path ){
        return filename;
 }
 
-const char* file_dialog( GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern, bool want_load, bool want_import, bool want_save ){
+const char* file_dialog( ui::Widget parent, bool open, const char* title, const char* path, const char* pattern, bool want_load, bool want_import, bool want_save ){
        for (;; )
        {
                const char* file = file_dialog_show( parent, open, title, path, pattern, want_load, want_import, want_save );
 
                if ( open
-                        || file == 0
+                        || file == nullptr
                         || !file_exists( file )
-                        || gtk_MessageBox( parent, "The file specified already exists.\nDo you want to replace it?", title, eMB_NOYES, eMB_ICONQUESTION ) == eIDYES ) {
+                        || parent.alert("The file specified already exists.\nDo you want to replace it?", title, ui::alert_type::NOYES, ui::alert_icon::QUESTION ) == ui::alert_response::YES ) {
                        return file;
                }
        }