static frame_t* screen_frame_new(void) {
frame_t* p_frame = (frame_t*)mem_allocate(sizeof(frame_t),&screen_frame_free);
p_frame->p_win = newwin(1, 1, 0, 0);
+ p_frame->top_index = 0;
bool first_window = !state_get_focused_frame();
char* path = first_window ? pwd() : state_get_focused_frame()->workdir->path;
p_frame->workdir = workdir_new(path);
if(p_frame->workdir) mem_release(p_frame->workdir);
}
+static void screen_frame_scroll(frame_t* p_frame){
+ int rows,cols;
+ getmaxyx(p_frame->p_win, rows, cols);
+ if(p_frame->workdir->idx < p_frame->top_index)
+ p_frame->top_index = p_frame->workdir->idx;
+ else if (p_frame->top_index < p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer))
+ p_frame->top_index = p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer);
+}
+
void screen_frame_draw_files(frame_t* frame){
- int i = frame->workdir->top_index;
+ int i;
int rows, cols;
int pathlength = strlen(frame->workdir->path);
getmaxyx(frame->p_win, rows, cols);
+ screen_frame_scroll(frame);
+ i = frame->top_index;
//draw path
wattron(frame->p_win, A_UNDERLINE);
mvwaddnstr(frame->p_win, 1, 1, frame->workdir->path, cols-2);
wattron(frame->p_win, A_STANDOUT | A_BOLD);
}
if(dir) wattron(frame->p_win, COLOR_PAIR(DIRECTORY));
- mvwaddnstr(frame->p_win, FrameTopBuffer+i-frame->workdir->top_index, 1, file->name, cols-2);
+ mvwaddnstr(frame->p_win, FrameTopBuffer+i-frame->top_index, 1, file->name, cols-2);
if(frame == state_get_focused_frame() && i == frame->workdir->idx){
wattroff(frame->p_win, A_STANDOUT | A_BOLD);
}
if(dir) wattroff(frame->p_win, COLOR_PAIR(DIRECTORY));
i++;
- if((FrameTopBuffer+i-frame->workdir->top_index+FrameBotBuffer) > rows) break;
+ if((FrameTopBuffer+i-frame->top_index+FrameBotBuffer) > rows) break;
}
}
mem_retain(wd->path);
wd->vfiles = vec_new(0);
workdir_ls(wd);
- wd->top_index = 0;
return wd;
}
mem_release(p_file->path);
}
+void workdir_set_idx(WorkDir_T* wd, int idx){
+ wd->idx = idx;
+ if(idx < 0) wd->idx = 0;
+ if(idx >= vec_size(wd->vfiles)) wd->idx = vec_size(wd->vfiles)-1;
+ state_set_screen_dirty(true);
+}
+
void workdir_next(WorkDir_T* wd) {
- //do nothing if at the end of the file list
- if(wd->idx < vec_size(wd->vfiles)-1){
- int rows,cols;
- wd->idx += 1;
- getmaxyx(stdscr, rows,cols);
- (void) cols;
- //scroll if necessary
- if((FrameTopBuffer+wd->idx+FrameBotBuffer) > rows)
- wd->top_index = wd->idx-(rows-FrameTopBuffer-FrameBotBuffer);
- }
- state_set_screen_dirty(true);
+ workdir_set_idx(wd, wd->idx+1);
}
void workdir_prev(WorkDir_T* wd) {
- //do nothing if at the top of the file list
- if(wd->idx > 0){
- wd->idx -= 1;
- //scroll if necessary
- if(wd->idx < wd->top_index)
- wd->top_index = wd->idx;
- }
- state_set_screen_dirty(true);
+ workdir_set_idx(wd, wd->idx-1);
+}
+
+void workdir_scroll_to_top(WorkDir_T* wd){
+ workdir_set_idx(wd, 0);
+}
+
+void workdir_scroll_to_bot(WorkDir_T* wd){
+ workdir_set_idx(wd, vec_size(wd->vfiles) - 1);
+}
+
+void workdir_jump_up(WorkDir_T* wd){
+ workdir_set_idx(wd, wd->idx - 20);
+}
+
+void workdir_jump_down(WorkDir_T* wd){
+ workdir_set_idx(wd, wd->idx + 20);
}
void workdir_cd(WorkDir_T* wd) {
wd->path = newpath;
mem_retain(wd->path);
wd->idx = 0;
- wd->top_index = 0;
}
workdir_ls(wd);
state_set_screen_dirty(true);
void workdir_seek(WorkDir_T* wd, char* search){
int i = 0;
if(strcmp(((File_T*)vec_at(wd->vfiles, 0))->name, "..") == 0) i++;
- while(i < vec_size(wd->vfiles) && strcmp(search, ((File_T*)vec_at(wd->vfiles, i))->name) < 0) i++;
- wd->idx = i;
-}
-
-void workdir_scroll_to_top(WorkDir_T* wd){
- wd->idx = 0;
- state_set_screen_dirty(true);
-}
-
-void workdir_scroll_to_bot(WorkDir_T* wd){
- wd->idx = vec_size(wd->vfiles) - 1;
- state_set_screen_dirty(true);
-}
-
-void workdir_jump_up(WorkDir_T* wd){
- wd->idx -= 20;
- if(wd->idx < 0) wd->idx = 0;
- state_set_screen_dirty(true);
+ while(i < vec_size(wd->vfiles) && strcmp(((File_T*)vec_at(wd->vfiles, i))->name, search) < 0) i++;
+ workdir_set_idx(wd, i);
}
-void workdir_jump_down(WorkDir_T* wd){
- wd->idx += 20;
- if(wd->idx >= vec_size(wd->vfiles)) wd->idx = vec_size(wd->vfiles)-1;
- state_set_screen_dirty(true);
-}