Function to add item at specific index needed

Bug #1323440 reported by Timothy on 2014-05-27

This bug report was converted into a question: question #249338: Function to add item at specific index needed.

This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

I've been poking around in the rapid paste plugin branch. Got it working with the current version Diodon. After getting it working I noticed it did not work as I would have expected. First press it pastes the first item, second press pastes the second item and moves it to top, third press pastes the third item and moves it to the top, and so on. I would have expected the first press to paste the first item and move it to the bottom, second press to paste the first item and move it to the bottom, and so on. After some digging I discovered that the only way to move an item to the bottom is to remove all the items then re-add them in the new order. A function that could add an item at a specific index would be very useful in this situation. Also I could definitely see it being useful in other plugins as well.

Oliver Sauder (sao) wrote :

There is a new concept how Diodon works since version 1.1.0 which where it is not possible to add any items in a different order. I therefore converted this bug into a question so to see whether we find another solution for your problem.

But let me explain how Diodon records its clipboard items as of version 1.1.0.

There are two parts of Diodon. A backend part which listens whether there are any new items available in the clipboard. If that's the case it will add a new event to Zeitgeist which states date, what data has been copied and a unique checksum to identify it.

Then there is another part the user interface in different variants which gives you access to the history of events (which by now is not limited by a number but solely will be available till it is deleted). The application indicator menu is then a simple representation of the recent clipboard items (or recent Zeitgeist events as you will). When you click on an item the indicator will perform a copy event which the backend will trigger and add it to the Zeitgeist event database. Zeitgeist on the other hand will then tell that a event has been changed so the menu can be rebuilt with the newest recent items.

So this prevents changing of any order of the menu as this would break the whole concept of simply triggering of copy events and making it accessible in many different means. This said let's discuss how we could overcome your issue:

1. As the last item in the menu is not the last available item but the last recent item (e.g. if 25 is shown the recent clipboard item with position 25) and first item is most recent copied item would it be confusing putting items at the end of the list or at the beginning would confuse the user (especially if this happens suddenly just when enabling a plugin). My question therefore is whether the menu actually needs to be adjusted for your plugin? What you could do is to leave the menu as is but just record how many times items have been "poped" of the list. If you have such an index whenever the user wants to pop another item you can identify which item of the recent items this is.

2. There is still a way to create a menu but you would need to create a new menu yourself in your plugin. There are some API changes needed that you can do this (e.g. changing of accessibility rights), but let's discuss first whether you think that's a way ahead before I make any API changes.
There is a class ClipboardMenu which can be fed with ClipboardItems. So when user starts "pop and paste" you then safe that state of items in your plugin and built a menu with it. User needs to have access to menu which can be a shortcut or another indicator etc. as you go along with pop and paste you have the full list of recent items at the time and you have to modify the order of the list as you go and recreate the menu. You would have full control over the menu and can adjust it as you need it.

Hope this clarifies. Let me know what you think.

Changed in diodon:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers