예제 #1
0
파일: file_dialog.cpp 프로젝트: zz676/godot
void FileDialog::set_access(Access p_access) {

	ERR_FAIL_INDEX(p_access,3);
	if (access==p_access)
		return;
	memdelete( dir_access );
	switch(p_access) {
		case ACCESS_FILESYSTEM: {

			dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
		} break;
		case ACCESS_RESOURCES: {

			dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
		} break;
		case ACCESS_USERDATA: {

			dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA);
		} break;
	}
	access=p_access;
	_update_drives();
	invalidate();
	update_filters();
	update_dir();
}
예제 #2
0
파일: file_dialog.cpp 프로젝트: zz676/godot
FileDialog::FileDialog() {

	show_hidden_files=true;

	VBoxContainer *vbc = memnew( VBoxContainer );
	add_child(vbc);
	set_child_rect(vbc);

	mode=MODE_SAVE_FILE;
	set_title("Save a File");
	
	dir = memnew(LineEdit);
	HBoxContainer *pathhb = memnew( HBoxContainer );
	pathhb->add_child(dir);
	dir->set_h_size_flags(SIZE_EXPAND_FILL);

	drives = memnew( OptionButton );
	pathhb->add_child(drives);
	drives->connect("item_selected",this,"_select_drive");

	makedir = memnew( Button );
	makedir->set_text("Create Folder");
	makedir->connect("pressed",this,"_make_dir");
	pathhb->add_child(makedir);
	
	vbc->add_margin_child("Path:",pathhb);
	
	tree = memnew(Tree);
	tree->set_hide_root(true);
	vbc->add_margin_child("Directories & Files:",tree,true);
	
	file = memnew(LineEdit);
	//add_child(file);
	vbc->add_margin_child("File:",file);
	

	filter = memnew( OptionButton );
	//add_child(filter);
	vbc->add_margin_child("Filter:",filter);
	filter->set_clip_text(true);//too many extensions overflow it

	dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	access=ACCESS_RESOURCES;
	_update_drives();

	
	connect("confirmed", this,"_action_pressed");
	//cancel->connect("pressed", this,"_cancel_pressed");
	tree->connect("cell_selected", this,"_tree_selected",varray(),CONNECT_DEFERRED);
	tree->connect("item_activated", this,"_tree_db_selected",varray());
	dir->connect("text_entered", this,"_dir_entered");
	file->connect("text_entered", this,"_file_entered");
	filter->connect("item_selected", this,"_filter_selected");

	
	confirm_save = memnew( ConfirmationDialog );
	confirm_save->set_as_toplevel(true);
	add_child(confirm_save);

	
	confirm_save->connect("confirmed", this,"_save_confirm_pressed");

	makedialog = memnew( ConfirmationDialog );
	makedialog->set_title("Create Folder");
	VBoxContainer *makevb= memnew( VBoxContainer );
	makedialog->add_child(makevb);
	makedialog->set_child_rect(makevb);
	makedirname = memnew( LineEdit );
	makevb->add_margin_child("Name:",makedirname);
	add_child(makedialog);
	makedialog->register_text_enter(makedirname);
	makedialog->connect("confirmed",this,"_make_dir_confirm");
	mkdirerr = memnew( AcceptDialog );
	mkdirerr->set_text("Could not create folder.");
	add_child(mkdirerr);

	exterr = memnew( AcceptDialog );
	exterr->set_text("Must use a valid extension.");
	add_child(exterr);


	//update_file_list();
	update_filters();
	update_dir();

	set_hide_on_ok(false);
	vbox=vbc;


	invalidated=true;
	if (register_func)
		register_func(this);
	
}
예제 #3
0
EditorFileDialog::EditorFileDialog() {

	show_hidden_files=default_show_hidden_files;
	display_mode=default_display_mode;
	local_history_pos=0;

	VBoxContainer *vbc = memnew( VBoxContainer );
	add_child(vbc);
	set_child_rect(vbc);

	mode=MODE_SAVE_FILE;
	set_title(TTR("Save a File"));

	HBoxContainer *pathhb = memnew( HBoxContainer );

	dir_prev = memnew( ToolButton );
	dir_next = memnew( ToolButton );
	dir_up = memnew( ToolButton );

	pathhb->add_child(dir_prev);
	pathhb->add_child(dir_next);
	pathhb->add_child(dir_up);

	dir_prev->connect("pressed",this,"_go_back");
	dir_next->connect("pressed",this,"_go_forward");
	dir_up->connect("pressed",this,"_go_up");

	dir = memnew(LineEdit);
	pathhb->add_child(dir);
	dir->set_h_size_flags(SIZE_EXPAND_FILL);

	refresh = memnew( ToolButton );
	refresh->connect("pressed",this,"_update_file_list");
	pathhb->add_child(refresh);

	favorite = memnew( ToolButton );
	favorite->set_toggle_mode(true);
	favorite->connect("toggled",this,"_favorite_toggled");
	pathhb->add_child(favorite);

	mode_thumbnails = memnew( ToolButton );
	mode_thumbnails->connect("pressed",this,"set_display_mode",varray(DISPLAY_THUMBNAILS));
	mode_thumbnails->set_toggle_mode(true);
	mode_thumbnails->set_pressed(display_mode==DISPLAY_THUMBNAILS);
	pathhb->add_child(mode_thumbnails);

	mode_list = memnew( ToolButton );
	mode_list->connect("pressed",this,"set_display_mode",varray(DISPLAY_LIST));
	mode_list->set_toggle_mode(true);
	mode_list->set_pressed(display_mode==DISPLAY_LIST);
	pathhb->add_child(mode_list);

	drives = memnew( OptionButton );
	pathhb->add_child(drives);
	drives->connect("item_selected",this,"_select_drive");

	makedir = memnew( Button );
	makedir->set_text(TTR("Create Folder"));
	makedir->connect("pressed",this,"_make_dir");
	pathhb->add_child(makedir);

	list_hb = memnew( HBoxContainer );

	vbc->add_margin_child(TTR("Path:"),pathhb);
	vbc->add_child(list_hb);
	list_hb->set_v_size_flags(SIZE_EXPAND_FILL);

	VBoxContainer *fav_vb = memnew( VBoxContainer );
	list_hb->add_child(fav_vb);
	HBoxContainer *fav_hb = memnew( HBoxContainer );
	fav_vb->add_child(fav_hb);
	fav_hb->add_child(memnew(Label(TTR("Favorites:"))));
	fav_hb->add_spacer();
	fav_up = memnew( ToolButton );
	fav_hb->add_child(fav_up);
	fav_up->connect("pressed",this,"_favorite_move_up");
	fav_down = memnew( ToolButton );
	fav_hb->add_child(fav_down);
	fav_down->connect("pressed",this,"_favorite_move_down");
	fav_rm = memnew( ToolButton );
	fav_hb->add_child(fav_rm);
	fav_rm->hide(); // redundant

	MarginContainer *fav_mv = memnew( MarginContainer );
	fav_vb->add_child(fav_mv);
	fav_mv->set_v_size_flags(SIZE_EXPAND_FILL);
	favorites = memnew( ItemList );
	fav_mv->add_child(favorites);
	favorites->connect("item_selected",this,"_favorite_selected");

	recent = memnew( ItemList );
	fav_vb->add_margin_child(TTR("Recent:"),recent,true);
	recent->connect("item_selected",this,"_recent_selected");

	VBoxContainer *item_vb = memnew( VBoxContainer );
	list_hb->add_child(item_vb);
	item_vb->set_h_size_flags(SIZE_EXPAND_FILL);

	item_list = memnew( ItemList );
	item_list->set_v_size_flags(SIZE_EXPAND_FILL);
	item_vb->add_margin_child(TTR("Directories & Files:"),item_list,true);

	HBoxContainer* filter_hb = memnew( HBoxContainer );
	item_vb->add_child(filter_hb);

	VBoxContainer *filter_vb = memnew( VBoxContainer );
	filter_hb->add_child(filter_vb);
	filter_vb->set_h_size_flags(SIZE_EXPAND_FILL);

	preview_vb = memnew( VBoxContainer );
	filter_hb->add_child(preview_vb);
	CenterContainer *prev_cc = memnew( CenterContainer );
	preview_vb->add_margin_child(TTR("Preview:"),prev_cc);
	preview = memnew( TextureFrame );
	prev_cc->add_child(preview);
	preview_vb->hide();


	file = memnew(LineEdit);
	//add_child(file);
	filter_vb->add_margin_child(TTR("File:"),file);


	filter = memnew( OptionButton );
	//add_child(filter);
	filter_vb->add_margin_child(TTR("Filter:"),filter);
	filter->set_clip_text(true);//too many extensions overflow it

	dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	access=ACCESS_RESOURCES;
	_update_drives();


	connect("confirmed", this,"_action_pressed");
	//cancel->connect("pressed", this,"_cancel_pressed");
	item_list->connect("item_selected", this,"_item_selected",varray(),CONNECT_DEFERRED);
	item_list->connect("item_activated", this,"_item_db_selected",varray());
	dir->connect("text_entered", this,"_dir_entered");
	file->connect("text_entered", this,"_file_entered");
	filter->connect("item_selected", this,"_filter_selected");


	confirm_save = memnew( ConfirmationDialog );
	confirm_save->set_as_toplevel(true);
	add_child(confirm_save);


	confirm_save->connect("confirmed", this,"_save_confirm_pressed");

	makedialog = memnew( ConfirmationDialog );
	makedialog->set_title(TTR("Create Folder"));
	VBoxContainer *makevb= memnew( VBoxContainer );
	makedialog->add_child(makevb);
	makedialog->set_child_rect(makevb);
	makedirname = memnew( LineEdit );
	makevb->add_margin_child(TTR("Name:"),makedirname);
	add_child(makedialog);
	makedialog->register_text_enter(makedirname);
	makedialog->connect("confirmed",this,"_make_dir_confirm");
	mkdirerr = memnew( AcceptDialog );
	mkdirerr->set_text(TTR("Could not create folder."));
	add_child(mkdirerr);

	exterr = memnew( AcceptDialog );
	exterr->set_text(TTR("Must use a valid extension."));
	add_child(exterr);


	//update_file_list();
	update_filters();
	update_dir();

	set_hide_on_ok(false);
	vbox=vbc;


	invalidated=true;
	if (register_func)
		register_func(this);

	preview_wheel_timeout=0;
	preview_wheel_index=0;
	preview_waiting=false;

}
예제 #4
0
FileDialog::FileDialog() {

	show_hidden_files = default_show_hidden_files;

	mode_overrides_title = true;

	VBoxContainer *vbc = memnew(VBoxContainer);
	add_child(vbc);

	mode = MODE_SAVE_FILE;
	set_title(RTR("Save a File"));

	HBoxContainer *hbc = memnew(HBoxContainer);

	dir_up = memnew(ToolButton);
	dir_up->set_tooltip(RTR("Go to parent folder"));
	hbc->add_child(dir_up);
	dir_up->connect("pressed", this, "_go_up");

	hbc->add_child(memnew(Label(RTR("Path:"))));
	dir = memnew(LineEdit);
	hbc->add_child(dir);
	dir->set_h_size_flags(SIZE_EXPAND_FILL);

	refresh = memnew(ToolButton);
	refresh->connect("pressed", this, "_update_file_list");
	hbc->add_child(refresh);

	drives = memnew(OptionButton);
	hbc->add_child(drives);
	drives->connect("item_selected", this, "_select_drive");

	makedir = memnew(Button);
	makedir->set_text(RTR("Create Folder"));
	makedir->connect("pressed", this, "_make_dir");
	hbc->add_child(makedir);
	vbc->add_child(hbc);

	tree = memnew(Tree);
	tree->set_hide_root(true);
	vbc->add_margin_child(RTR("Directories & Files:"), tree, true);

	hbc = memnew(HBoxContainer);
	hbc->add_child(memnew(Label(RTR("File:"))));
	file = memnew(LineEdit);
	file->set_stretch_ratio(4);
	file->set_h_size_flags(SIZE_EXPAND_FILL);
	hbc->add_child(file);
	filter = memnew(OptionButton);
	filter->set_stretch_ratio(3);
	filter->set_h_size_flags(SIZE_EXPAND_FILL);
	filter->set_clip_text(true); // too many extensions overflows it
	hbc->add_child(filter);
	vbc->add_child(hbc);

	dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	access = ACCESS_RESOURCES;
	_update_drives();

	connect("confirmed", this, "_action_pressed");
	tree->connect("cell_selected", this, "_tree_selected", varray(), CONNECT_DEFERRED);
	tree->connect("item_activated", this, "_tree_item_activated", varray());
	tree->connect("nothing_selected", this, "deselect_items");
	dir->connect("text_entered", this, "_dir_entered");
	file->connect("text_entered", this, "_file_entered");
	filter->connect("item_selected", this, "_filter_selected");

	confirm_save = memnew(ConfirmationDialog);
	confirm_save->set_as_toplevel(true);
	add_child(confirm_save);

	confirm_save->connect("confirmed", this, "_save_confirm_pressed");

	makedialog = memnew(ConfirmationDialog);
	makedialog->set_title(RTR("Create Folder"));
	VBoxContainer *makevb = memnew(VBoxContainer);
	makedialog->add_child(makevb);

	makedirname = memnew(LineEdit);
	makevb->add_margin_child(RTR("Name:"), makedirname);
	add_child(makedialog);
	makedialog->register_text_enter(makedirname);
	makedialog->connect("confirmed", this, "_make_dir_confirm");
	mkdirerr = memnew(AcceptDialog);
	mkdirerr->set_text(RTR("Could not create folder."));
	add_child(mkdirerr);

	exterr = memnew(AcceptDialog);
	exterr->set_text(RTR("Must use a valid extension."));
	add_child(exterr);

	update_filters();
	update_dir();

	set_hide_on_ok(false);
	vbox = vbc;

	invalidated = true;
	if (register_func)
		register_func(this);
}