« blib/lib/Applications/BackupAndRestore/Helper.pm
↑ Summary
blib/lib/Applications/FileQuickFind.pm »
| 1 | package Gtk2::Ex::FileLocator::FileChooser; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | our $VERSION = 0.01; | ||
| 6 | our $DEBUG = 1; | ||
| 7 | |||
| 8 | use Gtk2; | ||
| 9 | use Glib qw(TRUE FALSE); | ||
| 10 | |||
| 11 | use Glib::Object::Subclass Gtk2::HBox::, | ||
| 12 | properties => [ | ||
| 13 | Glib::ParamSpec->object( | ||
| 14 | 'chooser', 'chooser', | ||
| 15 | 'The file chooser dialog to use.', 'Gtk2::FileChooserDialog', | ||
| 16 | [qw/readable writable/] | ||
| 17 | ), | ||
| 18 | ], | ||
| 19 | signals => { | ||
| 20 | current_folder_changed => {}, | ||
| 21 | selection_changed => {}, | ||
| 22 | file_activated => {}, | ||
| 23 | }, | ||
| 24 | ; | ||
| 25 | |||
| 26 | sub INIT_INSTANCE { | ||
| 27 | my $this = shift; | ||
| 28 | |||
| 29 | $this->{path} = ""; | ||
| 30 | |||
| 31 | $this->set_border_width(0); | ||
| 32 | |||
| 33 | $this->set( 'chooser', new Gtk2::FileChooserDialog( '', undef, 'open' ) ); | ||
| 34 | $this->get('chooser')->set_local_only(FALSE); | ||
| 35 | |||
| 36 | $this->get('chooser') | ||
| 37 | ->signal_connect( 'delete-event', \&on_delete_event, $this ); | ||
| 38 | |||
| 39 | $this->get('chooser') | ||
| 40 | ->signal_connect( 'current_folder_changed', | ||
| 41 | sub { $this->signal_emit('current_folder_changed') } ); | ||
| 42 | $this->get('chooser') | ||
| 43 | ->signal_connect( 'selection_changed', | ||
| 44 | sub { $this->signal_emit('selection_changed') } ); | ||
| 45 | $this->get('chooser') | ||
| 46 | ->signal_connect( 'file_activated', | ||
| 47 | sub { $this->signal_emit('file_activated') } ); | ||
| 48 | } | ||
| 49 | |||
| 50 | sub on_delete_event { | ||
| 51 | my ( $widget, $event, $this ) = @_; | ||
| 52 | $widget->hide; | ||
| 53 | return 1; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub get_current_folder { | ||
| 57 | my ($this) = @_; | ||
| 58 | $this->get('chooser')->get_current_folder; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub set_current_folder { | ||
| 62 | my ( $this, $folder ) = @_; | ||
| 63 | $this->get('chooser')->set_current_folder( $folder || "" ); | ||
| 64 | } | ||
| 65 | |||
| 66 | sub get_filename { | ||
| 67 | my ($this) = @_; | ||
| 68 | my $uri = $this->get('chooser')->get_uri || ""; | ||
| 69 | $uri =~ s|^.+?\://||o if $uri; | ||
| 70 | return $uri; | ||
| 71 | } | ||
| 72 | |||
| 73 | sub set_filename { | ||
| 74 | my ( $this, $filename ) = @_; | ||
| 75 | |||
| 76 | return unless $filename; | ||
| 77 | return if ( $this->get('chooser')->get_filename || "" ) eq $filename; | ||
| 78 | |||
| 79 | #$this->Debug($filename); | ||
| 80 | $this->get('chooser')->set_filename( $this->{path} ); | ||
| 81 | |||
| 82 | return; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub get_uri { | ||
| 86 | my ($this) = @_; | ||
| 87 | $this->get('chooser')->get_uri; | ||
| 88 | } | ||
| 89 | |||
| 90 | sub set_uri { | ||
| 91 | my ( $this, $uri ) = @_; | ||
| 92 | |||
| 93 | return unless $uri; | ||
| 94 | return if ( $this->get('chooser')->get_uri || "" ) eq $uri; | ||
| 95 | |||
| 96 | $this->Debug($this, $uri); | ||
| 97 | $this->get('chooser')->set_uri($uri); | ||
| 98 | |||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub Debug { | ||
| 103 | my ( $this, @values ) = @_; | ||
| 104 | return unless $DEBUG; | ||
| 105 | printf "# %s %s\n", &caller_subroutine, @values | ||
| 106 | ? join " ", map { defined $_ ? $_ : "" } @values | ||
| 107 | : ""; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub caller_subroutine { ( caller(2) )[3] || "" } | ||
| 111 | 1; | ||
| 112 | __END__ |