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

Method exportKBMFileWithFileBrowser

Source/gui/TuningComponent.cpp:149–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149void TuningComponent::exportKBMFileWithFileBrowser() {
150 DBG("exportKBMFile()");
151 DBG(m_processor.m_tuning.keyboardMapping.rawText);
152
153 auto suggested_dir = ConfigFileManager::getInstance().getOptionTuningDir();
154
155 File file_suggestion(suggested_dir + File::getSeparatorString() + "mapping.kbm");
156
157 // set up filechooser
158 m_filechooser.reset(new FileChooser("Choose a file to save...", file_suggestion, "*.kbm", true));
159
160 //launch filechooser
161 m_filechooser->launchAsync(
162 FileBrowserComponent::saveMode | FileBrowserComponent::canSelectFiles,
163 [file_suggestion, this](const FileChooser &chooser) {
164 auto result = chooser.getURLResult();
165 String file_name = result.isEmpty() ? String()
166 : (result.isLocalFile() ? result.getLocalFile().getFullPathName()
167 : result.toString(true));
168
169 if (file_name != "") {
170 //append .odin if not already there
171 file_name = file_name.endsWith(".kbm") ? file_name : file_name + ".kbm";
172
173 File file_to_write(file_name);
174
175 //check whether file already exists
176 if (file_to_write.existsAsFile()) {
177 if (!(AlertWindow::showOkCancelBox(AlertWindow::WarningIcon,
178 "File already exists!",
179 "Are you sure you want to overwrite it?",
180 {},
181 {},
182 {}))) {
183 //user selected cancel
184 return;
185 }
186 }
187 FileOutputStream file_stream(file_to_write);
188
189 ConfigFileManager::getInstance().setOptionTuningDir(
190 file_to_write.getParentDirectory().getFullPathName());
191 ConfigFileManager::getInstance().saveDataToFile();
192
193 if (file_stream.openedOk()) {
194 DBG("Writing kbm mapping file to " << file_to_write.getFullPathName());
195 file_stream.setPosition(0);
196 file_stream << String(m_processor.m_tuning.keyboardMapping.rawText);
197 file_stream.flush();
198 } else {
199 AlertWindow::showMessageBox(
200 AlertWindow::AlertIconType::WarningIcon,
201 "Unable to save file!",
202 "Please make sure you have proper write-permissions for the selected directory!");
203 }
204 }
205 });
206}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected