From: Rudolf Polzer Date: Sun, 10 Oct 2010 12:35:18 +0000 (+0200) Subject: allow different file type selections for open/import/save X-Git-Tag: xonotic-v0.5.0~173^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=599056d18827a01ef0af31e5e3c80bfc2870bb6b;p=xonotic%2Fnetradiant.git allow different file type selections for open/import/save --- diff --git a/contrib/brushexport/callbacks.cpp b/contrib/brushexport/callbacks.cpp index ab6396ee..0aea73da 100644 --- a/contrib/brushexport/callbacks.cpp +++ b/contrib/brushexport/callbacks.cpp @@ -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; diff --git a/include/ifiletypes.h b/include/ifiletypes.h index e2851be2..0d061d2b 100644 --- a/include/ifiletypes.h +++ b/include/ifiletypes.h @@ -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" diff --git a/include/qerplugin.h b/include/qerplugin.h index a6a08d37..cac311ab 100644 --- a/include/qerplugin.h +++ b/include/qerplugin.h @@ -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*/); diff --git a/libs/gtkutil/filechooser.cpp b/libs/gtkutil/filechooser.cpp index f164d220..2246b57b 100644 --- a/libs/gtkutil/filechooser.cpp +++ b/libs/gtkutil/filechooser.cpp @@ -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 diff --git a/libs/gtkutil/filechooser.h b/libs/gtkutil/filechooser.h index d23beb5d..3789321e 100644 --- a/libs/gtkutil/filechooser.h +++ b/libs/gtkutil/filechooser.h @@ -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. diff --git a/radiant/filetypes.cpp b/radiant/filetypes.cpp index b76b968e..11c0a272 100644 --- a/radiant/filetypes.cpp +++ b/radiant/filetypes.cpp @@ -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()); } } diff --git a/radiant/map.cpp b/radiant/map.cpp index 365c50b4..ac95068a 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -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) {