Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Jul 3, 2015
1 parent 046d2b0 commit be6dc59
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
26 changes: 11 additions & 15 deletions src/fm_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,8 @@ void search_loop(void)
c = 'q';
break;
case 9: // tab to change tab
if (cont == MAX_TABS) {
pthread_mutex_lock(&lock);
active = 1 - active;
chdir(ps[active].my_cwd);
pthread_mutex_unlock(&lock);
return;
}
break;
change_tab();
return;
case 'q': case 'Q':
strcpy(sv.found_searched[ps[active].curr_pos], ps[active].my_cwd);
break;
Expand Down Expand Up @@ -698,12 +692,14 @@ static void extractor_thread(struct archive *a)

void change_tab(void)
{
pthread_mutex_lock(&lock);
active = !active;
pthread_mutex_unlock(&lock);
if (sv.searching != 3 + active) {
chdir(ps[active].my_cwd);
} else {
search_loop();
if (cont == MAX_TABS) {
pthread_mutex_lock(&lock);
active = !active;
pthread_mutex_unlock(&lock);
if (sv.searching != 3 + active) {
chdir(ps[active].my_cwd);
} else {
search_loop();
}
}
}
10 changes: 3 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,15 @@ static void main_loop(void)
}
break;
case 't': // t to open second tab
if (cont < MAX_TABS) {
new_tab();
}
new_tab();
break;
case 9: // tab to change tab
if (cont == MAX_TABS) {
change_tab();
}
change_tab();
break;
case 'w': // w to close second tab
if (active) {
delete_tab();
change_tab();
delete_tab();
}
break;
case 'n': // new file
Expand Down
83 changes: 50 additions & 33 deletions src/ui_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ static int is_hidden(const struct dirent *current_file);
static void scroll_helper_func(int x, int direction);
static void colored_folders(int win, const char *name);
static void helper_print(void);
static void create_helper_win(void);
static void remove_helper_win(void);
static void change_unit(float size, char *str);

WINDOW *helper_win = NULL;
Expand Down Expand Up @@ -175,6 +177,9 @@ static int is_hidden(const struct dirent *current_file)
*/
void new_tab(void)
{
if (cont == MAX_TABS) {
return;
}
cont++;
if (cont == 2) {
width[active] = COLS / cont;
Expand Down Expand Up @@ -205,16 +210,16 @@ void new_tab(void)
void delete_tab(void)
{
cont--;
wclear(ps[active].fm);
delwin(ps[active].fm);
ps[active].fm = NULL;
free_str(ps[active].nl);
ps[active].stat_active = 0;
memset(ps[active].my_cwd, 0, sizeof(ps[active].my_cwd));
width[!active] = COLS;
wborder(ps[!active].fm, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
wresize(ps[!active].fm, dim, width[!active]);
print_border_and_title(!active);
wclear(ps[!active].fm);
delwin(ps[!active].fm);
ps[!active].fm = NULL;
free_str(ps[!active].nl);
ps[!active].stat_active = 0;
memset(ps[!active].my_cwd, 0, sizeof(ps[!active].my_cwd));
width[active] = COLS;
wborder(ps[active].fm, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
wresize(ps[active].fm, dim, width[active]);
print_border_and_title(active);
}

void scroll_down(char **str)
Expand Down Expand Up @@ -292,32 +297,44 @@ static void colored_folders(int win, const char *name)

void trigger_show_helper_message(void)
{
int i;

if (helper_win == NULL) {
dim = LINES - INFO_HEIGHT - HELPER_HEIGHT;
for (i = 0; i < cont; i++) {
wresize(ps[i].fm, dim, width[i]);
print_border_and_title(i);
if (ps[i].curr_pos > dim - 3) {
ps[i].curr_pos = dim - 3 + ps[i].delta;
mvwprintw(ps[i].fm, dim - 3 + INITIAL_POSITION, 1, "->");
}
wrefresh(ps[i].fm);
}
helper_win = subwin(stdscr, HELPER_HEIGHT, COLS, LINES - INFO_HEIGHT - HELPER_HEIGHT, 0);
wclear(helper_win);
helper_print();
create_helper_win();
} else {
wclear(helper_win);
delwin(helper_win);
helper_win = NULL;
dim = LINES - INFO_HEIGHT;
for (i = 0; i < cont; i++) {
mvwhline(ps[i].fm, dim - 1 - HELPER_HEIGHT, 0, ' ', COLS);
wresize(ps[i].fm, dim, width[i]);
list_everything(i, dim - 2 - HELPER_HEIGHT + ps[i].delta, HELPER_HEIGHT, ps[i].nl);
remove_helper_win();
}
}

static void create_helper_win(void)
{
int i;

dim = LINES - INFO_HEIGHT - HELPER_HEIGHT;
for (i = 0; i < cont; i++) {
wresize(ps[i].fm, dim, width[i]);
print_border_and_title(i);
if (ps[i].curr_pos > dim - 3) {
ps[i].curr_pos = dim - 3 + ps[i].delta;
mvwprintw(ps[i].fm, dim - 3 + INITIAL_POSITION, 1, "->");
}
wrefresh(ps[i].fm);
}
helper_win = subwin(stdscr, HELPER_HEIGHT, COLS, LINES - INFO_HEIGHT - HELPER_HEIGHT, 0);
wclear(helper_win);
helper_print();
}

static void remove_helper_win(void)
{
int i;

wclear(helper_win);
delwin(helper_win);
helper_win = NULL;
dim = LINES - INFO_HEIGHT;
for (i = 0; i < cont; i++) {
mvwhline(ps[i].fm, dim - 1 - HELPER_HEIGHT, 0, ' ', COLS);
wresize(ps[i].fm, dim, width[i]);
list_everything(i, dim - 2 - HELPER_HEIGHT + ps[i].delta, HELPER_HEIGHT, ps[i].nl);
}
}

Expand Down

0 comments on commit be6dc59

Please sign in to comment.