@@ -93,14 +93,16 @@ void ShowTextInDialoog(QWidget *parent, const QString &text);
93
93
const QString MainWindow::ActionTagLastFiles (" LastFiles" );
94
94
const QString MainWindow::ActionTagLastFolders (" LastFolders" );
95
95
96
- MainWindow::MainWindow (const bool setIsSlave, ApplicationData *newData, QMainWindow *parent)
96
+ MainWindow::MainWindow (const bool isAutoDelete, const bool setIsSlave, ApplicationData *newData, QMainWindow *parent)
97
97
: QMainWindow(parent),
98
98
_uiServices(this ),
99
99
data(newData),
100
100
uiDelegate(this ),
101
101
_windowIcon(" :/icon/images/icon.png" ),
102
102
_closing(false )
103
103
{
104
+ _isAutoDelete = isAutoDelete;
105
+ isDeleted = false ;
104
106
_infoOnEditMode = NULL ;
105
107
_infoOnKeyboardShortcuts = NULL ;
106
108
_scxmlValidationErrors = NULL ;
@@ -162,6 +164,7 @@ MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWin
162
164
163
165
MainWindow::~MainWindow ()
164
166
{
167
+ isDeleted = true ;
165
168
ui.sessionTree ->setSessionManager (NULL );
166
169
dismissInfoOnKeyboard ();
167
170
dismissInfoEditTypes ();
@@ -176,6 +179,7 @@ MainWindow::~MainWindow()
176
179
void MainWindow::forgetData ()
177
180
{
178
181
if (NULL != data) {
182
+ ui.sessionTree ->setSessionManager (NULL );
179
183
disconnect (data, SIGNAL (clipboardDataChanged (bool )), this , SLOT (onClipboardDataChanged (bool )));
180
184
disconnect (data, SIGNAL (stateKeyboardShortcutChanged (bool )), this , SLOT (onStateKeyboardShortcutChanged (bool )));
181
185
if (!isSlave) {
@@ -194,7 +198,7 @@ ApplicationData *MainWindow::appData()
194
198
QString MainWindow::editNodeElementAsXML (const bool isBase64Coded, Element *pElement, const QString & /* text*/ , const bool /* isCData*/ , bool &isCDataOut, bool &isOk)
195
199
{
196
200
QString result;
197
- MainWindow *mainWindow = new MainWindow (true , data, this ) ;
201
+ MainWindow *mainWindow = new MainWindow (true , true , data, this ) ;
198
202
mainWindow->setWindowModality (Qt::WindowModal);
199
203
mainWindow->ui .editor ->loadText (pElement->getAsSimpleText (isBase64Coded));
200
204
mainWindow->ui .editor ->setCDATA (pElement->isCDATA ());
@@ -253,22 +257,12 @@ bool MainWindow::event(QEvent *e)
253
257
const bool result = QMainWindow::event (e);
254
258
switch (e->type ()) {
255
259
case QEvent::WindowActivate:
256
- #ifdef QXMLEDIT_TEST
257
- if (NULL == data) {
258
- qFatal (" fault activation" );
259
- }
260
- #endif
261
- if (NULL != data) {
260
+ if ((NULL != data) && !isDeleted) {
262
261
data->newWindowActivationStatus (this , true );
263
262
}
264
263
break ;
265
264
case QEvent::WindowDeactivate:
266
- #ifdef QXMLEDIT_TEST
267
- if (NULL == data) {
268
- qFatal (" fault deactivation" );
269
- }
270
- #endif
271
- if (NULL != data) {
265
+ if ((NULL != data) && !isDeleted) {
272
266
data->newWindowActivationStatus (this , false );
273
267
}
274
268
break ;
@@ -1401,9 +1395,10 @@ void MainWindow::closeEvent(QCloseEvent * event)
1401
1395
if (!isSlave) {
1402
1396
// disable events until destroyed
1403
1397
forgetData ();
1404
- deleteLater ();
1398
+ if (_isAutoDelete) {
1399
+ deleteLater ();
1400
+ }
1405
1401
} else {
1406
- Utils::TODO_THIS_RELEASE (" ma perche'? non forget data se closed? o deleted?" );
1407
1402
_slaveIsClosed = true ;
1408
1403
if (NULL != eventLoop) {
1409
1404
eventLoop->exit (_returnCodeAsSlave);
@@ -2729,12 +2724,25 @@ void MainWindow::reposFrame()
2729
2724
2730
2725
MainWindow *MainWindow::makeNewWindow ()
2731
2726
{
2732
- MainWindow *newWindow = new MainWindow (false , data);
2733
- if (NULL != newWindow) {
2734
- reposFrame ();
2735
2727
#ifndef QXMLEDIT_TEST
2736
- newWindow->show ();
2728
+ const bool show = true ;
2729
+ #else
2730
+ const bool show = false ;
2737
2731
#endif
2732
+ MainWindow *newWindow = MainWindow::newDynamicTopLevelNewWindow (data, true , show);
2733
+ return newWindow;
2734
+ }
2735
+
2736
+ MainWindow *MainWindow::newDynamicTopLevelNewWindow (ApplicationData *appData, const bool isRepos, const bool isShow)
2737
+ {
2738
+ MainWindow *newWindow = new MainWindow (true , false , appData);
2739
+ if (NULL != newWindow) {
2740
+ if (isRepos) {
2741
+ newWindow->reposFrame ();
2742
+ }
2743
+ if (isShow) {
2744
+ newWindow->show ();
2745
+ }
2738
2746
} else {
2739
2747
Utils::error (tr (" Error opening a new window." ));
2740
2748
}
0 commit comments