1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
//
// This file is part of the LibreOffice project.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
import UIKit
class DocumentController: UIViewController, MenuDelegate, UIDocumentPickerDelegate
{
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL)
{
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController)
{
}
// Show sidemenu (part of documentcontroller)
@IBAction func doMenu(_ sender: UIBarButtonItem)
{
if (sender.tag == 10) {
sender.tag = 0;
let viewMenuBack : UIView = view.subviews.last!
UIView.animate(withDuration: 0.3, animations: { () -> Void in
var frameMenu : CGRect = viewMenuBack.frame
frameMenu.origin.x = -1 * UIScreen.main.bounds.size.width
viewMenuBack.frame = frameMenu
viewMenuBack.layoutIfNeeded()
viewMenuBack.backgroundColor = UIColor.clear
}, completion: { (finished) -> Void in
viewMenuBack.removeFromSuperview()
})
return
}
sender.isEnabled = false
sender.tag = 10
let sidebar : SidebarController = self.storyboard!.instantiateViewController(withIdentifier: "SidebarController") as! SidebarController
view.addSubview(sidebar.view)
addChildViewController(sidebar)
sidebar.view.layoutIfNeeded()
sidebar.view.frame=CGRect(x: 0 - UIScreen.main.bounds.size.width, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height);
UIView.animate(withDuration: 0.3, animations: { () -> Void in
sidebar.view.frame=CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height);
sender.isEnabled = true
}, completion:nil)
}
// Last stop before displaying popover
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier == "showActions" {
let vc = segue.destination as! DocumentActions
vc.delegate = self
// JIX, TO BE CHANGED
vc.isDocActive = true
}
}
func actionMenuSelected(_ tag : Int)
{
switch tag
{
case 1: // New
print("menu New to be done")
case 2: // Open...
let openMenu = UIDocumentPickerViewController(documentTypes: ["public.content"], in: .open)
openMenu.delegate = self
self.present(openMenu, animated: true, completion: nil)
print("menu Open... to be done")
case 3: // Save
print("menu Save to be done")
case 4: // Save as...
print("menu Save as... to be done")
case 5: // Save as PDF...
print("menu Save as PDF... to be done")
case 6: // Print...
print("menu Print... to be done")
case 7: // Copy TO iPad
print("menu Copy TO iPad to be done")
case 8: // Delete FROM iPad
print("menu Delete FROM iPad to be done")
case 9: // Move FROM iPad
print("menu Move FROM iPad to be done")
default: // should not happen
print("unknown menu" + String(tag))
}
}
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view.
// let path = Bundle.main.path(forResource: "Info", ofType: "plist")
// let dict = NSDictionary(contentsOfFile: path!)
// let tableData = dict!.object(forKey: "CFBundleDocumentTypes")
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// Protocol for action popover callback
protocol MenuDelegate
{
func actionMenuSelected(_ tag : Int)
}
class DocumentActions: UITableViewController
{
// Pointer to callback class
var delegate : MenuDelegate?
var isDocActive : Bool = false
// Calling class might enable/disable each button
@IBOutlet weak var buttonNew: UIButton!
@IBOutlet weak var buttonOpen: UIButton!
@IBOutlet weak var buttonSave: UIButton!
@IBOutlet weak var buttonSaveAs: UIButton!
@IBOutlet weak var buttonSaveAsPDF: UIButton!
@IBOutlet weak var buttonPrint: UIButton!
@IBOutlet weak var buttonCopyTOiPad: UIButton!
@IBOutlet weak var buttonDeleteFROMiPad: UIButton!
@IBOutlet weak var buttonMoveFROMiPad: UIButton!
// Actions
@IBAction func actionMenuSelect(_ sender: UIButton)
{
dismiss(animated: false)
delegate?.actionMenuSelected(sender.tag)
}
override func viewDidLoad()
{
super.viewDidLoad()
buttonDeleteFROMiPad.isEnabled = isDocActive
buttonSave.isEnabled = isDocActive
buttonSaveAs.isEnabled = isDocActive
buttonSaveAsPDF.isEnabled = isDocActive
buttonPrint.isEnabled = isDocActive
}
}
|