SWITCH macro's initValue - mps

In a template, I want to use a $SWITCH$ macro. It requires me to specify an <initValue>:
What's the role of this <initValue>? What should/can I pass in as <initValue>? Note that no autocomplete suggestions appear on Ctrl+Space.
Below is the Inspector of the macro:

<initValue> is the editor of the template node which will be replaced in the process of the generation. The SWITCH specifies how it will be replaced.
In case of the SWITCH has the <ignore switch> as the default and there are no matches in the SWITCH, the template node will stay in the output model.
Modifying the template node is a bit tricky, the best option is to remove the SWITCH macro, modify the node (e.g. with the auto-completion) and then add the SWITCH macro back

All MPS macros are annotations on existing nodes so <initValue> is the editor of the underlying node showing through. If your switch always generates some code for each node then you don't need to care about the actual node. But if the switch has a default that says <ignore switch>, then the underlying node will be used as default if no cases match.

Related

Storing and retrieving files in Blockly Web

I want to use Blockly to do some calculations, and then generate text files (as opposed to exporting code to JavaScript, Python, PHP, etc.)
I can’t see an obvious way to create my own blocks to do this in Blockly, so using AppInventor (Version: nb168), I got storing and retrieving files to work, in a crude test app on my Android tablet.
In AppInventor/Designer mode, clicking Storage/File creates a “Non-visible component for storing and retrieving files. Use this component to write or read files on your device.”
Then, in AppInventor/Blocks mode, clicking the “File1” icon gives access to 7 “file type blocks”, e.g. AppendToFile, Delete, ReadFrom, SaveFile, etc.
Is it possible to create similar “file type blocks” to use in Blockly Web?
I have limited programming knowledge, so would appreciate simple answers, please.
Thanks, Pete.
Andrew N Marshall from Google/Blockly has told me this:
"This is absolutely possible ...as long as you willing to work within the browser's security restrictions. The resulting files will be need to be manually "downloaded" one at a time, rather than written directly to the user's file system.
... I would start understanding what JavaScript functions are available to you. Attempt to construct a string and save it via a download dialog...
That means the "file" contents are really just a string in memory, a JavaScript variable. We have lots of "Text" blocks that can do a variety of operations on strings. If those are enough, you'll only need one new block to identify the string variable and initiate the download process.
Otherwise, you'll need to think about what blocks you want, and how they operate. They may operate on a specific variable in the JavaScript VM, not necessary exposed as a variable to Blockly.
Either way, you'll need to learn how to create a block and a Blockly app. We have a code lab that will walk you through all the steps. You'll learn how each block generates a string of code, and in your case, that code will be related to the download code I mentioned earlier."
So I'll press on - I just wanted to be sure my goal is actually achievable before I started.
Thanks, Pete.

What is the best practice for overriding strings in Orchard CMS?

I often have the situation where the wording of specific strings from various modules or core features needs to be changed for specific tenants & themes in Orchard CMS.
For example, I may have a client that prefers to have the shopping cart checkout button say "Checkout Now" rather than "Go to checkout" which is a string contained within a view in a shopping module.
I can simply override the razor view in my theme and change the string, however views often are quite complex, and it doesn't feel right overriding a view just to change one string.
Another approach I have tried is to define a po translation file within my theme to override the string from the module. This works because the strings in the module are defined using the T() syntax. However, I've noticed that as soon as I define an override for a string within my theme, this override effects all tenants, instead of just the one tenant that has this theme enabled. I'm inclined to think that translations within modules/themes should be ignored from tenants where they are not enabled.
So I'm left wondering what the best approach for this scenario is?
The localisation/po file approach would be ok if tenants ignored po files from themes that aren't enabled, but then again, it would be really nice if there was a module or feature in core that allowed you to specify string overrides via the admin interface. I guess it's more of a "rewording" task than a "translation" task.
The preferred way of doing this is through template overrides. If you don't want to do that, you can actually break shapes down, and delegate the rendering to smaller templates that are easier to override. This is done by simply refactoring the part of a template that you want to be able to override individually into a separate template. This post explains how to do that: http://weblogs.asp.net/bleroy/creating-shapes-on-the-fly
If you're not willing to do that, you can use this module to get strings from the database instead of po files: http://gallery.orchardproject.net/List/Modules/Orchard.Module.Q42.DbTranslations It should be possible to modify it to fit your sceanrio.

Changing multiple Target Paths for multiple Reference Components

I need to change the target path for each reference component in a page and have been doing it manually. There are about 1000 of these and it's taking forever. Is there a way to replace a certain part of all the Target Paths at once? Essentially, I just need to replace a part in the string i.e. "/us_ck" with "ca_ck."
You can use the Bulk Editor, if you turn on the import feature for it. You could also use the CQ Groovy Console, and write a Groovy script that makes that change for you. This is probably the better way to go.

MFC ID_ vs IDM_ prefixes and their range

I have been working on cleaning an old project's resource.h.
In the project I am working on, I have some IDs which are in the form:
IDM_XXXX 32771
but are referred in code in ON_COMMAND and ON_UPDATE_COMMAND_UI statements.
So am I right in thinking that they are following the command architecture and ideally should be named as ID_XXX instead of IDM_XXXX?
I have read through TN022: Standard Commands Implementation and see that Microsoft says:
We recommend you use the standard "IDM_" prefix for menu items which
do not follow the command architecture and need menu-specific code to
enable and disable them.
I am not sure what is meant by menu-specific code here.
How are IDM_XXXX resources normally handled? Also what is the valid range range for IDM_XXXX? I have gone through TN020: ID Naming and Numbering Conventions but am confused.
ID_ and IDM_ are interchangeable because commands are accessible via command bars, menus or maybe ribbons. I never use IDM_, I only use ID_
Reserved by the MFC is 0xE000->0xEFFF and 0x7000->0x7FFF.
TN020 says that menu/command IDs must be in the range of 0x8000 and greater, but I found no reason why to do this. In the tooltip handling and command routing of the dialogs of the 16bit MFC version and AFAIK an old MFC4.x version, there was a specific code that looks for commands being greater than 0x8000.
By accident I had cases were an ID <0x8000 was created, but it worked.
I would resist not following the recommendations in the technical note. Microsoft does have undocumented messages that may interfere with your code if you violate their recommendations. And, debugging such an issue would be difficult. Additionally, following the recommendation allows you the extra benefit of...
following the MFC command architecture not only makes command handlers
more powerful (since they will work with toolbars) but makes the
command handler code reusable
This means MFC will use the same code to handle any menu and toolbar interactions that are linked together.

Drupal 7 reverse node reference url effect

I love using the Node Reference URL module but in the case of my current project I need something similar and with a slightly different effect.
I have a node type called Event which needs to have exactly 3 webforms referenced to each event I create.
With node_reference_url the configuration means I will setup the node reference fields in the webform node type with my Event type selected as the target.
However, I need to find a way of reversing that. I'm looking for code tips (or a module if it exists) which will allow me to configure the Event type so that I can have links on each event page to create a total of 3 webforms and their NIDs to be saved as references to the parent event page.
I am using entity reference to do such a thing. It allows you to add one or more reference fields to your content types. These references can be to nodes, profiles, etc.
If you would add these to your Event you could probably select the webforms from there.
I know this plugin also integrates with views (under advanced > relations), allowing you access the fields of the referred content. (Incuding the title and link to node options.)
Want to take it a step further?
Have a look at reference dialog. This module allows you to build similar reference fields combined with Add, Edit and Delete buttons. If the content you are referring to is not yet created, you can do so in an overlay.

Resources