|
1 | 1 | #!/usr/bin/env perl |
2 | | - |
3 | | -package main ; |
4 | | - |
5 | 2 | use strict; |
6 | 3 | use warnings; |
7 | 4 |
|
8 | | -use Glib ':constants'; |
9 | 5 | use Gtk3 -init; |
10 | | -Gtk3->init; |
11 | | - |
12 | | -use App::Asciio::Setup ; |
13 | | -use App::Asciio::GTK::Asciio ; |
14 | | -use App::Asciio::Server ; |
15 | | -use App::Asciio::GTK::Asciio::DnD ; |
16 | | - |
17 | | -use Module::Util qw(find_installed) ; |
18 | | -use File::Basename ; |
19 | | - |
20 | | -#----------------------------------------------------------------------------- |
21 | | - |
22 | | -my $window = Gtk3::Window->new('toplevel'); |
23 | | -$window->set_title("asciio"); |
24 | | -$window->set_default_size(1000, 1000) ; |
25 | | -$window->signal_connect("destroy", sub { exit(0); }); |
26 | | - |
27 | | -my $scwin = Gtk3::ScrolledWindow->new(); |
28 | | -$scwin->set_policy('automatic', 'automatic'); |
29 | | - |
30 | | -$window->add($scwin); |
31 | | - |
32 | | -my @asciios ; |
33 | | - |
34 | | -push @asciios, my $asciio = new App::Asciio::GTK::Asciio($window, 50, 25, $scwin) ; |
35 | | - |
36 | | -$scwin->add_with_viewport($asciio->{widget}); |
37 | | -$scwin->show_all(); |
38 | | - |
39 | | -my ($command_line_switch_parse_ok, $command_line_parse_message, $asciio_config) |
40 | | - = $asciio->ParseSwitches([@ARGV], 0) ; |
41 | | - |
42 | | -die "Error: '$command_line_parse_message'!" unless $command_line_switch_parse_ok ; |
43 | | - |
44 | | -my %object_override ; |
45 | | -if(defined $asciio_config->{DEBUG_FD}) |
46 | | - { |
47 | | - open my $fh, ">&=", $asciio_config->{DEBUG_FD} or die "can't open fd $asciio_config->{DEBUG_FD}: $!\n" ; |
48 | | - $fh->autoflush(1) ; |
49 | | - %object_override = (WARN => sub { print $fh "@_" }, ACTION_VERBOSE => sub { print $fh "$_[0]\n" ; } ) ; |
50 | | - } |
51 | | -else |
52 | | - { |
53 | | - %object_override = (WARN => sub { print STDERR "@_" }, ACTION_VERBOSE => sub { print STDERR "$_[0]\n" ; } ) ; |
54 | | - } |
55 | | - |
56 | | -my $setup_paths = [] ; |
57 | | - |
58 | | -$asciio->{DISPLAY_SETUP_INFORMATION}++ if $asciio_config->{DISPLAY_SETUP_INFORMATION} ; |
| 6 | +use Glib::Object::Introspection; |
| 7 | +use Glib qw(TRUE FALSE); |
59 | 8 |
|
60 | | -if(@{$asciio_config->{SETUP_PATHS}}) |
61 | | - { |
62 | | - $setup_paths = $asciio_config->{SETUP_PATHS} ; |
63 | | - } |
64 | | -else |
65 | | - { |
66 | | - my ($basename, $path, $ext) = File::Basename::fileparse(find_installed('App::Asciio'), ('\..*')) ; |
67 | | - my $setup_path = $path . $basename . '/setup/' ; |
68 | | - |
69 | | - $setup_paths = |
70 | | - [ |
71 | | - $setup_path . 'setup.ini', |
72 | | - $setup_path . 'GTK/setup.ini', |
73 | | - $ENV{HOME} . '/.config/Asciio/Asciio.ini', |
74 | | - ] ; |
75 | | - } |
| 9 | +use App::Asciio::GTK::Asciio::TabManager ; |
76 | 10 |
|
77 | | -$asciio->setup($setup_paths, \%object_override) ; |
| 11 | +my $window = Gtk3::Window->new('toplevel') ; |
| 12 | +$window->set_title('Asciio') ; |
| 13 | +$window->set_default_size(600, 400) ; |
78 | 14 |
|
79 | | -my ($character_width, $character_height) = $asciio->get_character_size() ; |
| 15 | +my $tab_manager = App::Asciio::GTK::Asciio::TabManager->new() ; |
80 | 16 |
|
81 | | -if(defined $asciio_config->{TARGETS}[0]) |
82 | | - { |
83 | | - $asciio->run_actions_by_name(['Open', $asciio_config->{TARGETS}[0]]) ; |
84 | | - |
85 | | - delete $asciio->{BINDINGS_COMPLETION} ; |
86 | | - |
87 | | - $window->set_default_size(@{$asciio->{WINDOW_SIZE}}) if defined $asciio->{WINDOW_SIZE} ; |
88 | | - } |
| 17 | +$window->add($tab_manager->get_widget()) ; |
89 | 18 |
|
90 | | -App::Asciio::setup_embedded_bindings($asciio, $asciio_config) ; |
91 | | - |
92 | | -$window->show_all(); |
93 | | - |
94 | | -$asciio->{widget}->set_size_request($asciio->{CANVAS_WIDTH} * $character_width, $asciio->{CANVAS_HEIGHT} * $character_height); |
95 | | -$asciio->set_modified_state(0) ; |
96 | | - |
97 | | -if(defined $asciio_config->{SCRIPT}) |
98 | | - { |
99 | | - require App::Asciio::Scripting ; |
100 | | - |
101 | | - App::Asciio::Utils::Scripting::run_external_script($asciio, $asciio_config->{SCRIPT}) ; |
102 | | - } |
103 | | - |
104 | | -$asciio->setup_dnd($window) ; |
105 | | - |
106 | | -#-------------------------------------------------------------------------- |
107 | | - |
108 | | -$window->signal_connect (delete_event => \&delete_event, \@asciios) ; |
109 | | - |
110 | | -sub delete_event |
111 | | -{ |
112 | | -my ($window, $event, $asciios) = @_; |
113 | | - |
114 | | -my $answer = 'yes'; |
115 | | - |
116 | | -my $should_save ; |
117 | | -for my $asciio (@{$asciios}) |
118 | | - { |
119 | | - $should_save++ if $asciio->get_modified_state() ; |
120 | | - } |
121 | | - |
122 | | -if($should_save) |
123 | | - { |
124 | | - $answer = $asciios[0]->display_quit_dialog('asciio', ' ' x 25 . "Document is modified!\n\nAre you sure you want to quit and lose your changes?\n") ; |
125 | | - } |
126 | | - |
127 | | -if($answer eq 'save_and_quit') |
128 | | - { |
129 | | - for my $asciio (@{$asciios}) |
| 19 | +$window->signal_connect |
| 20 | + ( |
| 21 | + destroy => sub |
130 | 22 | { |
131 | | - my @saved_result = $asciio->run_actions_by_name('Save') ; |
132 | | - |
133 | | - $answer = 'cancel' if(! defined $saved_result[0][0] || $saved_result[0][0] eq '') ; |
| 23 | + Gtk3::main_quit() ; |
134 | 24 | } |
135 | | - } |
136 | | - |
137 | | -return $answer eq 'cancel'; |
138 | | -} |
139 | | - |
140 | | -#-------------------------------------------------------------------------- |
141 | | - |
142 | | -App::Asciio::Server::start_web_server($asciios[0], $asciio_config->{WEB_PORT} // 4444) ; |
143 | | - |
144 | | -Gtk3->main(); |
| 25 | + ) ; |
| 26 | + |
| 27 | +$window->show_all() ; |
| 28 | + |
| 29 | +# $window->signal_connect |
| 30 | +# ( |
| 31 | +# 'key-press-event' => sub |
| 32 | +# { |
| 33 | +# my ($widget, $event) = @_ ; |
| 34 | +# $widget->grab_focus() ; |
| 35 | +# # App::Asciio::GTK::Asciio::button_press_event(undef, $event, $self) ; |
| 36 | +# print"in main window key-press-event\n" ; |
| 37 | +# return TRUE ; |
| 38 | +# } |
| 39 | +# ) ; |
| 40 | + |
| 41 | +Gtk3::main() ; |
145 | 42 |
|
0 commit comments