Changeset 741 for lang/ruby/Amalgam

Show
Ignore:
Timestamp:
10/26/07 23:40:50 (6 years ago)
Author:
cho45
Message:

lang/ruby/Amalgam/AppController.rb,
lang/ruby/Amalgam/English.lproj/MainMenu.nib/objects.nib,
lang/ruby/Amalgam/English.lproj/MainMenu.nib/info.nib:

でっかく。
コマンドとかは === で比較するようにした。
これによって正規表現がつかえるように
補完のところでは grep をつかっている。
正規表現同士だと必ず false になり、補完されない。

Location:
lang/ruby/Amalgam
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/Amalgam/AppController.rb

    r739 r741  
    3434 
    3535        def comboBox_objectValueForItemAtIndex(sender, index) 
    36                 (@candidate || [])[index] 
     36                (@candidate || [])[index].first 
    3737        end 
    3838 
    3939        def numberOfItemsInComboBox(sender) 
    40                 log "Reloaded data" 
     40                # log "Reloaded data" 
    4141                (@candidate || []).length 
    4242        end 
     
    4444        def comboBox_completedString(sender, string) 
    4545                #log "completedString->#{string}" 
    46                 (@candidate || []).grep(/^#{string}/i).first 
    47         rescue 
     46                string = Regexp.escape(string) 
     47                (@candidate || []).transpose[0].grep(/^#{string}/i).first 
     48        rescue Exception 
    4849                "" 
    4950        end 
     
    5152        def comboBox_indexOfItemWithStringValue(sender, string) 
    5253                @candidate ||= [] 
    53                 @candidate.index(string) || NSNotFound 
     54                @candidate.each_with_index do |(r,l),i| 
     55                        if r === string 
     56                                return i 
     57                        end 
     58                end 
     59                NSNotFound 
    5460        end 
    5561 
     
    6773        def windowDidBecomeMain(anot) 
    6874                @window.makeFirstResponder(@combo) 
    69                 @combo.reloadData 
    70                 @combo.stringValue = "" 
    71                 @now = nil 
     75                @combo.delegate = self 
     76                #@combo.reloadData 
     77                @editting = false 
     78                #@combo.stringValue = "" 
    7279        end 
    7380 
     
    101108                @combo.numberOfVisibleItems = 20 
    102109 
    103                 NSApp.register_hotkey("Command+Control+O") do 
     110                NSApp.register_hotkey("Command+`") do 
    104111                        log "HotKey hitted" 
    105112                        NSApp.activateIgnoringOtherApps(true) 
     
    109116                end 
    110117 
    111                 Thread.start do 
    112                         search_applications() 
    113                 end.join 
     118                build_candidates() 
     119 
     120                NSApp.activateIgnoringOtherApps(true) 
     121                @window.makeFirstResponder(@combo) 
    114122        end 
    115123 
     
    125133                case key 
    126134                when "\r" 
    127                         case @combo.stringValue 
    128                         when "exit", "Exit" 
    129                                 if OSX.NSRunAlertPanel("Sure?", "exit ok?", "Exit", "Cancel", nil) == NSAlertDefaultReturn 
    130                                         NSApp.terminate(nil) 
    131                                 end 
    132                         when /^d (.+)/i 
    133                                 code = Regexp.last_match[1] 
    134                                 result = "" 
    135                                 begin 
    136                                         result = eval(code, binding).inspect 
    137                                 rescue Exception => e 
    138                                         result = e.inspect 
    139                                 end 
    140                                 OSX.NSRunAlertPanel("Debug", result, "Ok", "", nil) == NSAlertDefaultReturn 
    141                         when /^\s*$/ 
    142                                 # nothing 
    143                         else 
     135                        unless @combo.stringValue.strip.empty? 
    144136                                index = comboBox_indexOfItemWithStringValue(@combo, @combo.stringValue) 
    145137                                unless index == NSNotFound 
    146                                         @commands[index].call 
     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 
    147144                                end 
    148145                        end 
     
    167164        end 
    168165 
    169         def search_applications 
     166        def relunch(*) 
     167                log "relunch" 
     168                path = NSBundle.mainBundle.executablePath.to_s 
     169                fork do 
     170                        sleep 2 
     171                        system(path) 
     172                end 
     173                NSApp.terminate(nil) 
     174        end 
     175 
     176        def build_candidates 
     177                @candidate = [] 
     178 
    170179                @applications = [Pathname.new("Finder")] 
    171180                search_applications_recursive("/Applications") 
    172181                search_applications_recursive("/Developer/Applications") 
    173                  
    174  
    175                 candidate = [] 
    176                 candidate = @applications.map {|f| 
     182 
     183                @candidate = @applications.map {|f| 
    177184                        [f.basename(".app").to_s, proc { 
    178185                                system("open", "-a", f) 
     
    180187                } 
    181188 
    182                 candidate.concat Pathname.glob("/System/Library/PreferencePanes/*.prefPane").map {|f| 
     189                @candidate.concat Pathname.glob("/System/Library/PreferencePanes/*.prefPane").map {|f| 
    183190                        [f.basename.to_s, proc { 
    184191                                system("open", f) 
     
    186193                } 
    187194 
    188                 @candidate, @commands = candidate.transpose 
    189  
    190                 log @candidate 
     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 { 
     208                        if OSX.NSRunAlertPanel("Sure?", "exit ok?", "Exit", "Cancel", nil) == NSAlertDefaultReturn 
     209                                NSApp.terminate(nil) 
     210                        end 
     211                }] 
     212 
    191213                log "Search done" 
    192214                #set_status "Search done" 
  • lang/ruby/Amalgam/English.lproj/MainMenu.nib/info.nib

    r735 r741  
    88        <dict> 
    99                <key>196</key> 
    10                 <string>538 496 204 63 0 0 1280 778 </string> 
     10                <string>538 496 358 63 0 0 1280 778 </string> 
    1111        </dict> 
    1212        <key>IBFramework Version</key>