1
0
Fork 0
forked from len0rd/rockbox

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