@@ -74,7 +74,7 @@ namespace Gui {
7474 << new QAction (" Help" , parent)
7575 << new QAction (" Edit Notes..." , parent)
7676 << new QAction (" Duplicate" , parent)
77- << new QAction (" Replace With" , parent)
77+ << new QAction (" Replace With... " , parent)
7878 // << disabled(new QAction("Ignore*", parent))
7979 << new QAction (" Show Log" , parent)
8080 // << disabled(new QAction("Make Sub-Network", parent)) // Issue #287
@@ -335,6 +335,7 @@ ModuleWidget::ModuleWidget(NetworkEditor* ed, const QString& name, ModuleHandle
335335 theModule_(theModule),
336336 previousModuleState_(UNSET),
337337 moduleId_(id(theModule)),
338+ name_(name),
338339 dialog_(nullptr ),
339340 dockable_(nullptr ),
340341 dialogErrorControl_(dialogErrorControl),
@@ -527,20 +528,39 @@ void ModuleWidget::setupModuleActions()
527528 || theModule_->get_id ().name_ == " Subnet" )
528529 actionsMenu_->getMenu ()->removeAction (actionsMenu_->getAction (" Duplicate" ));
529530 if (theModule_->get_id ().name_ == " Subnet" )
530- actionsMenu_->getMenu ()->removeAction (actionsMenu_->getAction (" Replace With" ));
531+ actionsMenu_->getMenu ()->removeAction (actionsMenu_->getAction (" Replace With... " ));
531532
532533 connectNoteEditorToAction (actionsMenu_->getAction (" Notes" ));
533534 connectUpdateNote (this );
534535}
535536
536537void ModuleWidget::postLoadAction ()
537538{
538- auto replaceWith = actionsMenu_->getAction (" Replace With" );
539- auto menu = new QMenu (this );
540- replaceWith->setMenu (menu);
541- fillReplaceWithMenu ();
542- connect (this , SIGNAL (connectionAdded (const SCIRun::Dataflow::Networks::ConnectionDescription&)), this , SLOT (fillReplaceWithMenu ()));
543- connect (this , SIGNAL (connectionDeleted (const SCIRun::Dataflow::Networks::ConnectionId&)), this , SLOT (fillReplaceWithMenu ()));
539+ auto replaceWith = actionsMenu_->getAction (" Replace With..." );
540+ if (replaceWith)
541+ connect (replaceWith, SIGNAL (triggered ()), this , SLOT (showReplaceWithWidget ()));
542+ }
543+
544+ void ModuleWidget::showReplaceWithWidget ()
545+ {
546+ #ifndef __APPLE__
547+ replaceWithDialog_ = new QDialog;
548+ replaceWithDialog_->setWindowTitle (" Replace a module" );
549+ auto layout = new QHBoxLayout;
550+ layout->addWidget (new QLabel (" Replace " + name_ + " with:" ));
551+ auto button = new QPushButton (" Choose a compatible module" );
552+ auto menu = new QMenu;
553+ button->setMenu (menu);
554+ fillReplaceWithMenu (menu);
555+ layout->addWidget (button);
556+ auto cancel = new QPushButton (" Cancel" );
557+ connect (cancel, SIGNAL (clicked ()), replaceWithDialog_, SLOT (reject ()));
558+ layout->addWidget (cancel);
559+ replaceWithDialog_->setLayout (layout);
560+ replaceWithDialog_->exec ();
561+ #else
562+ QMessageBox::information (nullptr , " Replace with disabled" , " The replace with command is disabled on OSX until the Qt 5 upgrade is complete." );
563+ #endif
544564}
545565
546566bool ModuleWidget::guiVisible () const
@@ -550,35 +570,25 @@ bool ModuleWidget::guiVisible() const
550570 return false ;
551571}
552572
553- void ModuleWidget::fillReplaceWithMenu ()
573+ void ModuleWidget::fillReplaceWithMenu (QMenu* menu )
554574{
555575 if (deleting_ || networkBeingCleared_)
556576 return ;
557577
558- auto menu = getReplaceWithMenu ();
559578 menu->clear ();
560579 LOG_DEBUG (" Filling menu for " << theModule_->get_module_name () << std::endl);
561580 auto replacements = Application::Instance ().controller ()->possibleReplacements (this ->theModule_ );
562581 auto isReplacement = [&](const ModuleDescription& md) { return replacements.find (md.lookupInfo_ ) != replacements.end (); };
563582 fillMenuWithFilteredModuleActions (menu, Application::Instance ().controller ()->getAllAvailableModuleDescriptions (),
564583 isReplacement,
565584 [=](QAction* action) { QObject::connect (action, SIGNAL (triggered ()), this , SLOT (replaceModuleWith ())); },
566- fullWidgetDisplay_->getModuleActionButton ());
567- }
568-
569- void ModuleWidget::menuFunction ()
570- {
571- // fullWidgetDisplay_->getModuleActionButton()->setMenu(nullptr);
572- // actionsMenu_.reset();
573- }
574-
575- QMenu* ModuleWidget::getReplaceWithMenu ()
576- {
577- return actionsMenu_->getAction (" Replace With" )->menu ();
585+ replaceWithDialog_);
578586}
579587
580588void ModuleWidget::replaceModuleWith ()
581589{
590+ delete replaceWithDialog_;
591+ replaceWithDialog_ = nullptr ;
582592 auto action = qobject_cast<QAction*>(sender ());
583593 auto moduleToReplace = action->text ();
584594 Q_EMIT replaceModuleWith (theModule_, moduleToReplace.toStdString ());
@@ -967,7 +977,6 @@ ModuleWidget::NetworkClearingScope::~NetworkClearingScope()
967977ModuleWidget::~ModuleWidget ()
968978{
969979 disconnect (this , SIGNAL (dynamicPortChanged (const std::string&, bool )), this , SLOT (updateDialogForDynamicPortChange (const std::string&, bool )));
970- disconnect (this , SIGNAL (connectionDeleted (const SCIRun::Dataflow::Networks::ConnectionId&)), this , SLOT (fillReplaceWithMenu ()));
971980
972981 if (!theModule_->isStoppable ())
973982 {
0 commit comments