コード例 #1
0
ファイル: project-model.c プロジェクト: rosedu/anjuta
/* 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);
}
コード例 #2
0
void on_liststore_recordedMotions_row_inserted(
    GtkTreeModel* model,
    GtkTreePath* path,
    GtkTreeIter* iter,
    gpointer user_data)
{
  gint* indices;
  int depth;
  if(g_dnd) {
    indices = gtk_tree_path_get_indices_with_depth(path, &depth);
    //printf("Row Inserted: %d\n", indices[0]);
    g_dndInsertIndex = indices[0];
    g_dndInsertIndexValid = true;

    printf("%d %d\n", g_dndRemoveIndexValid, g_dndInsertIndexValid);
    if(g_dndRemoveIndexValid && g_dndInsertIndexValid) {
      g_dndRemoveIndexValid = false;
      g_dndInsertIndexValid = false;
      recordMobot_t *m;
      m = g_robotManager->getMobot(0);
      for(int i = 1; m != NULL; i++) {
        RecordMobot_moveMotion(m, g_dndRemoveIndex, g_dndInsertIndex);
        m = g_robotManager->getMobot(i);
      }
      teachingDialog_refreshRecordedMotions(-1);
    }
  }
}
コード例 #3
0
static gboolean
dspy_introspection_model_get_iter (GtkTreeModel *model,
                                   GtkTreeIter  *iter,
                                   GtkTreePath  *tree_path)
{
  DspyIntrospectionModel *self = (DspyIntrospectionModel *)model;
  DspyNode *cur;
  gint *indices;
  gint depth;

  LOG_DEBUG (G_STRFUNC);

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

  memset (iter, 0, sizeof *iter);

  cur = (DspyNode *)self->root;
  indices = gtk_tree_path_get_indices_with_depth (tree_path, &depth);

  for (guint i = 0; cur != NULL && i < depth; i++)
    {
      gint pos = indices[i];

      if (cur->any.parent == NULL)
        cur = g_queue_peek_nth (&cur->node.nodes, pos);
      else if (cur->any.kind == DSPY_NODE_KIND_NODE)
        cur = (DspyNode *)cur->node.interfaces;
      else if (cur->any.kind == DSPY_NODE_KIND_INTERFACES)
        cur = g_queue_peek_nth (&cur->interfaces.interfaces, pos);
      else if (cur->any.kind == DSPY_NODE_KIND_INTERFACE)
        {
          if (pos == 0)
            cur = (DspyNode *)cur->interface.properties;
          else if (pos == 1)
            cur = (DspyNode *)cur->interface.signals;
          else if (pos == 2)
            cur = (DspyNode *)cur->interface.methods;
          else
            cur = NULL;
        }
      else if (cur->any.kind == DSPY_NODE_KIND_PROPERTIES)
        cur = g_queue_peek_nth (&cur->properties.properties, pos);
      else if (cur->any.kind == DSPY_NODE_KIND_SIGNALS)
        cur = g_queue_peek_nth (&cur->signals.signals, pos);
      else if (cur->any.kind == DSPY_NODE_KIND_METHODS)
        cur = g_queue_peek_nth (&cur->methods.methods, pos);
      else
        cur = NULL;
    }

  if (cur != NULL)
    {
      iter->user_data = cur;
      return TRUE;
    }

  return FALSE;
}
コード例 #4
0
ファイル: project-model.c プロジェクト: rosedu/anjuta
static void
gbf_project_model_merge (GtkTreeModel *model,
                         GtkTreePath *begin,
                         GtkTreePath *half,
                         GtkTreePath *end,
                         GtkTreeIterCompareFunc compare_func,
                         gpointer user_data)
{
	GtkTreeIter right;
	GtkTreeIter left;

	if (gtk_tree_model_get_iter (model, &left, begin) &&
	    gtk_tree_model_get_iter (model, &right, half))
	{
		gint depth;
		gint ll, lr;

		
		/* Get number of elements in both list */
		ll = (gtk_tree_path_get_indices_with_depth (half, &depth)[depth - 1]
		      - gtk_tree_path_get_indices_with_depth (begin, &depth)[depth - 1]);
		lr = (gtk_tree_path_get_indices_with_depth (end, &depth)[depth - 1]
		      - gtk_tree_path_get_indices_with_depth (half, &depth)[depth - 1]);

		while (ll && lr)
		{
			if (compare_func (model, &left, &right, user_data) <= 0)
			{
				gtk_tree_model_iter_next (model, &left);
				ll--;
			}
			else
			{
				GtkTreeIter iter;

				iter = right;
				gtk_tree_model_iter_next (model, &right);
				lr--;
				gtk_tree_store_move_before (GTK_TREE_STORE (model), &iter, &left);
			}
		}
	}
}
コード例 #5
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;
}
コード例 #6
0
ファイル: tree_view_categories.c プロジェクト: avgo/avgmoney
void TreeViewCategories_Paste(TreeViewCategories* c, unsigned int IsRoot)
{
	GtkTreeModel* tree_model;
	GtkTreePath* TreePathMoveDst;
	gint* indices_src;
	gint depth_src;
	gint* indices_dst;
	gint depth_dst;
	gchar* NameSrc;
	gchar* NameDst;
	int i;
	GtkTreeIter iter_dst;
	GtkTreeIter* iter_dst_ptr;
	GtkTreeIter iter_src;
	
	
	if (c->TreePathMoveSrc == NULL)
	{
		return ;
	}
	
	tree_model = gtk_tree_view_get_model(GTK_TREE_VIEW(c->treeview));
	gtk_tree_model_get_iter(tree_model, &iter_src, c->TreePathMoveSrc);
	NameSrc = gtk_tree_path_indices_name_gen(c->TreePathMoveSrc, "cat-src://", "/");
	
	if (IsRoot)
	{
		TreePathMoveDst = NULL;
		iter_dst_ptr = NULL;
		NameDst = gtk_tree_path_indices_name_gen(TreePathMoveDst, "cat-dst://", "/");
		
		g_print("%s\n"
		        "%s.", NameSrc, NameDst);
		
		indices_src = gtk_tree_path_get_indices_with_depth(c->TreePathMoveSrc, &depth_src);
		
		if (depth_src == 1)
		{
			g_print(" Исходное и конечное совпадают.\n\n");
			goto PASTE_FAIL;
		}
		g_print("\n\n");
	}
	else
	{
		gtk_tree_view_get_cursor(GTK_TREE_VIEW(c->treeview), &TreePathMoveDst, NULL);
		
		if (TreePathMoveDst == NULL)
		{
			goto PASTE_FAIL;
		}
		
		gtk_tree_model_get_iter(tree_model, &iter_dst, TreePathMoveDst);
		iter_dst_ptr = &iter_dst;
		NameDst = gtk_tree_path_indices_name_gen(TreePathMoveDst, "cat-dst://", "/");
		
		g_print("%s\n"
		        "%s.", NameSrc, NameDst);
		
		indices_src = gtk_tree_path_get_indices_with_depth(c->TreePathMoveSrc, &depth_src);
		indices_dst = gtk_tree_path_get_indices_with_depth(TreePathMoveDst, &depth_dst);
		
		for (i = 0; i < depth_src && i < depth_dst; ++i)
		{
			if (indices_src[i] != indices_dst[i])
				break;
		}
		if (i == depth_src)
		{
			g_print(" В себя же нельзя.\n\n");
			goto PASTE_FAIL;
		}
		if (i + 1 == depth_src && i == depth_dst)
		{
			g_print(" Исходное и конечное совпадают.\n\n");
			goto PASTE_FAIL;
		}
		g_print("\n\n");
	}
	
	gtk_tree_store_move(GTK_TREE_STORE(tree_model), &iter_src, iter_dst_ptr);
	
	c->cat_update.new_cat_id = c->new_cat_id;
	c->cat_update.MySQL = c->MySQL;
	
	TreeViewCategories_Enumerate(c, GTK_TREE_STORE(tree_model), NULL, 0);
	CatUpdate_Execute(&c->cat_update);
	CatUpdate_Free(&c->cat_update);
	
	gtk_tree_path_free(c->TreePathMoveSrc);  c->TreePathMoveSrc = NULL;

PASTE_FAIL:

	if (TreePathMoveDst != NULL)
		gtk_tree_path_free(TreePathMoveDst);
	
	if (NameSrc != NULL)
		g_free(NameSrc);
	if (NameDst != NULL)
		g_free(NameDst);
}
コード例 #7
0
ファイル: form_accounts.c プロジェクト: avgo/avgmoney
void FormAccounts_ButtonAccountRenameClicked(GtkButton* button, FormAccounts* fa)
{
	gchar* Text = NULL;
	gchar* TextOld = NULL;
	gchar* msg = NULL;
	GtkTreeModel* model;
	GtkTreePath* path = NULL;
	GtkTreeIter iter;
	gint* indices;
	gint depth;
	gint count;
	gint last_items_count = 1;
	gint last_account_item_index;
	gint cur_item_index;
	MYSQL_STMT* stmt = NULL;
	MYSQL_BIND param_update[2];
	unsigned long TextStrLength;
	const char* mysql_stmt_str = "UPDATE accounts SET name = ? WHERE id = ?;";
	gchar* id_str = NULL;
	unsigned int id;
	
	
	
	gtk_tree_view_get_cursor(GTK_TREE_VIEW(fa->ListViewAccounts), &path, NULL);
	
	if (path == NULL)
	{
		g_print("Ни один элемент не выбран.\n");
		goto END;
	}
	indices = gtk_tree_path_get_indices_with_depth(path, &depth);
	if (depth < 1)
		goto END;
	cur_item_index = indices[0];
	
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(fa->ListViewAccounts));
	count = gtk_tree_model_iter_n_children(model, NULL);
	if (count <= last_items_count)
		goto END;
	last_account_item_index = count - last_items_count - 1;
	if (cur_item_index > last_account_item_index)
		goto END;
	
	if (!gtk_tree_model_get_iter(model, &iter, path))
		goto END;
	gtk_tree_model_get(model, &iter,
			COL_ID_ACCOUNT_ID, &id_str,
			COL_ID_NAME,       &TextOld, -1);
	if (!id_str)
		goto END;
	id = strtoul(id_str, NULL, 10);
	
	msg = g_strdup_printf("Введите новое наименование для счёта «%s».", TextOld);
	gtk_input_dialog("Переименовать счёт", msg, TextOld, &Text);
	
	if (Text)
	{
		stmt = mysql_stmt_init(fa->MySQL);
		if (stmt == NULL)
		{
			g_print("%s(): mysql_stmt_init() error.\n", __func__);
			goto END;
		}
		
		if (mysql_stmt_prepare(stmt, mysql_stmt_str, strlen(mysql_stmt_str)))
		{
			g_print("%s(): mysql_stmt_prepare() error.\n", __func__);
			goto END;
		}
		
		TextStrLength = strlen(Text);
		memset(param_update, 0, sizeof(param_update));
		
		param_update[0].buffer_type   = MYSQL_TYPE_VAR_STRING;
		param_update[0].buffer        = (void*) Text;
		param_update[0].buffer_length = TextStrLength + 1;
		param_update[0].length        = &TextStrLength;
		
		param_update[1].buffer_type    = MYSQL_TYPE_LONG;
		param_update[1].buffer         = (void*) &id;
		param_update[1].is_unsigned    = 1;
		
		if (mysql_stmt_bind_param(stmt, param_update))
		{
			g_print("%s(): mysql_stmt_bind() error.\n", __func__);
			goto END;
		}
		
		if (mysql_stmt_execute(stmt))
		{
			g_print("%s(): mysql_stmt_bind() error.\n", __func__);
			goto END;
		}
		
		FormAccounts_UpdateData(fa);
	}
	
END:
	if (msg)      g_free(msg);
	if (Text)     g_free(Text);
	if (TextOld)  g_free(TextOld);
	if (path)     gtk_tree_path_free(path);
	if (id_str)   g_free(id_str);
	if (stmt)     mysql_stmt_close(stmt);
}