| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <stdexcept> |
| 4 |
#include "XDataLoader.h" |
| 5 |
#include "wxutil/dialog/DialogBase.h" |
| 6 |
#include "wxutil/dataview/TreeView.h" |
| 7 |
|
| 8 |
namespace ui |
| 9 |
{ |
| 10 |
|
| 11 |
class ReadableEditorDialog; |
| 12 |
|
| 13 |
///////////////////////////// XdFileChooserDialog: |
| 14 |
// Imports a given definition. If the definition has been found in multiple files, |
| 15 |
// the dialog shows up asking which file to use. |
| 16 |
class XdFileChooserDialog : |
| 17 |
public wxutil::DialogBase |
| 18 |
{ |
| 19 |
public: |
| 20 |
struct ImportFailedException : |
| 21 |
public std::runtime_error |
| 22 |
{ |
| 23 |
ImportFailedException(const std::string& what) : |
| 24 |
std::runtime_error(what) |
| 25 |
{} |
| 26 |
}; |
| 27 |
|
| 28 |
private: |
| 29 |
// Treestore enum |
| 30 |
struct ListStoreColumns : |
| 31 |
public wxutil::TreeModel::ColumnRecord |
| 32 |
{ |
| 33 |
ListStoreColumns() : |
| 34 |
name(add(wxutil::TreeModel::Column::String)) |
| 35 |
{} |
| 36 |
|
| 37 |
wxutil::TreeModel::Column name; |
| 38 |
|
| 39 |
}; |
| 40 |
// A container for storing enumerated widgets |
| 41 |
ListStoreColumns _columns; |
| 42 |
wxutil::TreeModel::Ptr _listStore; |
| 43 |
wxutil::TreeView* _treeview; |
| 44 |
|
| 45 |
// The chosen filename. |
| 46 |
std::string _chosenFile; |
| 47 |
|
| 48 |
// Pointer to the ReadableEditorDialog for updating the guiView. |
| 49 |
ReadableEditorDialog* _editorDialog; |
| 50 |
|
| 51 |
// Definition name |
| 52 |
std::string _defName; |
| 53 |
public: |
| 54 |
|
| 55 |
// Imports the definition given by defName and stores the result in newXData and the corresponding filename. |
| 56 |
// If the definition is found in mutliple files a dialog is shown asking the user which file to use. |
| 57 |
// @throws: ImportFailedException |
| 58 |
static int Import(const std::string& defName, XData::XDataPtr& newXData, |
| 59 |
std::string& filename, XData::XDataLoaderPtr& loader, ReadableEditorDialog* editorDialog); |
| 60 |
|
| 61 |
private: |
| 62 |
// Private constructor called by run. |
| 63 |
XdFileChooserDialog(const std::string& defName, const XData::XDataMap& xdMap, ReadableEditorDialog* editorDialog); |
| 64 |
|
| 65 |
void onOk(); |
| 66 |
void onCancel(); |
| 67 |
void onSelectionChanged(wxDataViewEvent& ev); |
| 68 |
}; |
| 69 |
|
| 70 |
} // namespace ui |