示例#1
0
gui::dialog::dimension_measurements file_dialog::layout(int xloc, int yloc)
{
	gui::dialog::dimension_measurements dim = dialog::layout(xloc, yloc);

	//shift the menu up
	unsigned y_shift = dim.menu_y - std::min<int>(dim.label_y, dim.textbox.y);
	int y_max = dim.menu_y + get_menu().height();
	dim.menu_y -= y_shift;

	//shift the extra buttons up
	if (show_directory_buttons_)
	{
		std::map<gui::dialog_button *const, std::pair<int,int> >::iterator i;
		for(i = dim.buttons.begin(); i != dim.buttons.end(); ++i)
		{
			const int btn_h = i->first->height();
			int& btn_y = i->second.second;
			y_max = std::max<int>(y_max, btn_y + btn_h);
			btn_y -= y_shift;
		}
	}

	//shift the textbox down
	const int textbox_bottom_y = dim.textbox.y + get_textbox().height();
	const int label_bottom_y = dim.label_y + get_textbox().get_label()->height();
	y_shift = y_max - std::max<int>(textbox_bottom_y, label_bottom_y);
	dim.textbox.y += y_shift;
	dim.label_y += y_shift;

	set_layout(dim);
	return dim;
}
示例#2
0
void file_dialog::set_save_text(const std::string& filename)
{
	const std::string fn = format_filename(filename);
	const size_t filename_dot = fn.find_last_of('.');
	get_textbox().set_text(fn);
	get_textbox().set_selection(0, filename_dot != std::string::npos ? filename_dot : fn.length());
	get_textbox().set_cursor_pos(0);
}
示例#3
0
void file_dialog::action(gui::dialog_process_info &dp_info) {
	if(result() == gui::CLOSE_DIALOG)
		return;

	//handle "delete item" requests
	if(result() == gui::DELETE_ITEM)
	{
		if(!chosen_file_.empty())
		{
			if(files_list_->delete_chosen_file() == -1) {
				gui2::show_transient_error_message(get_display().video()
						, _("Deletion of the file failed."));
				dp_info.clear_buttons();
			} else {
				dp_info.first_time = true;
			}
		}
		set_result(gui::CONTINUE_DIALOG);
	}
	//handle "create item" requests
	else if(result() == gui::CREATE_ITEM)
	{
		std::string new_dir_name = "";
		if(gui2::tfolder_create::execute(new_dir_name, get_display().video()))
		{
			if( !files_list_->make_directory(new_dir_name) ) {
				gui2::show_transient_error_message(get_display().video()
						, _("Creation of the directory failed."));
			} else {
				dp_info.first_time = true;
			}
		}
		dp_info.clear_buttons();
		set_result(gui::CONTINUE_DIALOG);
	}

	//update the chosen file
	if((dp_info.selection != last_selection_
		|| dp_info.first_time
		|| dp_info.double_clicked)
			&& (!files_list_->type_a_head()
				|| dp_info.new_left_button))
	{
		files_list_->reset_type_a_head();

		chosen_file_ = files_list_->get_choice();
		get_textbox().set_text(format_filename(chosen_file_));
		last_selection_ = (dp_info.double_clicked) ? -1 : dp_info.selection;
		last_textbox_text_ = textbox_text();
	}
	else if(textbox_text() != last_textbox_text_)
	{
		chosen_file_ = unformat_filename(textbox_text());
		last_textbox_text_ = textbox_text();

		// Do type-a-head search in listbox
        if (autocomplete_) {
		    files_list_->select_file(textbox_text());
        }
	}

	if(result() >=0) {
		//if a directory has been chosen, enter it
		if(files_list_->is_directory(chosen_file_))
		{
			files_list_->change_directory(chosen_file_);
			get_message().set_text(format_dirname(files_list_->get_directory()));

			//reset the chosen file
			chosen_file_ = "..";
			get_textbox().set_text(format_filename(chosen_file_));
			set_result(gui::CONTINUE_DIALOG);
		}
		//if a file has been chosen, return button index "Ok"
		else
		{
			set_result(0);
		}
	}
}
示例#4
0
void file_dialog::select_file(const std::string& file)
{
	chosen_file_ = file;
	get_textbox().set_text(format_filename(chosen_file_));
	files_list_->select_file(file);
}