OSDN Git Service

add a search history function
authormshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Mon, 28 Feb 2011 14:25:33 +0000 (14:25 +0000)
committermshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Mon, 28 Feb 2011 14:25:33 +0000 (14:25 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@24 54a90f34-5e62-402c-8eae-46c47f0b2e07

chartool/objective-c/Controller.h
chartool/objective-c/Controller.m
chartool/objective-c/HistoryRing.h [new file with mode: 0644]
chartool/objective-c/HistoryRing.m [new file with mode: 0644]
chartool/objective-c/JavaScriptEngine.h
chartool/objective-c/JavaScriptEngine.m
chartool/objective-c/chartool.xcodeproj/project.pbxproj

index a88725d..4af7101 100644 (file)
@@ -9,6 +9,7 @@
 #import <Cocoa/Cocoa.h>
 #import "JavaScriptEngine.h"
 #import "UnicharUtil.h"
+#import "HistoryRing.h"
 
 @interface Controller : NSObject {
        IBOutlet NSTextField* searchField;
@@ -21,6 +22,7 @@
        NSString* currentFont;
        JavaScriptEngine* engine;
        UnicharUtil* charUtil;
+       HistoryRing* history;
 }
 - (IBAction) search:(id)sender;
 - (IBAction) clickScriptButton: (id)sender;
index 9bb99ff..1c32255 100644 (file)
@@ -13,6 +13,7 @@
 - (id) init {
        engine = [JavaScriptEngine instance];
        charUtil = [UnicharUtil instance];
+       history = [HistoryRing instance];
        return [super init];
 }
 
        if (command == @selector(insertNewline:)) {
                [self search: control];
                return YES;
+       } else if (command == @selector(moveUp:)) {
+               NSString* v = [history previous];
+               if (v) [searchField setStringValue: v];
+       } else if (command == @selector(moveDown:)) {
+               NSString* v = [history next];
+               if (v) [searchField setStringValue: v];
        }
        return NO;
 }
 
        NSString* code = [charUtil getCharCodeFromUnichar: ch];
        [codeField setStringValue: code];
+
+       [history append: text];
 }
 
 - (IBAction) clickScriptButton: (id) sender {
        int tag = [sender tag];
        NSString* p = [tag == 0 ? codeField : nameField stringValue];
        NSUInteger m = [NSEvent modifierFlags];
-       [engine executeScriptAtIndex: tag withProperty: p AndModifier: m];
+       [engine executeScriptAtIndex: tag withProperty: p andModifier: m];
 }
 
 - (IBAction) copyGlyphCharacter: (id) sender {
 }
 
 - (IBAction) changeFont: (id) sender {
-       currentFont = [sender title];
+       [currentFont autorelease];
+       currentFont = [[sender title] retain];
        if (currentCharacter != nil) {
                [self drawOnGlyphView: currentCharacter];
        }
diff --git a/chartool/objective-c/HistoryRing.h b/chartool/objective-c/HistoryRing.h
new file mode 100644 (file)
index 0000000..dd6acf3
--- /dev/null
@@ -0,0 +1,23 @@
+//
+//  HistoryRing.h
+//  chartool
+//
+//  Created by mshio on 11/02/28.
+//  Copyright 2011 mshio. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface HistoryRing : NSObject {
+       NSMutableArray* array;
+       int pointer;
+}
+
++ (HistoryRing*) instance;
+
+- (BOOL) append:(NSString *)item;
+- (NSString *) previous;
+- (NSString *) next;
+
+@end
diff --git a/chartool/objective-c/HistoryRing.m b/chartool/objective-c/HistoryRing.m
new file mode 100644 (file)
index 0000000..9cacc18
--- /dev/null
@@ -0,0 +1,68 @@
+//
+//  HistoryRing.m
+//  chartool
+//
+//  Created by mshio on 11/02/28.
+//  Copyright 2011 mshio. All rights reserved.
+//
+
+#import "HistoryRing.h"
+
+
+@implementation HistoryRing
+
+- (void) setArray: (NSMutableArray*) anArray {
+       array = anArray;
+}
+
++ (HistoryRing*) instance {
+       static HistoryRing* _instance = nil;
+       if (! _instance) {
+               _instance = [[HistoryRing alloc] init];
+       }
+       return _instance;
+}
+
+- (id) init {
+       self = [super init];
+       if (self) {
+               array = [[NSMutableArray alloc] initWithCapacity: 99];
+               pointer = [array count];
+       }
+       return self;
+}
+
+- (BOOL) append: (NSString*) item {
+       BOOL ret = NO;
+       int count = [array count];
+       NSString* last = nil;
+       if (count > 0) {
+               last = [array objectAtIndex: count - 1];
+       }
+       if (! last || (last && ! [last isEqualToString: item])) {
+               if (count >= 99) [array removeObjectAtIndex: 0];
+               [array addObject: item];
+               pointer = [array count];
+               ret = YES;
+       }
+       return ret;
+}
+
+- (NSString*) previous {
+       NSString* ret = nil;
+       if (pointer - 1 >= 0) {
+               ret = [array objectAtIndex: --pointer];
+       }
+       return ret;
+}
+
+- (NSString*) next {
+       NSString* ret = nil;
+       NSUInteger max = [array count];
+       if (pointer < max) {
+               ret = [array objectAtIndex: pointer++];
+       }
+       return ret;
+}
+
+@end
index 94aaa8f..1153ea3 100644 (file)
@@ -16,6 +16,6 @@
 + (JavaScriptEngine *) instance;
 - (NSString *) evaluate: (NSString *) script;
 - (NSArray *) fontNamesWithArray;
-- (void) executeScriptAtIndex: (int) index withProperty: (NSString*) property AndModifier: (int) modifier;
+- (void) executeScriptAtIndex: (int) index withProperty: (NSString*) property andModifier: (int) modifier;
 
 @end
index cd2d85a..a193acd 100644 (file)
@@ -165,7 +165,7 @@ static JSValueRef jsOpenFile(JSContextRef ctx,
        [super release];
 }
 
-- (void) executeScriptAtIndex:(int)index withProperty:(NSString *)property AndModifier:(int)modifier {
+- (void) executeScriptAtIndex:(int)index withProperty:(NSString *)property andModifier:(int)modifier {
        JSObjectRef object = JSContextGetGlobalObject(context);
        JSStringRef nm = JSStringCreateWithUTF8CString("script");
        JSValueRef script = JSObjectGetProperty(context, object, nm, NULL);
index d3630dc..e933f67 100644 (file)
@@ -10,6 +10,7 @@
                1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
                4940082D12FEAFA90050DD3E /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4940082C12FEAFA90050DD3E /* JavaScriptCore.framework */; };
                4940083112FEAFD90050DD3E /* JavaScriptEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 4940083012FEAFD90050DD3E /* JavaScriptEngine.m */; };
+               49817B1A131BBB0D00BCEFA7 /* HistoryRing.m in Sources */ = {isa = PBXBuildFile; fileRef = 49817B19131BBB0D00BCEFA7 /* HistoryRing.m */; };
                49966FED12FD6588004DAD35 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 49966FEC12FD6588004DAD35 /* Controller.m */; };
                49D3C86013024AFC00DA507B /* UnicharUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 49D3C85F13024AFC00DA507B /* UnicharUtil.m */; };
                8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
@@ -29,6 +30,8 @@
                4940082C12FEAFA90050DD3E /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = /System/Library/Frameworks/JavaScriptCore.framework; sourceTree = "<absolute>"; };
                4940082F12FEAFD90050DD3E /* JavaScriptEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptEngine.h; sourceTree = "<group>"; };
                4940083012FEAFD90050DD3E /* JavaScriptEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JavaScriptEngine.m; sourceTree = "<group>"; };
+               49817B18131BBB0D00BCEFA7 /* HistoryRing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryRing.h; sourceTree = "<group>"; };
+               49817B19131BBB0D00BCEFA7 /* HistoryRing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryRing.m; sourceTree = "<group>"; };
                49966FEB12FD6588004DAD35 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = "<group>"; };
                49966FEC12FD6588004DAD35 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = "<group>"; };
                49D3C85E13024AFC00DA507B /* UnicharUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicharUtil.h; sourceTree = "<group>"; };
@@ -59,6 +62,8 @@
                                4940083012FEAFD90050DD3E /* JavaScriptEngine.m */,
                                49D3C85E13024AFC00DA507B /* UnicharUtil.h */,
                                49D3C85F13024AFC00DA507B /* UnicharUtil.m */,
+                               49817B18131BBB0D00BCEFA7 /* HistoryRing.h */,
+                               49817B19131BBB0D00BCEFA7 /* HistoryRing.m */,
                        );
                        name = Classes;
                        sourceTree = "<group>";
                                49966FED12FD6588004DAD35 /* Controller.m in Sources */,
                                4940083112FEAFD90050DD3E /* JavaScriptEngine.m in Sources */,
                                49D3C86013024AFC00DA507B /* UnicharUtil.m in Sources */,
+                               49817B1A131BBB0D00BCEFA7 /* HistoryRing.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };