root/lang/ruby/Chemr/CHMDocument.rb @ 656

Revision 656, 3.3 kB (checked in by cho45, 6 years ago)

lang/ruby/Chemr/CHMDocument.rb,
lang/ruby/Chemr/English.lproj/CHMDocument.nib/info.nib,
lang/ruby/Chemr/English.lproj/CHMDocument.nib/keyedobjects.nib:

ちょっとだけ修正
NSSearchField はうまくキー入力がとれない? サブクラスにしても keyDown がよばれない……

Line 
1#!rake ;#
2
3class CHMDocument < NSDocument
4        attr_reader :chm
5
6        #- (void)makeWindowControllers
7        def makeWindowControllers
8                c = CHMWindowController.alloc.initWithWindowNibName("CHMDocument")
9                self.addWindowController(c)
10        end
11
12        #- (BOOL)readFromURL:(NSURL *)inAbsoluteURL ofType:(NSString *)inTypeName error:(NSError **)outError
13        def readFromURL_ofType_error(url, type, error)
14                @chm = Chmlib::Chm.new(url.path.to_s)
15#               log chm
16#               r = NSURLRequest.requestWithURL CHMInternalURLProtocol.url_for(chm, chm.home)
17#               @webview.mainFrame.loadRequest r
18                true
19        end
20
21        #- (BOOL)writeToURL:(NSURL *)inAbsoluteURL ofType:(NSString *)inTypeName error:(NSError **)outError
22        def writeToURL_ofType_error(url, type, error)
23                false
24        end
25
26        #- (void)windowControllerDidLoadWindowNib:(NSWindowController *)windowController
27        def windowControllerDidLoadWindowNib(cont)
28                log "wCDLWN", cont
29        end
30
31#       def dataRepresentationOfType(aType)
32#       end
33#
34#       def loadDataRepresentation_ofType(data, aType)
35#       end
36
37#       def displayName
38#       end
39        def windowControllerWillLoadNib(cont)
40                log cont
41        end
42
43        def winwowNibName
44                "CHMDocument"
45        end
46end
47
48#class MySCWindow < NSWindow
49#
50#       attr_accessor :list
51#
52#       ib_action :keyDown do |e|
53#               log "keyDown #{e.keyCode} #{e.characters}"
54#       end
55#
56#       ib_action :moveDown do |sender|
57#               log "moveDown"
58#       end
59#
60#       ib_action :mouseDown do |sender|
61#               log "mouseDown"
62#       end
63#
64#       ib_action :moveUp do |sender|
65#               log "moveUp"
66#       end
67#end
68
69
70class CHMWindowController < NSWindowController
71        ib_outlet :webview
72        ib_outlet :list
73        ib_outlet :drawer
74        ib_outlet :search
75
76        def windowDidLoad
77                @chm = self.document.chm
78                browse @chm.home
79                @now = @index = @chm.index.to_a.sort_by {|k,v| k} # cache
80                @list.setDataSource(self)
81                @list.setDoubleAction("dblclicked_")
82                @search.setDelegate(self)
83                @drawer.open
84        end
85
86        # Tableview
87        def numberOfRowsInTableView(table)
88                @now.length
89        end
90
91        def tableView_objectValueForTableColumn_row(table, column, row)
92                @now[row][0]
93        end
94
95#       def tableView_setObjectValue_forTableColumn_row(table, value, column, row)
96#       end
97
98        def tableView_willDisplayCell_forTableColumn_row(table, cell, column, row)
99#               case column.identifier.to_s
100#               when 'regexp'
101#               when 'color'
102#                       _, r, g, b = */(..)(..)(..)$/.match(cell.stringValue.to_s).to_a.map{|i| i.to_i(16) / 255.0 }
103#                       color = NSColor.colorWithCalibratedRed_green_blue_alpha(r, g, b, 1)
104#                       cell.setDrawsBackground(true)
105#                       cell.setTextColor(color)
106#                       cell.setBackgroundColor(NSColor.blackColor)
107#               when 'hilight'
108#               end
109        end
110
111        def textShouldBeginEditing(text)
112                true
113        end
114
115        def textShouldEndEditing(text)
116                true
117        end
118
119        def acceptsFirstResponder
120                true
121        end
122
123        def controlTextDidChange(anot)
124                filtering @search.stringValue
125                @list.selectRowIndexes_byExtendingSelection(NSIndexSet.alloc.initWithIndex(0), false)
126        end
127
128        def controlTextDidEndEditing(anot)
129                log "end #{@now.first.inspect}"
130                browse @now.first[1].first
131        end
132
133        def filtering(str)
134                if str =~ /[A-Z]/
135                        r = /#{str}/
136                else
137                        r = /#{str}/i
138                end
139                @now = @index.select {|k,v|
140                        k =~ r
141                }.sort_by {|k,v| k }
142                @list.reloadData
143        end
144
145        def dblclicked(sender)
146                browse @now[@list.selectedRow][1].first
147        end
148
149        def browse(path)
150                if path
151                        path = "/#{path}" unless path[0] == ?/
152                        r = NSURLRequest.requestWithURL CHMInternalURLProtocol.url_for(@chm, path)
153                        @webview.mainFrame.loadRequest r
154                end
155        end
156
157        def searchActivate(sender)
158                log "activate"
159                @search.window.makeFirstResponder(@search)
160        end
161end
Note: See TracBrowser for help on using the browser.