diff --git a/scripts/start.pl b/scripts/start.pl index 7ceacac..9669239 100644 --- a/scripts/start.pl +++ b/scripts/start.pl @@ -44,7 +44,7 @@ sub activate { $app->add_action($save_as); my @saves; my $extra; - my $save_menu_item = Glib::IO::MenuItem->new( 'Save as', 'app.save_as' ); + my $save_menu_item = Glib::IO::MenuItem->new( 'Save as', 'app.save_as' ); $open->signal_connect( activate => sub { activate_open( $win, \@saves, \$extra, $save_as ); @@ -57,10 +57,10 @@ sub activate { ); $about->signal_connect( activate => \&activate_about, ); - my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' ); - my $open_menu_item = Glib::IO::MenuItem->new( 'Open', 'app.open' ); - my $submenu_file = Glib::IO::Menu->new; - my $submenu_help = Glib::IO::Menu->new; + my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' ); + my $open_menu_item = Glib::IO::MenuItem->new( 'Open', 'app.open' ); + my $submenu_file = Glib::IO::Menu->new; + my $submenu_help = Glib::IO::Menu->new; $submenu_help->append_item($about_menu_item); $submenu_file->append_item($open_menu_item); $submenu_file->append_item($save_menu_item); @@ -80,12 +80,12 @@ sub activate { } sub activate_open { - my $win = shift; - my $saves = shift; - my $extra = shift; + my $win = shift; + my $saves = shift; + my $extra = shift; my $save_as = shift; - my $dialog = Gtk4::FileDialog->new; - my $curdir = Glib::IO::File::new_for_path('.'); + my $dialog = Gtk4::FileDialog->new; + my $curdir = Glib::IO::File::new_for_path('.'); $dialog->set_initial_folder($curdir); $dialog->open( $win, undef, @@ -125,10 +125,10 @@ sub save { } sub start_editing_file { - my $win = shift; - my $file = shift; - my $saves = shift; - my $extra = shift; + my $win = shift; + my $file = shift; + my $saves = shift; + my $extra = shift; my $save_as = shift; my (@saves_raw); ( @saves_raw[ 0, 1 ], ${$extra} ) = read_save($file); @@ -136,42 +136,69 @@ sub start_editing_file { my $current_save_index = find_current_save_index(@$saves); my $save = $saves->[$current_save_index]; my %flags = @Rsaves::Constants::Emerald::Flags::FLAGS; - my $box_flags = Gtk4::Box->new( 'vertical', 0 ); + my $box_app = Gtk4::Box->new( 'vertical', 0 ); my $superdata = get_first_super_data($save); - for my $rematch_id ( - sort { $a <=> $b } - grep { $_ =~ /^\d+$/ } keys %rematches - ) - { - my $toggle = - Gtk4::ToggleButton->new_with_label( $rematches{$rematch_id} ); - $toggle->set_active( check_rematch( $save, $superdata, $rematch_id ) ); - $toggle->signal_connect( - toggled => sub { - my $active = $toggle->get_active; - Rsaves::set_rematch( $save, $superdata, $rematch_id, $active ); - Rsaves::set_first_super_data( $save, $superdata ); - } - ); - $box_flags->append($toggle); - } - for my $flag_id ( sort { $a <=> $b } grep { $_ =~ /^\d+$/ } keys %flags ) { - my $toggle = Gtk4::ToggleButton->new_with_label( $flags{$flag_id} ); - $toggle->set_active( check_flag_id( $save, $superdata, $flag_id ) ); - $toggle->signal_connect( - toggled => sub { - my $active = $toggle->get_active; - Rsaves::set_flag_id( $save, $superdata, $flag_id, $active ); - Rsaves::set_first_super_data( $save, $superdata ); - } - ); - - $box_flags->append($toggle); - } + my $search = Gtk4::SearchBar->new; + my $entry = Gtk4::Entry->new; + $search->set_child($entry); + $search->set_search_mode(1); + $box_app->append($search); + $box_app->set_property( 'vexpand', 1 ); my $scroll = Gtk4::ScrolledWindow->new; - $scroll->set_child($box_flags); - $win->set_child($scroll); + $scroll->set_property( 'vexpand', 1 ); + + my $populate_func = sub { + my $box_flags = Gtk4::Box->new( 'vertical', 0 ); + for my $rematch_id ( + sort { $a <=> $b } + grep { $_ =~ /^\d+$/ } keys %rematches + ) + { + my $buffer = $entry->get_buffer; + my $search_text = uc( $buffer->get_text ); + my $text = $rematches{$rematch_id}; + next unless index( $text, $search_text ) >= 0; + my $toggle = Gtk4::ToggleButton->new_with_label($text); + $toggle->set_active( + check_rematch( $save, $superdata, $rematch_id ) ); + $toggle->signal_connect( + toggled => sub { + my $active = $toggle->get_active; + Rsaves::set_rematch( $save, $superdata, $rematch_id, + $active ); + Rsaves::set_first_super_data( $save, $superdata ); + } + ); + $box_flags->append($toggle); + } + for + my $flag_id ( sort { $a <=> $b } grep { $_ =~ /^\d+$/ } keys %flags ) + { + my $buffer = $entry->get_buffer; + my $search_text = uc( $buffer->get_text ); + my $text = $flags{$flag_id}; + next unless index( $text, $search_text ) >= 0; + my $toggle = Gtk4::ToggleButton->new_with_label($text); + $toggle->set_active( check_flag_id( $save, $superdata, $flag_id ) ); + $toggle->signal_connect( + toggled => sub { + my $active = $toggle->get_active; + Rsaves::set_flag_id( $save, $superdata, $flag_id, $active ); + Rsaves::set_first_super_data( $save, $superdata ); + } + ); + + $box_flags->append($toggle); + } + $scroll->set_child($box_flags); + }; + $populate_func->(); + $entry->signal_connect( activate => sub { + $populate_func->(); + }); + $box_app->append($scroll); + $win->set_child($box_app); $save_as->set_enabled(1); } @@ -179,15 +206,16 @@ sub start_editing_file { sub activate_about { my $about = Gtk4::AboutDialog->new; $about->set_program_name('GEmeTool'); - $about->set_copyright( "© Sergio Iglesias (2024)"); + $about->set_copyright("© Sergio Iglesias (2024)"); $about->set_license_type('gpl-3-0'); - $about->add_credit_section('Ideas:', ['SpectreSpecs']); - $about->set_authors(['Sergio Iglesias']); + $about->add_credit_section( 'Ideas:', ['SpectreSpecs'] ); + $about->set_authors( ['Sergio Iglesias'] ); $about->set_website('https://git.owlcode.tech/sergiotarxz/GEmeTool'); $about->set_website_label('https://git.owlcode.tech/sergiotarxz/GEmeTool'); -# my $header_bar = Gtk4::HeaderBar->new; -# $header_bar->set_property( -# 'title-widget' => Gtk4::Label->new('About GEmeTool') ); -# $about->set_titlebar($header_bar); + + # my $header_bar = Gtk4::HeaderBar->new; + # $header_bar->set_property( + # 'title-widget' => Gtk4::Label->new('About GEmeTool') ); + # $about->set_titlebar($header_bar); $about->present; }