Re: GtkToolbar drag and drop



Marco Pesenti Gritti <marco gnome org> writes:

> 1 Keep the throbber visible at the end of the toolbar, after the
> overflow menu arrow. I think this is a strong requirement, being a form
> of feedback and not a faster way to access a function available from the
> menubar.
> 2 Have an efficient way of achieve user tasks (add spinner to a toolbar,
> remove spinner from a toolbar, move spinner from a toolbar to another).
> 3 Keep the user model the simpler is possible

Sorry about taking so long to get back to this. How does this sound:

        - get rid of GtkToolItem::pack_end as it's only useful for
          spinners.

        - add a new gtk_toolbar_set_end_item() that inserts a tool
          item in spinner position. This function could take NULL for
          the new tool item in which case the existing item, if any,
          would be removed.

        - Change gtk_toolbar_get_drop_position() to be:

           gboolean gtk_toolbar_get_drop_position (GtkToolbar *toolbar, 
                                                    int         x
                                                    int         y,
                                                    int        *pos)

          that would return TRUE if the indicated (x, y) corresonds to
          a valid drop location. In that case, 

               if *pos is non-negative, indicates the position where 
               the new item should be inserted. 

               If *pos is negative, indicates that the new item should 
               be added to the end of the toolbar.

          This function only indicates the "spinner" position as
          as valid drop target if the toolbar doesn't have a tool item
          in that position already.
        
        - add API 

                gtk_toolbar_highlight_drop_location (GtkToolbar *toolbar,
                                                     int         x,
                                                     int         y,
                                                     GtkToolItem *new_item)

                gtk_toolbar_unhighlight_drop_position (GtkToolbar *);

          that would [un]highlight corresponding position on the
          toolbar.

This API achieves:

        - ability to have zero or one spinners on the toolbar

        - good feedback on drag and drop.

        - some simplification of the gtktoolbar.c and gtktoolitem.c

        - expanding spacers can be added later if we decide it's a
          good idea (which I still think it might be).

The sacrifice is the ability to have more than one tool item in
spinner position, which is acceptable in my opinion.


Søren




The following is a sketch of how the toolbar editor would work:

Example: The toolbar editor's drag_motion handler would be something
like

    void drag_motion (toolbar, x, y)
    {
        int new_pos;

        if (gtk_toolbar_get_drop_position (toolbar, x, y, &new_pos) &&
            ((new item is spinner && new_pos < 0) ||
             (new item is not spinner && new_pos >= 0)))
        {
            gdk_drag_status (context, <action>, time);
            gtk_toolbar_highlight_drop_location (toolbar, x, y, new_item);
            return TRUE;
        }
        else
        {
            gdk_drag_status (context, 0, time);
            gtk_toolbar_unhighlight_drop_location (toolbar);
            return FALSE;
        }
    }

and drag_leave():

    void drag_leave (toolbar)
    {
        gtk_toolbar_unhighlight_drop_location (toolbar);
    }

Accepting the drop would be like

    void drag_drop (toolbar, ..., x, y, ...)
    {
        int new_pos;

        if (gtk_toolbar_get_drop_location (toolbar, x, y, &new_pos))
        {
            if (new item is spinner && new_pos < 0)
            {
                gtk_toolbar_set_end_item (toolbar, x, y, new_item);
            }
            else if (new item is not spinner && new_pos >= 0)
            {
                gtk_toolbar_insert (toolbar, new_pos, new_item);
            }
            else
            {
                g_assert_not_reached();
            }
        }
        else
        {
            g_assert_not_reached ();
        }
    }


        




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]