Path: blob/main/src/netedit/dialogs/file/GNEFileDialog.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEFileDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 202516///17// Dialog used for opening/saving files18/****************************************************************************/1920#include <utils/foxtools/MFXTextFieldIcon.h>21#include <utils/gui/div/GUIIOGlobals.h>22#include <netedit/GNEApplicationWindow.h>2324#include "GNEFileDialog.h"25#include "GNEFileSelector.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNEFileDialog::GNEFileDialog(GNEApplicationWindow* applicationWindow, const std::string elementFile,32const std::vector<std::string>& extensions, GNEFileDialog::OpenMode openMode,33GNEFileDialog::ConfigType configType):34GNEDialog(applicationWindow, TLF("Save % as", elementFile), GUIIcon::SAVE,35DialogType::FILE, GNEDialog::Buttons::ACCEPT_CANCEL, GNEDialog::OpenType::MODAL,36GNEDialog::ResizeMode::RESIZABLE, 500, 300) {37// update title and icon if we are opening38if (openMode != GNEFileDialog::OpenMode::SAVE) {39updateIcon(GUIIcon::OPEN);40updateTitle(TLF("Open %", elementFile));41}42// create file selector43myFileSelector = new GNEFileSelector(this, extensions, openMode, configType);44// retarget accept button to file selector45myAcceptButton->setTarget(myFileSelector);46myAcceptButton->setSelector(FXFileSelector::ID_ACCEPT);47// check if we have saved settings in registry48setWidth(getApp()->reg().readIntEntry("GNEFileDialog", "width", getWidth()));49setHeight(getApp()->reg().readIntEntry("GNEFileDialog", "height", getHeight()));50myFileSelector->setFileBoxStyle(getApp()->reg().readUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle()));51myFileSelector->showHiddenFiles((getApp()->reg().readUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles()) == 1) ? TRUE : FALSE);52// set initial directory53if (gCurrentFolder.length() > 0) {54myFileSelector->setDirectory(gCurrentFolder);55}56// open dialog without focusing the button57openDialog(myFileSelector->getFilenameTextField());58}596061GNEFileDialog::~GNEFileDialog() {62getApp()->reg().writeIntEntry("GNEFileDialog", "width", getWidth());63getApp()->reg().writeIntEntry("GNEFileDialog", "height", getHeight());64getApp()->reg().writeUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle());65getApp()->reg().writeUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles());66}676869void70GNEFileDialog::runInternalTest(const InternalTestStep::DialogArgument* dialogArgument) {71if (dialogArgument->getCustomAction().size() > 0) {72myFileSelector->setFilter(dialogArgument->getIndex());73myFileSelector->setPath(dialogArgument->getCustomAction());74}75}767778std::string79GNEFileDialog::getFilename() const {80return assureExtension(myFileSelector->getFilename());81}828384std::vector<std::string>85GNEFileDialog::getFilenames() const {86std::vector<std::string> filenames;87// assure extension for each file88for (auto& filename : myFileSelector->getFilenames()) {89filenames.push_back(assureExtension(filename));90}91return filenames;92}939495std::string96GNEFileDialog::getDirectory() const {97return myFileSelector->getDirectory();98}99100101long102GNEFileDialog::onCmdAccept(FXObject*, FXSelector, void*) {103// update current folder104gCurrentFolder = myFileSelector->getDirectory().c_str();105// close dialog accepting changes106return closeDialogAccepting();107}108109110std::string111GNEFileDialog::assureExtension(const std::string& filename) const {112// get group of extensions selected in comboBox113const auto& extensions = myFileSelector->getFileExtension();114// iterate all groups of extensions115for (const auto& extension : extensions) {116// iterate over all extension to check if is the same extension117if (StringUtils::endsWith(filename, extension)) {118return filename;119}120}121// in this point, we have to give an extension (if exist)122if (extensions.size() > 0) {123return (filename + extensions.front());124} else {125return filename;126}127}128129/****************************************************************************/130131132