Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFileDialog.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Dialog used for opening/saving files
19/****************************************************************************/
20
24
25#include "GNEFileDialog.h"
26#include "GNEFileSelector.h"
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
32GNEFileDialog::GNEFileDialog(GNEApplicationWindow* applicationWindow, const std::string elementFile,
33 const std::vector<std::string>& extensions, GNEFileDialog::OpenMode openMode,
34 GNEFileDialog::ConfigType configType):
35 GNEDialog(applicationWindow, TLF("Save % as", elementFile), GUIIcon::SAVE,
36 DialogType::FILE, GNEDialog::Buttons::ACCEPT_CANCEL, GNEDialog::OpenType::MODAL,
37 GNEDialog::ResizeMode::RESIZABLE, 500, 300) {
38 // update title and icon if we are opening
39 if (openMode != GNEFileDialog::OpenMode::SAVE) {
41 updateTitle(TLF("Open %", elementFile));
42 }
43 // create file selector
44 myFileSelector = new GNEFileSelector(this, extensions, openMode, configType);
45 // retarget accept button to file selector
47 myAcceptButton->setSelector(FXFileSelector::ID_ACCEPT);
48 // check if we have saved settings in registry
49 setWidth(getApp()->reg().readIntEntry("GNEFileDialog", "width", getWidth()));
50 setHeight(getApp()->reg().readIntEntry("GNEFileDialog", "height", getHeight()));
51 myFileSelector->setFileBoxStyle(getApp()->reg().readUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle()));
52 myFileSelector->showHiddenFiles((getApp()->reg().readUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles()) == 1) ? TRUE : FALSE);
53 // set initial directory
54 if (gCurrentFolder.length() > 0) {
56 }
57 // open dialog without focusing the button
59}
60
61
63 getApp()->reg().writeIntEntry("GNEFileDialog", "width", getWidth());
64 getApp()->reg().writeIntEntry("GNEFileDialog", "height", getHeight());
65 getApp()->reg().writeUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle());
66 getApp()->reg().writeUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles());
67}
68
69
70void
72 if (dialogArgument->getCustomAction().size() > 0) {
73 myFileSelector->setFilter(dialogArgument->getIndex());
74 myFileSelector->setPath(dialogArgument->getCustomAction());
75 }
76}
77
78
79std::string
83
84
85std::vector<std::string>
87 std::vector<std::string> filenames;
88 // assure extension for each file
89 for (auto& filename : myFileSelector->getFilenames()) {
90 filenames.push_back(assureExtension(filename));
91 }
92 return filenames;
93}
94
95
96std::string
100
101
102long
103GNEFileDialog::onCmdAccept(FXObject*, FXSelector, void*) {
104 // update current folder
106 // close dialog accepting changes
107 return closeDialogAccepting();
108}
109
110
111std::string
112GNEFileDialog::assureExtension(const std::string& filename) const {
113 // get group of extensions selected in comboBox
114 const auto& extensions = myFileSelector->getFileExtension();
115 // iterate all groups of extensions
116 for (const auto& extension : extensions) {
117 // iterate over all extension to check if is the same extension
118 if (StringUtils::endsWith(filename, extension)) {
119 return filename;
120 }
121 }
122 // in this point, we have to give an extension (if exist)
123 if (extensions.size() > 0) {
124 return (filename + extensions.front());
125 } else {
126 return filename;
127 }
128}
129
130/****************************************************************************/
DialogType
FXString gCurrentFolder
The folder used as last.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ OPEN
open icons
#define TLF(string,...)
Definition MsgHandler.h:306
The main window of Netedit.
void updateIcon(GUIIcon newIcon)
update icon
void openDialog(FXWindow *focusableElement=nullptr)
open dialog
FXButton * myAcceptButton
accept button
Definition GNEDialog.h:149
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:58
void updateTitle(const std::string &newTitle)
update title
void runInternalTest(const InternalTestStep::DialogArgument *dialogArgument)
run internal test
std::vector< std::string > getFilenames() const
Return empty-string terminated list of selected file names, or NULL if none selected.
std::string getDirectory() const
Return directory.
OpenMode
file open mode
std::string assureExtension(const std::string &filename) const
check extensions
GNEFileSelector * myFileSelector
the file selector widget
long onCmdAccept(FXObject *, FXSelector, void *)
called when accept or yes button is pressed (can be reimplemented in children)
~GNEFileDialog()
destructor
ConfigType
config type
std::string getFilename() const
Return file name, if any.
GNEFileDialog(GNEApplicationWindow *applicationWindow, const std::string elementFile, const std::vector< std::string > &extensions, GNEFileDialog::OpenMode openMode, GNEFileDialog::ConfigType configType)
constructor
std::string getFilename() const
Return file name, if any.
void setFileBoxStyle(FXuint style)
Change file list style.
std::string getDirectory() const
Return directory.
const std::vector< std::string > & getFileExtension() const
get file extension
std::vector< std::string > getFilenames() const
get file names
void setDirectory(const FXString &path)
Change directory.
MFXTextFieldIcon * getFilenameTextField() const
get file name entry field
void setPath(const std::string &path)
set path (either file or directory, used for testing)
FXbool showHiddenFiles() const
Return TRUE if showing hidden files.
FXuint getFileBoxStyle() const
Return file list style.
void setFilter(const int index)
set file filter (used for testing)
dialog arguments, used for certain modal dialogs that can not be edited using tab
const std::string & getCustomAction() const
get custom action
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.