QLayout* aLayout = myParent->layout();
if (aLayout)
aLayout->addWidget (GetMainWindow());
+
+ if (!myOpenedFileName.isEmpty())
+ myParent->setObjectName(myOpenedFileName);
}
}
// =======================================================================
void DFBrowser_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
- theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
if (myParent)
myParent->setObjectName (isSTEPFileName ? QString (TCollection_AsciiString (theFileName).ToCString()) : getWindowTitle());
+ else
+ myOpenedFileName = isSTEPFileName ? QString(TCollection_AsciiString(theFileName).ToCString()) : getWindowTitle();
if (anApplication.IsNull())
{
DFBrowser_Thread* myThread; //!< Threads manipulator, starting thread items, listens finalizing
ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
Handle(TInspectorAPI_PluginParameters) myParameters; //!< contains application, context, files that should be opened
+ QString myOpenedFileName; //!< cached name of opened file between parent is set, apply it by parent setting and nullify
};
#endif
// =======================================================================
void ShapeView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
- theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;
#define TInspector_Communicator_H
#include <inspector/TInspector_Window.hxx>
+#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <NCollection_List.hxx>
#include <Standard.hxx>
//! \param theStream stream for output
void Dump (Standard_OStream& theStream) const { return myWindow->Dump (theStream); }
-private:
+ //! Returns plugins parameters container
+ Handle(TInspectorAPI_PluginParameters) const GetPluginParameters() { return myWindow->GetPluginParameters(); }
+private:
TInspector_Window* myWindow; //!< current window
};
{ myPreferences->SetPreferences (thePluginName, theItem); }
//! Store plugin preferences into a preferences file
- void StorePreferences() { myPreferences->StorePreferences(); }
+ virtual void StorePreferences() Standard_OVERRIDE { myPreferences->StorePreferences(); }
//! Remove plugin preferences file
void RemovePreferences() { myPreferences->RemovePreferences(); }
void TInspector_Preferences::GetPreferences (const TCollection_AsciiString& thePluginName,
TInspectorAPI_PreferencesDataMap& theItem)
{
- theItem.Clear();
if (!myIsLoadedPreferences)
{
loadPreferences();
// =======================================================================
void TInspector_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
- theItem.Clear();
- theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveGeometry()).toStdString().c_str());
+ theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveGeometry()).toStdString().c_str());
}
// =======================================================================
if (!anInfo.myCommunicator)
continue;
+ aParameters->GetPreferences (anInfo.myName, aPreferences);
anInfo.myCommunicator->GetPreferences (aPreferences);
myParameters->SetPreferences (anInfo.myName, aPreferences);
}
//! \return path
TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); }
+ //! Returns plugins parameters container
+ //! \return instance of parameters container
+ Handle(TInspectorAPI_PluginParameters) GetPluginParameters() const { return myParameters; }
+
//! Returns plugin preferences: dock widgets state, tree view columns.
//! \param theItem container of preference elements
Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
Standard_EXPORT virtual void SetPreferences (const TCollection_AsciiString& thePluginName,
const TInspectorAPI_PreferencesDataMap& theItem) = 0;
+ //! Store plugin preferences into a preferences file
+ Standard_EXPORT virtual void StorePreferences() = 0;
+
//! Converts a Shape parameters excepting TShape into a string value
//! \param theShape processed shape
//! \return string instance
// function : fileNameInDataDir
// purpose :
// =======================================================================
-TCollection_AsciiString fileNameInDataDir(const TCollection_AsciiString& theEnvironmentDir,
- const TCollection_AsciiString& theName)
+TCollection_AsciiString fileNameInDataDir (const TCollection_AsciiString& theEnvironmentDir,
+ const TCollection_AsciiString& theName)
{
- OSD_Environment anEnvironment(theEnvironmentDir);
+ OSD_Environment anEnvironment (theEnvironmentDir);
TCollection_AsciiString aFileName = anEnvironment.Value();
- aFileName += TCollection_AsciiString("/") + theName;
+ aFileName += TCollection_AsciiString ("/") + theName;
return aFileName;
}
void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator,
TInspectorEXE_OpenButton* theButtonControl)
{
- if (theName.IsEqual ("TKDFBrowser"))
+ QStringList aRecentlyOpenedFiles;
+ TInspectorEXE_OpenFileDialog::GetPluginRecentlyOpenedFiles (theName, theCommunicator, aRecentlyOpenedFiles);
+ TCollection_AsciiString aFileName, anAdditionalFileName;
+ if (!aRecentlyOpenedFiles.isEmpty())
+ aFileName = TCollection_AsciiString (aRecentlyOpenedFiles.last().toUtf8().data());
+ if (aFileName.IsEmpty())
{
- theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step"));
- theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step"));
- }
- else if (theName.IsEqual ("TKShapeView"))
- {
- theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep"));
- theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ"));
- }
- else if (theName.IsEqual ("TKVInspector"))
- {
- theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep"));
- theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep"));
- theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ"));
+ if (theName.IsEqual ("TKDFBrowser"))
+ aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step");
+ else if (theName.IsEqual ("TKShapeView"))
+ aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep");
+ else if (theName.IsEqual ("TKVInspector"))
+ {
+ aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep");
+ anAdditionalFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep");
+ }
+ aRecentlyOpenedFiles.append (aFileName.ToCString());
+ if (!anAdditionalFileName.IsEmpty())
+ aRecentlyOpenedFiles.append (anAdditionalFileName.ToCString());
}
+ theCommunicator->OpenFile (theName, aFileName.ToCString());
+ if (!anAdditionalFileName.IsEmpty())
+ theCommunicator->OpenFile (theName, anAdditionalFileName);
+
+ theButtonControl->SetPluginRecentlyOpenedFiles (theName, aRecentlyOpenedFiles);
}
// =======================================================================
const int MARGIN_DIALOG = 4;
const int SPACING_DIALOG = 2;
+const int RECENT_FILES_CACHE_SIZE = 10;
+
TInspector_Communicator* MyCommunicator;
// =======================================================================
if (aPluginName.IsEmpty())
return;
- QString aDataDirName = QDir::currentPath();
- if (myDefaultDirs.IsBound (aPluginName))
- aDataDirName = myDefaultDirs.Find (aPluginName).ToCString();
+ QStringList aPluginRecentlyOpenedFiles;
+ if (myRecentlyOpenedFiles.contains(aPluginName))
+ {
+ QStringList aFileNames = myRecentlyOpenedFiles[aPluginName];
+ for (int i = 0; i < aFileNames.size(); i++)
+ {
+ QFileInfo aFileInfo (aFileNames[i]);
+ if (aFileInfo.exists() && aFileInfo.isFile())
+ aPluginRecentlyOpenedFiles.append(aFileInfo.absoluteFilePath());
+ }
+ }
- QString aFileName = TInspectorEXE_OpenFileDialog::OpenFile (0, aDataDirName);
+ QString aFileName = TInspectorEXE_OpenFileDialog::OpenFile (0, aPluginRecentlyOpenedFiles);
aFileName = QDir().toNativeSeparators (aFileName);
if (!aFileName.isEmpty()) {
QApplication::setOverrideCursor (Qt::WaitCursor);
TInspectorEXE_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data()));
+
+ QFileInfo aFileInfo (aFileName);
+ if (!aPluginRecentlyOpenedFiles.contains (aFileInfo.absoluteFilePath()))
+ {
+ myRecentlyOpenedFiles[aPluginName].append (aFileInfo.absoluteFilePath());
+ for (int i = 0; i < myRecentlyOpenedFiles[aPluginName].size() - RECENT_FILES_CACHE_SIZE; i++)
+ myRecentlyOpenedFiles[aPluginName].removeFirst();
+ TInspectorEXE_OpenFileDialog::SetPluginRecentlyOpenedFiles (aPluginName,
+ TInspectorEXE_OpenFileDialog::Communicator(), myRecentlyOpenedFiles[aPluginName]);
+
+ TInspectorEXE_OpenFileDialog::Communicator()->GetPluginParameters()->StorePreferences();
+ }
+
QApplication::restoreOverrideCursor();
}
}
// function : Constructor
// purpose :
// =======================================================================
-TInspectorEXE_OpenFileDialog::TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName)
-: QDialog(theParent), myDataDir (theDataDirName)
+TInspectorEXE_OpenFileDialog::TInspectorEXE_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles)
+: QDialog (theParent), myRecentlyOpenedFiles (theRecentlyOpenedFiles)
{
- setWindowTitle (theDataDirName);
+ setWindowTitle (tr ("Open File"));
QVBoxLayout* aDialogLay = new QVBoxLayout (this);
changeMargins (aDialogLay);
- // Title label
- QLabel* aTitleLabel = new QLabel (this);
- aTitleLabel->setText (tr ("Open File"));
- aDialogLay->addWidget (aTitleLabel);
-
// Samples View
QGroupBox* aSamplesBox = new QGroupBox (this);
- aSamplesBox->setTitle (tr ("Samples"));
+ aSamplesBox->setTitle (tr ("Recent files"));
aDialogLay->addWidget (aSamplesBox);
QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox);
changeMargins (aSampleLay);
- mySamplesView = createTableView (readSampleNames());
+ mySamplesView = createTableView (theRecentlyOpenedFiles);
aSampleLay->addWidget (mySamplesView);
// Select file
aSelectFileBtn->setIcon (QIcon (":folder_open.png"));
aSelectFileLay->addWidget (aSelectFileBtn, 1, 1);
- myFolderApplyOpen = new QToolButton (aSelectFileBox);
- myFolderApplyOpen->setIcon (QIcon (":folder_import.png"));
- myFolderApplyOpen->setIconSize (QSize (ICON_SIZE, ICON_SIZE));
- myFolderApplyOpen->setEnabled (false);
- aSelectFileLay->addWidget (myFolderApplyOpen, 0, 2, 2, 1);
-
- connect (mySelectedName, SIGNAL (textChanged (const QString&)),
- this, SLOT (onNameChanged (const QString&)));
connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked()));
- connect (myFolderApplyOpen, SIGNAL (clicked()), this, SLOT (onApplySelectClicked()));
+ connect (mySelectedName, SIGNAL (returnPressed()), this, SLOT (onApplySelectClicked()));
resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT);
}
// function : OpenFile
// purpose :
// =======================================================================
-QString TInspectorEXE_OpenFileDialog::OpenFile (QWidget* theParent, const QString& theDataDirName)
+QString TInspectorEXE_OpenFileDialog::OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles)
{
QString aFileName;
- TInspectorEXE_OpenFileDialog* aDialog = new TInspectorEXE_OpenFileDialog(theParent, theDataDirName);
+ TInspectorEXE_OpenFileDialog* aDialog = new TInspectorEXE_OpenFileDialog (theParent, theRecentlyOpenedFiles);
if (aDialog->exec() == QDialog::Accepted)
aFileName = aDialog->GetFileName();
return MyCommunicator;
}
+// =======================================================================
+// function : GetPluginRecentlyOpenedFiles
+// purpose :
+// =======================================================================
+void TInspectorEXE_OpenFileDialog::GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
+ TInspector_Communicator* theCommunicator,
+ QStringList& theFileNames)
+{
+ Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters();
+ TInspectorAPI_PreferencesDataMap aPreferencesItem;
+ aParameters->GetPreferences (thePluginName, aPreferencesItem);
+
+ for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (aPreferencesItem); anItemIt.More(); anItemIt.Next())
+ {
+ if (!anItemIt.Key().IsEqual("recently_opened_files"))
+ continue;
+ theFileNames = QString(anItemIt.Value().ToCString()).split(";", QString::SkipEmptyParts);
+ if (theFileNames.size() > RECENT_FILES_CACHE_SIZE)
+ for (int i = 0; i < theFileNames.size() - RECENT_FILES_CACHE_SIZE; i++)
+ theFileNames.removeFirst();
+ break;
+ }
+}
+
+// =======================================================================
+// function : SetPluginRecentlyOpenedFiles
+// purpose :
+// =======================================================================
+void TInspectorEXE_OpenFileDialog::SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
+ TInspector_Communicator* theCommunicator,
+ QStringList& theFileNames)
+{
+ Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters();
+
+ TInspectorAPI_PreferencesDataMap aPreferencesItem;
+ aParameters->GetPreferences (thePluginName, aPreferencesItem);
+ aPreferencesItem.Bind ("recently_opened_files", TCollection_AsciiString (theFileNames.join (";").toUtf8().data()));
+
+ aParameters->SetPreferences (thePluginName, aPreferencesItem);
+}
+
// =======================================================================
// function : onSampleSelectionChanged
// purpose :
accept();
}
-// =======================================================================
-// function : onNameChanged
-// purpose :
-// =======================================================================
-void TInspectorEXE_OpenFileDialog::onNameChanged (const QString& theText)
-{
- QFileInfo aFileInfo (theText);
- bool anExists = aFileInfo.exists() && aFileInfo.isFile();
- myFolderApplyOpen->setEnabled (anExists);
-}
-
// =======================================================================
// function : onSelectClicked
// purpose :
// =======================================================================
void TInspectorEXE_OpenFileDialog::onApplySelectClicked()
{
+ QString aFileName = mySelectedName->text();
+
+ QFileInfo aFileInfo (aFileName);
+ if (!aFileInfo.exists() || !aFileInfo.isFile())
+ return;
+
myFileName = mySelectedName->text();
accept();
}
aModel->Init (theFileNames);
return aModel;
}
-
-// =======================================================================
-// function : readSampleNames
-// purpose :
-// =======================================================================
-QStringList TInspectorEXE_OpenFileDialog::readSampleNames()
-{
- QStringList aNames;
-
- QDir aDir(myDataDir);
- aDir.setSorting(QDir::Name);
-
- QFileInfoList aDirEntries = aDir.entryInfoList();
- for (int aDirId = 0; aDirId < aDirEntries.size(); ++aDirId)
- {
- QFileInfo aFileInfo = aDirEntries.at(aDirId);
- if (aFileInfo.isFile())
- aNames.append (aFileInfo.absoluteFilePath());
- }
- return aNames;
-}
#ifndef TInspectorEXE_OpenFileDialog_H
#define TInspectorEXE_OpenFileDialog_H
+#include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
+
#include <NCollection_DataMap.hxx>
+#include <NCollection_List.hxx>
#include <TCollection_AsciiString.hxx>
#include <Standard_WarningsDisable.hxx>
QPushButton* StartButton();
//! Sets the default directory of plugin.
- void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir)
- { myDefaultDirs.Bind (thePluginName, theDefaultDir); }
+ void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
+ const QStringList& theRecentlyOpenedFiles)
+ { myRecentlyOpenedFiles[thePluginName] = theRecentlyOpenedFiles; }
private slots:
private:
QPushButton* myStartButton; //!< processed button
- NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> myDefaultDirs; //!< plugins default directories
+ //!< plugins recently opened files
+ QMap<TCollection_AsciiString, QStringList> myRecentlyOpenedFiles;
};
//! \class TInspectorEXE_OpenFileDialog
private:
//! Constructor
- TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName);
+ Standard_EXPORT TInspectorEXE_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles);
public:
//! \param theParent a parent for the new dialog
//! \param theDataDirName path to default samples directory
//! \returns a file name from the open file dialog
- static QString OpenFile (QWidget* theParent, const QString& theDataDirName);
+ Standard_EXPORT static QString OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles);
//! Returns selection name from the dialog
QString GetFileName() const { return myFileName; }
//! Returns communicator, if this is the first call, create a communicator instance
- static TInspector_Communicator* Communicator();
+ Standard_EXPORT static TInspector_Communicator* Communicator();
+
+ //! Returns preferences: previous opened documents.
+ //! \param thePluginName name of the plugin
+ //! \param theCommunicator source of preferences
+ //! \param theFileNames [out] container of recently opened file names
+ Standard_EXPORT static void GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
+ TInspector_Communicator* theCommunicator,
+ QStringList& theFileNames);
+
+ //! Sets preferences: previous opened documents.
+ //! \param thePluginName name of the plugin
+ //! \param theCommunicator source of preferences
+ //! \param theFileNames container of recently opened file names to be set into communicator preferences
+ Standard_EXPORT static void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName,
+ TInspector_Communicator* theCommunicator,
+ QStringList& theFileNames);
private slots:
//! Stores name of selected sample file
void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected);
- //! Updates enabling state of Open file button, it is enabled if the file by the entered path exists
- //! \param theText a file name text in line edit
- void onNameChanged (const QString& theText);
-
//! Open file dialog to select a file name. Fills file name line, enable import button
void onSelectClicked();
//! \return model
QAbstractItemModel* createModel (const QStringList& theFileNames);
- //! Generates container of file names in samples directory
- //! \return container of names
- QStringList readSampleNames();
-
private:
- QString myDataDir; //!< samples directory
+ QStringList myRecentlyOpenedFiles; //!< recently opened files
QString myFileName; //!< result file name
QTableView* mySamplesView; //! <view of sample file names
QLineEdit* mySelectedName; //!< alternative control to open file
- QToolButton* myFolderApplyOpen; //! button to open file
};
#endif
thePainter->fillRect (theOption.rect, myColor);
// action icon for all indices before the last one
- QIcon anIcon (":/icons/folder_import.png");
+ QIcon anIcon (":folder_import.png");
QSize anIconSize (ICON_SIZE, ICON_SIZE);
int aDX = (theOption.rect.width() - anIconSize.width()) / 2;
int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin);
// =======================================================================
void VInspector_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem)
{
- theItem.Clear();
theItem.Bind ("geometry", TreeModel_Tools::ToString (myMainWindow->saveState()).toStdString().c_str());
QMap<QString, QString> anItems;