allow different file type selections for open/import/save
This commit is contained in:
parent
e1ed914df2
commit
599056d188
|
|
@ -22,7 +22,7 @@ void OnExportClicked(GtkButton* button, gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2");
|
GtkWidget* window = lookup_widget(GTK_WIDGET(button), "w_plugplug2");
|
||||||
ASSERT_NOTNULL(window);
|
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)
|
if(!cpath)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,15 @@ public:
|
||||||
: name(""), pattern("")
|
: name(""), pattern("")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
filetype_t(const char* _name, const char* _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)
|
: name(_name), pattern(_pattern), can_load(_can_load), can_import(_can_import), can_save(_can_save)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* pattern;
|
const char* pattern;
|
||||||
|
bool can_load;
|
||||||
|
bool can_import;
|
||||||
|
bool can_save;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,7 +56,7 @@ public:
|
||||||
STRING_CONSTANT(Name, "filetypes");
|
STRING_CONSTANT(Name, "filetypes");
|
||||||
|
|
||||||
virtual void addType(const char* moduleType, const char* moduleName, filetype_t type) = 0;
|
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"
|
#include "modulesystem.h"
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ typedef EMessageBoxReturn (* PFN_QERAPP_MESSAGEBOX) (GtkWidget *parent, const ch
|
||||||
// - 'title' is the dialog title (can be null)
|
// - 'title' is the dialog title (can be null)
|
||||||
// - 'path' is used to set the initial directory (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
|
// - '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
|
// 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*/);
|
typedef char* (* PFN_QERAPP_DIRDIALOG) (GtkWidget *parent, const char* title/* = "Choose Directory"*/, const char* path/* = 0*/);
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public:
|
||||||
|
|
||||||
static char g_file_dialog_file[1024];
|
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;
|
filetype_t type;
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, co
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTypeList typelist;
|
FileTypeList typelist;
|
||||||
GlobalFiletypes().getTypeList(pattern, &typelist);
|
GlobalFiletypes().getTypeList(pattern, &typelist, want_load, want_import, want_save);
|
||||||
|
|
||||||
GTKMasks masks(typelist);
|
GTKMasks masks(typelist);
|
||||||
|
|
||||||
|
|
@ -288,11 +288,11 @@ char* dir_dialog(GtkWidget* parent, const char* title, const char* path)
|
||||||
return filename;
|
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(;;)
|
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
|
if(open
|
||||||
|| file == 0
|
|| file == 0
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
/// GTK+ file-chooser dialogs.
|
/// GTK+ file-chooser dialogs.
|
||||||
|
|
||||||
typedef struct _GtkWidget GtkWidget;
|
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.
|
/// \brief Prompts the user to browse for a directory.
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
|
||||||
struct filetype_copy_t
|
struct filetype_copy_t
|
||||||
{
|
{
|
||||||
filetype_copy_t(const char* moduleName, const filetype_t other)
|
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
|
const char* getModuleName() const
|
||||||
|
|
@ -44,8 +44,11 @@ class RadiantFileTypeRegistry : public IFileTypeRegistry
|
||||||
}
|
}
|
||||||
filetype_t getType() const
|
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:
|
private:
|
||||||
CopiedString m_moduleName;
|
CopiedString m_moduleName;
|
||||||
CopiedString m_name;
|
CopiedString m_name;
|
||||||
|
|
@ -62,11 +65,14 @@ public:
|
||||||
{
|
{
|
||||||
m_typelists[moduleType].push_back(filetype_copy_t(moduleName, type));
|
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];
|
filetype_list_t& list_ref = m_typelists[moduleType];
|
||||||
for(filetype_list_t::iterator i = list_ref.begin(); i != list_ref.end(); ++i)
|
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());
|
typelist->addType((*i).getModuleName(), (*i).getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1897,12 +1897,17 @@ const char* getMapsPath()
|
||||||
|
|
||||||
const char* map_open(const char* title)
|
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)
|
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()
|
void OpenMap()
|
||||||
|
|
@ -1923,7 +1928,7 @@ void OpenMap()
|
||||||
|
|
||||||
void ImportMap()
|
void ImportMap()
|
||||||
{
|
{
|
||||||
const char* filename = map_open("Import Map");
|
const char* filename = map_import("Import Map");
|
||||||
|
|
||||||
if(filename != 0)
|
if(filename != 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user