| | 27 | load_condition |
| | 28 | end |
| | 29 | |
| | 30 | def windowWillClose(sender) |
| | 31 | save_condition |
| | 32 | end |
| | 33 | |
| | 34 | def load_condition |
| | 35 | category = NSUserDefaults.standardUserDefaults[:documents] |
| | 36 | if category |
| | 37 | config = category[self.document.fileURL.absoluteString] |
| | 38 | if config |
| | 39 | self.window.setFrame_display(NSRect.new(*config[:frame].to_ruby), false) |
| | 40 | size = @drawer.contentSize |
| | 41 | size.width = config[:drawer_width].to_f |
| | 42 | @drawer.setContentSize(size) |
| | 43 | @search.stringValue = config[:search] |
| | 44 | @search.currentEditor.setSelectedRange(NSRange.new(@search.stringValue.length, 0)) |
| | 45 | controlTextDidChange(nil) |
| | 46 | |
| | 47 | r = NSURLRequest.requestWithURL NSURL.URLWithString(config[:url]) |
| | 48 | @webview.mainFrame.loadRequest r |
| | 49 | else |
| | 50 | config = category[:last] |
| | 51 | if config |
| | 52 | frame = self.window.frame |
| | 53 | frame.size = NSSize.new(*config[:frame].to_ruby[2..3]) |
| | 54 | self.window.setFrame_display(frame, false) |
| | 55 | size = @drawer.contentSize |
| | 56 | size.width = config[:drawer_width].to_i |
| | 57 | @drawer.setContentSize(size) |
| | 58 | end |
| | 59 | end |
| | 60 | end |
| | 61 | end |
| | 62 | |
| | 63 | def save_condition |
| | 64 | userdef = NSUserDefaults.standardUserDefaults |
| | 65 | category = userdef[:documents] |
| | 66 | category = category ? category.to_ruby : {} |
| | 67 | config = { |
| | 68 | :frame => self.window.frame.to_a.flatten, |
| | 69 | :search => @search.stringValue, |
| | 70 | :drawer_width => @drawer.contentSize.width, |
| | 71 | :url => @webview.mainFrameURL, |
| | 72 | } |
| | 73 | category[self.document.fileURL.absoluteString.to_s] = config |
| | 74 | category['last'] = config |
| | 75 | userdef[:documents] = category |
| | 76 | userdef.synchronize |
| | 77 | |
| | 78 | log @webview.mainFrameURL |