void MeshLibraryEditor::_menu_cbk(int p_option) {

	option=p_option;
	switch(p_option) {

		case MENU_OPTION_ADD_ITEM: {

			theme->create_item(theme->get_last_unused_item_id());
		} break;
		case MENU_OPTION_REMOVE_ITEM: {

			String p = editor->get_property_editor()->get_selected_path();
			if (p.begins_with("/MeshLibrary/item") && p.get_slice_count("/")>=3) {

				to_erase = p.get_slice("/",3).to_int();
				cd->set_text(vformat(TTR("Remove item %d?"),to_erase));
				cd->popup_centered(Size2(300,60));
			}
		} break;
		case MENU_OPTION_IMPORT_FROM_SCENE: {

			file->popup_centered_ratio();
		} break;
		 case MENU_OPTION_UPDATE_FROM_SCENE: {

			 cd->set_text("Update from existing scene?:\n"+String(theme->get_meta("_editor_source_scene")));
			 cd->popup_centered(Size2(500,60));
		 } break;
	}
}
Example #2
0
void EditorHelp::_help_callback(const String& p_topic) {

	String what = p_topic.get_slice(":",0);
	String clss = p_topic.get_slice(":",1);
	String name;
	if (p_topic.get_slice_count(":")==3)
		name=p_topic.get_slice(":",2);

	_request_help(clss); //first go to class

	int line=0;

	if (what=="class_desc") {
		line=description_line;
	} else if (what=="class_signal") {
		if (signal_line.has(name))
			line=signal_line[name];
	} else if (what=="class_method" || what=="class_method_desc") {
		if (method_line.has(name))
			line=method_line[name];
	} else if (what=="class_property") {

		if (property_line.has(name))
			line=property_line[name];
	} else if (what=="class_theme_item") {

		if (theme_property_line.has(name))
			line=theme_property_line[name];
	} else if (what=="class_constant") {

		if (constant_line.has(name))
			line=constant_line[name];
	}

	class_desc->call_deferred("scroll_to_line", line);

}
Example #3
0
void FileDialog::update_file_list() {

	tree->clear();
	dir_access->list_dir_begin();

	TreeItem *root = tree->create_item();
	Ref<Texture> folder = get_icon("folder");
	List<String> files;
	List<String> dirs;

	bool isdir;
	bool ishidden;
	bool show_hidden = show_hidden_files;
	String item;

	while ((item = dir_access->get_next(&isdir)) != "") {

		ishidden = dir_access->current_is_hidden();

		if (show_hidden || !ishidden) {
			if (!isdir)
				files.push_back(item);
			else
				dirs.push_back(item);
		}
	}

	if (dirs.find("..") == NULL) {
		//may happen if lacking permissions
		dirs.push_back("..");
	}

	dirs.sort_custom<NaturalNoCaseComparator>();
	files.sort_custom<NaturalNoCaseComparator>();

	while (!dirs.empty()) {
		String &dir_name = dirs.front()->get();
		TreeItem *ti = tree->create_item(root);
		ti->set_text(0, dir_name + "/");
		ti->set_icon(0, folder);

		Dictionary d;
		d["name"] = dir_name;
		d["dir"] = true;

		ti->set_metadata(0, d);

		dirs.pop_front();
	}

	dirs.clear();

	List<String> patterns;
	// build filter
	if (filter->get_selected() == filter->get_item_count() - 1) {

		// match all
	} else if (filters.size() > 1 && filter->get_selected() == 0) {
		// match all filters
		for (int i = 0; i < filters.size(); i++) {

			String f = filters[i].get_slice(";", 0);
			for (int j = 0; j < f.get_slice_count(","); j++) {

				patterns.push_back(f.get_slice(",", j).strip_edges());
			}
		}
	} else {
		int idx = filter->get_selected();
		if (filters.size() > 1)
			idx--;

		if (idx >= 0 && idx < filters.size()) {

			String f = filters[idx].get_slice(";", 0);
			for (int j = 0; j < f.get_slice_count(","); j++) {

				patterns.push_back(f.get_slice(",", j).strip_edges());
			}
		}
	}

	String base_dir = dir_access->get_current_dir();

	while (!files.empty()) {

		bool match = patterns.empty();
		String match_str;

		for (List<String>::Element *E = patterns.front(); E; E = E->next()) {

			if (files.front()->get().matchn(E->get())) {
				match_str = E->get();
				match = true;
				break;
			}
		}

		if (match) {
			TreeItem *ti = tree->create_item(root);
			ti->set_text(0, files.front()->get());

			if (get_icon_func) {

				Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
				ti->set_icon(0, icon);
			}

			if (mode == MODE_OPEN_DIR) {
				ti->set_custom_color(0, get_color("files_disabled"));
				ti->set_selectable(0, false);
			}
			Dictionary d;
			d["name"] = files.front()->get();
			d["dir"] = false;
			ti->set_metadata(0, d);

			if (file->get_text() == files.front()->get() || match_str == files.front()->get())
				ti->select(0);
		}

		files.pop_front();
	}

	if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == NULL)
		tree->get_root()->get_children()->select(0);

	files.clear();
}
Example #4
0
void FileDialog::_action_pressed() {

	if (mode == MODE_OPEN_FILES) {

		TreeItem *ti = tree->get_next_selected(NULL);
		String fbase = dir_access->get_current_dir();

		PoolVector<String> files;
		while (ti) {

			files.push_back(fbase.plus_file(ti->get_text(0)));
			ti = tree->get_next_selected(ti);
		}

		if (files.size()) {
			emit_signal("files_selected", files);
			hide();
		}

		return;
	}

	String f = dir_access->get_current_dir().plus_file(file->get_text());

	if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) {
		emit_signal("file_selected", f);
		hide();
	} else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) {

		String path = dir_access->get_current_dir();

		path = path.replace("\\", "/");
		TreeItem *item = tree->get_selected();
		if (item) {
			Dictionary d = item->get_metadata(0);
			if (d["dir"]) {
				path = path.plus_file(d["name"]);
			}
		}

		emit_signal("dir_selected", path);
		hide();
	}

	if (mode == MODE_SAVE_FILE) {

		bool valid = false;

		if (filter->get_selected() == filter->get_item_count() - 1) {
			valid = true; //match none
		} else if (filters.size() > 1 && filter->get_selected() == 0) {
			// match all filters
			for (int i = 0; i < filters.size(); i++) {

				String flt = filters[i].get_slice(";", 0);
				for (int j = 0; j < flt.get_slice_count(","); j++) {

					String str = flt.get_slice(",", j).strip_edges();
					if (f.match(str)) {
						valid = true;
						break;
					}
				}
				if (valid)
					break;
			}
		} else {
			int idx = filter->get_selected();
			if (filters.size() > 1)
				idx--;
			if (idx >= 0 && idx < filters.size()) {

				String flt = filters[idx].get_slice(";", 0);
				int filterSliceCount = flt.get_slice_count(",");
				for (int j = 0; j < filterSliceCount; j++) {

					String str = (flt.get_slice(",", j).strip_edges());
					if (f.match(str)) {
						valid = true;
						break;
					}
				}

				if (!valid && filterSliceCount > 0) {
					String str = (flt.get_slice(",", 0).strip_edges());
					f += str.substr(1, str.length() - 1);
					file->set_text(f.get_file());
					valid = true;
				}
			} else {
				valid = true;
			}
		}

		if (!valid) {

			exterr->popup_centered_minsize(Size2(250, 80));
			return;
		}

		if (dir_access->file_exists(f)) {
			confirm_save->set_text(RTR("File Exists, Overwrite?"));
			confirm_save->popup_centered(Size2(200, 80));
		} else {

			emit_signal("file_selected", f);
			hide();
		}
	}
}
Example #5
0
void ScriptTextEditor::_load_theme_settings() {

	get_text_edit()->clear_colors();

	/* keyword color */


	get_text_edit()->set_custom_bg_color(EDITOR_DEF("text_editor/background_color",Color(0,0,0,0)));
	get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
	get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
	get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));

	Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));

	get_text_edit()->set_syntax_coloring(true);
	List<String> keywords;
	script->get_language()->get_reserved_words(&keywords);
	for(List<String>::Element *E=keywords.front();E;E=E->next()) {

		get_text_edit()->add_keyword_color(E->get(),keyword_color);
	}

	//colorize core types
	Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));

	get_text_edit()->add_keyword_color("Vector2",basetype_color);
	get_text_edit()->add_keyword_color("Vector3",basetype_color);
	get_text_edit()->add_keyword_color("Plane",basetype_color);
	get_text_edit()->add_keyword_color("Quat",basetype_color);
	get_text_edit()->add_keyword_color("AABB",basetype_color);
	get_text_edit()->add_keyword_color("Matrix3",basetype_color);
	get_text_edit()->add_keyword_color("Transform",basetype_color);
	get_text_edit()->add_keyword_color("Color",basetype_color);
	get_text_edit()->add_keyword_color("Image",basetype_color);
	get_text_edit()->add_keyword_color("InputEvent",basetype_color);

	//colorize engine types
	Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4));

	List<String> types;
	ObjectTypeDB::get_type_list(&types);

	for(List<String>::Element *E=types.front();E;E=E->next()) {

		get_text_edit()->add_keyword_color(E->get(),type_color);
	}

	//colorize comments
	Color comment_color = EDITOR_DEF("text_editor/comment_color",Color::hex(0x797e7eff));
	List<String> comments;
	script->get_language()->get_comment_delimiters(&comments);

	for(List<String>::Element *E=comments.front();E;E=E->next()) {

		String comment = E->get();
		String beg = comment.get_slice(" ",0);
		String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String();

		get_text_edit()->add_color_region(beg,end,comment_color,end=="");
	}

	//colorize strings
	Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
	List<String> strings;
	script->get_language()->get_string_delimiters(&strings);

	for (List<String>::Element *E=strings.front();E;E=E->next()) {

		String string = E->get();
		String beg = string.get_slice(" ",0);
		String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
		get_text_edit()->add_color_region(beg,end,string_color,end=="");
	}

	//colorize symbols
	Color symbol_color= EDITOR_DEF("text_editor/symbol_color",Color::hex(0x005291ff));
	get_text_edit()->set_symbol_color(symbol_color);

}