summaryrefslogtreecommitdiff
path: root/apps/plugins/text_editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_editor.c')
-rw-r--r--apps/plugins/text_editor.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index 617aeae8b1..36cf65fe5a 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -138,6 +138,7 @@ char *list_get_name_cb(int selected_item, void* data,
138} 138}
139 139
140char filename[MAX_PATH]; 140char filename[MAX_PATH];
141bool newfile;
141int get_eol_string(char* fn) 142int get_eol_string(char* fn)
142{ 143{
143 int fd, result; 144 int fd, result;
@@ -174,22 +175,27 @@ int get_eol_string(char* fn)
174 return result; 175 return result;
175} 176}
176 177
177void save_changes(int overwrite) 178bool save_changes(int overwrite)
178{ 179{
179 int fd; 180 int fd;
180 int i; 181 int i;
181 182
182 if (!filename[0] || !overwrite) 183 if (newfile || !overwrite)
183 { 184 {
184 rb->strcpy(filename,"/"); 185 if(rb->kbd_input(filename,MAX_PATH))
185 rb->kbd_input(filename,MAX_PATH); 186 {
187 newfile = true;
188 rb->splash(HZ, "Cancelled");
189 return false;
190 }
186 } 191 }
187 192
188 fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC); 193 fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC);
189 if (fd < 0) 194 if (fd < 0)
190 { 195 {
196 newfile = true;
191 rb->splash(HZ*2, "Changes NOT saved"); 197 rb->splash(HZ*2, "Changes NOT saved");
192 return; 198 return false;
193 } 199 }
194 200
195 if (!overwrite) 201 if (!overwrite)
@@ -208,6 +214,8 @@ void save_changes(int overwrite)
208 rb->cpu_boost(0); 214 rb->cpu_boost(0);
209#endif 215#endif
210 rb->close(fd); 216 rb->close(fd);
217 newfile = false;
218 return true;
211} 219}
212 220
213void setup_lists(struct gui_synclist *lists, int sel) 221void setup_lists(struct gui_synclist *lists, int sel)
@@ -371,11 +379,13 @@ enum plugin_status plugin_start(const void* parameter)
371 } 379 }
372 } 380 }
373 rb->close(fd); 381 rb->close(fd);
382 newfile = false;
374 } 383 }
375 else 384 else
376 { 385 {
377 filename[0] = '\0'; 386 rb->strcpy(filename,"/");
378 rb->strcpy(eol,"\n"); 387 rb->strcpy(eol,"\n");
388 newfile = true;
379 } 389 }
380#ifdef HAVE_ADJUSTABLE_CPU_FREQ 390#ifdef HAVE_ADJUSTABLE_CPU_FREQ
381 rb->cpu_boost(0); 391 rb->cpu_boost(0);
@@ -463,8 +473,8 @@ enum plugin_status plugin_start(const void* parameter)
463 switch (do_item_menu(cur_sel, copy_buffer)) 473 switch (do_item_menu(cur_sel, copy_buffer))
464 { 474 {
465 case MENU_RET_SAVE: 475 case MENU_RET_SAVE:
466 save_changes(1); 476 if(save_changes(1))
467 changed = false; 477 changed = false;
468 break; 478 break;
469 case MENU_RET_UPDATE: 479 case MENU_RET_UPDATE:
470 changed = true; 480 changed = true;
@@ -490,17 +500,17 @@ enum plugin_status plugin_start(const void* parameter)
490 playback_control(NULL); 500 playback_control(NULL);
491 break; 501 break;
492 case 2: //save to disk 502 case 2: //save to disk
493 save_changes(1); 503 if(save_changes(1))
494 changed = 0; 504 changed = 0;
495 break; 505 break;
496 case 3: 506 case 3:
497 save_changes(0); 507 if(save_changes(0))
498 changed = 0; 508 changed = 0;
499 break; 509 break;
500 510
501 case 4: 511 case 4:
502 save_changes(1); 512 if(save_changes(1))
503 exit=1; 513 exit=1;
504 break; 514 break;
505 case 5: 515 case 5:
506 exit=1; 516 exit=1;
@@ -511,6 +521,8 @@ enum plugin_status plugin_start(const void* parameter)
511 break; 521 break;
512 } 522 }
513 rb->gui_synclist_set_nb_items(&lists,line_count); 523 rb->gui_synclist_set_nb_items(&lists,line_count);
524 if(line_count > 0 && line_count <= cur_sel)
525 rb->gui_synclist_select_item(&lists,line_count-1);
514 } 526 }
515 return PLUGIN_OK; 527 return PLUGIN_OK;
516} 528}