3737import de .doubleslash .keeptime .model .Settings ;
3838import de .doubleslash .keeptime .model .Work ;
3939import javafx .collections .ObservableList ;
40- import javafx .scene .paint .Color ;
4140
4241@ Service
4342public class Controller {
@@ -119,25 +118,24 @@ public void addNewProject(final Project project) {
119118 model .getProjectRepository ().saveAll (changedProjects );
120119 }
121120
122- public void updateSettings (final Color hoverBackgroundColor , final Color hoverFontColor ,
123- final Color defaultBackgroundColor , final Color defaultFontColor , final Color taskBarColor ,
124- final boolean useHotkey , final boolean displayProjectsRight , final boolean hideProjectsOnMouseExit ,
125- final boolean emptyNoteReminder ) {
126- // TODO create holder for all the properties (or reuse Settings.class?)
127- final Settings settings = model .getSettingsRepository ().findAll ().get (0 );
128- settings .setTaskBarColor (taskBarColor );
129-
130- settings .setDefaultBackgroundColor (defaultBackgroundColor );
131- settings .setDefaultFontColor (defaultFontColor );
132-
133- settings .setHoverBackgroundColor (hoverBackgroundColor );
134- settings .setHoverFontColor (hoverFontColor );
135- settings .setUseHotkey (useHotkey );
136- settings .setDisplayProjectsRight (displayProjectsRight );
137- settings .setHideProjectsOnMouseExit (hideProjectsOnMouseExit );
138- settings .setRemindIfNotesAreEmpty (emptyNoteReminder );
139-
140- model .getSettingsRepository ().save (settings );
121+ public void updateSettings (final Settings newValuedSettings ) {
122+ Settings settings = model .getSettingsRepository ().findAll ().get (0 );
123+
124+ settings .setTaskBarColor (newValuedSettings .getTaskBarColor ());
125+ settings .setDefaultBackgroundColor (newValuedSettings .getDefaultBackgroundColor ());
126+ settings .setDefaultFontColor (newValuedSettings .getDefaultFontColor ());
127+ settings .setHoverBackgroundColor (newValuedSettings .getHoverBackgroundColor ());
128+ settings .setHoverFontColor (newValuedSettings .getHoverFontColor ());
129+ settings .setUseHotkey (newValuedSettings .isUseHotkey ());
130+ settings .setDisplayProjectsRight (newValuedSettings .isDisplayProjectsRight ());
131+ settings .setHideProjectsOnMouseExit (newValuedSettings .isHideProjectsOnMouseExit ());
132+ settings .setSaveWindowPosition (newValuedSettings .isSaveWindowPosition ());
133+ settings .setWindowXProportion (newValuedSettings .getWindowXProportion ());
134+ settings .setWindowYProportion (newValuedSettings .getWindowYProportion ());
135+ settings .setScreenHash (newValuedSettings .getScreenHash ());
136+ settings .setRemindIfNotesAreEmpty (newValuedSettings .isRemindIfNotesAreEmpty ());
137+
138+ settings = model .getSettingsRepository ().save (settings );
141139
142140 model .defaultBackgroundColor .set (settings .getDefaultBackgroundColor ());
143141 model .defaultFontColor .set (settings .getDefaultFontColor ());
@@ -147,13 +145,28 @@ public void updateSettings(final Color hoverBackgroundColor, final Color hoverFo
147145 model .useHotkey .set (settings .isUseHotkey ());
148146 model .displayProjectsRight .set (settings .isDisplayProjectsRight ());
149147 model .hideProjectsOnMouseExit .set (settings .isHideProjectsOnMouseExit ());
148+ model .screenSettings .saveWindowPosition .set (settings .isSaveWindowPosition ());
149+ model .screenSettings .proportionalX .set (settings .getWindowXProportion ());
150+ model .screenSettings .proportionalY .set (settings .getWindowYProportion ());
151+ model .screenSettings .screenHash .set (settings .getScreenHash ());
150152 model .remindIfNotesAreEmpty .set (settings .isRemindIfNotesAreEmpty ());
151153 }
152154
153155 @ PreDestroy
154156 public void shutdown () {
155157 LOG .info ("Controller shutdown" );
156- saveCurrentWork (dateProvider .dateTimeNow ());
158+
159+ LOG .info ("Changing project to persist current work on shutdown." );
160+ changeProject (model .getIdleProject (), 0 );
161+
162+ LOG .info ("Updating settings to persist local changes on shutdown." );
163+ final Settings newSettings = new Settings (model .hoverBackgroundColor .get (), model .hoverFontColor .get (),
164+ model .defaultBackgroundColor .get (), model .defaultFontColor .get (), model .taskBarColor .get (),
165+ model .useHotkey .get (), model .displayProjectsRight .get (), model .hideProjectsOnMouseExit .get (),
166+ model .screenSettings .proportionalX .get (), model .screenSettings .proportionalY .get (),
167+ model .screenSettings .screenHash .get (), model .screenSettings .saveWindowPosition .get (),
168+ model .remindIfNotesAreEmpty .get ());
169+ updateSettings (newSettings );
157170 }
158171
159172 public void deleteProject (final Project p ) {
@@ -235,13 +248,13 @@ public void deleteWork(final Work workToBeDeleted) {
235248 * Changes the indexes of the originalList parameter to have a consistent order.
236249 *
237250 * @param originalList
238- * list of all projects to adapt the indexes for
251+ * list of all projects to adapt the indexes for
239252 * @param changedProject
240- * the project which has changed which already has the new index
253+ * the project which has changed which already has the new index
241254 * @param oldIndex
242- * the old index of the changed project
255+ * the old index of the changed project
243256 * @param newIndex
244- * the new index of the changed project (which the projects also already has)
257+ * the new index of the changed project (which the projects also already has)
245258 * @return all projects whose index has been adapted
246259 */
247260 List <Project > resortProjectIndexes (final List <Project > originalList , final Project changedProject ,
@@ -278,9 +291,9 @@ List<Project> resortProjectIndexes(final List<Project> originalList, final Proje
278291 * Decreases all indexes by one, after the removed index
279292 *
280293 * @param originalList
281- * list of all projects to adapt the indexes for
294+ * list of all projects to adapt the indexes for
282295 * @param removedIndex
283- * the index which has been removed
296+ * the index which has been removed
284297 * @return all projects whose index has been adapted
285298 */
286299 List <Project > adaptProjectIndexesAfterRemoving (final List <Project > originalList , final int removedIndex ) {
0 commit comments