How can I edit the WorldMenu in Pharo - menu

How can I remove or add an entry to the WorldMenu in Pharo at run time?
For example I have a menu option that loads extra tools for working with web tools. Running the code setting up these tools would include adding items to the menu to stop and start the web service. I don't want these stop and start items in normal use but the code setting up the items would be in the image.
I have seen and used the method in this question However this adds the item when the code is loaded.

Let me clarify what #Peter and I mean
Choose any class, and in the class side add your #menuCommandOn: method on the lines of
menuCommandOn: aBuilder
<worldMenu>
self showsItem ifTrue: [
(aBuilder item: self itemToken)
order: 0.1;
action: [self performItemAction]]
This way, even though the method would be invoked every time the world menu is about to pop up, it will add the menu item only if the logic behind #showsItem enables it. Notice that the dynamic nature of the menu doesn't require you to remove menu items, instead you simply do not add them. In your case such a logic should reflect the availability of the web service.
The #itemToken message send is a placeholder for the Symbol you want to use to identify the item. In other words, you would probably want to inline it as a literal rather than sending the #itemToken message. This Symbol will be used as the item label.
For further optional configuration features take a look at other implementors of #menuCommandOn:.

Related

Adding item to all view menus

In Eclipse, it is possible to extend to any pop-up menu using the following special location URI:
popup:org.eclipse.ui.popup.any
Is it possible to do the same for the view menus (the little triangle in each view)? (I am developing an Eclipse RCP application, not extending the IDE. The purpose for this item is to help debugging and testing of the application.).
The short answer: no, that is not possible, unless you add the items by hand for all views.
The slightly longer answer: yes, if you
manually go through the view registry
create a new AbstractContributionFactory with the location URI "menu:<view-id>" and whatever createContributionItems(...) you want for each. (Alternatively you can create AbstractMenuAdditionCacheEntry or even better MenuAdditionCacheEntry - though these are internal and requires a little extra work... The last allows you to have a centrally defined menus extension point that is used for all these additions.)
add these to the workbench using IMenuService.addContributionFactory(AbstractContributionFactory factory) (use IWorkbenchWindow.getService(IMenuService.class) to acquire the menu service).
I haven't tested the above recipe, but I have used something very similar in an application...

How to click a strange link looks like button in watir

I want to use the Watir to click a link that looks like a button attached the image.
I use the following method,but doesn't works:
#browser.div(:id,"NetworkAnalysisTabPanel").div(:index,1).div(:index,1).ul(:index,1).li(:index,1).link(:index,2).click
Note:
#browser.div(:id,"NetworkAnalysisTabPanel").div(:index,1).div(:index,1).ul(:index,1).li(:index,1).link(:index,2).flash
is working fine but click is not working in IE and FF
Link looks like this:
And HMTL like this:
Note: I am able to click on the element using selenium IDE with clickAt method
Try this (not tested):
browser.link(:class => "x-tab-strip-menu").click
If you can flash the link, but click does not do what you want, see this: How to find out which JavaScript events fired?
FYI what you have are links that are using standard background images controlled via CSS magic that keys on the class of the link to know what background to set. That's where the image comes from, and why you don't see it as part of the link in the HTML.
In that control, each tab is a list item element (li) in an unordered list (ul), and each list item has an ID, so that's the easiest way to tell it which tab you are trying to click inside.
Try identifying things starting with the LI that is the tab container, as within that container there is only one instance of each link of a given class. Of the 4 links, only one is without any kind of easy identifier, and if you need to click that one you'd need to use :index, but for the other 3 links using :class ought to work. This should result in code that is less brittle and subject to being broken if the order of tabs changes, or the page is refactored.
#browser.li(:id,"NetworkAnalysisTabPanel__ext-comp-1038").link(:class, "x-tab-strip-menu").click
If the number at the end of the ID is subject to change, you can try a regular expression to match the part you can predict and is unique from the others
#browser.li(:id,/NetworkAnalysisTabPanel__ext-comp-/).link(:class, "x-tab-strip-menu").click
If you can reliably identify the object and use .flash but .click does not seem to do anything, you may have to use .fire_event('onclick') instead or .click.
#browser.li(:id,/NetworkAnalysisTabPanel__ext-comp-/).link(:class, "x-tab-strip-menu").fire_event('onclick')
If that does not work, then you need to start experimenting with likely events that the control might be looking for (which will not necessarily show up in the HTML btw.. it may be in javascript or CSS etc)
UPDATE
This is where having an live example of the control that we can interact with is critical. doing some googling on the class names I was able to find one here and that let me play with it a little, and what I discovered is that it is looking for onmousedown. so, on that site, this works
browser.li(:id, 'TabPanel1__ctl07').link(:class, 'x-tab-strip-menu').fire_event('onmousedown')
Now since those ID's may not be the best identifier, a bit more digging (using .text on the li that holds the tab parts) found me some text, which in a menu like that ought to be unique.. SO, we can change this to make things a bit more robust and clearer as to what tab I'm clicking on (this will also be less subject to breaking if the tabs change around.
browser.li(:text, 'Menu 1').link(:class, 'x-tab-strip-menu').fire_event('onmousedown')
Lastly, since the click is causing client side code to execute, you may need a brief pause (a one or two second sleep) to wait for that portion of the page to re-render etc.

Custom theming Drupal 6 Menus

Is there a hook or preprocess function that I can access to write my own theming function for a drupal menu (in this case, primary links)?
I have a rather complex menu structure that requires a little extra markup than I'm currently getting by just rendering the menu items in a block (involving sub-menus with a little custom markup) and really need to get access to build the menu's content variable myself, ideally from an array that has all the primary links and their children in scope.
While it may not be the best solution, it is one that worked quite quickly and painlessly:
Drupal keeps a cached version of all your menus in the cache_menu table, I ran a this query to retreive a serialized string containing all the contents of the menu:
SELECT data FROM menu_cache WHERE serialized = 1 AND cid LIKE 'links:primary_links:%';
Substitute primary_links for whatever the name of your menu is and call unserialize on $row->data to get a structured array of everything you should need to build a custom menu.
I call a function in hook_preprocess_block that swaps the content of the menu block with my own and everything seems to be working fine.

in-place message in MFC?

Hi
If any one knows how to use in-place warning message in MFC could you share info.
Is there a way to use it or is there any control we can use directly in mfc.
In-Place warning message: A warning message with appropriate icon along with warning message, will be displayed with in the same dialog.
I found some info about in-place message in msdn
InPlace message in msdn glossary
Different messages
Please share information.
Regards
Haranadh
From your comment, it appears that you're referring to this as an in-place message:
Ironically, of course, that's labeled as the incorrect example on the MSDN page that you link to. It's specifically recommended that you provide more specific advice, such as securing the projector with a password so that the presentation is not visible to unintended viewers. Putting that aside, however...
This is quite easy to implement in MFC. It's done simply with two STATIC controls, one on the left that displays an icon (in this case, a warning triangle) and the longer one on the right that displays static text (the warning message itself). If you're using the dialog editor to create your window, it's a simple matter of dragging the two controls to the dialog window and arranging them accordingly. There isn't a single control that encapsulates this functionality, but it's silly to expect that there would be, considering that doing it with two separate static controls is already so straightforward.
To load built-in icons such as the warning triangle shown above, you can use the LoadStandardIcon function and specify IDI_WARNING as the icon name. The complete list of values is available here. Obviously you can load any icon of your choosing as well; just add it to your project's resources.
Since you will presumably want to display the warning message only when it's applicable, you will need to programmatically hide and show the two controls depending on action taken by the user in your dialog. The standard ShowWindow member function makes this a trivial task. Call it on the two static controls, passing SW_SHOW as its argument if you want the warning message to be visible. Otherwise, you can specify SW_HIDE to hide the control.
As an alternative to what you are trying to do; you could place your message in a dialog:
int nResult = AfxMessageBox("Save changes to Current Job?", MB_YESNO);
if (nResult == IDYES)
{
OnFileSave();
}

Magento _prepareLayout() called 5 times to many

** New EDIT **
so what I'm trying to do is this.
I want the to add new form elements generated by my module on the product view of the following url
http://magento.example.com/catalog/product/view/id/46
ultimately these elements will be determined to show up by a related table in my module
I expected that if I extended Mage_Catalog_Block_Product_View in my module as shown below I would be able to create a block in the product form that would contain such form fields, only if he are in the related table in my module
so I created a test.phtml file in
app/design/frontend/default/default/templates/<module>/test.phtml
then as you can see in my the View.php file described bellow I built the block and displayed it in the product view.
It did appear but 5 times too many. from the answers below this is normal so that answers the question as to why the it shows up five times but leaves the question what is the proper way to proceecd since this plan is not going to work
** End New Edit **
in my module I call _prepareLayout() and it does this 5 times when i pull up the page
here's my code
in
/app/code/local/Namespace/Module/Product/Veiw.php
class <Namespace>_<module>_Block_Product_View extends Mage_Catalog_Block_Product_View {
protected function _toHtml() {
return parent::_toHtml();
}
public function _prepareLayout() {
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => '<module>/test.phtml')
);
if ($block){
$this->getLayout()->getBlock('content')->insert($block)->toHtml();
}else{
echo "no block";
}
return parent::_prepareLayout();
}
}
NOTE:
I just noticed this also takes away the price availability qty and add to cart button. which is also a problem
EDIT
First I want to thank you all for your answers. Second i want to give you more context
the reason for choosing to do this in the module is that I don't want the block to show up on every product . What i have is a table of what I'll call custom options containing properties of the product sort of like hair color height weight etc and depending on what set of properties are attached to the product (if any) will depend on what html content will show up on the page.
so in one case it my get a drop down menu and in another case it may get an input box. the other very important piece is that this must be setup so that I can give the end result out as a module that can be installed and not worrry that it won't show up if someone upgrades there magento
that said does it still make sense to do this all in the xml file ?
It seems to me that your code is overriding a core Magento module in order to achieve what could be easily done in the layout xml configuration. I would strongly recommend the follwing:
Use the built-in configuration mechanisms (e.g. layout xml - read Alan's excellent tutorial here) instead of writing code whenever possible.
Don't override the core code
if you must change the behaviour of the core code, use an Observer rather than Rewrite/Override
if you absolutely must Override, always call parent::whatever()
For example, if you create a <module>.xml layout file in your theme (app/design/frontend/default/<theme>/layout), you could use the following code:
<catalog_product_view>
<reference name="content">
<block type="module/block" name"my_block_name_here" template="module/test.phtml"/>
</reference>
</catalog_product_view>
You would then need to use a getChildHtml('my_block_name_here'); call within your phtml to position the block.
So unless there is other functionality happening inside your _prepareLayout, there's no need to override the core, or even to override the default catalog.xml.
EDIT (small edit above)
So now in your Block (I would recommend that you call it Namespace_Module_Block_Product_Customattributes or something like that), you are not overriding the core Product_View block, but merely processing your logic for what html widgets to use to render your custom attributes. Leave the rest of the tier prices, add to cart, other generic product block code, etc to Magento to work out.
If you are worried about the upgrade path for your module's users, you should definitely NOT be overriding core code. Use the configuration approach and very selectively introduce code that "plays nice" with the system rather than try to boss it around with overrides.
I took a look at a stock Magento install of CE 1.4.1, and unmodified the _prepareLayout method is called six times when loading the URL
http://magento.example.com/catalog/product/view/id/46
That's because the class is instantiated six times. So that's the correct behavior.
As for the vanishing element, I can'y say for sure, but your override to _prepareLayout doesn't appear to either
Do the same things as Mage_Catalog_Block_Product_View::_prepareLayout
Call parent::_prepareLayout();
When you override a class in a Magento you're replacing an existing class with your own. If you change a method, you're responsible for that old code being run.
It's not clear what you're trying to accomplish here. You should consider breaking your problem down into smaller problems, and then posting one (or more) "I tried X, expected Y, and got Z" type questions. As written no one's going to be able to answer your question.

Resources