How can I add an item in the World-menu of Pharo 4.0? - smalltalk

How can I add a new item - Workspace openLabel: 'Workspace' - to the World-menu of Pharo 4.0 ? (What can I say... I prefer Workspace over the new what's-it-called. :-)
I've looked at several menu-related items in the Browser, but couldn't really make head or tails of it. I also tried to find where the menu is stored (it must be somewhere, right?), but couldn't find it.
Also, how would I go about to add it to one of the existing sub-menues of World-menu, and how could I create a new sub-menu (in the World-menu) and add it there?

Add the following class method to any class you like. Best to make one especially for this purpose and load it to your new images:
WorkspaceWorldMenuItem class>>menuCommandOn: aBuilder
menuCommandOn: aBuilder
<worldMenu>
(aBuilder item: #'Workspace')
order: 0.1;
label: 'Workspace';
action: [ Workspace open ]
The interesting part is the <worldMenu> pragma. You usually put it directly after the selector (and comment) and before any other element in the method.
To have a look at example usage open Finder, choose the Pragmas mode and search for worldMenu (without the angle brackets).

Related

How do I start Etoys from Squeak?

In the Squeak System Browser, I see that there are many class categories related to Etoys:
But how do I access Etoys from Squeak? How do I get something like the screenshot shown below?
(Source of Etoys screenshot: https://commons.wikimedia.org/wiki/File:Squeak_screenshot.png)
There are also Squeak versions set up specifically for Etoys, e.g.:
https://squeak.js.org/etoys/#fullscreen
I think there is easier way than Leandro is proposing.
Just run the Workspace from the menu where you type:
Project enterNewWithInitialBalloons
Select it with mouse and run it - Do it (alt+d). Application should start. I'm unfamiliar with the application. To me it looks similar to the picture you show.
Edit: how did I find it?
I searched through the source code. I have to agree that this is not straight forward.
First I tried to find anything that has to do with Etoys project/class. I tried to find anything that would indicate that you can start it.
This way I found Etoys-Experimental package with class EToysLauncher. The word launcher to me sounded like it could be launched. I looked at the class of the EToysLauncher where I found instance creating protocol where you can find these methods (remember we are still at the experimental package!):
#buildGallery
#buildPanel
#openGallery
#openPanel
If you go through these e.g. EToysLauncher openPanel you will get a message doesNotUnderstand: #latestProjectVersionsFromFileEntries. I then started to investigate the Walkback. I tried to check what is the issue here. I got this message because of the last line ^ Project latestProjectVersionsFromFileEntries: entries.
I went to the Project>>latestProjectVersionsFromFileEntries: to check what it is actually doing. In meantime I have inspected the values from the entries variable in the debugger. In the entries I could find an OrderedCollection but nothing what would satisfy #('*.pr' '*.pr.gz' '*.project') from the method. So I thought to myself, that perphaps the Project itself could satisfy it.
I went to the Project class and protocol Etoys-Squeakland-instance creation where I found two methods #enterNew and #enterNewWithInitialBalloons.
The #enterNew gives doesNotUnderstand: #newMorphicOn: so I skipped that one and tried the #enterNewWithInitialBalloons, which worked and since it is in the protocol Etoys-Squeakland-instance creation I came to the conclusion it has create Etoys-Squeakland new instance.
Edit: Show shared flaps?
Yes, you can activate the flaps also via Show shared flaps.
There is, however, quite a difference between running the Project enterNewWithInitialBalloons and Showing the shared flaps via Preferences.
If you start the Etoys via the Project enterNewWithInitialBalloons you will start completely new project (your currently opened windows will be hidden). To see your previous windows you need to either Porojects/Enter Project and switch to the HomeProject or you have to close the newly opened project via Projects/Close This Project.
The source that shows it is:
enterNewWithInitialBalloons
| newP |
newP := MorphicProject new.
newP world addMorph: (DoCommandOnceMorph new extent: 1#1; actionBlock: [SugarNavigatorBar putUpInitialBalloonHelp]; yourself).
newP enter.
This creates new MorphicProject and to this project it adds new Morph.
On the other hand, if you start it with Preferences/Show shared flaps the flaps will be just added to your current environment without creating a new project.
The source that shows it is: Preferences class >>sharedFlapsSettingChanged
sharedFlapsSettingChanged
"The current value of the showSharedFlaps flag has changed; now react"
self showSharedFlaps "viz. the new setting"
ifFalse:
[Flaps globalFlapTabsIfAny do:
[:aFlapTab | Flaps removeFlapTab: aFlapTab keepInList: true]]
ifTrue:
[Smalltalk isMorphic ifTrue:
[self currentWorld addGlobalFlaps]]
The self currentWorld addGlobalFlaps adds the flaps to the currentWorld. The PasteUpMorph>>addGlobalFlaps creates new PasteUpMorph and adds it.
You can also notice the difference also in the menu bar title Untitled vs. HomeProject.

Adding "properties" to objects in a Blender scene

I am just starting my dive into Blender coming mainly from Quake's Radiant. I am trying to research whether it will fit the need I have for a level editor replacement. So with that in mind, here is my question:
What is the best method for creating and storing a set of prefab "entity" objects such as health packs, ammo pickups, and "moveable" objects such that they have a set of "properties" that can be changed within Blender?
I have found this page, but I am still getting lost as to how to integrate them on a per object basis and achieve the desired result:
https://docs.blender.org/manual/en/dev/editors/properties_editor.html
Note: It is not my goal to use the Blender game engine - just attach values to things for me to export to my own engine.
Edit1: Found an article discussing the topic although it seems very outdated:
https://www.gamasutra.com/blogs/IwanGabovitch/20120524/171032/Using_Blender_3D_as_a_3d_map_editor_rather_than_programming_your_own_from_scratch.php
Example:
// entity 105
{
"inv_item" "2"
"inv_name" "#str_02917"
"classname" "item_medkit"
"name" "item_medkit_11"
"origin" "-150 2322 72"
"triggerFirst" "1"
"triggersize" "40"
"rotation" "0.224951 0.97437 0 -0.97437 0.224951 0 0 0 1"
}
While we can manually add custom properties to any object, these are added to the specific object so can be unique to each object.
A better way of integrating new properties is to use bpy.props, these can be added to an objects class in blender, this means every object will have the same properties available.
You can setup a custom panel to edit your properties, like this simple example. Both the properties and panel as well as your object exporter can be defined in an addon which you can have enable at startup so that it is available every time you run blender. An addon also makes it easier for you to share your game editor with others.
The link I found seems to be the best option and allow for the most flexibility. The source code for the Super Tux Kart plugins serve as a great reference implementation:
https://sourceforge.net/p/supertuxkart/code/HEAD/tree/media/trunk/blender_26/

How to change Textmate's context menu key binding?

In Textmate there is a great shortcut to get to the context menu without using the mouse (I wish it worked systemwide!!!). It is Opt+F2.
When working on my Macbook, however, F2 is mapped to screen brightness, so I have to press fn+opt+F2, for which I have to use both hands - and that's quite uncomfortable.
Is the a way how I could map it to the right opt key, for example?
For TextMate 2 you can create ~/Library/Application Support/TextMate/KeyBindings.dict and let it contain something like:
{ "#d" = "showContextMenu:"; }
Here #d corresponds to ⌘D. See this blog post on how to construct the key equivalent strings.
Source: TextMate mailing list
Key binding files are read in the following order. A new binding for a bound key overrides the previous one:
/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
/Library/KeyBindings/DefaultKeyBinding.dict
~/Library/KeyBindings/DefaultKeyBinding.dict
/path/to/TextMate.app/Contents/Resources/KeyBindings.dict
~/Library/Application Support/TextMate/KeyBindings.dict
A relaunch of TextMate (⌃⌘Q) is required before changes take effect.

How to add a new method in Smalltalk source code?

I am new to Smalltalk and I am trying to add a new method in the Integer class present in Smalltalk. The method should go in the 'accessor' protocol. I am using VisualWorks and not finding any option to do that. I have gone through the developers guide still its not clear to me. Can someone please give me screen shots or step wise solution about how to proceed with it?
Open your browser window [Small Talk Launcher --> System --> Browser]
Select a Package
Select a Class
Select a Protocol to which you want to add your new method.
You can find the tab "source" below the 4 partitions [Package, Class, Protocol, Method].
Replace the text in that "source" tab with the source code of your method.
Go to to "edit" option in the Browser menu.
Select "Accept" option.
Your new method is added successfully!
Cheers!
Aditya.
If you go into Smalltalk idea, you'll de that classes are objects as well and that you can just say class to compile a new method e.i. add a new method to itself:
Integer compile: 'getSomeVar ^someVar' classified: 'someVar'
_This will add to Integer in someVar protocol a method called getSomeVar that will return someVarinstance variable._
But for a general workflow you should use tools provided by Smalltalk environment such as a System Browser mentioned by Aditya Kappagantula

titanium how do i add a view to the single context

So i have a titanium app, and i just read about single contexts. (Incidentally, somebody here should write a book about programming in titanium... the only one out there doesn't really mention single contexts or any of that new-fangled stuff. Heck, make it an eBook. I'd buy it)
The titanium documentation stresses their use (http://docs.appcelerator.com/titanium/latest/#!/guide/Coding_Strategies-section-29004891_CodingStrategies-Executioncontexts) and then politely forgets how to implement a single context!!
So, question:
Let's say i have the awesomeWidget page - this just shows a button, and when you click on a button a new screen appears.
The aswesomeWidget page is accessed through another page - it is not from the root of the titanium app.
Keeping to single contexts, how do i add the view that the button creates to the current window?
Do I:
keep a global pointer to the current (and only) window?
pass the variable holding the current window down to all the following pages that use it
something else?
First off, Titanium keeps a reference to your current window anyway for you, so this use case is easy. For example:
awesomeWidgetButton.addEventListener('click' function(e) {
var yourView = Ti.UI.createView({...});
Titanium.UI.currentWindow.add(yourView);
});
If you want to dig further, the concept of a single context is closely tied to the use of CommonJS modules and the require keyword. It is very simple to keep a single context, just never open a window with the url component filled out, and liberally use the require() keyword. Other than that, its up to your imagination to keep track of who points to what and vice versa, there are standard patterns and best practices that apply here (MVC, Singletons, just keep it simple) just as in coding in any other language.