@@ -16,6 +16,7 @@ public class Duke {
16
16
static ArrayList <Task > listInputs = new ArrayList <>();
17
17
public static String listPath = "/src/main/java/taskList.txt" ;
18
18
public static boolean isPrintMessageEnabled = true ;
19
+ public static boolean isLoading = true ;
19
20
//static int listPosition = 0;
20
21
21
22
private static final String BYE_MESSAGE = " " + "Bye. Hope to see you again soon!" ;
@@ -162,6 +163,13 @@ public static void eventOperation(String input){
162
163
* save command triggered: manually save tasks in list
163
164
*/
164
165
public static void saveOperation (){
166
+ if (listInputs .size () <= 0 ){
167
+ printMessage (" List is empty" );
168
+ return ;
169
+ }else if (isLoading == true ){
170
+ return ;
171
+ }
172
+
165
173
isPrintMessageEnabled = false ;
166
174
try {
167
175
writeListToFile (listPath );
@@ -238,17 +246,20 @@ public static void createNewFile(String filePath){
238
246
}
239
247
}catch (IOException e ) {
240
248
System .out .println ("An error occurred." );
249
+ System .out .println ("listPath: " + listPath );
241
250
}
242
251
}
243
252
244
253
public static void getList (String taskListPath ){
245
254
isPrintMessageEnabled = false ;
255
+ isLoading = true ;
246
256
try {
247
257
fileToList (taskListPath );
248
258
} catch (FileNotFoundException e ) {
249
259
createNewFile (taskListPath );
250
260
}finally {
251
261
isPrintMessageEnabled = true ;
262
+ isLoading = false ;
252
263
}
253
264
}
254
265
0 commit comments