| 69 | In addition Randall suggested the following method to be used for |
| 70 | evaluating strings as tcl commands instead of the original NSArray parsing |
| 71 | we were doing. This meant that code that originally looked like: |
| 72 | |
| 73 | {{{ |
| 74 | -(NSURL *)pathToPortIndex:(NSString *)source { |
| 75 | return [NSURL fileURLWithPath: |
| 76 | [interpreter evaluateArrayAsString: |
| 77 | [NSArray arrayWithObjects: |
| 78 | @"return [macports::getindex", |
| 79 | source, |
| 80 | @"]", |
| 81 | nil]]]; |
| 82 | } |
| 83 | }}} |
| 84 | |
| 85 | to code that looked like: |
| 86 | |
| 87 | {{{ |
| 88 | -(NSURL *)pathToPortIndex:(NSString *)source { |
| 89 | return [NSURL fileURLWithPath: |
| 90 | [interpreter evaluateStringAsString: |
| 91 | [NSString stringWithFormat:@"return [macports::getindex %@ ]", source]]]; |
| 92 | } |
| 93 | |
| 94 | }}} |
| 95 | |
| 96 | This definitely made for much more cleaner code. In fact it led to my writing a |
| 97 | generic function for evaluating a given Tcl command with an array of arguments. |
| 98 | Each element in this array can be either an NSString or NSArray for flexilbility. |
| 99 | Also, there's no limit to the size of the argument array. The method looks |
| 100 | like: |
| 101 | |
| 102 | {{{ |
| 103 | - (void)execPortProc:(NSString *)procedure withParams:(NSArray *)params { |
| 104 | //params can contain either NSStrings or NSArrays |
| 105 | NSString * sparams = [NSString stringWithString:@" "]; |
| 106 | NSEnumerator * penums = [params objectEnumerator]; |
| 107 | MPInterpreter *interpreter = [MPInterpreter sharedInterpreter]; |
| 108 | |
| 109 | id elem; |
| 110 | |
| 111 | while (elem = [penums nextObject]) { |
| 112 | if ([elem isMemberOfClass:[NSString class]]) { |
| 113 | sparams = [sparams stringByAppendingString:elem]; |
| 114 | sparams = [sparams stringByAppendingString:@" "]; |
| 115 | } |
| 116 | |
| 117 | else if ([elem isKindOfClass:[NSArray class]]) { |
| 118 | //Maybe I should be more careful in the above if statement and |
| 119 | //explicitly check for the classes i'm interested in? |
| 120 | sparams = [sparams stringByAppendingString:[elem componentsJoinedByString:@" "]]; |
| 121 | sparams = [sparams stringByAppendingString:@" "]; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | [interpreter evaluateStringAsString: |
| 126 | [NSString stringWithFormat:@"[%@ %@]" , procedure, sparams]]; |
| 127 | } |
| 128 | }}} |
| 129 | thanks Randall. |
| 130 | |
| 131 | Second thing worth mentioning I think I have found a solution to Notifications |
| 132 | in the framework. I won't give too many details but basically it involves |
| 133 | having a "bridge" singleton instance class between the Tcl API and Framework. |
| 134 | When a ui_$priority procedure is calls, it in turn calls a notifications procedure |
| 135 | which calls a method (and this can be any method) of the "bridge" |
| 136 | class. This method can be a notification, message to a Framework class, delegate |
| 137 | triggering method ... the important thing is the Framework is notified of the |
| 138 | change without having to do a system-wide broadcast (e.g. NSDistributedNotification |
| 139 | center notification). More details after this has been refined. The |
| 140 | current code for it has been checked into svn. |
| 141 | |
| 142 | Finally, I'll be releasing a MidTerm Evaluation version of the Framework today. |
| 143 | IT HAS NOT BEEN TESTED. The main purpose is for feedback on the current |
| 144 | functionality as is being advertised by the Docmentation. The main things it |
| 145 | is currently lacking are incorporation of Authorization, finished Notifications |
| 146 | and thorough Testing. Any and all feedback is welcome. |
| 147 | The .dmg and .zip files can be downloaded from svn by doing |
| 148 | |
| 149 | svn co http://svn.macosforge.org/repository/macports/users/armahg/MacPorts_Framework/MPFMidtermRelease.dmg for the dmg |
| 150 | |
| 151 | svn co http://svn.macosforge.org/repository/macports/users/armahg/MacPorts_Framework/MPFMidtermRelease.zip for the .zip file |
| 152 | |
| 153 | and svn co http://svn.macosforge.org/repository/macports/users/armahg/MacPorts_Framework/MPFMidtermRelease/ for the whole folder |