13
0

cont'd work on Lua Script Console

This commit is contained in:
Robin Gareus 2016-03-24 01:44:06 +01:00
parent 28b707061b
commit 2061c352d2

View File

@ -46,6 +46,7 @@
#include "public_editor.h" #include "public_editor.h"
#include "tooltips.h" #include "tooltips.h"
#include "utils.h" #include "utils.h"
#include "utils_videotl.h"
#include "i18n.h" #include "i18n.h"
@ -120,7 +121,7 @@ LuaWindow::LuaWindow ()
_btn_open.set_sensitive (false); // TODO _btn_open.set_sensitive (false); // TODO
_btn_save.set_sensitive (false); _btn_save.set_sensitive (false);
_btn_delete.set_sensitive (false); // TODO _btn_delete.set_sensitive (false);
// layout // layout
@ -164,7 +165,6 @@ LuaWindow::LuaWindow ()
LuaScripting::instance().scripts_changed.connect (*this, invalidator (*this), boost::bind (&LuaWindow::refresh_scriptlist, this), gui_context()); LuaScripting::instance().scripts_changed.connect (*this, invalidator (*this), boost::bind (&LuaWindow::refresh_scriptlist, this), gui_context());
Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer()); Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer());
_script_changed_connection = tb->signal_changed().connect (sigc::mem_fun(*this, &LuaWindow::script_changed)); _script_changed_connection = tb->signal_changed().connect (sigc::mem_fun(*this, &LuaWindow::script_changed));
} }
@ -197,7 +197,6 @@ void LuaWindow::set_session (Session* s)
update_title (); update_title ();
_session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&LuaWindow::update_title, this), gui_context()); _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&LuaWindow::update_title, this), gui_context());
// expose "Session" point directly
lua_State* L = lua.getState(); lua_State* L = lua.getState();
LuaBindings::set_session (L, _session); LuaBindings::set_session (L, _session);
} }
@ -207,7 +206,7 @@ LuaWindow::session_going_away ()
{ {
ENSURE_GUI_THREAD (*this, &LuaWindow::session_going_away); ENSURE_GUI_THREAD (*this, &LuaWindow::session_going_away);
lua.do_command ("collectgarbage();"); lua.do_command ("collectgarbage();");
//TODO: re-init lua-engine (drop all references) ?? //TODO: re-init lua-engine (drop all references)
SessionHandlePtr::session_going_away (); SessionHandlePtr::session_going_away ();
_session = 0; _session = 0;
@ -308,24 +307,50 @@ LuaWindow::clear_output ()
void void
LuaWindow::new_script () LuaWindow::new_script ()
{ {
#if 0 char buf[32];
Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer()); snprintf (buf, sizeof (buf), "#%d", count_scratch_buffers () + 1);
tb->set_text (""); script_buffers.push_back (ScriptBufferPtr (new LuaWindow::ScriptBuffer (buf)));
#endif script_selection_changed (script_buffers.back ());
refresh_scriptlist ();
} }
void void
LuaWindow::delete_script () LuaWindow::delete_script ()
{ {
#if 0 assert (_current_buffer->flags & Buffer_Scratch);
Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer()); for (ScriptBufferList::iterator i = script_buffers.begin (); i != script_buffers.end (); ++i) {
tb->set_text (""); if ((*i) == _current_buffer) {
#endif script_buffers.erase (i);
break;
}
}
for (ScriptBufferList::const_iterator i = script_buffers.begin (); i != script_buffers.end (); ++i) {
if ((*i)->flags & Buffer_Scratch) {
script_selection_changed (*i);
return;
}
}
new_script ();
} }
void void
LuaWindow::import_script () LuaWindow::import_script ()
{ {
// TODO: dialog to select file or enter URL
// TODO convert a few URL (eg. pastebin) to raw.
#if 0
char *url = "http://pastebin.com/raw/3UMkZ6nV";
char *rv = a3_curl_http_get (url, 0);
if (rv) {
new_script ();
Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer());
tb->set_text (rv);
_current_buffer->flags &= BufferFlags(~Buffer_Dirty);
update_gui_state ();
}
free (rv);
#endif
} }
void void
@ -396,7 +421,7 @@ LuaWindow::save_script ()
time_t t = time(0); time_t t = time(0);
struct tm * timeinfo = localtime (&t); struct tm * timeinfo = localtime (&t);
strftime (buf, sizeof(buf), "%s%d", timeinfo); strftime (buf, sizeof(buf), "%s%d", timeinfo);
sprintf (buf, "%s%d", buf, random ()); // is this valid? sprintf (buf, "%s%ld", buf, random ()); // is this valid?
MD5 md5; MD5 md5;
std::string fn = md5.digestString (buf); std::string fn = md5.digestString (buf);
@ -439,7 +464,6 @@ LuaWindow::setup_buffers ()
return; return;
} }
script_buffers.push_back (ScriptBufferPtr (new LuaWindow::ScriptBuffer("#1"))); script_buffers.push_back (ScriptBufferPtr (new LuaWindow::ScriptBuffer("#1")));
script_buffers.push_back (ScriptBufferPtr (new LuaWindow::ScriptBuffer("#2"))); // XXX
_current_buffer = script_buffers.front(); _current_buffer = script_buffers.front();
refresh_scriptlist (); refresh_scriptlist ();
@ -449,7 +473,13 @@ LuaWindow::setup_buffers ()
uint32_t uint32_t
LuaWindow::count_scratch_buffers () const LuaWindow::count_scratch_buffers () const
{ {
return 0; uint32_t n = 0;
for (ScriptBufferList::const_iterator i = script_buffers.begin (); i != script_buffers.end (); ++i) {
if ((*i)->flags & Buffer_Scratch) {
++n;
}
}
return n;
} }
void void