Set focus on file for install-all feature

This commit is contained in:
TheFloW 2016-09-04 15:30:39 +02:00
parent 45d6acd8a9
commit 522683e39f
3 changed files with 58 additions and 0 deletions

18
file.c
View File

@ -419,6 +419,24 @@ FileListEntry *fileListGetNthEntry(FileList *list, int n) {
return entry;
}
int fileListGetNumberByName(FileList *list, char *name) {
FileListEntry *entry = list->head;
int name_length = strlen(name);
int n = 0;
while (entry) {
if (entry->name_length == name_length && strcmp(entry->name, name) == 0)
break;
n++;
entry = entry->next;
}
return n;
}
void fileListAddEntry(FileList *list, FileListEntry *entry, int sort) {
entry->next = NULL;
entry->previous = NULL;

4
file.h
View File

@ -85,10 +85,14 @@ char **getMountPoints();
FileListEntry *fileListFindEntry(FileList *list, char *name);
FileListEntry *fileListGetNthEntry(FileList *list, int n);
int fileListGetNumberByName(FileList *list, char *name);
void fileListAddEntry(FileList *list, FileListEntry *entry, int sort);
int fileListRemoveEntry(FileList *list, FileListEntry *entry);
int fileListRemoveEntryByName(FileList *list, char *name);
void fileListEmpty(FileList *list);
int fileListGetEntries(FileList *list, char *path);
#endif

36
main.c
View File

@ -149,6 +149,39 @@ DIR_UP_RETURN:
dirUpCloseArchive();
}
void focusOnFilename(char *name) {
int name_pos = fileListGetNumberByName(&file_list, name);
if (name_pos < file_list.length) {
while (1) {
int index = base_pos + rel_pos;
if (index == name_pos)
break;
if (index > name_pos) {
if (rel_pos > 0) {
rel_pos--;
} else {
if (base_pos > 0) {
base_pos--;
}
}
}
if (index < name_pos) {
if ((rel_pos + 1) < file_list.length) {
if ((rel_pos + 1) < MAX_POSITION) {
rel_pos++;
} else {
if ((base_pos + rel_pos + 1) < file_list.length) {
base_pos++;
}
}
}
}
}
}
}
int refreshFileList() {
int ret = 0, res = 0;
@ -949,6 +982,9 @@ int dialogSteps() {
snprintf(install_path, MAX_PATH_LENGTH, "%s%s", install_list.path, entry->name);
args.file = install_path;
// Focus
focusOnFilename(entry->name);
// Remove entry
fileListRemoveEntry(&install_list, entry);
} else {