char explorer_on_enter(t_tekpaint *tekpaint, t_explorer *explorer, int *i) { char *path; char *file_name; DIR *dirp; if ((file_name = get_focused_file_name(explorer, *i))) { path = concat_path(explorer->current_path, file_name); if (NULL == (dirp = opendir(path))) { closedir(dirp); if (explorer_on_enter_file(file_name, path, explorer)) return (1); } else { closedir(dirp); explorer->current_path = path; *i = 0; read_files(explorer); display_files(tekpaint, explorer, *i); } } else my_putstr("Ce fichier est incorrect !\n"); return (0); }
void dirs(t_list **list, t_frmt *frmt) { t_list *files; t_file *file; files = *list; while (files && frmt->is_upper_r) { file = (t_file *)files->data; if (file->permissions[0] == 'd' && file->sub_dirs) { ft_printf("\n%s\n", file->path); display_files(&file->sub_dirs, frmt); } file = NULL; files = files->next; } }
char explorer(t_tekpaint *tekpaint, t_explorer *explorer) { tekpaint->tool.explorer = explorer; explorer->current_path = "./"; explorer->img = NULL; explorer->win = bunny_start_style(EXPLORER_WIDTH, EXPLORER_HEIGHT, TITLEBAR | CLOSE_BUTTON, explorer->win_name); explorer->buffer = bunny_new_pixelarray(EXPLORER_WIDTH, EXPLORER_HEIGHT); if (explorer->buffer == NULL) return (0); fill_buffer(explorer->buffer, BLACK); read_files(explorer); display_files(tekpaint, explorer, 0); bunny_set_key_response(explorer_on_key); bunny_set_click_response(NULL); bunny_set_loop_main_function((t_bunny_loop)main_loop_explorer); bunny_loop(explorer->win, 50, tekpaint); explorer_reset(tekpaint, explorer); return (1); }
void display_dir_recursively(t_file *file, t_args *args) { t_file *content; char *path; DIR *dir; path = ft_strjoin(file->path, "/"); ft_putchar('\n'); ft_putstr(file->path); ft_putstr(":\n"); if ((dir = opendir(path))) { content = NULL; while (add_file_dir(&content, readdir(dir), path)) ; closedir(dir); if (content) display_files(content, args, 1, 0); } else ft_error(file); ft_strdel(&path); }
/* Callback when a directory is selected */ static gint item_event_directory(GooCanvasItem *item, GdkEvent *event, gchar *dir) { if(!rootitem) return FALSE; switch (event->type) { case GDK_BUTTON_PRESS: if(strcmp(g_path_get_basename(dir), "..")==0) { /* Up one level. Remove .. and one directory on the right of the path */ dir[strlen(dir)-3] = '\0'; dir=g_path_get_dirname(dir); } display_files(rootitem, g_strdup(dir)); gtk_entry_set_text(GTK_ENTRY(widget_entry), ""); break; default: break; } return FALSE; }
t_bunny_response explorer_on_key(t_bunny_event_state state, t_bunny_keysym key, void *data) { t_tekpaint *tekpaint; t_explorer *explorer; static int i; char *file_name; tekpaint = (t_tekpaint*) data; explorer = tekpaint->tool.explorer; read_files(explorer); if (key == BKS_UP && state == GO_UP && i > 0) i--; else if (key == BKS_DOWN && state == GO_UP) i++; else if (key == BKS_RETURN && state == GO_UP) { if (explorer_on_enter(tekpaint, explorer, &i)) return (EXIT_ON_SUCCESS); } display_files(tekpaint, explorer, i); return (GO_ON); }
static int display_file_selector(int the_mode, GcomprisBoard *gcomprisBoard, gchar *rootdir, gchar *file_exts, FileSelectorCallBack iscb, void *user_context) { gchar *full_rootdir; mode = the_mode; /* Get the coordinate x y of the control area from the skin */ control_area_x1 = gc_skin_get_number_default("gcompris/fileselectx", 85); control_area_y1 = gc_skin_get_number_default("gcompris/fileselecty", 80); directory_label_y = gc_skin_get_number_default("gcompris/fileselectdiry", 180); if(rootitem) return 0; gc_bar_hide(TRUE); gc_board_pause(TRUE); fileSelectorCallBack=iscb; rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#FILE_SELECTOR", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); /* Entry area */ widget_entry = gtk_entry_new (); if(mode==MODE_SAVE) gtk_entry_set_max_length(GTK_ENTRY(widget_entry), 30); goo_canvas_widget_new (rootitem, GTK_WIDGET(widget_entry), control_area_x1, control_area_y1, 230.0, 30.0, NULL); gtk_signal_connect(GTK_OBJECT(widget_entry), "activate", GTK_SIGNAL_FUNC(entry_enter_callback), widget_entry); gtk_widget_show(widget_entry); /* * Create the combo with the file types * ------------------------------------ */ if(mode==MODE_SAVE && file_exts && *file_exts != '\0') { gchar **all_type = g_strsplit(file_exts, " ", 0); guint i = 0; gtk_combo_filetypes = gtk_combo_box_new_text(); /* Extract first string */ while (all_type[i]) gtk_combo_box_append_text(GTK_COMBO_BOX(gtk_combo_filetypes), g_strdup(all_type[i++]) ); g_strfreev(all_type); goo_canvas_widget_new (rootitem, gtk_combo_filetypes, control_area_x1 + 400, control_area_y1, 250.0, 35.0, NULL); gtk_widget_show(gtk_combo_filetypes); gtk_combo_box_set_active(GTK_COMBO_BOX(gtk_combo_filetypes), 0); } /* * Buttons * ------- */ // CANCEL gc_util_button_text_svg(rootitem, BOARDWIDTH * 1/3, BOARDHEIGHT - 32, "#BUTTON_TEXT", _("CANCEL"), (GtkSignalFunc) item_event_file_selector, "/cancel/"); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 2/3, BOARDHEIGHT - 32, "#BUTTON_TEXT", (mode==MODE_LOAD ? _("LOAD") : _("SAVE")), (GtkSignalFunc) item_event_file_selector, "/ok/"); file_selector_displayed = TRUE; full_rootdir = g_strconcat(gc_prop_get()->user_dir, "/", rootdir, NULL); gc_util_create_rootdir(full_rootdir); current_rootdir = full_rootdir; current_user_context = user_context; display_files(rootitem, full_rootdir); return 0; }
void move_cursor(WINDOW **win, int ch, struct file **file_list) { int i, x, y, oldX, oldY, change_row; getyx(*win, y, x); for (i = 0; file_list[i] != NULL; i++) file_list[i]->underline = 0; if (ch == KEY_UP) { if (y != 0) y--; else { oldX = --i; for (; i >= 0; i--) if (file_list[i]->col < x || (x == 0 && i == oldX)) { y = file_list[i]->row; x = file_list[i]->col; break; } } } else if (ch == KEY_DOWN) { oldY = y; for (i = 0; file_list[i] != NULL; i++) if (file_list[i]->col == x && file_list[i]->row > y) { y = file_list[i]->row; break; } if (y == oldY) { for (i = 0; file_list[i] != NULL; i++) if (file_list[i]->col > x) { x = file_list[i]->col; y = file_list[i]->row; break; } if (y == oldY) { x = 0; y = 0; } } } else if (ch == KEY_LEFT) { if (x != 0) { for (i -= 1; i >= 0; i--) if (file_list[i]->col < x) { x = file_list[i]->col; break; } } else y = 0; } else if (ch == KEY_RIGHT) { oldX = x; for (i = 0; file_list[i] != NULL; i++) { if (file_list[i]->col > x) { x = file_list[i]->col; break; } } if (x == oldX) y = file_list[i-1]->row; else { change_row = 0; for (i = 0; file_list[i] != NULL; i++) { if (file_list[i]->col == x && file_list[i]->row == y) { change_row = 0; break; } else if (file_list[i]->col == x && file_list[i]->row != y) { change_row = 1; oldY = file_list[i]->row; } } if (change_row == 1) y = oldY; } } for (i = 0; file_list[i] != NULL; i++) if (file_list[i]->row == y && file_list[i]->col == x) file_list[i]->underline = 1; display_files(win, file_list); wmove(*win, y, x); wrefresh(*win); }