I have a wxMenuBar, and a wxMenu. I can successfully attach the menu to the menubar with Append(...). I can also successfully remove the menu with Remove(...).
The "menu" sample demonstrates adding and removing menus: it creates a menu, Append-s it, and then Remove-s it, calling delete on the returned pointer. To add another, it makes a whole new menu. Thus there's not any reattaching.
However, I would like to be able to Append, Remove, and the re-Append any particular menu (or something equivalent that allows that). Furthermore, it must have no memory leaks.
I have tried:
//startup
menubar->Append(menu,title);
//later
delete menubar->Remove(1);
That produces a working program with no memory leaks. Curiously, I have found that the pointer returned by menubar->Remove isn't the same as the pointer originally Append-ed.
I tried:
//startup
menubar->Append(menu,title);
//later
delete menubar->Remove(1);
menubar->Append(menu,title); //add it back immediately after removing it.
This produces an assertion error in appbase.cpp:1015, something about attaching a menu twice.
I don't really know what I'm doing, and I would appreciate if someone would explain the "right" way to do this.
I don't understand how can the menu returned by Remove() be different from the one you appended. Perhaps your menu is not at the position 1?
Anyhow, the rules are simple: menu bar takes ownership of the menus appended to (or inserted into) it, meaning that it will delete them. When you remove a menu from the menu bar, it relinquishes ownership and now you're responsible for deleting it.
So you can remove the menu and add it back again later. But you can't add the same menu twice.
So long as you do not delete the menu and keep it saved somewhere, you should be fine.
Something like this:
//construct menu
// this needs to be saved somewhere, perhaps as an attribute of the app frame
wxMenu * menu = new wxMenu( title );
....
// Attach menu to menubar
menubar->Append(menu,title);
....
// remove menu ( but don't delete! )
menubar->Remove(1);
....
// re-attach menu
Append(menu,title);
This is standard way to handle pop-up context menus that are shown when something is right-clicked, except that instead of popping up the menu in the window, it is attached to the menubar.
Related
I am trying to give an object in the interface builder a custom class. When typing in the class name in the Identity Inspector it automatically finishes the line as its already present in the dropdown list of available classes.
However after entering the class the page comes up with a padlock image and clears the class name.
What is the cause of this and how can I rectify it?
firstly, you must reload xcode
if it not work you must have subclass associate with it in IB
Create CustomClass:UITableViewCell then drop UITableViewCell to IB and then just type the name
If dropdown list not display, reload Xcode
Assuming you've specific the right IB object (e.g., a dynamic cell prototype, whose default class is UITableViewCell) and your custom class is defined correctly (as a subclass of UITableViewCell, itself), then I have a couple of thoughts of what you might try:
Sometimes exiting and restarting Xcode is often enough.
Also try selecting "Clean" from the "Build" menu (or press shift+command ⌘+K).
In the worst case scenario, sometimes you have to exit Xcode and delete the DerivedData folder and then restart Xcode. To find the derived data folder, press command ⌘+, (comma) and go to the last tab, "Locations", and click on the arrow next to the "Derived Data" folder:
Having pulled up that folder in Finder, quit Xcode, delete the contents of that DerivedData folder in Finder (after quitting Xcode), and then restart Xcode and try again.
I think I have found the solution (not sure if I have found a fix for the actual problem or just found a way around it)...
I changed the Lock dropdown setting to Nothing and it now allows me to set my own custom class to the Object in the file.
Whats strange is that the document lock was previously set to Inherit (Nothing) anyway so not sure what the difference is here.
I am working on xib file that has many objects, which hide each other and also change in code.
I would to make my work, and any other future programmer easier by adding comments in the xib file.
I thought of just putting some text area outside the view I'm using, but I want to make sure I'm not effecting the final executable.
Is this a valid way to do it?
1./ In interface-builder, select the object to comment, open the inspector:
in the last tab (with the (i) icon, at the bottom of the inspector panel, you'll see a note area: write your comments there. You may want to click on "show with the selection".
2./ comment in code any object that should change programmatically
How do I undo the removal of a method in Squeak Smalltalk?
'World Menu'->'open'->'simple change sorter'
In the top-right pane, select the class from which the method was removed.
In the middle pane, select the removed method.
Right click on the method name, bringing up a menu
Select "versions"
When the versions tool comes up, select the top (most recent) version, which is the one you deleted.
Click the "revert" button
When you browse your class, you will see that the method is restored.
If you use OmniBrowser and the Refactoring Tools you have unlimited undo/redo on all your code changes like in any other modern editor. Select in the context menu Refactor > Undo.
You can open your changes file:
Tools menu at the top of your screen.
File List (which should open in the right place).
In the upper right pane select the changes file (given an image called Foo.image, you'd look for Foo.changed).
Hit the "recent changes" button, browsing as far back as the latest (top) snapshot.
All method additions, alterations, deletions, DoIts are listed in the list that pops up.
Select the method/s you want, right click (I can never remember the colours for mouse buttons) and "fileIn selections".
I've a question. I cannot find the way, how to add buttons to main toolbar programmatically. My problem is, that I've the task to dynamically (based on XML configuration file) build menus and toolbar. I found how to add a menu item programmatically, but not toolbar button.
Tutorials mostly show how to create buttons and menus using plugin descriptor (plugin.xml), but not how to do it programatically. It seems, that it is out of bounds of Eclipse plugin philosophy.
I've just found this:
There might be layout problems with this approach. I also don't
believe the framework will try and re-create your dynamic item except
at random toolbarmanager updates. With Menus they can be updated on an
SWT.Show event, which is why CompoundContributionItem only applies to
Menus.
What shall I do? Can I say Sorry, there is no way to build toolbar dynamically. I can do it just for menus? Collegue says, that it must be possible, but he does neither know how.
The only way to be able to create main toolbar entries programmatically is in an RCP app, where you supply the ActionBarAdvisor for the workbench window. This isn't dynamic, however, just called on window creation.
Another way to do it would be to use org.eclipse.ui.menus and contribute org.eclipse.ui.menus.ExtensionContributionFactory. It also works only on workbench window creation (not really dynamic), but you could read your own XML and provide IContributionItems for the main menu or toolbar.
How dynamic are you trying to be? Most solutions work well on startup/window creation.
PW
Whenever you try to do something programmatically in Eclipse that is normally done through plugin definitions you are walking on thin ice. I've tried it on a few occasions and it rarely ended up being easy or good.
Instead, think of what it is that you only know at runtime and need to be able to change on the fly. Is it the name or icon of the button? That can be changed at runtime.
Take a look at runtime commands, they can be confusing to define properly, but with them you can for example create buttons that are only visible if a condition is active. That condition could be set at runtime.
I have a Cocoa app I'm working on and I get a different result in appearance for the NSToolbar I am using for the main window.
Specifically, I'm using a search field as the last NSToolbarItem and, whereas under Snow Leopard it is displayed correctly:
it is cut under Leopard:
Looking at those two versions it appears that the spaces I put between the items are not respected under Leopard. I also saw that sometimes, after I make some update at the toolbar in Interface Builder, these changes are not mirrored in the running application even under Snow. I have to drag the default bar from the customizing menu in order to see them.
UPDATE
The reason for the NSToolbar not always mirroring what is in the .nib file resides in the autosave mechanism that was enabled for me, as NSGod suggested.
What can be the cause of this misbehavior?
Is there something about constraints, (minimum and maximum) sizes that I should have taken into account?
Feel free to point some documentation to me
UPDATE 2
Is there a way to programmatically introduce item and spaces into a NSToolbar or check the consistency (at run time) of those entered with Interface Builder?
While I do recall having a couple of oddities with search fields in NSToolbars, I've never seen the behavior where the right side of it is cut off.
Are the NSToolbarItems that are spaces the fixed one-unit space, or the flexible spaces?
"I also saw that sometimes, after I
make some update at the toolbar in
Interface Builder, these changes are
not mirrored in the running
application even under Snow. I have to
drag the default bar from the
customizing menu in order to see them."
You need to keep in mind that if you've enabled user customization and autosave behavior in the toolbar, then when the user explicitly makes a change, it will be saved to user defaults. If you then re-arrange your toolbar in IB and run the app, it's possible that the configuration saved in user defaults is overriding the default configuration you've specified in the nib file.
What I usually do is during testing, delete the prefs file for my app so changes can't be overridden. (FWIW, I usually use an AppleScript saved as an application that I keep in my Dock. It just runs a do shell script command which deletes the prefs file. Being a GUI-oriented type of person, it's easier for me to just click it to have it run right before debugging. This version of the script asks for the prefs file to delete, though it can also be customized: http://www.markdouma.com/developer/DeleteAppPrefs.zip. If you've never run it before, you get the choose file dialog, and the chosen file is saved as an alias inside the actual AppleScript, so you're not asked again. You can drag the icon onto AppleScript Editor to take a look at the script or change it).
Anyway, then, if I'm going to release a new version of an app that uses a new toolbar layout, and want to prevent the config from being overridden, I'll change the toolbar's identifier (or autosave name) to something like "docToolbar2.0".