Changeset 276

Show
Ignore:
Timestamp:
01/01/08 11:31:24 (1 year ago)
Author:
wolf
Message:

[NEW] JRShellView: Implement command handler. Write silly demo.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/JRShellView/JRShellView.h

    r271 r276  
    11#import <Cocoa/Cocoa.h> 
    22 
     3@protocol JRShellViewCommandHandler <NSObject> 
     4- (NSString*)executeCommand:(NSString*)command_ errorString:(NSString**)errorString_; 
     5//TODO probably a category - (NSString*)rewriteCommand:(NSString*)command_; 
     6@end 
     7 
    38@interface JRShellView : NSTextView { 
    4     NSMutableArray  *commandHistory; 
    5     unsigned        currentCommandHistoryIndex; 
     9    unsigned                        commandStart; 
    610     
    7     unsigned        commandStart; 
    8     NSString        *uncompletedCommand; 
     11    NSString                        *uncompletedCommand; 
     12     
     13    NSMutableArray                  *commandHistory; 
     14    unsigned                        currentCommandHistoryIndex; 
     15     
     16    id<JRShellViewCommandHandler>   commandHandler; 
    917} 
    1018 
     19- (id<JRShellViewCommandHandler>)commandHandler; 
     20- (void)setCommandHandler:(id<JRShellViewCommandHandler>)handler_; 
     21 
    1122@end 
  • trunk/cocoa/JRShellView/JRShellView.m

    r275 r276  
    22 
    33@interface NSText (UndocumentedSelectionMovement) 
     4// see: 
     5// <http://www.hcs.harvard.edu/~jrus/Site/System%20Bindings.html> 
     6// <http://www.lsmason.com/articles/macosxkeybindings.html> 
    47- (IBAction)moveParagraphBackwardAndModifySelection:(id)sender; 
    58- (IBAction)moveToBeginningOfDocumentAndModifySelection:(id)sender; 
     
    5356} 
    5457 
     58- (id<JRShellViewCommandHandler>)commandHandler { 
     59    return commandHandler; 
     60} 
     61 
     62- (void)setCommandHandler:(id<JRShellViewCommandHandler>)handler_ { 
     63    commandHandler = handler_; // Not retained. 
     64} 
     65 
    5566- (void)keyDown:(NSEvent*)event_ { 
    5667    if ([event_ type] != NSKeyDown || ![[event_ characters] length]) { 
     
    7990- (void)insertNewline:(id)sender_ { // return 
    8091    NSString *cmd = [self calcCurrentCommandString]; 
     92    NSString *cmdResult = nil, *errorString = nil; 
    8193    if (cmd) { 
    82         // TODO cmd = [commandHandler rewriteCommand]; 
    83         // TODO result = [commandHandler executeCommand]; 
     94        // TODO cmd = [commandHandler rewriteCommand:cmd]; 
     95        cmdResult = [commandHandler executeCommand:cmd errorString:&errorString]; 
    8496        [commandHistory addObject:cmd]; 
    8597        currentCommandHistoryIndex = NSNotFound; 
     
    8799    [super setSelectedRange:NSMakeRange([[self string] length],0)]; // Go to end of command in case return was issued elsewhere. 
    88100    [super insertNewline:sender_]; 
    89     // TODO output 
     101    if (errorString) { 
     102        [super insertText:errorString]; 
     103        [super insertNewline:sender_]; 
     104    } else { 
     105        if (cmdResult) { 
     106            [super insertText:cmdResult]; 
     107            [super insertNewline:sender_]; 
     108        } 
     109    } 
    90110    [self insertPrompt]; 
    91111} 
  • trunk/cocoa/JRShellView/JRShellViewDemo/AppController.h

    r271 r276  
    1 // 
    2 //  AppController.h 
    3 //  JRShellViewDemo 
    4 // 
    5 //  Created by wolf on 12/31/07. 
    6 //  Copyright __MyCompanyName__ 2007. All rights reserved. 
    7 // 
     1#import <Cocoa/Cocoa.h> 
     2#import "JRShellView.h" 
    83 
    9 #import <Cocoa/Cocoa.h> 
    10  
    11 @interface AppController : NSObject { 
    12  
     4@interface AppController : NSObject <JRShellViewCommandHandler> { 
     5    IBOutlet JRShellView *shellView; 
    136} 
    147 
  • trunk/cocoa/JRShellView/JRShellViewDemo/AppController.m

    r271 r276  
    1 // 
    2 //  AppController.m 
    3 //  JRShellViewDemo 
    4 // 
    5 //  Created by wolf on 12/31/07. 
    6 //  Copyright __MyCompanyName__ 2007. All rights reserved. 
    7 // 
    8  
    91#import "AppController.h" 
    102 
    113@implementation AppController 
     4 
     5- (void)awakeFromNib { 
     6    [shellView setCommandHandler:self]; 
     7} 
     8 
     9- (NSString*)executeCommand:(NSString*)command_ errorString:(NSString**)errorString_ { 
     10    if ([command_ isEqualToString:@"rentzsch"]) { 
     11        *errorString_ = @"rentzsch is obviously already reversed or something. I mean, seriously check those consonants."; 
     12        return nil; 
     13    } else { 
     14        unsigned charIndex = 0, charCount = [command_ length]; 
     15        unichar *input = (unichar*)[[NSMutableData dataWithCapacity:charCount * sizeof(unichar)] mutableBytes]; 
     16        [command_ getCharacters:input]; 
     17        unichar *output = (unichar*)[[NSMutableData dataWithCapacity:charCount * sizeof(unichar)] mutableBytes]; 
     18        for (; charIndex < charCount; charIndex++) { 
     19            output[charCount-charIndex-1] = input[charIndex]; 
     20        } 
     21        return [NSString stringWithCharacters:output length:charCount]; 
     22    } 
     23} 
    1224 
    1325- (void)applicationDidFinishLaunching:(NSNotification*)notification_ { 
  • trunk/cocoa/JRShellView/JRShellViewDemo/English.lproj/MainMenu.nib/classes.nib

    r271 r276  
    2626                        <key>LANGUAGE</key> 
    2727                        <string>ObjC</string> 
     28                        <key>OUTLETS</key> 
     29                        <dict> 
     30                                <key>shellView</key> 
     31                                <string>JRShellView</string> 
     32                        </dict> 
    2833                        <key>SUPERCLASS</key> 
    2934                        <string>NSObject</string> 
  • trunk/cocoa/JRShellView/JRShellViewDemo/English.lproj/MainMenu.nib/info.nib

    r271 r276  
    1111        <key>IBOpenObjects</key> 
    1212        <array> 
    13                 <integer>212</integer> 
     13                <integer>21</integer> 
    1414        </array> 
    1515        <key>IBSystem Version</key> 
  • trunk/cocoa/JRShellView/JRShellViewDemo/JRShellViewDemo.xcodeproj/wolf.mode1v3

    r271 r276  
    198198        <array/> 
    199199        <key>OpenEditors</key> 
    200         <array> 
    201                 <dict> 
    202                         <key>Content</key> 
    203                         <dict> 
    204                                 <key>PBXProjectModuleGUID</key> 
    205                                 <string>79AEA9BA0D29CC6E00A2C50F</string> 
    206                                 <key>PBXProjectModuleLabel</key> 
    207                                 <string>JRShellView.m</string> 
    208                                 <key>PBXSplitModuleInNavigatorKey</key> 
    209                                 <dict> 
    210                                         <key>Split0</key> 
    211                                         <dict> 
    212                                                 <key>PBXProjectModuleGUID</key> 
    213                                                 <string>79AEA9BB0D29CC6E00A2C50F</string> 
    214                                                 <key>PBXProjectModuleLabel</key> 
    215                                                 <string>JRShellView.m</string> 
    216                                                 <key>_historyCapacity</key> 
    217                                                 <integer>0</integer> 
    218                                                 <key>bookmark</key> 
    219                                                 <string>79AEA9BC0D29CC6E00A2C50F</string> 
    220                                                 <key>history</key> 
    221                                                 <array> 
    222                                                         <string>79AEA9AC0D29CB8500A2C50F</string> 
    223                                                 </array> 
    224                                         </dict> 
    225                                         <key>SplitCount</key> 
    226                                         <string>1</string> 
    227                                 </dict> 
    228                                 <key>StatusBarVisibility</key> 
    229                                 <true/> 
    230                         </dict> 
    231                         <key>Geometry</key> 
    232                         <dict> 
    233                                 <key>Frame</key> 
    234                                 <string>{{0, 20}, {1046, 730}}</string> 
    235                                 <key>PBXModuleWindowStatusBarHidden2</key> 
    236                                 <false/> 
    237                                 <key>RubberWindowFrame</key> 
    238                                 <string>78 756 1046 771 0 0 2560 1578 </string> 
    239                         </dict> 
    240                 </dict> 
    241                 <dict> 
    242                         <key>Content</key> 
    243                         <dict> 
    244                                 <key>PBXProjectModuleGUID</key> 
    245                                 <string>79AEA9BD0D29CC6E00A2C50F</string> 
    246                                 <key>PBXProjectModuleLabel</key> 
    247                                 <string>JRShellView.h</string> 
    248                                 <key>PBXSplitModuleInNavigatorKey</key> 
    249                                 <dict> 
    250                                         <key>Split0</key> 
    251                                         <dict> 
    252                                                 <key>PBXProjectModuleGUID</key> 
    253                                                 <string>79AEA9BE0D29CC6E00A2C50F</string> 
    254                                                 <key>PBXProjectModuleLabel</key> 
    255                                                 <string>JRShellView.h</string> 
    256                                                 <key>_historyCapacity</key> 
    257                                                 <integer>0</integer> 
    258                                                 <key>bookmark</key> 
    259                                                 <string>79AEA9C00D29CC6E00A2C50F</string> 
    260                                                 <key>history</key> 
    261                                                 <array> 
    262                                                         <string>79AEA9BF0D29CC6E00A2C50F</string> 
    263                                                 </array> 
    264                                         </dict> 
    265                                         <key>SplitCount</key> 
    266                                         <string>1</string> 
    267                                 </dict> 
    268                                 <key>StatusBarVisibility</key> 
    269                                 <true/> 
    270                         </dict> 
    271                         <key>Geometry</key> 
    272                         <dict> 
    273                                 <key>Frame</key> 
    274                                 <string>{{0, 20}, {1046, 730}}</string> 
    275                                 <key>PBXModuleWindowStatusBarHidden2</key> 
    276                                 <false/> 
    277                                 <key>RubberWindowFrame</key> 
    278                                 <string>38 781 1046 771 0 0 2560 1578 </string> 
    279                         </dict> 
    280                 </dict> 
    281         </array> 
     200        <array/> 
    282201        <key>PerspectiveWidths</key> 
    283202        <array> 
     
    356275                                                        <array> 
    357276                                                                <array> 
    358                                                                         <integer>4</integer> 
     277                                                                        <integer>2</integer> 
    359278                                                                        <integer>1</integer> 
    360279                                                                        <integer>0</integer> 
     
    426345                                                </dict> 
    427346                                                <dict> 
    428                                                         <key>BecomeActive</key> 
    429                                                         <true/> 
    430347                                                        <key>ContentConfiguration</key> 
    431348                                                        <dict> 
     
    464381                        <key>TableOfContents</key> 
    465382                        <array> 
    466                                 <string>79AEA9A10D29CB0A00A2C50F</string> 
     383                                <string>794053AA0D2AFF9A00976130</string> 
    467384                                <string>1CE0B1FE06471DED0097A5F4</string> 
    468                                 <string>79AEA9A20D29CB0A00A2C50F</string> 
     385                                <string>794053AB0D2AFF9A00976130</string> 
    469386                                <string>1CE0B20306471E060097A5F4</string> 
    470387                                <string>1CE0B20506471E060097A5F4</string> 
     
    600517        <key>WindowOrderList</key> 
    601518        <array> 
    602                 <string>79AEA9C10D29CC6E00A2C50F</string> 
    603                 <string>79AEA9C20D29CC6E00A2C50F</string> 
    604                 <string>79AEA9C30D29CC6E00A2C50F</string> 
     519                <string>794053D20D2B029600976130</string> 
     520                <string>794053C20D2B018D00976130</string> 
     521                <string>794053C30D2B018D00976130</string> 
     522                <string>794053C40D2B018D00976130</string> 
    605523                <string>1C78EAAD065D492600B07095</string> 
    606524                <string>1CD10A99069EF8BA00B06720</string> 
    607525                <string>79AEA9B00D29CC0E00A2C50F</string> 
    608                 <string>79AEA9BD0D29CC6E00A2C50F</string> 
     526                <string>7940539F0D2AFF8300976130</string> 
    609527                <string>79AEA9BA0D29CC6E00A2C50F</string> 
    610528                <string>/Users/wolf/code/trac/cocoa/JRShellView/JRShellViewDemo/JRShellViewDemo.xcodeproj</string> 
     
    688606                        <array> 
    689607                                <string>79AEA9B00D29CC0E00A2C50F</string> 
    690                                 <string>79AEA9B10D29CC0E00A2C50F</string> 
     608                                <string>794053AE0D2AFF9A00976130</string> 
    691609                                <string>1CD0528F0623707200166675</string> 
    692610                                <string>XCMainBuildResultsModuleGUID</string> 
     
    730648                                                                                <key>sizes</key> 
    731649                                                                                <array> 
    732                                                                                         <string>{{0, 0}, {316, 185}}</string> 
    733                                                                                         <string>{{316, 0}, {378, 185}}</string> 
     650                                                                                        <string>{{0, 0}, {316, 198}}</string> 
     651                                                                                        <string>{{316, 0}, {378, 198}}</string> 
    734652                                                                                </array> 
    735653                                                                        </dict> 
     
    746664                                                                                <key>sizes</key> 
    747665                                                                                <array> 
    748                                                                                         <string>{{0, 0}, {694, 185}}</string> 
    749                                                                                         <string>{{0, 185}, {694, 196}}</string> 
     666                                                                                        <string>{{0, 0}, {694, 198}}</string> 
     667                                                                                        <string>{{0, 198}, {694, 183}}</string> 
    750668                                                                                </array> 
    751669                                                                        </dict> 
     
    780698                                                                        </array> 
    781699                                                                        <key>Frame</key> 
    782                                                                         <string>{{316, 0}, {378, 185}}</string> 
     700                                                                        <string>{{316, 0}, {378, 198}}</string> 
    783701                                                                        <key>RubberWindowFrame</key> 
    784                                                                         <string>99 1082 694 422 0 0 2560 1578 </string> 
     702                                                                        <string>1319 1019 694 422 0 0 2560 1578 </string> 
    785703                                                                </dict> 
    786704                                                                <key>RubberWindowFrame</key> 
    787                                                                 <string>99 1082 694 422 0 0 2560 1578 </string> 
     705                                                                <string>1319 1019 694 422 0 0 2560 1578 </string> 
    788706                                                        </dict> 
    789707                                                        <key>Module</key> 
     
    808726                        <array> 
    809727                                <string>1CD10A99069EF8BA00B06720</string> 
    810                                 <string>79AEA9B20D29CC0E00A2C50F</string> 
     728                                <string>794053AF0D2AFF9A00976130</string> 
    811729                                <string>1C162984064C10D400B95A72</string> 
    812                                 <string>79AEA9B30D29CC0E00A2C50F</string> 
    813                                 <string>79AEA9B40D29CC0E00A2C50F</string> 
    814                                 <string>79AEA9B50D29CC0E00A2C50F</string> 
    815                                 <string>79AEA9B60D29CC0E00A2C50F</string> 
    816                                 <string>79AEA9B70D29CC0E00A2C50F</string> 
     730                                <string>794053B00D2AFF9A00976130</string> 
     731                                <string>794053B10D2AFF9A00976130</string> 
     732                                <string>794053B20D2AFF9A00976130</string> 
     733                                <string>794053B30D2AFF9A00976130</string> 
     734                                <string>794053B40D2AFF9A00976130</string> 
    817735                        </array> 
    818736                        <key>ToolbarConfiguration</key> 
    819737                        <string>xcode.toolbar.config.debugV3</string> 
    820738                        <key>WindowString</key> 
    821                         <string>99 1082 694 422 0 0 2560 1578 </string> 
     739                        <string>1319 1019 694 422 0 0 2560 1578 </string> 
    822740                        <key>WindowToolGUID</key> 
    823741                        <string>1CD10A99069EF8BA00B06720</string> 
     
    953871                                                                <string>{{0, 0}, {650, 209}}</string> 
    954872                                                                <key>RubberWindowFrame</key> 
    955                                                                 <string>99 1254 650 250 0 0 2560 1578 </string> 
     873                                                                <string>1744 1042 650 250 0 0 2560 1578 </string> 
    956874                                                        </dict> 
    957875                                                        <key>Module</key> 
     
    976894                        <array> 
    977895                                <string>1C78EAAD065D492600B07095</string> 
    978                                 <string>79AEA9B80D29CC0E00A2C50F</string> 
     896                                <string>794053B50D2AFF9A00976130</string> 
    979897                                <string>1C78EAAC065D492600B07095</string> 
    980898                        </array> 
     
    982900                        <string>xcode.toolbar.config.consoleV3</string> 
    983901                        <key>WindowString</key> 
    984                         <string>99 1254 650 250 0 0 2560 1578 </string> 
     902                        <string>1744 1042 650 250 0 0 2560 1578 </string> 
    985903                        <key>WindowToolGUID</key> 
    986904                        <string>1C78EAAD065D492600B07095</string> 
  • trunk/cocoa/JRShellView/JRShellViewDemo/JRShellViewDemo.xcodeproj/wolf.pbxuser

    r271 r276  
    88                addToTargets = ( 
    99                        8D1107260486CEB800E47090 /* JRShellViewDemo */, 
     10                ); 
     11                breakpoints = ( 
    1012                ); 
    1113                codeSenseManager = 79AEA9A50D29CB0A00A2C50F /* Code sense */; 
     
    2123                                        243, 
    2224                                        20, 
    23                                         48.16259765625
     25                                        48
    2426                                        43, 
    2527                                        43, 
     
    3638                                ); 
    3739                        }; 
    38                         PBXPerProjectTemplateStateSaveDate = 220842757; 
    39                         PBXWorkspaceStateSaveDate = 220842757; 
    40                 }; 
    41                 perUserProjectItems = { 
    42                         79AEA9AC0D29CB8500A2C50F /* PBXBookmark */ = 79AEA9AC0D29CB8500A2C50F /* PBXBookmark */; 
    43                         79AEA9BC0D29CC6E00A2C50F /* PBXTextBookmark */ = 79AEA9BC0D29CC6E00A2C50F /* PBXTextBookmark */; 
    44                         79AEA9BF0D29CC6E00A2C50F /* PBXTextBookmark */ = 79AEA9BF0D29CC6E00A2C50F /* PBXTextBookmark */; 
    45                         79AEA9C00D29CC6E00A2C50F /* PBXTextBookmark */ = 79AEA9C00D29CC6E00A2C50F /* PBXTextBookmark */; 
     40                        PBXPerProjectTemplateStateSaveDate = 220921734; 
     41                        PBXWorkspaceStateSaveDate = 220921734; 
    4642                }; 
    4743                sourceControlManager = 79AEA9A40D29CB0A00A2C50F /* Source Control */; 
    4844                userBuildSettings = { 
     45                }; 
     46        }; 
     47        795A7F90099D0E3600450061 /* AppController.h */ = { 
     48                uiCtxt = { 
     49                        sepNavIntBoundsRect = "{{0, 0}, {997, 1223}}"; 
     50                        sepNavSelRange = "{86, 25}"; 
     51                        sepNavVisRange = "{0, 160}"; 
     52                        sepNavWindowFrame = "{{775, 156}, {1056, 1350}}"; 
     53                }; 
     54        }; 
     55        795A7F91099D0E3600450061 /* AppController.m */ = { 
     56                uiCtxt = { 
     57                        sepNavIntBoundsRect = "{{0, 0}, {997, 1246}}"; 
     58                        sepNavSelRange = "{383, 0}"; 
     59                        sepNavVisRange = "{0, 1041}"; 
     60                        sepNavWindowFrame = "{{746, 173}, {1056, 1350}}"; 
    4961                }; 
    5062        }; 
     
    90102        79AEA9A60D29CB1100A2C50F /* JRShellView.m */ = { 
    91103                uiCtxt = { 
    92                         sepNavIntBoundsRect = "{{0, 0}, {987, 7700}}"; 
    93                         sepNavSelRange = "{599, 0}"; 
    94                         sepNavVisRange = "{0, 1048}"; 
    95                         sepNavWindowFrame = "{{78, 724}, {1046, 803}}"; 
     104                        sepNavIntBoundsRect = "{{0, 0}, {997, 6538}}"; 
     105                        sepNavSelRange = "{3135, 0}"; 
     106                        sepNavVisRange = "{1592, 3140}"; 
     107                        sepNavWindowFrame = "{{838, 185}, {1056, 1350}}"; 
    96108                }; 
    97109        }; 
     
    99111                uiCtxt = { 
    100112                        sepNavIntBoundsRect = "{{0, 0}, {987, 699}}"; 
    101                         sepNavSelRange = "{0, 0}"; 
    102                         sepNavVisRange = "{0, 236}"; 
    103                         sepNavWindowFrame = "{{38, 749}, {1046, 803}}"; 
     113                        sepNavSelRange = "{72, 85}"; 
     114                        sepNavVisRange = "{0, 694}"; 
     115                        sepNavWindowFrame = "{{810, 744}, {1046, 803}}"; 
    104116                }; 
    105         }; 
    106         79AEA9AC0D29CB8500A2C50F /* PBXBookmark */ = { 
    107                 isa = PBXBookmark; 
    108                 fRef = 79AEA9A60D29CB1100A2C50F /* JRShellView.m */; 
    109         }; 
    110         79AEA9BC0D29CC6E00A2C50F /* PBXTextBookmark */ = { 
    111                 isa = PBXTextBookmark; 
    112                 fRef = 79AEA9A60D29CB1100A2C50F /* JRShellView.m */; 
    113                 name = "JRShellView.m: 22"; 
    114                 rLen = 0; 
    115                 rLoc = 599; 
    116                 rType = 0; 
    117                 vrLen = 1048; 
    118                 vrLoc = 0; 
    119         }; 
    120         79AEA9BF0D29CC6E00A2C50F /* PBXTextBookmark */ = { 
    121                 isa = PBXTextBookmark; 
    122                 fRef = 79AEA9A70D29CB1100A2C50F /* JRShellView.h */; 
    123                 rLen = 0; 
    124                 rLoc = 9223372036854775807; 
    125                 rType = 0; 
    126         }; 
    127         79AEA9C00D29CC6E00A2C50F /* PBXTextBookmark */ = { 
    128                 isa = PBXTextBookmark; 
    129                 fRef = 79AEA9A70D29CB1100A2C50F /* JRShellView.h */; 
    130                 name = "JRShellView.h: 1"; 
    131                 rLen = 0; 
    132                 rLoc = 0; 
    133                 rType = 0; 
    134                 vrLen = 236; 
    135                 vrLoc = 0; 
    136117        }; 
    137118        8D1107260486CEB800E47090 /* JRShellViewDemo */ = {