Index: extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm
===================================================================
--- extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm	(revision 5261)
+++ extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm	(revision 5390)
@@ -101,9 +101,9 @@
           categories
           imagelist
-          image_preview
+          image_preview_dlg
           image_prop_piwigo
-          image_prop_exif
+          exif_dlg
           image_prop_tags
-          global_settings_panel
+          global_settings_dlg
           piwigo_property_list
           exif_properties
@@ -119,10 +119,13 @@
           image_tags
           piwigo_photo_properties
-          dlg_piwigo_photo_properties
+          piwigo_photo_properties_dlg
           piwigo_photo_properties_tags
-          image_preview_refresh
+          image_preview_need_refresh
           imageviewer_refresh
           imageviewer_item_refresh
           horizontal_splitter
+          destination_category_dlg
+          destination_categories
+          categories_treectrl
       /;
 __PACKAGE__->mk_accessors( @properties );
@@ -137,4 +140,6 @@
 use Uploader::GUI::wxImageProcessingProgressDlg;
 use Uploader::GUI::wxChoiceFilteredPanel;
+use Uploader::GUI::wxDestinationCategoryDlg;
+use Uploader::GUI::wxCategoryTreeCtrl;
 use utf8;
 $|=1;
@@ -146,4 +151,5 @@
 sub new {
     my( $class, $params ) = @_;
+
     my $self  = $class->SUPER::new( 
         undef, 
@@ -158,4 +164,37 @@
     $self->pwg( $params->{pwg} );
     $self->imagelist( $params->{imagelist} );
+
+
+    $self->imagelist->pwg(
+        $self->pwg
+    );
+
+    $self->imagelist->categories(
+        []
+    );
+
+
+    $self->init_gui_callbacks;
+    $self->init_properties_dlg_bindings;
+    $self->init_frame;
+    $self->init_menus;
+    $self->init_event_handlers;
+    $self->init_image_types;   
+
+    $self->imageviewer->SelectItem(
+        $self->current_imageviewer_index
+    ) if $self->imageviewer->GetItemCount;
+   
+    # if file in command line parameters, try to load
+    my $files = wxTheApp->argv;
+    $self->SetNewFiles($files) if scalar @$files;
+
+    $self->Show;
+    $self;
+}
+
+
+sub init_gui_callbacks {
+    my ( $self ) = @_;
 
     # callback for GUI refresh : add thumbnail images to the imageviewer control
@@ -249,54 +288,8 @@
         sub { $self->UploadDisplayEndInfo(@_) }
     );
-
-
-    $self->imagelist->pwg(
-        $self->pwg
-    );
-
-    $self->imagelist->categories(
-        []
-    );
-
-
-    $self->_set_setting_properties;
-    $self->_initFrame;
-    $self->_initMenus;
-    $self->_initEventHandlers;
-    $self->_initImgTypes;   
-
-    $self->imageviewer->SelectItem(
-        $self->current_imageviewer_index
-    ) if $self->imageviewer->GetItemCount;
-   
-    # if file in command line parameters, try to load
-    my $files = wxTheApp->argv;
-    $self->SetNewFiles($files) if scalar @$files;
-
-    $self->Show;
-    $self;
-}
-
-
-sub _initImgTypes {
-    my ( $self ) = @_;
-
-    $self->{IMGTYPE} = {
-        'jpg' => wxBITMAP_TYPE_JPEG,
-        'gif' => wxBITMAP_TYPE_GIF,
-        'png' => wxBITMAP_TYPE_PNG,
-    };
-}
-
-
-sub GetWxBitmapType {
-    my ( $self, $type ) = @_;
-    
-    $self->{IMGTYPE}->{$type};
-}
-
-
-
-sub _set_setting_properties {
+}
+
+
+sub init_properties_dlg_bindings {
     my ( $self ) = @_;
 
@@ -665,4 +658,94 @@
 }
 
+sub init_image_types {
+    my ( $self ) = @_;
+
+    $self->{IMGTYPE} = {
+        'jpg' => wxBITMAP_TYPE_JPEG,
+        'gif' => wxBITMAP_TYPE_GIF,
+        'png' => wxBITMAP_TYPE_PNG,
+    };
+}
+
+
+sub init_frame {
+    my ( $self ) = @_;
+    
+    $self->create_toolbar;
+
+    my $sizer_h = Wx::BoxSizer->new( wxHORIZONTAL );
+    
+
+
+    $self->imageviewer(
+        Uploader::GUI::wxImageListCtrl->new( 
+            { 
+                parentwnd => $self,
+                imagelist => $self->imagelist,
+                image_size => $self->imagelist->wx_thumb_size,
+                columns => $self->piwigo_property_list,
+            }
+        )
+    );
+
+
+    $self->piwigo_photo_properties_dlg (
+        Uploader::GUI::wxPhotoProperties->new(
+            {
+                parentwnd  => $self,
+                categories => [ @{$self->pwg->categories}],
+                properties => $self->piwigo_photo_properties,
+                tags       =>
+                {
+                    id => $main::PHOTO_PROPERTIES_TAG,
+                    choices => $self->piwigo_tags,
+                    selection => $self->image_tags,
+                    creation_callback => sub { $self->_create_piwigo_tag(@_) },
+               },
+            }
+        )
+    );
+
+    $self->piwigo_photo_properties_tags(
+        $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_TAG)
+    );
+
+    $self->tree(
+        $self->piwigo_photo_properties_dlg->FindWindow($main::PHOTO_PROPERTIES_CATEGORIES)
+    );
+
+    $self->init_dnd_targets;
+    $self->init_dialogs;
+    $self->show_hide_pwg_categories_empty_msg;
+
+    if( $self->imagelist->wx_thumb_imglist->GetImageCount){
+        $self->ShowImageViewer;
+        
+        $self->imageviewer->Refresh(
+            $self->imagelist->wx_thumb_imglist
+        );
+       
+        $self->OnUpdateImageviewerNotEmpty;
+    }
+    else{
+        $self->OnUpdateImageviewerEmpty;
+    }
+
+    # the imageviewer has a stretch factor of 1 : expands its size on frame resize
+    $sizer_h->Add( $self->imageviewer, 1, wxEXPAND|wxALL, 2 );
+    $sizer_h->Add( $self->piwigo_photo_properties_dlg, 0, wxEXPAND|wxALL, 2 );
+
+
+    $self->SetSizer(
+        $sizer_h
+    );
+    my $new_size = $sizer_h->Fit(
+        $self
+    );
+    $self->SetMinSize([600, 660]);
+    $self->Center;
+}
+
+
 sub _create_piwigo_tag {
     my ( $self, $name ) = @_;
@@ -684,108 +767,9 @@
 }
 
-sub _refreshFrame {
-    my ( $self ) = @_;
-    
-    eval { $self->_set_setting_properties; };
-    $self->_refresh_settings_panels_properties;
-    map {
-        $_->Refresh;
-    }
-    (
-        $self->image_prop_exif,
-        $self->global_settings_panel,
-        $self->piwigo_photo_properties_tags
-    );
-    
-}
-
-# 
-sub _initFrame {
-    my ( $self ) = @_;
-    
-    $self->create_toolbar;
-
-    my $sizer_h = Wx::BoxSizer->new( wxHORIZONTAL );
-    
-
-
-    $self->imageviewer(
-        Uploader::GUI::wxImageListCtrl->new( 
-            { 
-                parentwnd => $self,
-                imagelist => $self->imagelist,
-                image_size => $self->imagelist->wx_thumb_size,
-                columns => $self->piwigo_property_list,
-            }
-        )
-    );
-
-    # message displayed in the image listctrl when empty
-    $self->imageviewer->InitEmptyMsg;
-
-    $self->init_panels;
-
-    $self->dlg_piwigo_photo_properties (
-        Uploader::GUI::wxPhotoProperties->new(
-            {
-                parentwnd       => $self,
-                properties      => $self->piwigo_photo_properties,
-                tags            =>
-                {
-                    id => $main::PHOTO_PROPERTIES_TAG,
-                    choices => $self->piwigo_tags,
-                    selection => $self->image_tags,
-                    creation_callback => sub { $self->_create_piwigo_tag(@_) },
-               },
-            }
-        )
-    );
-
-    $self->piwigo_photo_properties_tags(
-        $self->dlg_piwigo_photo_properties->FindWindow($main::PHOTO_PROPERTIES_TAG)
-    );
-
-    $self->create_tree(
-        $self->dlg_piwigo_photo_properties->FindWindow($main::PHOTO_PROPERTIES_CATEGORIES)
-    );
-
-    $self->init_empty_category_msg;
-    $self->set_empty_tree_panel_evt_paint;
-    $self->show_pwg_categories_empty_msg;
-
-    $self->init_dnd_targets;
-
-    if( $self->imagelist->wx_thumb_imglist->GetImageCount){
-        $self->ShowImageViewer;
-        
-        $self->imageviewer->Refresh(
-            $self->imagelist->wx_thumb_imglist
-        );
-       
-        $self->OnUpdateImageviewerNotEmpty;
-    }
-    else{
-        $self->OnUpdateImageviewerEmpty;
-    }
-
-    # the imageviewer has a stretch factor of 1 : expands its size on frame resize
-    $sizer_h->Add( $self->imageviewer, 1, wxEXPAND|wxALL, 2 );
-    $sizer_h->Add( $self->dlg_piwigo_photo_properties, 0, wxEXPAND|wxALL, 2 );
-
-
-    $self->SetSizer(
-        $sizer_h
-    );
-    my $new_size = $sizer_h->Fit(
-        $self
-    );
-    $self->SetMinSize([600, 660]);
-    $self->Center;
-}
 
 sub OnUpdateImageviewerEmpty {
     my ( $self ) = @_;
 
-    $self->dlg_piwigo_photo_properties->{_properties_notebook}->Enable(0);
+    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(0);
     $self->imageviewer->OnEmpty;
 }
@@ -794,32 +778,14 @@
     my ( $self ) = @_;
 
-    $self->dlg_piwigo_photo_properties->{_properties_notebook}->Enable(1);
+    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(1);
     $self->imageviewer->OnNotEmpty;
 }
 
 
-sub _refresh_settings_panels_properties {
+sub init_dialogs {
     my ( $self ) = @_;    
 
-    $self->dlg_piwigo_photo_properties->properties(
-        $self->piwigo_photo_properties
-    );
-
-    
-    $self->image_prop_exif->properties(
-        $self->exif_properties
-    );
-
-    $self->global_settings_panel->properties(
-        $self->global_settings
-    );    
-
-}
-
-sub _init_settings_panels {
-    my ( $self ) = @_;    
-
-
-    $self->image_prop_exif(
+
+    $self->exif_dlg(
         Uploader::GUI::wxPropertyListDlg->new( 
             { 
@@ -830,7 +796,7 @@
         )
     );
-    $self->image_prop_exif->Hide;
-
-    $self->global_settings_panel(
+    $self->exif_dlg->Hide;
+
+    $self->global_settings_dlg(
         Uploader::GUI::wxGlobalSettings->new( 
             { 
@@ -841,9 +807,7 @@
         )
     );
-    $self->global_settings_panel->Hide;
-
-
-
-    $self->image_preview(
+    $self->global_settings_dlg->Hide;
+
+    $self->image_preview_dlg(
         Uploader::GUI::wxImagePreview->new(
             { 
@@ -854,13 +818,41 @@
     );
 
-}
-
-sub init_panels {
-    my ( $self ) = @_;
-    
-    $self->_init_settings_panels;    
-}
-
-# HTML code for getting started dialog box
+    $self->destination_category_dlg(
+        Uploader::GUI::wxDestinationCategoryDlg->new(
+            { 
+                parentwnd    => $self,
+                caption      => gettext("Upload to Piwigo"),
+                categories   => [@{$self->pwg->categories}],
+                properties   => {
+                                    $main::CHOOSE_DESTINATION => { label => wxTheApp->branding->{'What is the destination category?'} },
+                                    $main::DESTINATION_CATEGORIES_OK => { label=>gettext("Upload to Piwigo")},
+                                    $main::DESTINATION_CATEGORIES_CANCEL => { label=>gettext("Cancel")},
+                                    $main::DESTINATION_CATEGORIES => {
+                                        id_selection => sub { $self->imagelist->categories(@_) },
+                                        frame_callback => sub {
+                                            my ( $dlg, $ctrl, $evt ) = @_;
+                                            $dlg->FindWindow($main::DESTINATION_CATEGORIES_OK)->Enable(scalar @{$self->imagelist->categories});
+                                        },
+                                    },
+                                },
+                frame_callback => sub { $self->OnRefreshCategories },
+            }
+        )
+    );
+
+    $self->destination_category_dlg->Hide;
+
+    $self->destination_categories(
+        $self->destination_category_dlg->FindWindow($main::DESTINATION_CATEGORIES)
+    );
+
+    $self->categories_treectrl(
+        [
+            $self->destination_categories,
+            $self->tree,
+        ]
+    );
+
+}
 
 
@@ -883,18 +875,15 @@
 
 
-
 sub OnPhotoProperties {
     my ( $self ) = @_;
 
-    $self->image_prop_exif->Show(1);
-}
+    $self->exif_dlg->Show(1);
+}
+
 
 sub OnPreview {
     my ( $self ) = @_;
 
-    $self->image_preview->Show(1);
-
-
-
+    $self->image_preview_dlg->Show(1);
 }
 
@@ -903,5 +892,5 @@
     my ( $self ) = @_;
 
-    $self->global_settings_panel->Show(1);
+    $self->global_settings_dlg->Show(1);
 }
 
@@ -913,9 +902,11 @@
 }
 
+
 sub OnGeneralSettingsClose {
     my ( $self, $event ) = @_;
 
-    $self->global_settings_panel->Hide;
-}
+    $self->global_settings_dlg->Hide;
+}
+
 
 sub OnImageExifPropClose {
@@ -925,190 +916,20 @@
 }
 
-sub create_tree {
-    my ( $self, $tree ) = @_;
-
-    my $images = [
-        map {
-            Wx::Bitmap->new( $_, wxBITMAP_TYPE_PNG )
-            
-        }
-        (
-          wxTheApp->resource_path('tree_pwg.png'),
-          wxTheApp->resource_path('tree_folder.png'),
-        )    
-    ];
-
-    $self->treeimglist( Wx::ImageList->new( 16, 16, 1 ) );
+
+
+
+sub show_hide_pwg_categories_empty_msg {
+    my ( $self ) = @_;
+
     map {
-        $self->treeimglist->Add($_);
-    }
-    @$images;
-   
-    $self->tree( 
-        $tree || Wx::TreeCtrl->new( 
-           $self->horizontal_splitter, 
-           -1, 
-           wxDefaultPosition, 
-           wxDefaultSize, 
-           wxCLIP_CHILDREN|
-           wxTR_HAS_BUTTONS|
-           wxTR_EDIT_LABELS 
-        ) 
-    );
-
-    $self->tree->SetImageList( $self->treeimglist );
-    if(wxTheApp->use_offline){
-        $self->tree->Enable(0);
-    }
-    else{
-        $self->populate_tree_categories ;
-    }
-
-    $self->tree ;
-}
-
-
-sub set_empty_tree_panel_evt_paint{
-    my ( $self ) = @_;
-    Wx::Event::EVT_PAINT( $self->tree, sub {
-            my ( $tree, $event ) = @_;
-            if(exists $tree->{_empty_panel} and ! exists $tree->{_empty_panel}{_paint}){
-                my ($w, $h) = $tree->GetSizeWH;
-                my ($x, $y) = $tree->{_empty_panel}->GetPositionXY;
-
-                $tree->{_empty_panel}{x} = $x if !exists $tree->{_empty_panel}{x} ;
-                $tree->{_empty_panel}{y} = $y if !exists $tree->{_empty_panel}{y};
-                my ($wp, $hp) = $tree->{_empty_panel}->GetSizeWH;
-                my $x_off = ($w-$wp)/2 > 0 ? ($w-$wp)/2 : 0;
-                my $y_off = ($h-$hp)/2 > 0 ? ($h-$hp)/2 : 0;
-                $tree->{_empty_panel}->Move(
-                    [
-                        $tree->{_empty_panel}{x}+$x_off,
-                        $tree->{_empty_panel}{y}+$y_off
-                    ]
-                );
-                $tree->{_empty_panel}{_paint} = 1;
-            }
-            $event->Skip;
-        }
-    ) if 1;
-
-}
-
-
-sub init_empty_category_msg {
-
-    my ( $self ) = @_;
-    # add a panel
-    my $empty_panel = Wx::Panel->new($self->tree, -1, wxDefaultPosition, wxDefaultSize);
-    my( $item0 ) = Wx::BoxSizer->new( wxVERTICAL );
-    
-    my $fb = Wx::Font->new( 12, wxSWISS, wxNORMAL, wxBOLD );
-
-
-    my( $item1 ) = Wx::Button->new(
-        $empty_panel,
-        $main::CATEGORIES_ADD,
-        wxTheApp->branding->{'Add new category'},
-        wxDefaultPosition,
-        [-1,40],
-        0
-    );
-    my $btfont = Wx::Font->new(12, wxSWISS, wxNORMAL, wxNORMAL );
-    $item1->SetFont($btfont);
-    $item0->AddWindow( $item1, 0, wxALIGN_CENTER|wxALL, 5 );
-
-
-    $empty_panel->SetSizer( $item0 );
-    $item0->SetSizeHints( $empty_panel );
-
-    $self->tree->{_empty_panel} = $empty_panel;
-    $self->tree->{_empty_panel}->SetBackgroundColour(wxWHITE);
-
-    my ($wp, $hp) = $self->tree->{_empty_panel}->GetSizeWH;
-
-    $self->tree->SetMinSize( [20+$wp, -1 ]);
-
-}
-
-
-sub pwg_categories_are_empty {
-    my ( $self ) = @_;
-
-    scalar @{wxTheApp->pwg->categories} < 1 ? 1 : 0 ;
-}
-
-
-sub populate_tree_categories {
-    my ( $self ) = @_;
-
-    $self->populate_tree(
-        $self->tree,
-        wxTheApp->pwg->categories,
-    ) if defined wxTheApp->pwg ;
-}
-
-
-sub show_pwg_categories_empty_msg {
-    my ( $self ) = @_;
-
-    if($self->pwg_categories_are_empty){
-        $self->tree->{_empty_panel}->Show(1);
-    }
-    else{
-        $self->tree->{_empty_panel}->Show(0);
-    }
-}
-
-
-
-# returns a valid itemData
-sub itemData { Wx::TreeItemData->new( $_[0] ) }
-
-sub populate_tree {
-    my ( $self, $tree, $tree_items ) = @_;
-    my $root = shift @{$tree_items};
-
-    $self->tree_root(
-        $tree->AddRoot( 
-            $root->[0], 
-            $root->[3], 
-            $root->[4], 
-            itemData( $root->[2] ) 
-        )
-    );
-
-  $self->populate_tree_helper( $tree, $self->tree_root, $tree_items );
-  
-  $tree->SelectItem( $self->tree_root );
-  $tree->Expand( $self->tree_root );
-}
-
-sub populate_tree_helper {
-  my ( $self, $tree, $parent_id, $tree_items ) = @_;
-
-  my $id;
-
-  map {
-      my $name = $_->[0];
-
-      $id = $tree->AppendItem( 
-                                   $parent_id, 
-                                   $name,
-                                   defined($_->[3]) ? $_->[3] : 0, 
-                                   defined($_->[4]) ? $_->[4] : 0, 
-                                   itemData( $_->[2]) 
-                              );
-      $self->tree_item_default($id) if ! defined $self->tree_item_default;
-      # current item has children
-      if( ref( $_->[1] ) eq 'ARRAY' ) {
-          $self->populate_tree_helper( $tree, $id, $_->[1] );
-      } 
-  }
-  @{$tree_items};
-
-}
-
-sub _initMenus {
+        $_->GetCount > 1 ?
+            $_->HideEmptyMsg :
+            $_->ShowEmptyMsg;
+    }@{$self->categories_treectrl};
+
+}
+
+
+sub init_menus {
     my ( $self ) = @_ ;
 
@@ -1221,5 +1042,5 @@
 }
 
-sub _initEventHandlers {
+sub init_event_handlers {
     my ( $self ) = @_ ;
     
@@ -1243,5 +1064,5 @@
     Wx::Event::EVT_CLOSE( $self, \&OnClose );
 
-    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategories );
+    Wx::Event::EVT_MENU( $self, 1+$ID_TREE_CTX_MENU, \&OnAddCategory );
     Wx::Event::EVT_MENU( $self, 2+$ID_TREE_CTX_MENU, \&OnRefreshCategories );
     Wx::Event::EVT_MENU( $self, 3+$ID_TREE_CTX_MENU, \&OnExpandCategories );
@@ -1254,5 +1075,4 @@
     Wx::Event::EVT_BUTTON( $self, $self->imageviewer->add_button->GetId, \&OnAddImages );
 
-    Wx::Event::EVT_BUTTON( $self, $main::CATEGORIES_ADD, \&OnAddCategories );
 
     # only refresh when calling event is finished
@@ -1262,8 +1082,8 @@
             my ( $self, $event ) = @_;
 
-            if ( $self->image_preview_refresh and $self->image_preview->IsShown ){
+            if ( $self->image_preview_need_refresh and $self->image_preview_dlg->IsShown ){
                 $self->set_preview_image; 
-                $self->image_preview->Refresh;
-                $self->image_preview_refresh(0);
+                $self->image_preview_dlg->Refresh;
+                $self->image_preview_need_refresh(0);
             }
 
@@ -1283,6 +1103,6 @@
             }
 
-            if(!scalar @{$self->imageviewer->GetSelectedItems} and $self->dlg_piwigo_photo_properties->{_properties_notebook}->IsEnabled){
-                $self->dlg_piwigo_photo_properties->{_properties_notebook}->Enable(0);
+            if(!scalar @{$self->imageviewer->GetSelectedItems} and $self->piwigo_photo_properties_dlg->{_properties_notebook}->IsEnabled){
+                $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(0);
             }
 
@@ -1314,8 +1134,9 @@
 }
 
+
 sub OnUpdateToolbar {
     my( $self ) = @_;
     
-    if($self->global_settings_panel->IsShown){
+    if($self->global_settings_dlg->IsShown){
         $self->toolbar->EnableTool(104, 0);
     }
@@ -1324,5 +1145,5 @@
     }
 
-    if($self->global_settings_panel->IsShown){
+    if($self->global_settings_dlg->IsShown){
         $self->toolbar->EnableTool(104, 0);
     }
@@ -1342,9 +1163,9 @@
 
     if (!$self->imageviewer->GetItemCount){
-        $self->image_preview->image(
+        $self->image_preview_dlg->image(
             0
         ); 
         # have to reset
-        $self->dlg_piwigo_photo_properties->ClearProperties;
+        $self->piwigo_photo_properties_dlg->ClearProperties;
         $self->piwigo_photo_properties_tags->ClearAllSelection;
         $self->imagelist->SetCurrentImage(-1);
@@ -1359,6 +1180,6 @@
     }
 
-    $self->image_preview->Refresh;
-    $self->image_prop_exif->Refresh;
+    $self->image_preview_dlg->Refresh;
+    $self->exif_dlg->Refresh;
 }
 
@@ -1402,17 +1223,10 @@
 }
 
+
 sub OnTreeSelChanged {
     my( $self, $event ) = @_;
-  
-    my @items = $self->tree->GetSelections;
 
     $self->imagelist->categories(
-        [
-            map {
-                my $category = $self->tree->GetPlData( $_ );
-                $category->{id} if $category != -1;
-            }
-            @items
-        ]
+        $event->GetEventObject->GetSelectionsIds
     );
 }
@@ -1506,34 +1320,11 @@
 }
 
-sub OnAddCategories {
+sub OnAddCategory {
     my ( $self, $event ) = @_;
 
-    my $parent_item = $self->tree->GetSelection;
-
-    my $category = $self->tree->GetPlData($parent_item);
-    my $category_id;
-    
-    $category_id = $category->{id} if 'HASH' eq ref($category) ;
-
-    my $dialog = Wx::TextEntryDialog->new( 
-        $self, 
-        wxTheApp->branding->{'Category name'}, 
-        wxTheApp->branding->{'Add new category'},
-        wxTheApp->branding->{'New category'}, 
-    );
-
-    if( $dialog->ShowModal != wxID_CANCEL ) {
-        my $name = $dialog->GetValue;
-        my ( $success, $status_msg, $content ) = $self->pwg->AddCategories( $name, $category_id);
-
-        if($success){
-            $self->tree->{_empty_panel}->Show(0);
-            $self->_append_category($parent_item, $name, $content->{result}{id});
-        }
-    }
-
-
-    $dialog->Destroy;
-}
+    $self->tree->AddCategory;
+
+}
+
 
 sub OnRefreshCategories {
@@ -1545,28 +1336,17 @@
 
 sub _refresh_all_categories_helper {
-    my ( $self ) = @_;    
+    my ( $self ) = @_;
 
     my $busycursor = Wx::BusyCursor->new();
     $self->tree->CollapseAll;
     $self->tree->DeleteAllItems;
-    $self->imagelist->categories([]);
     $self->pwg->RefreshCategories();
-    $self->populate_tree_categories;
-    $self->show_pwg_categories_empty_msg;
-}
-
-sub _append_category {
-    my ( $self, $parent_id, $name, $id ) = @_;
-
-    $self->tree->SelectItem(
-        $self->tree->AppendItem(
-            $parent_id, 
-            $name, 
-            1, 
-            -1, 
-            Wx::TreeItemData->new( { id => $id } )
-        )
-    );
-}
+    $self->tree->categories(
+        $self->pwg->categories
+    );
+    $self->tree->Populate;
+    $self->show_hide_pwg_categories_empty_msg;
+}
+
 
 sub OnImageViewerEndLabelEdit {
@@ -1578,5 +1358,5 @@
     );
         
-    $self->dlg_piwigo_photo_properties->SetProperties;
+    $self->piwigo_photo_properties_dlg->SetProperties;
 }
 
@@ -1598,6 +1378,6 @@
     my $indx = $event->GetIndex;
 
-    $self->dlg_piwigo_photo_properties->{_properties_notebook}->Enable(1) 
-        if !$self->dlg_piwigo_photo_properties->{_properties_notebook}->IsEnabled;
+    $self->piwigo_photo_properties_dlg->{_properties_notebook}->Enable(1) 
+        if !$self->piwigo_photo_properties_dlg->{_properties_notebook}->IsEnabled;
     $self->_on_imageviewer_item_selected($indx);
 
@@ -1647,8 +1427,8 @@
     # and when current event is processed
     # see call to EVT_IDLE
-    $self->image_preview_refresh(1);
-
-    $self->dlg_piwigo_photo_properties->SetProperties if defined $self->dlg_piwigo_photo_properties;
-    $self->image_prop_exif->Refresh;
+    $self->image_preview_need_refresh(1);
+
+    $self->piwigo_photo_properties_dlg->SetProperties if defined $self->piwigo_photo_properties_dlg;
+    $self->exif_dlg->Refresh;
     $self->piwigo_photo_properties_tags->Refresh;
 
@@ -1665,14 +1445,14 @@
 
 
-    $self->dlg_piwigo_photo_properties->{_multi_selection_mode_panel}{_text1}->SetLabel(
+    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}{_text1}->SetLabel(
         sprintf(gettext("You have selected a batch of %s photos"), $self->imageviewer->GetSelectectItemsCount )
     );
 
-    $self->dlg_piwigo_photo_properties->{_multi_selection_mode_panel}{_text2}->SetLabel(
+    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}{_text2}->SetLabel(
         gettext("Changes apply to the whole batch")
     );
 
-    $self->dlg_piwigo_photo_properties->{_multi_selection_mode_panel}->Show(1);
-    $self->dlg_piwigo_photo_properties->Layout;
+    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}->Show(1);
+    $self->piwigo_photo_properties_dlg->Layout;
 }
 
@@ -1680,6 +1460,6 @@
     my( $self ) = @_;
 
-    $self->dlg_piwigo_photo_properties->{_multi_selection_mode_panel}->Show(0);
-    $self->dlg_piwigo_photo_properties->Layout;
+    $self->piwigo_photo_properties_dlg->{_multi_selection_mode_panel}->Show(0);
+    $self->piwigo_photo_properties_dlg->Layout;
 
 }
@@ -1708,9 +1488,9 @@
     }
 
-    $self->image_preview->image_size(
+    $self->image_preview_dlg->image_size(
         [$image->GetWidth, $image->GetHeight, ]
     );        
 
-    $self->image_preview->image(
+    $self->image_preview_dlg->image(
         $image
     );        
@@ -1751,5 +1531,5 @@
 
     if(!$self->imageviewer->GetItemCount){
-        $self->image_preview->image(0);
+        $self->image_preview_dlg->image(0);
         $self->OnUpdateImageviewerEmpty;
     }
@@ -1763,5 +1543,5 @@
     }
 
-    $self->image_preview->Refresh;
+    $self->image_preview_dlg->Refresh;
     Wx::Yield();
 }
@@ -1850,10 +1630,4 @@
         $self->imageviewer->Show(1);
     }
-}
-
-
-sub ActivateImageViewer {
-    my ( $self ) = @_;    
-    
 }
 
@@ -1883,4 +1657,10 @@
 
 
+sub GetWxBitmapType {
+    my ( $self, $type ) = @_;
+    
+    $self->{IMGTYPE}->{$type};
+}
+
 
 # prepare and upload image_selection
@@ -1891,15 +1671,7 @@
 
     if( $self->destination_categories_are_empty ){
-        Wx::MessageBox( 
-            sprintf(
-                "%s", 
-                wxTheApp->branding->{'What is the destination category?'}
-            ),
-            gettext("Piwigo upload error"),
-            wxOK | wxICON_EXCLAMATION, 
-        );
-
-    }
-    else {
+        return unless $self->destination_category_dlg->ShowModal != wxID_CANCEL;
+    }
+#    else {
         # all selected is implicit
         if(!scalar @{$self->imageviewer->GetSelectedItems}){
@@ -1939,5 +1711,5 @@
             );
         }
-    }
+    #}
 }
 
@@ -2009,7 +1781,8 @@
 
     #destroy hidden dialogs
-    $self->global_settings_panel->Destroy;
-    $self->image_preview->Destroy;
-    $self->image_prop_exif->Destroy;
+    $self->global_settings_dlg->Destroy;
+    $self->image_preview_dlg->Destroy;
+    $self->exif_dlg->Destroy;
+    $self->destination_category_dlg->Destroy;
 
     $self->progressdlg->Destroy if defined $self->progressdlg;
