line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Gtk2-Ex-History. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Gtk2-Ex-History is free software; you can redistribute it and/or modify it |
6
|
|
|
|
|
|
|
# under the terms of the GNU General Public License as published by the Free |
7
|
|
|
|
|
|
|
# Software Foundation; either version 3, or (at your option) any later |
8
|
|
|
|
|
|
|
# version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Gtk2-Ex-History is distributed in the hope that it will be useful, but |
11
|
|
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12
|
|
|
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Gtk2-Ex-History. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Gtk2::Ex::History::Button; |
19
|
1
|
|
|
1
|
|
28776
|
use 5.008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
20
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
21
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
22
|
1
|
|
|
1
|
|
1593
|
use Gtk2 1.220; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Gtk2::Ex::History; |
25
|
|
|
|
|
|
|
use Glib::Ex::ConnectProperties 13; # v.13 for model-rows |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
28
|
|
|
|
|
|
|
#use Smart::Comments; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = 8; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Glib::Object::Subclass |
33
|
|
|
|
|
|
|
'Gtk2::Button', |
34
|
|
|
|
|
|
|
signals => { clicked => \&_do_clicked, |
35
|
|
|
|
|
|
|
button_press_event => \&_do_button_press_event }, |
36
|
|
|
|
|
|
|
properties => [ Glib::ParamSpec->object |
37
|
|
|
|
|
|
|
('history', |
38
|
|
|
|
|
|
|
'History object', |
39
|
|
|
|
|
|
|
'The history object to act on.', |
40
|
|
|
|
|
|
|
'Gtk2::Ex::History', |
41
|
|
|
|
|
|
|
Glib::G_PARAM_READWRITE), |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Glib::ParamSpec->enum |
44
|
|
|
|
|
|
|
('way', |
45
|
|
|
|
|
|
|
'Which way', |
46
|
|
|
|
|
|
|
'Which way to go in the history when clicked, either back or forward.', |
47
|
|
|
|
|
|
|
'Gtk2::Ex::History::Way', |
48
|
|
|
|
|
|
|
'back', |
49
|
|
|
|
|
|
|
Glib::G_PARAM_READWRITE), |
50
|
|
|
|
|
|
|
]; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub INIT_INSTANCE { |
53
|
|
|
|
|
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
# for some reason these setting don't take effect here but must be done in |
55
|
|
|
|
|
|
|
# SET_PROPERTY below |
56
|
|
|
|
|
|
|
$self->set_label ("gtk-go-back"); # default |
57
|
|
|
|
|
|
|
$self->set_use_stock (1); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub SET_PROPERTY { |
61
|
|
|
|
|
|
|
my ($self, $pspec, $newval) = @_; |
62
|
|
|
|
|
|
|
my $pname = $pspec->get_name; |
63
|
|
|
|
|
|
|
$self->{$pname} = $newval; # per default GET_PROPERTY |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# if ($pname eq 'history' || $pname eq 'way') { ... |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# should only need to update the icon when setting 'way', but as of gtk |
68
|
|
|
|
|
|
|
# 2.18 the icon in INIT_INSTANCE doesn't take effect -- something about |
69
|
|
|
|
|
|
|
# "constructor" -- so as a workaround apply the stock icon when setting |
70
|
|
|
|
|
|
|
# 'history' too |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
my $way = $self->get('way'); |
73
|
|
|
|
|
|
|
$self->set_label ("gtk-go-$way"); |
74
|
|
|
|
|
|
|
$self->set_use_stock (1); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# the history model, either the back or forward one |
77
|
|
|
|
|
|
|
my $history = $self->{'history'}; |
78
|
|
|
|
|
|
|
$self->{'connp'} = $history && Glib::Ex::ConnectProperties->dynamic |
79
|
|
|
|
|
|
|
([$history->model($way), 'model-rows#not-empty'], |
80
|
|
|
|
|
|
|
[$self, 'sensitive']); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# 'clicked' class closure |
84
|
|
|
|
|
|
|
sub _do_clicked { |
85
|
|
|
|
|
|
|
my ($self) = @_; |
86
|
|
|
|
|
|
|
### History-Button clicked: $self->get('way') |
87
|
|
|
|
|
|
|
my $history = $self->{'history'} || return; |
88
|
|
|
|
|
|
|
my $way = $self->get('way'); |
89
|
|
|
|
|
|
|
$history->$way; |
90
|
|
|
|
|
|
|
return shift->signal_chain_from_overridden(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# 'button-press-event' class closure |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# Might like this popup to work even when there's no items in the model and |
96
|
|
|
|
|
|
|
# the button is therefore insensitive, but the button-press-event doesn't |
97
|
|
|
|
|
|
|
# come through when insensitive. |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
sub _do_button_press_event { |
100
|
|
|
|
|
|
|
my ($self, $event) = @_; |
101
|
|
|
|
|
|
|
### History-Button button-press-event: $event->button |
102
|
|
|
|
|
|
|
if ($event->button == 3 && (my $history = $self->{'history'})) { |
103
|
|
|
|
|
|
|
require Gtk2::Ex::History::Menu; |
104
|
|
|
|
|
|
|
Gtk2::Ex::History::Menu->new_popup (history => $history, |
105
|
|
|
|
|
|
|
way => $self->get('way'), |
106
|
|
|
|
|
|
|
event => $event); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
return shift->signal_chain_from_overridden(@_); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |