mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add and delete of script directory from context menu
p4#: 21461
This commit is contained in:
parent
0b2e19926d
commit
2e2212d7ea
@ -28,6 +28,7 @@
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RimInputPropertyCollection.h"
|
||||
#include "RimExportInputPropertySettings.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiuPreferencesDialog.h"
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
#include "RimInputCase.h"
|
||||
@ -215,6 +216,14 @@ void RimUiTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||
menu.addAction(QString("New Statistics Case"), this, SLOT(slotNewStatisticsCase()));
|
||||
}
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
else if (dynamic_cast<RimScriptCollection*>(uiItem->dataObject().p()) || dynamic_cast<RimCalcScript*>(uiItem->dataObject().p()))
|
||||
{
|
||||
QMenu menu;
|
||||
menu.addAction(QString("Add Script Path"), this, SLOT(slotAddScriptPath()));
|
||||
menu.addAction(QString("Delete Script Path"), this, SLOT(slotDeleteScriptPath()));
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
}
|
||||
@ -1302,3 +1311,60 @@ void RimUiTreeView::setExpandedUpToRoot(const QModelIndex& itemIndex)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::slotAddScriptPath()
|
||||
{
|
||||
QString selectedFolder = QFileDialog::getExistingDirectory(this, "Select script folder");
|
||||
if (!selectedFolder.isEmpty())
|
||||
{
|
||||
QString filePathString = RiaApplication::instance()->preferences()->scriptDirectories();
|
||||
|
||||
QChar separator(';');
|
||||
if (!filePathString.isEmpty() && !filePathString.endsWith(separator, Qt::CaseInsensitive))
|
||||
{
|
||||
filePathString += separator;
|
||||
}
|
||||
|
||||
filePathString += selectedFolder;
|
||||
|
||||
RiaApplication::instance()->preferences()->scriptDirectories = filePathString;
|
||||
RiaApplication::instance()->applyPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimUiTreeView::slotDeleteScriptPath()
|
||||
{
|
||||
RimUiTreeModelPdm* myModel = dynamic_cast<RimUiTreeModelPdm*>(model());
|
||||
caf::PdmUiTreeItem* uiItem = myModel->getTreeItemFromIndex(currentIndex());
|
||||
if (uiItem)
|
||||
{
|
||||
if (dynamic_cast<RimScriptCollection*>(uiItem->dataObject().p()))
|
||||
{
|
||||
RimScriptCollection* scriptCollection = dynamic_cast<RimScriptCollection*>(uiItem->dataObject().p());
|
||||
QString toBeRemoved = scriptCollection->directory;
|
||||
|
||||
QString originalFilePathString = RiaApplication::instance()->preferences()->scriptDirectories();
|
||||
QString filePathString = originalFilePathString.remove(toBeRemoved);
|
||||
|
||||
// Remove duplicate separators
|
||||
QChar separator(';');
|
||||
QString regExpString = QString("%1{1,5}").arg(separator);
|
||||
filePathString.replace(QRegExp(regExpString), separator);
|
||||
|
||||
// Remove separator at end
|
||||
if (filePathString.endsWith(separator))
|
||||
{
|
||||
filePathString = filePathString.left(filePathString.size() - 1);
|
||||
}
|
||||
|
||||
RiaApplication::instance()->preferences()->scriptDirectories = filePathString;
|
||||
RiaApplication::instance()->applyPreferences();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,9 @@ private slots:
|
||||
void slotAddCaseGroup();
|
||||
void slotDeleteObjectFromPdmPointersField();
|
||||
|
||||
void slotAddScriptPath();
|
||||
void slotDeleteScriptPath();
|
||||
|
||||
void slotCopyPdmObjectToClipboard();
|
||||
void slotPastePdmObjects();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user