Exemplo n.º 1
0
static void
select_index (const gchar *uri)
{
  GtkTreeSelection *selection;
  GtkTreeIter      *iter = NULL;

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));

  if (uri)
    iter = g_hash_table_lookup (uri_hash_table, uri);

  if (iter)
    {
      GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
      GtkTreePath  *path;
      GtkTreePath  *scroll_path;

      path = gtk_tree_model_get_path (model, iter);
      scroll_path = gtk_tree_path_copy (path);

      gtk_tree_path_up (path);
      gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), path);
      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), scroll_path,
                                    NULL, FALSE, 0.0, 0.0);

      gtk_tree_path_free (path);
      gtk_tree_path_free (scroll_path);

      gtk_tree_selection_select_iter (selection, iter);
    }
  else
    {
      gtk_tree_selection_unselect_all (selection);
    }
}
Exemplo n.º 2
0
static void
search_selection_changed(GtkTreeSelection * treeselection, gpointer user_data) {

    GtkTreeIter iter;
    GtkTreePath * path;
    GtkTreePath * path_up;
    gpointer gptr1;
    gpointer gptr2;
    playlist_t * pl;

    if (!gtk_tree_selection_get_selected(search_select, NULL, &iter)) {
        return;
    }

    gtk_tree_model_get(GTK_TREE_MODEL(search_store), &iter,
                       1, &gptr1, 3, &gptr2, -1);

    path = (GtkTreePath *)gptr1;
    path_up = gtk_tree_path_copy(path);

    pl = (playlist_t *)gptr2;

    if (gtk_tree_path_up(path_up)) {
        gtk_tree_view_expand_row(GTK_TREE_VIEW(pl->view), path_up, FALSE);
    }

    gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(pl->view), path, NULL, TRUE, 0.5f, 0.5f);
    gtk_tree_view_set_cursor(GTK_TREE_VIEW(pl->view), path, NULL, FALSE);

    playlist_set_current(pl);

    gtk_tree_path_free(path_up);
}
static GtkTreePath *
get_drop_path (NautilusTreeViewDragDest *dest,
               GtkTreePath *path)
{
    NautilusFile *file;
    GtkTreePath *ret;

    if (!path || !dest->details->have_drag_data) {
        return NULL;
    }

    ret = gtk_tree_path_copy (path);
    file = file_for_path (dest, ret);

    /* Go up the tree until we find a file that can accept a drop */
    while (file == NULL /* dummy row */ ||
            !nautilus_drag_can_accept_info (file,
                                            dest->details->drag_type,
                                            dest->details->drag_list)) {
        if (gtk_tree_path_get_depth (ret) == 1) {
            gtk_tree_path_free (ret);
            ret = NULL;
            break;
        } else {
            gtk_tree_path_up (ret);

            nautilus_file_unref (file);
            file = file_for_path (dest, ret);
        }
    }
    nautilus_file_unref (file);

    return ret;
}
Exemplo n.º 4
0
static void
nemo_list_model_sort_file_entries (NemoListModel *model, GSequence *files, GtkTreePath *path)
{
	GSequenceIter **old_order;
	GtkTreeIter iter;
	int *new_order;
	int length;
	int i;
	FileEntry *file_entry;
	gboolean has_iter;

	length = g_sequence_get_length (files);

	if (length <= 1) {
		return;
	}
	
	/* generate old order of GSequenceIter's */
	old_order = g_new (GSequenceIter *, length);
	for (i = 0; i < length; ++i) {
		GSequenceIter *ptr = g_sequence_get_iter_at_pos (files, i);
		
		file_entry = g_sequence_get (ptr);
		if (file_entry->files != NULL) {
			gtk_tree_path_append_index (path, i);
			nemo_list_model_sort_file_entries (model, file_entry->files, path);
			gtk_tree_path_up (path);
		}

		old_order[i] = ptr;
	}

	/* sort */
	g_sequence_sort (files, nemo_list_model_file_entry_compare_func, model);

	/* generate new order */
	new_order = g_new (int, length);
	/* Note: new_order[newpos] = oldpos */
	for (i = 0; i < length; ++i) {
		new_order[g_sequence_iter_get_position (old_order[i])] = i;
	}

	/* Let the world know about our new order */

	g_assert (new_order != NULL);

	has_iter = FALSE;
	if (gtk_tree_path_get_depth (path) != 0) {
		gboolean get_iter_result;
		has_iter = TRUE;
		get_iter_result = gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
		g_assert (get_iter_result);
	}

	gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
				       path, has_iter ? &iter : NULL, new_order);

	g_free (old_order);
	g_free (new_order);
}
Exemplo n.º 5
0
/* sort using merge sort */
static void
gbf_project_model_sort (GtkTreeModel *model,
                        GtkTreePath *begin,
                        GtkTreePath *end,
                        GtkTreeIterCompareFunc compare_func,
                        gpointer user_data)
{
	GtkTreePath *half;
	gint depth;

	/* Empty list are sorted */
	if (gtk_tree_path_compare (begin, end) >= 0)
	{
		return;
	}

	/* Split the list in two */
	half = gtk_tree_path_copy (begin);
	gtk_tree_path_up (half);
	gtk_tree_path_append_index (half, (gtk_tree_path_get_indices_with_depth (begin, &depth)[depth -1] +
	                                   gtk_tree_path_get_indices_with_depth (end, &depth)[depth - 1]) / 2);

	/* List with a single element are sorted too */
	if (gtk_tree_path_compare (begin, half) < 0)
	{
		gbf_project_model_sort (model, begin, half, compare_func, user_data);
		gbf_project_model_sort (model, half, end, compare_func, user_data);
		gbf_project_model_merge (model, begin, half, end, compare_func, user_data);
	}
	
	gtk_tree_path_free (half);
}
Exemplo n.º 6
0
/* listen on the diagram for object add/remove */
static void
_object_add (DiagramData      *dia,
	     Layer            *layer,
             DiaObject        *obj,
	     DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter;
  GtkTreeIter *iter = &_iter;
  /* a bit backward: the first child is in the diagram, but not the tree yet */
  gboolean had_child = layer_object_count (layer) > 1;

  g_return_if_fail (DIA_DIAGRAM(dia) != NULL);

  NODE_DIAGRAM(iter) = dia;
  NODE_LAYER(iter)   = layer;
  NODE_OBJECT(iter)  = obj;


  /* FIXME: this may get called before the layer is added to the tree */
  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  if (path) {
    gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter);
    /* enforce update */
    if (!had_child && gtk_tree_path_up (path))
      gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, &_iter);
    gtk_tree_path_free (path);
  }
}
Exemplo n.º 7
0
static void delete_log_cb(gpointer *data)
{
	if (!purple_log_delete((PurpleLog *)data[2]))
	{
		purple_notify_error(NULL, NULL, _("Log Deletion Failed"),
		                  _("Check permissions and try again."));
	}
	else
	{
		GtkTreeStore *treestore = data[0];
		GtkTreeIter *iter = (GtkTreeIter *)data[1];
		GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(treestore), iter);
		gboolean first = !gtk_tree_path_prev(path);

#if GTK_CHECK_VERSION(2,2,0)
		if (!gtk_tree_store_remove(treestore, iter) && first)
		{
			/* iter was the last child at its level */

			if (gtk_tree_path_up(path))
			{
				gtk_tree_model_get_iter(GTK_TREE_MODEL(treestore), iter, path);
				gtk_tree_store_remove(treestore, iter);
			}
		}
#else
		gtk_tree_store_remove(treestore, iter);
#endif
		gtk_tree_path_free(path);
	}

	delete_log_cleanup_cb(data);
}
Exemplo n.º 8
0
/* Expand trees (and any subtrees they may have) whose ett_ shows them as
 * expanded.
 * Callers should block calls to expand_tree() to avoid useless recursion.
 */
static void
check_expand_trees(GtkTreeView *tree_view, GtkTreeModel *model, GtkTreePath *path,
                   GtkTreeIter *iter, gboolean scroll_it, gboolean expand_parent)
{
    /* code inspired by gtk_tree_model_foreach_helper */

    field_info *fi;

    do {
        GtkTreeIter child;

        if (gtk_tree_model_iter_children(model, &child, iter)) {
            gtk_tree_model_get(model, iter, 1, &fi, -1);

            if (tree_expanded(fi->tree_type)) {
                if (expand_parent)
                    gtk_tree_view_expand_row(tree_view, path, FALSE);

                if (scroll_it)
                     gtk_tree_view_scroll_to_cell(tree_view, path, NULL, TRUE, (prefs.gui_auto_scroll_percentage/100.0f), 0.0f);

                /* try to expand children only when parent is expanded */
                gtk_tree_path_down(path);
                check_expand_trees(tree_view, model, path, &child, scroll_it, TRUE);
                gtk_tree_path_up(path);
            }
        }

        gtk_tree_path_next(path);
    } while (gtk_tree_model_iter_next(model, iter));
}
Exemplo n.º 9
0
static void fm_dir_tree_model_add_place_holder_child_item (FmDirTreeModel *dir_tree_model, GList *parent_node,
                                                           GtkTreePath *tree_path, gboolean emit_signal)
{
    FmDirTreeItem *parent_item = (FmDirTreeItem*) parent_node->data;
    
    // Check if the parent node can expand...
    FmFileInfo *file_info = parent_item->file_info;
    FmPath *path = fm_file_info_get_path (file_info);
    
    TREEVIEW_DEBUG ("TREEVIEW_DEBUG: fm_dir_tree_model_add_place_holder_child_item: file = %s\t emit_signal = %d\n",
                    fm_file_info_get_name (file_info), emit_signal);
    
    
    // don't expand the trash can...
    // TODO_axl: add a can_expand flag into the file_info
    if (fm_path_is_trash (path) && fm_path_is_root (path))
        return;
    
    TREEVIEW_DEBUG ("TREEVIEW_DEBUG: fm_dir_tree_model_add_place_holder_child_item: create place holder\n\n");
    
    FmDirTreeItem *dir_tree_item = fm_dir_tree_item_new (dir_tree_model, parent_node, NULL);
    
    parent_item->children = g_list_prepend (parent_item->children, dir_tree_item);

    if (!emit_signal)
        return;
        
    GtkTreeIter it;
    fm_dir_tree_model_item_to_tree_iter (dir_tree_model, parent_item->children, &it);
    
    gtk_tree_path_append_index (tree_path, 0);
    
    gtk_tree_model_row_inserted (GTK_TREE_MODEL (dir_tree_model), tree_path, &it);
    gtk_tree_path_up (tree_path);
}
Exemplo n.º 10
0
/* 
 * text has been dragged into the watch tree view
 */
static void on_watch_dragged_callback(GtkWidget *wgt, GdkDragContext *context, int x, int y,
	GtkSelectionData *seldata, guint info, guint _time,
    gpointer userdata)
{
	/* string that is dragged */
	gchar *expression = (gchar*)seldata->data;
	GtkTreePath *path = NULL;
	GtkTreeViewDropPosition pos;
	GtkTreePath *empty_path;
	GtkTreeIter newvar;

	/* lookup for where the text has been dropped */
	gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(wtree), x, y, &path, &pos);

	/* if dropped into last row - insert before it */
	empty_path = wtree_empty_path();
	if (!gtk_tree_path_compare(empty_path, path))
		pos = GTK_TREE_VIEW_DROP_BEFORE;
	gtk_tree_path_free(empty_path);
	
	/* if dropped into children area - insert before parent */
	if (gtk_tree_path_get_depth(path) > 1)
	{
		while (gtk_tree_path_get_depth(path) > 1)
			gtk_tree_path_up(path);
		pos = GTK_TREE_VIEW_DROP_BEFORE;
	}
	
	/* insert new row */
	if (path)
	{
		GtkTreeIter sibling;
		gtk_tree_model_get_iter(wmodel, &sibling, path);
		
		if (GTK_TREE_VIEW_DROP_BEFORE == pos || GTK_TREE_VIEW_DROP_INTO_OR_BEFORE == pos)
			gtk_tree_store_insert_before(wstore, &newvar, NULL, &sibling);
		else
			gtk_tree_store_insert_after(wstore, &newvar, NULL, &sibling);
	}
	else
	{
		GtkTreeIter empty;

		wtree_empty_row(&empty);
		gtk_tree_store_insert_before(wstore, &newvar, NULL, &empty);
	}
	
	/* if debugger is active (in stopped condition) - add to run-time watch list
	 *  if not - just set new expession in the tree view */ 
	if (DBS_STOPPED == debug_state)
	{
		variable *var = active_module->add_watch(expression);
		change_watch(GTK_TREE_VIEW(wtree), &newvar, var);
	}
	else
		variable_set_name_only(wstore, &newvar, expression);

	config_set_debug_changed();
}
Exemplo n.º 11
0
/**
@brief delete selected row(s), if any, from @a treeview

@param treeview where the action is to occur

@return
*/
void e2_tree_delete (GtkTreeView *treeview)
{
	GtkTreeSelection *sel = gtk_tree_view_get_selection (treeview);
	if (gtk_tree_selection_count_selected_rows (sel) > 0)
	{
		GtkTreeModel *model;
		GList *tmp, *rowrefs = NULL;
		GList *selpaths = gtk_tree_selection_get_selected_rows (sel, &model);
		//identify a place to goto after the deletion
		//(current place, if we're at the start of the tree)
		GtkTreePath *newpath = gtk_tree_path_copy (selpaths->data);
		if (!gtk_tree_path_prev (newpath))
			if (gtk_tree_path_get_depth (newpath) > 1)
				gtk_tree_path_up (newpath);
		GtkTreePath *path;
		GtkTreeIter iter;

		//create treerowrefs for all selected rows
		for (tmp = selpaths; tmp!=NULL; tmp=tmp->next)
		{
			path = (GtkTreePath *) tmp->data;
			if (gtk_tree_model_get_iter (model, &iter, path))
				_e2_tree_reference_treerow (model, &iter, &rowrefs);
			gtk_tree_path_free (path);
		}
		g_list_free (selpaths);

		for (tmp = rowrefs; tmp != NULL; tmp = tmp->next)
		{
			path = gtk_tree_row_reference_get_path ((GtkTreeRowReference *) tmp->data);
			if (path != NULL)
			{
				if (gtk_tree_model_get_iter (model, &iter, path))
				{
					//gtk_tree_selection_unselect_path (sel, path);	//needed ?
					//this deletes all children too
					gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
				}
				gtk_tree_path_free (path);
			}
			gtk_tree_row_reference_free ((GtkTreeRowReference *) tmp->data);
		}
		g_list_free (rowrefs);

		//go to the new place
		if (!gtk_tree_model_get_iter (model, &iter, newpath)
			&& gtk_tree_model_get_iter_first (model, &iter))
		{
			gtk_tree_path_free (newpath);
			newpath = gtk_tree_model_get_path (model, &iter);
		}
		gtk_tree_view_set_cursor (treeview, newpath,
			gtk_tree_view_get_column (treeview, 0), FALSE);

		gtk_tree_path_free (newpath);
	}
}
Exemplo n.º 12
0
static void get_selection_bus_foreach_func (GtkTreeModel *tm, GtkTreePath *tp, GtkTreeIter *itr, gpointer data)
  {
  GET_SELECTION_BUS_STRUCT *gsbs = (GET_SELECTION_BUS_STRUCT *)data ;
  int this_depth = gtk_tree_path_get_depth (tp), row_type = -1 ;

  if (gsbs->state == GSBS_REJECT) return ;

  gtk_tree_model_get (tm, itr, BUS_LAYOUT_MODEL_COLUMN_TYPE, &row_type, -1) ;

  if (GSBS_START == gsbs->state && 2 == this_depth)
    {
    if (gtk_tree_path_up (gsbs->tpBus = gtk_tree_path_copy (tp)))
      gsbs->state = GSBS_D1B_ACCEPT ;
    else
      gsbs->state = GSBS_REJECT ;
    }
  else
  if (GSBS_START == gsbs->state && 1 == this_depth)
    {
    if (row_type & ROW_TYPE_BUS)
      {
      gsbs->tpBus = gtk_tree_path_copy (tp) ;
      gsbs->state = GSBS_D1B_ACCEPT ;
      }
    else
      gsbs->state = GSBS_REJECT ;
    }
  else // At this point, gsbs->state can only be GSBS_ACCEPT
    {
    if (1 == this_depth) gsbs->state = GSBS_REJECT ;
    else
      {
      GtkTreePath *tpThisParent = NULL ;

      if (!gtk_tree_path_up (tpThisParent = gtk_tree_path_copy (tp)))
        gsbs->state = GSBS_REJECT ;
      else
        gsbs->state = (0 == gtk_tree_path_compare (tpThisParent, gsbs->tpBus)) ? GSBS_D1B_ACCEPT : GSBS_REJECT ;

      gtk_tree_path_free (tpThisParent) ;
      }
    }
  }
Exemplo n.º 13
0
/* builds a keyword string out of GtkTreePath */
static void _lib_keywords_string_from_path(char *dest,size_t ds,
    GtkTreeModel *model,
    GtkTreePath *path)
{
  g_assert(model!=NULL);
  g_assert(path!=NULL);

  GList *components = NULL;
  GtkTreePath *wp = gtk_tree_path_copy(path);
  GtkTreeIter iter;

  /* get components of path */
  while (1)
  {
    GValue value;
    memset(&value,0,sizeof(GValue));

    /* get iter from path, break out if fail */
    if (!gtk_tree_model_get_iter(model, &iter, wp))
      break;

    /* add component to begin of list */
    gtk_tree_model_get_value(model, &iter, 0, &value);
    if ( !(gtk_tree_path_get_depth(wp) == 1 &&
           strcmp(g_value_get_string(&value), _(UNCATEGORIZED_TAG)) == 0))
    {
      components = g_list_insert(components,
                                 g_strdup(g_value_get_string(&value)),
                                 0);
    }
    g_value_unset(&value);

    /* get parent of current path break out if we are at root */
    if (!gtk_tree_path_up(wp) || gtk_tree_path_get_depth(wp) == 0)
      break;
  }

  /* build the tag string from components */
  int dcs = 0;

  if(g_list_length(components) == 0) dcs += g_snprintf(dest+dcs, ds-dcs," ");

  for(guint i=0; i<g_list_length(components); i++)
  {
    dcs += g_snprintf(dest+dcs, ds-dcs,
                      "%s%s",
                      (gchar *)g_list_nth_data(components, i),
                      (i < g_list_length(components)-1) ? "|" : "");
  }

  /* free data */
  gtk_tree_path_free(wp);


}
Exemplo n.º 14
0
void
music_store_mark_changed(GtkTreeIter * iter) {

	GtkTreeIter iter_store;
	GtkTreePath * path;
	char name[MAXLEN];
	char * pname;
	store_t * data;

	music_store_selection_changed(STORE_TYPE_FILE);

	path = gtk_tree_model_get_path(GTK_TREE_MODEL(music_store), iter);

        while (gtk_tree_path_get_depth(path) > 1) {
                gtk_tree_path_up(path);
        }

	gtk_tree_model_get_iter(GTK_TREE_MODEL(music_store), &iter_store, path);
	gtk_tree_path_free(path);

	gtk_tree_model_get(GTK_TREE_MODEL(music_store), &iter_store, MS_COL_DATA, &data, -1);

	switch (data->type) {
	case STORE_TYPE_FILE:
		{
			store_data_t * store_data = (store_data_t *)data;
			if (store_data->dirty) {
				return;
			}
			store_data->dirty = 1;
		}
		break;
	default:
		/* skip */
		return;
	}

	gtk_tree_model_get(GTK_TREE_MODEL(music_store), &iter_store, MS_COL_NAME, &pname, -1);

	name[0] = '*';
	name[1] = '\0';
	strncat(name, pname, MAXLEN-2);
	g_free(pname);

	gtk_tree_store_set(music_store, &iter_store, MS_COL_NAME, name, -1);

	music_store_changed = 1;
	gtk_window_set_title(GTK_WINDOW(browser_window), _("*Music Store"));
	if (options.enable_mstore_toolbar) {
		gtk_widget_set_sensitive(toolbar_save_button, TRUE);
	}
}
Exemplo n.º 15
0
static void
gimp_action_view_select_path (GimpActionView *view,
                              GtkTreePath    *path)
{
  GtkTreeView *tv = GTK_TREE_VIEW (view);
  GtkTreePath *expand;

  expand = gtk_tree_path_copy (path);
  gtk_tree_path_up (expand);
  gtk_tree_view_expand_row (tv, expand, FALSE);
  gtk_tree_path_free (expand);

  gtk_tree_view_set_cursor (tv, path, NULL, FALSE);
  gtk_tree_view_scroll_to_cell (tv, path, NULL, TRUE, 0.5, 0.0);
}
Exemplo n.º 16
0
static void
move_up (int val)
{
    int i;
    GtkTreePath *path;
    GtkTreePath *tree_path;
    GtkTreeIter iter1;
    GtkTreeIter iter2;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (main_gui.displayed_list));

    gtk_tree_view_get_cursor (GTK_TREE_VIEW (main_gui.displayed_list), &path, NULL);

    if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter1, path))
        return;

    for (i = 0; i < val; i++) {
        if (!gtk_tree_path_prev (path)) {
            if (!gtk_tree_path_up (path)) {
                break;
            } else {
                if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter1, path))
                    break;
            }
        } else {
            if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (main_gui.displayed_list), path)) {
                gtk_tree_path_down (path);
                gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter2, path);
                iter1 = iter2;
                while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter2)) {
                    iter1 = iter2;
                }
            } else {
                if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter1, path))
                    break;
            }
        }
    }

    tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter1);
    gtk_tree_view_set_cursor (GTK_TREE_VIEW (main_gui.displayed_list), tree_path, NULL, FALSE);
    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (main_gui.displayed_list), tree_path, NULL, TRUE, 0.5, 0);
    gtk_tree_path_free (tree_path);

    gtk_widget_grab_focus (main_gui.displayed_list);

}
Exemplo n.º 17
0
gboolean on_dir_tree_view_key_press( GtkWidget* view,
                                     GdkEventKey* evt,
                                     gpointer user_data )
{
    switch(evt->keyval) {
    case GDK_Left:
    case GDK_Right:
        break;
    default:
        return FALSE;
    }


    GtkTreeSelection *select = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
    GtkTreeModel *model;
    GtkTreeIter iter;
    if(!gtk_tree_selection_get_selected(select, &model, &iter))
        return FALSE;

    GtkTreePath *path = gtk_tree_model_get_path(model, &iter);

    switch( evt->keyval ) {
    case GDK_Left:
        if(gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_collapse_row(GTK_TREE_VIEW(view), path);
        } else if(gtk_tree_path_up(path)) {
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        } else {
            return FALSE;
        }
        break;
    case GDK_Right:
        if(!gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path)) {
            gtk_tree_view_expand_row(GTK_TREE_VIEW(view), path, FALSE);
        } else {
            gtk_tree_path_down(path);
            gtk_tree_selection_select_path(select, path);
            gtk_tree_view_set_cursor(GTK_TREE_VIEW(view), path, NULL, FALSE);
        }
        break;
    }
    return TRUE;
}
Exemplo n.º 18
0
static void fm_dir_tree_model_item_reload_icon (FmDirTreeModel *dir_tree_model, FmDirTreeItem *dir_tree_item,
                                                GtkTreePath *tree_path)
{
    g_return_if_fail (dir_tree_item != NULL);
    
    GtkTreeIter it;
    GList *l;

    //~ if (dir_tree_item->icon)
    //~ {
        //~ g_object_unref (dir_tree_item->icon);
        //~ dir_tree_item->icon = NULL;
        //~ gtk_tree_model_row_changed (GTK_TREE_MODEL (dir_tree_model), tree_path, &it);
    //~ }

    if (dir_tree_item->fm_icon)
    {
        fm_icon_unref (dir_tree_item->fm_icon);
        dir_tree_item->fm_icon = NULL;
        gtk_tree_model_row_changed (GTK_TREE_MODEL (dir_tree_model), tree_path, &it);
    }

    if (dir_tree_item->children)
    {
        gtk_tree_path_append_index (tree_path, 0);
        for (l = dir_tree_item->children; l; l=l->next)
        {
            fm_dir_tree_model_item_reload_icon (dir_tree_model, (FmDirTreeItem*) l->data, tree_path);
            gtk_tree_path_next (tree_path);
        }
        gtk_tree_path_up (tree_path);
    }

    for (l = dir_tree_item->hidden_children; l; l=l->next)
    {
        FmDirTreeItem *child = (FmDirTreeItem*) l->data;
        if (child && child->fm_icon)
        {
            fm_icon_unref (child->fm_icon);
            child->fm_icon = NULL;
        }
    }
}
Exemplo n.º 19
0
int
path_get_store_type(GtkTreePath * p) {

	GtkTreeIter iter;
        GtkTreePath * path;
	store_t * data;

	path = gtk_tree_path_copy(p);

        while (gtk_tree_path_get_depth(path) > 1) {
                gtk_tree_path_up(path);
        }

        gtk_tree_model_get_iter(GTK_TREE_MODEL(music_store), &iter, path);
	gtk_tree_model_get(GTK_TREE_MODEL(music_store), &iter, MS_COL_DATA, &data, -1);
	gtk_tree_path_free(path);

	return data->type;
}
Exemplo n.º 20
0
static void fm_dir_tree_model_remove_all_children (FmDirTreeModel *dir_tree_model, GList *item_list,
                                                   GtkTreePath *tree_path)
{
    FmDirTreeItem *dir_tree_item = (FmDirTreeItem*)item_list->data;
    if (G_UNLIKELY (!dir_tree_item->children))
        return;
    
    gtk_tree_path_append_index (tree_path, 0);
    
    while (dir_tree_item->children)
    {
        fm_dir_tree_item_free_l (dir_tree_item->children);
        dir_tree_item->children = g_list_delete_link (dir_tree_item->children, dir_tree_item->children);
        
        char *tmp_path = gtk_tree_path_to_string (tree_path);
        //TREEVIEW_DEBUG ("TREEVIEW_DEBUG: fm_dir_tree_model_remove_all_children %s\n", tmp_path);
        g_free (tmp_path);
        
        // signal the view that we removed the placeholder item.
        // everytime we remove the first item, its next item became the
        // first item, so there is no need to update tree_path.
        gtk_tree_model_row_deleted (GTK_TREE_MODEL (dir_tree_model), tree_path);
    }

    if (dir_tree_item->hidden_children)
    {
        g_list_foreach (dir_tree_item->hidden_children, (GFunc)fm_dir_tree_item_free, NULL);
        g_list_free (dir_tree_item->hidden_children);
        dir_tree_item->hidden_children = NULL;
    }
    
    gtk_tree_path_up (tree_path);
    
    GtkTreeIter it;
    gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dir_tree_model), tree_path, &it);
    
    // ???
    //~ gtk_tree_model_row_changed ((GtkTreeModel*) dir_tree_model, tree_path, &it);
}
Exemplo n.º 21
0
static int
path_menu_index (RBDisplayPageMenu *menu, GtkTreePath *path)
{
	GtkTreePath *root;
	GtkTreePath *compare;
	int depth;
	int *indices;
	int index;

	compare = gtk_tree_path_copy (path);
	if (gtk_tree_path_up (compare) == FALSE) {
		gtk_tree_path_free (compare);
		return -1;
	}

	if (gtk_tree_path_get_depth (compare) == 0) {
		gtk_tree_path_free (compare);
		return -1;
	}

	root = get_root_path (menu);
	if (root == NULL) {
		gtk_tree_path_free (compare);
		return -1;
	}

	if (gtk_tree_path_compare (compare, root) != 0) {
		gtk_tree_path_free (root);
		gtk_tree_path_free (compare);
		return -1;
	}

	indices = gtk_tree_path_get_indices_with_depth (path, &depth);
	index = count_items (menu, indices[depth-1]);
	gtk_tree_path_free (root);
	gtk_tree_path_free (compare);
	return index;
}
Exemplo n.º 22
0
static void bmark_popup_menu_deldoc_lcb(GtkWidget * widget, Tbfwin *bfwin) {
	if (bfwin->bmark) {
		GtkTreePath *path;
		GtkTreeViewColumn *col;
		gtk_tree_view_get_cursor(bfwin->bmark, &path, &col);
		if (path != NULL) {
			gchar *name;
			gchar *pstr;
			gchar *btns[] = { GTK_STOCK_NO, GTK_STOCK_YES, NULL };
			GtkTreeIter iter;
			gint depth, ret;
			depth = gtk_tree_path_get_depth(path);
			if (depth == 2) {
				/* go up to parent */
				gtk_tree_path_up(path);
			} else if (depth != 1) {
				g_print("a bug in function bmark_popup_menu_deldoc_lcb()\n");
#ifdef DEVELOPMENT
				exit(124);
#endif
				return;
			}
			gtk_tree_model_get_iter(gtk_tree_view_get_model(bfwin->bmark), &iter, path);
			gtk_tree_path_free(path);
			gtk_tree_model_get(GTK_TREE_MODEL(bfwin->bookmarkstore), &iter, NAME_COLUMN,&name, -1);
		
			pstr = g_strdup_printf(_("Do you really want to delete all bookmarks for %s?"), name);
			ret =	multi_query_dialog(bfwin->main_window, _("Delete bookmarks?"), pstr,
							   0, 0, btns);
			g_free(pstr);
			if (ret == 0)
				return;
			bmark_del_children_backend(bfwin, &iter);
		}
	}
	gtk_widget_grab_focus(bfwin->current_document->view);
}
Exemplo n.º 23
0
static GtkTreePath *
dspy_introspection_model_get_path (GtkTreeModel *model,
                                   GtkTreeIter  *iter)
{
  DspyIntrospectionModel *self = (DspyIntrospectionModel *)model;
  GtkTreePath *path;
  DspyNode *node;

  LOG_DEBUG (G_STRFUNC);

  g_assert (DSPY_IS_INTROSPECTION_MODEL (self));
  g_assert (iter != NULL);

  node = iter->user_data;

  g_assert (node != NULL);
  g_assert (node->any.parent != NULL);

  path = gtk_tree_path_new_first ();

  g_assert (gtk_tree_path_get_depth (path) == 1);

  for (; node->any.parent != NULL; node = node->any.parent)
    {
      gint pos = 0;

      for (const GList *list = &node->any.link; list->prev; list = list->prev)
        pos++;

      gtk_tree_path_prepend_index (path, pos);
    }

  gtk_tree_path_up (path);

  return g_steal_pointer (&path);
}
Exemplo n.º 24
0
/* 
 * key has been pressed while being in watch tree view
 */
static gboolean on_watch_key_pressed_callback(GtkWidget *widget, GdkEvent  *event, gpointer user_data)
{
	/* handling only Delete button pressing
	 * that means "delete selected rows" */
	int keyval = ((GdkEventKey*)event)->keyval;
	if (keyval != GDK_Delete)
		return FALSE;

	/* get selected rows */
	GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(wtree));
	GList *rows = gtk_tree_selection_get_selected_rows(selection, &wmodel);
	
	/* empty row path */
	GtkTreePath *empty_path = wtree_empty_path();

	/* check whether only empty row was selected */
	if (1 != gtk_tree_selection_count_selected_rows(selection) ||
	    gtk_tree_path_compare((GtkTreePath*)rows->data, empty_path))
	{
		/* path reference to select after deleteing finishes */
		GtkTreeRowReference *reference_to_select = NULL;

		/* get references to the rows */
		GList *references = NULL;
		GList *iter = rows;
		while (iter)
		{
			GtkTreePath *path = (GtkTreePath*)iter->data;

			/* move up paths to the root elements */
			while (gtk_tree_path_get_depth(path) > 1)
				gtk_tree_path_up(path);

			/* add path reference if it's not an empty row*/
			if (gtk_tree_path_compare(path, empty_path))
				references = g_list_append(references, gtk_tree_row_reference_new(wmodel, path));

			iter = iter->next;
		}

		/* iterate through references and remove */
		iter = references;
		while (iter)
		{
			GtkTreeRowReference *reference = (GtkTreeRowReference*)iter->data;
			/* check for valid reference because two or more equal
			refernces could be put in the list if several child items
			of the same node were selected and the path for the
			current reference was already deleted */
			if (gtk_tree_row_reference_valid(reference))
			{
				GtkTreePath *path = gtk_tree_row_reference_get_path(reference);

				if (!reference_to_select)
				{
					/* select upper sibling of the upper
					selected row that has unselected upper sibling */
					GtkTreePath *sibling = gtk_tree_path_copy(path);
					if(gtk_tree_path_prev(sibling))
					{
						if (!gtk_tree_selection_path_is_selected(selection, sibling))
							reference_to_select = gtk_tree_row_reference_new(gtk_tree_view_get_model(GTK_TREE_VIEW(wtree)), sibling);
					}
					else if (gtk_tree_path_next(sibling), gtk_tree_path_compare(path, sibling))
						reference_to_select = gtk_tree_row_reference_new(gtk_tree_view_get_model(GTK_TREE_VIEW(wtree)), sibling);
				}

				/* get iterator */
				GtkTreeIter titer;
				gtk_tree_model_get_iter(wmodel, &titer, path);

				/* remove from the debug session, if it's active */
				if (DBS_STOPPED == debug_state)
				{

					gchar *internal = NULL;
					gtk_tree_model_get (
						wmodel,
						&titer,
						W_INTERNAL, &internal,
						-1);

					active_module->remove_watch(internal);

					g_free(internal);
				}


				gtk_tree_store_remove(wstore, &titer);

				gtk_tree_path_free(path);
			}
			
			iter = iter->next;
		}

		/* if all (with or without empty row) was selected - set empty row
		as a path to be selected after deleting */
		if (!reference_to_select)
		{
			GtkTreePath *path = wtree_empty_path();
			reference_to_select = gtk_tree_row_reference_new (gtk_tree_view_get_model(GTK_TREE_VIEW(wtree)), path);
			gtk_tree_path_free(path);
		}

		/* set selection */
		gtk_tree_selection_unselect_all(selection);
		GtkTreePath *path_to_select = gtk_tree_row_reference_get_path(reference_to_select);
		gtk_tree_selection_select_path(selection, path_to_select);
		gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(widget), path_to_select, NULL, TRUE, 0.5, 0.5);
		gtk_tree_path_free(path_to_select);	

		/* free references list */
		g_list_foreach (references, (GFunc)gtk_tree_row_reference_free, NULL);
		g_list_free (references);

		config_set_debug_changed();
	}

	gtk_tree_path_free(empty_path);

	/* free rows list */
	g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
	g_list_free (rows);

	return FALSE;
}
Exemplo n.º 25
0
// start helpers
static void swap_buses (GtkTreeModel *tm, GtkTreeSelection *sel, bus_layout_D *dialog, GtkTreePath *tpSrc, GtkTreePath *tpDst)
  {
  int Nix ;
  GtkTreeIter itr ;
  SWAP_BUSES_STRUCT src, dst ;
  SWAP_BUSES_STRUCT *min = NULL, *max = NULL ;
  EXP_ARRAY *ar_bSelSrc = NULL, *ar_bSelDst = NULL ;
  gboolean bDstExpanded = TRUE ;

  if (!gtk_tree_model_get_iter (tm, &(src.itr), tpSrc)) return ;
  src.tp = gtk_tree_path_copy (tpSrc) ;
  src.icChildren = gtk_tree_model_iter_n_children (tm, &(src.itr)) ;

  if (!gtk_tree_model_get_iter (tm, &(dst.itr), tpDst))
    {
    gtk_tree_path_free (src.tp) ;
    return ;
    }
  dst.tp = gtk_tree_path_copy (tpDst) ;
  dst.icChildren = gtk_tree_model_iter_n_children (tm, &(dst.itr)) ;

  if (dst.icChildren < src.icChildren)
    {
    min = &dst ;
    max = &src ;
    }
  else
    {
    min = &src ;
    max = &dst ;
    }

  bDstExpanded = gtk_tree_view_row_expanded (gtk_tree_selection_get_tree_view (sel), dst.tp) ;

  g_signal_handlers_block_matched (G_OBJECT (sel), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, (gpointer)tree_view_selection_changed, NULL) ;

  for (Nix = 0 ; Nix < max->icChildren - min->icChildren ; Nix++)
    gtk_tree_store_append (GTK_TREE_STORE (tm), &itr, &(min->itr)) ;

  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  ar_bSelSrc = exp_array_new (sizeof (gboolean), 1) ;
  ar_bSelDst = exp_array_new (sizeof (gboolean), 1) ;
  exp_array_1d_insert_vals (ar_bSelSrc, NULL, max->icChildren, 0) ;
  exp_array_1d_insert_vals (ar_bSelDst, NULL, max->icChildren, 0) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    exp_array_index_1d (ar_bSelSrc, gboolean, Nix) =
      gtk_tree_selection_path_is_selected (sel, src.tp) ;
    exp_array_index_1d (ar_bSelDst, gboolean, Nix) =
      gtk_tree_selection_path_is_selected (sel, dst.tp) ;

    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    if (exp_array_index_1d (ar_bSelDst, gboolean, Nix))
      gtk_tree_view_expand_to_path (gtk_tree_selection_get_tree_view (sel), src.tp) ;

    if (exp_array_index_1d (ar_bSelSrc, gboolean, Nix))
      gtk_tree_view_expand_to_path (gtk_tree_selection_get_tree_view (sel), dst.tp) ;

    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    swap_model_paths_contents (tm, src.tp, dst.tp) ;
    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;
  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < max->icChildren ; Nix++)
    {
    GTK_TREE_SELECTION_SET_PATH_SELECTED (sel, src.tp, exp_array_index_1d (ar_bSelDst, gboolean, Nix)) ;
    GTK_TREE_SELECTION_SET_PATH_SELECTED (sel, dst.tp, exp_array_index_1d (ar_bSelSrc, gboolean, Nix)) ;
    gtk_tree_path_next (src.tp) ;
    gtk_tree_path_next (dst.tp) ;
    }

  if (!gtk_tree_path_up (src.tp)) goto swap_buses_quit ;
  if (!gtk_tree_path_up (dst.tp)) goto swap_buses_quit ;

  swap_model_paths_contents (tm, src.tp, dst.tp) ;

  gtk_tree_path_down (src.tp) ;
  gtk_tree_path_down (dst.tp) ;

  for (Nix = 0 ; Nix < min->icChildren ; Nix++)
    gtk_tree_path_next (max->tp) ;
  if (gtk_tree_model_get_iter (tm, &itr, max->tp))
    while (gtk_tree_store_remove (GTK_TREE_STORE (tm), &itr)) ;

  if (!bDstExpanded)
    {
    for (Nix = 0 ; Nix < ar_bSelDst->icUsed ; Nix++)
      if (exp_array_index_1d (ar_bSelDst, gboolean, Nix))
        break ;

    if (Nix == ar_bSelDst->icUsed)
      if (gtk_tree_path_up (src.tp))
        gtk_tree_view_collapse_row (gtk_tree_selection_get_tree_view (sel), src.tp) ;
    }

swap_buses_quit:

  exp_array_free (ar_bSelSrc) ;
  exp_array_free (ar_bSelDst) ;
  gtk_tree_path_free (src.tp) ;
  gtk_tree_path_free (dst.tp) ;
  g_signal_handlers_unblock_matched (G_OBJECT (sel), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, (gpointer)tree_view_selection_changed, NULL) ;
  tree_view_selection_changed (sel, dialog) ;
  }
Exemplo n.º 26
0
bool
sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
                  girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

  if(zathura->ui.index == NULL) {
    return false;
  }

  GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
  GtkTreePath *path;

  gtk_tree_view_get_cursor(tree_view, &path, NULL);
  if (path == NULL) {
    return false;
  }

  GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
  GtkTreeIter   iter;
  GtkTreeIter   child_iter;

  gboolean is_valid_path = TRUE;

  switch(argument->n) {
    case TOP:
      /* go to the first node */
      gtk_tree_path_free(path);
      path = gtk_tree_path_new_first();
      break;
    case BOTTOM:
      /* go to the last visiible node */
      gtk_tree_path_free(path);
      path = gtk_tree_path_new_from_indices(gtk_tree_model_iter_n_children(model, NULL) - 1, -1);
      gtk_tree_model_get_iter(model, &iter, path);
      while (gtk_tree_model_iter_has_child(model, &iter) == TRUE &&
          gtk_tree_view_row_expanded(tree_view, path) == TRUE) {
          gtk_tree_path_append_index(path, gtk_tree_model_iter_n_children(model, &iter) - 1);
      }
      break;
    case UP:
      if (gtk_tree_path_prev(path) == FALSE) {
        /* For some reason gtk_tree_path_up returns TRUE although we're not
         * moving anywhere. */
        is_valid_path = gtk_tree_path_up(path) && (gtk_tree_path_get_depth(path) > 0);
      } else { /* row above */
        while (gtk_tree_view_row_expanded(tree_view, path)) {
          gtk_tree_model_get_iter(model, &iter, path);
          /* select last child */
          gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
                                        gtk_tree_model_iter_n_children(model, &iter)-1);
          gtk_tree_path_free(path);
          path = gtk_tree_model_get_path(model, &child_iter);
        }
      }
      break;
    case COLLAPSE:
      if (gtk_tree_view_collapse_row(tree_view, path) == FALSE
          && gtk_tree_path_get_depth(path) > 1) {
        gtk_tree_path_up(path);
        gtk_tree_view_collapse_row(tree_view, path);
      }
      break;
    case DOWN:
      if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) {
        gtk_tree_path_down(path);
      } else {
        do {
          gtk_tree_model_get_iter(model, &iter, path);
          if (gtk_tree_model_iter_next(model, &iter)) {
            gtk_tree_path_free(path);
            path = gtk_tree_model_get_path(model, &iter);
            break;
          }
        } while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
                && gtk_tree_path_up(path));
      }
      break;
    case EXPAND:
      if (gtk_tree_view_expand_row(tree_view, path, FALSE)) {
        gtk_tree_path_down(path);
      }
      break;
    case EXPAND_ALL:
      gtk_tree_view_expand_all(tree_view);
      break;
    case COLLAPSE_ALL:
      gtk_tree_view_collapse_all(tree_view);
      gtk_tree_path_free(path);
      path = gtk_tree_path_new_first();
      gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
      break;
    case TOGGLE:
      gtk_tree_model_get_iter(model, &iter, path);
      if (gtk_tree_model_iter_has_child(model, &iter) == TRUE) {
        if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) {
          gtk_tree_view_collapse_row(tree_view, path);
        } else {
          gtk_tree_view_expand_row(tree_view, path, FALSE);
        }
        break;
      }
    case SELECT:
      cb_index_row_activated(tree_view, path, NULL, zathura);
      gtk_tree_path_free(path);
      return false;
  }

  if (is_valid_path == TRUE) {
    gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
  }

  gtk_tree_path_free(path);

  return false;
}
Exemplo n.º 27
0
// This little bit is needed to prevent the default drag motion
// handler from expanding rows if you hover over them while
// dragging.
// Also controls where valid drop locations are
G_MODULE_EXPORT gboolean
queue_drag_motion_cb(
    GtkTreeView *tv,
    GdkDragContext *ctx,
    gint x,
    gint y,
    guint time,
    signal_user_data_t *ud)
{
    GtkTreePath *path = NULL;
    GtkTreeViewDropPosition pos;
    gint *indices, row, status, finished;
    GValue *js;
    GtkTreeIter iter;
    GtkTreeView *srctv;
    GtkTreeModel *model;
    GtkTreeSelection *select;
    GtkWidget *widget;

    widget = gtk_drag_get_source_widget(ctx);
    if (widget == NULL || widget != GTK_WIDGET(tv))
        return TRUE;

    // This bit checks to see if the source is allowed to be
    // moved.  Only pending and canceled items may be moved.
    srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx));
    select = gtk_tree_view_get_selection (srctv);
    gtk_tree_selection_get_selected (select, &model, &iter);
    path = gtk_tree_model_get_path (model, &iter);
    indices = gtk_tree_path_get_indices(path);
    row = indices[0];
    gtk_tree_path_free(path);
    js = ghb_array_get_nth(ud->queue, row);
    status = ghb_settings_get_int(js, "job_status");
    if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED)
    {
        gdk_drag_status(ctx, 0, time);
        return TRUE;
    }

    // The reset checks that the destination is a valid position
    // in the list.  Can not move above any finished or running items
    gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos);
    if (path == NULL)
    {
        gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
        return TRUE;
    }
    // Don't allow *drop into*
    if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE)
        pos = GTK_TREE_VIEW_DROP_BEFORE;
    if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER)
        pos = GTK_TREE_VIEW_DROP_AFTER;
    // Don't allow droping int child items
    if (gtk_tree_path_get_depth(path) > 1)
    {
        gtk_tree_path_up(path);
        pos = GTK_TREE_VIEW_DROP_AFTER;
    }
    indices = gtk_tree_path_get_indices(path);
    row = indices[0];
    js = ghb_array_get_nth(ud->queue, row);

    finished = find_last_finished(ud->queue);
    if (row < finished)
    {
        gtk_tree_path_free(path);
        gdk_drag_status(ctx, 0, time);
        return TRUE;
    }
    if (pos != GTK_TREE_VIEW_DROP_AFTER && 
        row == finished)
    {
        gtk_tree_path_free(path);
        gdk_drag_status(ctx, 0, time);
        return TRUE;
    }
    gtk_tree_view_set_drag_dest_row(tv, path, pos);
    gtk_tree_path_free(path);
    gdk_drag_status(ctx, GDK_ACTION_MOVE, time);
    return TRUE;
}
Exemplo n.º 28
0
G_MODULE_EXPORT void 
queue_drag_cb(
    GtkTreeView *dstwidget, 
    GdkDragContext *dc, 
    gint x, gint y, 
    GtkSelectionData *selection_data, 
    guint info, guint t, 
    signal_user_data_t *ud)
{
    GtkTreePath *path = NULL;
    //GtkTreeModel *model;
    GtkTreeViewDropPosition pos;
    GtkTreeIter dstiter, srciter;
    gint *indices, row;
    GValue *js;
    
    GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget);
            
    g_debug("queue_drag_cb ()");
    // This doesn't work here for some reason...
    // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos);
    gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos);
    // This little hack is needed because attempting to drop after
    // the last item gives us no path or pos.
    if (path == NULL)
    {
        gint n_children;

        n_children = gtk_tree_model_iter_n_children(dstmodel, NULL);
        if (n_children)
        {
            pos = GTK_TREE_VIEW_DROP_AFTER;
            path = gtk_tree_path_new_from_indices(n_children-1, -1);
        }
        else
        {
            pos = GTK_TREE_VIEW_DROP_BEFORE;
            path = gtk_tree_path_new_from_indices(0, -1);
        }
    }
    if (path)
    {
        if (gtk_tree_path_get_depth(path) > 1)
            gtk_tree_path_up(path);
        if (gtk_tree_model_get_iter (dstmodel, &dstiter, path))
        {
            GtkTreeIter iter;
            GtkTreeView *srcwidget;
            GtkTreeModel *srcmodel;
            GtkTreeSelection *select;
            GtkTreePath *srcpath = NULL;
            GtkTreePath *dstpath = NULL;

            srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc));
            //srcmodel = gtk_tree_view_get_model(srcwidget);
            select = gtk_tree_view_get_selection (srcwidget);
            gtk_tree_selection_get_selected (select, &srcmodel, &srciter);

            srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
            indices = gtk_tree_path_get_indices(srcpath);
            row = indices[0];
            gtk_tree_path_free(srcpath);
            js = ghb_array_get_nth(ud->queue, row);

            switch (pos)
            {
                case GTK_TREE_VIEW_DROP_BEFORE:
                case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
                    gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel), 
                                                    &iter, NULL, &dstiter);
                    break;

                case GTK_TREE_VIEW_DROP_AFTER:
                case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
                    gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel), 
                                                    &iter, NULL, &dstiter);
                    break;

                default:
                    break;
            }
            // Reset job to pending
            ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING);
            add_to_queue_list(ud, js, &iter);

            dstpath = gtk_tree_model_get_path (dstmodel, &iter);
            indices = gtk_tree_path_get_indices(dstpath);
            row = indices[0];
            gtk_tree_path_free(dstpath);
            ghb_array_insert(ud->queue, row, js);

            srcpath = gtk_tree_model_get_path (srcmodel, &srciter);
            indices = gtk_tree_path_get_indices(srcpath);
            row = indices[0];
            gtk_tree_path_free(srcpath);
            ghb_array_remove(ud->queue, row);
            gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter);
            ghb_save_queue(ud->queue);
        }
        gtk_tree_path_free(path);
    }
}
Exemplo n.º 29
0
/*
 * key pressed event
 */
static gboolean on_key_pressed(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
	guint keyval = ((GdkEventKey*)event)->keyval;
	GtkTreeSelection *selection;
	GList *rows;

	/* do not process event is page is readonly (debug is running) */
	if (readonly)
		return FALSE;

	/* get selected rows */
	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
	rows = gtk_tree_selection_get_selected_rows(selection, &model);
	rows = g_list_sort(rows, (GCompareFunc)gtk_tree_path_compare);

	if (keyval == GDK_Delete && rows && g_list_length(rows))
	{
		GList *breaks, *iter;
		GtkTreeRowReference *new_selection = NULL;
		GtkTreePath *first_path = (GtkTreePath*)rows->data;

		/* "delete selected rows" */

		/* get new selection */
		if (gtk_tree_path_get_depth(first_path) > 1)
		{
			new_selection = get_unselected_sibling(first_path);
		}
		if (!new_selection)
		{
			GtkTreePath *file_path = gtk_tree_path_copy(first_path);
			if (gtk_tree_path_get_depth(file_path) > 1)
			{
				gtk_tree_path_up(file_path);
			}
			new_selection = get_unselected_sibling(file_path);
			gtk_tree_path_free(file_path);
		}
		
		/* collect GList of breakpoints to remove
		if file row is met - add all unselected breaks to the list as well */
		breaks = NULL;
		for (iter = rows; iter; iter = iter->next)
		{
			GtkTreePath *path = (GtkTreePath*)iter->data;
			GtkTreeIter titer;
			
			gtk_tree_model_get_iter(model, &titer, path);
			
			if (1 == gtk_tree_path_get_depth(path))
			{
				GtkTreeIter citer;
				gtk_tree_model_iter_children(model, &citer, &titer);
				
				do
				{
					if (!gtk_tree_selection_iter_is_selected(selection, &citer))
					{
						gchar *file = NULL;
						gint line;
						breakpoint *bp;

						gtk_tree_model_get(model, &titer, FILEPATH, &file, -1);
						gtk_tree_model_get(model, &citer, LINE, &line, -1);

						bp = breaks_lookup_breakpoint(file, line);
						
						breaks = g_list_append(breaks, bp);
						
						g_free(file);
					}
				}
				while(gtk_tree_model_iter_next(model, &citer));
			}
			else
			{
				GtkTreeIter piter;
				gchar *file = NULL;
				gint line;
				breakpoint *bp;

				gtk_tree_model_iter_parent(model, &piter, &titer);
				
				gtk_tree_model_get(model, &piter, FILEPATH, &file, -1);

				gtk_tree_model_get(model, &titer, LINE, &line, -1);

				bp = breaks_lookup_breakpoint(file, line);
				
				breaks = g_list_append(breaks, bp);
				
				g_free(file);
			}
		}
		
		if (1 == g_list_length(breaks))
		{
			breakpoint *bp = (breakpoint*)breaks->data;
			g_list_free(breaks);
			breaks_remove(bp->file, bp->line);
		}
		else
		{
			breaks_remove_list(breaks);
		}

		if (new_selection)
		{
			/* get path to select */
			GtkTreePath *path = NULL;
			path = gtk_tree_row_reference_get_path(new_selection);

			gtk_tree_selection_select_path(selection, path);
			gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(widget), path, NULL, TRUE, 0.5, 0.5);
			gtk_tree_path_free(path);

			gtk_tree_row_reference_free(new_selection);
		}
	}

	/* free rows list */
	g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
	g_list_free (rows);

	return FALSE;
}
Exemplo n.º 30
0
static gboolean
bookmark_tree_store_row_drop_possible (GtkTreeDragDest  *drag_dest,
                                       GtkTreePath      *dest_path,
                                       GtkSelectionData *selection_data)
{
    GtkTreeModel *src_model = NULL;
    GtkTreePath *src_path = NULL;
    GtkTreePath *tmp = NULL;
    gboolean retval = FALSE;
    GtkTreeIter iter;
    GNode *src_node, *dst_node;
    gftp2_bookmark *src_bm, *dst_bm;
  
    if (!gtk_tree_get_row_drag_data (selection_data,
                                     &src_model,
                                     &src_path))
        goto out;

/*
    fprintf (stderr, "%s -to- %s", 
             gtk_tree_path_to_string (src_path), 
             gtk_tree_path_to_string (dest_path));
*/
    
    /* can only drag to ourselves */
    if (src_model != GTK_TREE_MODEL (drag_dest))
        goto out;

    /* Can't drop into ourself. */
    if (gtk_tree_path_is_ancestor (src_path,
                                   dest_path))
        goto out;

    /* Can't drop if dest_path's parent doesn't exist */
    if (gtk_tree_path_get_depth (dest_path) > 1)
    {
        tmp = gtk_tree_path_copy (dest_path);
        gtk_tree_path_up (tmp);
        
        if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_dest),
                                      &iter, tmp))
            goto out;

        gtk_tree_model_get (src_model, &iter, /* src_model == dst_model */
                            COLUMN_ENTRY, &dst_node,
                            -1);
        g_assert (dst_node);
        dst_bm = (gftp2_bookmark *)dst_node->data;
        /* can't drag an item into a non-folder */
        if (!dst_bm->is_folder)
            goto out;

        gtk_tree_model_get_iter (src_model, &iter, src_path);
        gtk_tree_model_get (src_model, &iter, 
                            COLUMN_ENTRY, &src_node,
                            -1);
        g_assert (src_node);
        src_bm = (gftp2_bookmark *)src_node->data;
        /* can't drag folder into a folder */
        if (src_bm->is_folder)
            goto out;
    }


    /* Can otherwise drop anywhere. */
    retval = TRUE;

out:
    /* fprintf (stderr, " %s\n", retval ? "Can drop" : "Can't drop"); */

    if (src_path)
        gtk_tree_path_free (src_path);
    if (tmp)
        gtk_tree_path_free (tmp);

    return retval;
}