2013-06-23 18:30:21 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2013 sapier
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-06-11 09:43:31 +02:00
|
|
|
#include "guiPathSelectMenu.h"
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
GUIFileSelectMenu::GUIFileSelectMenu(gui::IGUIEnvironment* env,
|
2017-04-21 23:40:48 +02:00
|
|
|
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
|
2017-06-11 09:43:31 +02:00
|
|
|
const std::string &title, const std::string &formname,
|
|
|
|
bool is_file_select) :
|
2017-04-21 23:40:48 +02:00
|
|
|
GUIModalMenu(env, parent, id, menumgr),
|
|
|
|
m_title(utf8_to_wide(title)),
|
2017-06-11 09:43:31 +02:00
|
|
|
m_formname(formname),
|
|
|
|
m_file_select_dialog(is_file_select)
|
2013-06-23 18:30:21 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GUIFileSelectMenu::~GUIFileSelectMenu()
|
|
|
|
{
|
2016-04-28 20:27:59 +02:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFileSelectMenu::regenerateGui(v2u32 screensize)
|
|
|
|
{
|
2022-05-22 00:11:59 +02:00
|
|
|
removeAllChildren();
|
2013-06-23 18:30:21 +02:00
|
|
|
m_fileOpenDialog = 0;
|
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
core::dimension2du size(600 * m_gui_scale, 400 * m_gui_scale);
|
2017-06-11 09:43:31 +02:00
|
|
|
core::rect<s32> rect(0, 0, screensize.X, screensize.Y);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
DesiredRect = rect;
|
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
|
|
|
|
m_fileOpenDialog =
|
2017-06-11 09:43:31 +02:00
|
|
|
Environment->addFileOpenDialog(m_title.c_str(), false, this, -1);
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2017-06-11 09:43:31 +02:00
|
|
|
core::position2di pos = core::position2di(screensize.X / 2 - size.Width / 2,
|
|
|
|
screensize.Y / 2 - size.Height / 2);
|
2013-06-23 18:30:21 +02:00
|
|
|
m_fileOpenDialog->setRelativePosition(pos);
|
|
|
|
m_fileOpenDialog->setMinSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFileSelectMenu::drawMenu()
|
|
|
|
{
|
2017-06-11 09:43:31 +02:00
|
|
|
gui::IGUISkin *skin = Environment->getSkin();
|
2013-06-23 18:30:21 +02:00
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gui::IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
2017-06-11 09:43:31 +02:00
|
|
|
void GUIFileSelectMenu::acceptInput()
|
|
|
|
{
|
2017-08-18 07:44:42 +02:00
|
|
|
if (m_text_dst && !m_formname.empty()) {
|
2015-05-19 08:24:14 +02:00
|
|
|
StringMap fields;
|
2017-06-11 09:43:31 +02:00
|
|
|
if (m_accepted) {
|
|
|
|
std::string path;
|
|
|
|
if (!m_file_select_dialog) {
|
|
|
|
core::string<fschar_t> string =
|
|
|
|
m_fileOpenDialog->getDirectoryName();
|
|
|
|
path = std::string(string.c_str());
|
|
|
|
} else {
|
|
|
|
path = wide_to_utf8(m_fileOpenDialog->getFileName());
|
|
|
|
}
|
|
|
|
fields[m_formname + "_accepted"] = path;
|
|
|
|
} else {
|
2013-06-23 18:30:21 +02:00
|
|
|
fields[m_formname + "_canceled"] = m_formname;
|
2017-06-11 09:43:31 +02:00
|
|
|
}
|
2017-08-18 07:44:42 +02:00
|
|
|
m_text_dst->gotText(fields);
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
2017-06-11 09:43:31 +02:00
|
|
|
quitMenu();
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
|
2017-06-11 09:43:31 +02:00
|
|
|
bool GUIFileSelectMenu::OnEvent(const SEvent &event)
|
2013-06-23 18:30:21 +02:00
|
|
|
{
|
|
|
|
if (event.EventType == irr::EET_GUI_EVENT) {
|
|
|
|
switch (event.GUIEvent.EventType) {
|
2017-06-11 09:43:31 +02:00
|
|
|
case gui::EGET_ELEMENT_CLOSED:
|
|
|
|
case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
|
|
|
|
m_accepted = false;
|
|
|
|
acceptInput();
|
|
|
|
return true;
|
|
|
|
case gui::EGET_DIRECTORY_SELECTED:
|
|
|
|
m_accepted = !m_file_select_dialog;
|
|
|
|
acceptInput();
|
|
|
|
return true;
|
|
|
|
case gui::EGET_FILE_SELECTED:
|
|
|
|
m_accepted = m_file_select_dialog;
|
|
|
|
acceptInput();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
// ignore this event
|
|
|
|
break;
|
2013-06-23 18:30:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
}
|