summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_cmd_dispatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'mixgtk/mixgtk_cmd_dispatcher.c')
-rw-r--r--mixgtk/mixgtk_cmd_dispatcher.c105
1 files changed, 58 insertions, 47 deletions
diff --git a/mixgtk/mixgtk_cmd_dispatcher.c b/mixgtk/mixgtk_cmd_dispatcher.c
index 7ed4a11..f237a1a 100644
--- a/mixgtk/mixgtk_cmd_dispatcher.c
+++ b/mixgtk/mixgtk_cmd_dispatcher.c
@@ -1,24 +1,24 @@
/* -*-c-*- -------------- mixgtk_cmd_dispatcher.c :
* Implementation of the functions declared in mixgtk_cmd_dispatcher.h
* ------------------------------------------------------------------
- * $Id: mixgtk_cmd_dispatcher.c,v 1.15 2002/04/09 23:28:19 jao Exp $
+ * $Id: mixgtk_cmd_dispatcher.c,v 1.16 2004/06/23 10:50:10 jao Exp $
* ------------------------------------------------------------------
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
+ * Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
*/
#include <stdlib.h>
@@ -74,9 +74,11 @@ static const gchar *TITLE_FORMAT_ = "gmixvm - %s";
static void
log_command_ (mixgtk_dispatch_data_t *dis, const gchar *cmd)
{
- gtk_text_insert (GTK_TEXT (dis->log), NULL, NULL, NULL,"MIX> ", -1);
- gtk_text_insert (GTK_TEXT (dis->log), NULL, NULL, NULL, cmd, -1);
- gtk_text_insert (GTK_TEXT (dis->log), NULL, NULL, NULL, "\n", -1);
+ GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis->log));
+
+ gtk_text_buffer_insert_at_cursor (buf, "MIX> ", -1);
+ gtk_text_buffer_insert_at_cursor (buf, cmd, -1);
+ gtk_text_buffer_insert_at_cursor (buf, "\n", -1);
#ifdef HAVE_LIBHISTORY
add_history ((char *)cmd);
@@ -90,16 +92,22 @@ flush_log_ (mixgtk_dispatch_data_t *dis)
{
enum {BLKSIZE = 100};
static gchar BUFFER[BLKSIZE];
-
+
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis->log));
+ GtkTextMark *mark;
ssize_t k;
+
fflush (dis->out);
while ((k = read (dis->fildes[0], BUFFER, BLKSIZE)) != 0)
{
if (k == -1 && errno != EINTR) break;
if (k != -1)
- gtk_text_insert (GTK_TEXT (dis->log), NULL, NULL, NULL,
- BUFFER, k);
+ gtk_text_buffer_insert_at_cursor (buffer, BUFFER, k);
}
+
+ mark = gtk_text_buffer_get_insert (buffer);
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (dis->log), mark, 0,
+ TRUE, 0, 0);
}
/* hooks */
@@ -116,7 +124,7 @@ load_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg,
gpointer data)
{
static glong id = -1;
-
+
if (mix_vm_cmd_dispatcher_get_last_result (dis))
{
GtkWindow *mainw =
@@ -129,7 +137,7 @@ load_post_hook_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg,
mixgtk_mixal_load_file ();
mixgtk_mixal_update ();
mixgtk_mixal_update_bp_all ();
-
+
if (id != -1)
gtk_statusbar_remove (GTK_STATUSBAR (dis_data_.status),
dis_data_.context, (guint)id);
@@ -291,27 +299,28 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top)
dis_data_.prompt =
mixgtk_widget_factory_get (top, MIXGTK_WIDGET_PROMPT);
g_return_val_if_fail (dis_data_.prompt != NULL, FALSE);
-
+
if (dis_data_.log)
text = gtk_editable_get_chars (GTK_EDITABLE (dis_data_.log), 0, -1);
-
+
dis_data_.log =
mixgtk_widget_factory_get (top, MIXGTK_WIDGET_LOG);
-
+
g_return_val_if_fail (dis_data_.log != NULL, FALSE);
-
+
if (text)
{
- gtk_text_insert (GTK_TEXT (dis_data_.log), NULL, NULL, NULL, text, -1);
+ gtk_text_buffer_insert_at_cursor
+ (gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis_data_.log)), text, -1);
g_free (text);
}
-
+
if (!dis_data_.dispatcher)
{
static const gchar *HISTORY_FILE = "gmixvm.history";
static gint HISTORY_SIZE = 100;
mix_config_t *config = mixgtk_config_get_mix_config ();
-
+
int r = pipe (dis_data_.fildes);
g_return_val_if_fail (r == 0, FALSE);
/* connect stdout/stderr to the pipe's write end */
@@ -336,10 +345,10 @@ mixgtk_cmd_dispatcher_init (mixgtk_dialog_id_t top)
dis_data_.out,
config);
mix_vm_cmd_dispatcher_print_time (dis_data_.dispatcher, FALSE);
-
+
install_hooks_ ();
}
-
+
dis_data_.status =
mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_STATUSBAR);
g_return_val_if_fail (dis_data_.status != NULL, FALSE);
@@ -424,38 +433,38 @@ complete_command_ (void)
{
GtkEntry *entry = GTK_ENTRY (dis_data_.prompt);
gchar *prefix = NULL;
- gchar *text = gtk_entry_get_text (entry);
+ const gchar *text = gtk_entry_get_text (entry);
const GList *cmds =
mix_vm_cmd_dispatcher_complete (dis_data_.dispatcher, text, &prefix);
if (prefix != NULL)
{
+ GtkTextBuffer *buf =
+ gtk_text_view_get_buffer (GTK_TEXT_VIEW (dis_data_.log));
+
gtk_entry_set_text (entry, prefix);
g_free (prefix);
if (g_list_length ((GList *)cmds) > 1)
{
- static gchar BUFFER[25];
+ static gchar BUFFER[25];
gint k = 0;
- gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL, "Completions:\n", -1);
+ gtk_text_buffer_insert_at_cursor (buf, "Completions:\n", -1);
while (cmds)
{
g_snprintf (BUFFER, 25, "%-12s", (const char*)cmds->data);
++k;
- gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL, BUFFER, -1);
+ gtk_text_buffer_insert_at_cursor (buf, BUFFER, -1);
if (k%5 == 0)
- gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL, "\n", -1);
-
+ gtk_text_buffer_insert_at_cursor (buf, "\n", -1);
+
cmds = cmds->next;
}
if (k%5 != 0)
- gtk_text_insert (GTK_TEXT (dis_data_.log),
- NULL, NULL, NULL, "\n", -1);
+ gtk_text_buffer_insert_at_cursor (buf, "\n", -1);
}
else
- gtk_entry_append_text (entry, " ");
+ gtk_text_buffer_insert_at_cursor (buf, " ", -1);
+ flush_log_ (&dis_data_);
}
}
@@ -488,18 +497,20 @@ on_command_prompt_key_press_event (GtkEntry *w, GdkEventKey *e, gpointer d)
return TRUE;
}
- if (key == GDK_Return)
+ return FALSE;
+}
+
+void
+on_command_prompt_activate (GtkEntry *prompt, gpointer data)
+{
+ gchar *text =
+ g_strstrip (gtk_editable_get_chars (GTK_EDITABLE (prompt), 0, -1));
+ if (text && *text)
{
- gchar *text = g_strstrip (gtk_entry_get_text (w));
- if (text && *text)
- {
- log_command_ (&dis_data_, text);
- if (!try_guile_ (text))
- mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text);
- gtk_entry_set_text (w, "");
- }
- return TRUE;
+ log_command_ (&dis_data_, text);
+ if (!try_guile_ (text))
+ mix_vm_cmd_dispatcher_dispatch_text (dis_data_.dispatcher, text);
+ gtk_entry_set_text (prompt, "");
}
-
- return FALSE;
+ g_free (text);
}