summaryrefslogtreecommitdiff
path: root/tools/editor/editor_settings.h
blob: c44afd95935008dad313cb503a2a828515a6a02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*************************************************************************/
/*  editor_settings.h                                                    */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#ifndef EDITOR_SETTINGS_H
#define EDITOR_SETTINGS_H

#include "object.h"

#include "resource.h"
#include "os/thread_safe.h"

class EditorPlugin;

class EditorSettings : public Resource {

	OBJ_TYPE( EditorSettings, Resource );
private:
	_THREAD_SAFE_CLASS_

public:
	struct Plugin {

		EditorPlugin *instance;
		String path;
		String name;
		String author;
		String version;
		String description;
		bool installs;
		String script;
		Vector<String> install_files;
	};
private:
	Map<String,Plugin> plugins;

	struct VariantContainer {
		int order;
		Variant variant;
		bool hide_from_editor;
		VariantContainer(){ order=0; hide_from_editor=false; }
		VariantContainer(const Variant& p_variant, int p_order) { variant=p_variant; order=p_order; hide_from_editor=false; }
	};

	HashMap<String,PropertyInfo> hints;
	int last_order;
	HashMap<String,VariantContainer> props;
	String resource_path;

	bool _set(const StringName& p_name, const Variant& p_value);
	bool _get(const StringName& p_name,Variant &r_ret) const;
	void _get_property_list(List<PropertyInfo> *p_list) const;

	static Ref<EditorSettings> singleton;

	String config_file_path;
	String settings_path;

	Ref<Resource> clipboard;


	EditorPlugin *_load_plugin_editor(const String& p_path);
	Error _load_plugin(const String& p_path,Plugin& plugin);

	void _load_defaults();

protected:

	static void _bind_methods();
public:

	enum {
		NOTIFICATION_EDITOR_SETTINGS_CHANGED=10000
	};


	bool has(String p_var) const;
	static EditorSettings *get_singleton();
	void erase(String p_var);
	String get_settings_path() const;

	const Map<String,Plugin>& get_plugins() const { return plugins; }

	void scan_plugins();
	void enable_plugins();

	void raise_order(const String& p_name);
	static void create();
	static void save();
	static void destroy();

	void notify_changes();

	void set_plugin_enabled(const String& p_plugin,bool p_enabled);
	bool is_plugin_enabled(const String& p_plugin);

	void load_installed_plugin(const String& p_plugin);

	void set_resource_clipboard(const Ref<Resource>& p_resource) { clipboard=p_resource; }
	Ref<Resource> get_resource_clipboard() const { return clipboard; }

	void add_property_hint(const PropertyInfo& p_hint);

	EditorSettings();
	~EditorSettings();

};

//not a macro any longer

#define EDITOR_DEF(m_var,m_val) _EDITOR_DEF(m_var,Variant(m_val))
Variant _EDITOR_DEF( const String& p_var, const Variant& p_default);

#endif // EDITOR_SETTINGS_H