]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
allow different file type selections for open/import/save
authorRudolf Polzer <divverent@alientrap.org>
Sun, 10 Oct 2010 12:35:18 +0000 (14:35 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 10 Oct 2010 12:35:18 +0000 (14:35 +0200)
contrib/brushexport/callbacks.cpp
include/ifiletypes.h
include/qerplugin.h
libs/gtkutil/filechooser.cpp
libs/gtkutil/filechooser.h
radiant/filetypes.cpp
radiant/map.cpp

index ab6396ee94f2d557c17081046031e5041f3bafa4..0aea73da8d42d599c6bef614ab7d57e27f42db02 100644 (file)
@@ -22,7 +22,7 @@ void OnExportClicked(GtkButton* button, gpointer user_data)
 {
        GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2");
        ASSERT_NOTNULL(window);
-       const char* cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0);
+       const char* cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0, false, false, true);
        if(!cpath)
                return;
 
index e2851be29df2decd931ba4fe7caebfa8efe4fa03..0d061d2bbfb0b75ef399cf30ae5c0a9564cff7a9 100644 (file)
@@ -31,12 +31,15 @@ public:
     : name(""), pattern("")
   {
   }
-  filetype_t(const char* _name, const char* _pattern)
-    : name(_name), pattern(_pattern)
+  filetype_t(const char* _name, const char* _pattern, bool _can_load = true, bool _can_import = true, bool _can_save = true)
+    : name(_name), pattern(_pattern), can_load(_can_load), can_import(_can_import), can_save(_can_save)
   {
   }
   const char* name;
   const char* pattern;
+  bool can_load;
+  bool can_import;
+  bool can_save;
 };
 
 
@@ -53,7 +56,7 @@ public:
   STRING_CONSTANT(Name, "filetypes");
 
   virtual void addType(const char* moduleType, const char* moduleName, filetype_t type) = 0;
-  virtual void getTypeList(const char* moduleType, IFileTypeList* typelist) = 0;
+  virtual void getTypeList(const char* moduleType, IFileTypeList* typelist, bool want_load = false, bool want_import = false, bool want_save = false) = 0;
 };
 
 #include "modulesystem.h"
index a6a08d372817d70f9c7b8b79ab2b83e3fa739573..cac311ab9da11a9c55cf30fde8fcde76ef059dd0 100644 (file)
@@ -71,7 +71,7 @@ typedef EMessageBoxReturn (* PFN_QERAPP_MESSAGEBOX) (GtkWidget *parent, const ch
 // - 'title' is the dialog title (can be null)
 // - 'path' is used to set the initial directory (can be null)
 // - 'pattern': the first pattern is for the win32 mode, then comes the Gtk pattern list, see Radiant source for samples
-typedef const char* (* PFN_QERAPP_FILEDIALOG) (GtkWidget *parent, bool open, const char* title, const char* path/* = 0*/, const char* pattern/* = 0*/);
+typedef const char* (* PFN_QERAPP_FILEDIALOG) (GtkWidget *parent, bool open, const char* title, const char* path/* = 0*/, const char* pattern/* = 0*/, bool want_load/* = false*/, bool want_import/* = false*/, bool want_save/* = false*/);
 
 // returns a gchar* string that must be g_free'd by the user
 typedef char* (* PFN_QERAPP_DIRDIALOG) (GtkWidget *parent, const char* title/* = "Choose Directory"*/, const char* path/* = 0*/);
index f164d220d8f3cdcd1a2099b9e042b7e9155f953e..2246b57bd60608f5651c3a4c66ae5769cb21c820 100644 (file)
@@ -137,7 +137,7 @@ public:
 
 static char g_file_dialog_file[1024];
 
-const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
+const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern, bool want_load, bool want_import, bool want_save)
 {
   filetype_t type;
 
@@ -147,7 +147,7 @@ const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, co
   }
 
   FileTypeList typelist;
-  GlobalFiletypes().getTypeList(pattern, &typelist);
+  GlobalFiletypes().getTypeList(pattern, &typelist, want_load, want_import, want_save);
 
   GTKMasks masks(typelist);
 
@@ -288,11 +288,11 @@ 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)
+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)
 {
   for(;;)
   {
-    const char* file = file_dialog_show(parent, open, title, path, pattern);
+    const char* file = file_dialog_show(parent, open, title, path, pattern, want_load, want_import, want_save);
 
     if(open
       || file == 0
index d23beb5da320da8d165e1f9ab197eaf680efe1e6..3789321e4b13b9a8be1b3f6d2b115c30f6249f2b 100644 (file)
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 /// GTK+ file-chooser dialogs.
 
 typedef struct _GtkWidget GtkWidget;
-const char* file_dialog(GtkWidget *parent, bool open, const char* title, const char* path = 0, const char* pattern = 0);
+const char* file_dialog(GtkWidget *parent, bool open, const char* title, const char* path = 0, const char* pattern = 0, bool want_load = false, bool want_import = false, bool want_save = false);
 
 
 /// \brief Prompts the user to browse for a directory.
index b76b968e765d2311cea17f4d46b0ba42d636b020..11c0a272eceb97788479abc36d0b4a3c93815e25 100644 (file)
@@ -35,7 +35,7 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
   struct filetype_copy_t
   {
     filetype_copy_t(const char* moduleName, const filetype_t other)
-      : m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern)
+      : m_moduleName(moduleName), m_name(other.name), m_pattern(other.pattern), m_can_load(other.can_load), m_can_import(other.can_import), m_can_save(other.can_save)
     {
     }
     const char* getModuleName() const
@@ -44,8 +44,11 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
     }
     filetype_t getType() const
     {
-      return filetype_t(m_name.c_str(), m_pattern.c_str());
+      return filetype_t(m_name.c_str(), m_pattern.c_str(), m_can_load, m_can_save, m_can_import);
     }
+    bool m_can_load;
+    bool m_can_import;
+    bool m_can_save;
   private:
     CopiedString m_moduleName;
     CopiedString m_name;
@@ -62,11 +65,14 @@ public:
   {
     m_typelists[moduleType].push_back(filetype_copy_t(moduleName, type));
   }
-  void getTypeList(const char* moduleType, IFileTypeList* typelist)
+  void getTypeList(const char* moduleType, IFileTypeList* typelist, bool want_load, bool want_import, bool want_save)
   {
     filetype_list_t& list_ref = m_typelists[moduleType];
     for(filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i)
     {
+      if(want_load && !(*i).m_can_load) return;
+      if(want_import && !(*i).m_can_import) return;
+      if(want_save && !(*i).m_can_save) return;
       typelist->addType((*i).getModuleName(), (*i).getType());
     }
   }
index 365c50b475289cf3f789d2e08897be47fff5beb0..ac95068ae9ef49635b33f6c44da5a7cc917ffb40 100644 (file)
@@ -1897,12 +1897,17 @@ const char* getMapsPath()
 
 const char* map_open(const char* title)
 {
-  return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name());
+  return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name(), true, false, false);
+}
+
+const char* map_import(const char* title)
+{
+  return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name(), false, true, false);
 }
 
 const char* map_save(const char* title)
 {
-  return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name());
+  return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name(), false, false, true);
 }
 
 void OpenMap()
@@ -1923,7 +1928,7 @@ void OpenMap()
 
 void ImportMap()
 {
-  const char* filename = map_open("Import Map");
+  const char* filename = map_import("Import Map");
 
   if(filename != 0)
   {