1#
2#  MainController.rb
3#  CGPDFViewer
4#
5#  Created by Laurent Sansonetti on 12/12/06.
6#  Copyright (c) 2006 Apple Computer. All rights reserved.
7#
8
9class MainController < NSObject
10
11  # These six methods pass the appropriate message to the current
12  # (frontmost) PDFView.  They are called by the menu items and enable
13  # keyboard shortcuts.
14  ib_action :firstPage do |sender|
15    currentPDFView.setPageNumber(1)
16  end
17  
18  ib_action :lastPage do |sender|
19    currentPDFView.setPageNumber(currentPDFView.pageCount)
20  end
21
22  ib_action :pageDown do |sender|
23    currentPDFView.incrementPageNumber(self)
24  end
25  
26  ib_action :pageUp do |sender|
27    currentPDFView.decrementPageNumber(self)
28  end
29
30  ib_action :rotateLeft do |sender|
31    currentPDFView.rotateLeft(self)
32  end
33
34  ib_action :rotateRight do |sender|
35    currentPDFView.rotateRight(self)
36  end
37
38  # Retrieve the PDF View of the main window.
39  def currentPDFView
40    NSApp.mainWindow.windowController.document.pdfView
41  end
42
43  # Disable inappropriate menu items.
44  def validateMenuItem(item)
45    action = item.action
46    if action == 'firstPage:' or action == 'pageUp'
47      currentPDFView != nil and currentPDFView.pageNumber != 1
48    elsif action == 'lastPage:' or action == 'pageDown'
49      currentPDFView != nil and currentPDFView.pageNumber != currentPDFView.pageCount
50    elsif action == 'rotateLeft' or action == 'rotateRight'
51      currentPDFView != nil
52    else
53      true
54    end
55  end
56end
57