text_editor: don't set filename "/" before input new filename so that user can easily create copy in same directory.

select new last line if last line is cut/deleted or concatenated to above line.
fix bugs when changes are not saved (FS#9692, patch by Johannes Linke).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21994 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-07-21 14:35:29 +00:00
parent 1a4b0cadd6
commit 3f7dfeed3a

View file

@ -138,6 +138,7 @@ char *list_get_name_cb(int selected_item, void* data,
} }
char filename[MAX_PATH]; char filename[MAX_PATH];
bool newfile;
int get_eol_string(char* fn) int get_eol_string(char* fn)
{ {
int fd, result; int fd, result;
@ -174,22 +175,27 @@ int get_eol_string(char* fn)
return result; return result;
} }
void save_changes(int overwrite) bool save_changes(int overwrite)
{ {
int fd; int fd;
int i; int i;
if (!filename[0] || !overwrite) if (newfile || !overwrite)
{ {
rb->strcpy(filename,"/"); if(rb->kbd_input(filename,MAX_PATH))
rb->kbd_input(filename,MAX_PATH); {
newfile = true;
rb->splash(HZ, "Cancelled");
return false;
}
} }
fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC); fd = rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC);
if (fd < 0) if (fd < 0)
{ {
newfile = true;
rb->splash(HZ*2, "Changes NOT saved"); rb->splash(HZ*2, "Changes NOT saved");
return; return false;
} }
if (!overwrite) if (!overwrite)
@ -208,6 +214,8 @@ void save_changes(int overwrite)
rb->cpu_boost(0); rb->cpu_boost(0);
#endif #endif
rb->close(fd); rb->close(fd);
newfile = false;
return true;
} }
void setup_lists(struct gui_synclist *lists, int sel) void setup_lists(struct gui_synclist *lists, int sel)
@ -371,11 +379,13 @@ enum plugin_status plugin_start(const void* parameter)
} }
} }
rb->close(fd); rb->close(fd);
newfile = false;
} }
else else
{ {
filename[0] = '\0'; rb->strcpy(filename,"/");
rb->strcpy(eol,"\n"); rb->strcpy(eol,"\n");
newfile = true;
} }
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(0); rb->cpu_boost(0);
@ -463,7 +473,7 @@ enum plugin_status plugin_start(const void* parameter)
switch (do_item_menu(cur_sel, copy_buffer)) switch (do_item_menu(cur_sel, copy_buffer))
{ {
case MENU_RET_SAVE: case MENU_RET_SAVE:
save_changes(1); if(save_changes(1))
changed = false; changed = false;
break; break;
case MENU_RET_UPDATE: case MENU_RET_UPDATE:
@ -490,16 +500,16 @@ enum plugin_status plugin_start(const void* parameter)
playback_control(NULL); playback_control(NULL);
break; break;
case 2: //save to disk case 2: //save to disk
save_changes(1); if(save_changes(1))
changed = 0; changed = 0;
break; break;
case 3: case 3:
save_changes(0); if(save_changes(0))
changed = 0; changed = 0;
break; break;
case 4: case 4:
save_changes(1); if(save_changes(1))
exit=1; exit=1;
break; break;
case 5: case 5:
@ -511,6 +521,8 @@ enum plugin_status plugin_start(const void* parameter)
break; break;
} }
rb->gui_synclist_set_nb_items(&lists,line_count); rb->gui_synclist_set_nb_items(&lists,line_count);
if(line_count > 0 && line_count <= cur_sel)
rb->gui_synclist_select_item(&lists,line_count-1);
} }
return PLUGIN_OK; return PLUGIN_OK;
} }