Skip to content

Commit 5dafc6a

Browse files
committed
Fix config dir path and cleaned up whitespace
1 parent 8b62459 commit 5dafc6a

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/TmcModuleInstall.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import fi.helsinki.cs.tmc.core.TmcCore;
44
import fi.helsinki.cs.tmc.core.communication.TmcServerCommunicationTaskFactory;
5+
import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
56
import fi.helsinki.cs.tmc.core.domain.Course;
67
import fi.helsinki.cs.tmc.core.holders.TmcLangsHolder;
78
import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder;
@@ -36,19 +37,22 @@ public class TmcModuleInstall extends ModuleInstall {
3637

3738
@Override
3839
public void restored() {
40+
TmcSettingsHolder.set(new TmcCoreSettingsImpl());
41+
TmcLangsHolder.set(new TaskExecutorImpl());
42+
3943
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
4044
@Override
4145
public void run() {
42-
TmcLangsHolder.set(new TaskExecutorImpl());
43-
TmcSettingsHolder.set(new TmcCoreSettingsImpl());
46+
4447
TmcCore.setInstance(new TmcCore());
45-
48+
4649
CheckForNewExercisesOrUpdates.startTimer();
4750
CheckForNewReviews.startTimer();
4851
ReviewEventListener.start();
4952
PushEventListener.start();
53+
TmcSettings settings = TmcSettingsHolder.get();
5054
SpywareFacade.start();
51-
55+
5256
Preferences prefs = NbPreferences.forModule(TmcModuleInstall.class);
5357

5458
SpecificationVersion currentVersion = getCurrentModuleVersion();
@@ -90,7 +94,7 @@ public void bgTaskFailed(Throwable ex) {
9094
log.warning("moduleInstall refresh failed " + ex);
9195
}
9296
}).run();
93-
*/
97+
*/
9498
}
9599
}
96100
});

tmc-plugin/src/fi/helsinki/cs/tmc/coreimpl/TmcCoreSettingsImpl.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
import fi.helsinki.cs.tmc.tailoring.Tailoring;
1111

1212
import com.google.common.base.Optional;
13+
import java.io.IOException;
1314
import java.net.ProxySelector;
1415
import java.nio.file.Path;
1516
import java.nio.file.Paths;
1617
import java.util.Locale;
1718
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
19+
import org.openide.filesystems.FileObject;
20+
import org.openide.filesystems.FileStateInvalidException;
21+
import org.openide.filesystems.FileUtil;
22+
import org.openide.util.Exceptions;
1823
import org.openide.util.Lookup;
1924
import org.openide.util.NbPreferences;
2025

@@ -105,7 +110,18 @@ public void setConfigRoot(Path path) {
105110

106111
@Override
107112
public Path getConfigRoot() {
108-
return Paths.get(NbPreferences.forModule(TmcCoreSettingsImpl.class).absolutePath());
113+
FileObject root = FileUtil.getConfigRoot();
114+
FileObject tmcRoot = root.getFileObject("tmc");
115+
116+
if (tmcRoot == null) {
117+
try {
118+
tmcRoot = root.createFolder("tmc");
119+
} catch (IOException ex) {
120+
throw new RuntimeException(ex);
121+
}
122+
}
123+
124+
return FileUtil.toFile(tmcRoot).toPath();
109125
}
110126

111127
public static class SavedEvent implements TmcEvent {}

tmc-plugin/src/fi/helsinki/cs/tmc/ui/ExerciseIconAnnotator.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.netbeans.api.project.Project;
2424
import org.netbeans.spi.project.ProjectIconAnnotator;
2525
import org.openide.util.ChangeSupport;
26+
import org.openide.util.Exceptions;
2627
import org.openide.util.ImageUtilities;
2728
import org.openide.util.lookup.ServiceProvider;
2829

@@ -44,7 +45,7 @@ public ExerciseIconAnnotator() {
4445
this.courses = CourseDb.getInstance();
4546
this.projectMediator = ProjectMediator.getInstance();
4647
this.iconCache = new HashMap<String, Image>();
47-
48+
4849
eventBus.subscribeDependent(new TmcEventListener() {
4950
public void receive(CourseDb.ChangedEvent event) {
5051
SwingUtilities.invokeLater(new Runnable() {
@@ -64,10 +65,10 @@ public Image annotateIcon(Project nbProject, Image origImg, boolean openedNode)
6465
if (exercise == null || !exercise.getCourseName().equals(courses.getCurrentCourseName())) {
6566
return origImg;
6667
}
67-
68+
6869
//TODO: use ImageUtilities.createDisabledImage for expired exercises.
6970
//Had some very weird problems with that. Try again some day.
70-
71+
7172
Image img = origImg;
7273
try {
7374
Image annotation = annotationIconForExericse(exercise);
@@ -77,13 +78,13 @@ public Image annotateIcon(Project nbProject, Image origImg, boolean openedNode)
7778
} catch (IOException e) {
7879
log.log(Level.WARNING, "Failed to load exercise icon annotation", e);
7980
}
80-
81+
8182
String tooltip = tooltipForExercise(exercise);
8283
img = ImageUtilities.assignToolTipToImage(img, tooltip);
83-
84+
8485
return img;
8586
}
86-
87+
8788
private Image annotationIconForExericse(Exercise exercise) throws IOException {
8889
String name = annotationIconNameForExercise(exercise);
8990
if (name != null) {
@@ -96,7 +97,7 @@ private Image annotationIconForExericse(Exercise exercise) throws IOException {
9697
return null;
9798
}
9899
}
99-
100+
100101
private String annotationIconNameForExercise(Exercise exercise) {
101102
if (exercise.hasDeadlinePassed()) {
102103
return null;
@@ -110,7 +111,7 @@ private String annotationIconNameForExercise(Exercise exercise) {
110111
return "black-project-dot.png";
111112
}
112113
}
113-
114+
114115
private String tooltipForExercise(Exercise exercise) {
115116
List<String> parts = new ArrayList<String>();
116117
if (exercise.isAttempted()) {
@@ -129,23 +130,23 @@ private String tooltipForExercise(Exercise exercise) {
129130
parts.add("code review not yet done");
130131
}
131132
}
132-
133+
133134
} else {
134135
parts.add("exercise not yet submitted");
135136
}
136-
137+
137138
if (!exercise.isCompleted() && exercise.getDeadline() != null) {
138139
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
139140
parts.add("deadline: " + df.format(exercise.getDeadline()));
140141
}
141-
142+
142143
return StringUtils.capitalize(StringUtils.join(parts, " - "));
143144
}
144-
145+
145146
public void updateAllIcons() {
146147
changeSupport.fireChange();
147148
}
148-
149+
149150
@Override
150151
public void addChangeListener(ChangeListener listener) {
151152
changeSupport.addChangeListener(listener);

0 commit comments

Comments
 (0)