mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 18:30:15 -04:00
linked list to keep track of past directory indexes
This commit is contained in:
36
dir.c
36
dir.c
@@ -19,6 +19,8 @@ extern volatile unsigned long selected_file_current;
|
||||
extern volatile unsigned long selected_file_last;
|
||||
extern color *colors;
|
||||
int (*order_func)() = sort_natural;
|
||||
linked_dir *visited_dirs;
|
||||
linked_dir *current_dir;
|
||||
|
||||
unsigned long get_dir_size(char *path);
|
||||
void get_dir_content(char *path, unsigned long *dir_file_count, file *dir_content);
|
||||
@@ -332,3 +334,37 @@ void update_selected_file(){
|
||||
mid_content[selected_file_current].status |= FILE_STATUS_HOVER;
|
||||
file_current->status = mid_content[selected_file_current].status;
|
||||
}
|
||||
void dir_set_selected_file_current(unsigned long selected_file_current){
|
||||
current_dir->selected_file_current = selected_file_current;
|
||||
mvwaddch(stdscr, 0,0, selected_file_current + '0');
|
||||
}
|
||||
|
||||
unsigned long dir_get_selected_file_current(){
|
||||
current_dir = visited_dirs;
|
||||
char hit = 0;
|
||||
char *path = getcwd(NULL, 0);
|
||||
while(current_dir->next != NULL) {
|
||||
if (strcmp(path, current_dir->path) == 0) {
|
||||
hit = 1;
|
||||
break;
|
||||
}
|
||||
current_dir = current_dir->next;
|
||||
}
|
||||
if (hit == 0) {
|
||||
current_dir->next = malloc(sizeof(linked_dir));
|
||||
current_dir->next->next = NULL;
|
||||
current_dir->next->path = path;
|
||||
return 0;
|
||||
} else {
|
||||
free(path);
|
||||
return current_dir->selected_file_current;
|
||||
}
|
||||
}
|
||||
void dir_init(){
|
||||
visited_dirs = malloc(sizeof(linked_dir));
|
||||
visited_dirs->path = getcwd(NULL, 0);
|
||||
visited_dirs->selected_file_current = 0;
|
||||
visited_dirs->next = NULL;
|
||||
current_dir = visited_dirs;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user