|
|
|
Problem with insert and append GtkIconview 4 Months, 1 Week ago
|
Karma: 0
|
|
Hello ,
sometimes when I move an Icon in my gtkiconview on the last icon it disappears and I can't find it where the error is.
here is the code
public function on_drop($widget, $context, $x, $y, $data, $info, $time)
{
$drop_info = $widget->get_dest_item_at_pos($x, $y); // check for insert or append
$data = unserialize(urldecode($data->get_text()));
if ($drop_info) {
list($path, $position) = $drop_info; // get the insert position
$func = 'insert';
if ($position == Gtk::TREE_VIEW_DROP_BEFORE ||
$position == Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE) {
$pos = $path[0];
} else {
$pos = $path[0]+1;
}
} else {
$func = 'append';
}
foreach ($data as $element)
{
$titel = $element[0] ;
$filepath = $element[1];
//first remove icon if it is a move inside the same iconview we are performing
if ($this->_TreeIconViewId == $element[3])
{
$iter = $this->_modelfilter->get_iter($element[2]);
$convertediter = $this->_modelfilter->convert_iter_to_child_iter($iter);
$this->_model->get_path($convertediter);
$this->_model->remove($convertediter);
}
if ($func == 'insert')
{
echo "it is an insert";
$iter = $this->_modelfilter->get_iter($pos);
$div_id = $this->_modelfilter->get_value($iter,3);
$convertediter = $this->_modelfilter->convert_iter_to_child_iter($iter);
$pos_base = $this->_model->get_path($convertediter);
$this->_model->insert($pos_base[0],array($titel,$this->create_thumbnail($filepath),$filepath,$div_id,1));
}
else // for an append
{
echo "it is an append";
$this->_selection = $this->_divview->get_selection();
list($model,$iter)=$this->_selection->get_selected();
$div_id = $model->get_value($iter,2);
$this->_model->append(array($titel,$this->create_thumbnail($filepath),$filepath,$div_id,1));
}
}
$this->_iconview->set_model($this->_modelfilter);
$this->_iconview->emit_stop_by_name('drag_data_received');
}
Thx
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 254
|
|
Re:Problem with insert and append GtkIconview 4 Months, 1 Week ago
|
Karma: 7
|
|
Hi Wim,
Is it possible that you come out with a smaller self-contained code that we could run to replicate the problem?
It's really difficult to debug without seeing the actual problem...
Alternatively, looking at your code given above, since you know your codes better, I would suggest that you take a closer look at those iters and paths you are converting back and forth between the model and modelfilter. Although it's difficult to examine the iter, you can convert all iter to path and echo a copy of the path to see if they are correct (especially at the remove and insert/append point).
Regards,
/kksou
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Problem with insert and append GtkIconview 4 Months, 1 Week ago
|
Karma: 0
|
|
public function on_drop($widget, $context, $x, $y, $data, $info, $time)
{
$drop_info = $widget->get_dest_item_at_pos($x, $y); // check for insert or append
$data = unserialize(urldecode($data->get_text()));
if ($drop_info) {
list($path, $position) = $drop_info; // get the insert position
$func = 'insert';
if ($position == Gtk::TREE_VIEW_DROP_BEFORE ||
$position == Gtk::TREE_VIEW_DROP_INTO_OR_BEFORE) {
$pos = $path[0];
$dropkind = 1;
echo "drop into or before";
} else {
$pos = $path[0]+1;
echo "drop after";
$dropkind = 1;
}
} else {
$func = 'append';
}
foreach ($data as $element)
{
$titel = $element[0] ;
$filepath = $element[1];
//first remove icon if it is a move inside the same iconview we are performing
if ($this->_TreeIconViewId == $element[3])
{
if ($pos > 0)
{$pos = $pos - $dropkind;} // if we move in the same GtkIconView we do not need to add 1 the path
$iter = $this->_modelfilter->get_iter($element[2]);
$convertediter = $this->_modelfilter->convert_iter_to_child_iter($iter);
$this->_model->remove($convertediter);
}
//insert the dragged icon in to its place
if ($func == 'insert')
{
echo "it is an insert";
$iter = $this->_modelfilter->get_iter($pos);
$div_id = $this->_modelfilter->get_value($iter,3);
$convertediter = $this->_modelfilter->convert_iter_to_child_iter($iter);
$pos_base = $this->_model->get_path($convertediter);
$this->_model->insert($pos_base[0],array($titel,$this->create_thumbnail($filepath),$filepath,$div_id,1));
}
else // for an append
{
echo "it is an append";
$this->_model->append(array($titel,$this->create_thumbnail($filepath),$filepath,$div_id,1));
}
}
$this->_iconview->set_model($this->_modelfilter);
$this->_iconview->emit_stop_by_name('drag_data_received');
}
Hello Everybody
I found it what the problem was in kksou example of drag and drop you at 1 up to the path. But if you do a move you don't need to add this 1 up since you first remove an item.
So I check if it is a drop after and if it is call it 1
and if it is in the same gtkiconview I reset the path position by the little formule $pos = $ pos - $dropkind;
but if you do this you must first check if your $pos is bigger than 0. This isn't the case if you drag an item before the first item in your list.
that's it
thx for the support
So kksou , you could add this to your example of drag drop gtkiconview part4 doing a drag to other gtkiconview as wel as a move inside the same iconview.
see ya
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|