/** * get_previous_sibling_node(GNode * cur_node) * @brief Gets previous sibling node, or wraps around if NULL * @param cur_node * @return GNode of sibling previous, or wrapped around */ GNode *get_prev_sibling_node(GNode * cur_node) { GNode *tmp_node = NULL; if ((tmp_node = g_node_prev_sibling(cur_node)) == NULL) { return g_node_last_sibling(cur_node); } return tmp_node; }
gboolean insert_in_tree(GNode *directory, File *file) { GNode *new_file, *file_ptr, *dir_ptr; int position; if (file->name[0] == '.' && FILE(directory)->show_dotfiles == FALSE) { insert_sorted_in_dotfiles(directory, file); return FALSE; } new_file = insert_sorted_in_tree(directory, file); for (dir_ptr = directory; !G_NODE_IS_ROOT(dir_ptr); dir_ptr = dir_ptr->parent) { if (FILE(dir_ptr)->open == FALSE) return FALSE; } if (FILE(dir_ptr)->open == FALSE) return FALSE; file_ptr = get_previous_file(new_file); position = g_list_position(lines, FILE(file_ptr)->line); lines = g_list_insert(lines, new_file, position + 1); file->line = g_list_nth(lines, position + 1); if (g_list_length(first_line) - g_list_length(last_line) + 1) { if (g_list_previous(first_line) == file->line) first_line = file->line; else if (g_list_next(last_line) == file->line) last_line = file->line; } if (g_list_position(lines, first_line) <= position + 1 && position + 1 <= g_list_position(lines, last_line)) { if (position + 1 < g_list_position(lines, selected_line)) { if (g_list_length(first_line) <= getmaxy(tree_window)) print_lines(first_line, last_line, FALSE); else { first_line = g_list_next(first_line); print_lines(first_line, file->line, FALSE); } } else { if (g_list_length(first_line) > getmaxy(tree_window)) last_line = g_list_previous(last_line); if (g_node_last_sibling(new_file) == new_file) print_lines(g_list_previous(file->line), last_line, FALSE); else print_lines(file->line, last_line, FALSE); } return TRUE; } return FALSE; }
void print_parents_lines(GList *line) { GNode *file_ptr; int depth; for (file_ptr = NODE(line)->parent, depth = g_node_depth(file_ptr) - 1; !G_NODE_IS_ROOT(file_ptr); file_ptr = file_ptr->parent, depth--) { if (file_ptr != g_node_last_sibling(file_ptr)) mvwaddch(tree_window, g_list_position(first_line, line), 2 * depth - 2, ACS_VLINE); else mvwaddch(tree_window, g_list_position(first_line, line), 2 * depth - 2, ' '); mvwaddch(tree_window, g_list_position(first_line, line), 2 * depth - 1, ' '); } }
void print_line(GList *line) { int line_number = g_list_position(first_line, line); GNode *file = NODE(line); int depth = g_node_depth(file) - 1; char *link_str; wmove(tree_window, line_number, 0); wclrtoeol(tree_window); if (line == selected_line) wattron(tree_window, A_REVERSE); if (G_NODE_IS_ROOT(file)) { wattron(tree_window, A_BOLD); waddnstr(tree_window, FILE(file)->name, getmaxx(tree_window) - 1); if (!g_str_has_suffix(FILE(file)->name, "/")) waddch(tree_window, '/'); wattroff(tree_window, A_BOLD); } else { if (file != g_node_last_sibling(file)) mvwaddch(tree_window, line_number, 2 * depth - 2, ACS_LTEE); else mvwaddch(tree_window, line_number, 2 * depth - 2, ACS_LLCORNER); waddch(tree_window, ACS_HLINE); if (FILE(file)->link == TRUE) { link_str = g_strdup_printf("%s -> %s", FILE(file)->name, FILE(file)->link_path); waddnstr(tree_window, link_str, getmaxx(tree_window) - 2 * depth - 1); free(link_str); } else waddnstr(tree_window, FILE(file)->name, getmaxx(tree_window) - 2 * depth - 1); if (FILE(file)->type == directory_type && ((FILE(file)->link == TRUE && !g_str_has_suffix(FILE(file)->link_path, "/")) || (FILE(file)->link == FALSE && !g_str_has_suffix(FILE(file)->name, "/")))) waddch(tree_window, '/'); print_parents_lines(line); } wattroff(tree_window, A_REVERSE); }