mainwnd.cpp 14.6 KB
Newer Older
Tobias WEBER's avatar
Tobias WEBER committed
1
2
/**
 * in20 data analysis tool
Tobias WEBER's avatar
Tobias WEBER committed
3
 * @author Tobias Weber <tweber@ill.fr>
Tobias WEBER's avatar
Tobias WEBER committed
4
5
6
7
 * @date 6-Apr-2018
 * @license see 'LICENSE' file
 */

8
9
#define MAX_RECENT_FILES 16

Tobias WEBER's avatar
Tobias WEBER committed
10
#include "mainwnd.h"
Tobias WEBER's avatar
Tobias WEBER committed
11
#include "globals.h"
Tobias WEBER's avatar
Tobias WEBER committed
12
#include "funcs.h"
13
14
#include "libs/file.h"
#include "libs/algos.h"
Tobias WEBER's avatar
Tobias WEBER committed
15
16
#include "libs/helper.h"
#include "libs/str.h"
Tobias WEBER's avatar
Tobias WEBER committed
17

Tobias WEBER's avatar
Tobias WEBER committed
18
#include <QtWidgets/QMessageBox>
19
#include <QtWidgets/QFileDialog>
Tobias WEBER's avatar
Tobias WEBER committed
20
21
22
#include <QtWidgets/QDialog>

#include <iostream>
Tobias WEBER's avatar
Tobias WEBER committed
23

Tobias WEBER's avatar
Tobias WEBER committed
24
25
26
27

using t_real = double;


Tobias WEBER's avatar
Tobias WEBER committed
28
29
MainWnd::MainWnd(QSettings* pSettings)
	: QMainWindow(), m_pSettings(pSettings), 
Tobias WEBER's avatar
Tobias WEBER committed
30
	m_pBrowser(new FileBrowser(this, pSettings)),
31
	m_pWS(new WorkSpace(this, pSettings)),
Tobias WEBER's avatar
Tobias WEBER committed
32
33
	m_pCLI(new CommandLine(this, pSettings)),
	m_pCurPlot(new PlotterDock(this))
Tobias WEBER's avatar
Tobias WEBER committed
34
{
Tobias WEBER's avatar
Tobias WEBER committed
35
36
37
	// the command line widget has to be accessible globally for error output
	g_pCLI = m_pCLI;

Tobias WEBER's avatar
Tobias WEBER committed
38
	this->setObjectName("in20");
39
	SetCurrentFile("");
Tobias WEBER's avatar
Tobias WEBER committed
40
	LoadPlugins();
Tobias WEBER's avatar
Tobias WEBER committed
41

Tobias WEBER's avatar
Tobias WEBER committed
42
43
44

	// ------------------------------------------------------------------------
	// Menu Bar
Tobias WEBER's avatar
Tobias WEBER committed
45
46
47
48
49
50
51
52
53
	QMenu *menuFile = new QMenu("File", m_pMenu);
	QMenu *menuView = new QMenu("View", m_pMenu);
	QMenu *menuHelp = new QMenu("Help", m_pMenu);

	// file
	auto *acNew = new QAction(QIcon::fromTheme("document-new"), "New", m_pMenu);
	menuFile->addAction(acNew);
	menuFile->addSeparator();
	auto *acOpen = new QAction(QIcon::fromTheme("document-open"), "Open...", m_pMenu);
54
	m_menuOpenRecent = new QMenu("Open Recent", m_pMenu);
Tobias WEBER's avatar
Tobias WEBER committed
55
	menuFile->addAction(acOpen);
56
57
	m_menuOpenRecent->setIcon(QIcon::fromTheme("document-open-recent"));
	menuFile->addMenu(m_menuOpenRecent);
Tobias WEBER's avatar
Tobias WEBER committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
	menuFile->addSeparator();
	auto *acSave = new QAction(QIcon::fromTheme("document-save"), "Save", m_pMenu);
	auto *acSaveAs = new QAction(QIcon::fromTheme("document-save-as"), "Save As...", m_pMenu);
	menuFile->addAction(acSave);
	menuFile->addAction(acSaveAs);
	menuFile->addSeparator();
	auto *acPrefs = new QAction("Preferences...", m_pMenu);
	acPrefs->setMenuRole(QAction::PreferencesRole);
	menuFile->addAction(acPrefs);
	menuFile->addSeparator();
	auto *acQuit = new QAction(QIcon::fromTheme("application-exit"), "Quit", m_pMenu);
	acQuit->setMenuRole(QAction::QuitRole);
	menuFile->addAction(acQuit);

	// view
	menuView->addAction(m_pBrowser->toggleViewAction());
	menuView->addAction(m_pWS->toggleViewAction());
	menuView->addAction(m_pCLI->toggleViewAction());
	menuView->addAction(m_pCurPlot->toggleViewAction());

	// help
	auto *acAbout = new QAction(QIcon::fromTheme("help-about"), "About...", m_pMenu);
	auto *acAboutQt = new QAction(QIcon::fromTheme("help-about"), "About Qt...", m_pMenu);
	acAbout->setMenuRole(QAction::AboutRole);
	acAboutQt->setMenuRole(QAction::AboutQtRole);
	menuHelp->addAction(acAbout);
	menuHelp->addAction(acAboutQt);

	m_pMenu->addMenu(menuFile);
	m_pMenu->addMenu(menuView);
Tobias WEBER's avatar
Tobias WEBER committed
88
89
	if(m_plugin_dlgs.size())
		m_pMenu->addMenu(m_pmenuPluginTools);
Tobias WEBER's avatar
Tobias WEBER committed
90
	m_pMenu->addMenu(menuHelp);
Tobias WEBER's avatar
Tobias WEBER committed
91
	this->setMenuBar(m_pMenu);
Tobias WEBER's avatar
Tobias WEBER committed
92
93
94
	// ------------------------------------------------------------------------


Tobias WEBER's avatar
Tobias WEBER committed
95
96
97

	// ------------------------------------------------------------------------
	// docks
Tobias WEBER's avatar
Tobias WEBER committed
98
	//this->setStatusBar(m_pStatus);
Tobias WEBER's avatar
Tobias WEBER committed
99
100
	this->setCentralWidget(m_pMDI);
	this->addDockWidget(Qt::LeftDockWidgetArea, m_pBrowser);
Tobias WEBER's avatar
Tobias WEBER committed
101
	this->addDockWidget(Qt::RightDockWidgetArea, m_pWS);
102
	this->addDockWidget(Qt::BottomDockWidgetArea, m_pCLI);
Tobias WEBER's avatar
Tobias WEBER committed
103
	this->addDockWidget(Qt::BottomDockWidgetArea, m_pCurPlot);
Tobias WEBER's avatar
Tobias WEBER committed
104
	// ------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
105

Tobias WEBER's avatar
Tobias WEBER committed
106
107


108
109
	// ------------------------------------------------------------------------
	// connections
Tobias WEBER's avatar
Tobias WEBER committed
110
	connect(m_pBrowser->GetWidget(), &FileBrowserWidget::TransferFiles, m_pWS->GetWidget(), &WorkSpaceWidget::ReceiveFiles);
Tobias WEBER's avatar
Tobias WEBER committed
111
112
	connect(m_pWS->GetWidget(), &WorkSpaceWidget::PlotDataset, m_pCurPlot->GetWidget(), &Plotter::Plot);
	connect(m_pBrowser->GetWidget(), &FileBrowserWidget::PlotDataset, m_pCurPlot->GetWidget(), &Plotter::Plot);
113
114
115
116
	connect(acNew, &QAction::triggered, this, &MainWnd::NewFile);
	connect(acOpen, &QAction::triggered, this, static_cast<void(MainWnd::*)()>(&MainWnd::OpenFile));
	connect(acSave, &QAction::triggered, this, static_cast<void(MainWnd::*)()>(&MainWnd::SaveFile));
	connect(acSaveAs, &QAction::triggered, this, &MainWnd::SaveFileAs);
Tobias WEBER's avatar
Tobias WEBER committed
117
118
119
120
	//connect(acPrefs, &QAction::triggered, this, ....);	TODO
	//connect(acAbout, &QAction::triggered, this, ....);	TODO
	connect(acAboutQt, &QAction::triggered, this, []() { qApp->aboutQt(); });
	connect(acQuit, &QAction::triggered, this, &QMainWindow::close);
Tobias WEBER's avatar
Tobias WEBER committed
121
122
123
124
125
126
127
128
129

	// link symbol maps of workspace widget and command line parser
	m_pCLI->GetWidget()->GetParserContext().SetWorkspace(m_pWS->GetWidget()->GetWorkspace());

	// connect the "workspace updated" signal from the command line parser
	m_pCLI->GetWidget()->GetParserContext().GetWorkspaceUpdatedSignal().connect([this](const std::string& ident)
	{
		m_pWS->GetWidget()->UpdateList();
	});
130
131
132
	// ------------------------------------------------------------------------


Tobias WEBER's avatar
Tobias WEBER committed
133

Tobias WEBER's avatar
Tobias WEBER committed
134
135
	// ------------------------------------------------------------------------
	// restore settings
Tobias WEBER's avatar
Tobias WEBER committed
136
137
	if(m_pSettings)
	{
138
139
140
		if(m_pSettings->contains("mainwnd/recentsessions"))
			SetRecentFiles(m_pSettings->value("mainwnd/recentsessions").toStringList());

Tobias WEBER's avatar
Tobias WEBER committed
141
142
143
		// restore window state
		if(m_pSettings->contains("mainwnd/geo"))
			this->restoreGeometry(m_pSettings->value("mainwnd/geo").toByteArray());
Tobias WEBER's avatar
Tobias WEBER committed
144
145
		else
			this->resize(800, 600);
Tobias WEBER's avatar
Tobias WEBER committed
146
147
148
		if(m_pSettings->contains("mainwnd/state"))
			this->restoreState(m_pSettings->value("mainwnd/state").toByteArray());
	}
Tobias WEBER's avatar
Tobias WEBER committed
149
	// ------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
150
151
152
153
154
155



	// ------------------------------------------------------------------------
	// add the built-in function list to the completer
	QStringList lstFuncs;
Tobias WEBER's avatar
Tobias WEBER committed
156
157
158
159
160
161
162
163
164
	for(const auto &pair : g_funcs_real_1arg) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 1 argument]").c_str()));
	for(const auto &pair : g_funcs_real_2args) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 2 arguments]").c_str()));
	for(const auto &pair : g_funcs_arr_1arg) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 1 argument]").c_str()));
	for(const auto &pair : g_funcs_arr_2args) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 2 arguments]").c_str()));
	for(const auto &pair : g_funcs_gen_0args) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, no arguments]").c_str()));
	for(const auto &pair : g_funcs_gen_1arg) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 1 argument]").c_str()));
	for(const auto &pair : g_funcs_gen_2args) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, 2 arguments]").c_str()));
	for(const auto &pair : g_funcs_gen_vararg) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [function, variable arguments]").c_str()));
	for(const auto &pair : g_consts_real) lstFuncs.push_back(((pair.first + "###" + std::get<1>(pair.second) + " [constant]").c_str()));
Tobias WEBER's avatar
Tobias WEBER committed
165
166
	m_pCLI->GetWidget()->SetCompleterItems(lstFuncs);
	// ------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
167
168
169
170
}


MainWnd::~MainWnd()
Tobias WEBER's avatar
Tobias WEBER committed
171
172
173
{
	UnloadPlugins();
}
Tobias WEBER's avatar
Tobias WEBER committed
174
175
176


void MainWnd::showEvent(QShowEvent *pEvt)
Tobias WEBER's avatar
Tobias WEBER committed
177
{
Tobias WEBER's avatar
Tobias WEBER committed
178
	QMainWindow::showEvent(pEvt);
Tobias WEBER's avatar
Tobias WEBER committed
179
180
181
182
183
184
185
}


void MainWnd::closeEvent(QCloseEvent *pEvt)
{
	if(m_pSettings)
	{
186
187
188
189
190
		// remove superfluous entries and save the recent files list
		while(m_recentFiles.size() > MAX_RECENT_FILES)
			m_recentFiles.pop_front();
		m_pSettings->setValue("mainwnd/recentsessions", m_recentFiles);

Tobias WEBER's avatar
Tobias WEBER committed
191
192
193
194
195
196
197
		// save window state
		m_pSettings->setValue("mainwnd/geo", this->saveGeometry());
		m_pSettings->setValue("mainwnd/state", this->saveState());
	}

	QMainWindow::closeEvent(pEvt);
}
Tobias WEBER's avatar
Tobias WEBER committed
198
199
200
201
202
203



/**
 * File -> New
 */
204
void MainWnd::NewFile()
Tobias WEBER's avatar
Tobias WEBER committed
205
{
206
	SetCurrentFile("");
Tobias WEBER's avatar
Tobias WEBER committed
207
208
	m_pWS->GetWidget()->GetWorkspace()->clear();
	m_pWS->GetWidget()->UpdateList();
Tobias WEBER's avatar
Tobias WEBER committed
209
210
211
212
213
214
}


/**
 * File -> Open
 */
215
void MainWnd::OpenFile()
Tobias WEBER's avatar
Tobias WEBER committed
216
{
217
	QString dirLast = m_pSettings->value("mainwnd/sessiondir", "").toString();
Tobias WEBER's avatar
Tobias WEBER committed
218

219
220
221
222
223
224
	QString filename = QFileDialog::getOpenFileName(this, "Open File", dirLast, "IN20 Files (*.in20 *.IN20)");
	if(filename=="" || !QFile::exists(filename))
		return;

	if(OpenFile(filename))
		m_pSettings->setValue("mainwnd/sessiondir", QFileInfo(filename).path());
Tobias WEBER's avatar
Tobias WEBER committed
225
226
227
228
229
230
}


/**
 * File -> Save
 */
231
void MainWnd::SaveFile()
Tobias WEBER's avatar
Tobias WEBER committed
232
{
233
234
235
236
	if(m_curFile == "")
		SaveFileAs();
	else
		SaveFile(m_curFile);
Tobias WEBER's avatar
Tobias WEBER committed
237
238
239
240
241
242
}


/**
 * File -> Save As
 */
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
void MainWnd::SaveFileAs()
{
	QString dirLast = m_pSettings->value("mainwnd/sessiondir", "").toString();

	QString filename = QFileDialog::getSaveFileName(this, "Save File", dirLast, "IN20 Files (*.in20 *.IN20)");
	if(filename=="")
		return;

	if(SaveFile(filename))
		m_pSettings->setValue("mainwnd/sessiondir", QFileInfo(filename).path());
}


/**
 * load File
 */
bool MainWnd::OpenFile(const QString &file)
Tobias WEBER's avatar
Tobias WEBER committed
260
{
Tobias WEBER's avatar
Tobias WEBER committed
261
262
	static const std::string basename = "in20/";

263
264
	if(file=="" || !QFile::exists(file))
		return false;
Tobias WEBER's avatar
Tobias WEBER committed
265

Tobias WEBER's avatar
Tobias WEBER committed
266
267

	// load xml
268
	tl2::Prop<std::string> prop;
Tobias WEBER's avatar
Tobias WEBER committed
269
	prop.SetSeparator('/');
270
	if(!prop.Load(file.toStdString(), tl2::PropType::XML))
Tobias WEBER's avatar
Tobias WEBER committed
271
272
273
274
275
276
	{
		QMessageBox::critical(this, "Error", "Could not open session.");	
		return false;
	}

	// check format and version
Tobias WEBER's avatar
Tobias WEBER committed
277
278
279
	auto optFmt = prop.QueryOpt<std::string>(basename + "format");
	auto optVer = prop.QueryOpt<std::string>(basename + "version");
	auto optTime = prop.QueryOpt<t_real>(basename + "timestamp");
Tobias WEBER's avatar
Tobias WEBER committed
280
281
282
283
284
285
	if(!optFmt || *optFmt != "session")
	{
		QMessageBox::critical(this, "Error", "Not a session file. Ignoring.");
		return false;
	}
	if(optVer && optTime)
286
		print_out("Loading session file version ", *optVer, ", dated ", tl2::epoch_to_str(*optTime), ".");
Tobias WEBER's avatar
Tobias WEBER committed
287
288


Tobias WEBER's avatar
Tobias WEBER committed
289
290
	m_pWS->GetWidget()->GetWorkspace()->clear();
	m_pWS->GetWidget()->LoadWorkspace(basename, prop);
Tobias WEBER's avatar
Tobias WEBER committed
291

292
293
294
295
296
297
298
299
300
301
302
303

	SetCurrentFile(file);
	AddRecentFile(file);
	return true;
}


/**
 * save File
 */
bool MainWnd::SaveFile(const QString &file)
{
Tobias WEBER's avatar
Tobias WEBER committed
304
305
	static const std::string basename = "in20/";

306
307
308
	if(file=="")
		return false;

Tobias WEBER's avatar
Tobias WEBER committed
309
310
311
	std::unordered_map<std::string, std::string> sessionmap;

	// set format and version
Tobias WEBER's avatar
Tobias WEBER committed
312
313
	sessionmap[basename + "format"] = "session";
	sessionmap[basename + "version"] = PROGRAM_VERSION;
314
	sessionmap[basename + "timestamp"] = tl2::var_to_str(tl2::epoch<t_real>());
Tobias WEBER's avatar
Tobias WEBER committed
315
316


Tobias WEBER's avatar
Tobias WEBER committed
317
318
	// save workspace variables
	m_pWS->GetWidget()->SaveWorkspace(basename, sessionmap);
Tobias WEBER's avatar
Tobias WEBER committed
319
320


321
	tl2::Prop<std::string> prop;
Tobias WEBER's avatar
Tobias WEBER committed
322
	prop.SetSeparator('/');
Tobias WEBER's avatar
Tobias WEBER committed
323
324
	prop.Add(sessionmap);

325
	if(!prop.Save(file.toStdString(), tl2::PropType::XML))
Tobias WEBER's avatar
Tobias WEBER committed
326
327
328
329
	{
		QMessageBox::critical(this, "Error", "Could not save session.");	
		return false;
	}
330
331
332
333

	SetCurrentFile(file);
	AddRecentFile(file);
	return true;
Tobias WEBER's avatar
Tobias WEBER committed
334
335
}

336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

/**
 * add a file to the recent files menu
 */
void MainWnd::AddRecentFile(const QString &file)
{
	for(const auto &recentfile : m_recentFiles)
	{
		// file already in list?
		if(recentfile == file)
			return;
	}

	m_recentFiles.push_back(file);
	RebuildRecentFiles();
}


/**
 * set the recent file menu
 */
void MainWnd::SetRecentFiles(const QStringList &files)
{
	m_recentFiles = files;
	RebuildRecentFiles();
}


/**
 * create the "recent files" sub-menu
 */
void MainWnd::RebuildRecentFiles()
{
	m_menuOpenRecent->clear();

	std::size_t num_recent_files = 0;
	for(auto iter = m_recentFiles.rbegin(); iter != m_recentFiles.rend(); ++iter)
	{
		QString filename = *iter;
		auto *acFile = new QAction(QIcon::fromTheme("document"), filename, m_pMenu);

		connect(acFile, &QAction::triggered, [this, filename]() { this->OpenFile(filename); });
		m_menuOpenRecent->addAction(acFile);

		if(++num_recent_files >= MAX_RECENT_FILES)
			break;
	}
}


/**
 * remember current file and set window title
 */
void MainWnd::SetCurrentFile(const QString &file)
{
	static const QString title("IN20 Tool");
	m_curFile = file;

	if(m_curFile == "")
		this->setWindowTitle(title);
	else	
		this->setWindowTitle(title + " -- " + m_curFile);
}
Tobias WEBER's avatar
Tobias WEBER committed
399
400
401
402
403
404
405
406



/**
 * looks for and loads plugin tools
 */
void MainWnd::LoadPlugins()
{
Tobias WEBER's avatar
Tobias WEBER committed
407
408
409
410
	m_pmenuPluginTools = new QMenu("Tools", m_pMenu);

	std::vector<QString> plugindirs{{ "plugins", "../plugins", qApp->applicationDirPath()+"/plugins" }};
	for(const auto& plugindir : plugindirs)
Tobias WEBER's avatar
Tobias WEBER committed
411
	{
Tobias WEBER's avatar
Tobias WEBER committed
412
		print_out("Looking for plugins in \"", plugindir.toStdString(), "\"...");
Tobias WEBER's avatar
Tobias WEBER committed
413

Tobias WEBER's avatar
Tobias WEBER committed
414
415
		QDirIterator iter(plugindir, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
		while(iter.hasNext())
Tobias WEBER's avatar
Tobias WEBER committed
416
		{
Tobias WEBER's avatar
Tobias WEBER committed
417
418
419
			std::string dllfile = iter.next().toStdString();
			std::string rawfile = tl2::get_file_nodir(dllfile, false);
			if(rawfile == "." || rawfile == "..")
Tobias WEBER's avatar
Tobias WEBER committed
420
421
				continue;

Tobias WEBER's avatar
Tobias WEBER committed
422
			try
Tobias WEBER's avatar
Tobias WEBER committed
423
			{
Tobias WEBER's avatar
Tobias WEBER committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
				auto dll = std::make_shared<boost::dll::shared_library>(dllfile);
				if(!dll || !dll->is_loaded())
				{
					print_err("Could not load plugin \"", dllfile, "\".");
					continue;
				}

				if(!dll->has("tl_descr") || !dll->has("tl_init") || !dll->has("tl_create") || !dll->has("tl_destroy"))
				{
					print_err("Not a valid plugin: \"", dllfile, "\".");
					continue;
				}


				PluginDlg plugin;
				plugin.dll = dll;

				// plugin functions
				plugin.f_descr = dll->get<PluginDlg::t_descr>("tl_descr");
				plugin.f_init = dll->get<PluginDlg::t_init>("tl_init");
				plugin.f_create = dll->get<PluginDlg::t_create>("tl_create");
				plugin.f_destroy = dll->get<PluginDlg::t_destroy>("tl_destroy");

				// plugin descriptors
				{
					std::vector<std::string> vecdescr;
					tl2::get_tokens<std::string, std::string>(plugin.f_descr(), ";", vecdescr);

					plugin.ty = vecdescr[0];
					plugin.name = vecdescr[1];
					plugin.descr = vecdescr[2];

					// add menu item
					auto *acTool = new QAction(plugin.name.c_str(), m_pMenu);
					acTool->setToolTip(plugin.descr.c_str());
					m_pmenuPluginTools->addAction(acTool);
					const std::size_t pluginNr = m_plugin_dlgs.size();
					connect(acTool, &QAction::triggered, this, [this, pluginNr]()
					{
						if(pluginNr >= m_plugin_dlgs.size())
						{
							print_err("Invalid plugin number ", pluginNr, ".");
							return;
						}

						// get plugin corresponding to this menu item
						auto& plugin = m_plugin_dlgs[pluginNr];
						if(!plugin.inited)
							plugin.inited = plugin.f_init();

						if(plugin.inited && !plugin.dlg)
							plugin.dlg = plugin.f_create(this);

						if(plugin.dlg)
						{
							plugin.dlg->show();
							plugin.dlg->activateWindow();
							plugin.dlg->raise();
							plugin.dlg->setFocus();
						}
					});

					print_out("Plugin ", dll->location(), " loaded. ",
						"Module type: \"", plugin.ty, "\", ",
						"name: \"", plugin.name, "\", ",
						"description: \"", plugin.descr, "\"."); 

					m_plugin_dlgs.emplace_back(std::move(plugin));
				}
Tobias WEBER's avatar
Tobias WEBER committed
493
			}
Tobias WEBER's avatar
Tobias WEBER committed
494
			catch(const std::exception& ex)
Tobias WEBER's avatar
Tobias WEBER committed
495
			{
Tobias WEBER's avatar
Tobias WEBER committed
496
				print_err("Error loading plugin \"", dllfile, "\": ", ex.what(), ".");
Tobias WEBER's avatar
Tobias WEBER committed
497
498
			}
		}
Tobias WEBER's avatar
Tobias WEBER committed
499
500
501
502
503
504
505
506
507
508
509
510
511
	}
}


/**
 * unloads plugins
 */
void MainWnd::UnloadPlugins()
{
	for(auto &plugin : m_plugin_dlgs)
	{
		// remove dialogs
		if(plugin.dlg && plugin.f_destroy)
Tobias WEBER's avatar
Tobias WEBER committed
512
		{
Tobias WEBER's avatar
Tobias WEBER committed
513
514
			plugin.f_destroy(plugin.dlg);
			plugin.dlg = nullptr;
Tobias WEBER's avatar
Tobias WEBER committed
515
		}
Tobias WEBER's avatar
Tobias WEBER committed
516
517

		plugin.inited = false;
Tobias WEBER's avatar
Tobias WEBER committed
518
	}
Tobias WEBER's avatar
Tobias WEBER committed
519
520
521

	m_plugin_dlgs.clear();
}