Skip to content

Commit

Permalink
improve template service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean28518 committed May 13, 2023
1 parent c11dc72 commit eaa769c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/lib/services/template_setting_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class TemplateSettingService {
// Save the templateSettings map in the template file
List<String> templateLines = _getLinesFromSettingsFile();

print("Huhu");

// Read the lines and store the settings in the templateSettings map
bool settingSet = false;
for (int i = 0; i < templateLines.length; i++) {
String line = templateLines[i];
if (line.startsWith(r'\newcommand{')) {
Expand All @@ -62,11 +61,23 @@ class TemplateSettingService {
lineSplit[0] = lineSplit[0].replaceAll('\\', "");
// Check if the key is the same as the key we are looking for
if (lineSplit[0] == key) {
if (value.isEmpty) {
// If the key is empty, remove the line
templateLines.removeAt(i);
i--;
settingSet = true;
continue;
}
// If the key is the same, replace the value
templateLines[i] = r'\newcommand{\' + key + r'}{' + value + r'}';
settingSet = true;
}
}
}
if (!settingSet) {
// If the setting is not set, add it to the end of the file
templateLines.add(r'\newcommand{\' + key + r'}{' + value + r'}');
}
// Write the templateLines to the template file
File templateFile = File('${getConfigDirectory()}/template.tex');
templateFile.writeAsStringSync(templateLines.join('\n'));
Expand Down
7 changes: 1 addition & 6 deletions src/lib/widgets/template_setting_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,17 @@ class TemplateSettingWidgetTextLine extends StatelessWidget {
},
controller: controller,
),
SizedBox(
const SizedBox(
width: 20,
),
MintYButton(
// text: const Text("Speichern", style: MintY.heading4White),
text: const Icon(
Icons.save,
color: Colors.white,
),
width: 50,
color: MintY.currentColor,
onPressed: () {
// remove all latex key characters from the value
value = value.replaceAll(r'\', '');
value = value.replaceAll('{', '');
value = value.replaceAll('}', '');
TemplateSettingService.saveValue(latexKey, value);
controller.text = value;
},
Expand Down

0 comments on commit eaa769c

Please sign in to comment.