import asset dialogs remembers last used directories

This commit is contained in:
Mikulas Florek 2016-02-05 00:39:45 +01:00
parent e7e6c2c514
commit 83a9ecd363
9 changed files with 74 additions and 20 deletions

View file

@ -1,4 +1,4 @@
#LumixEngine
#Lumix Engine
=========
<a href="https://scan.coverity.com/projects/5919">

View file

@ -1591,6 +1591,7 @@ ImportAssetDialog::ImportAssetDialog(Lumix::WorldEditor& editor, Metadata& metad
m_source[0] = '\0';
m_output_dir[0] = '\0';
m_texture_output_dir[0] = '\0';
Lumix::copyString(m_last_dir, m_editor.getEngine().getPathManager().getBasePath());
}
@ -1621,7 +1622,7 @@ bool ImportAssetDialog::checkTexture(const char* source_dir,
<< path
<< " not found, please locate it");
if (!PlatformInterface::getOpenFilename(new_path, sizeof(new_path), "All\0*.*\0")) return false;
if (!PlatformInterface::getOpenFilename(new_path, sizeof(new_path), "All\0*.*\0", nullptr)) return false;
Lumix::string old_path_str(path, m_editor.getAllocator());
Lumix::string new_path_str(new_path, m_editor.getAllocator());
@ -1862,10 +1863,16 @@ void ImportAssetDialog::onGUI()
ImGui::SameLine();
if (ImGui::Button("..."))
{
PlatformInterface::getOpenFilename(m_source, sizeof(m_source), "All\0*.*\0");
PlatformInterface::getOpenFilename(m_source, sizeof(m_source), "All\0*.*\0", m_source);
checkSource();
}
if (m_is_importing || m_is_converting)
{
ImGui::EndDock();
return;
}
if (isImage(m_source))
{
if (ImGui::Checkbox("Convert to raw", &m_convert_to_raw))
@ -1885,7 +1892,8 @@ void ImportAssetDialog::onGUI()
ImGui::SameLine();
if (ImGui::Button("...###browseoutput"))
{
PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir));
auto* base_path = m_editor.getEngine().getPathManager().getBasePath();
PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir), base_path);
}
if (ImGui::Button("Import texture"))
@ -1896,9 +1904,9 @@ void ImportAssetDialog::onGUI()
return;
}
if (m_importer.GetScene())
auto* scene = m_importer.GetScene();
if (scene)
{
auto* scene = m_importer.GetScene();
ImGui::Checkbox("Import model", &m_import_model);
if (m_import_model)
{
@ -1961,7 +1969,10 @@ void ImportAssetDialog::onGUI()
ImGui::SameLine();
if (ImGui::Button("...###browseoutput"))
{
PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir));
if (PlatformInterface::getOpenDirectory(m_output_dir, sizeof(m_output_dir), m_last_dir))
{
Lumix::copyString(m_last_dir, m_output_dir);
}
}
ImGui::InputText(
@ -1969,8 +1980,11 @@ void ImportAssetDialog::onGUI()
ImGui::SameLine();
if (ImGui::Button("...###browsetextureoutput"))
{
PlatformInterface::getOpenDirectory(
m_texture_output_dir, sizeof(m_texture_output_dir));
if (PlatformInterface::getOpenDirectory(
m_texture_output_dir, sizeof(m_texture_output_dir), m_last_dir))
{
Lumix::copyString(m_last_dir, m_output_dir);
}
}
if (m_output_dir[0] != '\0')

View file

@ -61,6 +61,7 @@ class LUMIX_EDITOR_API ImportAssetDialog
Lumix::BinaryArray m_mesh_mask;
char m_import_message[1024];
char m_message[1024];
char m_last_dir[Lumix::MAX_PATH_LENGTH];
char m_source[Lumix::MAX_PATH_LENGTH];
char m_output_dir[Lumix::MAX_PATH_LENGTH];
char m_texture_output_dir[Lumix::MAX_PATH_LENGTH];

View file

@ -578,33 +578,73 @@ namespace PlatformInterface
}
bool getOpenFilename(char* out, int max_size, const char* filter)
bool getOpenFilename(char* out, int max_size, const char* filter, const char* starting_file)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
if (starting_file)
{
char* to = out;
for (const char* from = starting_file; *from; ++from, ++to)
{
if (to - out > max_size - 1) break;
*to = *to == '/' ? '\\' : *from;
}
*to = '\0';
}
else
{
out[0] = '\0';
}
ofn.lpstrFile = out;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = max_size;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrInitialDir = nullptr;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_NONETWORKBUTTON;
return GetOpenFileName(&ofn) == TRUE;
auto x= GetOpenFileName(&ofn);
auto err =GetLastError();
auto err2 =CommDlgExtendedError();
return x == TRUE;
}
bool getOpenDirectory(char* out, int max_size)
bool getOpenDirectory(char* out, int max_size, const char* starting_dir)
{
bool ret = false;
IFileDialog *pfd;
if (SUCCEEDED(CoCreateInstance(
CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
{
if (starting_dir)
{
PIDLIST_ABSOLUTE pidl;
WCHAR wstarting_dir[MAX_PATH];
WCHAR* wc = wstarting_dir;
for (const char* c = starting_dir; *c && wc - wstarting_dir < MAX_PATH - 1; ++c, ++wc)
{
*wc = *c == '/' ? '\\' : *c;
}
*wc = 0;
HRESULT hresult = ::SHParseDisplayName(wstarting_dir, 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hresult))
{
IShellItem *psi;
hresult = ::SHCreateShellItem(NULL, NULL, pidl, &psi);
if (SUCCEEDED(hresult))
{
pfd->SetFolder(psi);
}
ILFree(pidl);
}
}
DWORD dwOptions;
if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
{

View file

@ -96,12 +96,12 @@ namespace PlatformInterface
LUMIX_EDITOR_API void getKeyName(int key, char* out, int max_size);
LUMIX_EDITOR_API void setCursor(Cursor cursor);
LUMIX_EDITOR_API bool getOpenFilename(char* out, int max_size, const char* filter);
LUMIX_EDITOR_API bool getOpenFilename(char* out, int max_size, const char* filter, const char* starting_file);
LUMIX_EDITOR_API bool getSaveFilename(char* out,
int max_size,
const char* filter,
const char* default_extension);
LUMIX_EDITOR_API bool getOpenDirectory(char* out, int max_size);
LUMIX_EDITOR_API bool getOpenDirectory(char* out, int max_size, const char* starting_dir);
LUMIX_EDITOR_API bool shellExecuteOpen(const char* path);
LUMIX_EDITOR_API bool deleteFile(const char* path);

View file

@ -442,7 +442,7 @@ public:
void loadAndExecuteCommands()
{
char filename[Lumix::MAX_PATH_LENGTH];
if (PlatformInterface::getOpenFilename(filename, Lumix::lengthOf(filename), "JSON files\0*.json\0"))
if (PlatformInterface::getOpenFilename(filename, Lumix::lengthOf(filename), "JSON files\0*.json\0", nullptr))
{
m_editor->executeUndoStack(Lumix::Path(filename));
}

View file

@ -1775,7 +1775,7 @@ void ShaderEditor::loadNodeConnections(Lumix::InputBlob& blob, Node& node)
void ShaderEditor::load()
{
char path[Lumix::MAX_PATH_LENGTH];
if (!PlatformInterface::getOpenFilename(path, Lumix::lengthOf(path), "Shader edit data\0*.sed\0"))
if (!PlatformInterface::getOpenFilename(path, Lumix::lengthOf(path), "Shader edit data\0*.sed\0", nullptr))
{
return;
}

View file

@ -1289,7 +1289,7 @@ void TerrainEditor::onGUI()
if (ImGui::Button("Select mask"))
{
char filename[Lumix::MAX_PATH_LENGTH];
if (PlatformInterface::getOpenFilename(filename, Lumix::lengthOf(filename), "All\0*.*\0"))
if (PlatformInterface::getOpenFilename(filename, Lumix::lengthOf(filename), "All\0*.*\0", nullptr))
{
int image_width;
int image_height;

View file

@ -1624,7 +1624,6 @@ struct PipelineImpl : public Pipeline
rots[bone_index].toMatrix(bone_mtx[bone_index]);
bone_mtx[bone_index].translate(poss[bone_index]);
bone_mtx[bone_index] = bone_mtx[bone_index] * bone.inv_bind_matrix;
//bone_mtx[bone_index].transpose();
}
bgfx::setUniform(m_bone_matrices_uniform, bone_mtx, pose.getCount());
}