[Drawkit] Introductory demo ??
Graham Cox
graham.cox at bigpond.com
Wed Jun 18 23:47:46 PDT 2008
Ah - you've run into a little issue that I fixed after the last beta
drop.
NSUndoManager indeed does not implement -changeCount, though
DKUndoManager does. So I added a respondsToSelector: check in the one
place I use it, with DKObjectDrawingLayer. The better solution would
be to swap the NSUndoManager for a DKUndoManager, but when the app
isn't document based, it's not clear how to do that. I've asked about
this on cocoa-dev.
For now you could add the check yourself to the code in DrawKit:
- (void) recordSelectionForUndo
{
if ( m_selectionUndo )
{
[m_selectionUndo release];
m_selectionUndo = nil;
}
// keep a note of the undo count at this point - if it hasn't changed
when the
// selection is committed, then don't record the selection change
unless the flag forces it.
if([[self undoManager] respondsToSelector:@selector(changeCount)]) //
<------------------------------------------ +
mUndoCount = [(DKUndoManager*)[self undoManager] changeCount];
m_selectionUndo = [[self selection] retain];
LogEvent_( kReactiveEvent, @"recorded selection for possible undo,
count = %d", mUndoCount );
}
- (void) commitSelectionUndoWithActionName:(NSString*) actionName
{
// sends the recorded selection to the undo manager. If sel changes
are not undoable on their own, the sel change is only
// added to the undo stack if some other operation has also occurred,
and then only if the selection actually
// changed. If the flag is to record all changes, unaccompanied sel
changes are recorded regardless.
unsigned cc;
if([[self undoManager]
respondsToSelector:@selector(changeCount)]) //
<------------------------------------------ +
cc = [(DKUndoManager*)[self undoManager] changeCount];
else
cc = mUndoCount + 1;
if (([self selectionChangesAreUndoable] || cc > mUndoCount) &&
m_selectionUndo != nil )
{
// if selection hasn't changed, do nothing
if([self selectionHasChangedFromRecorded])
{
LogEvent_( kStateEvent, @"selection changed - recording for undo");
[[self undoManager] registerUndoWithTarget:self
selector:@selector(setSelection:) object:m_selectionUndo];
// use the passed action name if there is one, otherwise any stored
action name
if ( actionName != nil )
[[self undoManager] setActionName:actionName];
}
}
else
{
// here, the selection is the only change, and it's not meant to be
undone, so
// do not set the action name
actionName = nil;
}
if ( actionName != nil )
[[self undoManager] setActionName:actionName];
// done with the recorded selection, so get rid of it
[m_selectionUndo release];
m_selectionUndo = nil;
}
cheers, Graham
On 19 Jun 2008, at 3:23 pm, Troy Rollins wrote:
>
> On Jun 19, 2008, at 12:46 AM, Graham Cox wrote:
>
>> I'll attach the project file to this message, but I'll also put the
>> project and executable up on the website so you can download it.
>> The single controller class is: a) the controller between the UI
>> shown here and DK, b) the application's delegate (to get a few
>> things set up at launch) c) the table's delegate and datasource and
>> d) the window's delegate. So it wears a few hats which also add a
>> little to its complexity, but overall it's extremely lightweight.
>> You can also get to a number of features by right-clicking objects
>> in the drawing (that's just default DK behaviour).
>
> Compiling doesn't seem to raise any issues, however I've been unable
> so far to actually create a drawing object.
>
> Mouse actions give me -
>
> 2008-06-19 01:18:57.257 DK Mini Demo[4380:10b] *** -[NSUndoManager
> changeCount]: unrecognized selector sent to instance 0x475610
> 2008-06-19 01:18:57.258 DK Mini Demo[4380:10b] *** -[NSUndoManager
> changeCount]: unrecognized selector sent to instance 0x475610
> 2008-06-19 01:18:57.407 DK Mini Demo[4380:10b]
> enableUndoRegistration: NSUndoManager 0x475610 is in invalid state,
> enableUndoRegistration may only be invoked with matching call to
> disableUndoRegistration
>
>
>
>
> --
> Troy
> RPSystems, Ltd.
> http://www.rpsystems.net
>
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net
More information about the Drawkit
mailing list