int select_file(char *prompt, char *fname) { int ret; static char p[256] = ""; filebox.h = screen_h - 10; filebox.height = screen_h - 14; filebox.w = MAX(screen_w - 16, 32); filebox.slen = filebox.w - 8; draw_box(prompt, 7, 2, filebox.w, 5, TRUE); draw_listbox(&filebox); hi_vid(); goto1(7,6); pch(LJOIN_CHAR); goto1(filebox.w+6,6); pch(RJOIN_CHAR); if (!fname[0]) { if (p[0]) strcpy(fname, p); else getcwd(fname, 256); cleanup_filename(fname); append_backslash(fname); } fill_filelist(fname); goto1(12, 4); ret = do_input_text(fname, 255, 54, is_filechar, fsel_proc, TRUE, fsel_mouse); if (ret != ESC) { strcpy(p, fname); *get_fname(p) = 0; } n_vid(); empty_filelist(); dirty_everything(); return ret; }
int LocalPackage::get_filelist(bool index) { return fill_filelist(&data, index); }
void open_grf_file (const char *fname) { char *title, *tmp; GrfError err; Grf *newgrf; GList *list, *cols; if (!g_file_test (fname, G_FILE_TEST_EXISTS)) { show_error (_("File %s does not exist."), fname); return; } mainWin.busy (true); mainWin.status (_("Loading...")); while (gtk_events_pending ()) gtk_main_iteration (); newgrf = grf_open (fname, "r", &err); if (!newgrf) { char *base; base = g_path_get_basename (fname); mainWin.status (""); gdk_window_set_cursor (W(main)->window, NULL); show_error (_("Error while opening %s:\n%s"), base, grf_strerror (err)); g_free (base); return; } if (document.grf) grf_free (document.grf); document.grf = newgrf; document.filename = fname; title = g_strdup_printf (_("%s - GRF Tool"), fname); gtk_window_set_title (GTK_WINDOW (W(main)), title); g_free (title); gtk_list_store_clear (GTK_LIST_STORE (filelist)); cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (W(filelist))); for (list = cols; list; list = list->next) { GtkTreeViewColumn *col = (GtkTreeViewColumn *) list->data; gtk_tree_view_column_set_sort_indicator (col, FALSE); } gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (filelist), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); g_list_free (cols); fill_filelist (); tmp = g_path_get_basename (fname); title = g_strdup_printf (_("%s: %ld files"), tmp, (long int)document.grf->nfiles); mainWin.status (title); g_free (tmp); g_free (title); gtk_widget_set_sensitive (W(extract), TRUE); mainWin.busy (false); }
int fsel_proc(int key, char *s, int *len, int *cpos) { if ((ascii(key)==CR) || (ascii(key)==LF)) { if ((*len > 0) && ((s[*len-1] == '\\') || (s[*len-1] == '/'))) { fill_filelist(s); hi_vid(); return TRUE; } } if (key==UP_ARROW) { if (filebox.count > 0) { if (filebox.current >= 0) filebox.current--; else filebox.current = filebox.scroll; if (filebox.current < 0) filebox.current = 0; if (filebox.current < filebox.scroll) filebox.scroll = filebox.current; goto changed; } } else if (key==DOWN_ARROW) { if (filebox.count > 0) { if (filebox.current >= 0) filebox.current++; else filebox.current = filebox.scroll; if (filebox.current >= filebox.count) filebox.current = filebox.count-1; if (filebox.current >= filebox.scroll + filebox.height) filebox.scroll = filebox.current - filebox.height + 1; goto changed; } } else if (key==PAGE_UP) { if (filebox.count > 0) { if (filebox.current >= 0) filebox.current -= filebox.height - 1; else filebox.current = filebox.scroll; if (filebox.current < 0) filebox.current = 0; if (filebox.current < filebox.scroll) filebox.scroll = filebox.current; goto changed; } } else if (key==PAGE_DOWN) { if (filebox.count > 0) { if (filebox.current >= 0) filebox.current += filebox.height - 1; else filebox.current = filebox.scroll; if (filebox.current >= filebox.count) filebox.current = filebox.count-1; if (filebox.current >= filebox.scroll + filebox.height) filebox.scroll = filebox.current - filebox.height + 1; goto changed; } } else if (ascii(key)==TAB) { if (filebox.current >= 0) goto changed; } else if (key==-1) fill_filelist(s); hi_vid(); return FALSE; changed: strcpy(s, filebox.data[filebox.current].text); *len = *cpos = strlen(s); draw_contents(&filebox); hi_vid(); return TRUE; }