1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * complete.c: Our auto completion engine. This is an abstract class
4 * that must be derived to implement its actual functionality.
7 * Miguel de Icaza (miguel@gnu.org)
11 * Derived types of GnmComplete provide the search function.
13 * The search function should not take too long to run, and try to
14 * search on each step information on its data repository. When the
15 * data repository information has been extenuated or if a match has
16 * been found, then the method should return FALSE and invoke the
17 * notification function that was provided to GnmComplete.
20 * (C) 2000-2001 Ximain Inc.
22 #include <gnumeric-config.h>
26 #include <gsf/gsf-impl-utils.h>
30 #define PARENT_TYPE (G_TYPE_OBJECT)
31 #define ACC(o) (GNM_COMPLETE_CLASS (G_OBJECT_GET_CLASS (o)))
34 * gnm_complete_construct:
35 * @complete: #GnmComplete
36 * @notify: (scope async): #GnmCompleteMatchNotifyFn
37 * @notify_closure: user data
40 gnm_complete_construct (GnmComplete
*complete
,
41 GnmCompleteMatchNotifyFn notify
,
44 complete
->notify
= notify
;
45 complete
->notify_closure
= notify_closure
;
49 complete_finalize (GObject
*object
)
52 GnmComplete
*complete
= GNM_COMPLETE (object
);
54 if (complete
->idle_tag
) {
55 g_source_remove (complete
->idle_tag
);
56 complete
->idle_tag
= 0;
59 g_free (complete
->text
);
60 complete
->text
= NULL
;
62 parent
= g_type_class_peek (PARENT_TYPE
);
63 parent
->finalize (object
);
67 complete_idle (gpointer data
)
69 GnmComplete
*complete
= data
;
71 g_return_val_if_fail (complete
->idle_tag
!= 0, FALSE
);
73 if (ACC(complete
)->search_iteration (complete
))
76 complete
->idle_tag
= 0;
82 gnm_complete_start (GnmComplete
*complete
, char const *text
)
84 g_return_if_fail (complete
!= NULL
);
85 g_return_if_fail (GNM_IS_COMPLETE (complete
));
86 g_return_if_fail (text
!= NULL
);
88 if (complete
->text
!= text
) {
89 g_free (complete
->text
);
90 complete
->text
= g_strdup (text
);
93 if (complete
->idle_tag
== 0)
94 complete
->idle_tag
= g_idle_add (complete_idle
, complete
);
96 if (ACC(complete
)->start_over
)
97 ACC(complete
)->start_over (complete
);
101 default_search_iteration (G_GNUC_UNUSED GnmComplete
*complete
)
107 complete_class_init (GObjectClass
*object_class
)
109 GnmCompleteClass
*complete_class
= (GnmCompleteClass
*) object_class
;
111 object_class
->finalize
= complete_finalize
;
112 complete_class
->search_iteration
= default_search_iteration
;
115 GSF_CLASS (GnmComplete
, gnm_complete
,
116 complete_class_init
, NULL
, PARENT_TYPE
)