- Timestamp:
- 10/27/07 11:39:32 (6 years ago)
- Location:
- lang/ruby/Amalgam
- Files:
-
- 2 added
- 1 removed
- 5 modified
-
. (modified) (1 prop)
-
Amalgam.xcodeproj/cho45.mode1 (added)
-
AppController.rb (modified) (5 diffs)
-
English.lproj (modified) (1 prop)
-
English.lproj/MainMenu.nib/classes.nib (modified) (1 diff)
-
English.lproj/MainMenu.nib/info.nib (modified) (1 diff)
-
English.lproj/MainMenu.nib/keyedobjects.nib (added)
-
English.lproj/MainMenu.nib/objects.nib (deleted)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/Amalgam
-
Property
svn:ignore set
to
build
pkg
-
Property
svn:ignore set
to
-
lang/ruby/Amalgam/AppController.rb
r746 r747 29 29 end 30 30 31 class Candidate 32 attr_accessor :name, :icon, :proc 33 34 def initialize(name, icon=nil, &block) 35 @name = name 36 @proc = block 37 case icon 38 when Symbol 39 @icon = NSWorkspace.sharedWorkspace.iconForFileType(icon.to_s) 40 when Pathname 41 @icon = NSWorkspace.sharedWorkspace.iconForFile(icon.to_s) 42 when NilClass 43 @icon = NSWorkspace.sharedWorkspace.iconForFileType("unknown") 44 else 45 str = NSData.objc_send :dataWithBytes, icon.to_s, :length 46 @icon = NSImage.alloc.initWithData(str) 47 end 48 end 49 50 def call(*args) 51 if @proc.arity.abs > 0 52 @proc.call(self, *args) 53 end 54 end 55 end 56 31 57 class AppController < NSObject 32 ib_outlets :view 33 ib_outlets :combo 34 35 def comboBox_objectValueForItemAtIndex(sender, index) 36 (@candidate || [])[index].first 37 end 38 39 def numberOfItemsInComboBox(sender) 40 # log "Reloaded data" 41 (@candidate || []).length 42 end 43 44 def comboBox_completedString(sender, string) 45 #log "completedString->#{string}" 46 string = Regexp.escape(string) 47 (@candidate || []).transpose[0].grep(/^#{string}/i).first 48 rescue Exception 49 "" 50 end 51 52 def comboBox_indexOfItemWithStringValue(sender, string) 53 @candidate ||= [] 54 @candidate.each_with_index do |(r,l),i| 55 if r === string 56 return i 57 end 58 end 59 NSNotFound 60 end 61 62 # def controlTextDidChange(anot) 63 # end 58 ib_outlet :view 59 ib_outlet :input 60 ib_outlet :results 61 62 # Tableview 63 def numberOfRowsInTableView(table) 64 @now.length 65 end 66 67 def tableView_objectValueForTableColumn_row(table, column, row) 68 case column.identifier.to_s.to_sym 69 when :icon 70 @now[row].icon || 71 NSWorkspace.sharedWorkspace.iconForFileType('unknown') 72 when :name 73 @now[row].name 74 end 75 end 76 77 def tableView_setObjectValue_forTableColumn_row(table, value, column, row) 78 end 79 80 def tableView_willDisplayCell_forTableColumn_row(table, cell, column, row) 81 end 82 83 def run_current_selection(*) 84 if @now[@results.selectedRow] 85 @now[@results.selectedRow].call 86 end 87 end 88 89 def controlTextDidChange(anot) 90 filtering @input.stringValue 91 @results.selectRowIndexes_byExtendingSelection(NSIndexSet.alloc.initWithIndex(0), false) 92 end 64 93 65 94 def windowDidResignKey(anot) … … 72 101 73 102 def windowDidBecomeMain(anot) 74 @window.makeFirstResponder(@combo) 75 @combo.delegate = self 76 #@combo.reloadData 77 @editting = false 78 #@combo.stringValue = "" 103 @window.makeFirstResponder(@input) 79 104 end 80 105 81 106 def windowDidBecomeKey(anot) 82 @window.makeFirstResponder(@combo) 107 @window.makeFirstResponder(@input) 108 @now = @candidates 83 109 end 84 110 … … 105 131 @window.setFrameOrigin([screenFrame.size.width / 2, screenFrame.size.height / 2]) 106 132 107 @combo.editable = true108 @combo.numberOfVisibleItems = 20109 110 133 NSApp.register_hotkey("Command+`") do 111 134 log "HotKey hitted" … … 117 140 118 141 build_candidates() 142 @results.dataSource = self 143 119 144 120 145 NSApp.activateIgnoringOtherApps(true) 121 @window.makeFirstResponder(@combo) 146 @window.makeFirstResponder(@input) 147 end 148 149 def filtering(str) 150 str = str.to_s 151 if str =~ /[A-Z]/ 152 r = /^#{str}/ 153 else 154 r = /^#{str}/i 155 end 156 @now = @candidates.select {|i| 157 r === i.name 158 }.sort_by {|i| i.name.length } 159 160 if @now.length.zero? 161 r = /#{str.split(//).map {|c| Regexp.escape(c) }.join(".*")}/i 162 @now = @candidates.select {|i| 163 r === i.name 164 }.sort_by {|i| 165 r.match(i.name).begin(0) 166 } 167 @results.usesAlternatingRowBackgroundColors = false 168 @results.backgroundColor = NSColor.objc_send( 169 :colorWithCalibratedRed, 0.95, 170 :green, 0.90, 171 :blue, 0.90, 172 :alpha, 1 173 ) 174 else 175 @results.usesAlternatingRowBackgroundColors = true 176 end 177 178 @results.reloadData 179 end 180 181 def nextCandidate(sender) 182 if @results.selectedRow <= @now.size 183 @results.selectRowIndexes_byExtendingSelection(NSIndexSet.alloc.initWithIndex(@results.selectedRow+1), false) 184 @results.scrollRowToVisible(@results.selectedRow) 185 end 186 end 187 188 def prevCandidate(sender) 189 if @results.selectedRow > 0 190 @results.selectRowIndexes_byExtendingSelection(NSIndexSet.alloc.initWithIndex(@results.selectedRow-1), false) 191 @results.scrollRowToVisible(@results.selectedRow) 192 end 122 193 end 123 194 124 195 def process_keyevent(e) 125 unless @editting126 @combo.stringValue = ""127 @editting = true128 @combo.textColor = NSColor.controlTextColor129 end130 @combo.scrollItemAtIndexToTop(0)131 196 key = key_string(e) 132 197 #log key 133 198 case key 199 when "C-n" 200 nextCandidate nil 201 when "C-p" 202 prevCandidate nil 134 203 when "\r" 135 unless @combo.stringValue.strip.empty? 136 index = comboBox_indexOfItemWithStringValue(@combo, @combo.stringValue) 137 unless index == NSNotFound 138 pro = @candidate[index][1] 139 if pro.arity == 0 140 pro.call 141 else 142 pro.call(@candidate[index][0], @combo.stringValue.to_s) 143 end 144 end 204 log @input.stringValue 205 unless @input.stringValue.strip.empty? 206 run_current_selection 145 207 end 146 208 @window.orderOut(nil) 209 when "\t" 210 when "S-\t" 147 211 when "C-u" 148 @combo.stringValue = "" 212 @input.stringValue = "" 213 filtering "" 149 214 when "C-c" 150 215 @window.orderOut(nil) 151 216 end 217 152 218 false 153 219 end … … 175 241 176 242 def build_candidates 177 @candidate = []178 179 @applications = [ Pathname.new("Finder")]243 @candidates = [] 244 245 @applications = [] 180 246 search_applications_recursive("/Applications") 181 247 search_applications_recursive("/Developer/Applications") 182 248 183 @candidate = @applications.map {|f|184 [f.basename(".app").to_s, proc {249 @candidates = @applications.map {|f| 250 Candidate.new(f.basename(".app").to_s, f.realpath) do 185 251 system("open", "-a", f) 186 }]252 end 187 253 } 188 254 189 @candidate .concat Pathname.glob("/System/Library/PreferencePanes/*.prefPane").map {|f|190 [f.basename.to_s, proc {255 @candidates.concat Pathname.glob("/System/Library/PreferencePanes/*.prefPane").map {|f| 256 Candidate.new(f.basename.to_s, f.realpath) do 191 257 system("open", f) 192 }]258 end 193 259 } 194 260 195 @candidate << [/.d (.+)/, proc {|s,m| 196 code = m[s, 1] 197 result = "" 198 begin 199 result = eval(code, binding).inspect 200 rescue Exception => e 201 result = e.inspect 202 end 203 log result 204 OSX.NSRunAlertPanel("Debug", result, "Ok", "", nil) 205 }] 206 207 @candidate << ["Exit", proc { 261 # TODO 262 # @candidates << Candidate.new(/.d (.+)/, NSWorkspace.sharedWorkspace.iconForFile("sh")) do 263 # code = m[s, 1] 264 # result = "" 265 # begin 266 # result = eval(code, binding).inspect 267 # rescue Exception => e 268 # result = e.inspect 269 # end 270 # log result 271 # OSX.NSRunAlertPanel("Debug", result, "Ok", "", nil) 272 # end 273 274 @candidates << Candidate.new("Exit", :sh) do 208 275 if OSX.NSRunAlertPanel("Sure?", "exit ok?", "Exit", "Cancel", nil) == NSAlertDefaultReturn 209 276 NSApp.terminate(nil) 210 277 end 211 }] 212 278 end 279 280 @now = @candidates 213 281 log "Search done" 214 282 #set_status "Search done" -
lang/ruby/Amalgam/English.lproj
-
Property
svn:ignore set
to
MainMenu~.nib
-
Property
svn:ignore set
to
-
lang/ruby/Amalgam/English.lproj/MainMenu.nib/classes.nib
r734 r747 4 4 CLASS = AppController; 5 5 LANGUAGE = ObjC; 6 OUTLETS = { combo= id; view = id; };6 OUTLETS = {input = id; results = id; view = id; }; 7 7 SUPERCLASS = NSObject; 8 8 }, -
lang/ruby/Amalgam/English.lproj/MainMenu.nib/info.nib
r741 r747 8 8 <dict> 9 9 <key>196</key> 10 <string> 538 496 358 630 0 1280 778 </string>10 <string>350 466 358 235 0 0 1280 778 </string> 11 11 </dict> 12 12 <key>IBFramework Version</key>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)