15 #include "internal/org_mitk_gui_qt_application_Activator.h" 25 #include <QFileDialog> 31 auto context = mitk::org_mitk_gui_qt_application_Activator::GetContext();
33 if (
nullptr == context)
38 if (!dataStorageServiceReference)
43 if (
nullptr == dataStorageService)
48 if (dataStorageReference.IsNull())
51 return dataStorageReference->GetDataStorage();
56 auto dataStorage = GetDataStorage();
58 if (dataStorage.IsNull())
63 if (selectedNodes->empty())
66 return selectedNodes->front();
69 QString GetPathOfFirstSelectedNode()
71 auto firstSelectedNode = GetFirstSelectedNode();
73 if (firstSelectedNode.IsNull())
76 auto data = firstSelectedNode->GetData();
81 auto pathProperty = data->GetConstProperty(
"path");
83 if (pathProperty.IsNull())
86 return QFileInfo(QString::fromStdString(pathProperty->GetValueAsString())).canonicalPath();
90 class QmitkFileOpenActionPrivate
97 action->setText(
"&Open File...");
98 action->setToolTip(
"Open data files (images, surfaces,...)");
100 QObject::connect(action, SIGNAL(triggered(
bool)), action, SLOT(
Run()));
106 if (prefService !=
nullptr)
113 QString GetLastFileOpenPath()
const 118 return prefs->Get(
"LastFileOpenPath",
"");
123 void SetLastFileOpenPath(
const QString& path)
const 128 prefs->Put(
"LastFileOpenPath", path);
133 bool GetOpenEditor()
const 138 return prefs->GetBool(
"OpenEditor",
true);
148 , d(new QmitkFileOpenActionPrivate)
155 , d(new QmitkFileOpenActionPrivate)
162 : QAction(nullptr), d(new QmitkFileOpenActionPrivate)
164 d->Init(window,
this);
174 auto path = GetPathOfFirstSelectedNode();
177 path = d->GetLastFileOpenPath();
180 QStringList fileNames = QFileDialog::getOpenFileNames(
nullptr,
"Open",
184 if (fileNames.empty())
189 d->SetLastFileOpenPath(fileNames.front());
~QmitkFileOpenAction() override
virtual IDataStorageReference::Pointer GetDataStorage() const =0
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
static void LoadFiles(const QStringList &fileNames, berry::IWorkbenchWindow::Pointer wnd, bool openEditor=true)
static QString GetFileOpenFilterString()
GetFilterString.
static Pointer New(const char *_arg)
void Run(berry::IWorkbenchPartSite::Pointer workbenchPartSite, mitk::DataStorage::Pointer dataStorage)
berry::SmartPointer< Self > Pointer
QmitkFileOpenAction(berry::IWorkbenchWindow::Pointer window)
ObjectType * GetPointer() const