removing an item from a menu

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

removing an item from a menu

jWarrior
I am creating a 'history' of buffers off the &File menu
using Menu>>addItem: and this works just fine.

The problem is -removing- items from the history.
Menu>>removeItem seems to remove the item
from a local copy only, and does not refresh
the display.

Any ideas? Thanks

Donald


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

jWarrior
| bufferMenu items item index|


bufferMenu := self view menuBar detect: [:each | each text = 'Buffers'].
"get the ^^^ menu to be changed"
items := bufferMenu items select: [:each | each class ~= DividerMenuItem].
" toss the ^^ dividers"
 item := items detect: [:each | each description = currentTool timeStamp]
ifNone: [nil].
"^^ find the one to remove"
 bufferMenu removeItem: item.
"remove it"
 1 to: self view menuBar items size do: [:each | ((self view menuBar items
at: each) text =
'Buffers') ifTrue: [index := each ]].
"find ^^ the position in the menu bar of the menu to be replaced"
 self view menuBar at: index put: bufferMenu.
"replace it"

inspecting self view menuBar after executing this code shows that the item
was removed and menuBar was updated.

BUT the view's menu is unchanged. Any ideas welcome.

"Donald MacQueen" <[hidden email]> wrote in message
news:98t0lr$5n1$[hidden email]...

> I am creating a 'history' of buffers off the &File menu
> using Menu>>addItem: and this works just fine.
>
> The problem is -removing- items from the history.
> Menu>>removeItem seems to remove the item
> from a local copy only, and does not refresh
> the display.
>
> Any ideas? Thanks
>
> Donald
>
>


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

Frank Sergeant
"Donald MacQueen" <[hidden email]> wrote in message
news:98t6jt$m1$[hidden email]...
> inspecting self view menuBar after executing this code shows that the item
> was removed and menuBar was updated.

> BUT the view's menu is unchanged. Any ideas welcome.

Perhaps sending #recreate to the view would help?


-- Frank
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

jWarrior
Good idea, but it didn't work. thanks anyway.

"Frank Sergeant" <[hidden email]> wrote in message
news:ZDss6.1233$[hidden email]...
>
> "Donald MacQueen" <[hidden email]> wrote in message
> news:98t6jt$m1$[hidden email]...
> > inspecting self view menuBar after executing this code shows that the
item

> > was removed and menuBar was updated.
>
> > BUT the view's menu is unchanged. Any ideas welcome.
>
> Perhaps sending #recreate to the view would help?
>
>
> -- Frank
> [hidden email]
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

Ian Bartholomew
In reply to this post by jWarrior
Donald,

> BUT the view's menu is unchanged. Any ideas welcome.

This is a rough translation of your code to match a method I used to use
back in the days of Dolphin 2.  I was never very happy with this technique
then, and I haven't tried it again now, but it might give you a pointer.
The idea was, as I recall, to destroy all the copies of the menu that
Windows knows about and then redraw them with/without the bits you do/don't
want.

menuBar := self view topShell menuBar.
self view topShell menuBar: nil.
menuBar free.

bufferMenu := menuBar at: 'Buffers'.
"adjust bufferMenu as required"

self view topShell menuBar: menuBar

I will stress that this is untried code, a possibly incorrect technique to
use and was last tried by me two Dolphin versions ago so be very, very,
careful ....

Ian


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

jWarrior
Ian,

that worked. 10*6 thanks. youDaBloke! as they say across
the pond. ;-)

i tried everything i could think of including sending 'clear' to the
menu and then re-adding the items one by one, but i guess
windows was still holding onto the menu.

sheesh. this ought to be easier. oh, well. onto the next
challenge.

Donald

"Ian Bartholomew" <[hidden email]> wrote in message
news:osvs6.27612$[hidden email]...
> Donald,
>
> > BUT the view's menu is unchanged. Any ideas welcome.
>
> This is a rough translation of your code to match a method I used to use
> back in the days of Dolphin 2.  I was never very happy with this technique
> then, and I haven't tried it again now, but it might give you a pointer.
> The idea was, as I recall, to destroy all the copies of the menu that
> Windows knows about and then redraw them with/without the bits you
do/don't

> want.
>
> menuBar := self view topShell menuBar.
> self view topShell menuBar: nil.
> menuBar free.
>
> bufferMenu := menuBar at: 'Buffers'.
> "adjust bufferMenu as required"
>
> self view topShell menuBar: menuBar
>
> I will stress that this is untried code, a possibly incorrect technique to
> use and was last tried by me two Dolphin versions ago so be very, very,
> careful ....
>
> Ian
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: removing an item from a menu

Blair McGlashan
Donald

You wrote in message news:98u3kn$1l8$[hidden email]...

> Ian,
>
> that worked. 10*6 thanks. youDaBloke! as they say across
> the pond. ;-)
>
> i tried everything i could think of including sending 'clear' to the
> menu and then re-adding the items one by one, but i guess
> windows was still holding onto the menu.
>
> sheesh. this ought to be easier. oh, well. onto the next
> challenge.

It ought to be, and indeed it really needs a patch. The attached should do
it and will enable you to dynamically remove items from a menu using either
#removeItem: or #removeItemAt: - the existing implementations in D3 and D4
don't actually update the underlying Windows menu, which is not consistent
with the behaviour of #addItem:.

This patch could be improved on a little with an override in MenuBar to call
DrawMenuBar() because at present if a top-level item is removed from a
MenuBar then that menu bar is not immediately redrawn to reflect the change,
although it does update when activated. However this is only a cosmetic
issue, and normally one doesn't delete items from the menu bar itself, so I
haven't done that in this patch.

The patch should work in 3.06 or 4.0. I'd suggest adding it to a package by
pasting it into the post-install script rather than as loose methods of
one's package since it updates system methods. Alternatively you might
prefer to call the #removeItem(At): methods something else, e.g.
#reallyRemoveItem(At): instead.

Regards

Blair

























begin 666 Menu_removeItem.st
M(4UE;G4@;65T:&]D<T9O<B$-"@T*<F5M;W9E271E;3H@:71E;0T*"2)296UO
M=F4@=&AE('-P96-I9FEE9" \365N=4ET96T^(&9R;VT@=&AE(')E8V5I=F5R
M+B(-"@T*"5YS96QF(')E;6]V94ET96U!=#H@*&ET96US(&EN9&5X3V8Z(&ET
M96T@:69!8G-E;G0Z(%MS96QF(&5R<F]R3F]T1F]U;F0Z(&ET96U=*2$@(0T*
M(4UE;G4@8V%T96=O<FEE<T9O<CH@(W)E;6]V94ET96TZ(7!U8FQI8R%R96UO
M=FEN9R$@(0T*#0HA365N=2!M971H;V1S1F]R(0T*#0IR96UO=F5)=&5M070Z
M(&EN9&5X#0H)(E)E;6]V92!T:&4@;65N=2!I=&5M(&%T('1H92!S<&5C:69I
M960@/&EN=&5G97(^(&EN9&5X+@T*"4%N<W=E<B!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