| 748 | } |
| 749 | |
| 750 | void ModuleWidget::saveDialog() { |
| 751 | std::string presetDir = model->getUserPresetDirectory(); |
| 752 | system::createDirectories(presetDir); |
| 753 | |
| 754 | WeakPtr<ModuleWidget> weakThis = this; |
| 755 | async_dialog_filebrowser(true, "preset.vcvm", presetDir.c_str(), "Save preset", [=](char* pathC) { |
| 756 | |
| 757 | // Delete directories if empty |
| 758 | DEFER({ |
| 759 | try { |
| 760 | system::remove(presetDir); |
| 761 | system::remove(system::getDirectory(presetDir)); |
| 762 | } |
| 763 | catch (Exception& e) { |
| 764 | // Ignore exceptions if directory cannot be removed. |
| 765 | } |
| 766 | }); |
| 767 | |
| 768 | if (!weakThis) |
| 769 | return; |
| 770 | if (!pathC) { |
| 771 | // No path selected |
| 772 | return; |
| 773 | } |
| 774 | DEFER({std::free(pathC);}); |
| 775 | |
| 776 | std::string path = pathC; |
| 777 | // Automatically append .vcvm extension |
| 778 | if (system::getExtension(path) != ".vcvm") |
| 779 | path += ".vcvm"; |
| 780 | |
| 781 | weakThis->save(path); |
| 782 | }); |
| 783 | } |
| 784 | |
| 785 | void ModuleWidget::disconnect() { |
| 786 | for (PortWidget* pw : getPorts()) { |
no test coverage detected