Skip to content

Commit

Permalink
Merge remote branch 'origin/bugfix/7055_loaddialog_invalid_input'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed Oct 10, 2013
2 parents 0f5c962 + 0e59f56 commit 1a3e35a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace MantidQt
QString m_currentFiles;
/// The initial height
int m_initialHeight;
/// Flag to indicating if we are populating the dialog
bool m_populating;
};

}
Expand Down
33 changes: 31 additions & 2 deletions Code/Mantid/MantidQt/CustomDialogs/src/LoadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ namespace MantidQt
{
namespace CustomDialogs
{
namespace
{
/// Holds a flag at a given value
/// and flips it back to its starting value on destruction
struct HoldFlag
{
HoldFlag(bool& current, const bool holdValue) : initial(current), heldflag(current)
{
heldflag = holdValue;
}
~HoldFlag() { heldflag = initial; }
bool initial;
bool & heldflag;
};
}

// Declare the dialog. Name must match the class name
DECLARE_DIALOG(LoadDialog);

Expand All @@ -33,7 +49,8 @@ namespace MantidQt

/// Default constructor
LoadDialog:: LoadDialog(QWidget *parent)
: API::AlgorithmDialog(parent), m_form(), m_currentFiles(), m_initialHeight(0)
: API::AlgorithmDialog(parent), m_form(), m_currentFiles(), m_initialHeight(0),
m_populating(false)
{
// We will handle parsing the input ourselves on startup
m_autoParseOnInit = false;
Expand All @@ -48,6 +65,8 @@ namespace MantidQt
*/
void LoadDialog::createDynamicWidgets()
{
HoldFlag hold(m_populating, true);

m_form.fileWidget->blockSignals(true);
createDynamicLayout();
m_form.fileWidget->blockSignals(false);
Expand Down Expand Up @@ -95,10 +114,20 @@ namespace MantidQt
}

/**
* Protection against removing the file while the dialog is up.
* Called when the run button is clicked
*/
void LoadDialog::accept()
{
// The file widget may have been edited but not lost focus so that the search wasn't
// attempted for the new contents. Force one here.
// The widget does nothing if the contents have not changed so it will be quick for this case
m_form.fileWidget->findFiles();
while(m_form.fileWidget->isSearching() || m_populating)
{
QApplication::instance()->processEvents();
}

// Check that the file still exists just incase it somehow got removed
std::string errMess = getAlgorithm()->getPointerToProperty("Filename")->isValid();
if ( !errMess.empty() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ namespace MantidQt
QString getText() const;

bool isValid() const;
bool isSearching() const;
QStringList getFilenames() const;
QString getFirstFilename() const;
int getEntryNum() const;
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ void FindFilesThread::run()
// Reset result member vars.
m_error.clear();
m_filenames.clear();
m_valueForProperty.clear();

if( m_text.empty() )
{
if( m_isOptional )
Expand All @@ -87,7 +89,6 @@ void FindFilesThread::run()

try
{
m_valueForProperty = "";
// Use the property of the algorithm to find files, if one has been specified.
if( m_algorithm.length() != 0 && m_property.length() != 0 )
{
Expand Down Expand Up @@ -494,6 +495,16 @@ bool MWRunFiles::isValid() const
}
}

/**
* Is the widget currently searching
* @return True if a search is inprogress
*/
bool MWRunFiles::isSearching() const
{
return (m_thread ? m_thread->isRunning() : false);
}


/**
* Returns the names of the files found
* @return an array of filenames entered in the box
Expand Down

0 comments on commit 1a3e35a

Please sign in to comment.