Cleanup of preferences and addition of a new preferences module.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@18597 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-02-15 00:50:50 +00:00
parent 1f430325c8
commit 8053f279cf
18 changed files with 652 additions and 5 deletions

View file

@ -1,3 +1,14 @@
2004-02-14 19:55 Gregory John Casamento <greg_casamento@yahoo.com>
* GormShelfPref.[hm]: Added controller class for new preferences
module.
* GormShelfPref.gorm: Added interface for new preferences
module.
Thanks to Enrico Sersale. This preferences module for Gorm
is based heavily on code that he wrote for GWorkspace.
* Gorm.m: Definitions for notification.
* GormPrivate.h: Declaractions for notification.
2004-02-12 22:42 Gregory John Casamento <greg_casamento@yahoo.com>
* GormClassInspector.m: Added category to allow direct manipulation

View file

@ -3,4 +3,5 @@
ShowPalettes = YES;
ShowInspectors = YES;
HeaderList = ();
CellSizeWidth = 72;
}

View file

@ -115,6 +115,8 @@ Gorm_RESOURCE_FILES = \
Images/tabtop_nib.tiff \
Images/tabbot_nib.tiff \
Images/GormView.tiff \
Images/LeftArr.tiff \
Images/RightArr.tiff \
Resources/GormViewSizeInspector.gorm \
Resources/GormCustomClassInspector.gorm \
Resources/GormSoundInspector.gorm \
@ -122,6 +124,7 @@ Gorm_RESOURCE_FILES = \
Resources/GormPreferences.gorm \
Resources/GormPrefHeaders.gorm \
Resources/GormPrefGeneral.gorm \
Resources/GormShelfPref.gorm \
Resources/GormScrollViewAttributesInspector.gorm \
Resources/GormNSSplitViewInspector.gorm \
Resources/GormClassInspector.gorm \
@ -162,7 +165,8 @@ Gorm_HEADERS = \
GormFontViewController.h \
GormSetNameController.h \
GormGeneralPref.h \
GormFunctions.h
GormFunctions.h \
GormShelfPref.h
Gorm_OBJC_FILES = \
Gorm.m \
@ -206,7 +210,8 @@ Gorm_OBJC_FILES = \
GormFontViewController.m \
GormSetNameController.m \
GormGeneralPref.m \
GormFunctions.m
GormFunctions.m \
GormShelfPref.m
-include GNUmakefile.preamble

1
Gorm.m
View file

@ -39,6 +39,7 @@ NSString *GormDidModifyClassNotification = @"GormDidModifyClassNotification";
NSString *GormDidAddClassNotification = @"GormDidAddClassNotification";
NSString *GormDidDeleteClassNotification = @"GormDidDeleteClassNotification";
NSString *GormWillDetachObjectFromDocumentNotification = @"GormWillDetachObjectFromDocumentNotification";
NSString *GormResizeCellNotification = @"GormResizeCellNotification";
@class InfoPanel;

View file

@ -1707,7 +1707,7 @@ static NSImage *classesImage = nil;
mainRect.origin = NSMakePoint(0,0);
scrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
[scrollView setHasVerticalScroller: YES];
[scrollView setHasHorizontalScroller: NO];
[scrollView setHasHorizontalScroller: YES];
[scrollView setAutoresizingMask:
NSViewHeightSizable|NSViewWidthSizable];
[scrollView setBorderType: NSBezelBorder];

View file

@ -35,4 +35,11 @@ NSArray* findAllSubmenus(NSArray *array);
// find all items in the menu...
NSArray* findAll(NSMenu *menu);
// cut the file label to the appropriate length...
NSString *cutFileLabelText(NSString *filename, id label, int length);
// get the cell size for all editors
NSSize defaultCellSize();
#endif

View file

@ -67,3 +67,79 @@ NSArray* findAll(NSMenu *menu)
NSArray *items = [menu itemArray];
return findAllSubmenus(items);
}
// cut the text... code taken from GWorkspace, by Enrico Sersale
static inline NSString *cutText(NSString *filename, id label, int lenght)
{
NSString *cutname = nil;
NSString *reststr = nil;
NSString *dots;
NSFont *labfont;
NSDictionary *attr;
float w, cw, dotslenght;
int i;
cw = 0;
labfont = [label font];
attr = [NSDictionary dictionaryWithObjectsAndKeys:
labfont, NSFontAttributeName, nil];
dots = @"...";
dotslenght = [dots sizeWithAttributes: attr].width;
w = [filename sizeWithAttributes: attr].width;
if (w > lenght)
{
i = 0;
while (cw <= (lenght - dotslenght))
{
if (i == [filename cStringLength])
{
break;
}
cutname = [filename substringToIndex: i];
reststr = [filename substringFromIndex: i];
cw = [cutname sizeWithAttributes: attr].width;
i++;
}
if ([cutname isEqual: filename] == NO)
{
if ([reststr cStringLength] <= 3)
{
return filename;
}
else
{
cutname = [cutname stringByAppendingString: dots];
}
}
else
{
return filename;
}
}
else
{
return filename;
}
return cutname;
}
NSString *cutFileLabelText(NSString *filename, id label, int length)
{
if (length > 0)
{
return cutText(filename, label, length);
}
return filename;
}
NSSize defaultCellSize()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int width = [defaults integerForKey: @"CellSizeWidth"];
NSSize size = NSMakeSize(width, 72);
return size;
}

View file

@ -23,6 +23,7 @@
*/
#include "GormPrivate.h"
#include "GormFunctions.h"
/*
* Method to return the image that should be used to display objects within
@ -238,6 +239,12 @@ static NSMapTable *docMap = 0;
- (void) handleNotification: (NSNotification*)aNotification
{
NSString *name = [aNotification name];
if([name isEqual: GormResizeCellNotification])
{
NSDebugLog(@"Recieved notification");
[self setCellSize: defaultCellSize()];
}
}
@ -267,7 +274,7 @@ static NSMapTable *docMap = 0;
IBObjectPboardType, GormLinkPboardType, nil]];
[self setAutosizesCells: NO];
[self setCellSize: NSMakeSize(72,72)];
[self setCellSize: defaultCellSize()];
[self setIntercellSpacing: NSMakeSize(8,8)];
[self setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
[self setMode: NSRadioModeMatrix];
@ -290,6 +297,13 @@ static NSMapTable *docMap = 0;
[self setEditor: self
forDocument: aDocument];
[self addObject: anObject];
// set up the notification...
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(handleNotification:)
name: GormResizeCellNotification
object: nil];
}
return self;
}

View file

@ -13,6 +13,7 @@
id _generalView;
id _headersView;
id _shelfView;
}
- (void) popupAction: (id)sender;

View file

@ -1,6 +1,7 @@
#include "GormPrefController.h"
#include "GormGeneralPref.h"
#include "GormHeadersPref.h"
#include "GormShelfPref.h"
#include <AppKit/NSBox.h>
#include <AppKit/NSPopUpButton.h>
@ -13,6 +14,7 @@
{
_generalView = [[GormGeneralPref alloc] init];
_headersView = [[GormHeadersPref alloc] init];
_shelfView = [[GormShelfPref alloc] init];
[prefBox setContentView:[_generalView view]];
@ -36,9 +38,12 @@
case 1:
[prefBox setContentView: [_headersView view]];
break;
case 2:
[prefBox setContentView: [_shelfView view]];
break;
default:
NSLog(@"Ouch Default : - (void) popupAction: (id)sender");
break;
}
}
}

View file

@ -43,6 +43,7 @@ extern NSString *GormDidModifyClassNotification;
extern NSString *GormDidAddClassNotification;
extern NSString *GormDidDeleteClassNotification;
extern NSString *GormWillDetachObjectFromDocumentNotification;
extern NSString *GormResizeCellNotification;
// templates
@interface GSNibItem (GormAdditions)

84
GormShelfPref.h Normal file
View file

@ -0,0 +1,84 @@
/* GormShelfPref.h
*
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* Author: Gregory Casamento <greg_casamento@yahoo.com>
* Date: February 2004
*
* Author: Enrico Sersale <enrico@imago.ro>
* Date: August 2001
*
* This class is heavily based on work done by Enrico Sersale
* on ShelfPref.h for GWorkspace.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef GORMSHELFPREF_H
#define GORMSHELFPREF_H
#include <AppKit/NSView.h>
#include <Foundation/NSObject.h>
typedef enum {
leftarrow,
rightarrow
} ArrowPosition;
@class NSEvent;
@class NSNotification;
@interface ArrResizer : NSView
{
NSImage *arrow;
ArrowPosition position;
id controller;
}
- (id)initForController:(id)acontroller
withPosition:(ArrowPosition)pos;
- (ArrowPosition)position;
@end
@interface GormShelfPref : NSObject
{
IBOutlet id win;
IBOutlet id prefbox;
IBOutlet id iconbox;
IBOutlet id imView;
IBOutlet id leftResBox;
IBOutlet id rightResBox;
IBOutlet id nameField;
IBOutlet id setButt;
ArrResizer *leftResizer;
ArrResizer *rightResizer;
NSString *fname;
int cellsWidth;
}
- (void)tile;
- (void)selectionChanged:(NSNotification *)n;
- (void)startMouseEvent:(NSEvent *)event
onResizer:(ArrResizer *)resizer;
- (void)setNewWidth:(int)w;
- (IBAction)setDefaultWidth:(id)sender;
- (NSView *)view;
- (int) shelfCellsWidth;
@end
#endif

272
GormShelfPref.m Normal file
View file

@ -0,0 +1,272 @@
/* GormShelfPref.m
*
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* Author: Gregory Casamento <greg_casamento@yahoo.com>
* Date: February 2004
*
* Author: Enrico Sersale <enrico@imago.ro>
* Date: August 2001
*
* This class is heavily based on work done by Enrico Sersale
* on ShelfPref.m for GWorkspace.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include "GormFunctions.h"
#include "GormShelfPref.h"
#include "GormPrivate.h"
#define BOX_W 197
#define NAME_OR_Y 5
#define NAME_W 16
#define NAME_MARGIN 6
#ifndef max
#define max(a,b) ((a) > (b) ? (a):(b))
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a):(b))
#endif
static NSString *nibName = @"GormShelfPref";
@implementation ArrResizer
- (void)dealloc
{
RELEASE (arrow);
[super dealloc];
}
- (id)initForController:(id)acontroller
withPosition:(ArrowPosition)pos
{
self = [super init];
[self setFrame: NSMakeRect(0, 0, 16, 16)];
position = pos;
controller = acontroller;
if (position == leftarrow) {
ASSIGN (arrow, [NSImage imageNamed: @"LeftArr.tiff"]);
} else {
ASSIGN (arrow, [NSImage imageNamed: @"RightArr.tiff"]);
}
return self;
}
- (ArrowPosition)position
{
return position;
}
- (void)mouseDown:(NSEvent *)e
{
[controller startMouseEvent: e onResizer: self];
}
- (void)drawRect:(NSRect)rect
{
[super drawRect: rect];
[arrow compositeToPoint: NSZeroPoint operation: NSCompositeSourceOver];
}
@end
@implementation GormShelfPref
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
TEST_RELEASE (prefbox);
RELEASE (leftResizer);
RELEASE (rightResizer);
RELEASE (fname);
[super dealloc];
}
- (id)init
{
self = [super init];
if ((self = [super init]) != nil)
{
if ([NSBundle loadNibNamed: nibName owner: self] == NO)
{
NSLog(@"failed to load %@!", nibName);
}
else
{
int orx;
RETAIN (prefbox);
RELEASE (win);
[imView setImageScaling: NSScaleProportionally];
// set up the info...
[imView setImage: [NSImage imageNamed: @"GormObject.tiff"]];
ASSIGN(fname, @"GormSampleObjectName");
cellsWidth = [self shelfCellsWidth];
orx = (int)((BOX_W - cellsWidth) / 2);
leftResizer = [[ArrResizer alloc] initForController: self
withPosition: leftarrow];
[leftResizer setFrame: NSMakeRect(0, 0, NAME_W, NAME_W)];
[(NSBox *)leftResBox setContentView: leftResizer];
[leftResBox setFrame: NSMakeRect(orx - NAME_W, NAME_OR_Y, NAME_W, NAME_W)];
rightResizer = [[ArrResizer alloc] initForController: self
withPosition: rightarrow];
[rightResizer setFrame: NSMakeRect(0, 0, NAME_W, NAME_W)];
[(NSBox *)rightResBox setContentView: rightResizer];
[rightResBox setFrame: NSMakeRect(orx + cellsWidth, NAME_OR_Y, NAME_W, NAME_W)];
[nameField setFrame: NSMakeRect(orx, NAME_OR_Y, cellsWidth, NAME_W)];
[nameField setStringValue: cutFileLabelText(fname, nameField, cellsWidth -NAME_MARGIN)];
/* Internationalization */
[setButt setTitle: _(@"Default")];
[iconbox setTitle: _(@"Title Width")];
}
}
return self;
}
- (NSView *)view
{
return ((NSView *)prefbox);
}
- (void)selectionChanged:(NSNotification *)n
{
/*
NSArray *selPaths = [gw selectedPaths];
int count = [selPaths count];
NSString *fpath = [selPaths objectAtIndex: 0];
NSString *defApp;
NSString *type;
ASSIGN (fname, [fpath lastPathComponent]);
[imView setImage: @"GormObject.tiff"];
cellsWidth = [self shelfCellsWidth];
[self tile];
*/
}
- (int) shelfCellsWidth
{
// return the current cell width;
return [[NSUserDefaults standardUserDefaults] integerForKey: @"CellSizeWidth"];
}
- (void)tile
{
int orx = (int)((BOX_W - cellsWidth) / 2);
[nameField setFrame: NSMakeRect(orx, NAME_OR_Y, cellsWidth, NAME_W)];
[nameField setStringValue: cutFileLabelText(fname, nameField, cellsWidth -NAME_MARGIN)];
[leftResBox setFrame: NSMakeRect(orx - NAME_W, NAME_OR_Y, NAME_W, NAME_W)];
[rightResBox setFrame: NSMakeRect(orx + cellsWidth, NAME_OR_Y, NAME_W, NAME_W)];
[iconbox setNeedsDisplay: YES];
}
- (void)startMouseEvent:(NSEvent *)event onResizer:(ArrResizer *)resizer
{
NSApplication *app = [NSApplication sharedApplication];
NSDate *farAway = [NSDate distantFuture];
ArrowPosition pos = [resizer position];
int orx = (int)[prefbox convertPoint: [event locationInWindow] fromView: nil].x;
NSView *resbox1 = (pos == leftarrow) ? leftResBox : rightResBox;
NSView *resbox2 = (pos == leftarrow) ? rightResBox : leftResBox;
unsigned int eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
NSEvent *e;
[prefbox lockFocus];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
e = [app nextEventMatchingMask: eventMask
untilDate: farAway
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
while ([e type] != NSLeftMouseUp)
{
int x = (int)[prefbox convertPoint: [e locationInWindow] fromView: nil].x;
int diff = x - orx;
int orx1 = (int)[resbox1 frame].origin.x;
int orx2 = (int)[resbox2 frame].origin.x;
if ((max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff)) < 160
&& (max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff)) > 70) {
int fieldwdt = max(orx1 + diff, orx2 - diff) - min(orx1 + diff, orx2 - diff) - NAME_W;
int nameforx = (int)((BOX_W - fieldwdt) / 2);
[resbox1 setFrameOrigin: NSMakePoint(orx1 + diff, NAME_OR_Y)];
[resbox2 setFrameOrigin: NSMakePoint(orx2 - diff, NAME_OR_Y)];
[nameField setFrame: NSMakeRect(nameforx, NAME_OR_Y, fieldwdt, NAME_W)];
[nameField setStringValue: cutFileLabelText(fname, nameField, fieldwdt -NAME_MARGIN)];
[iconbox setNeedsDisplay: YES];
orx = x;
}
e = [app nextEventMatchingMask: eventMask
untilDate: farAway
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
[prefbox unlockFocus];
[self setNewWidth: (int)[nameField frame].size.width];
[setButt setEnabled: YES];
}
- (void) _postNotification
{
NSDebugLog(@"Notify the app that the size has changed....");
[[NSNotificationCenter defaultCenter]
postNotificationName: GormResizeCellNotification
object: self];
}
- (void)setNewWidth:(int)w
{
// set the new default...
[[NSUserDefaults standardUserDefaults] setInteger: w forKey: @"CellSizeWidth"];
[self _postNotification];
}
- (void)setDefaultWidth:(id)sender
{
// set some default width...
cellsWidth = 72;
[[NSUserDefaults standardUserDefaults] setInteger: cellsWidth forKey: @"CellSizeWidth"];
[self tile];
[setButt setEnabled: NO];
[self _postNotification];
}
@end

View file

@ -0,0 +1,169 @@
{
ArrResizer = {
Actions = (
"initForController:"
);
Outlets = (
);
Super = NSView;
};
FirstResponder = {
Actions = (
"activateContextHelpMode:",
"alignCenter:",
"alignJustified:",
"alignLeft:",
"alignRight:",
"arrangeInFront:",
"cancel:",
"capitalizeWord:",
"changeColor:",
"changeFont:",
"checkSpelling:",
"close:",
"complete:",
"copy:",
"copyFont:",
"copyRuler:",
"cut:",
"delete:",
"deleteBackward:",
"deleteForward:",
"deleteToBeginningOfLine:",
"deleteToBeginningOfParagraph:",
"deleteToEndOfLine:",
"deleteToEndOfParagraph:",
"deleteToMark:",
"deleteWordBackward:",
"deleteWordForward:",
"deminiaturize:",
"deselectAll:",
"fax:",
"hide:",
"hideOtherApplications:",
"indent:",
"loosenKerning:",
"lowerBaseline:",
"lowercaseWord:",
"makeKeyAndOrderFront:",
"miniaturize:",
"miniaturizeAll:",
"moveBackward:",
"moveBackwardAndModifySelection:",
"moveDown:",
"moveDownAndModifySelection:",
"moveForward:",
"moveForwardAndModifySelection:",
"moveLeft:",
"moveRight:",
"moveToBeginningOfDocument:",
"moveToBeginningOfLine:",
"moveToBeginningOfParagraph:",
"moveToEndOfDocument:",
"moveToEndOfLine:",
"moveToEndOfParagraph:",
"moveUp:",
"moveUpAndModifySelection:",
"moveWordBackward:",
"moveWordBackwardAndModifySelection:",
"moveWordForward:",
"moveWordForwardAndModifySelection:",
"newDocument:",
"ok:",
"openDocument:",
"orderBack:",
"orderFront:",
"orderFrontColorPanel:",
"orderFrontDataLinkPanel:",
"orderFrontFontPanel:",
"orderFrontHelpPanel:",
"orderFrontStandardAboutPanel:",
"orderFrontStandardInfoPanel:",
"orderOut:",
"pageDown:",
"pageUp:",
"paste:",
"pasteAsPlainText:",
"pasteAsRichText:",
"pasteFont:",
"pasteRuler:",
"performClose:",
"performMiniaturize:",
"performZoom:",
"print:",
"raiseBaseline:",
"revertDocumentToSaved:",
"runPageLayout:",
"runToolbarCustomizationPalette:",
"saveAllDocuments:",
"saveDocument:",
"saveDocumentAs:",
"saveDocumentTo:",
"scrollLineDown:",
"scrollLineUp:",
"scrollPageDown:",
"scrollPageUp:",
"scrollViaScroller:",
"selectAll:",
"selectLine:",
"selectNextKeyView:",
"selectParagraph:",
"selectPreviousKeyView:",
"selectText:",
"selectText:",
"selectToMark:",
"selectWord:",
"showContextHelp:",
"showGuessPanel:",
"showHelp:",
"showWindow:",
"stop:",
"subscript:",
"superscript:",
"swapWithMark:",
"takeDoubleValueFrom:",
"takeFloatValueFrom:",
"takeIntValueFrom:",
"takeObjectValueFrom:",
"takeStringValueFrom:",
"terminate:",
"tightenKerning:",
"toggle:",
"toggleContinuousSpellChecking:",
"toggleRuler:",
"toggleToolbarShown:",
"toggleTraditionalCharacterShape:",
"transpose:",
"transposeWords:",
"turnOffKerning:",
"turnOffLigatures:",
"underline:",
"unhide:",
"unhideAllApplications:",
"unscript:",
"uppercaseWord:",
"useAllLigatures:",
"useStandardKerning:",
"useStandardLigatures:",
"yank:",
"zoom:"
);
Super = NSObject;
};
GormShelfPref = {
Actions = (
"setDefaultWidth:"
);
Outlets = (
win,
prefbox,
iconbox,
imView,
leftResBox,
rightResBox,
nameField,
setButt
);
Super = NSObject;
};
}

Binary file not shown.