gtksourceview r2278 - in branches/gtksourcecompletion: gtksourceview tests
- From: jessevdk svn gnome org
- To: svn-commits-list gnome org
- Subject: gtksourceview r2278 - in branches/gtksourcecompletion: gtksourceview tests
- Date: Mon, 13 Apr 2009 20:16:52 +0000 (UTC)
Author: jessevdk
Date: Mon Apr 13 20:16:52 2009
New Revision: 2278
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=2278&view=rev
Log:
Fixed filtering and cycling (now keeps very fast counters)
Modified:
branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c
branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.h
branches/gtksourcecompletion/tests/completion-simple.c
Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c (original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletion.c Mon Apr 13 20:16:52 2009
@@ -337,7 +337,7 @@
/* Check if there are any proposals left */
if (finish_if_empty &&
- gtk_source_completion_model_is_empty (completion->priv->model_proposals))
+ gtk_source_completion_model_is_empty (completion->priv->model_proposals, FALSE))
{
gtk_source_completion_finish (completion);
}
@@ -348,41 +348,78 @@
static gboolean
select_provider (GtkSourceCompletion *completion,
ListSelector advance,
- ListSelector c1,
- ListSelector c2)
+ ListSelector cycle_first,
+ ListSelector cycle_last)
{
- GList *i1;
- GList *i2;
- GtkSourceCompletionProvider *p1;
- GtkSourceCompletionProvider *p2;
-
+ GList *first;
+ GList *last;
+ GList *orig;
+ GList *current;
+ GtkSourceCompletionProvider *provider;
+
/* If there is only one provider, then there is no other selection */
if (completion->priv->active_providers->next == NULL)
{
return FALSE;
}
+
+ if (completion->priv->filter_provider != NULL)
+ {
+ orig = g_list_find (completion->priv->active_providers,
+ completion->priv->filter_provider);
+ }
+ else
+ {
+ orig = NULL;
+ }
- i1 = c1 (completion->priv->active_providers);
- p1 = GTK_SOURCE_COMPLETION_PROVIDER (i1->data);
+ first = cycle_first (completion->priv->active_providers);
+ last = cycle_last (completion->priv->active_providers);
+ current = orig;
- i2 = c2 (completion->priv->active_providers);
- p2 = GTK_SOURCE_COMPLETION_PROVIDER (i2->data);
+ do
+ {
+ if (current == NULL)
+ {
+ current = first;
+ }
+ else if (current == last)
+ {
+ current = NULL;
+ }
+ else
+ {
+ current = advance (current);
+ }
+
+ if (current != NULL)
+ {
+ provider = GTK_SOURCE_COMPLETION_PROVIDER (current->data);
- if (completion->priv->filter_provider == NULL)
+ if (gtk_source_completion_model_n_proposals (completion->priv->model_proposals,
+ provider) != 0)
+ {
+ break;
+ }
+ }
+ else if (!gtk_source_completion_model_is_empty (completion->priv->model_proposals, TRUE))
+ {
+ break;
+ }
+ } while (orig != current);
+
+ if (orig == current)
{
- completion->priv->filter_provider = p1;
+ return FALSE;
}
- else if (completion->priv->filter_provider == p2)
+
+ if (current != NULL)
{
- completion->priv->filter_provider = NULL;
+ completion->priv->filter_provider = current->data;
}
else
{
- i1 = advance (g_list_find (completion->priv->active_providers,
- completion->priv->filter_provider));
- p1 = GTK_SOURCE_COMPLETION_PROVIDER (i1->data);
-
- completion->priv->filter_provider = p1;
+ completion->priv->filter_provider = NULL;
}
update_selection_label (completion);
@@ -445,29 +482,44 @@
gtk_window_move (GTK_WINDOW (completion->priv->info_window), x, y);
}
-static gboolean
+static GtkSourceCompletionModelFilterFlag
proposals_filter_func (GtkSourceCompletionModel *model,
GtkSourceCompletionProvider *provider,
GtkSourceCompletionProposal *proposal,
GtkSourceCompletion *completion)
{
- gboolean ret;
+ GtkSourceCompletionModelFilterFlag ret = GTK_SOURCE_COMPLETION_MODEL_NONE;
+ gboolean visible;
+ gboolean count;
/* Filter on provider */
- if (completion->priv->filter_provider != NULL &&
- completion->priv->filter_provider != provider)
+ if (completion->priv->filter_provider != NULL && completion->priv->filter_provider != provider)
{
- ret = FALSE;
+ visible = FALSE;
+ count = TRUE;
}
else if (completion->priv->filter_criteria == NULL)
{
- return TRUE;
+ visible = TRUE;
+ count = FALSE;
}
else
{
- ret = gtk_source_completion_provider_filter_proposal (provider,
- proposal,
- completion->priv->filter_criteria);
+ visible = gtk_source_completion_provider_filter_proposal (provider,
+ proposal,
+ completion->priv->filter_criteria);
+
+ count = FALSE;
+ }
+
+ if (!visible)
+ {
+ ret |= GTK_SOURCE_COMPLETION_MODEL_FILTERED;
+
+ if (count)
+ {
+ ret |= GTK_SOURCE_COMPLETION_MODEL_COUNT;
+ }
}
return ret;
@@ -1510,7 +1562,7 @@
g_list_reverse (completion->priv->active_providers);
/* Check if there are any completions */
- if (gtk_source_completion_model_is_empty (completion->priv->model_proposals))
+ if (gtk_source_completion_model_is_empty (completion->priv->model_proposals, FALSE))
{
gtk_source_completion_finish (completion);
return FALSE;
Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c (original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.c Mon Apr 13 20:16:52 2009
@@ -7,7 +7,7 @@
GtkSourceCompletionProvider *provider;
GtkSourceCompletionProposal *proposal;
- gboolean filtered;
+ GtkSourceCompletionModelFilterFlag filtered;
} ProposalNode;
struct _GtkSourceCompletionModelPrivate
@@ -335,6 +335,12 @@
}
static void
+tree_model_row_deleted (GtkTreeModel *tree_model,
+ GtkTreePath *path)
+{
+}
+
+static void
tree_model_iface_init (gpointer g_iface,
gpointer iface_data)
{
@@ -352,7 +358,9 @@
iface->iter_n_children = tree_model_iter_n_children;
iface->iter_nth_child = tree_model_iter_nth_child;
iface->iter_parent = tree_model_iter_parent;
+
iface->row_inserted = tree_model_row_inserted;
+ iface->row_deleted = tree_model_row_deleted;
}
static void
@@ -398,11 +406,22 @@
}
static void
-num_inc (GtkSourceCompletionModel *model,
- GtkSourceCompletionProvider *provider)
+num_inc (GtkSourceCompletionModel *model,
+ GtkSourceCompletionProvider *provider,
+ gboolean inc_local,
+ gboolean inc_global)
{
guint *num;
- ++model->priv->num;
+
+ if (inc_global)
+ {
+ ++model->priv->num;
+ }
+
+ if (!inc_local)
+ {
+ return;
+ }
num = g_hash_table_lookup (model->priv->num_per_provider, provider);
@@ -421,12 +440,22 @@
}
static void
-num_dec (GtkSourceCompletionModel *model,
- GtkSourceCompletionProvider *provider)
+num_dec (GtkSourceCompletionModel *model,
+ GtkSourceCompletionProvider *provider,
+ gboolean dec_local,
+ gboolean dec_global)
{
guint *num;
+
+ if (dec_global)
+ {
+ --model->priv->num;
+ }
- --model->priv->num;
+ if (!dec_local)
+ {
+ return;
+ }
num = g_hash_table_lookup (model->priv->num_per_provider, provider);
@@ -436,18 +465,18 @@
}
}
-static gboolean
+static GtkSourceCompletionModelFilterFlag
node_update_filter_state (GtkSourceCompletionModel *model,
ProposalNode *node)
{
- gboolean ret;
+ GtkSourceCompletionModelFilterFlag ret;
ret = node->filtered;
- node->filtered = !model->priv->filter (model,
- node->provider,
- node->proposal,
- model->priv->filter_data);
+ node->filtered = model->priv->filter (model,
+ node->provider,
+ node->proposal,
+ model->priv->filter_data);
return ret;
}
@@ -467,7 +496,7 @@
{
ProposalNode *node;
GtkTreePath *path;
- gboolean filtered;
+ GtkSourceCompletionModelFilterFlag filtered;
GtkSourceCompletionProvider *provider;
path = path_from_list (model, item);
@@ -485,9 +514,13 @@
model->priv->store = g_list_remove_link (model->priv->store, item);
+ num_dec (model,
+ provider,
+ !filtered || (filtered & GTK_SOURCE_COMPLETION_MODEL_COUNT),
+ !filtered);
+
if (!filtered)
{
- num_dec (model, provider);
gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
}
@@ -544,16 +577,19 @@
model->priv->last = item;
iter->user_data = item;
+ num_inc (model,
+ node->provider,
+ !node->filtered || (node->filtered & GTK_SOURCE_COMPLETION_MODEL_COUNT),
+ !node->filtered);
+
if (!node->filtered)
{
path = path_from_list (model, item);
- num_inc (model, node->provider);
-
gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, iter);
gtk_tree_path_free (path);
}
-
+
return TRUE;
}
@@ -575,7 +611,7 @@
GtkTreePath *path;
ProposalNode *node;
GList *list;
- gboolean filtered;
+ GtkSourceCompletionModelFilterFlag filtered;
g_return_if_fail (GTK_IS_SOURCE_COMPLETION_MODEL (model));
@@ -596,9 +632,13 @@
model->priv->last = NULL;
}
+ num_dec (model,
+ node->provider,
+ !filtered || (filtered & GTK_SOURCE_COMPLETION_MODEL_COUNT),
+ !filtered);
+
if (!filtered)
{
- num_dec (model, node->provider);
gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
}
}
@@ -613,7 +653,7 @@
gtk_source_completion_model_refilter (GtkSourceCompletionModel *model)
{
GList *item;
- gboolean filtered;
+ GtkSourceCompletionModelFilterFlag filtered;
ProposalNode *node;
GtkTreePath *path;
GtkTreeIter iter;
@@ -629,7 +669,7 @@
node = (ProposalNode *)item->data;
filtered = node_update_filter_state (model, node);
- if (filtered == node->filtered)
+ if ((filtered != 0) == (node->filtered != 0))
{
/* Keep the same, so increase path */
if (!filtered)
@@ -640,7 +680,11 @@
else if (filtered)
{
/* Was filtered, but not any more, so insert it */
- num_inc (model, node->provider);
+ num_inc (model,
+ node->provider,
+ !(filtered & GTK_SOURCE_COMPLETION_MODEL_COUNT),
+ TRUE);
+
gtk_tree_model_row_inserted (GTK_TREE_MODEL (model),
path,
&iter);
@@ -649,7 +693,11 @@
else
{
/* Was not filtered, but is now, so remove it */
- num_dec (model, node->provider);
+ num_dec (model,
+ node->provider,
+ !(node->filtered & GTK_SOURCE_COMPLETION_MODEL_COUNT),
+ TRUE);
+
gtk_tree_model_row_deleted (GTK_TREE_MODEL (model),
path);
}
@@ -659,11 +707,20 @@
}
gboolean
-gtk_source_completion_model_is_empty (GtkSourceCompletionModel *model)
+gtk_source_completion_model_is_empty (GtkSourceCompletionModel *model,
+ gboolean invisible)
{
g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_MODEL (model), FALSE);
- return model->priv->num == 0;
+ if (invisible)
+ {
+ return model->priv->num == 0;
+ }
+ else
+ {
+ return model->priv->num == 0 ||
+ gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 0;
+ }
}
guint
Modified: branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.h
==============================================================================
--- branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.h (original)
+++ branches/gtksourcecompletion/gtksourceview/gtksourcecompletionmodel.h Mon Apr 13 20:16:52 2009
@@ -51,6 +51,13 @@
GObjectClass parent_class;
};
+typedef enum
+{
+ GTK_SOURCE_COMPLETION_MODEL_NONE,
+ GTK_SOURCE_COMPLETION_MODEL_FILTERED = 1 << 0,
+ GTK_SOURCE_COMPLETION_MODEL_COUNT = 1 << 1
+} GtkSourceCompletionModelFilterFlag;
+
enum
{
GTK_SOURCE_COMPLETION_MODEL_COLUMN_LABEL,
@@ -60,7 +67,7 @@
GTK_SOURCE_COMPLETION_MODEL_N_COLUMNS
};
-typedef gboolean (* GtkSourceCompletionModelVisibleFunc) (GtkSourceCompletionModel *model,
+typedef GtkSourceCompletionModelFilterFlag (* GtkSourceCompletionModelVisibleFunc) (GtkSourceCompletionModel *model,
GtkSourceCompletionProvider *provider,
GtkSourceCompletionProposal *proposal,
gpointer userdata);
@@ -79,7 +86,9 @@
gboolean gtk_source_completion_model_remove (GtkSourceCompletionModel *model,
GtkTreeIter *iter);
-gboolean gtk_source_completion_model_is_empty (GtkSourceCompletionModel *model);
+gboolean gtk_source_completion_model_is_empty (GtkSourceCompletionModel *model,
+ gboolean invisible);
+
guint gtk_source_completion_model_n_proposals (GtkSourceCompletionModel *model,
GtkSourceCompletionProvider *provider);
Modified: branches/gtksourcecompletion/tests/completion-simple.c
==============================================================================
--- branches/gtksourcecompletion/tests/completion-simple.c (original)
+++ branches/gtksourcecompletion/tests/completion-simple.c Mon Apr 13 20:16:52 2009
@@ -168,7 +168,10 @@
prov_devhelp = gsc_provider_devhelp_new ();
gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_test1));
- gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_devhelp));
+ //gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_devhelp));
+
+ prov_test1 = gsc_provider_test_new ("Test 2");
+ gtk_source_completion_add_provider (comp, GTK_SOURCE_COMPLETION_PROVIDER (prov_test1));
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]