Automatically generated predicate row templates for to-many key? - cocoa

In my Core Data managed object model, I have an entity Foo with a to-many relationship (with a to-many inverse) to entity Baz named baz. Baz has a string property named "tag". When I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:#"baz.tag"] inEntityDescription:FooDescription] to create the row editors for an NSPredicateEditor, the result contains (as expected) a row template like
[Popup: baz.tag] [Popup: Contains|is|is not|...] [TextField]
When I select "Contains" from the popup, a query with the predicate works as expected. If I choose any of the other popups (e.g. "is"), I get the following error: "to-many key not allowed here". Can I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] or do I have to build the row editor manually?

It looks like the automatically generated template (using [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]) cannot produce the correct operators. The solution is to create the template manually using [NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:]. For the given example:
id template = [[NSPredicateEditorRowTemplate initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:#"baz.tag"]] rightExpressionAttributeType:NSStringAttributeType modifier:NSAnyPredicateModifier operators:keywordOperators options:0];

Related

AppleScript: Using "whose" with record values does not work

In my scriptable app, one of the properties is of a named record type, and that record type has been declared in the sdef as well (named "custom record").
I can get the record like this:
get owner of anElement
--> {pool:"test", position:2}
I can also successfully test for it like this:
set target to {pool:"test", position:2}
if owner of anElement = target then
-- found!
But I cannot use it in a whose clause:
get allElements whose owner = target
--> {}
I also cannot use missing value in the test:
get allElements whose owner = missing value
--> error number -1700 from missing value to custom record
Is that expected behavior with AppleScript, i.e. is it unable to handle records in whose clauses?
Or am I doing something wrong? I have so far not implemented any coercion handlers nor special record handlers because nothing has indicated that I'd need them.
Also, please see my related question: Cocoa Scripting: Returning "null" vs. "missing value"
Short answer : It's expected behavior.
The whose clause works only for element reference types (classes which have an object specifier), but not for record types and custom lists.
Even the selection property of the Finder cannot be filtered by a whose clause.

Need to find Property name

I have several tables in my application that are displaying lists of objects from classes. I have properties to represent each value in those classes as defined in the following example
...
Public Property Cod() As Int32
Get
Return _codigo
End Get
Set(ByVal Value As Int32)
_codigo = value
End Set
End Property
...
My code hides every column and then, I use the "formatarCol" method to state which columns I want shown represented as the second parameter(which must have the same name as the properties mentioned above) and the name to be displayed for that column as the third parameter.
...
Utilidades.formatarCol(.Columns, "Cod", "Cod")
Utilidades.formatarCol(.Columns, "Estab", "Estabelecimento")
Utilidades.formatarCol(.Columns, "Sel", "Sel.")
...
Everything is working fine but I was trying to rename some of the properties. If I rename said properties I have to go to each table and manually change each string. I can't just use a replace all because different classes may have properties with the same name.
I was hoping that someone had a suggestion on how to get the Property's name instead of manually adding a string so that if I need to rename a Property again I won't have to manually go through every column where it's used and change the string.
You can rename property via refactor:
Right click your property in code -> Refactor -> Rename
It will only rename property for your class and for all occurrences of that property.
To access the name of a property in a class you can use NameOf
Example:
NameOf([Namespace to class].Cod) //returns "Cod"

Is it possible to instruct a `Gtk::TreeView` to display a custom type?

There is something I don't understand how to do with Gtkmm 3.
I have a custom business type that I have declared like this:
enum class Eurocents : int {};
I would like to render this type into a Gtk::TreeView which has a Gtk::ListStore as model. So I declare a Gtk::TreeModelColumn<Eurocents>, and add it to the model. I then append_column this model column to the Gtk::TreeView with an appropriate title.
I then append_row to the model and set the value corresponding to the column to (Eurocents)100.
The result I get is that the cell is displayed empty. Understandably so, because I would not expect Gtkmm to know how to render my arbitrary type.
I would like to instruct Gtkmm on how to render my type.
I already know how to display Glib types like Glib::ustring and formatting to Glib::ustring for display is possible, but it is not the subject of the question.
Is it possible to code columns that can display arbitrary types like this? And if so, how? What is required for sorting to work?
The most common, and easiest way, is to use a cell_data_func callback. For instance, you can create your own instance of a Gtk::TreeView::Column (the view column), pack a cell renderer (or more) into your Gtk::TreeView::Column, append your Gtk::TreeView::Column to the TreeView with Gtk::TreeView::append_column(), and call set_cell_data_func() on your Gtk::TreeView::Column():
https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeViewColumn.html#a3469e1adf42e5932ea123ec33e4ce4e1
You callback would then get the value(s) from the model and set the appropriate values of the properties of the renderer(s).
Here is an example that shows the use of set_cell_data_func(), as well as showing other stuff:
https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-examples.html.en#sec-editable-cells-example
This link should also be useful:
https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview.html.en#treeview-cellrenderer-details
If you like, Gtk::TreeView::insert_column_with_data_func() makes this a little more concise: https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeView.html#a595dcc0b503a7c1004c296b82c51ac54
As for the sorting, you should be able to just call set_sort_func() to specify how the column is sorted: https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeSortable.html#a3a6454bd0a285324c71edb73e403cb1c
Then this regular sorting advice should apply: https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-sort.html.en

NSSearchField not working as expected

I'm trying to follow Marcus Zarra in his book 'Core Data'. In the book, he makes a small sample application, but it doesn't give much help when things don't work out...
He starts out by visually designing three entities, and then adding array controllers for each entity to the main nib.
Second, he adds a tableview and some other visual components to show data from the array controllers.
So far, I have managed to follow, but now he adds a search field to the gui, and binds it to the same array controller as one of the tableviews. Expected behavior would be for the tableview to get filtered when typing in the search field, but nothing happens.
How do I find out what's wrong?
The relevant parts from the nib is as follow:
NSArrayController Recipes
- Mode = Entity
- Enitity Name = Recipe
TableView w/TableColumn
- Value Bind To Recipes
-- Controller Key = arrangedObjects
-- Model Key Path = name
Search Field
- Predicate Bind To Recipes
-- Controller Key = filterPredicate
-- Model Key Path = name
-- Display name = predicate
-- Predicate Format = keyPath contains $value
There are no relevant messages in the console.
regards,
-Vegar
The book example is wrong and will be fixed in the next printing. You can remove the Model Key Path entirely as it is never read and change the predicate format to:
name contains[c] $value

How do I swap items in a VB6 collection?

If I have a collection of forms (myForms) and I want to switch the position of two forms in the collection (say items 3 and 4 for example), I would expect that the following code would work:
Dim temp as Form
Set temp = myForms(3)
Set myForms(3) = myForms(4)
Set myForms(4) = temp
But that doesn't work. It fails at the third line with the error "Controls property is read only." If I change the line to:
myForms(3) = myForms(4)
I get a type mismatch error instead.
If myForms is a standard collection:
Dim myForms as New Collection
(which is actually different from the controls collection) and you've added the forms using:
myForms.Add frmOne, myForms.Add frmTwo
etc then (yes) you do need to use the Add and Remove methods because of the way the collection references the added objects.
Otherwise the interpretation is that you actually want to replace one form with another and this is not allowed. You can't say:
Set frmOne = frmTwo
unless these are actually variables of type Form.
Why do you need to switch the order? Are you referencing the item numbers somewhere? Would using a Dictionary to collect the forms and reference them by a key be useful?
PS. The type mismatch is simply because both items are objects and need to be 'Set'.
You can't actually swap around items in the controls collection in VB6. You need to use the Add and Remove functions associated with each. Check out this article:
http://support.microsoft.com/kb/190670
Hope this helps!

Resources