source: releases/Pester/1.1b7/Source/NJRHistoryTrackingComboBox.m@ 491

Last change on this file since 491 was 355, checked in by Nicholas Riley, 17 years ago

English.lproj/MainMenu.nib: Modernize menu and alarm set dialog
layout. Use keyed archiving (10.2+) nib format.

Info-Pester.plist: Moved from old PBX project.

NJRFSObjectSelector.m: Bug fixes from code sent to Joey: remove
incorrect usage of tryToPerform:with:; fix logic error in menu
construction. Work around Cocoa's deciding that the menu font size
needs adjustment when it doesn't - so the menu font size now matches
the button font size, though the position is still off. Don't pop up
a menu if we're disabled. Use IconRefs for menu icons, though not
(yet) for the button icon.

NJRHistoryTrackingComboBox.m: Remove item height adjustment
workaround; it now makes the items too tall.

NJRHotKey.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyField.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyManager.m: Add a missing [super dealloc] caught by current
GCC.

NJRIntervalField.m: Fix some type errors.

NJRQTMediaPopUpButton.m: Replace SoundFileManager SPI usage, which
doesn't work in Leopard anyway, with manual enumeration of system
sounds. Start migration to QTKit. Use IconRefs for menu icons.

NJRReadMeController.m: Change source encoding to UTF-8.

NJRSoundManager.m: Fix a type error.

NJRVoicePopUpButton.m: Change source encoding to UTF-8.

NSMenuItem-NJRExtensions.[hm]: Code from ICeCoffEE to use IconRefs for
menu item icons.

PSAlarm.m: Change source encoding to UTF-8.

PSAlarms.m: Fix a signedness mismatch.

PSAlarmsController.m: Change source encoding to UTF-8.

PSAlarmSetController.m: Set keyboard focus after unchecking "Do
script:" and "Play" checkboxes.

PSAlerts.m: Add a missing [super dealloc] caught by current GCC. Fix
a memory leak in property list serialization.

PSPowerManager.[hm]: There's now API for scheduling wakeups; use it
(the old code asserted on startup). To fix: removing scheduled
wakeup. Fix a small type-checking error.

PSPreferencesController.m: Add a missing [super dealloc] caught by
current GCC.

PSScriptAlert.m: Change source encoding to UTF-8.

PSTimeDateEditor.m: Fix a tiny, and one-time, memory leak.

PSTimer.m: Update for new PSPowerManager API.

Pester.pbproj: Deleted; now supporting OS X 10.4+ (up from 10.1,
aiee.)

Pester.xcodeproj: Xcode 2.4+ project, upgraded targets, etc.

SoundFileManager.h: Deleted; this SPI no longer exists in Leopard and
possibly earlier.

File size: 2.3 KB
Line 
1//
2// NJRHistoryTrackingComboBox.m
3// DockCam
4//
5// Created by Nicholas Riley on Fri Jun 28 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRHistoryTrackingComboBox.h"
10
11#define NJRHistoryTrackingComboBoxMaxItems 10
12
13@implementation NJRHistoryTrackingComboBox
14
15- (NSString *)_defaultKey;
16{
17 NSAssert([self tag] != 0, NSLocalizedString(@"Can't track history for combo box with tag 0: please set a tag", "Assertion for history tracking combo box if tag is 0"));
18 return [NSString stringWithFormat: @"NJRHistoryTrackingComboBox tag %d", [self tag]];
19}
20
21- (void)awakeFromNib;
22{
23 [[NSNotificationCenter defaultCenter] addObserver: self
24 selector: @selector(textDidEndEditing:)
25 name: NSTextDidEndEditingNotification
26 object: self];
27 [self removeAllItems];
28 [self addItemsWithObjectValues: [[NSUserDefaults standardUserDefaults] stringArrayForKey: [self _defaultKey]]];
29}
30
31- (void)_writeHistory;
32{
33 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
34 [defaults setObject: [self objectValues] forKey: [self _defaultKey]];
35 [defaults synchronize];
36}
37
38- (IBAction)removeEntry:(id)sender;
39{
40 int idx = [self indexOfSelectedItem];
41 if (idx == -1) {
42 [self selectItemWithObjectValue: [self stringValue]];
43 idx = [self indexOfSelectedItem];
44 }
45 if (idx != -1) [self removeItemAtIndex: idx];
46 [self setStringValue: @""];
47 [self _writeHistory];
48}
49
50- (IBAction)clearAllEntries:(id)sender;
51{
52 [self removeAllItems];
53 [self setStringValue: @""];
54 [self _writeHistory];
55}
56
57- (BOOL)textShouldEndEditing:(NSText *)textObject;
58{
59 NSString *newValue = [self stringValue];
60 int oldIndex = [self indexOfItemWithObjectValue: newValue];
61 if ([newValue length] == 0) return YES; // donÕt save empty entries
62 [self removeItemWithObjectValue: newValue];
63 [self insertItemWithObjectValue: newValue atIndex: 0];
64 if (oldIndex == NSNotFound) {
65 int numItems = [self numberOfItems];
66 while (numItems-- > NJRHistoryTrackingComboBoxMaxItems) {
67 [self removeItemAtIndex: numItems - 1];
68 }
69 }
70 [self _writeHistory];
71 return YES;
72}
73
74@end
Note: See TracBrowser for help on using the repository browser.