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, GNEDialog::Buttons::ACCEPT_CANCEL,
36 GNEDialog::OpenType::MODAL, GNEDialog::ResizeMode::RESIZABLE, 500, 300) {
37 // update title and icon if we are opening
38 if (openMode != GNEFileDialog::OpenMode::SAVE) {
40 updateTitle(TLF("Open %", elementFile));
41 }
42 // create file selector
43 myFileSelector = new GNEFileSelector(this, extensions, openMode, configType);
44 // retarget accept button to file selector
46 myAcceptButton->setSelector(FXFileSelector::ID_ACCEPT);
47 // check if we have saved settings in registry
48 setWidth(getApp()->reg().readIntEntry("GNEFileDialog", "width", getWidth()));
49 setHeight(getApp()->reg().readIntEntry("GNEFileDialog", "height", getHeight()));
50 myFileSelector->setFileBoxStyle(getApp()->reg().readUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle()));
51 myFileSelector->showHiddenFiles((getApp()->reg().readUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles()) == 1) ? TRUE : FALSE);
52 // set initial directory
53 if (gCurrentFolder.length() > 0) {
55 }
56 // open dialog without focusing the button
58}
59
60
62 getApp()->reg().writeIntEntry("GNEFileDialog", "width", getWidth());
63 getApp()->reg().writeIntEntry("GNEFileDialog", "height", getHeight());
64 getApp()->reg().writeUnsignedEntry("GNEFileDialog", "style", myFileSelector->getFileBoxStyle());
65 getApp()->reg().writeUnsignedEntry("GNEFileDialog", "showhidden", myFileSelector->showHiddenFiles());
66}
67
68
69void
71 // not yet finish
72}
73
74
75std::string
79
80
81std::vector<std::string>
83 std::vector<std::string> filenames;
84 // assure extension for each file
85 for (auto& filename : myFileSelector->getFilenames()) {
86 filenames.push_back(assureExtension(filename));
87 }
88 return filenames;
89}
90
91
92std::string
96
97
98long
99GNEFileDialog::onCmdAccept(FXObject*, FXSelector, void*) {
100 // update current folder
102 // close dialog accepting changes
103 return closeDialogAccepting();
104}
105
106
107std::string
108GNEFileDialog::assureExtension(const std::string& filename) const {
109 // get group of extensions selected in comboBox
110 const auto& extensions = myFileSelector->getFileExtension();
111 // iterate all groups of extensions
112 for (const auto& extension : extensions) {
113 // iterate over all extension to check if is the same extension
114 if (StringUtils::endsWith(filename, extension)) {
115 return filename;
116 }
117 }
118 // in this point, we have to give an extension (if exist)
119 if (extensions.size() > 0) {
120 return (filename + extensions.front());
121 } else {
122 return filename;
123 }
124}
125
126/****************************************************************************/
FXString gCurrentFolder
The folder used as last.
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ OPEN
open icons
@ SAVE
save icons
#define TLF(string,...)
Definition MsgHandler.h:307
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:138
long closeDialogAccepting()
close dialog accepting the changes
OpenType
Open dialog type.
Definition GNEDialog.h:55
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
FXbool showHiddenFiles() const
Return TRUE if showing hidden files.
FXuint getFileBoxStyle() const
Return file list style.
dialog arguments, used for certain modal dialogs that can not be edited using tab
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.