From c80afb451422c35cd249fb5509e80c00d9a75018 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Mar 2005 05:11:41 +0000 Subject: [PATCH] Added some code which tries another way to change the font if the responder chain isn't sucessful in locating the object to call changeFont: on. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20871 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++++ GNUmakefile | 2 + GormDocument.h | 1 + GormDocument.m | 5 ++- NSFontManager+GormExtensions.h | 34 +++++++++++++++ NSFontManager+GormExtensions.m | 77 ++++++++++++++++++++++++++++++++++ 6 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 NSFontManager+GormExtensions.h create mode 100644 NSFontManager+GormExtensions.m diff --git a/ChangeLog b/ChangeLog index 76effb15..d7367033 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-03-08 00:15 Gregory John Casamento + + * GNUmakefile: Added new files. + * GormDocument.h: Added header for InterfaceBuilder.h to get + the necessary interface declarations. + * GormDocument.m: Change to retain and release the last used + editor. + * NSFontManager+GormExtensions.[hm]: New files. + 2005-03-07 22:18 Gregory John Casamento * GormDocument.m: Added code to make the window of the widget diff --git a/GNUmakefile b/GNUmakefile index c42095a9..fc1e87e1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -182,6 +182,7 @@ Gorm_HEADERS = \ GormViewWithContentViewEditor.h \ GormViewWithSubviewsEditor.h \ NSColorWell+GormExtensions.h \ + NSFontManager+GormExtensions.h \ NSView+GormExtensions.h Gorm_OBJC_FILES = \ @@ -235,6 +236,7 @@ Gorm_OBJC_FILES = \ GormViewWithSubviewsEditor.m \ GormWindowEditor.m \ NSColorWell+GormExtensions.m \ + NSFontManager+GormExtensions.m \ NSView+GormExtensions.m \ main.m \ Gorm.m diff --git a/GormDocument.h b/GormDocument.h index 8a29c2ee..ef128537 100644 --- a/GormDocument.h +++ b/GormDocument.h @@ -29,6 +29,7 @@ #include #include #include +#include @class GormClassManager, GormClassEditor, GormObjectProxy, GormFilesOwner; diff --git a/GormDocument.m b/GormDocument.m index ea30e609..42f939e8 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -916,7 +916,8 @@ static NSImage *fileImage = nil; - (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver: self]; - + ASSIGN(lastEditor, nil); + // close the window... [window close]; @@ -2960,7 +2961,7 @@ static NSImage *fileImage = nil; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSDebugLog(@"setSelectionFromEditor %@", anEditor); - lastEditor = anEditor; + ASSIGN(lastEditor, anEditor); [(Gorm *)NSApp stopConnecting]; // cease any connection if ([(NSObject *)anEditor respondsToSelector: @selector(window)]) { diff --git a/NSFontManager+GormExtensions.h b/NSFontManager+GormExtensions.h new file mode 100644 index 00000000..aa0c1e09 --- /dev/null +++ b/NSFontManager+GormExtensions.h @@ -0,0 +1,34 @@ +/* NSFontManager+GormExtensions.h + * + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * Author: Gregory John Casamento + * Date: 2005 + * + * This file is part of GNUstep. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef INCLUDED_NSFontManager_GormExtensions_h +#define INCLUDED_NSFontManager_GormExtensions_h + +#include + +@interface NSFontManager (GormExtensions) +- (BOOL) sendAction; +@end + +#endif diff --git a/NSFontManager+GormExtensions.m b/NSFontManager+GormExtensions.m new file mode 100644 index 00000000..0ef52f7c --- /dev/null +++ b/NSFontManager+GormExtensions.m @@ -0,0 +1,77 @@ +/* NSFontManager+GormExtensions.m + * + * Copyright (C) 2004 Free Software Foundation, Inc. + * + * Author: Gregory John Casamento + * Date: 2004 + * + * This file is part of GNUstep. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include "NSFontManager+GormExtensions.h" +#include "GormDocument.h" + +@interface GormDocument (FontManagerMethod) +- (id) lastEditor; +@end + +@implementation GormDocument (FontManagerMethod) +- (id) lastEditor +{ + return lastEditor; +} +@end + +@implementation NSFontManager (GormExtensions) + +- (BOOL) sendAction +{ + NSApplication *theApp = [NSApplication sharedApplication]; + BOOL result = NO; + + if (_action) + result = [theApp sendAction: _action to: nil from: self]; + + if(result == NO) + { + id object = [(GormDocument *)[(id)NSApp activeDocument] lastEditor]; + NS_DURING + { + if(object != nil) + { + if([object respondsToSelector: _action]) + { + [object performSelector: _action withObject: self]; + result = YES; + } + } + } + NS_HANDLER + { + NSDebugLog(@"Couldn't set font on %@: %@", object, [localException reason]); + result = NO; // just to be sure. + } + NS_ENDHANDLER + } + + return result; +} + +@end