22const QString DATA{
"pbData"};
23const QString SCRIPT{
"pbScript"};
24const QString EXTENSIONS{
"pbExt"};
28const std::string DATASEARCH_DIRS{
"datasearch.directories"};
29const std::string PYTHONSCRIPTS_DIRS{
"pythonscripts.directories"};
30const std::string USERPYTHONPLUGINS_DIRS{
"user.python.plugins.directories"};
31const std::string DATASEARCH_ARCHIVE{
"datasearch.searcharchive"};
32const std::string DEFAULT_FACILITY{
"default.facility"};
33const std::string DEFAULTSAVE_DIR{
"defaultsave.directory"};
37const auto LastDirectory{
"ManageUserSettings/last_directory"};
41const QString HELP_ID{
"ManageUserDirectories"};
44QPointer<ManageUserDirectories> CURRENTLY_OPEN_MUD;
52 if (CURRENTLY_OPEN_MUD.isNull()) {
54 CURRENTLY_OPEN_MUD->show();
56 CURRENTLY_OPEN_MUD->raise();
58 return CURRENTLY_OPEN_MUD;
66 setAttribute(Qt::WA_DeleteOnClose);
95 connect(
m_uiForm.pbDataRemDir, SIGNAL(clicked()),
this, SLOT(
remDir()));
96 connect(
m_uiForm.pbScriptRemDir, SIGNAL(clicked()),
this, SLOT(
remDir()));
97 connect(
m_uiForm.pbExtRemoveDir, SIGNAL(clicked()),
this, SLOT(
remDir()));
98 connect(
m_uiForm.pbDataMoveUp, SIGNAL(clicked()),
this, SLOT(
moveUp()));
99 connect(
m_uiForm.pbScriptMoveUp, SIGNAL(clicked()),
this, SLOT(
moveUp()));
100 connect(
m_uiForm.pbExtMoveUp, SIGNAL(clicked()),
this, SLOT(
moveUp()));
101 connect(
m_uiForm.pbDataMoveDown, SIGNAL(clicked()),
this, SLOT(
moveDown()));
102 connect(
m_uiForm.pbScriptMoveDown, SIGNAL(clicked()),
this, SLOT(
moveDown()));
112 auto &config = ConfigService::Instance();
113 auto populateListWidget = [&config](QListWidget *widget,
const std::string &key) {
114 const auto directories = QString::fromStdString(config.getString(key)).trimmed();
115 const auto items = directories.split(
";", Qt::SkipEmptyParts);
117 widget->addItems(items);
120 populateListWidget(
m_uiForm.lwDataSearchDirs, ConfigKeys::DATASEARCH_DIRS);
121 populateListWidget(
m_uiForm.lwScriptSearchDirs, ConfigKeys::PYTHONSCRIPTS_DIRS);
122 populateListWidget(
m_uiForm.lwExtSearchDirs, ConfigKeys::USERPYTHONPLUGINS_DIRS);
125 const auto archive = QString::fromStdString(config.getString(ConfigKeys::DATASEARCH_ARCHIVE)).trimmed().toLower();
126 const auto defaultFacility =
127 QString::fromStdString(config.getString(ConfigKeys::DEFAULT_FACILITY)).trimmed().toUpper();
128 m_uiForm.cbSearchArchive->addItem(QString(
"default facility only - ") + defaultFacility);
129 m_uiForm.cbSearchArchive->addItem(
"all");
130 m_uiForm.cbSearchArchive->addItem(
"off");
131 if (archive ==
"on") {
132 m_uiForm.cbSearchArchive->setCurrentIndex(0);
133 }
else if (archive ==
"all") {
134 m_uiForm.cbSearchArchive->setCurrentIndex(1);
135 }
else if (archive ==
"off") {
136 m_uiForm.cbSearchArchive->setCurrentIndex(2);
138 m_uiForm.cbSearchArchive->addItem(
"custom - " + archive.toUpper());
139 m_uiForm.cbSearchArchive->setCurrentIndex(3);
143 const auto saveDir = QString::fromStdString(config.getString(ConfigKeys::DEFAULTSAVE_DIR)).trimmed();
144 m_uiForm.leDefaultSave->setText(saveDir);
151 auto &config = ConfigService::Instance();
153 QString newSearchArchive =
m_uiForm.cbSearchArchive->currentText().toLower();
154 if (newSearchArchive ==
"all" || newSearchArchive ==
"off") {
156 }
else if (newSearchArchive.startsWith(
"default facility only")) {
157 newSearchArchive =
"on";
169 auto toConfigPath = [](QString path) {
172 auto unixStylePath = path.replace(
'\\',
'/');
173 if (!unixStylePath.endsWith(
'/'))
174 unixStylePath.append(
'/');
175 return unixStylePath;
177 auto toConfigString = [&toConfigPath](QListWidget *itemsWidget) {
179 for (
int i = 0; i < itemsWidget->count(); i++) {
180 const auto path = itemsWidget->item(i)->text().trimmed();
182 paths.append(toConfigPath(path));
184 return paths.join(
";").toStdString();
188 config.setString(ConfigKeys::DATASEARCH_ARCHIVE, newSearchArchive.toStdString());
189 config.setString(ConfigKeys::DATASEARCH_DIRS, toConfigString(
m_uiForm.lwDataSearchDirs));
190 config.setString(ConfigKeys::DEFAULTSAVE_DIR, toConfigPath(
m_uiForm.leDefaultSave->text().trimmed()).toStdString());
192 config.setString(ConfigKeys::PYTHONSCRIPTS_DIRS, toConfigString(
m_uiForm.lwScriptSearchDirs));
193 config.setString(ConfigKeys::USERPYTHONPLUGINS_DIRS, toConfigString(
m_uiForm.lwExtSearchDirs));
196 config.saveConfig(config.getUserFilename());
205 const auto objectName = sender->objectName();
206 if (objectName.contains(ButtonPrefix::DATA)) {
208 }
else if (objectName.contains(ButtonPrefix::SCRIPT)) {
210 }
else if (objectName.contains(ButtonPrefix::EXTENSIONS)) {
234 QLineEdit *input(
nullptr);
238 }
else if (
m_uiForm.tabWidget->currentWidget() ==
m_uiForm.tabPythonDirectories) {
239 input =
m_uiForm.leDirectoryPathPython;
242 if (input && input->text() !=
"") {
253 const auto lastDirectory = settings.value(QSettingsKeys::LastDirectory,
"").toString();
255 const auto newDir = QFileDialog::getExistingDirectory(
this, tr(
"Select New Data Directory"), lastDirectory,
256 QFileDialog::ShowDirsOnly);
258 if (!newDir.isEmpty()) {
259 settings.setValue(QSettingsKeys::LastDirectory, newDir);
267 for (
auto &i : selected) {
276 for (
auto &i : selected) {
277 int index = list->row(i);
279 QListWidgetItem *move = list->takeItem(
index);
280 list->insertItem(
index - 1, move);
282 list->setCurrentItem(i);
289 int count = list->count();
291 for (
auto &i : selected) {
292 int index = list->row(i);
294 QListWidgetItem *move = list->takeItem(
index);
295 list->insertItem(
index + 1, move);
297 list->setCurrentItem(i);
304 auto lastDirectory =
m_uiForm.leDefaultSave->text().trimmed();
305 if (lastDirectory.isEmpty())
306 lastDirectory = settings.value(QSettingsKeys::LastDirectory,
"").toString();
308 const auto newDir = QFileDialog::getExistingDirectory(
this, tr(
"Select New Default Save Directory"), lastDirectory,
309 QFileDialog::ShowDirsOnly);
311 if (!newDir.isEmpty()) {
312 const auto path = newDir + QDir::separator();
313 settings.setValue(QSettingsKeys::LastDirectory, path);
314 m_uiForm.leDefaultSave->setText(path);
std::map< DeltaEMode::Type, std::string > index
static void showCustomInterface(const QString &name, const QString &area=QString(), const QString §ion=QString())
Access and update the user directory settings within the Mantid config service.
void saveProperties()
Save the current contents of the widgets back to the main config.
void confirmClicked()
Persist the properties to the config store and close the dialog.
void loadProperties()
Load config properties into the form widgets.
void browseToDirectory()
Browse to find a new directory.
void selectSaveDir()
Find an existing directory to be used for the save directory path.
void enableSaveToFile(bool enabled)
Control if the config service changes are persisted to the user file.
void moveDown()
Lower an item down in the list based on the sender of the signal.
virtual void initLayout()
Create the UI layout, fill the widgets and connect the relevant signals.
static ManageUserDirectories * openManageUserDirectories()
Show the default dialog or raise the existing one if it exists.
QListWidget * listWidget(QObject *object)
Return the QListWidget related to the given sender.
void moveUp()
Raise an item up in the list based on the sender of the signal.
ManageUserDirectories(QWidget *parent=nullptr)
Constructor.
void helpClicked()
Show the help for ManageUserDirectories.
void cancelClicked()
Close the dialog without saving the configuration.
void addDirectory()
Handle the add directory button to take the text from a text box based on the signal sender to the co...
Ui::ManageUserDirectories m_uiForm
void remDir()
Remove a directory from the list based on the sender.
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...