422 setSetting<Setting::RenderStyle>(renderPreferences.style); |
422 setSetting<Setting::RenderStyle>(renderPreferences.style); |
423 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes); |
423 setSetting<Setting::DrawAxes>(renderPreferences.drawAxes); |
424 setSetting<Setting::Wireframe>(renderPreferences.wireframe); |
424 setSetting<Setting::Wireframe>(renderPreferences.wireframe); |
425 libraries.storeToSettings(); |
425 libraries.storeToSettings(); |
426 settingsChanged.emit(); |
426 settingsChanged.emit(); |
427 }; |
|
428 const auto updateRecentlyOpenedDocumentsMenu = [&]{ |
|
429 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); |
|
430 for (QAction* action : ui.menuRecentFiles->findChildren<QAction*>()) { |
|
431 QString path = action->data().toString(); |
|
432 QObject::connect( |
|
433 action, |
|
434 &QAction::triggered, |
|
435 [path, &libraries, &documents, &mainWindow]() { |
|
436 openModelFromPath(path, &libraries, &documents, &mainWindow); |
|
437 } |
|
438 ); |
|
439 } |
|
440 }; |
427 }; |
441 const auto executeAction = [&]( |
428 const auto executeAction = [&]( |
442 QTextDocument* model, const ModelAction& action |
429 QTextDocument* model, const ModelAction& action |
443 ) { |
430 ) { |
444 std::visit(overloaded{ |
431 std::visit(overloaded{ |
462 } |
449 } |
463 //model->assignAt(action.position, action.newElement); |
450 //model->assignAt(action.position, action.newElement); |
464 }, |
451 }, |
465 }, action); |
452 }, action); |
466 |
453 |
467 }; |
|
468 const auto restoreSettings = [&]{ |
|
469 recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
|
470 renderPreferences = loadRenderPreferences(); |
|
471 libraries.restoreFromSettings(); |
|
472 updateRecentlyOpenedDocumentsMenu(); |
|
473 colorTable = loadColors(&libraries); |
|
474 updateRenderPreferences(&ui, &renderPreferences, &documents); |
|
475 ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
|
476 ui.retranslateUi(&mainWindow); |
|
477 mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
|
478 settingsChanged.emit(); |
|
479 }; |
|
480 const auto addRecentlyOpenedFile = [&](const QString& path){ |
|
481 constexpr int maxRecentlyOpenedFiles = 10; |
|
482 recentlyOpenedFiles.removeAll(path); |
|
483 recentlyOpenedFiles.insert(0, path); |
|
484 while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) |
|
485 { |
|
486 recentlyOpenedFiles.removeLast(); |
|
487 } |
|
488 saveSettings(); |
|
489 updateRecentlyOpenedDocumentsMenu(); |
|
490 }; |
454 }; |
491 const auto openModelForEditing = [&](const ModelId modelId){ |
455 const auto openModelForEditing = [&](const ModelId modelId){ |
492 QTextDocument* model = documents.getModelById(modelId); |
456 QTextDocument* model = documents.getModelById(modelId); |
493 if (model != nullptr) { |
457 if (model != nullptr) { |
494 ModelData* data = new ModelData(&documents); |
458 ModelData* data = new ModelData(&documents); |
558 subWindow->setWidget(data->canvas.get()); |
522 subWindow->setWidget(data->canvas.get()); |
559 subWindow->setWindowTitle(tabName(fileInfo)); |
523 subWindow->setWindowTitle(tabName(fileInfo)); |
560 subWindow->show(); |
524 subWindow->show(); |
561 } |
525 } |
562 }; |
526 }; |
|
527 const auto updateRecentlyOpenedDocumentsMenu = [&]{ |
|
528 rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); |
|
529 for (QAction* action : ui.menuRecentFiles->actions()) { |
|
530 QString path = action->data().toString(); |
|
531 QObject::connect( |
|
532 action, |
|
533 &QAction::triggered, |
|
534 [path, &libraries, &documents, &mainWindow, &openModelForEditing]() { |
|
535 const auto id = openModelFromPath(path, &libraries, &documents, &mainWindow); |
|
536 if (id.has_value()) |
|
537 { |
|
538 openModelForEditing(id.value()); |
|
539 } |
|
540 } |
|
541 ); |
|
542 } |
|
543 }; |
|
544 const auto restoreSettings = [&]{ |
|
545 recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
|
546 renderPreferences = loadRenderPreferences(); |
|
547 libraries.restoreFromSettings(); |
|
548 updateRecentlyOpenedDocumentsMenu(); |
|
549 colorTable = loadColors(&libraries); |
|
550 updateRenderPreferences(&ui, &renderPreferences, &documents); |
|
551 ui.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
|
552 ui.retranslateUi(&mainWindow); |
|
553 mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
|
554 settingsChanged.emit(); |
|
555 }; |
|
556 const auto addRecentlyOpenedFile = [&](const QString& path){ |
|
557 constexpr int maxRecentlyOpenedFiles = 10; |
|
558 recentlyOpenedFiles.removeAll(path); |
|
559 recentlyOpenedFiles.insert(0, path); |
|
560 while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) |
|
561 { |
|
562 recentlyOpenedFiles.removeLast(); |
|
563 } |
|
564 saveSettings(); |
|
565 updateRecentlyOpenedDocumentsMenu(); |
|
566 }; |
563 QObject::connect(ui.actionNew, &QAction::triggered, [&]{ |
567 QObject::connect(ui.actionNew, &QAction::triggered, [&]{ |
564 openModelForEditing(documents.newModel()); |
568 openModelForEditing(documents.newModel()); |
565 }); |
569 }); |
566 QObject::connect(ui.actionOpen, &QAction::triggered, [&]{ |
570 QObject::connect(ui.actionOpen, &QAction::triggered, [&]{ |
567 const QString path = getOpenModelPath(&mainWindow); |
571 const QString path = getOpenModelPath(&mainWindow); |