NSIS section hide (compile and execute) - nsis

Well I found a few forum topics on nsis section hiding, also checked NSIS help but couldn't find my answer. I want a simple thing i.e. per my requirement I want to hide a section completely without commenting whole lines of code.
Now this should effect two things.
Section should be removed from compilation scope just like if I commented those lines.
Do not execute the section codes from installer.
If I use #, /o or - before section name. It's doing the 2nd point. But any way to achieve the first one?

You can use conditional compiling:
!define INCLUDESECTION
!ifdef INCLUDESECTION
Section "section1"
...
SectionEnd
!endif
You can also decide to include the section or not, from command line:
makensis.exe /DINCLUDESECTION example.nsi
In this case, you don't have to define INCLUDESECTION inside your nsis code.

It's bad idea to disable sections at compile time to avoid it's selection/execution because:
Sections designed all about of code runtime behaviour, not of compile time. Otherwise it produces an infinite set of !ifdef...!endif for section scope control and bloatware compilation definitions incorporation like yours INCLUDESECTION.
At some point you will want to switch a section selection/visibility in the runtime which will force you to mix the runtime and compile time code that is even worse.
I may think it all went from an invalid undestanding of section selection/hideness behaviour in the runtime. So, to ensure you that theres is no much problems to use section selection/hiding in the runtime you have to understand several things to think on:
In Windows sections implemented through the SysTreeView32 control and inherites/workarounds all issues introduced by such controls. This means you have to hide/unhide sections (controls items) in a Page Pre (OnCreate) function instead of Page Show (OnShow) function which basically uses to control a section visibility state.
Sections can still run even if hidden, because the hidden state is independent to the selection state. To hide section you have to set empty string to the section name when the selection state introduced by the respective contol item flag. So, in some cases you might have to test a section hideness at the section code block to skip it's further execution.
Parent section selection triggers children selection recursively by the control. But because hidden not readonly children sections does select too, you have to update parent selection state from the "Partial Selected"/"All Selected"/"All Unselected" manually at the end of your .onSelChange handler function to fixup control checkboxes visibility to it's actual appearence.
So, to do all things right you have to:
Write the set of the UpdateSectionGroupSelectionN macroses to postprocess each section group visibility state update, where N - is number of subitems in a section. If all not hidden subitems in a section is selected, then parent must be updated to the "All Selected" state. If some of not hidden subitems in a section is selected, then parent must be updated to the "Partial Selected" state. If all subitems is hidden then you have to decide that to do with such parent items (may be it's should not even change or must be hidden too in the Page Pre function).
Add to a section beggining hideness state check code to bypass section further execution in case if other section neighbors could be hidden or in case of some other reason.
I know all said it's a bit tricky to do, but you will find that this way is almost one common way to fixup all section issues at once and for all and avoid the code further complication on the way.

Related

How can I edit the WorldMenu in Pharo

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:.

How do you set the File Layout to put [ClassInitialize] and [ClassCleanup] at the top of the file using Resharper 9?

How do you set the File Layout to put the MsTest [ClassInitialize] and [ClassCleanup] methods at the top of the file using Resharper 9?
With the default set-up for R#, the methods are just alpha sorted with the other test methods
I appreciate that I can amend the "All other members" from sort by Name, to sort first by Static and then by Name, but this seems like a quick hack
You can edit the file layout rules that ReSharper uses for reordering file content by code cleanup, by going to ReSharper → Options → Code Editing → C# → File Layout.
Full details are available in the web help, but the idea is to create a pattern very similar to the default "NUnit Test Fixtures" pattern, but for MSTest. In fact, this is a nice idea for a default pattern, so I've added a feature suggestion you can track or vote: RSRP-446275
Essentially, you want to do what the default NUnit Test Fixtures rule does.Create a new "type pattern" and add it between "NUnit Test Fixtures" and "Default Pattern". Double click to edit the pattern, and switch to constraints view by clicking the cog in the top right. Here you can say it has to be of Kind "Class" And "Has attribute" Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute.
Switch back to Composition (rules) view, and add an "Entry" from the Toolbox. Give it a name, such as "Setup/Teardown Methods", and double click on it. This should be set up the same as NUnit's - And (Kind=Method, Or (Has attribute=Microsoft...ClassInitializeAttribute, Has attribute=Microsoft...ClassCleanup)).
The NUnit pattern defines another couple of entries - an empty one for "All other members" and one for "Test methods", which is kind=method and has attribute=Test. Something similar could be done for mutest's TestMethod attribute.

Apply a context action to an entire file

Is there any way to make Resharper apply a context action at every applicable site in a file?
In particular, in order to comply with coding standards, I wish to apply 'Specify type explicitly' to every 'var' declaration across a number of files.
In general, you can't apply a context action in multiple code positions.
However, in the case of specifying type explicitly, you can use Code Cleanup to batch-apply this.
Choose "ReSharper > Tools > Clean up code"
Click "Edit Profiles"
Click "Add" to create a new cleanup profile and specify a name for it (say, "goodbye var").
In the list of profile settings, clear all check boxes to prevent unwanted code style changes.
Under C# > Use 'var' in declaration, select "Do not change" for "Replace direction", and "Always use explicit type" in the other two drop-downs.
Click "OK".
Choose "ReSharper > Tools > Clean up code" once more, choose the "goodbye var" profile, and click "Run".
Note that you can invoke code cleanup in different scopes: step 7 above implies that you're calling it in the scope of the currently opened file. However, you can choose a wider scope (folder, project, solution) in the Solution Explorer and invoke Code Cleanup from there.

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