improved handling of the FileSystemWatcher handling
This commit is contained in:
parent
5fb0503f2a
commit
8afe98617a
@ -81,6 +81,7 @@ PTextEdit::PTextEdit( QWidget *parent, Qt::WindowFlags f )
|
|||||||
{
|
{
|
||||||
fAdmin = new PAdmin();
|
fAdmin = new PAdmin();
|
||||||
|
|
||||||
|
fFileSystemWatcherActive = true;
|
||||||
fFileSystemWatcher = new QFileSystemWatcher();
|
fFileSystemWatcher = new QFileSystemWatcher();
|
||||||
if (fFileSystemWatcher == 0) {
|
if (fFileSystemWatcher == 0) {
|
||||||
QMessageBox::information(this, "**ERROR**", "Couldn't invoke QFileSystemWatcher!");
|
QMessageBox::information(this, "**ERROR**", "Couldn't invoke QFileSystemWatcher!");
|
||||||
@ -93,8 +94,6 @@ PTextEdit::PTextEdit( QWidget *parent, Qt::WindowFlags f )
|
|||||||
fMsr2DataParam = 0;
|
fMsr2DataParam = 0;
|
||||||
fFindReplaceData = 0,
|
fFindReplaceData = 0,
|
||||||
|
|
||||||
// fFileWatcher = 0;
|
|
||||||
|
|
||||||
fKeepMinuit2Output = false;
|
fKeepMinuit2Output = false;
|
||||||
fTitleFromDataFile = fAdmin->getTitleFromDataFileFlag();
|
fTitleFromDataFile = fAdmin->getTitleFromDataFileFlag();
|
||||||
fEnableMusrT0 = fAdmin->getEnableMusrT0Flag();
|
fEnableMusrT0 = fAdmin->getEnableMusrT0Flag();
|
||||||
@ -111,6 +110,7 @@ PTextEdit::PTextEdit( QWidget *parent, Qt::WindowFlags f )
|
|||||||
|
|
||||||
textFamily(fAdmin->getFontName());
|
textFamily(fAdmin->getFontName());
|
||||||
textSize(QString("%1").arg(fAdmin->getFontSize()));
|
textSize(QString("%1").arg(fAdmin->getFontSize()));
|
||||||
|
fFontChanging = false;
|
||||||
|
|
||||||
QPixmap image0(":/images/musrfit.xpm");
|
QPixmap image0(":/images/musrfit.xpm");
|
||||||
setWindowIcon( image0 );
|
setWindowIcon( image0 );
|
||||||
@ -566,7 +566,7 @@ void PTextEdit::load( const QString &f, const int index )
|
|||||||
if ( !QFile::exists( f ) )
|
if ( !QFile::exists( f ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QFileInfo info(f);
|
// QFileInfo info(f);
|
||||||
|
|
||||||
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
|
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
|
||||||
edit->setFont(QFont(fAdmin->getFontName(), fAdmin->getFontSize()));
|
edit->setFont(QFont(fAdmin->getFontName(), fAdmin->getFontSize()));
|
||||||
@ -598,8 +598,10 @@ void PTextEdit::load( const QString &f, const int index )
|
|||||||
*/
|
*/
|
||||||
PSubTextEdit *PTextEdit::currentEditor() const
|
PSubTextEdit *PTextEdit::currentEditor() const
|
||||||
{
|
{
|
||||||
if ( fTabWidget->currentWidget() && fTabWidget->currentWidget()->inherits( "PSubTextEdit" ) ) {
|
if ( fTabWidget->currentWidget() ) {
|
||||||
return (PSubTextEdit*)fTabWidget->currentWidget();
|
if (fTabWidget->currentWidget()->inherits( "PSubTextEdit" )) {
|
||||||
|
return (PSubTextEdit*)fTabWidget->currentWidget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -830,6 +832,8 @@ void PTextEdit::fileSave()
|
|||||||
if ( !currentEditor() )
|
if ( !currentEditor() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fFileSystemWatcherActive = false;
|
||||||
|
|
||||||
if ( *fFilenames.find( currentEditor() ) == QString("noname") ) {
|
if ( *fFilenames.find( currentEditor() ) == QString("noname") ) {
|
||||||
fileSaveAs();
|
fileSaveAs();
|
||||||
} else {
|
} else {
|
||||||
@ -843,6 +847,8 @@ void PTextEdit::fileSave()
|
|||||||
QString fln = *fFilenames.find( currentEditor() );
|
QString fln = *fFilenames.find( currentEditor() );
|
||||||
fTabWidget->setTabText(fTabWidget->indexOf( currentEditor() ), QFileInfo(fln).fileName());
|
fTabWidget->setTabText(fTabWidget->indexOf( currentEditor() ), QFileInfo(fln).fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileSystemWatcherActivation(); // delayed activation of fFileSystemWatcherActive
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -854,6 +860,8 @@ void PTextEdit::fileSaveAs()
|
|||||||
if ( !currentEditor() )
|
if ( !currentEditor() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
fFileSystemWatcherActive = false;
|
||||||
|
|
||||||
QString fn = QFileDialog::getSaveFileName( this,
|
QString fn = QFileDialog::getSaveFileName( this,
|
||||||
tr( "Save msr-/mlog-file As" ), QString::null,
|
tr( "Save msr-/mlog-file As" ), QString::null,
|
||||||
tr( "msr-Files (*.msr *.mlog);;All Files (*)" ) );
|
tr( "msr-Files (*.msr *.mlog);;All Files (*)" ) );
|
||||||
@ -863,6 +871,8 @@ void PTextEdit::fileSaveAs()
|
|||||||
fileSave();
|
fileSave();
|
||||||
fTabWidget->setTabText(fTabWidget->indexOf( currentEditor() ), QFileInfo(fn).fileName());
|
fTabWidget->setTabText(fTabWidget->indexOf( currentEditor() ), QFileInfo(fn).fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileSystemWatcherActivation(); // delayed activation of fFileSystemWatcherActive
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -1581,6 +1591,7 @@ void PTextEdit::musrFit()
|
|||||||
|
|
||||||
PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd);
|
PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd);
|
||||||
fitOutputHandler.setModal(true);
|
fitOutputHandler.setModal(true);
|
||||||
|
fFileSystemWatcherActive = false;
|
||||||
fitOutputHandler.exec();
|
fitOutputHandler.exec();
|
||||||
|
|
||||||
// handle the reloading of the files
|
// handle the reloading of the files
|
||||||
@ -1624,6 +1635,8 @@ void PTextEdit::musrFit()
|
|||||||
load(complementFileName, idx);
|
load(complementFileName, idx);
|
||||||
fTabWidget->setCurrentIndex(currentIdx);
|
fTabWidget->setCurrentIndex(currentIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileSystemWatcherActivation();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -1632,11 +1645,6 @@ void PTextEdit::musrFit()
|
|||||||
*/
|
*/
|
||||||
void PTextEdit::musrMsr2Data()
|
void PTextEdit::musrMsr2Data()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if ( !currentEditor() )
|
|
||||||
return;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (fMsr2DataParam == 0) {
|
if (fMsr2DataParam == 0) {
|
||||||
fMsr2DataParam = new PMsr2DataParam();
|
fMsr2DataParam = new PMsr2DataParam();
|
||||||
// init fMsr2DataParam
|
// init fMsr2DataParam
|
||||||
@ -1841,6 +1849,7 @@ cout << endl;
|
|||||||
|
|
||||||
PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd);
|
PFitOutputHandler fitOutputHandler(QFileInfo(*fFilenames.find( currentEditor() )).absolutePath(), cmd);
|
||||||
fitOutputHandler.setModal(true);
|
fitOutputHandler.setModal(true);
|
||||||
|
fFileSystemWatcherActive = false;
|
||||||
fitOutputHandler.exec();
|
fitOutputHandler.exec();
|
||||||
|
|
||||||
// check if it is necessary to load msr-files
|
// check if it is necessary to load msr-files
|
||||||
@ -1914,6 +1923,8 @@ cout << endl;
|
|||||||
|
|
||||||
delete dlg;
|
delete dlg;
|
||||||
dlg = 0;
|
dlg = 0;
|
||||||
|
|
||||||
|
fileSystemWatcherActivation();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -2119,6 +2130,10 @@ void PTextEdit::fontChanged( const QFont &f )
|
|||||||
fFontChanging = true;
|
fFontChanging = true;
|
||||||
fComboFont->lineEdit()->setText( f.family() );
|
fComboFont->lineEdit()->setText( f.family() );
|
||||||
fComboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
|
fComboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
|
||||||
|
|
||||||
|
if (!currentEditor())
|
||||||
|
return;
|
||||||
|
|
||||||
currentEditor()->setFont(f);
|
currentEditor()->setFont(f);
|
||||||
currentEditor()->setWindowModified(false);
|
currentEditor()->setWindowModified(false);
|
||||||
currentEditor()->viewport()->setFocus();
|
currentEditor()->viewport()->setFocus();
|
||||||
@ -2131,6 +2146,7 @@ void PTextEdit::fontChanged( const QFont &f )
|
|||||||
*/
|
*/
|
||||||
void PTextEdit::textChanged(const bool forced)
|
void PTextEdit::textChanged(const bool forced)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!currentEditor())
|
if (!currentEditor())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2142,16 +2158,17 @@ void PTextEdit::textChanged(const bool forced)
|
|||||||
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") > 0) &&
|
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") > 0) &&
|
||||||
!currentEditor()->document()->isModified()) {
|
!currentEditor()->document()->isModified()) {
|
||||||
tabLabel.truncate(tabLabel.length()-1);
|
tabLabel.truncate(tabLabel.length()-1);
|
||||||
fTabWidget->setTabText(fTabWidget->indexOf(fTabWidget), tabLabel);
|
fTabWidget->setTabText(fTabWidget->currentIndex(), tabLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") < 0) &&
|
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") < 0) &&
|
||||||
currentEditor()->document()->isModified())
|
currentEditor()->document()->isModified()) {
|
||||||
fTabWidget->setTabText(fTabWidget->indexOf(fTabWidget), tabLabel+"*");
|
fTabWidget->setTabText(fTabWidget->currentIndex(), tabLabel+"*");
|
||||||
|
}
|
||||||
|
|
||||||
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") < 0) &&
|
if ((fTabWidget->tabText(fTabWidget->currentIndex()).indexOf("*") < 0) &&
|
||||||
forced)
|
forced)
|
||||||
fTabWidget->setTabText(fTabWidget->indexOf(fTabWidget), tabLabel+"*");
|
fTabWidget->setTabText(fTabWidget->currentIndex(), tabLabel+"*");
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -2244,6 +2261,9 @@ void PTextEdit::applyFontSettings(QWidget*)
|
|||||||
*/
|
*/
|
||||||
void PTextEdit::fileChanged(const QString &fileName)
|
void PTextEdit::fileChanged(const QString &fileName)
|
||||||
{
|
{
|
||||||
|
if (!fFileSystemWatcherActive)
|
||||||
|
return;
|
||||||
|
|
||||||
QString str = "File '" + fileName + "' changed on the system.\nDo you want to reload it?";
|
QString str = "File '" + fileName + "' changed on the system.\nDo you want to reload it?";
|
||||||
int result = QMessageBox::question(this, "**INFO**", str, QMessageBox::Yes, QMessageBox::No);
|
int result = QMessageBox::question(this, "**INFO**", str, QMessageBox::Yes, QMessageBox::No);
|
||||||
if (result == QMessageBox::Yes) {
|
if (result == QMessageBox::Yes) {
|
||||||
@ -2269,6 +2289,29 @@ void PTextEdit::fileChanged(const QString &fileName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>.Delayed reactivation of file system watcher, needed when saving files. At the moment the delay
|
||||||
|
* is set to 1000 ms.
|
||||||
|
*/
|
||||||
|
void PTextEdit::fileSystemWatcherActivation()
|
||||||
|
{
|
||||||
|
if (fFileSystemWatcherTimeout.isActive())
|
||||||
|
return;
|
||||||
|
|
||||||
|
fFileSystemWatcherTimeout.singleShot(1000, this, SLOT(setFileSystemWatcherActive()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>.slot needed to reactivate the file system watcher. It is called by PTextEdit::fileSystemWatcherActivation()
|
||||||
|
* after some given timeout.
|
||||||
|
*/
|
||||||
|
void PTextEdit::setFileSystemWatcherActive()
|
||||||
|
{
|
||||||
|
fFileSystemWatcherActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// END
|
// END
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "musredit.h"
|
#include "musredit.h"
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ private:
|
|||||||
PSubTextEdit *currentEditor() const;
|
PSubTextEdit *currentEditor() const;
|
||||||
void doConnections( PSubTextEdit *e );
|
void doConnections( PSubTextEdit *e );
|
||||||
bool validRunList(const QString runList);
|
bool validRunList(const QString runList);
|
||||||
|
void fileSystemWatcherActivation();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void insertTitle();
|
void insertTitle();
|
||||||
@ -132,10 +134,13 @@ private slots:
|
|||||||
|
|
||||||
void applyFontSettings(QWidget*);
|
void applyFontSettings(QWidget*);
|
||||||
void fileChanged(const QString &fileName);
|
void fileChanged(const QString &fileName);
|
||||||
|
void setFileSystemWatcherActive();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PAdmin *fAdmin;
|
PAdmin *fAdmin;
|
||||||
QFileSystemWatcher *fFileSystemWatcher;
|
QFileSystemWatcher *fFileSystemWatcher;
|
||||||
|
bool fFileSystemWatcherActive;
|
||||||
|
QTimer fFileSystemWatcherTimeout;
|
||||||
|
|
||||||
QAction *fMusrT0Action;
|
QAction *fMusrT0Action;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user