Xacobeo

 view release on metacpan or  search on metacpan

lib/Xacobeo/UI/DomView.pm  view on Meta::CPAN

			undef,
			__("Show the node"),
			sub { $self->do_select_node() }
		],
		[
			'DomViewCopyXPath',
			'gtk-copy',
			__("_Copy XPath"),
			undef,
			__("Copy the node's XPath"),
			sub { $self->do_copy_xpath() }
		],
	];

	my $actions = Gtk2::ActionGroup->new("DomViewActions");
	$self->action_group($actions);
	$actions->add_actions($entries, undef);
	$actions->set_sensitive(FALSE);

	my $ui_manager = Gtk2::UIManager->new();
	$self->ui_manager($ui_manager);

	my $ui_string = <<'__XML__';
<ui>
	<popup name="DomViewPopup">
		<menuitem action='DomViewSelectNode'/>
		<placeholder name="DomViewPlaceholder_1"/>
		<separator/>
		<menuitem action='DomViewCopyXPath'/>
		<placeholder name="DomViewPlaceholder_2"/>
	</popup>
</ui>
__XML__
	$ui_manager->add_ui_from_string($ui_string);

	$ui_manager->insert_action_group($actions, 0);
	return $ui_manager;
}


#
# Transform the signal 'row-activated' into 'node-selected'.
#
sub callback_row_activated {
	my ($self, $path) = @_;

	my $model = $self->get_model;
	my $iter = $model->get_iter($path);
	my $node = $model->get($iter, $NODE_DATA);
	$self->signal_emit('node-selected' => $node);
}


sub do_copy_xpath {
	my $self = shift;

	my $node = $self->get_selected_node or return;
	my $xpath = Xacobeo::XS->get_node_path($node, $self->namespaces);

	foreach my $selection (qw(SELECTION_CLIPBOARD SELECTION_PRIMARY)) {
		my $clipboard = Gtk2::Clipboard->get(Gtk2::Gdk->$selection);
		$clipboard->set_text($xpath);
	}
}


sub do_select_node {
	my $self = shift;

	my $node = $self->get_selected_node or return;
	$self->signal_emit('node-selected' => $node);
}


sub get_selected_node {
	my $self = shift;
	# Get the selected node and find its xpath
	my $selection = $self->get_selection;
	my ($model, $iter) = $selection->get_selected or return;
	my $node = $model->get($iter, $NODE_DATA);
	return $node;
}


#
# Display a context menu for a given node when right clicking.
#
sub callback_button_press_event {
	my ($self, $event) = @_;

	return FALSE unless $event->button == 3;

	my $path = $self->get_path_at_pos($event->x, $event->y) or return FALSE;

	my $selection = $self->get_selection;
	$selection->unselect_all();
	$selection->select_path($path);

	$self->action_group->set_sensitive(TRUE);

	$self->menu->popup(undef, undef, undef, undef, $event->button, $event->time);

	return TRUE;
}


#
# Display a context menu for a given node when right clicking.
#
sub callback_popup_menu {
	my ($self) = @_;
	$self->menu->popup(undef, undef, undef, undef, 0, 0);
	return TRUE;
}


sub set_document {
	my $self = shift;
	my ($document) = @_;

	$self->document($document);
	$self->namespaces(



( run in 1.418 second using v1.01-cache-2.11-cpan-f03e8824b8d )