Accessing an outlet in Interface Builder in Document-Based Application - macruby

With MacRuby 0.12 and XCode 4.4.1 (Mountain Lion), I created a Document-Based Application.
In my document window nib, I have two objects:
A NSTextView (in a NSScrollView), which has a custom class MyView
A NSTextField
In my Ruby code, I have in MyView:
attr_accessor :field
I would like to bind this value to the NSTextField in Interface Builder.
When I select Bind to, the choices are limited to:
Shared User Defaults Controller
File's Owner
Application.
I choose the latter but then what should be the Model Key Path?
Furthermore, where is Application in my code? I don't see it anywhere in the template.

Might be related to this bug:
https://github.com/MacRuby/MacRuby/issues/135

Related

Form subclasses in codename one

I'm building an app in Codename one. I'm trying to both create a Form in the codename one resource GUI and specify its type used in code. Background is to be able to specify dynamically which data is used in the form.
Is this recommended and is there a recommended way to accomplish that?
Currently I'm digging into the codenameone code and it looks like one way would be to pass a custom-made resource to the StateMachine/UIBuilder. The UIBuilder asks the resource for the component type and use this to return a custom type,
and register the custom form types with lines like
UIBuilder.registerCustomComponent("MyForm",com.myapp.MyForm.class);
Any suggestions to this?
Right now the only way to do this in the old GUI builder is to replace all the forms with your new Form subclass which could be fine for many cases. E.g. override this in the state machine:
protected Component createComponentInstance(String componentType, Class cls) {
if(cls == From.class) {
return new MyForm();
}
return super.createComponentInstance(componentType, cls);
}
Notice that we are in the process of moving to a new more traditional GUI builder, right now its in technology preview state (translation: buggy as hell and lots of missing features) but this should be trivial in the future. See:
https://www.codenameone.com/blog/new-gui-builder.html
https://www.codenameone.com/blog/gui-builder-walkthru.html
https://www.codenameone.com/blog/terse-syntax-migration-wizard-more.html

CakePHP2.x Plugin consisting of single Pages view

My understanding of the CakePHP2 doc leads me to believe I can create a simple plugin that consists of a single view and that view can (if done correctly) override the default view.
For example, if the application has a app/View/Pages/foo.ctp that simply displays the text "Foo", then a Plugin in app/Plugin/Bar/View/Pages/foo.ctp that contains the text "Bar"
I've made sure that the bootstrap.php loads the plugin with CakePlugin::load('Bar');
And I've deleted app/tmp/cache//
From what I understand I'm not required by Cake to need a Controller or Model.
Yet, the application only displays "Foo" instead of the intended override of displaying "Bar".
From what I've described, what parts of my understanding or implementation approach seem wrong? (And why?) And what are the simple/better ways to implement this plugin view?
TIA
(I have read http://book.cakephp.org/2.0/en/plugins.html and http://book.cakephp.org/2.0/en/views.html)
Themes?
A theme is just a collection of template files that can be used to override the templates used in an application; whereas plugins also contain classes - are you looking for themes?
Creating a template in a plugin is not enough
Alone is not sufficient to just create a template file and load a plugin. To render it you'll need to either:
Explicitly render the file
I.e. In any controller:
$this->render('Bar.template_name')
Create an actual plugin
I.e. Create plugin files:
$ Console\cake bake plugin Bar
$ Console\cake bake controller Some --plugin Bar
$ etc.
$ echo "Something" > Plugin/Bar/View/Some/index.ctp
And request: http://yourapp.com/bar/index
See the docs on how to create a plugin for more information.

Best configuration and parameters for ctags in a CakePHP project

What is the best configuration and parameters for ctags in a CakePHP project?
I want to be able to auto-complete ctp files, Components, Behaviours, Models and Helpers?
Check these github repositories, I have found then and they are so good for work with php and cakephp
https://github.com/amix/vimrc
https://github.com/ndreynolds/vim-cakephp
This solution requires 1 line in your .ctags file and two lines in your .vimrc file, so it's fairly minimal.
tl;dr
.ctags:
--langmap=php:+.ctp
.vimrc:
# Controller -> Component
map <leader>t yiw<cr>:tag /^<C-R>"<CR>
# View -> Helper
map <leader>h yiw<cr>:tag /^<C-R>"Helper<CR>
Add Views to your tags
This solution is mostly for jumping between files. I'll try and add auto-completion at a later date.
Add this to your ~/.ctags options file to include CakePHP views as PHP files:
--langmap=php:+.ctp
Then I'm assuming you've done ctags -R . at the root of your project (that's what I've done at least). This out of the box should pick up PHP syntax and class definitions.
Auto-completion (general)
I found the auto-completion (omni-completion from Ctrl+XCtrl+O) doesn't work very nicely with PHP, e.g. if I type $this-> and then try to auto-complete it doesn't find any tags.
The fix for this was to use install phpcomplete.vim. This will find methods within your class.
However that won't auto-complete connected models.
Models
By default ctags should work for all Controller -> Model jumping as the Model name is the same as the class name.
Behaviors
These again should be fine as you don't specify the name of the behavior you just have the method name which depending on how independent the name is it should get found - or at least it will be in the list of tags.
Components
There's no direct way of mapping these, I couldn't see a way of mapping them through the ctags --regex options. ctags recognises that they are classes but doesn't know the xxx -> xxxComponent mapping.
However there is one slight trick. You can do a tag search on the beginning of the class name (source)
:tag /^Email
will find
class EmailComponent
You can then map this in your .vimrc
map <leader>t yiw<cr>:tag /^<C-R>"<CR>
This copies the word that you've got the cursor over and then pastes it into the tag command and executes it. My leader is set to ,, so I can type ,t and it takes me to the corresponding component under the cursor.
Helpers
Ok, another slight hack in the .vimrc file:
map <leader>h yiw<cr>:tag /^<C-R>"Helper<CR>
Using ,h, this will jump you from $html->... to
class HtmlHelper extends AppHelper {
But it doesn't work for functions inside e.g. if your cursor is over script in $html->script, it will not take you to the HtmlHelper script method. So it's a work in progress.

Change NamespaceManager on Full Text Search GAE

We have an application in GAE, and we are reenginering this to use Full Text. We have to index all data already in the GAE and our application also use namespaces.
We are trying to create a java procedure to be runned by administrator, who has not namespace. In other services, we have created similar java procedures, applying namespace by code, so the idea is to index all data in each namespace. (We use NamespaceFilter to control user domain.)
This is part of code:
private static final Index INDEX = SearchServiceFactory.getSearchService()
.getIndex(IndexSpec.newBuilder().setName("Actividad"));
NamespaceManager.set("userdomain1");
INDEX.add(doc);
Setting namespace is ignored.
Is this the expected behaviour? Is there an alternative way to index all the information in every namespace?
With similar code on datastore it's work fine.
A SearchService object is bound to a namespace, so you need to call NamespaceManager.set() before calling SearchServiceFactory.getSearchService(). Alternatively, call the version of getSearchService() that has a namespace parameter. See:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/SearchServiceFactory#getSearchService(java.lang.String)

App Engine - why are there PhoneNumber, Link, Rating etc classes?

I haven't found any reason for the existence of a few of the App Engine classes. There's a PhoneNumber, a Link, a PostalAddress, a GeoPt, a Rating, etc. Why are these given special treatment? They don't seem to have any smarts - e.g. geo searching. I know Link has more space than a String property, but the rest?
See:
http://code.google.com/appengine/docs/java/datastore/dataclasses.html
Those types are 'semantic' types. They're present in the Java API for parity with the Python API. In the Python API, they define special behaviour with regards to the .to_xml() method - for example, a PhoneNumberProperty serializes like this:
<property name="foo" type="gd:phonenumber"><gd:phoneNumber>12345-678</gd:phoneNumber></property>
I think they're mostly just there to cover common cases and save developers time. If a lot of apps use a phone number field, why require each developer to have to write them? A developer can still write their own if they need/want to.
Not sure about java, but in python the following model/code (tested on dev server) will throw BadValueError, with the message "Invalid URL: stackoverflow.com"
class foo(db.model):
link = db.LinkProperty()
bar = foo()
bar.link = 'stackoverflow.com'
While:
bar.link = 'http://stackoverflow.com'
Works fine.
I haven't tested, but the other properties may or may not also do validation.
Basically using this types in your models allows to add indirect meta data to your code. This may be useful if you are working with any kind of universal renderer for your model classes or if you are performing validation of user input on your models.
For example if you are using PhoneNumber type for a field named userNumber you reflection based renderer may understand that it should automatically assign corresponding validator to text field which will represent it.
Regards,
Pavel.

Resources