Desktop: ConstructContextualMenu


I use code in (a Canvas) ConstructContextualMenu Event to build a… Contextual Menu.
Nothing fancy here.

BUT, if I change a file name after ConstructContextualMenu is fired, it still appears in the Contextual Menu.

Beside not doing strange things in the back of my application, is there’s a way to not getting the error ?
Can I fire that event when I want ?

Another explanation:
In Canvas1.ConstructContextualMenu I check what is on a special folder and build a ContextualMenu.

At use time, I can right click and see my entries (files) in the Contextual Menu). I ‘click down’ outside the menu to dismiss it.
Then, I change a file name (that appears in the list above), and I right-click / get once again the Contextual Menu and can see the entry I already renamed.
How can I get the new list ?

Maybe you cache your values?
I’ve just tried and works perfectly

Hi Antonio,

thank you for your answer.

No, I do not cache my values.

I rephrase the question:

Step #1: I right-click and see a list of entries.
Step #2: I rename OR remove the file corresponding at an entry
Stem #3: I right-click and see a list of entries:

In that case (Step #3), the entry I rename OR remove is still there.

The code to build the Contextual Menu only do that: read in a loop a folder contents and build the Contextual Menu based on that folder contents.

For me, the build is done only once (or something is done (or not) on my back).

52 viewers / 1 answer.

so ff is your folderItem
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean
dim n as integer=ff.Count-1
for i as integer=1 to n
base.Append new MenuItem(ff.Item(i).Name)
End Function
and if you right click you see a list of files.
Then change/delete one on them in the Finder and when you right click again you see the same list as before??

I do not have my code handly, but you understand the idea.

Just before refreshing the window, I was thinking: “what an idiot I am: add a MsBox in the ConstructContextualMenu event and see if it is displayed once or many times…”.

I will try.

No, no: I have Xojo, I will try right away in a new project.

OK, I just checked your code and … you are right, it works !

Now, I have to wait 'till after lunch to check my code and try to understand why it does not works …

Thank you Antonio.

52 viewers / 1 answer
how many answers did you need?

Emile -

Are you using a new FolderItem in the ConstructContextualMenu, or a folder item defined elesewhere?

For this to work as you expect, you should Dim a new folder item at the top of the event. You may even want to Nil it after the menu is created.

Dave: 1 good answer is enough. More points of view can help to understand, sometimes * ;-:slight_smile:

Antonio was right: it was my fault. For some reason I stored in a FolderItem array the files I wanted at “open time” and use the array to display the list of available image to watch (from the current folder).

It tooks me time to find where I filled the array (I searched 'till I changed the name of the array to get the list of involved instances / I could do that with a find too).
After the discover of the bug, I had hard time to find a way to do what I wanted to do (to get a reference to the ‘current’ folder. That is certainly why I coded it that way).
Now it works ‘fine’: that was the case previously until I modified an image file name to make it meaningful…
More testings are needed.

  • Nota: 80% of people can understand your explanation. 20% of people need a different explanation to understand. Sometimes I am in the former group, sometimes I am in the later group.
    And if I want to get 80% of the people to understand, I have to make extra efforts in my explanations or only 20% of my readers will understand, more or less.
    Speed is the ennemy of clarity.

At last, hen I started programming the Apple IIgs, I had hard times with Apple programming books. Then, I read a French book (in French…) and it started to be clear for me. I met the author some years later and he told me that he used… the Apple documentation (and his own skills) to wrote the book !
I certainly was in the 20% group when at first I read the Apple docs and fall into the 80% group when I read his book Then, my understanding grows (to 90% ?)