ListBox: How to change the value of “action As Integer”

After a long quest, at last, I finally found a clue on how to use it…

This is a Class Constant that have some explanation here.

Some other explanation exists here, an important line is:

[quote]The Action parameter specifies the drag action, which is typically done by holding down a modifier key (Shift, Alt, Option, Command, etc.) while doing the drag. It can take the following class constants of the DragItem class[/quote].
The most important part of teh sentence above is:
which is typically done by holding down a modifier key (Shift, Alt, Option, Command, etc.) while doing the drag

In fact, the only modifier that returns some value that is not 0 (DragItem.DragActionDefault) is the Option Key (in my MacBook keyboard).

All other modifier keys returns 0 or do nothing at all:

Command: select or deselect a Row; cannot do anything unless pressed during the drag, but action = 0 in that case.

Shift: Add or remove contiguous Rows; cannot do anything unless pressed during the drag, but action = 0 in that case.

alt Same as the option key when running OS X. Have to be tested on Windows for more details.

Shift-Lock Also returns 0 (zero).

So, as far as I can see, beside Action Default and Action Copy, the two other Constants cannot be used: Action Move and Action Link.

And for the meaning of the actions, I only can suppose that:
Action Default The default value (whatever it can be; I feel for ActionMove)
Action Copy The developer have to add the code to copy the selected Rows (teh dragged Rows)
Action Move The current default mode: Move the selected rows to the new location (to be computed because DropObject does not have x,y)
Action Link I can only dream about what this can be used for.

Origin of the action parameter

[code]Release Notes (2006r2):
[New] [All] Drag 'n Drop:
Added an additional parameter (Action As Integer) to the DropObject, DragEnter, DragExit and DragOver events. This parameter specifies the drag action, which can take on the value of any one of the following:

        DragItem.DragActionDefault = 0
        DragItem.DragActionCopy = 1
        DragItem.DragActionMove = 2
        DragItem.DragActionLink = 3[/code]

That is all I found in that subject. Ideas ?

[quote=203420:@Emile Schwarz]Origin of the action parameter

Release Notes (2006r2):
[New] [All] Drag 'n Drop:
Added an additional parameter (Action As Integer) to the DropObject, DragEnter, DragExit and DragOver events. This parameter specifies the drag action, which can take on the value of any one of the following:

        DragItem.DragActionDefault = 0
        DragItem.DragActionCopy = 1
        DragItem.DragActionMove = 2
        DragItem.DragActionLink = 3[/quote]

No need to dive in the release notes. It is well documented in the LR for all Drag events :
http://documentation.xojo.com/index.php/RectControl.DragEnter

I arrived there by clicking DragEnter on the LR ListBox page. Keep it simple :wink:

Fine, even if I noted that (release notes).

And how do you change the value of action ? (in other words: where is the documentation ?)

I ask because:

is not something I qualify of “well documented”.

You will get the same kind of data in some more pages (DragExit and DragOver for examples).

Nota: I tell “I’m drowning” and your answer is “swim !” ?

[quote=203427:@Emile Schwarz]Fine, even if I noted that (release notes).

And how do you change the value of action ? (in other words: where is the documentation ?)

I ask because:

is not something I qualify of “well documented”.

You will get the same kind of data in some more pages (DragExit and DragOver for examples).

Nota: I tell “I’m drowning” and your answer is “swim !” ?[/quote]

Have you looked at the DragAndDrop example in Desktop ?

If you read carefully the LR, it explains the values are constants. Action is not modifiable. It just tells you what is going on.

I just slightly modified the ListBoxesDragAndDrop example, added DragEnter to the DragListbox (the one on the right where things are dropped). If I simply move the text line from the listbox on the left, I get zero (DragItem.DragActionDefault). If I hold the Option key while dragging I get the copy cursor with the green +, and Action becomes 1 (DragItem.DragActionCopy = 1). This probably intended to be use with a Select Case to do additional processing.

I quickly looked under Mac and Windows, it seems indeed Action is zero as default and 1 when holding Option. On Windows, default is 2 and holding Control makes 1 like Option.

In that respect, Windows default Action seems more adequate, since in the example the item is moved from one listbox to another.

I would tend instead of using Action, to employ KeyBoard.AsyncKeyDown to see exactly which modifiers are down.

The question “How to I change the value of ‘ACTION’”, answer as Michel mentioned… you don’t
Its not for YOU to decide, it is the OS/App telling YOU what is happening. 99.999% of the time most developers ignore it

I get an eye of the answers above and I hop my text below is correct. I will read it back later today.

Michel: thank you for your searches and answers.

This sentence is misleading. I am able to change this value (as you discovers later) by pressing the Option Key (OS X). So that value is modifiable by an action of the user.

To update where I am actually, I dropped the whole idea of “action“ because it does not works.

I woke up early this morning (around 4) and make intensive searched. Finally I used for my testings the Apple concept for make a copy (as seen anywhere / everywhere from the Finder to applications): use Option-Drag.

Unfortunately (read one of my other posts), there are troubles there too.

Dave: thank you for your answer.
In fact, your answer takes the developer point of view stricto sensu. My question took the user into account plus the developer point of view.

Somewhere in the applciation run, DragItem.Action is set by the user (pressing a Modifier Key) and we, as developers have to add code to take that into account.

99.999% of the time most developers ignore it
You are correct (IMHO at 100% here) I ignored it (since 2006, so 9 years !) until recently when I wanted to know its usage, vaguely figuring I can have an usage for it.

At last, in the documentation, the Drag.Over page is the most complete even if the list of the Modifier Keys is incomplete.

FWIW: List of the Modifier Keys (MacBook)

Command Key Control Key Option Key Shift Key Caps Lock Function Key
That does not means all of these will modify the action parameter.

What I meant is that the title was somehow implying that parameter could be altered when in fact it is returned by the system.

As for being modifiable with the keyboard, this is largely inaccurate, as the tests I reported about easily show. With the DragAndDrops project, on Mac, one never gets Move that is the default behavior of the program, just zero. Indeed Copy works, but that is it. On Windows, Move and Copy work.

My deep conviction is that Action is flaky, and altogether inadvisable for a cross platform program. For myself, I would replace that by KeyBoard.AsyncKeyDown which at least gives a good picture of the modifiers. As usual, in the end, you do as you please. Don’t complain Action bit you :wink:

Don’t forget that Link involves two modifiers. Command and Option.

Thanks Greg,

I think that I checked all Modifier Keys combination… but I will check that specifically.

That said, I do not know (for sure, even if I can think at things) what ActionLink can do.

Michel,
OK, if you want to call that like this.

But, for me, if the user (the person who buy your software) have a way to make the OS modify the “action” value, my title have a wrong understanding. Like what I said to Dave, if the user have a way to modify the value (and this is a fact), the value can be modified and the developer have to add code to execite what the user want.

In that case, the user (me) do a ActionCopy and all I want to see is the software make a copy of the Row (or Rows) I seledted/dragged. And the developer (me) have to add code to do that.

Instead of turning around the subject, either this work or this does not works. For me, and at this stage, the anwser is… Both :frowning:

Unfortunately, this is an advice that have not been tested (for Drag to Copy: Press the Option Key while dragging one or more Rows): I checked that two days ago and it does not works the way you will expect: the copy is done, but the dragged Row(s) are also moved… beside that an empty Row is added (I was able to squash that).

Found in github (C++ project):
‘ActionLink’: Add a link to the data. Note that this is only useful if source and destination agree on what it means.

(-- | Used in ‘Graphics.UI.Gtk.Genearl.Drag.DragContext’)

OK. Thank you. In the Finder, doing that (holding Option-cmd-item drag with the Mouse) creates an Alias file (a Link file on Windows ? a Link file on linux).

With the data find above, it is a bit more clear. Now how to use that ? (Why will I use a link… what use can I have to a link ?…)

The C++ code above comes from GIMP.

Complete page is here.

Search for data DragAction = ActionDefault to get the interesting part.

I may be mistaken, but you seem to assume that pressing Option will do the copy for you. Action is only there to tell you the user expects copy, but then you have to code accordingly. The code you have to move will not automagically be transformed into copy for you.

Using Action or using Async.Keyboard is just a matter of making sure which modifier is pressed.

You’re mistaken. I do just how you said:
if the user want a copy, I do the copy.

Because you talk about Copy, the copy process is simple, the result is buggy: the selected Rows are moved to the position the Mouse is released / do not stay where they belonw (as it is done when you make a standard copy in the Finder). The copy is appended at the end of the ListBox (btw: and this is a problem in a real life file (with 1000 Rows…: this is where using a demo ListBox shows its limits ! Doing a copy with a 15 Rows ListBox does not displays the append problem).

Once you know what you want and understand how to code it:

a. If action …
b. If Keyboard.AsyncOptionKey…

the core of the if block is the same.

This is for OS X:

[code]Event DropObject(obj As DragItem, action As Integer)

Select Case action

Case DragItem.DragActionDefault, DragItem.DragActionMove
// OS X: no key pressed while dragging
// the moving of the row(s) will work automatically

Case DragItem.DragActionCopy
// OS X: AltKey pressed while dragging (has shown a “plus sign” while dragging)
// the moving of the row(s) will work automatically
// since the rows are moved and not copied one will need to re-insert the rows at their old locations

Case DragItem.DragActionLink
// OS X: AltKey + CmdKey pressed together while dragging (has shown a “link arrow” while dragging)

End

End[/code]

I looked into the example project, which is meant to append only. If I was to implement an insertion at the drop place, it would be difficult, as there seems to be no regular way of getting the mouse position at the instant of the drop to know at which row to insert.

Or even to show a visual indicator of where the insertion will take place.

MouseMove does not fire when dragging an object, and MouseDrag seems to fire only when the mouse moves from the MouseDown that started the drag. I guess it would require using System.MouseX and System.MouseY.