In case of unique completion use Tab to complete
This commit is contained in:
parent
961a3bb4c3
commit
1f25813ae8
@ -14,6 +14,7 @@
|
|||||||
#include "mooedit/mootextcompletion.h"
|
#include "mooedit/mootextcompletion.h"
|
||||||
#include "mooutils/moomarshals.h"
|
#include "mooutils/moomarshals.h"
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <gdk/gdkkeysyms.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +48,6 @@ static void moo_text_completion_populate (MooTextCompletion *cmp
|
|||||||
GtkTextIter *cursor,
|
GtkTextIter *cursor,
|
||||||
const char *text);
|
const char *text);
|
||||||
static void moo_text_completion_complete (MooTextCompletion *cmpl,
|
static void moo_text_completion_complete (MooTextCompletion *cmpl,
|
||||||
GtkTreeModel *model,
|
|
||||||
GtkTreeIter *iter);
|
GtkTreeIter *iter);
|
||||||
static char *moo_text_completion_get_text (MooTextCompletion *cmpl,
|
static char *moo_text_completion_get_text (MooTextCompletion *cmpl,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
@ -73,6 +73,8 @@ static void cell_data_func (GtkTreeViewColumn *col
|
|||||||
static void on_popup_activate (MooTextCompletion *cmpl,
|
static void on_popup_activate (MooTextCompletion *cmpl,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter);
|
GtkTreeIter *iter);
|
||||||
|
static gboolean popup_key_press (MooTextCompletion *cmpl,
|
||||||
|
GdkEventKey *event);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FINISH,
|
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 = GINT_TO_POINTER (0);
|
||||||
cmpl->priv->text_func_data_notify = NULL;
|
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 ();
|
cell = gtk_cell_renderer_text_new ();
|
||||||
gtk_tree_view_column_pack_start (cmpl->priv->popup->column, cell, TRUE);
|
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_CALLBACK (moo_text_completion_update), cmpl);
|
||||||
g_signal_connect_swapped (cmpl->priv->popup, "hide",
|
g_signal_connect_swapped (cmpl->priv->popup, "hide",
|
||||||
G_CALLBACK (moo_text_completion_hide), cmpl);
|
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)
|
if (!automatic)
|
||||||
{
|
{
|
||||||
moo_text_completion_complete (cmpl, cmpl->priv->model, &iter);
|
moo_text_completion_complete (cmpl, &iter);
|
||||||
goto finish;
|
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);
|
prefix = moo_text_completion_get_text (cmpl, cmpl->priv->model, &iter);
|
||||||
|
|
||||||
if (prefix && !strcmp (prefix, text))
|
if (prefix)
|
||||||
goto finish;
|
{
|
||||||
|
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)
|
else if (!automatic)
|
||||||
{
|
{
|
||||||
@ -260,11 +270,10 @@ finish:
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
moo_text_completion_complete (MooTextCompletion *cmpl,
|
moo_text_completion_complete (MooTextCompletion *cmpl,
|
||||||
GtkTreeModel *model,
|
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete != NULL);
|
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);
|
moo_text_completion_finish (cmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,10 +434,31 @@ moo_text_completion_hide (MooTextCompletion *cmpl)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
on_popup_activate (MooTextCompletion *cmpl,
|
on_popup_activate (MooTextCompletion *cmpl,
|
||||||
GtkTreeModel *model,
|
G_GNUC_UNUSED GtkTreeModel *model,
|
||||||
GtkTreeIter *iter)
|
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;
|
int max_len;
|
||||||
guint hide_on_activate : 1;
|
guint hide_on_activate : 1;
|
||||||
guint activate_on_tab : 1;
|
|
||||||
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkScrolledWindow *scrolled_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_show_real (MooTextPopup *popup);
|
||||||
static void moo_text_popup_hide_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 void moo_text_popup_ensure_popup (MooTextPopup *popup);
|
||||||
static gboolean moo_text_popup_empty (MooTextPopup *popup);
|
static gboolean moo_text_popup_empty (MooTextPopup *popup);
|
||||||
static void moo_text_popup_resize (MooTextPopup *popup);
|
static void moo_text_popup_resize (MooTextPopup *popup);
|
||||||
@ -71,7 +73,8 @@ enum {
|
|||||||
HIDE,
|
HIDE,
|
||||||
ACTIVATE,
|
ACTIVATE,
|
||||||
TEXT_CHANGED,
|
TEXT_CHANGED,
|
||||||
NUM_SIGNALS
|
KEY_PRESS_EVENT,
|
||||||
|
N_SIGNALS
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -80,11 +83,10 @@ enum {
|
|||||||
PROP_MAX_LEN,
|
PROP_MAX_LEN,
|
||||||
PROP_POSITION,
|
PROP_POSITION,
|
||||||
PROP_DOC,
|
PROP_DOC,
|
||||||
PROP_MODEL,
|
PROP_MODEL
|
||||||
PROP_ACTIVATE_ON_TAB
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static guint signals[NUM_SIGNALS];
|
static guint signals[N_SIGNALS];
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -119,6 +121,7 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||||||
|
|
||||||
klass->show = moo_text_popup_show_real;
|
klass->show = moo_text_popup_show_real;
|
||||||
klass->hide = moo_text_popup_hide_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));
|
g_type_class_add_private (klass, sizeof (MooTextPopupPrivate));
|
||||||
|
|
||||||
@ -130,14 +133,6 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||||||
TRUE,
|
TRUE,
|
||||||
G_PARAM_READWRITE));
|
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,
|
g_object_class_install_property (gobject_class,
|
||||||
PROP_MAX_LEN,
|
PROP_MAX_LEN,
|
||||||
g_param_spec_int ("max-len",
|
g_param_spec_int ("max-len",
|
||||||
@ -207,6 +202,16 @@ moo_text_popup_class_init (MooTextPopupClass *klass)
|
|||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
_moo_marshal_VOID__VOID,
|
_moo_marshal_VOID__VOID,
|
||||||
G_TYPE_NONE, 0);
|
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
|
static gboolean
|
||||||
popup_key_press (MooTextPopup *popup,
|
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)
|
switch (event->keyval)
|
||||||
{
|
{
|
||||||
case GDK_Tab:
|
case GDK_Tab:
|
||||||
case GDK_KP_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_Down:
|
||||||
case GDK_Up:
|
case GDK_Up:
|
||||||
case GDK_KP_Down:
|
case GDK_KP_Down:
|
||||||
@ -990,11 +998,6 @@ moo_text_popup_set_property (GObject *object,
|
|||||||
g_object_notify (object, "hide-on-activate");
|
g_object_notify (object, "hide-on-activate");
|
||||||
break;
|
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:
|
case PROP_MAX_LEN:
|
||||||
popup->priv->max_len = g_value_get_int (value);
|
popup->priv->max_len = g_value_get_int (value);
|
||||||
g_object_notify (object, "max-len");
|
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);
|
g_value_set_boolean (value, popup->priv->hide_on_activate != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_ACTIVATE_ON_TAB:
|
|
||||||
g_value_set_boolean (value, popup->priv->activate_on_tab != 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_MAX_LEN:
|
case PROP_MAX_LEN:
|
||||||
g_value_set_int (value, popup->priv->max_len);
|
g_value_set_int (value, popup->priv->max_len);
|
||||||
break;
|
break;
|
||||||
|
@ -43,13 +43,16 @@ struct _MooTextPopupClass
|
|||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
|
|
||||||
void (*show) (MooTextPopup *popup);
|
void (*show) (MooTextPopup *popup);
|
||||||
void (*hide) (MooTextPopup *popup);
|
void (*hide) (MooTextPopup *popup);
|
||||||
|
|
||||||
void (*activate) (MooTextPopup *popup,
|
void (*activate) (MooTextPopup *popup,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter);
|
GtkTreeIter *iter);
|
||||||
void (*text_changed) (MooTextPopup *popup);
|
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-misc.h"
|
||||||
#include "mooutils/mooutils-fs.h"
|
#include "mooutils/mooutils-fs.h"
|
||||||
#include "mooutils/moopython.h"
|
#include "mooutils/moopython.h"
|
||||||
|
#include <gdk/gdkkeysyms.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -612,9 +613,8 @@ _completion_complete (CmplPlugin *plugin,
|
|||||||
|
|
||||||
if (cmpl)
|
if (cmpl)
|
||||||
{
|
{
|
||||||
g_print ("complete complete\n");
|
|
||||||
moo_text_completion_set_doc (cmpl, GTK_TEXT_VIEW (doc));
|
|
||||||
plugin->working = TRUE;
|
plugin->working = TRUE;
|
||||||
|
moo_text_completion_set_doc (cmpl, GTK_TEXT_VIEW (doc));
|
||||||
g_signal_connect (cmpl, "finish", G_CALLBACK (completion_finished), plugin);
|
g_signal_connect (cmpl, "finish", G_CALLBACK (completion_finished), plugin);
|
||||||
moo_text_completion_try_complete (cmpl, automatic);
|
moo_text_completion_try_complete (cmpl, automatic);
|
||||||
}
|
}
|
||||||
@ -634,28 +634,44 @@ popup_timeout (CmplPlugin *plugin)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
install_popup_timeout (CmplPlugin *plugin)
|
remove_popup_timeout (CmplPlugin *plugin)
|
||||||
{
|
{
|
||||||
if (!plugin->popup_timeout)
|
if (plugin->popup_timeout)
|
||||||
plugin->popup_timeout =
|
g_source_remove (plugin->popup_timeout);
|
||||||
g_timeout_add (plugin->popup_interval, (GSourceFunc) popup_timeout, plugin);
|
plugin->popup_timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
reinstall_popup_timeout (CmplPlugin *plugin)
|
reinstall_popup_timeout (CmplPlugin *plugin)
|
||||||
{
|
{
|
||||||
if (plugin->popup_timeout)
|
remove_popup_timeout (plugin);
|
||||||
g_source_remove (plugin->popup_timeout);
|
|
||||||
plugin->popup_timeout = 0;
|
|
||||||
|
|
||||||
if (!plugin->working)
|
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
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,10 +688,7 @@ static void
|
|||||||
disconnect_doc (CmplPlugin *plugin,
|
disconnect_doc (CmplPlugin *plugin,
|
||||||
MooEdit *doc)
|
MooEdit *doc)
|
||||||
{
|
{
|
||||||
if (plugin->popup_timeout)
|
remove_popup_timeout (plugin);
|
||||||
g_source_remove (plugin->popup_timeout);
|
|
||||||
plugin->popup_timeout = 0;
|
|
||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (doc, (gpointer) doc_key_release, plugin);
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) doc_key_release, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user