@@ -150,17 +150,6 @@ mbServerDevice *mbServerWindowManager::activeDevice() const
150150 return m_deviceManager->activeDevice ();
151151}
152152
153- void mbServerWindowManager::setActiveDevice (mbServerDevice *device)
154- {
155- mbServerDeviceUi *ui = m_deviceManager->deviceUi (device);
156- if (ui)
157- {
158- QMdiSubWindow *sw = m_hashWindows.value (ui);
159- if (sw)
160- m_area->setActiveSubWindow (sw);
161- }
162- }
163-
164153void mbServerWindowManager::showScriptModule (mbServerScriptModule *sm)
165154{
166155 mbServerScriptModuleEditor *se = m_scriptManager->scriptModuleEditor (sm);
@@ -181,7 +170,11 @@ void mbServerWindowManager::showDeviceScript(mbServerDevice *device, mbServerDev
181170
182171void mbServerWindowManager::showScriptEditor (mbServerBaseScriptEditor *scriptEditor)
183172{
184- showSubWindow (scriptEditor);
173+ QMdiSubWindow *sw = m_hashWindows.value (scriptEditor);
174+ if (sw)
175+ showSubWindow (sw);
176+ else
177+ scriptEditorAdd (scriptEditor);
185178}
186179
187180void mbServerWindowManager::setActiveScriptEditor (mbServerBaseScriptEditor *scriptEditor)
@@ -191,24 +184,39 @@ void mbServerWindowManager::setActiveScriptEditor(mbServerBaseScriptEditor *scri
191184 m_area->setActiveSubWindow (sw);
192185}
193186
194- void mbServerWindowManager::showDeviceUi (const mbServerDeviceUi *ui)
187+ void mbServerWindowManager::setActiveDevice (mbServerDevice *device)
188+ {
189+ mbServerDeviceUi *ui = m_deviceManager->deviceUi (device);
190+ if (ui)
191+ showDeviceUi (ui);
192+ }
193+
194+ void mbServerWindowManager::showDeviceUi (mbServerDeviceUi *ui)
195195{
196- showSubWindow (ui);
196+ QMdiSubWindow *sw = m_hashWindows.value (ui);
197+ if (sw)
198+ showSubWindow (sw);
199+ else
200+ deviceUiAdd (ui);
197201}
198202
199203void mbServerWindowManager::actionWindowDeviceCloseAll ()
200204{
201- Q_FOREACH (QMdiSubWindow *sw, m_devices )
205+ Q_FOREACH (mbServerDeviceUi *ui, m_deviceManager-> deviceUis () )
202206 {
203- sw->close ();
207+ QMdiSubWindow *sw = m_hashWindows.value (ui);
208+ if (sw)
209+ closeSubWindow (sw);
204210 }
205211}
206212
207213void mbServerWindowManager::actionWindowScriptCloseAll ()
208214{
209- Q_FOREACH (QMdiSubWindow *sw, m_scriptEditors )
215+ Q_FOREACH (mbServerBaseScriptEditor *ui, m_scriptManager-> scriptEditors () )
210216 {
211- sw->close ();
217+ QMdiSubWindow *sw = m_hashWindows.value (ui);
218+ if (sw)
219+ closeSubWindow (sw);
212220 }
213221}
214222
@@ -222,10 +230,8 @@ void mbServerWindowManager::actionWindowCloseAll()
222230void mbServerWindowManager::deviceUiAdd (mbServerDeviceUi *ui)
223231{
224232 QMdiSubWindow* sw = subWindowAdd (ui);
225- m_devices.append (sw);
226233 connect (ui, &mbServerDeviceUi::nameChanged, sw, &QWidget::setWindowTitle);
227234 sw->setWindowTitle (ui->name ());
228- Q_EMIT deviceWindowAdded (ui);
229235}
230236
231237void mbServerWindowManager::deviceUiRemove (mbServerDeviceUi *ui)
@@ -234,20 +240,15 @@ void mbServerWindowManager::deviceUiRemove(mbServerDeviceUi *ui)
234240 QMdiSubWindow* sw = subWindowRemove (ui);
235241 if (sw)
236242 {
237- Q_EMIT deviceWindowRemoving (ui);
238- m_devices.removeOne (sw);
239- delete sw;
243+ sw->deleteLater ();
240244 }
241245}
242246
243247void mbServerWindowManager::scriptEditorAdd (mbServerBaseScriptEditor *ui)
244248{
245249 QMdiSubWindow* sw = subWindowAdd (ui);
246- m_scriptEditors.append (sw);
247250 connect (ui, &mbServerBaseScriptEditor::nameChanged, sw, &QWidget::setWindowTitle);
248251 sw->setWindowTitle (ui->name ());
249- sw->installEventFilter (this );
250- Q_EMIT scriptWindowAdded (ui);
251252}
252253
253254void mbServerWindowManager::scriptEditorRemove (mbServerBaseScriptEditor *ui)
@@ -256,30 +257,10 @@ void mbServerWindowManager::scriptEditorRemove(mbServerBaseScriptEditor *ui)
256257 QMdiSubWindow* sw = subWindowRemove (ui);
257258 if (sw)
258259 {
259- Q_EMIT scriptWindowRemoving (ui);
260- m_scriptEditors.removeOne (sw);
261260 sw->deleteLater ();
262261 }
263262}
264263
265- bool mbServerWindowManager::eventFilter (QObject *obj, QEvent *e)
266- {
267- switch (e->type ())
268- {
269- case QEvent::Close:
270- {
271- QMdiSubWindow *sw = qobject_cast<QMdiSubWindow*>(obj);
272- // Q_ASSERT (sw != nullptr);
273- mbServerBaseScriptEditor *ui = qobject_cast<mbServerBaseScriptEditor*>(sw->widget ());
274- m_scriptManager->removeScriptEditor (ui);
275- return true ;
276- }
277- default :
278- break ;
279- }
280- return QObject::eventFilter (obj, e);
281- }
282-
283264void mbServerWindowManager::subWindowActivated (QMdiSubWindow *sw)
284265{
285266 if (sw)
@@ -302,3 +283,11 @@ void mbServerWindowManager::subWindowActivated(QMdiSubWindow *sw)
302283 mbCoreWindowManager::subWindowActivated (sw);
303284 }
304285}
286+
287+ void mbServerWindowManager::closeSubWindow (QMdiSubWindow *sw)
288+ {
289+ if (mbServerBaseScriptEditor *ui = qobject_cast<mbServerBaseScriptEditor*>(sw->widget ()))
290+ m_scriptManager->removeScriptEditor (ui);
291+ else
292+ mbCoreWindowManager::closeSubWindow (sw);
293+ }
0 commit comments