Xacobeo

 view release on metacpan or  search on metacpan

examples/Xacobeo/Ex/ClipboardLoad.pm  view on Meta::CPAN

package Xacobeo::Ex::ClipboardLoad;

=head1 NAME

Xacobeo::Ex::ClipboardLoad - Test plugin

=head1 DESCRIPTION

Sample plugin that allows to load an XML document based on the contents of the
clipboard.

The plugin adds the entry I<Load from clipboard> under the I<File> main menu.
The plugin can also be activated through the shortcut I<CTRL SHIFT L>.

=head1 USAGE

Copy the file examples/cliboard.plugin into $HOME/.config/xacobeo/plugins/ and
add examples/Xacobeo into your PERL5LIB path.

Or copy examples/Xacobeo/Ex/ClipboardLoad.pm somewhere and add the full path
to the variable I<Script> in the file F<cliboard.plugin>. For instance if you
copy the perl module to F<$HOME/.config/xacobeo/plugins/ and that your user name

examples/Xacobeo/Ex/ClipboardLoad.pm  view on Meta::CPAN

	$window->statusbar->display("Plugin Loaded!");

	# Build an action group, this is where we define the name, shortcut, icon and
	# the callback for our actions.
	my $actions = Gtk2::ActionGroup->new("XacobeoTestPluginActions");
	$actions->add_actions([
		# Entries (name, stock id, label, accelerator, tooltip, callback)
		[
			'FileNewFromClipboard',
			'gtk-paste',
			"_Load from clipboard",
			'<control><shift>L',
			"Load a file from the clipboard",
			sub { $self->load_from_clipboard(@_, $window) }
		],
	]);

	
	# Inject our new actions into the existing application
	my $ui_manager = $window->ui_manager;
	$ui_manager->insert_action_group($actions, 0);
	$ui_manager->add_ui(
		$ui_manager->new_merge_id,
		'/MenuBar/FileMenu/FilePlaceholder_1',
		'FileNewFromClipboard',
		'FileNewFromClipboard',
		'menuitem',
		FALSE
	);
}


sub load_from_clipboard {
	my $self = shift;
	my ($action, $window) = @_;

	# Prepare the system clipboard
	my $selection = Gtk2::Gdk::Atom->new('CLIPBOARD');
	my $clipboard = Gtk2::Clipboard->get($selection);
	
	# Get the xml from clipboard
	my $xml = $clipboard->wait_for_text;
	return unless defined $xml;
	
	# Load the temporary xml file
	my $document = Xacobeo::Document->new_from_string($xml, 'xml');
	$window->set_title('clipboard');
	$window->load_document($document);
}


__PACKAGE__->load();


=head1 AUTHORS

Emmanuel Rodriguez E<lt>potyl@cpan.orgE<gt>.

examples/cliboard.plugin  view on Meta::CPAN

[Xacobeo Plugin]
Name=Clipboard Load
Package=Xacobeo::Ex::ClipboardLoad
Description=Loads a new XML document from the contents of the clipboard
Icon=gtk-paste
Authors=Emmanuel Rodriguez <potyl@cpan.org>
Copyright=Copyright © 2009 Emmanuel Rodriguez
Website=http://search.cpan.org/perldoc?Xacobeo

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

}


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);
}



( run in 0.931 second using v1.01-cache-2.11-cpan-84e82930d8c )