Example #1
0
void PlacesView::onMoveBookmarkDown()
{
  PlacesModel::ItemAction* action = static_cast<PlacesModel::ItemAction*>(sender());
  if(!action->index().isValid())
    return;
  PlacesModelBookmarkItem* item = static_cast<PlacesModelBookmarkItem*>(model_->itemFromIndex(action->index()));

  int row = item->row();
  if(row < model_->rowCount()) {
    FmBookmarkItem* bookmarkItem = item->bookmark();
    FmBookmarks* bookmarks = fm_bookmarks_dup();
    fm_bookmarks_reorder(bookmarks, bookmarkItem, row + 1);
    g_object_unref(bookmarks);
  }
}
Example #2
0
static void on_drag_data_received ( GtkWidget *dest_widget,
                GdkDragContext *drag_context, gint x, gint y,
                GtkSelectionData *sel_data, guint info, guint time)
{
    FmPlacesView* view = FM_PLACES_VIEW(dest_widget);
    GtkTreePath* dest_tp = NULL;
    GtkTreeViewDropPosition pos;

    gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(view), x, y, &dest_tp, &pos);
    switch(info)
    {
    case FM_DND_DEST_TARGET_BOOOKMARK:
        if(get_bookmark_drag_dest(view, &dest_tp, &pos)) /* got the drop position */
        {
            GtkTreePath* src_tp;
            /* get the source row */
            gboolean ret = gtk_tree_get_row_drag_data(sel_data, NULL, &src_tp);
            if(ret)
            {
                /* don't do anything if source and dest are the same row */
                if(G_UNLIKELY(gtk_tree_path_compare(src_tp, dest_tp) == 0))
                    ret = FALSE;
                else
                {
                    /* don't do anything if this is not a bookmark item */
                    if(!fm_places_model_path_is_bookmark(FM_PLACES_MODEL(model), src_tp))
                        ret = FALSE;
                }
                if(ret)
                {
                    GtkTreeIter src_it, dest_it;
                    FmPlaceItem* item = NULL;
                    ret = FALSE;
                    /* get the source bookmark item */
                    if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &src_it, src_tp))
                        gtk_tree_model_get(GTK_TREE_MODEL(model), &src_it, FM_PLACES_MODEL_COL_INFO, &item, -1);
                    if(item)
                    {
                        /* move it to destination position */
                        if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &dest_it, dest_tp))
                        {
                            int new_pos, sep_pos;
                            /* get index of the separator */
                            const GtkTreePath* sep_tp = fm_places_model_get_separator_path(FM_PLACES_MODEL(model));
                            sep_pos = gtk_tree_path_get_indices(sep_tp)[0];

                            if(pos == GTK_TREE_VIEW_DROP_BEFORE)
                                gtk_list_store_move_before(model, &src_it, &dest_it);
                            else
                                gtk_list_store_move_after(model, &src_it, &dest_it);
                            new_pos = gtk_tree_path_get_indices(dest_tp)[0] - sep_pos - 1;
                            /* reorder the bookmark item */
                            fm_bookmarks_reorder(FM_PLACES_MODEL(model)->bookmarks, item->bm_item, new_pos);
                            ret = TRUE;
                        }
                    }
                }
                gtk_tree_path_free(src_tp);
            }
            gtk_drag_finish(drag_context, ret, FALSE, time);
        }
        break;
    default:
        /* check if files are received. */
        fm_dnd_dest_drag_data_received(view->dnd_dest, drag_context, x, y, sel_data, info, time);
        break;
    }
    if(dest_tp)
        gtk_tree_path_free(dest_tp);
}