summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-03-01 14:23:48 +0100
committerSimon Rettberg2019-03-01 14:23:48 +0100
commitbad4aa69f978a8cdd4debad1a8454f87c90dce87 (patch)
tree595201e525d9f8e9d8ce183b3640927c61b12fe8
parent[client] set to nothing instead of empty marker (diff)
downloadtutor-module-bad4aa69f978a8cdd4debad1a8454f87c90dce87.tar.gz
tutor-module-bad4aa69f978a8cdd4debad1a8454f87c90dce87.tar.xz
tutor-module-bad4aa69f978a8cdd4debad1a8454f87c90dce87.zip
[client] Fix editing custom runscript
-rwxr-xr-xdozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/StartupConfigurator.java82
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java2
2 files changed, 43 insertions, 41 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/StartupConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/StartupConfigurator.java
index eaa64af3..a9cafc03 100755
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/StartupConfigurator.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/configurator/StartupConfigurator.java
@@ -224,49 +224,39 @@ public class StartupConfigurator extends StartupConfiguratorLayout {
taRunScript.setText("");
return;
}
- String header = null;
- try (BufferedReader reader = new BufferedReader(new StringReader(lecture))) {
- header = reader.readLine();
- } catch (IOException e) {
- // swallow ...
- }
- if (header != null) {
- // we should have following format: ext=<interpreter/extension>;visibility=<flag>;...
- // e.g. ext=sh;visibility=0
- startupSettings.deserializeItems(header);
- String extension = startupSettings.get(Field.EXTENSION);
- for (RunscriptType type : RunscriptType.values()) {
- if (type.extension.equals(extension)) {
- cboRunscriptType.setSelectedItem(type);
- // mark that we found it by nulling the shebang...
- extension = null;
- break;
- }
+
+ startupSettings.deserializeItems(lecture);
+ String extension = startupSettings.get(Field.EXTENSION);
+ for (RunscriptType type : RunscriptType.values()) {
+ if (type.extension.equals(extension)) {
+ cboRunscriptType.setSelectedItem(type);
+ // mark that we found it by nulling the shebang...
+ extension = null;
+ break;
}
- int visibility = Util.parseInt(startupSettings.get(Field.VISIBILITY), 1);
- for (RunscriptVisibility windowFlag : RunscriptVisibility.values()) {
- if (windowFlag.value == visibility) {
- cboRunscriptVisibility.setSelectedItem(windowFlag);
- break;
- }
+ }
+ int visibility = Util.parseInt(startupSettings.get(Field.VISIBILITY), 1);
+ for (RunscriptVisibility windowFlag : RunscriptVisibility.values()) {
+ if (windowFlag.value == visibility) {
+ cboRunscriptVisibility.setSelectedItem(windowFlag);
+ break;
}
- cboSoundState.setSelectedItem(SoundState.DEFAULT);
- int mute = Util.parseInt(startupSettings.get(Field.MUTED), -1);
- for (SoundState s : SoundState.values()) {
- if (s.value == mute) {
- cboSoundState.setSelectedItem(s);
- break;
- }
+ }
+ cboSoundState.setSelectedItem(SoundState.DEFAULT);
+ int mute = Util.parseInt(startupSettings.get(Field.MUTED), -1);
+ for (SoundState s : SoundState.values()) {
+ if (s.value == mute) {
+ cboSoundState.setSelectedItem(s);
+ break;
}
+ }
- if (extension != null) {
- // user specific shebang, so just write the text to the cbo
- cboRunscriptType.getEditor().setItem(extension);
- }
+ if (extension != null) {
+ // user specific shebang, so just write the text to the cbo
+ cboRunscriptType.getEditor().setItem(extension);
}
- // finished with the interpreter, remove that line from the given config
- // before setting that text
- taRunScript.setText(lecture.replaceFirst(".*?\n", ""));
+
+ taRunScript.setText(startupSettings.runScript);
}
public void addToChangeMonitor(DialogChangeMonitor changeMonitor) {
@@ -325,20 +315,32 @@ public class StartupConfigurator extends StartupConfiguratorLayout {
sb.append('=');
sb.append(e.getValue());
}
+ sb.append('\n');
+ if (this.runScript != null) {
+ sb.append(this.runScript);
+ }
return sb.toString();
}
public void deserializeItems(String data) {
- if (data == null)
+ if (data == null || data.isEmpty())
return;
+ String[] stuff = data.split("\n", 2);
+ // we should have following format: ext=<interpreter/extension>;visibility=<flag>;...
+ // e.g. ext=sh;visibility=0
items.clear();
- String[] parts = data.split(";");
+ String[] parts = stuff[0].split(";");
for (String s : parts) {
String[] entry = s.split("=");
if (entry.length == 2) {
items.put(entry[0], entry[1]);
}
}
+ if (stuff.length < 2) {
+ runScript = "";
+ } else {
+ runScript = stuff[1];
+ }
}
@Override
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
index a88bef22..7a698618 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
@@ -530,7 +530,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout implements
final LectureWrite metadata = new LectureWrite(txtTitle.getText(), txtDescription.getText(),
lecture.getImageVersionId(), chkAutoUpdate.isSelected(), chkIsActive.isSelected(),
startTime, endTime,
- startupSettings.runScript, null,
+ startupSettings.serializeItems(), null,
chkIsExam.isSelected(),
chkHasInternetAccess.isSelected(),
lecture.getDefaultPermissions(), ctlLocationSelector.getSelectedLocationsAsIds(),