[OMC] OMC 2.0.1pr1

OnMyCommand discussion omc at abracode.com
Wed Sep 3 23:30:02 PDT 2008


Hello,

OMC 2.0.1 preview 1 is available at:
http://www.abracode.com/free/cmworkshop/OMC_2.0.1pr1.zip
See release notes below.
I have been working on Cocoa progress dialog but it is not finished and is
disabled in this build. Old Carbon progress should work as usual.
Instead, thanks to feedback from Rudi Grams, I focused on adding more
control and flexibility to Cocoa nib dialogs. All improvements in this
release are Cocoa only - Carbon nib dialogs are not actively developed
anymore.
omc_dialog_control can send messages to the dialog window itself in addition
to controls and views. Instead of specifying a control number you write
omc_window and the target will be your dialog window. Only a couple of
messages apply to windows though (move, resize, close, select).

All features mentioned above are evolutionary improvements but what really
got me excited and what I consider a paradigm shift is omc_invoke option,
which allows you to send an ObjC message to a control, window, application
or workspace. It is a new bridge between command line tool and Cocoa code.
This option opens new possibilities of controlling UI elements of the OMC
dialog and may take you beyond the bare bones support previously offered by
omc_dialog_control. A simple example to demonstrate the syntax:
omc_dialog_control $OMC_NIB_DLG_GUID 1 omc_invoke setEditable: NO
It is as if you wrote in ObjC:
[editField1 setEditable:NO];
You need to consult Cocoa developer documentation which methods are
implemented by which controls to get it to work. There are of course some
limitations and caveats when using omc_invoke (see release notes) because
great power gives you great opportunities to cause disasters.
I hope some people will find it as useful as I found it exciting to develop.
 
Enjoy,
Tom
Abracode



OMC 2.0.1 Preview 1 (September 3, 2008)

1. Added support for controls in NSTabView in Cocoa nib dialogs
2. Added new messages to omc_dialog_control and new message targets:
omc_window, omc_application, omc_workspace
    omc_select  ‹ brings dialog window to front
    omc_terminate_ok ‹ close dialog with OK message
    omc_terminate_cancel ‹  close dialog with Cancel message
    omc_resize ‹ for dialog window or controls
    omc_move ‹ for dialog window or controls
    omc_scroll  ‹ scroll  a view within NSScrollerView
    omc_invoke  ‹ send an Obj-C message to control or window
Example usage of new
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID omc_window
omc_resize 600 200
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID omc_window
omc_move 50 30
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID omc_window
omc_terminate_ok
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID omc_window
omc_select
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 1 omc_resize
160 22
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 2 omc_scroll 0
0

The syntax for omc_invoke is that you specify parts of the method name and
arguments separated by spaces:
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 1 omc_invoke
someMethod: arg1 andMore: arg2.
This equivalent to calling ObjC:
[myObject1 someMethod:arg1 andMore:arg2];
In most cases you will deal with methods taking only one argument, for
example a command sent to NSTextField control with tag 1:
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 1 omc_invoke
setEditable: NO
is equivalent to calling:
[editField1 setEditable:NO];
OMC supports several types of arguments you can pass when calling ObjC
message. All types of numbers are supported (int, float, double, long long,
etc). Enum values are also supported but not by the enum name and rather by
its value - you need to find the actual integer value in documentation or
haders. BOOL values can be set as 1/0 or YES/NO or true/false (case
insensitive). Most common structures are also supported:
NSRange = {location, length}
NSPoint = {x, y}
NSSize = {width, height}
NSRect = {{x, y}, {width, height}}

When passing a structure argument you pass a string of numbers separated by
commas but not spaces so in command line they appear as one argument when
invoking omc_dialog_control:
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 2 omc_invoke
setFrame: 20,20,200,200
equivalent to 
[view2 setFrame: NSMakeRect(20, 20, 200, 200)]; //BTW, remember Cocoa
coordinate system starts at bottom-left and positive y goes up

omc_invoke also supports passing strings as arguments. They end up as
NSString * in method call. Unfortunately there is currently no way to pass
other types of Coca objects as arguments. So for example you cannot pass
NSColor or NSFont objects. With some extra work this limitation might be
overcome if there is enough interest in the omc_invoke feature.
If you want to use nil for calls which take optional objects you can do it
using omc_nil special word, for example:
"$OMC_OMC_SUPPORT_PATH/omc_dialog_control" $OMC_NIB_DLG_GUID 3 omc_invoke
performClick: omc_nil

omc_invoke messages may be directed not only to controls in the dialog but
also to the dialog window itself (omc_window, NSWindow), the host
application (omc_application, NSApplication), or user workspace shared
object (omc_workspace, NSWorkspace). The last target handles messages that
affect the system  or Finder.

omc_invoke is very powerful but also dangerous: you can easily crash the
host app if you call some method incorrectly. You may also cause leaks if
you call a method that creates some object. In general omc_invoke method
ignores the return value from the call. It would be hard to return this
value to sender because the message travels asynchronously across processes.
So it really does not make sense to call any "getter" methods but rather
some "setter" methods.
Additional limitation is that you can only call instance methods of
supported targets (denoted with -), not class methods (denoted with +).

3. Added scroller.omc example in Examples/External modules/.
4. Added OMCView for Cocoa nib dialogs. It is a subclass of NSView which
just adds a tag id so you can embed controls inside and send messages to it
(move, resize, scroll, etc)






More information about the OMC mailing list