summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/windows/godot_win.cpp107
-rw-r--r--scene/gui/text_edit.cpp3
-rw-r--r--tools/editor/editor_settings.cpp2
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp64
-rw-r--r--tools/editor/plugins/script_editor_plugin.h4
5 files changed, 84 insertions, 96 deletions
diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp
index 0e74f63510..81c90d9dd0 100644
--- a/platform/windows/godot_win.cpp
+++ b/platform/windows/godot_win.cpp
@@ -115,29 +115,24 @@ PCHAR*
return argv;
}
-char* mb_to_utf8(const char* mbs) {
-
- int wlen = MultiByteToWideChar(CP_ACP,0,mbs,-1,NULL,0); // returns 0 if failed
- wchar_t *wbuf = new wchar_t[wlen + 1];
- MultiByteToWideChar(CP_ACP,0,mbs,-1,wbuf,wlen);
- wbuf[wlen]=0;
-
- int ulen = WideCharToMultiByte(CP_UTF8,0,wbuf,-1,NULL,0,NULL,NULL);
+char* wc_to_utf8(const wchar_t* wc) {
+ int ulen = WideCharToMultiByte(CP_UTF8,0,wc,-1,NULL,0,NULL,NULL);
char * ubuf = new char[ulen + 1];
- WideCharToMultiByte(CP_UTF8,0,wbuf,-1,ubuf,ulen,NULL,NULL);
+ WideCharToMultiByte(CP_UTF8,0,wc,-1,ubuf,ulen,NULL,NULL);
ubuf[ulen] = 0;
return ubuf;
}
-int main(int argc, char** argv) {
+int widechar_main(int argc, wchar_t** argv) {
OS_Windows os(NULL);
setlocale(LC_CTYPE, "");
char ** argv_utf8 = new char*[argc];
+
for(int i=0; i<argc; ++i) {
- argv_utf8[i] = mb_to_utf8(argv[i]);
+ argv_utf8[i] = wc_to_utf8(argv[i]);
}
Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]);
@@ -154,82 +149,30 @@ int main(int argc, char** argv) {
return os.get_exit_code();
};
-HINSTANCE godot_hinstance = NULL;
-
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
-
- int argc;
- char** argv;
-
- char* arg;
- int index;
- int result;
-
- // count the arguments
-
- argc = 1;
- arg = lpCmdLine;
-
- while (arg[0] != 0) {
-
- while (arg[0] != 0 && arg[0] == ' ') {
- arg++;
- }
-
- if (arg[0] != 0) {
-
- argc++;
-
- while (arg[0] != 0 && arg[0] != ' ') {
- arg++;
- }
-
- }
-
- }
-
- // tokenize the arguments
-
- argv = (char**)malloc(argc * sizeof(char*));
-
- arg = lpCmdLine;
- index = 1;
-
- while (arg[0] != 0) {
-
- while (arg[0] != 0 && arg[0] == ' ') {
- arg++;
- }
-
- if (arg[0] != 0) {
-
- argv[index] = arg;
- index++;
-
- while (arg[0] != 0 && arg[0] != ' ') {
- arg++;
- }
-
- if (arg[0] != 0) {
- arg[0] = 0;
- arg++;
- }
-
- }
+int main(int _argc, char** _argv) {
+ // _argc and _argv are ignored
+ // we are going to use the WideChar version of them instead
- }
+ LPWSTR *wc_argv;
+ int argc;
+ int result;
- // put the program name into argv[0]
+ wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc);
- char filename[_MAX_PATH];
+ if( NULL == wc_argv ) {
+ wprintf(L"CommandLineToArgvW failed\n");
+ return 0;
+ }
- GetModuleFileName(NULL, filename, _MAX_PATH);
- argv[0] = filename;
+ result = widechar_main(argc, wc_argv);
- // call the user specified main function
+ LocalFree(wc_argv);
+ return result;
+}
- result = main(argc, argv);
+HINSTANCE godot_hinstance = NULL;
- free(argv);
- return result;
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
+ godot_hinstance = hInstance;
+ return main(0,NULL);
}
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 75174a85de..681c33652e 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -3494,6 +3494,9 @@ void TextEdit::set_line(int line, String new_text)
return;
_remove_text(line, 0, line, text[line].length());
_insert_text(line, 0, new_text);
+ if (cursor.line==line) {
+ cursor.column=MIN(cursor.column,new_text.length());
+ }
}
void TextEdit::insert_at(const String &p_text, int at)
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index 52eeb1fefd..9a4505efed 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -408,7 +408,7 @@ void EditorSettings::_load_defaults() {
set("text_editor/idle_parse_delay",2);
set("text_editor/create_signal_callbacks",true);
- set("text_editor/autosave_interval_seconds",60);
+ set("text_editor/autosave_interval_secs",0);
set("text_editor/font","");
hints["text_editor/font"]=PropertyInfo(Variant::STRING,"text_editor/font",PROPERTY_HINT_GLOBAL_FILE,"*.fnt");
set("text_editor/auto_brace_complete", false);
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index 7deb856fa6..edc5d460e7 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -130,6 +130,7 @@ void ScriptEditorQuickOpen::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_confirmed"),&ScriptEditorQuickOpen::_confirmed);
ObjectTypeDB::bind_method(_MD("_sbox_input"),&ScriptEditorQuickOpen::_sbox_input);
+
ADD_SIGNAL(MethodInfo("goto_line",PropertyInfo(Variant::INT,"line")));
}
@@ -815,11 +816,11 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
+
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -839,7 +840,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
// begins with tab
if (line_text.begins_with("\t"))
@@ -865,11 +866,10 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -879,7 +879,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
line_text = '\t' + line_text;
tx->set_line(begin, line_text);
@@ -912,11 +912,12 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
+
+
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -930,7 +931,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
if (line_text.begins_with("#"))
@@ -1089,6 +1090,18 @@ void ScriptEditor::_notification(int p_what) {
editor->connect("stop_pressed",this,"_editor_stop");
editor->connect("script_add_function_request",this,"_add_callback");
editor->connect("resource_saved",this,"_res_saved_callback");
+ autosave_timer->connect("timeout",this,"_autosave_scripts");
+ {
+ float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
+ if (autosave_time>0) {
+ autosave_timer->set_wait_time(autosave_time);
+ autosave_timer->start();
+ } else {
+ autosave_timer->stop();
+ }
+ }
+
+ EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
}
@@ -1339,7 +1352,8 @@ void ScriptEditor::_bind_methods() {
ObjectTypeDB::bind_method("_breaked",&ScriptEditor::_breaked);
ObjectTypeDB::bind_method("_show_debugger",&ScriptEditor::_show_debugger);
ObjectTypeDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip);
-
+ ObjectTypeDB::bind_method("_autosave_scripts",&ScriptEditor::_autosave_scripts);
+ ObjectTypeDB::bind_method("_editor_settings_changed",&ScriptEditor::_editor_settings_changed);
}
@@ -1568,6 +1582,25 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const
}
+void ScriptEditor::_editor_settings_changed() {
+
+ print_line("settings changed");
+ float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
+ if (autosave_time>0) {
+ autosave_timer->set_wait_time(autosave_time);
+ autosave_timer->start();
+ } else {
+ autosave_timer->stop();
+ }
+
+}
+
+void ScriptEditor::_autosave_scripts() {
+
+ print_line("autosaving");
+ save_external_data();
+}
+
ScriptEditor::ScriptEditor(EditorNode *p_editor) {
editor=p_editor;
@@ -1718,6 +1751,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
v_split->add_child(debugger);
debugger->connect("breaked",this,"_breaked");
+
+ autosave_timer = memnew( Timer );
+ autosave_timer->set_one_shot(false);
+ add_child(autosave_timer);
+
// debugger_gui->hide();
}
diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h
index 7526138112..acfdd1e966 100644
--- a/tools/editor/plugins/script_editor_plugin.h
+++ b/tools/editor/plugins/script_editor_plugin.h
@@ -154,6 +154,7 @@ class ScriptEditor : public VBoxContainer {
MenuButton *window_menu;
MenuButton *debug_menu;
MenuButton *help_menu;
+ Timer *autosave_timer;
uint64_t idle;
TabContainer *tab_container;
@@ -195,6 +196,9 @@ class ScriptEditor : public VBoxContainer {
void _show_debugger(bool p_show);
void _update_window_menu();
+ void _editor_settings_changed();
+ void _autosave_scripts();
+
static ScriptEditor *script_editor;
protected:
void _notification(int p_what);