In case of unique completion use Tab to complete
parent
961a3bb4c3
commit
1f25813ae8
|
@ -14,6 +14,7 @@
|
|||
#include "mooedit/mootextcompletion.h"
|
||||
#include "mooutils/moomarshals.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
@ -47,7 +48,6 @@ static void moo_text_completion_populate (MooTextCompletion *cmp
|
|||
GtkTextIter *cursor,
|
||||
const char *text);
|
||||
static void moo_text_completion_complete (MooTextCompletion *cmpl,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter);
|
||||
static char *moo_text_completion_get_text (MooTextCompletion *cmpl,
|
||||
GtkTreeModel *model,
|
||||
|
@ -73,6 +73,8 @@ static void cell_data_func (GtkTreeViewColumn *col
|
|||
static void on_popup_activate (MooTextCompletion *cmpl,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter);
|
||||
static gboolean popup_key_press (MooTextCompletion *cmpl,
|
||||
GdkEventKey *event);
|
||||
|
||||
enum {
|
||||
FINISH,
|
||||
|
@ -120,7 +122,7 @@ moo_text_completion_init (MooTextCompletion *cmpl)
|
|||
cmpl->priv->text_func_data = GINT_TO_POINTER (0);
|
||||
cmpl->priv->text_func_data_notify = NULL;
|
||||
|
||||
cmpl->priv->popup = g_object_new (MOO_TYPE_TEXT_POPUP, "activate-on-tab", TRUE, NULL);
|
||||
cmpl->priv->popup = g_object_new (MOO_TYPE_TEXT_POPUP, NULL);
|
||||
|
||||
cell = gtk_cell_renderer_text_new ();
|
||||
gtk_tree_view_column_pack_start (cmpl->priv->popup->column, cell, TRUE);
|
||||
|
@ -135,6 +137,8 @@ moo_text_completion_init (MooTextCompletion *cmpl)
|
|||
G_CALLBACK (moo_text_completion_update), cmpl);
|
||||
g_signal_connect_swapped (cmpl->priv->popup, "hide",
|
||||
G_CALLBACK (moo_text_completion_hide), cmpl);
|
||||
g_signal_connect_swapped (cmpl->priv->popup, "key-press-event",
|
||||
G_CALLBACK (popup_key_press), cmpl);
|
||||
}
|
||||
|
||||
|
||||
|
@ -216,16 +220,22 @@ moo_text_completion_try_complete_real (MooTextCompletion *cmpl,
|
|||
{
|
||||
if (!automatic)
|
||||
{
|
||||
moo_text_completion_complete (cmpl, cmpl->priv->model, &iter);
|
||||
moo_text_completion_complete (cmpl, &iter);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
moo_text_completion_get_region (cmpl, &start, &end);
|
||||
text = gtk_text_iter_get_slice (&start, &end);
|
||||
prefix = moo_text_completion_get_text (cmpl, cmpl->priv->model, &iter);
|
||||
|
||||
if (prefix && !strcmp (prefix, text))
|
||||
goto finish;
|
||||
if (prefix)
|
||||
{
|
||||
moo_text_completion_get_region (cmpl, &start, NULL);
|
||||
end = start;
|
||||
gtk_text_iter_forward_chars (&end, g_utf8_strlen (prefix, -1));
|
||||
text = gtk_text_iter_get_slice (&start, &end);
|
||||
|
||||
if (!strcmp (prefix, text))
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
else if (!automatic)
|
||||
{
|
||||
|
@ -260,11 +270,10 @@ finish:
|
|||
|
||||
static void
|
||||
moo_text_completion_complete (MooTextCompletion *cmpl,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete != NULL);
|
||||
MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete (cmpl, model, iter);
|
||||
MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete (cmpl, cmpl->priv->model, iter);
|
||||
moo_text_completion_finish (cmpl);
|
||||
}
|
||||
|
||||
|
@ -425,10 +434,31 @@ moo_text_completion_hide (MooTextCompletion *cmpl)
|
|||
|
||||
static void
|
||||
on_popup_activate (MooTextCompletion *cmpl,
|
||||
GtkTreeModel *model,
|
||||
G_GNUC_UNUSED GtkTreeModel *model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
moo_text_completion_complete (cmpl, model, iter);
|
||||
moo_text_completion_complete (cmpl, iter);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
popup_key_press (MooTextCompletion *cmpl,
|
||||
GdkEventKey *event)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_Tab:
|
||||
if (moo_text_completion_unique (cmpl, &iter))
|
||||
{
|
||||
moo_text_completion_complete (cmpl, &iter);
|
||||
return TRUE;
|
||||
}
|
||||
/* fall through */
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ struct _MooTextPopupPrivate {
|
|||
|
||||
int max_len;
|
||||
guint hide_on_activate : 1;
|
||||
guint activate_on_tab : 1;
|
||||
|
||||
GtkWidget *window;
|
||||
GtkScrolledWindow *scrolled_window;
|
||||
|
@ -55,6 +54,9 @@ static void moo_text_popup_dispose (GObject *object);
|
|||
static void moo_text_popup_show_real (MooTextPopup *popup);
|
||||
static void moo_text_popup_hide_real (MooTextPopup *popup);
|
||||
|
||||
static gboolean moo_text_popup_key_press (MooTextPopup *popup,
|
||||
GdkEventKey *event);
|
||||
|
||||
static void moo_text_popup_ensure_popup (MooTextPopup *popup);
|
||||
static gboolean moo_text_popup_empty (MooTextPopup *popup);
|
||||
static void moo_text_popup_resize (MooTextPopup *popup);
|
||||
|
@ -71,7 +73,8 @@ enum {
|
|||
HIDE,
|
||||
ACTIVATE,
|
||||
TEXT_CHANGED,
|
||||
NUM_SIGNALS
|
||||
KEY_PRESS_EVENT,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -80,11 +83,10 @@ enum {
|
|||
PROP_MAX_LEN,
|
||||
PROP_POSITION,
|
||||
PROP_DOC,
|
||||
PROP_MODEL,
|
||||
PROP_ACTIVATE_ON_TAB
|
||||
PROP_MODEL
|
||||
};
|
||||
|
||||
static guint signals[NUM_SIGNALS];
|
||||
static guint signals[N_SIGNALS];
|
||||
|
||||
|
||||
static void
|
||||
|
@ -119,6 +121,7 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||
|
||||
klass->show = moo_text_popup_show_real;
|
||||
klass->hide = moo_text_popup_hide_real;
|
||||
klass->key_press_event = moo_text_popup_key_press;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (MooTextPopupPrivate));
|
||||
|
||||
|
@ -130,14 +133,6 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||
TRUE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ACTIVATE_ON_TAB,
|
||||
g_param_spec_boolean ("activate-on-tab",
|
||||
"activate-on-tab",
|
||||
"activate-on-tab",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_MAX_LEN,
|
||||
g_param_spec_int ("max-len",
|
||||
|
@ -207,6 +202,16 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||
NULL, NULL,
|
||||
_moo_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
signals[KEY_PRESS_EVENT] =
|
||||
g_signal_new ("key-press-event",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (MooTextPopupClass, key_press_event),
|
||||
g_signal_accumulator_true_handled, NULL,
|
||||
_moo_marshal_BOOLEAN__BOXED,
|
||||
G_TYPE_BOOLEAN, 1,
|
||||
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -749,18 +754,21 @@ popup_move_selection (MooTextPopup *popup,
|
|||
|
||||
static gboolean
|
||||
popup_key_press (MooTextPopup *popup,
|
||||
GdkEventKey *event)
|
||||
GdkEventKey *event)
|
||||
{
|
||||
gboolean retval;
|
||||
g_signal_emit (popup, signals[KEY_PRESS_EVENT], 0, event, &retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
moo_text_popup_key_press (MooTextPopup *popup,
|
||||
GdkEventKey *event)
|
||||
{
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_Tab:
|
||||
case GDK_KP_Tab:
|
||||
if (popup->priv->activate_on_tab)
|
||||
{
|
||||
moo_text_popup_activate (popup);
|
||||
return TRUE;
|
||||
}
|
||||
/* fall through */
|
||||
case GDK_Down:
|
||||
case GDK_Up:
|
||||
case GDK_KP_Down:
|
||||
|
@ -990,11 +998,6 @@ moo_text_popup_set_property (GObject *object,
|
|||
g_object_notify (object, "hide-on-activate");
|
||||
break;
|
||||
|
||||
case PROP_ACTIVATE_ON_TAB:
|
||||
popup->priv->activate_on_tab = g_value_get_boolean (value) != 0;
|
||||
g_object_notify (object, "activate-on-tab");
|
||||
break;
|
||||
|
||||
case PROP_MAX_LEN:
|
||||
popup->priv->max_len = g_value_get_int (value);
|
||||
g_object_notify (object, "max-len");
|
||||
|
@ -1033,10 +1036,6 @@ moo_text_popup_get_property (GObject *object,
|
|||
g_value_set_boolean (value, popup->priv->hide_on_activate != 0);
|
||||
break;
|
||||
|
||||
case PROP_ACTIVATE_ON_TAB:
|
||||
g_value_set_boolean (value, popup->priv->activate_on_tab != 0);
|
||||
break;
|
||||
|
||||
case PROP_MAX_LEN:
|
||||
g_value_set_int (value, popup->priv->max_len);
|
||||
break;
|
||||
|
|
|
@ -43,13 +43,16 @@ struct _MooTextPopupClass
|
|||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*show) (MooTextPopup *popup);
|
||||
void (*hide) (MooTextPopup *popup);
|
||||
void (*show) (MooTextPopup *popup);
|
||||
void (*hide) (MooTextPopup *popup);
|
||||
|
||||
void (*activate) (MooTextPopup *popup,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter);
|
||||
void (*text_changed) (MooTextPopup *popup);
|
||||
void (*activate) (MooTextPopup *popup,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter);
|
||||
void (*text_changed) (MooTextPopup *popup);
|
||||
|
||||
gboolean (*key_press_event) (MooTextPopup *popup,
|
||||
GdkEventKey *event);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/moopython.h"
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
@ -612,9 +613,8 @@ _completion_complete (CmplPlugin *plugin,
|
|||
|
||||
if (cmpl)
|
||||
{
|
||||
g_print ("complete complete\n");
|
||||
moo_text_completion_set_doc (cmpl, GTK_TEXT_VIEW (doc));
|
||||
plugin->working = TRUE;
|
||||
moo_text_completion_set_doc (cmpl, GTK_TEXT_VIEW (doc));
|
||||
g_signal_connect (cmpl, "finish", G_CALLBACK (completion_finished), plugin);
|
||||
moo_text_completion_try_complete (cmpl, automatic);
|
||||
}
|
||||
|
@ -634,28 +634,44 @@ popup_timeout (CmplPlugin *plugin)
|
|||
|
||||
|
||||
static void
|
||||
install_popup_timeout (CmplPlugin *plugin)
|
||||
remove_popup_timeout (CmplPlugin *plugin)
|
||||
{
|
||||
if (!plugin->popup_timeout)
|
||||
plugin->popup_timeout =
|
||||
g_timeout_add (plugin->popup_interval, (GSourceFunc) popup_timeout, plugin);
|
||||
if (plugin->popup_timeout)
|
||||
g_source_remove (plugin->popup_timeout);
|
||||
plugin->popup_timeout = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
reinstall_popup_timeout (CmplPlugin *plugin)
|
||||
{
|
||||
if (plugin->popup_timeout)
|
||||
g_source_remove (plugin->popup_timeout);
|
||||
plugin->popup_timeout = 0;
|
||||
remove_popup_timeout (plugin);
|
||||
|
||||
if (!plugin->working)
|
||||
install_popup_timeout (plugin);
|
||||
{
|
||||
if (!plugin->popup_timeout)
|
||||
plugin->popup_timeout =
|
||||
g_timeout_add (plugin->popup_interval, (GSourceFunc) popup_timeout, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
doc_key_release (CmplPlugin *plugin)
|
||||
doc_key_release (CmplPlugin *plugin,
|
||||
GdkEventKey *event)
|
||||
{
|
||||
reinstall_popup_timeout (plugin);
|
||||
gboolean install = TRUE;
|
||||
|
||||
switch (event->keyval)
|
||||
{
|
||||
case GDK_Escape:
|
||||
install = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (install)
|
||||
reinstall_popup_timeout (plugin);
|
||||
else
|
||||
remove_popup_timeout (plugin);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -672,10 +688,7 @@ static void
|
|||
disconnect_doc (CmplPlugin *plugin,
|
||||
MooEdit *doc)
|
||||
{
|
||||
if (plugin->popup_timeout)
|
||||
g_source_remove (plugin->popup_timeout);
|
||||
plugin->popup_timeout = 0;
|
||||
|
||||
remove_popup_timeout (plugin);
|
||||
g_signal_handlers_disconnect_by_func (doc, (gpointer) doc_key_release, plugin);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue