URI:
       tAdd "View (no view increase)" button - flashcards - Stupid LaTeX flashcard viewer
  HTML git clone git://lumidify.org/flashcards.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit 06cb6bb4bc4937f472ecf4ae0702b464c92b6588
   DIR parent 4eceb1ac312221c71a1d56c087913f1b4aa20025
  HTML Author: lumidify <nobody@lumidify.org>
       Date:   Thu,  9 Apr 2020 09:24:41 +0200
       
       Add "View (no view increase)" button
       
       Diffstat:
         M README                              |      17 +++++++++++++----
         M config.json                         |       2 +-
         M viewer2.pl                          |      39 +++++++++++++++++++------------
       
       3 files changed, 38 insertions(+), 20 deletions(-)
       ---
   DIR diff --git a/README b/README
       t@@ -23,7 +23,16 @@ view the later one. In this case, the chain will still always be shown
        in order, but the view counts for the flashcards in the chain won't
        be the same.
        
       -The actual program only has two buttons, "Next card" and "Reveal card",
       -which should be obvious. The number of times the card was viewed is
       -saved in `config.json` and a random card from the cards that have been
       -viewed the least is displayed each time.
       +The actual program only has four buttons:
       +
       +- "Next card" goes to the next card and increases the view count of the
       +  currently viewed card (but only if the back was revealed).
       +- "Next (no view increase)" does the same but never increases the view count.
       +- "Reveal back" reveals the back of the card.
       +- "Reload images" reloads the images from the cache (useful when editing
       +  the LaTeX files since you can regenerate the cache and then just
       +  reload images).
       +
       +The number of times the card was viewed is saved in `config.json`.
       +The "next" buttons choose a random card from the cards that have been
       +viewed the least each time.
   DIR diff --git a/config.json b/config.json
       t@@ -1 +1 @@
       -{"cards":{"02":4,"03":5,"05":4,"04":10,"01":10,"06":4}}
       +{"cards":{"01":0,"04":0,"02":1,"03":0,"06":0,"05":1}}
   DIR diff --git a/viewer2.pl b/viewer2.pl
       t@@ -143,11 +143,8 @@ sub gui {
                my $view_count;
                my $card_id;
        
       -        # so you can press "Reveal card" multiple times without increasing the view count again 
       -        my $view_count_increased = 0;
                my $vbox = Gtk2::VBox->new(FALSE, 5);
                my $hbox = Gtk2::HBox->new(FALSE, 5);
       -        my $button = Gtk2::Button->new_with_mnemonic("_Next card");
        
                my $image_front1 = Gtk2::Image->new();
                my $image_front2 = Gtk2::Image->new();
       t@@ -158,32 +155,44 @@ sub gui {
                        return FALSE;
                }, $window);
        
       -        $button->signal_connect(clicked => sub {
       -                $view_count_increased = 0;
       -                ($view_count, $card_id) = next_card $config, $cards, $cards_backreference, $image_front1, $image_front2, $window_w, $window, $card_id;
       -                $image_back->clear();
       -        }, $window);
       -        $hbox->pack_start($button, FALSE, FALSE, 0);
       +        my $revealed = 0;
                my $label = Gtk2::Label->new("");
       -        $button = Gtk2::Button->new_with_mnemonic("Reveal _back");
       +        my $button = Gtk2::Button->new_with_mnemonic("_Next card");
                $button->signal_connect(clicked => sub {
       -                if (!$view_count_increased) {
       -                        load_image_back $image_back, $window_w, $image_back_h, $card_id;
       -                        $view_count_increased = 1;
       +                if ($revealed) {
                                $config->{cards}->{$card_id}++;
                                $cards->{$view_count+1}->{$card_id} = $cards->{$view_count}->{$card_id};
                                delete $cards->{$view_count}->{$card_id};
                                if (!%{$cards->{$view_count}}) {
                                        delete $cards->{$view_count};
                                }
       -                        $label->set_text("View count: " . ($view_count + 1));
       +                }
       +                $revealed = 0;
       +                ($view_count, $card_id) = next_card $config, $cards, $cards_backreference, $image_front1, $image_front2, $window_w, $window, $card_id;
       +                $label->set_text("View count: " . $view_count);
       +                $image_back->clear();
       +        }, $window);
       +        $hbox->pack_start($button, FALSE, FALSE, 0);
       +        $button = Gtk2::Button->new_with_mnemonic("Next (no _view increase)");
       +        $button->signal_connect(clicked => sub {
       +                $revealed = 0;
       +                ($view_count, $card_id) = next_card $config, $cards, $cards_backreference, $image_front1, $image_front2, $window_w, $window, $card_id;
       +                $label->set_text("View count: " . $view_count);
       +                $image_back->clear();
       +        }, $window);
       +        $hbox->pack_start($button, FALSE, FALSE, 0);
       +        $button = Gtk2::Button->new_with_mnemonic("Reveal _back");
       +        $button->signal_connect(clicked => sub {
       +                if (!$revealed) {
       +                        load_image_back $image_back, $window_w, $image_back_h, $card_id;
       +                        $revealed = 1;
                        }
                }, $window);
                $hbox->pack_start($button, FALSE, FALSE, 0);
                $button = Gtk2::Button->new_with_mnemonic("_Reload images");
                $button->signal_connect(clicked => sub {
                        load_images_front $image_front1, $image_front2, $window_w, $card_id;
       -                if ($view_count_increased) {
       +                if ($revealed) {
                                load_image_back $image_back, $window_w, $image_back_h, $card_id;
                        }
                }, $window);