File-dialog now converts the returned filename from multibyte to widechar when it has to.

Also added a function to access the original name as well as the converted name for directories.
Can't fix the interface completely unfortunately without breaking it :-/
Not yet fixed is the conversion to lower-characters - that will be one of the next tasks (had to clean up other stuff before I could approach that).
Also _IRR_WCHAR_FILESYSTEM currently not compiling, but been like that a few versions already.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5215 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2015-12-14 15:59:35 +00:00
parent 15fce47e24
commit b539e46b5f
5 changed files with 79 additions and 44 deletions

View File

@ -165,7 +165,7 @@ public:
IGUIFileOpenDialog* dialog =
(IGUIFileOpenDialog*)event.GUIEvent.Caller;
Context.listbox->addItem(L"EGET_DIRECTORY_SELECTED");
Context.listbox->addItem(core::stringw(dialog->getDirectoryName()).c_str());
Context.listbox->addItem(dialog->getDirectoryNameW());
}
break;

View File

@ -1347,7 +1347,7 @@ bool CQuake3EventHandler::OnEvent(const SEvent& eve)
else
if ( eve.GUIEvent.Caller == gui.ArchiveFileOpen && eve.GUIEvent.EventType == gui::EGET_FILE_SELECTED )
{
AddArchive ( gui.ArchiveFileOpen->getFileName() );
AddArchive ( gui.ArchiveFileOpen->getFileNameP() );
gui.ArchiveFileOpen = 0;
}
else

View File

@ -29,11 +29,17 @@ namespace gui
IGUIFileOpenDialog(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIElement(EGUIET_FILE_OPEN_DIALOG, environment, parent, id, rectangle) {}
//! Returns the filename of the selected file. Returns NULL, if no file was selected.
//! Returns the filename of the selected file converted to wide characters. Returns NULL if no file was selected.
virtual const wchar_t* getFileName() const = 0;
//! Returns the directory of the selected file. Returns NULL, if no directory was selected.
virtual const io::path& getDirectoryName() = 0;
//! Returns the filename of the selected file. Is empty if no file was selected.
virtual const io::path& getFileNameP() const = 0;
//! Returns the directory of the selected file. Empty if no directory was selected.
virtual const io::path& getDirectoryName() const = 0;
//! Returns the directory of the selected file converted to wide characters. Returns NULL if no directory was selected.
virtual const wchar_t* getDirectoryNameW() const = 0;
};

View File

@ -147,18 +147,40 @@ CGUIFileOpenDialog::~CGUIFileOpenDialog()
//! returns the filename of the selected file. Returns NULL, if no file was selected.
const wchar_t* CGUIFileOpenDialog::getFileName() const
const const wchar_t* CGUIFileOpenDialog::getFileName() const
{
return FileName.c_str();
return FileNameW.c_str();
}
const io::path& CGUIFileOpenDialog::getFileNameP() const
{
return FileName;
}
//! Returns the directory of the selected file. Returns NULL, if no directory was selected.
const io::path& CGUIFileOpenDialog::getDirectoryName()
const io::path& CGUIFileOpenDialog::getDirectoryName() const
{
FileSystem->flattenFilename ( FileDirectory );
return FileDirectory;
return FileDirectoryFlat;
}
const wchar_t* CGUIFileOpenDialog::getDirectoryNameW() const
{
return FileDirectoryFlatW.c_str();
}
void CGUIFileOpenDialog::setFileName(const irr::io::path& name)
{
FileName = name;
pathToStringW(FileNameW, FileName);
}
void CGUIFileOpenDialog::setDirectoryName(const irr::io::path& name)
{
FileDirectory = name;
FileDirectoryFlat = name;
FileSystem->flattenFilename (FileDirectoryFlat );
pathToStringW(FileDirectoryFlatW, FileDirectoryFlat);
}
//! called if an event happened.
bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
@ -204,13 +226,13 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
{
if (FileList->isDirectory(selected))
{
FileName = L"";
FileDirectory = FileList->getFullFileName(selected);
setFileName("");
setDirectoryName(FileList->getFullFileName(selected));
}
else
{
FileDirectory = L"";
FileName = FileList->getFullFileName(selected);
setDirectoryName("");
setFileName(FileList->getFullFileName(selected));
}
return true;
}
@ -224,14 +246,14 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
{
if (FileList->isDirectory(selected))
{
FileDirectory = FileList->getFullFileName(selected);
FileSystem->changeWorkingDirectoryTo(FileList->getFileName(selected));
setDirectoryName(FileList->getFullFileName(selected));
FileSystem->changeWorkingDirectoryTo(FileDirectory );
fillListBox();
FileName = "";
setFileName("");
}
else
{
FileName = FileList->getFullFileName(selected);
setFileName(FileList->getFullFileName(selected));
}
return true;
}
@ -244,7 +266,7 @@ bool CGUIFileOpenDialog::OnEvent(const SEvent& event)
if ( FileSystem->changeWorkingDirectoryTo( dir ) )
{
fillListBox();
FileName = L"";
setFileName("");
}
return true;
}
@ -342,7 +364,7 @@ void CGUIFileOpenDialog::serializeAttributes(io::IAttributes* out, io::SAttribut
//! Reads attributes of the element
/* Note that thiese paths changes will happen at arbitrary places upon
/* Note that these paths changes will happen at arbitrary places upon
load of the gui description. This may be undesired. */
void CGUIFileOpenDialog::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
@ -358,6 +380,17 @@ void CGUIFileOpenDialog::deserializeAttributes(io::IAttributes* in, io::SAttribu
IGUIFileOpenDialog::deserializeAttributes(in,options);
}
void CGUIFileOpenDialog::pathToStringW(irr::core::stringw& result, const irr::io::path& p)
{
#ifndef _IRR_WCHAR_FILESYSTEM
char* oldLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL,""); // multibyteToWString is affected by LC_CTYPE. Filenames seem to need the system-locale.
core::multibyteToWString(result, p);
setlocale(LC_ALL, oldLocale);
#else
result = path.c_str();
#endif
}
//! fills the listbox with files.
void CGUIFileOpenDialog::fillListBox()
@ -375,42 +408,23 @@ void CGUIFileOpenDialog::fillListBox()
FileList = FileSystem->createFileList();
core::stringw s;
#ifndef _IRR_WCHAR_FILESYSTEM
char* oldLocale = setlocale(LC_ALL, NULL);
setlocale(LC_ALL,""); // multibyteToWString is affected by LC_CTYPE. Filenames seem to need the system-locale.
#endif
if (FileList)
{
for (u32 i=0; i < FileList->getFileCount(); ++i)
{
#ifndef _IRR_WCHAR_FILESYSTEM
core::multibyteToWString(s, FileList->getFileName(i));
#else
s = FileList->getFileName(i).c_str();
#endif
pathToStringW(s, FileList->getFileName(i));
FileBox->addItem(s.c_str(), skin->getIcon(FileList->isDirectory(i) ? EGDI_DIRECTORY : EGDI_FILE));
}
}
if (FileNameText)
{
#ifndef _IRR_WCHAR_FILESYSTEM
core::multibyteToWString(s, FileSystem->getWorkingDirectory());
#else
s = FileSystem->getWorkingDirectory();
#endif
FileDirectory = s;
setDirectoryName(FileSystem->getWorkingDirectory());
pathToStringW(s, FileDirectory);
FileNameText->setText(s.c_str());
}
#ifndef _IRR_WCHAR_FILESYSTEM
setlocale(LC_ALL, oldLocale);
#endif
}
//! sends the event that the file has been selected.
void CGUIFileOpenDialog::sendSelectedEvent( EGUI_EVENT_TYPE type)
{

View File

@ -34,8 +34,14 @@ namespace gui
//! returns the filename of the selected file. Returns NULL, if no file was selected.
virtual const wchar_t* getFileName() const _IRR_OVERRIDE_;
//! Returns the filename of the selected file. Is empty if no file was selected.
virtual const io::path& getFileNameP() const _IRR_OVERRIDE_;
//! Returns the directory of the selected file. Returns NULL, if no directory was selected.
virtual const io::path& getDirectoryName() _IRR_OVERRIDE_;
virtual const io::path& getDirectoryName() const _IRR_OVERRIDE_;
//! Returns the directory of the selected file converted to wide characters. Returns NULL if no directory was selected.
virtual const wchar_t* getDirectoryNameW() const _IRR_OVERRIDE_;
//! called if an event happened.
virtual bool OnEvent(const SEvent& event) _IRR_OVERRIDE_;
@ -48,6 +54,12 @@ namespace gui
protected:
void setFileName(const irr::io::path& name);
void setDirectoryName(const irr::io::path& name);
//! Ensure filenames are converted correct depending on wide-char settings
void pathToStringW(irr::core::stringw& result, const irr::io::path& p);
//! fills the listbox with files.
void fillListBox();
@ -58,8 +70,11 @@ namespace gui
void sendCancelEvent();
core::position2d<s32> DragStart;
core::stringw FileName;
io::path FileName;
core::stringw FileNameW;
io::path FileDirectory;
io::path FileDirectoryFlat;
core::stringw FileDirectoryFlatW;
io::path RestoreDirectory;
io::path StartDirectory;