18#include <gdk/gdkkeysyms.h>
46#define MAX_LUACONSOLE_HISTORY 20
67 GtkAllocation *allocation,
75 int response, gpointer data);
131 if (pdialog->
shell == NULL) {
149 if (pdialog->
shell == NULL) {
163 return (NULL != pdialog->
shell);
175 if (NULL != pdialog->
shell) {
185 GtkWidget *
entry, *box, *vbox, *sw, *text, *notebook;
200 vbox = gtk_grid_new();
201 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
202 GTK_ORIENTATION_VERTICAL);
203 gtk_container_add(GTK_CONTAINER(box), vbox);
205 sw = gtk_scrolled_window_new(NULL, NULL);
206 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
207 GTK_SHADOW_ETCHED_IN);
208 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
209 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
210 gtk_container_add(GTK_CONTAINER(vbox), sw);
213 gtk_widget_set_hexpand(text,
TRUE);
214 gtk_widget_set_vexpand(text,
TRUE);
216 gtk_text_view_set_editable(GTK_TEXT_VIEW(text),
FALSE);
217 gtk_container_add(GTK_CONTAINER(sw), text);
218 g_signal_connect(text,
"size-allocate",
221 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
222 gtk_widget_realize(text);
223 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 5);
226 g_signal_connect(text,
"destroy", G_CALLBACK(gtk_widget_destroyed),
230 entry = gtk_entry_new();
231 g_object_set(
entry,
"margin", 2, NULL);
232 gtk_container_add(GTK_CONTAINER(vbox),
entry);
235 g_signal_connect(
entry,
"key_press_event",
238 g_signal_connect(
entry,
"destroy", G_CALLBACK(gtk_widget_destroyed),
258 const char *theinput;
264 theinput = gtk_entry_get_text(w);
282 gtk_entry_set_text(w,
"");
289 int response, gpointer data)
314 filesel = gtk_file_chooser_dialog_new(
"Load Lua file", GTK_WINDOW(
toplevel),
315 GTK_FILE_CHOOSER_ACTION_OPEN,
316 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
317 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
320 gtk_window_set_position(GTK_WINDOW(filesel), GTK_WIN_POS_MOUSE);
322 g_signal_connect(filesel,
"response",
326 gtk_window_present(GTK_WINDOW(filesel));
335 if (response == GTK_RESPONSE_OK) {
336 gchar *filename = g_filename_to_utf8(gtk_file_chooser_get_filename
337 (GTK_FILE_CHOOSER(
widget)),
338 -1, NULL, NULL, NULL);
340 if (NULL != filename) {
346 gtk_widget_destroy(
widget);
359 switch (ev->keyval) {
364 gtk_editable_set_position(GTK_EDITABLE(w), -1);
377 gtk_entry_set_text(GTK_ENTRY(w),
"");
379 gtk_editable_set_position(GTK_EDITABLE(w), -1);
395 GtkAllocation *allocation,
398 static int old_width = 0, old_height = 0;
399 if (allocation->width != old_width
400 || allocation->height != old_height) {
402 old_width = allocation->width;
403 old_height = allocation->height;
419 if (pdialog->
shell) {
426 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pdialog->
message_area),
427 &end, 0.0,
TRUE, 1.0, 0.0);
446 if (pdialog->
shell) {
459 const struct text_tag_list *tags)
470 gtk_text_buffer_get_end_iter(buf, &iter);
471 gtk_text_buffer_insert(buf, &iter,
"\n", -1);
472 mark = gtk_text_buffer_create_mark(buf, NULL, &iter,
TRUE);
481 strftime(timebuf,
sizeof(timebuf),
"[%H:%M:%S] ", &now_tm);
482 gtk_text_buffer_insert(buf, &iter, timebuf, -1);
485 text_start_offset = gtk_text_iter_get_offset(&iter);
486 gtk_text_buffer_insert(buf, &iter,
astring, -1);
494 gtk_text_buffer_delete_mark(buf, mark);
const struct ft_color ftc_luaconsole_input
#define text_tag_list_iterate_end
#define text_tag_list_iterate(tags, ptag)
bool genlist_remove(struct genlist *pgenlist, const void *punlink)
struct genlist * genlist_new(void)
void * genlist_get(const struct genlist *pgenlist, int idx)
void genlist_prepend(struct genlist *pgenlist, void *data)
void genlist_destroy(struct genlist *pgenlist)
int genlist_size(const struct genlist *pgenlist)
void set_message_buffer_view_link_handlers(GtkWidget *view)
void scroll_if_necessary(GtkTextView *textview, GtkTextMark *scroll_target)
void apply_text_tag(const struct text_tag *ptag, GtkTextBuffer *buf, ft_offset_t text_start_offset, const char *text)
GtkWidget * bottom_notebook
GtkWidget * right_notebook
#define GUI_GTK_OPTION(optname)
void gui_dialog_destroy(struct gui_dialog *dlg)
void gui_dialog_present(struct gui_dialog *dlg)
void gui_dialog_raise(struct gui_dialog *dlg)
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top)
void gui_dialog_response_set_callback(struct gui_dialog *dlg, GUI_DIALOG_RESPONSE_FUN fun)
GtkWidget * gui_dialog_add_button(struct gui_dialog *dlg, const char *text, int response)
GtkWidget * gui_dialog_add_stockbutton(struct gui_dialog *dlg, const char *stock, const char *text, int response)
void gui_dialog_show_all(struct gui_dialog *dlg)
void gui_dialog_set_title(struct gui_dialog *dlg, const char *title)
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
#define MAX_LUACONSOLE_HISTORY
void luaconsole_dialog_popdown(void)
static struct luaconsole_data * luaconsole_dialog_get(void)
static void luaconsole_dialog_scroll_to_bottom(void)
void luaconsole_dialog_init(void)
bool luaconsole_dialog_is_open(void)
static void luaconsole_load_file_callback(GtkWidget *widget, gint response, gpointer data)
static void luaconsole_dialog_create(struct luaconsole_data *pdialog)
static void luaconsole_response_callback(struct gui_dialog *pgui_dialog, int response, gpointer data)
static struct luaconsole_data * luaconsole
static void luaconsole_dialog_refresh(struct luaconsole_data *pdialog)
static void luaconsole_dialog_destroy(struct luaconsole_data *pdialog)
static void luaconsole_input_return(GtkEntry *w, gpointer data)
void real_luaconsole_append(const char *astring, const struct text_tag_list *tags)
static void luaconsole_load_file_popup(void)
void real_luaconsole_dialog_update(void)
void luaconsole_dialog_popup(bool raise)
static gboolean luaconsole_input_handler(GtkWidget *w, GdkEventKey *ev)
void luaconsole_dialog_done(void)
static void luaconsole_dialog_area_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
void luaconsole_welcome_message(void)
void luaconsole_printf(const struct ft_color color, const char *format,...)
#define fc_calloc(n, esz)
bool script_client_do_file(const char *filename)
bool script_client_do_string(const char *str)
struct gui_dialog * shell
struct genlist * history_list
GtkTextView * message_area
GtkTextBuffer * message_buffer
struct tm * fc_localtime(const time_t *timep, struct tm *result)