-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.php
109 lines (85 loc) · 2.75 KB
/
App.php
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
<?php
declare(strict_types=1);
namespace Ardillo\Examples\CsvEdit;
use Ardillo\{
Menu,
ReactApp,
Size,
TableModel,
};
use React\Dns\Model\Message;
class App extends ReactApp
{
public Main\Window $win;
public Handler $handler;
public TableModel $model;
public string $lastPath;
public function onMenuItemClicked(int $id): void
{
switch ($id) {
case 1:
$path = $this->win->openFile();
if ($path) {
$this->handler->import($path);
}
break;
case 2:
if (!isset($this->lastPath)) {
$this->win->messageBox(
Main\Window::MESSAGE_BOX_ERROR, 'Cannot save',
'Open a file before attempting to save data'
);
break;
}
$path = $this->lastPath;
case 3:
if (!isset($path)) {
$path = $this->win->saveFile();
if (is_null($path)) {
break;
}
}
$this->handler->export($path);
break;
case 5:
$this->win->messageBox(
Main\Window::MESSAGE_BOX_DEFAULT, 'Ardillo CSV Editor',
"CSV editor built with Ardillo\nhttps://ardillo.org"
);
break;
}
}
public function setupMenu(): void
{
$file = $this->appendMenu(null, Menu::Top, 0, 'File');
$this->appendMenu($file, Menu::Item, 1, 'Open');
$this->appendMenu($file, Menu::Item, 2, 'Save');
$this->appendMenu($file, Menu::Item, 3, 'Save As...');
$this->appendMenu($file, Menu::Quit, 4, null);
$help = $this->appendMenu(null, Menu::Top, 0, 'Help');
$this->appendMenu($help, Menu::About, 5, null);
}
public function onSigInt(int $signo): void
{
echo 'Caught SIGINT ...' . PHP_EOL;
unset($this->win);
$this->stop();
}
protected function OnInit(): void
{
$this->setupMenu();
$this->handler = new Handler;
$this->model = new TableModel($this->handler);
$this->win = new Main\Window('Ardillo CSV Editor', new Size(640, 480), true);
$this->win->setup();
$this->win->show();
$options = getopt('f:', ['file:']);
if (isset($options['f']) || isset($options['file'])) {
$file = isset($options['f']) ? $options['f'] : $options['file'];
if (is_string($file)) {
$this->handler->import($file);
}
}
$this->loop->addSignal(self::SIGINT, $this->onSigInt(...));
}
}