]> git.mdlowis.com Git - archive/afm.git/commitdiff
FIXED IT
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 25 Jul 2014 16:29:00 +0000 (12:29 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 25 Jul 2014 16:29:00 +0000 (12:29 -0400)
source/input.c
source/screen.c
source/workdir.c

index bb3ad6376a5b7481e3a213f86301670afca3759a..f64621cbadf2132017abee6477706d6d37af111b 100644 (file)
@@ -22,15 +22,15 @@ static void handle_quit(void) {
 }
 
 static void handle_next(void) {
-    //workdir_next(state_get_focused_frame()->workdir);
+    workdir_next(state_get_focused_frame()->workdir);
 }
 
 static void handle_prev(void) {
-    //workdir_prev(state_get_focused_frame()->workdir);
+    workdir_prev(state_get_focused_frame()->workdir);
 }
 
 static void handle_cd(void) {
-    //workdir_cd(state_get_focused_frame()->workdir);
+    workdir_cd(state_get_focused_frame()->workdir);
 }
 
 static binding_t Default_Bindings[] = {
index 337f311caefb0050753d8b95a79bdc2de1ef01fc..98ecd40ddcd748cd767625a93fe40f1e5cc7a1b0 100644 (file)
@@ -20,7 +20,6 @@ static void screen_frame_free(void* p_frame);
 void screen_frame_draw_files(frame_t* frame);
 
 static list_t* Screen_List;
-static frame_t* Focused_Frame;
 
 static frame_t* master_frame(void){
     return (frame_t*) Screen_List->head->contents;
@@ -29,7 +28,7 @@ static frame_t* master_frame(void){
 void screen_init(void) {
     Screen_List = list_new();
     list_push_back(Screen_List, screen_frame_new());
-    //Focused_Frame = master_frame();
+    state_set_focused_frame(master_frame());
 }
 
 void screen_deinit(void) {
@@ -59,7 +58,7 @@ void screen_close(void) {
     int num_frames = list_size(Screen_List);
     if(num_frames > 1){
         list_delete(Screen_List, 0);
-        //Focused_Frame = master_frame();
+        state_set_focused_frame(master_frame());
     }
     state_set_screen_dirty(true);
 }
@@ -76,7 +75,7 @@ static void screen_place_windows(void) {
     mvwin(p_frame->p_win, 0, 0);
     wresize(p_frame->p_win, lines, (num_frames > 1) ? cols/2 : cols);
     wclear(p_frame->p_win);
-    //screen_frame_draw_files(p_frame);
+    screen_frame_draw_files(p_frame);
     box(p_frame->p_win, 0 , 0);
     wrefresh(p_frame->p_win);
 
@@ -93,7 +92,7 @@ static void screen_place_windows(void) {
         mvwin(p_frame->p_win, pos, cols/2);
         wresize(p_frame->p_win, height, cols/2);
         wclear(p_frame->p_win);
-        //screen_frame_draw_files(p_frame);
+        screen_frame_draw_files(p_frame);
         wmove(p_frame->p_win, 1, 1);
         box(p_frame->p_win, 0 , 0);
         wrefresh(p_frame->p_win);
@@ -107,8 +106,8 @@ static void screen_place_windows(void) {
 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);
-    //char* path = Focused_Frame->workdir->path;
-    //p_frame->workdir = workdir_new(".");
+    char* path = state_get_focused_frame() ? state_get_focused_frame()->workdir->path : get_current_dir_name();
+    p_frame->workdir = workdir_new(path);
     return p_frame;
 }
 
@@ -118,7 +117,7 @@ static void screen_frame_free(void* p_frame_ptr) {
     wborder(p_frame->p_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
     wrefresh(p_frame->p_win);
     delwin(p_frame->p_win);
-    //if(p_frame->workdir) mem_release(p_frame->workdir);
+    if(p_frame->workdir) mem_release(p_frame->workdir);
 }
 
 void screen_frame_draw_files(frame_t* frame){
@@ -131,15 +130,15 @@ void screen_frame_draw_files(frame_t* frame){
     wattroff(frame->p_win, A_UNDERLINE);
     //list files
     while (i < vec_size(frame->workdir->vfiles)){
-        //if(frame == Focused_Frame && i == frame->workdir->idx){
-        //    wattron(frame->p_win, A_STANDOUT);
-        //    wattron(frame->p_win, A_BOLD);
-        //}
+        if(frame == state_get_focused_frame() && i == frame->workdir->idx){
+            wattron(frame->p_win, A_STANDOUT);
+            wattron(frame->p_win, A_BOLD);
+        }
         mvwaddnstr(frame->p_win, FrameTopBuffer+i-frame->workdir->top_index, 1, vec_at(frame->workdir->vfiles, i), cols-2);
-        //if(frame == Focused_Frame && i == frame->workdir->idx){
-        //    wattroff(frame->p_win, A_STANDOUT);
-        //    wattroff(frame->p_win, A_BOLD);
-        //}
+        if(frame == state_get_focused_frame() && i == frame->workdir->idx){
+            wattroff(frame->p_win, A_STANDOUT);
+            wattroff(frame->p_win, A_BOLD);
+        }
         i++;
         if((FrameTopBuffer+i-frame->workdir->top_index+FrameBotBuffer) > rows) break;
     }
index 2dfde8119820bd4c65cfe6684a3fa461916a41f2..df5b713649acf4779d624bbffbffd0b9e11e6413 100644 (file)
@@ -21,18 +21,18 @@ static bool is_dir(char* path) {
 void workdir_free(void* p_wd);
 
 WorkDir_T* workdir_new(char* path){
-       WorkDir_T* wd = mem_allocate(sizeof(WorkDir_T), &workdir_free);
-       wd->idx = 0;
-       wd->path = path;
-       wd->vfiles = vec_new(0);
-       workdir_ls(wd);
-       wd->top_index = 0;
-       return wd;
+    WorkDir_T* wd = mem_allocate(sizeof(WorkDir_T), &workdir_free);
+    wd->idx = 0;
+    wd->path = path;
+    wd->vfiles = vec_new(0);
+    workdir_ls(wd);
+    wd->top_index = 0;
+    return wd;
 }
 
 void workdir_free(void* p_wd){
-       WorkDir_T* wd = (WorkDir_T*)p_wd;
-       mem_release(wd->vfiles);
+    WorkDir_T* wd = (WorkDir_T*)p_wd;
+    mem_release(wd->vfiles);
 }
 
 void workdir_next(WorkDir_T* wd) {
@@ -46,6 +46,7 @@ void workdir_next(WorkDir_T* wd) {
         if((FrameTopBuffer+wd->idx+FrameBotBuffer) > rows)
             wd->top_index = wd->idx-(rows-FrameTopBuffer-FrameBotBuffer);
     }
+    state_set_screen_dirty(true);
 }
 
 void workdir_prev(WorkDir_T* wd) {
@@ -56,47 +57,49 @@ void workdir_prev(WorkDir_T* wd) {
         if(wd->idx < wd->top_index)
             wd->top_index = wd->idx;
     }
+    state_set_screen_dirty(true);
 }
 
 //go up a directory: remove everything after (including) last '/' character
 char* workdir_cd_up(WorkDir_T* wd){
-       int last_slash = 0, i = 0;
-       char* newpath;
-       while(wd->path[i] != 0){
-               if(wd->path[i] == '/') last_slash = i;
-               i++;
-       }
-       if(last_slash == 0){
-               newpath = mem_allocate(sizeof(char)*2, NULL);
-               strcpy(newpath, "/");
-       } else {
-               newpath = mem_allocate(sizeof(char)*last_slash, NULL);
-               strncpy(newpath, wd->path, last_slash);
-               newpath[last_slash] = 0;
-       }
-       return newpath;
+    int last_slash = 0, i = 0;
+    char* newpath;
+    while(wd->path[i] != 0){
+        if(wd->path[i] == '/') last_slash = i;
+        i++;
+    }
+    if(last_slash == 0){
+        newpath = mem_allocate(sizeof(char)*2, NULL);
+        strcpy(newpath, "/");
+    } else {
+        newpath = mem_allocate(sizeof(char)*last_slash, NULL);
+        strncpy(newpath, wd->path, last_slash);
+        newpath[last_slash] = 0;
+    }
+    return newpath;
 }
 
 //go down a directory: append '/subdir' to path
 char* workdir_cd_down(WorkDir_T* wd){
-       char* subdir = vec_at(wd->vfiles, wd->idx);
-       int newpathlen = strlen(wd->path) + strlen(subdir) + 2; //+2, for slash & end null;
-       char *newpath = mem_allocate(sizeof(char)*newpathlen, NULL);
-       strcpy(newpath, wd->path);
-       strcat(newpath, "/");
-       strcat(newpath, subdir);
-       return newpath;
+    char* subdir = vec_at(wd->vfiles, wd->idx);
+    int newpathlen = strlen(wd->path) + strlen(subdir) + 2; //+2, for slash & end null;
+    char *newpath = mem_allocate(sizeof(char)*newpathlen, NULL);
+    strcpy(newpath, wd->path);
+    strcat(newpath, "/");
+    strcat(newpath, subdir);
+    return newpath;
 }
 
 void workdir_cd(WorkDir_T* wd) {
-       char* newpath = (wd->idx == 0) ? workdir_cd_up(wd) : workdir_cd_down(wd);
-       if(is_dir(newpath)){
-               //TODO: this segfaults: mem_release(wd->path);
-               wd->path = newpath;
-               wd->idx = 0;
-               wd->top_index = 0;
-       }
-       workdir_ls(wd);
+    char* newpath = (wd->idx == 0) ? workdir_cd_up(wd) : workdir_cd_down(wd);
+    if(is_dir(newpath)){
+        //TODO: this segfaults: mem_release(wd->path);
+        wd->path = newpath;
+        wd->idx = 0;
+        wd->top_index = 0;
+    }
+    workdir_ls(wd);
+    state_set_screen_dirty(true);
 }
 
 void workdir_ls(WorkDir_T* wd){
@@ -121,7 +124,7 @@ void workdir_ls(WorkDir_T* wd){
         strcpy(lol, filename);
         vec_push_back(wd->vfiles, lol);
         free(filename);
-               filename = 0;
+        filename = 0;
     }
     //mem_release(dotdot); #dont free, because there's a bug(?) in vectors and reference counting
     //reference counter is not incremented for added items, so releasinghere will free the memory