Beispiel #1
0
int
clip_GTK_ENTRYCOMPLETIONGETENTRY(ClipMachine * ClipMachineMemory)
{
   C_object *ccompletion = _fetch_co_arg(ClipMachineMemory);

   C_widget *cwid;

   GtkWidget *wid;

   CHECKCOBJ(ccompletion, GTK_IS_ENTRY_COMPLETION(ccompletion->object));

   wid = gtk_entry_completion_get_entry(GTK_ENTRY_COMPLETION(ccompletion->object));

   if (wid)
    {
       cwid = _list_get_cwidget(ClipMachineMemory, wid);
       if (!cwid)
	  cwid = _register_widget(ClipMachineMemory, wid, NULL);
       if (cwid)
	  _clip_mclone(ClipMachineMemory, RETPTR(ClipMachineMemory), &cwid->obj);
    }

   return 0;
 err:
   return 1;
}
Beispiel #2
0
static gboolean  fm_path_entry_match_selected(GtkEntryCompletion *widget,
                                              GtkTreeModel       *model,
                                              GtkTreeIter        *iter,
                                              gpointer user_data)
{
    GtkWidget *entry = gtk_entry_completion_get_entry(widget);
    gchar new_text[PATH_MAX];
    FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE( FM_PATH_ENTRY(entry) );
    gchar *model_file_name;
    gchar *new_path;
    gtk_tree_model_get(GTK_TREE_MODEL(model), iter,
                       COL_FILE_NAME, &model_file_name,
                       -1);
    /* FIXME: should we use UTF-8 encoded display name here? */
    new_path = fm_path_to_str(priv->completion_model->dir->dir_path);
    g_sprintf(new_text, "%s/%s",
              /* prevent leading double slash */
              g_str_equal(new_path, "/") ? "" : new_path,
              model_file_name);
    g_free(new_path);
    priv->completion_len = 0;
    gtk_entry_set_text(GTK_ENTRY(entry), new_text);
    /* move the cursor to the end of entry */
    gtk_editable_set_position(GTK_EDITABLE(entry), -1);
    return TRUE;
}
Beispiel #3
0
static gboolean fm_path_entry_match_func(GtkEntryCompletion   *completion,
                                         const gchar          *key,
                                         GtkTreeIter          *iter,
                                         gpointer user_data)
{
    gboolean ret;
    GtkTreeModel *model = gtk_entry_completion_get_model(completion);
    FmPathEntry *pe = FM_PATH_ENTRY( gtk_entry_completion_get_entry(completion) );
    FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(pe);
    FmFileInfo *model_file_info;
    gchar *model_file_name;
    /* get original key (case sensitive) */
    const gchar *original_key = gtk_entry_get_text( GTK_ENTRY(pe) );
    gboolean is_dir;
    /* find sep in key */
    gchar *key_last_slash = strrchr(original_key, G_DIR_SEPARATOR);

    /* no model based completion possible */
    if( (!model) || (key_last_slash == NULL) )
        return FALSE;

    priv->completion_len = strlen(key_last_slash + 1);

    /* get filename, info from model */
    gtk_tree_model_get(GTK_TREE_MODEL(model), iter,
                       COL_FILE_NAME, &model_file_name,
                       COL_FILE_INFO, &model_file_info,
                       -1);

    ret = fm_file_info_is_dir(model_file_info) && g_str_has_prefix(model_file_name, key_last_slash + 1);
    g_free(model_file_name);
    return ret;
}
Beispiel #4
0
/**
 * Case insensitive substring search for a completion match.
 *
 * Based on the default matching function in GtkEntryCompletion.
 *
 * This function is called once for each iter in the GtkEntryCompletion's
 * list of completion entries (model).
 *
 * @param completion Completion object to apply this function on
 * @param key        Complete string from the GtkEntry.
 * @param iter       Item in list of autocomplete database to compare key against.
 * @param user_data  Unused.
 */
static gboolean
on_match_func (GtkEntryCompletion *completion, const gchar *key,
               GtkTreeIter *iter, gpointer user_data)
{
  gchar *item = NULL;
  gchar *normalized_string;
  gchar *case_normalized_string;
  gboolean ret = FALSE;
  GtkTreeModel *model = gtk_entry_completion_get_model (completion);

  GtkEditable *e = (GtkEditable*) gtk_entry_completion_get_entry(completion);
  gint cur_pos = gtk_editable_get_position(e); /* returns 1..* */
  gint p = cur_pos;
  gint var_start;
  gboolean var_present = FALSE;

  for (p = cur_pos; p >= 0; p--)
  {
    gchar *ss = gtk_editable_get_chars(e, p, cur_pos);
    if (strncmp(ss, "$(", 2) == 0)
    {
      var_start = p+2;
      var_present = TRUE;
      g_free(ss);
      break;
    }
    g_free(ss);
  }

  if (var_present)
  {
    gchar *varname = gtk_editable_get_chars(e, var_start, cur_pos);

    gtk_tree_model_get (model, iter, COMPL_VARNAME, &item, -1);

    if (item != NULL)
    {
      // Do utf8-safe case insensitive string compare.
      // Shamelessly stolen from GtkEntryCompletion.
      normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL);

      if (normalized_string != NULL)
      {
        case_normalized_string = g_utf8_casefold (normalized_string, -1);

        if (!g_ascii_strncasecmp(varname, case_normalized_string,
                                 strlen (varname)))
          ret = TRUE;

        g_free (case_normalized_string);
      }
      g_free (normalized_string);
    }
    g_free (varname);
  }
  g_free (item);

  return ret;
}
/* Autocompletion in locationbar has found a match */
static gboolean _interface_tweaks_on_insert_prefix(InterfaceTweaks *self,
													gchar *inPrefix,
													gpointer inUserData)
{
	g_return_val_if_fail(IS_INTERFACE_TWEAKS(self), FALSE);
	g_return_val_if_fail(GTK_IS_ENTRY_COMPLETION(inUserData), FALSE);

	InterfaceTweaksPrivate	*priv=self->priv;
	GtkEntryCompletion		*completion=GTK_ENTRY_COMPLETION(inUserData);
	GtkEntry				*entry;
	guint					changedSignalID;
	const gchar				*text;
	gint					textLength;
	GSList					*handlers;

	/* Check if we should auto-complete URIs in locationbar */
	if(priv->autocompleteLocationbar==FALSE) return(TRUE);

	/* Get entry of completion */
	entry=GTK_ENTRY(gtk_entry_completion_get_entry(completion));

	/* Get current text (that is before text is set by completion)
	 * and remember its length
	 */
	text=gtk_entry_get_text(entry);
	textLength=strlen(text);

	/* Get "changed" signal ID */
	changedSignalID=g_signal_lookup("changed", GTK_TYPE_ENTRY);

	/* Emit "changed" event for all signal handlers as the entry
	 * still contains the unmodified text.
	 */
	g_signal_emit(entry, changedSignalID, 0);

	/* Block all unblocked signal handlers for "changed" signal, update entry text
	 * to the text of completion and unblock these signal handlers again.
	 * This way we prevent "changed" signal emissions for completion-text.
	 */
	handlers=_interface_tweaks_block_all_handlers(G_OBJECT(entry), changedSignalID);

	gtk_entry_set_text(entry, inPrefix);
	gtk_editable_select_region(GTK_EDITABLE(entry), textLength, -1);

	_interface_tweaks_unblock_handlers(G_OBJECT(entry), handlers);
	g_slist_free(handlers);

	/* Tell emission that we handled signal and stop further processing */
	return(TRUE);
}
Beispiel #6
0
/**
 * Called when the user selects an entry from the autocomplete list.
 *
 * @param[in] widget
 * @param[in] model     Data structure containing autocomplete strings.
 * @param[in] iter      Pointer into data structure.
 * @param[in] user_data unused here
 *
 * @return Currently always true
 */
static gboolean
on_match_select(GtkEntryCompletion *widget,
                GtkTreeModel *model,
                GtkTreeIter *iter,
                gpointer user_data)
{

  const gchar *varname;
  GtkEditable *e = (GtkEditable*) gtk_entry_completion_get_entry(widget);
  gchar *s = gtk_editable_get_chars(e, 0, -1);
  gint cur_pos = gtk_editable_get_position(e);
  gint p = cur_pos;
  gchar *end;
  gint del_end_pos = -1;

  GValue value = {0, };
  gtk_tree_model_get_value(model, iter, COMPL_VARNAME, &value);
  varname = g_value_get_string(&value);

  for (p = cur_pos; p - 2 > 0; p--)
  {
    if (strncmp(s + p - 2, "$(", 2) == 0)
    {
      break;
    }
  }

  end = s + cur_pos;

  if (end)
  {
    del_end_pos = end - s + 1;
  }
  else
  {
    del_end_pos = cur_pos;
  }

  size_t text_len = strlen(varname) + 2;
  gchar *addtext = (gchar*) g_malloc(text_len);
  snprintf(addtext, text_len, "%s)", varname);

  gtk_editable_delete_text(e, p, del_end_pos);
  gtk_editable_insert_text(e, addtext, -1, &p);
  gtk_editable_set_position(e, p);
  g_value_unset(&value);
  g_free(addtext);
  return TRUE;
}
Beispiel #7
0
gboolean 
match_selected_cb (GtkEntryCompletion *completion,
		   GtkTreeModel       *model,
		   GtkTreeIter        *iter)
{
  gchar *str;
  GtkWidget *entry;

  entry = gtk_entry_completion_get_entry (completion);
  gtk_tree_model_get (GTK_TREE_MODEL (model), iter, 1, &str, -1);
  gtk_entry_set_text (GTK_ENTRY (entry), str);
  gtk_editable_set_position (GTK_EDITABLE (entry), -1);
  g_free (str);

  return TRUE;
}
Beispiel #8
0
/*
 * FUNCTION DEFINITION
 */
static gboolean dialog_search_entry_completion_cb(GtkEntryCompletion *completion,
                                                  const gchar *key,
                                                  GtkTreeIter *iter,
                                                  gpointer data)
{
  const av_doc *doc = (const av_doc *)data;
  const gchar *real_key = NULL;
  gchar *item = NULL;
  GtkTreeModel *model = NULL;
  gchar *str_normalized = NULL;
  gchar *str_case_normalized = NULL;
  glong key_len = 0;
  gboolean result = FALSE;

  AV_DBG("%s: e\n", __func__);

  /* Get text in entry */
  real_key = gtk_entry_get_text(GTK_ENTRY(gtk_entry_completion_get_entry(completion)));
  if (g_utf8_strlen(real_key, -1) <= AV_WIDGET_ENTRY_COMPLETION_KEY_LEN_MIN) return FALSE;

  /* Get model in completion */
  model = gtk_entry_completion_get_model(completion);
  g_return_val_if_fail(gtk_tree_model_get_column_type(model, 0) == G_TYPE_STRING, FALSE);

  /* Get item in tree iter */
  gtk_tree_model_get(model, iter, 0, &item, -1);
  if (item == NULL) return FALSE;

  /* Normalize string */
  str_normalized = g_utf8_normalize(item, -1, G_NORMALIZE_ALL);
  str_case_normalized = g_utf8_casefold(str_normalized, -1);

  AV_DBG("%s: key=%s, string=%s\n", __func__, key, str_case_normalized);

  /* Match string */
  key_len = g_utf8_strlen(key, -1);
  if (!strncmp(key, str_case_normalized, key_len)) result = TRUE;

  g_free(str_normalized);
  g_free(str_case_normalized);
  g_free(item);

  AV_DBG("%s: x\n", __func__);

  return result;
}
static gboolean
xpath_match_select(	GtkEntryCompletion	* widget,
					GtkTreeModel		* model,
					GtkTreeIter			* iter,
					XpathExplorer		* ttt)
{ 
	GtkEntry	* entry;
	gchar	 	* xpath;

	gtk_tree_model_get(model, iter, XML_TREE_MODEL_COL_XPATH, xpath, -1);
	entry = gtk_entry_completion_get_entry (widget);
	
	gtk_entry_set_text(entry, xpath);

	xpath_update_completion(ttt, ttt->model, entry);
	
	g_free(xpath);
	return FALSE;
}
static gboolean
city_changed_cb (GtkEntryCompletion *entry_completion,
                 GtkTreeModel       *model,
                 GtkTreeIter        *iter,
                 CcDateTimePanel *self)
{
  GtkWidget *entry;
  gchar *zone;

  gtk_tree_model_get (model, iter,
                      CITY_COL_ZONE, &zone, -1);
  cc_timezone_map_set_timezone (CC_TIMEZONE_MAP (self->priv->map), zone);
  g_free (zone);

  entry = gtk_entry_completion_get_entry (GTK_ENTRY_COMPLETION (entry_completion));
  gtk_entry_set_text (GTK_ENTRY (entry), "");

  return TRUE;
}
Beispiel #11
0
static gboolean fm_path_entry_match_func(GtkEntryCompletion   *completion,
                                         const gchar          *key,
                                         GtkTreeIter          *iter,
                                         gpointer user_data)
{
    gboolean ret;
    GtkTreeModel *model = gtk_entry_completion_get_model(completion);
    FmPathEntry *entry = FM_PATH_ENTRY( gtk_entry_completion_get_entry(completion) );
    FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry);
    char *model_basename;
    const char* typed_basename;
    /* we don't use the case-insensitive key provided by entry completion here */
    typed_basename = gtk_entry_get_text(entry) + priv->parent_len;
    gtk_tree_model_get(model, iter, COL_BASENAME, &model_basename, -1);

    if(model_basename[0] == '.' && typed_basename[0] != '.')
        ret = FALSE; /* ignore hidden files when needed. */
    else
        ret = g_str_has_prefix(model_basename, typed_basename); /* FIXME: should we be case insensitive here? */
    g_free(model_basename);
    return ret;
}
static VALUE
rg_entry(VALUE self)
{
    return GOBJ2RVAL(gtk_entry_completion_get_entry(_SELF(self)));
}