MCPcopy Create free account
hub / github.com/TheWaveWarden/odin2 / exportSCLFileWithFileBrowser

Method exportSCLFileWithFileBrowser

Source/gui/TuningComponent.cpp:88–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void TuningComponent::exportSCLFileWithFileBrowser() {
89 DBG("exportSCLFile()");
90
91 DBG(m_processor.m_tuning.scale.rawText);
92
93 auto suggested_dir = ConfigFileManager::getInstance().getOptionTuningDir();
94
95 File file_suggestion(suggested_dir + File::getSeparatorString() + "tuning.scl");
96
97 // set up filechooser
98 m_filechooser.reset(new FileChooser("Choose a file to save...", file_suggestion, "*.scl", true));
99
100 //launch filechooser
101 m_filechooser->launchAsync(
102 FileBrowserComponent::saveMode | FileBrowserComponent::canSelectFiles,
103 [file_suggestion, this](const FileChooser &chooser) {
104 auto result = chooser.getURLResult();
105 String file_name = result.isEmpty() ? String()
106 : (result.isLocalFile() ? result.getLocalFile().getFullPathName()
107 : result.toString(true));
108
109 if (file_name != "") {
110 //append .odin if not already there
111 file_name = file_name.endsWith(".scl") ? file_name : file_name + ".scl";
112
113 File file_to_write(file_name);
114
115 //check whether file already exists
116 if (file_to_write.existsAsFile()) {
117 if (!(AlertWindow::showOkCancelBox(AlertWindow::WarningIcon,
118 "File already exists!",
119 "Are you sure you want to overwrite it?",
120 {},
121 {},
122 {}))) {
123 //user selected cancel
124 return;
125 }
126 }
127 FileOutputStream file_stream(file_to_write);
128
129 ConfigFileManager::getInstance().saveDataToFile();
130 ConfigFileManager::getInstance().setOptionTuningDir(
131 file_to_write.getParentDirectory().getFullPathName());
132
133 if (file_stream.openedOk()) {
134 DBG("Writing tuning file to " << file_to_write.getFullPathName());
135 file_stream.setPosition(0);
136 file_stream << String(m_processor.m_tuning.scale.rawText);
137 file_stream.flush();
138 //savePatchInOpenedFileStream(file_stream);
139 } else {
140 AlertWindow::showMessageBox(
141 AlertWindow::AlertIconType::WarningIcon,
142 "Unable to save file!",
143 "Please make sure you have proper write-permissions for the selected directory!");
144 }
145 }

Callers

nothing calls this directly

Calls 5

getOptionTuningDirMethod · 0.80
saveDataToFileMethod · 0.80
setOptionTuningDirMethod · 0.80
resetMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected