[gnome-mud] Refactor and improve mud input box handling



commit 00309aa7b687c9324c693ccd6e1d3941eb53ae16
Author: Mart Raudsepp <leio gentoo org>
Date:   Sat Jan 5 23:47:33 2019 +0200

    Refactor and improve mud input box handling
    
    Introduce a MudInputView class, which is a GtkStack based composite
    widget, that contains the GtkTextView and GtkEntry, allowing to start
    hiding the internals inside this new class. Now using a GtkStack
    allows to use some animations and otherwise conceptually better
    handling of this double widget thing from lack of GtkTextView
    supporting password entry. It also simplifies all the grab_focus
    calls, as this separate class now overrides grab_focus and passes
    it on to the active child, so the caller doesn't need to care.
    
    GtkScrolledWindow in GTK3 forces a min-height on its vscrollbar,
    which forces the whole GtkStack to be at least that high as well.
    This is worked around by a custom stylesheet that applies a lower
    min-height on MudInputView's vertical scrollbar.
    
    The resizing behaviour with GtkTextView+GtkScrolledView is buggy,
    so the resizing is a bit erratic. This is to be investigated deeper
    and improved still. It seems GtkTextView doesn't request a higher
    size after a new line is started until some letters are written in
    it, which is causing trouble and jumpy behaviour.

 data/main.ui                     |  50 +-----------
 data/org.gnome.MUD.gresource.xml |   4 +
 data/style.css                   |   3 +
 meson.build                      |   2 +-
 src/gnome-mud.c                  |  14 +++-
 src/meson.build                  |   2 +
 src/mud-input-view.c             | 157 +++++++++++++++++++++++++++++++++++++
 src/mud-input-view.h             |  37 +++++++++
 src/mud-input-view.ui            |  32 ++++++++
 src/mud-window.c                 | 164 ++++++++-------------------------------
 10 files changed, 282 insertions(+), 183 deletions(-)
---
diff --git a/data/main.ui b/data/main.ui
index 1835657..1615fea 100644
--- a/data/main.ui
+++ b/data/main.ui
@@ -980,56 +980,8 @@
               </packing>
             </child>
             <child>
-              <object class="GtkHBox" id="hbox10">
+              <object class="MudInputView" id="mud_input_view">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <child>
-                  <object class="GtkVBox" id="vbox4">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <child>
-                      <object class="GtkScrolledWindow" id="text_view_scroll">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="hscrollbar_policy">automatic</property>
-                        <property name="vscrollbar_policy">automatic</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkTextView" id="text_view">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkEntry" id="password_entry">
-                        <property name="can_focus">True</property>
-                        <property name="visibility">False</property>
-                        <property name="invisible_char">●</property>
-                        <property name="primary_icon_activatable">False</property>
-                        <property name="secondary_icon_activatable">False</property>
-                        <property name="primary_icon_sensitive">True</property>
-                        <property name="secondary_icon_sensitive">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
diff --git a/data/org.gnome.MUD.gresource.xml b/data/org.gnome.MUD.gresource.xml
index eaca15d..dc17ef1 100644
--- a/data/org.gnome.MUD.gresource.xml
+++ b/data/org.gnome.MUD.gresource.xml
@@ -5,4 +5,8 @@
     <file preprocess="xml-stripblanks">muds.ui</file>
     <file preprocess="xml-stripblanks">prefs.ui</file>
   </gresource>
+  <gresource prefix="/org/gnome/MUD/ui">
+    <file preprocess="xml-stripblanks" alias="mud-input-view.ui">../src/mud-input-view.ui</file>
+    <file>style.css</file>
+  </gresource>
 </gresources>
diff --git a/data/style.css b/data/style.css
new file mode 100644
index 0000000..1bc42b1
--- /dev/null
+++ b/data/style.css
@@ -0,0 +1,3 @@
+mud-input-view scrollbar.vertical slider {
+  min-height: 10px;
+}
diff --git a/meson.build b/meson.build
index 692b51e..d9063dc 100644
--- a/meson.build
+++ b/meson.build
@@ -25,7 +25,7 @@ localedir = join_paths(datadir, 'locale')
 schemadir = join_paths(datadir, 'glib-2.0', 'schemas')
 
 libgio_dep = dependency('gio-2.0', version: '>= 2.48')
-libgtk_dep = dependency('gtk+-3.0', version: '>= 3.10')
+libgtk_dep = dependency('gtk+-3.0', version: '>= 3.16')
 libvte_dep = dependency('vte-2.91', version: '>= 0.37')
 libpcre_dep = dependency('libpcre', version: '>= 6.0.0')
 libgst_dep = dependency('gstreamer-1.0', version: '>= 1.0', required: get_option('gstreamer'))
diff --git a/src/gnome-mud.c b/src/gnome-mud.c
index 40b1bc7..3d88587 100644
--- a/src/gnome-mud.c
+++ b/src/gnome-mud.c
@@ -1,7 +1,8 @@
 /* GNOME-Mud - A simple Mud Client
  * gnome-mud.c
- * Copyright (C) 1998-2005 Robin Ericsson <lobbin localhost nu>
- * Copyright (C) 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 1998-2005 Robin Ericsson <lobbin localhost nu>
+ * Copyright 2005-2009 Les Harris <lharris gnome org>
+ * Copyright 2019 Mart Raudsepp <leio gentoo org>
  *
  * 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
@@ -42,6 +43,7 @@ main (gint argc, char *argv[])
     DebugLogger *logger;
     GString *dir;
     GSettings *global_settings;
+    GtkCssProvider *css_provider;
 
     /* Initialize internationalization */
     bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
@@ -61,6 +63,14 @@ main (gint argc, char *argv[])
     gst_init(&argc, &argv);
 #endif
 
+    /* Load our style overrides */
+    css_provider = gtk_css_provider_new ();
+    gtk_css_provider_load_from_resource (css_provider, "/org/gnome/MUD/ui/style.css");
+    gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+                                               css_provider,
+                                               GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+    g_object_unref (css_provider);
+
     dir = g_string_new(NULL);
     g_string_printf(dir,
                     "%s%cgnome-mud%clogs",
diff --git a/src/meson.build b/src/meson.build
index a66983b..a5f512c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -21,6 +21,8 @@ gnome_mud_sources = [
   'mud-connection-view.h',
   'mud-connection.c',
   'mud-connection.h',
+  'mud-input-view.c',
+  'mud-input-view.h',
   'mud-line-buffer.c',
   'mud-line-buffer.h',
   'mud-log.c',
diff --git a/src/mud-input-view.c b/src/mud-input-view.c
new file mode 100644
index 0000000..ca97ee2
--- /dev/null
+++ b/src/mud-input-view.c
@@ -0,0 +1,157 @@
+/* mud-input-view.c
+ *
+ * Copyright 2019 Mart Raudsepp <leio gentoo org>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "mud-input-view.h"
+
+struct _MudInputView
+{
+  GtkStack     parent_instance;
+  GtkWidget   *scrolled_text_view;
+  GtkTextView *text_view;
+  GtkEntry    *password_entry;
+};
+
+G_DEFINE_TYPE (MudInputView, mud_input_view, GTK_TYPE_STACK)
+
+enum {
+  PROP_0,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+MudInputView *
+mud_input_view_new (void)
+{
+  return g_object_new (MUD_TYPE_INPUT_VIEW, NULL);
+}
+
+void
+mud_input_view_show_password (MudInputView *self)
+{
+  g_return_if_fail (MUD_IS_INPUT_VIEW (self));
+
+  gtk_stack_set_visible_child (GTK_STACK (self), GTK_WIDGET (self->password_entry));
+}
+
+void
+mud_input_view_hide_password (MudInputView *self)
+{
+  g_return_if_fail (MUD_IS_INPUT_VIEW (self));
+
+  gtk_stack_set_visible_child (GTK_STACK (self), GTK_WIDGET (self->scrolled_text_view));
+}
+
+GtkTextView *
+mud_input_view_get_text_view (MudInputView *self)
+{
+  /* TODO: Temporary accessor until more functionality gets moved to this class directly (the members 
shouldn't be accessible from outside) */
+  g_return_val_if_fail (MUD_IS_INPUT_VIEW (self), NULL);
+
+  return self->text_view;
+}
+
+GtkEntry *
+mud_input_view_get_password_entry (MudInputView *self)
+{
+  /* TODO: Temporary accessor until more functionality gets moved to this class directly (the members 
shouldn't be accessible from outside) */
+  g_return_val_if_fail (MUD_IS_INPUT_VIEW (self), NULL);
+
+  return self->password_entry;
+}
+
+static void
+mud_input_view_finalize (GObject *object)
+{
+  MudInputView *self = (MudInputView *)object;
+
+  G_OBJECT_CLASS (mud_input_view_parent_class)->finalize (object);
+}
+
+static void
+mud_input_view_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+  MudInputView *self = MUD_INPUT_VIEW (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+mud_input_view_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+  MudInputView *self = MUD_INPUT_VIEW (object);
+
+  switch (prop_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+mud_input_view_grab_focus (GtkWidget *widget)
+{
+  MudInputView *self = MUD_INPUT_VIEW (widget);
+
+  if (gtk_stack_get_visible_child (GTK_STACK (self)) == self->password_entry)
+    {
+      gtk_widget_grab_focus (self->password_entry);
+    }
+  else
+    {
+      gtk_widget_grab_focus (self->text_view);
+    }
+}
+
+static void
+mud_input_view_class_init (MudInputViewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = mud_input_view_finalize;
+  object_class->get_property = mud_input_view_get_property;
+  object_class->set_property = mud_input_view_set_property;
+  widget_class->grab_focus = mud_input_view_grab_focus;
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/MUD/ui/mud-input-view.ui");
+  gtk_widget_class_bind_template_child (widget_class, MudInputView, scrolled_text_view);
+  gtk_widget_class_bind_template_child (widget_class, MudInputView, text_view);
+  gtk_widget_class_bind_template_child (widget_class, MudInputView, password_entry);
+
+  gtk_widget_class_set_css_name (widget_class, "mud-input-view");
+}
+
+static void
+mud_input_view_init (MudInputView *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+  gtk_stack_set_visible_child (GTK_STACK (self), self->scrolled_text_view);
+}
diff --git a/src/mud-input-view.h b/src/mud-input-view.h
new file mode 100644
index 0000000..2be2431
--- /dev/null
+++ b/src/mud-input-view.h
@@ -0,0 +1,37 @@
+/* mud-input-view.h
+ *
+ * Copyright 2019 Mart Raudsepp <leio gentoo org>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define MUD_TYPE_INPUT_VIEW (mud_input_view_get_type())
+
+G_DECLARE_FINAL_TYPE (MudInputView, mud_input_view, MUD, INPUT_VIEW, GtkStack)
+
+MudInputView *mud_input_view_new                (void);
+void          mud_input_view_show_password      (MudInputView *self);
+void          mud_input_view_hide_password      (MudInputView *self);
+GtkTextView  *mud_input_view_get_text_view      (MudInputView *self);
+GtkEntry     *mud_input_view_get_password_entry (MudInputView *self);
+
+G_END_DECLS
diff --git a/src/mud-input-view.ui b/src/mud-input-view.ui
new file mode 100644
index 0000000..974c862
--- /dev/null
+++ b/src/mud-input-view.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="MudInputView" parent="GtkStack">
+    <property name="visible">true</property>
+    <property name="homogeneous">false</property>
+    <property name="transition-type">GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP</property>
+    <property name="interpolate-size">true</property>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolled_text_view">
+        <property name="visible">true</property>
+        <property name="max-content-height">200</property><!-- TODO: Make dynamic based on window size? -->
+        <property name="propagate-natural-height">true</property>
+        <child>
+          <object class="GtkTextView" id="text_view">
+            <property name="visible">true</property>
+            <property name="wrap-mode">GTK_WRAP_WORD_CHAR</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkEntry" id="password_entry">
+        <property name="visible">true</property>
+        <property name="visibility">false</property>
+        <property name="input-purpose">GTK_INPUT_PURPOSE_PASSWORD</property>
+      </object>
+    </child>
+  </template>
+</interface>
+
+
diff --git a/src/mud-window.c b/src/mud-window.c
index 2650d8e..f344d4d 100644
--- a/src/mud-window.c
+++ b/src/mud-window.c
@@ -32,6 +32,7 @@
 #include "gnome-mud.h"
 #include "gnome-mud-icons.h"
 #include "mud-connection-view.h"
+#include "mud-input-view.h"
 #include "mud-window-prefs.h"
 #include "mud-window.h"
 #include "mud-tray.h"
@@ -47,10 +48,8 @@ struct _MudWindowPrivate
 {
     GSList *mud_views_list;
 
-    GtkWidget *notebook;
-    GtkWidget *textview;
-    GtkWidget *textviewscroll;
-    GtkWidget *password_entry;
+    GtkWidget    *notebook;
+    MudInputView *mud_input_view;
 
     GtkWidget *startlog;
     GtkWidget *stoplog;
@@ -93,12 +92,11 @@ enum
 enum
 {
     RESIZED,
-    TOGGLEDOFF,
     LAST_SIGNAL
 };
 
 /* Signal Identifier Map */
-static guint mud_window_signal[LAST_SIGNAL] = { 0, 0 };
+static guint mud_window_signal[LAST_SIGNAL] = { 0, };
 
 /* Class Function Prototypes */
 static void mud_window_init       (MudWindow *self);
@@ -124,8 +122,6 @@ static gboolean mud_window_grab_entry_focus_cb(GtkWidget *widget,
 static void mud_window_disconnect_cb(GtkWidget *widget, MudWindow *self);
 static void mud_window_reconnect_cb(GtkWidget *widget, MudWindow *self);
 static void mud_window_closewindow_cb(GtkWidget *widget, MudWindow *self);
-static void mud_window_textview_buffer_changed(GtkTextBuffer *buffer, 
-                                               MudWindow *self);
 static gboolean mud_window_textview_keypress(GtkWidget *widget,
                                              GdkEventKey *event, 
                                              MudWindow *self);
@@ -156,7 +152,6 @@ static void mud_window_size_allocate_cb(GtkWidget *widget,
 /* Private Method Prototypes */
 static void mud_window_remove_connection_view(MudWindow *self, gint nr);
 static gint mud_window_textview_get_display_line_count(GtkTextView *textview);
-static void mud_window_textview_ensure_height(MudWindow *self, guint max_lines);
 static void mud_window_clear_profiles_menu(GtkWidget *widget, gpointer data);
 
 /* Class Functions */
@@ -206,18 +201,6 @@ mud_window_class_init (MudWindowClass *klass)
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE,
                      0);
-
-    mud_window_signal[TOGGLEDOFF] =
-        g_signal_new("toggled-off",
-                     G_TYPE_FROM_CLASS(object_class),
-                     G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
-                     0,
-                     NULL,
-                     NULL,
-                     g_cclosure_marshal_VOID__VOID,
-                     G_TYPE_NONE,
-                     0);
-
 }
 
 static void
@@ -231,6 +214,10 @@ mud_window_init (MudWindow *self)
     self->priv = MUD_WINDOW_GET_PRIVATE(self);
 
     /* start glading */
+    /* We use this composite widget in our UI file, so need to ensure it's registered */
+    /* TODO: Move this above gtk_widget_init_template call of our own, once we use that */
+    g_type_ensure (mud_input_view_get_type());
+
     builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");
 
     /* set public properties */
@@ -254,10 +241,8 @@ mud_window_init (MudWindow *self)
     self->priv->bufferdump = GTK_WIDGET(gtk_builder_get_object(builder, "menu_dump_buffer"));
     self->priv->mi_profiles = GTK_WIDGET(gtk_builder_get_object(builder, "mi_profiles_menu"));
     self->priv->notebook = GTK_WIDGET(gtk_builder_get_object(builder, "notebook"));
-    self->priv->textviewscroll = GTK_WIDGET(gtk_builder_get_object(builder, "text_view_scroll"));
-    self->priv->textview = GTK_WIDGET(gtk_builder_get_object(builder, "text_view"));
+    self->priv->mud_input_view = MUD_INPUT_VIEW(gtk_builder_get_object(builder, "mud_input_view"));
     self->priv->image = GTK_WIDGET(gtk_builder_get_object(builder, "image"));
-    self->priv->password_entry = GTK_WIDGET(gtk_builder_get_object(builder, "password_entry"));
 
     /* connect quit buttons */
     g_signal_connect(self->window,
@@ -351,49 +336,16 @@ mud_window_init (MudWindow *self)
                      G_CALLBACK(mud_window_size_allocate_cb),
                      self);
 
-    g_signal_connect(self->priv->textview,
+    g_signal_connect(mud_input_view_get_text_view(self->priv->mud_input_view),
                      "key_press_event",
                      G_CALLBACK(mud_window_textview_keypress),
                      self);
 
-    g_signal_connect(self->priv->password_entry,
+    g_signal_connect(mud_input_view_get_password_entry (self->priv->mud_input_view),
                      "key_press_event",
                      G_CALLBACK(mud_window_entry_keypress),
                      self);
 
-    g_signal_connect(
-            gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->priv->textview)),
-            "changed",
-            G_CALLBACK(mud_window_textview_buffer_changed),
-            self);
-
-    /* Setup TextView */
-    gtk_text_view_set_wrap_mode(
-            GTK_TEXT_VIEW(self->priv->textview), GTK_WRAP_WORD_CHAR);
-
-    /* Set the initial height of the input box equal to the height of one line */
-    gtk_text_buffer_get_start_iter(
-            gtk_text_view_get_buffer(
-                GTK_TEXT_VIEW(self->priv->textview)),
-                &iter);
-
-    gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(self->priv->textview),
-                                  &iter, &y,
-                                  &self->priv->textview_line_height);
-
-    gtk_widget_set_size_request(self->priv->textview, -1,
-                                self->priv->textview_line_height*1);
-    gtk_widget_set_size_request(
-            gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(self->priv->textviewscroll)),
-            -1, 1);
-
-    if (gtk_widget_get_visible(self->priv->textviewscroll))
-        gtk_widget_queue_resize(self->priv->textviewscroll);
-
-    gtk_window_get_size(GTK_WINDOW(self->window),
-                        &self->priv->width,
-                        &self->priv->height);
-
     gtk_widget_set_visible(GTK_WIDGET(self->window), TRUE);
 
     g_object_unref(builder);
@@ -521,10 +473,7 @@ mud_window_grab_entry_focus_cb(GtkWidget *widget,
 {
     MudWindow *self = MUD_WINDOW(user_data);
 
-    if(gtk_widget_get_visible(self->priv->textview))
-        gtk_widget_grab_focus(self->priv->textview);
-    else
-        gtk_widget_grab_focus(self->priv->password_entry);
+    gtk_widget_grab_focus(GTK_WIDGET (self->priv->mud_input_view));
 
     return TRUE;
 }
@@ -561,18 +510,12 @@ mud_window_closewindow_cb(GtkWidget *widget, MudWindow *self)
     mud_window_close_current_window(self);
 }
 
-static void
-mud_window_textview_buffer_changed(GtkTextBuffer *buffer, MudWindow *self)
-{
-    mud_window_textview_ensure_height(self, 5);
-}
-
 static gboolean
 mud_window_textview_keypress(GtkWidget *widget, GdkEventKey *event, MudWindow *self)
 {
     gchar *text;
     const gchar *history;
-    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self->priv->textview));
+    GtkTextBuffer *buffer = gtk_text_view_get_buffer (mud_input_view_get_text_view 
(self->priv->mud_input_view));
     GtkTextIter start, end;
     MudParseBase *base;
 
@@ -656,11 +599,12 @@ mud_window_entry_keypress(GtkWidget *widget,
     {
         if (self->priv->current_view)
         {
-            text = gtk_entry_get_text(GTK_ENTRY(self->priv->password_entry));
+            GtkEntry *password_entry = mud_input_view_get_password_entry (self->priv->mud_input_view);
+            text = gtk_entry_get_text(password_entry);
 
             mud_connection_view_send(self->priv->current_view, text);
 
-            gtk_entry_set_text(GTK_ENTRY(self->priv->password_entry), "");
+            gtk_entry_set_text(password_entry, "");
         }
 
         return TRUE;
@@ -723,10 +667,7 @@ mud_window_notebook_page_change(GtkNotebook *notebook, gpointer page, gint arg,
 
         mud_window_toggle_input_mode(self, self->priv->current_view);
 
-        if(gtk_widget_get_visible(self->priv->textview))
-            gtk_widget_grab_focus(self->priv->textview);
-        else
-            gtk_widget_grab_focus(self->priv->password_entry);
+        gtk_widget_grab_focus(self->priv->mud_input_view);
 
         g_object_get(self->priv->current_view,
                 "ui-vbox", &viewport,
@@ -855,10 +796,7 @@ mud_window_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer
         g_object_unref(buf);
     }
 
-    if(gtk_widget_get_visible(self->priv->textview))
-        gtk_widget_grab_focus(self->priv->textview);
-    else
-        gtk_widget_grab_focus(self->priv->password_entry);
+    gtk_widget_grab_focus (GTK_WIDGET (self->priv->mud_input_view));
 
     return FALSE;
 }
@@ -1048,16 +986,6 @@ mud_window_textview_get_display_line_count(GtkTextView *textview)
     return result;
 }
 
-static void
-mud_window_textview_ensure_height(MudWindow *self, guint max_lines)
-{
-    gint lines = mud_window_textview_get_display_line_count(GTK_TEXT_VIEW(self->priv->textview));
-    gtk_widget_set_size_request(self->priv->textview, -1,
-            self->priv->textview_line_height * MIN(lines, max_lines));
-    gtk_widget_queue_resize(gtk_widget_get_parent(self->priv->textview));
-}
-
-
 static void
 mud_window_clear_profiles_menu(GtkWidget *widget, gpointer data)
 {
@@ -1072,44 +1000,25 @@ mud_window_get_views(MudWindow *window)
 }
 
 void
-mud_window_toggle_input_mode(MudWindow *self,
-                             MudConnectionView *view)
+mud_window_toggle_input_mode (MudWindow         *self,
+                              MudConnectionView *view)
 {
-    gboolean local_echo;
-
-    g_return_if_fail(IS_MUD_WINDOW(self));
+  g_return_if_fail (IS_MUD_WINDOW (self));
 
-    /* Don't want to log a critical when a view unrefs */
-    if(!IS_MUD_CONNECTION_VIEW(view))
-        return;
+  /* Don't want to log a critical when a view unrefs */
+  if (!IS_MUD_CONNECTION_VIEW (view))
+    return;
 
-    if(g_direct_equal(self->priv->current_view, view))
+  if (g_direct_equal (self->priv->current_view, view))
     {
-        g_object_get(view, "local-echo", &local_echo, NULL);
-
-        if(local_echo)
-        {
-            if(gtk_widget_get_mapped(self->priv->password_entry))
-            {
-                gtk_widget_hide(self->priv->password_entry);
+      gboolean local_echo;
 
-                gtk_widget_show(self->priv->textviewscroll);
-                gtk_widget_show(self->priv->textview);
+      g_object_get (view, "local-echo", &local_echo, NULL);
 
-                gtk_widget_grab_focus(self->priv->textview);
-
-                g_signal_emit(self, mud_window_signal[TOGGLEDOFF], 0);
-            }
-        }
-        else
-        {
-            gtk_widget_show(self->priv->password_entry);
-
-            gtk_widget_hide(self->priv->textviewscroll);
-            gtk_widget_hide(self->priv->textview);
-
-            gtk_widget_grab_focus(self->priv->password_entry);
-        }
+      if (local_echo)
+        mud_input_view_hide_password (self->priv->mud_input_view);
+      else
+        mud_input_view_show_password (self->priv->mud_input_view);
     }
 }
 
@@ -1326,15 +1235,8 @@ mud_window_disconnected(MudWindow *self)
     gtk_widget_set_sensitive(self->priv->toolbar_disconnect, FALSE);
     gtk_widget_set_sensitive(self->priv->toolbar_reconnect, TRUE);
 
-    if(gtk_widget_get_visible(self->priv->password_entry))
-    {
-        gtk_widget_hide(self->priv->password_entry);
-
-        gtk_widget_show(self->priv->textviewscroll);
-        gtk_widget_show(self->priv->textview);
-
-        gtk_widget_grab_focus(self->priv->textview);
-    }
+    mud_input_view_hide_password (self->priv->mud_input_view);
+    gtk_widget_grab_focus(GTK_WIDGET(self->priv->mud_input_view));
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]