MCPcopy Create free account
hub / github.com/FabricMC/Matcher / loadMappings

Method loadMappings

src/main/java/matcher/gui/menu/FileMenu.java:146–194  ·  view source on GitHub ↗
(MappingFormat format)

Source from the content-addressed store, hash-verified

144 }
145
146 private void loadMappings(MappingFormat format) {
147 Window window = gui.getScene().getWindow();
148 Path file;
149
150 if (format == null || format.hasSingleFile()) {
151 SelectedFile res = Gui.requestFile("Select mapping file", window, getMappingLoadExtensionFilters(), true); // TODO: pre-select format if non-null
152 if (res == null) return; // aborted
153
154 file = res.path;
155 format = getFormat(res.filter.getDescription());
156 } else {
157 file = Gui.requestDir("Select mapping dir", window);
158 }
159
160 if (file == null) return;
161
162 try {
163 List<String> namespaces = MappingReader.getNamespaces(file, format);
164
165 Dialog<MappingsLoadSettings> dialog = new Dialog<>();
166 //dialog.initModality(Modality.APPLICATION_MODAL);
167 dialog.setResizable(true);
168 dialog.setTitle("Import Settings");
169 dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
170
171 LoadMappingsPane content = new LoadMappingsPane(namespaces);
172 dialog.getDialogPane().setContent(content);
173 dialog.setResultConverter(button -> button == ButtonType.OK ? content.getSettings() : null);
174 final MappingFormat loadFormat = format;
175
176 Optional<MappingsLoadSettings> result = dialog.showAndWait();
177 if (!result.isPresent()) return;
178
179 MappingsLoadSettings settings = result.get();
180 ClassEnvironment env = gui.getMatcher().getEnv();
181
182 Mappings.load(file, loadFormat,
183 settings.nsSource, settings.nsTarget,
184 settings.fieldSource, settings.fieldTarget,
185 (settings.a ? env.getEnvA() : env.getEnvB()),
186 settings.replace);
187 } catch (IOException e) {
188 e.printStackTrace();
189 gui.showAlert(AlertType.ERROR, "Load error", "Error while loading mappings", e.toString());
190 return;
191 }
192
193 gui.onMappingChange();
194 }
195
196 private static List<ExtensionFilter> getMappingLoadExtensionFilters() {
197 MappingFormat[] formats = MappingFormat.values();

Callers 1

initMethod · 0.95

Calls 15

requestFileMethod · 0.95
getFormatMethod · 0.95
requestDirMethod · 0.95
getSettingsMethod · 0.95
loadMethod · 0.95
getEnvAMethod · 0.95
getEnvBMethod · 0.95
getSceneMethod · 0.80
getMatcherMethod · 0.80
showAlertMethod · 0.80
getEnvMethod · 0.65

Tested by

no test coverage detected