@@ -108,6 +108,7 @@ FrmMain::FrmMain(QWidget *parent) :
108108 ui->fraDropUser ->setVisible (false );
109109
110110 connectWindowTitleUpdater ();
111+ connectFilesManagerToUpdateControls ();
111112
112113 // Initialize OpenAI key
113114 if (ConfigurationAI::instance ().openAIKey () != " " ) {
@@ -532,6 +533,17 @@ void FrmMain::initializeLogMenu()
532533 });
533534}
534535
536+ void FrmMain::connectFilesManagerToUpdateControls ()
537+ {
538+ FilesManager& fm = FilesManager::instance ();
539+ connect (&fm, &FilesManager::gcodeFileStateChanged, this , [this ](bool , const QString&, bool ) {
540+ updateControlsState (currentUiState ());
541+ });
542+ connect (&fm, &FilesManager::heightmapFileStateChanged, this , [this ](bool , const QString&, bool ) {
543+ updateControlsState (currentUiState ());
544+ });
545+ }
546+
535547void FrmMain::connectWindowTitleUpdater ()
536548{
537549 FilesManager& fm = FilesManager::instance ();
@@ -1826,9 +1838,10 @@ void FrmMain::onMachineStateChanged(MachineState state)
18261838{
18271839 ui->state ->setState (state);
18281840
1829- ui->control ->updateControlsState (communicator ()-> stateBehavior ());
1841+ ui->control ->updateControlsState (currentUiState ());
18301842
18311843 // ui->spindle->...
1844+
18321845 // ui->cmdSpindle->setEnabled(state == DeviceHold0 || ((communicator()->senderState() != SenderTransferring) && (communicator()->senderState() != SenderStopping)));
18331846}
18341847
@@ -1950,7 +1963,8 @@ void FrmMain::updateOnStateBehaviorChanged(AbstractStateBehavior *sb)
19501963 ThemeManager::instance ().dark () ? " black" : " white"
19511964 );
19521965 ui->console ->appendSystem (QString (" State: %1" ).arg (sb->description ()));
1953- updateControlsState ();
1966+ FilesManager& fm = FilesManager::instance ();
1967+ updateControlsState ({ sb, { fm.gcodeOpened (), fm.heightmapOpened () } });
19541968
19551969 // Auto-dismiss the prompt dialog when the user-prompt state goes away
19561970 // (e.g. user resolved the prompt via a side-channel like the toolbar
@@ -3014,10 +3028,23 @@ void FrmMain::newHeightmap()
30143028 updateControlsState ();
30153029}
30163030
3017- void FrmMain::updateControlsState ()
3031+ UiState FrmMain::currentUiState () const
3032+ {
3033+ FilesManager& fm = FilesManager::instance ();
3034+
3035+ return {
3036+ Core::instance ().communicator ()->stateBehavior (),
3037+ {
3038+ fm.gcodeOpened (),
3039+ fm.heightmapOpened ()
3040+ },
3041+ };
3042+ }
3043+
3044+ void FrmMain::updateControlsState (const UiState& state)
30183045{
30193046 bool portOpened = connection () && connection ()->isConnected ();
3020- AbstractStateBehavior *sb = communicator ()-> stateBehavior () ;
3047+ AbstractStateBehavior *sb = state. sb ;
30213048 bool running = sb->is (AbstractStateBehavior::Type::Running);
30223049 bool paused = sb->is (AbstractStateBehavior::Type::Pause) || sb->is (AbstractStateBehavior::Type::ToolChange);
30233050 bool idle = sb->is (AbstractStateBehavior::Type::Idle);
@@ -3026,22 +3053,23 @@ void FrmMain::updateControlsState()
30263053 // ui->control->setEnabled(portOpened);
30273054 ui->spindle ->setEnabled (portOpened);
30283055 // TODO: add Action::Jog to ToolChangeBehavior::availableActions(), then simplify to sb->canExecute(Action::Jog)
3029- ui->jog ->setEnabled (sb->isOneOf (AbstractStateBehavior::Type::Idle, AbstractStateBehavior::Type::GoTo, AbstractStateBehavior::Type::Jogging));
30303056
30313057 ui->console ->setEnabled (portOpened && !m_configuration.joggingModule ().keyboardControl ());
30323058 // ui->cmdCommandSend->setEnabled(portOpened);
30333059
3034- ui->control ->updateControlsState (sb);
3060+ ui->control ->updateControlsState (state);
3061+ ui->jog ->updateControlsState (state);
30353062
30363063 // ui->spindle->...
30373064 // ui->cmdSpindle->setEnabled(!running);
30383065
30393066 bool canOpenFile = UiPermissions::isAllowed (UiPermission::OpenFile, sb->type ());
30403067 ui->actFileNew ->setEnabled (idle);
30413068 ui->actFileOpen ->setEnabled (canOpenFile);
3042- ui->program ->setOpenButtonEnabled (canOpenFile);
3043- ui->program ->setResetButtonEnabled (idle && !program ().empty ());
3044- ui->program ->setSendButtonEnabled (sb->canExecute (Action::Type::Run) && !program ().empty ());
3069+ // ui->program->setOpenButtonEnabled(canOpenFile);
3070+ // ui->program->setResetButtonEnabled(idle && !program().empty());
3071+ // ui->program->setSendButtonEnabled(sb->canExecute(Action::Type::Run) && !program().empty());
3072+ ui->program ->updateControlsState (state);
30453073 // switch (senderState) {
30463074 // case SenderState::Pausing:
30473075 // case SenderState::Pausing2:
@@ -3109,10 +3137,7 @@ void FrmMain::updateControlsState()
31093137
31103138 ui->program ->setSendButtonText (m_heightmapMode ? tr (" Probe" ) : tr (" Send" ));
31113139
3112- ui->heightmap ->updateControlsState (
3113- !program ().empty (),
3114- m_heightmapMode
3115- );
3140+ ui->heightmap ->updateControlsState (state);
31163141
31173142 ui->actFileSaveTransformedAs ->setVisible (ui->heightmap ->useMap ());
31183143
0 commit comments