Commits

Anonymous committed 1f7f65b

Now handling the save file.

  • Participants
  • Parent commits 25e1877

Comments (0)

Files changed (1)

File 1st-version-as-scripts/edit-yaml-gui.pl

     return;
 }
 
+sub _serialize
+{
+    my $self = shift;
+
+    return
+    {
+        filename => $self->filename(),
+        tags => $self->tags(),
+        title => $self->title(),
+        description_parts => $self->description_parts(),
+    };
+}
+
 package Flickr::WxPerlUploader::App;
 
 use base 'Wx::App';
         (qw(
             _common_tags
             _photo_files
+            _was_data_changed
         )),
         )
     }
     ;
 
-use YAML::XS qw(LoadFile);
+use YAML::XS qw(LoadFile DumpFile);
+
+my $filename = "upload-spec.yml";
 
 sub _read_photos {
     my $self = shift;
 
-    my $filename = "upload-spec.yml";
-
     my $yaml = LoadFile($filename);
 
     $self->_common_tags($yaml->{'common_tags'});
     return $self;
 }
 
+sub _save
+{
+    my $self = shift;
+
+    DumpFile($filename, 
+        {
+            common_tags => $self->_common_tags(),
+            files =>
+            [
+                map { $_->_serialize() } @{$self->_photo_files()},
+            ],
+        },
+    );
+
+    $self->_was_data_changed(0);
+
+    return;
+}
+
 sub OnInit
 {
     my( $self ) = @_;
 
     $self->_read_photos();
+    $self->_was_data_changed(0);
 
     my $frame = Wx::Frame->new( undef, -1, 'wxPerl', wxDefaultPosition, [ 200, 100 ] );
 
 
     my $file_menu = Wx::Menu->new;
     
-    my $exit_item = $file_menu->Append(Wx::wxID_NEW, Wx::gettext("E&xit"));
+    my $exit_item = $file_menu->Append(Wx::wxID_EXIT, Wx::gettext("E&xit"));
 
     Wx::Event::EVT_MENU(
         $frame,
         },
     );
 
+    my $save_item = $file_menu->Append(Wx::wxID_SAVE, Wx::gettext("&Save"));
+
+    Wx::Event::EVT_MENU(
+        $frame,
+        $save_item,
+        sub {
+            return $self->_save();
+        }
+    );
+
     $menu_bar->Append($file_menu, "&File");
 
     $frame->SetMenuBar($menu_bar);
             my $list = shift;
             my $event = shift;
 
-            if (defined($self->{_prev_image}))
-            {
-                $self->_photo_files->[$self->{_prev_image}]->title(
-                    $title_box->GetValue()
-                );
-            }
-
             my $idx = $event->GetSelection();
 
             $self->{_prev_image} = $idx;
             return;
         },
     );
+
+    Wx::Event::EVT_TEXT( $self, $title_box,
+        sub {
+
+            if (defined($self->{_prev_image}))
+            {
+                $self->_photo_files->[$self->{_prev_image}]->title(
+                    $title_box->GetValue()
+                );
+            }
+
+            $self->_was_data_changed(1);
+        },
+    );
 =begin Hello
 
     EVT_LISTBOX_DCLICK($frame->{list}, wxID_ANY(), sub {