Skip to content

Commit 2471b40

Browse files
Merge pull request #333 from g-maxime/import
Apply imported core to already opened files
2 parents 2096d2a + d5fbeb4 commit 2471b40

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

Source/Common/Core.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Core::Core()
197197
Canceled=false;
198198
SaveMode=false;
199199
SaveMode_OneFile=false;
200+
Reopen=false;
200201
#ifdef _WIN32
201202
TCHAR Path[MAX_PATH];
202203
BOOL Result=SHGetSpecialFolderPath(NULL, Path, CSIDL_APPDATA, true);
@@ -319,7 +320,7 @@ float Core::Menu_File_Open_Files_Finish_Middle ()
319320
Files_Modified_NotWritten_Count--;
320321
delete Handler->second.Riff; Handler->second.Riff=NULL;
321322
}
322-
else
323+
else if (!Reopen)
323324
{
324325
Handler++; //Already opened
325326

@@ -1174,7 +1175,9 @@ int Core::Menu_File_Import_Core(const string &FileName)
11741175
ReturnValue++;
11751176
}
11761177

1178+
Reopen=true; // Apply imported core to already opened files
11771179
Menu_File_Open_Files_Finish();
1180+
Reopen=false;
11781181
}
11791182
else if (Buffer_Offset>=8
11801183
&& Buffer[0]=='<'
@@ -1213,7 +1216,9 @@ int Core::Menu_File_Import_Core(const string &FileName)
12131216
}
12141217
}
12151218

1219+
Reopen=true; // Apply imported core to already opened files
12161220
Menu_File_Open_Files_Finish();
1221+
Reopen=false;
12171222
}
12181223
else
12191224
throw "--in-core=: not a valid file";

Source/Common/Core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ class Core : public Thread
273273
ZtringList Menu_Close_File_FileNames;
274274
bool SaveMode;
275275
bool SaveMode_OneFile;
276+
bool Reopen;
276277
};
277278

278279
#endif

Source/GUI/Qt/GUI_Main.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,55 @@ void GUI_Main::dropEvent(QDropEvent *Event)
273273
for (size_t Pos=0; Pos<Cores.size(); Pos++)
274274
C->Menu_File_Import_Core(Cores[Pos].To_UTF8());
275275
C->StdOut("Importing Core file, finished");
276-
//Showing
277-
if (C->Text_stderr_Updated_Get())
276+
277+
//Showing errors
278+
string Errors=C->Text_stderr_Last_Get();
279+
if (!Errors.empty())
278280
{
279-
Menu_View_Output_stderr->setChecked(true);
280-
View_Refresh(View_Output_stderr);
281+
QDialog ErrorDialog(this);
282+
ErrorDialog.setWindowTitle("BWF MetaEdit");
283+
ErrorDialog.setWindowIcon(QIcon(":/Image/Logo/Logo.png"));
284+
ErrorDialog.setModal(true);
285+
286+
// Calculate maximum width based on screen size
287+
QScreen* Screen=QApplication::screenAt(mapToGlobal(QPoint(0, 0)));
288+
int MaxWidth=Screen?(Screen->availableGeometry().width()*2/3):800; // Default to 800 if no screen
289+
int MaxHeight=Screen?(Screen->availableGeometry().height()*2/4):600; // Default to 600 if no screen
290+
291+
QVBoxLayout* Layout=new QVBoxLayout(&ErrorDialog);
292+
293+
// Message
294+
QString Message=QString("The following error(s) have occurred during the import operation:");
295+
QLabel *MessageLabel=new QLabel(Message, &ErrorDialog);
296+
Layout->addWidget(MessageLabel);
297+
298+
// Error text
299+
QTextEdit *ErrorTextEdit = new QTextEdit(&ErrorDialog);
300+
ErrorTextEdit->setReadOnly(true);
301+
ErrorTextEdit->setFontFamily("Monospace");
302+
ErrorTextEdit->setLineWrapMode(QTextEdit::NoWrap);
303+
ErrorTextEdit->setPlainText(QString::fromStdString(Errors));
304+
Layout->addWidget(ErrorTextEdit);
305+
306+
// Close button
307+
QHBoxLayout* ButtonLayout=new QHBoxLayout;
308+
ButtonLayout->addStretch(1);
309+
QPushButton *CloseButton=new QPushButton("&Close", &ErrorDialog);
310+
QObject::connect(CloseButton, &QPushButton::clicked, &ErrorDialog, &QDialog::close);
311+
ButtonLayout->addWidget(CloseButton);
312+
Layout->addLayout(ButtonLayout);
313+
314+
// Size dialog
315+
QFontMetrics FontMetrics(ErrorTextEdit->font());
316+
QRect BoundingRect = FontMetrics.boundingRect(QString().fromStdString(C->Text_stderr.str()));
317+
int Width=min(MaxWidth, BoundingRect.width()+150);
318+
int Height=min(MaxHeight, BoundingRect.height()+150); // Add some padding and space for buttons
319+
ErrorDialog.resize(Width, Height);
320+
321+
ErrorDialog.exec();
281322
}
282-
else
283-
View_Refresh();
323+
324+
View_Refresh();
284325
}
285326

286327
if (Files.size())

0 commit comments

Comments
 (0)