Changeset 3372 for extensions/pLoader


Ignore:
Timestamp:
May 30, 2009, 10:48:30 AM (15 years ago)
Author:
ronosman
Message:

Refactor context menu item initialization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm

    r3371 r3372  
    2424use Wx::DND;
    2525use Wx qw/
     26             wxITEM_NORMAL
    2627             wxNullBitmap
    2728             wxID_OK
     
    340341          perspective
    341342          current_imageviewer_index
     343          imageviewer_mnu
     344          tree_mnu
    342345      /;
    343346__PACKAGE__->mk_accessors( @properties );
     
    456459    $self->_set_setting_properties;
    457460    $self->_initFrame;
    458     $self->_InitEventHandlers;
     461    $self->_initMenus;
     462    $self->_initEventHandlers;
    459463    $self->_initImgTypes;   
    460464
     
    12931297
    12941298
    1295 
    1296 sub _InitEventHandlers {
     1299sub _initMenus {
     1300    my ( $self ) = @_ ;
     1301
     1302    $self->_tree_mnu;
     1303    $self->_imageviewer_mnu;   
     1304}
     1305
     1306
     1307sub _tree_mnu {
     1308    my ( $self ) = @_; 
     1309
     1310    my $ctx_mnu = Wx::Menu->new;
     1311   
     1312    map {
     1313        $ctx_mnu->Append(
     1314            @$_[0..2], wxITEM_NORMAL
     1315        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
     1316    }
     1317    (
     1318        # workaround : first item does not show bitmap
     1319        [
     1320            0,
     1321            "",
     1322            "",
     1323            '../res/mnu_folder_new.png',
     1324        ],
     1325        [
     1326            1+$ID_TREE_CTX_MENU,
     1327            wxTheApp->branding->{'Add new category'},
     1328            sprintf(
     1329                "%s %s %s %s",
     1330                gettext("Add a new"),
     1331                wxTheApp->branding->{category},
     1332                gettext("to the currently selected"),
     1333                wxTheApp->branding->{category},
     1334            ),
     1335            '../res/mnu_folder_new.png',
     1336        ],
     1337        [
     1338            2+$ID_TREE_CTX_MENU,
     1339            "Refresh",
     1340            sprintf(
     1341                "Refresh %s list.",
     1342                wxTheApp->branding->{category},
     1343            ),
     1344            '../res/mnu_refresh.png',
     1345        ],
     1346    );
     1347
     1348    $ctx_mnu->Delete(0);
     1349    $self->tree_mnu(
     1350         $ctx_mnu
     1351    ); 
     1352}       
     1353
     1354sub _imageviewer_mnu {
     1355    my ( $self ) = @_; 
     1356
     1357    my $ctx_mnu = Wx::Menu->new;
     1358   
     1359    map {
     1360        $ctx_mnu->Append(
     1361            @$_[0..2]
     1362        )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
     1363    }
     1364    (
     1365        # workaround : first item does not show bitmap
     1366        [
     1367            0,
     1368            "",
     1369            "",
     1370            '../res/mnu_properties.png',
     1371        ],
     1372        [
     1373            1+$ID_IMAGEVIEWER_CTX_MENU,
     1374            gettext("Properties"),
     1375            gettext("Modify photo properties"),
     1376            '../res/mnu_properties.png',
     1377        ],
     1378        [
     1379            2+$ID_IMAGEVIEWER_CTX_MENU,
     1380            gettext("Preview"),
     1381            gettext("Display photo preview"),
     1382            '../res/mnu_preview.png',
     1383        ],
     1384    );
     1385       
     1386    $ctx_mnu->Delete(0);
     1387    $self->imageviewer_mnu(
     1388         $ctx_mnu
     1389    ); 
     1390}
     1391
     1392sub _initEventHandlers {
    12971393    my ( $self ) = @_ ;
    12981394       
     
    13041400    Wx::Event::EVT_MENU( $self, 105, \&OnChooseLanguage );
    13051401    EVT_TREE_SEL_CHANGED( $self, $self->tree, \&OnTreeSelChanged );
    1306     EVT_TREE_ITEM_RIGHT_CLICK( $self->tree, $self->tree, \&OnTreeItemRightClick );
     1402    EVT_TREE_ITEM_RIGHT_CLICK( $self, $self->tree, \&OnTreeItemRightClick );
    13071403
    13081404    EVT_LIST_END_LABEL_EDIT( $self, $self->imageviewer, \&OnImageViewerEndLabelEdit );
     
    13631459        }
    13641460    }
     1461
    13651462}
    13661463
     
    13711468    $self->imagelist->RemoveImageSelection;
    13721469    $self->imageviewer->Refresh;       
     1470
    13731471}
    13741472
     
    14221520    my( $self, $event ) = @_;
    14231521
    1424     my $point = $event->GetPoint ;
    1425     my $ctx_mnu = Wx::Menu->new;
    1426    
    1427     map {
    1428         $ctx_mnu->Append(
    1429             @$_[0..2]
    1430         )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
    1431     }
    1432     (
    1433         [
    1434             1+$ID_TREE_CTX_MENU,
    1435             wxTheApp->branding->{'Add new category'},
    1436             sprintf(
    1437                 "%s %s %s %s",
    1438                 gettext("Add a new"),
    1439                 wxTheApp->branding->{category},
    1440                 gettext("to the currently selected"),
    1441                 wxTheApp->branding->{category},
    1442             ),
    1443             '../res/mnu_folder_new.png',
    1444         ],
    1445         [
    1446             2+$ID_TREE_CTX_MENU,
    1447             "Refresh",
    1448             sprintf(
    1449                 "Refresh %s list.",
    1450                 wxTheApp->branding->{category},
    1451             ),
    1452             '../res/mnu_refresh.png',
    1453         ],
    1454     );
    1455 
    1456     $self->PopupMenu($ctx_mnu, wxDefaultPosition);
     1522
     1523    $self->PopupMenu($self->tree_mnu, wxDefaultPosition);
    14571524       
    14581525}
     
    14621529    my( $self, $event ) = @_;
    14631530
    1464     my $point = $event->GetPoint ;
    1465     my $ctx_mnu = Wx::Menu->new;
    1466    
    1467     map {
    1468         $ctx_mnu->Append(
    1469             @$_[0..2]
    1470         )->SetBitmap(Wx::Bitmap->new($_->[3],wxBITMAP_TYPE_PNG));
    1471     }
    1472     (
    1473         [
    1474             1+$ID_IMAGEVIEWER_CTX_MENU,
    1475             gettext("Properties"),
    1476             gettext("Modify photo properties"),
    1477             '../res/mnu_properties.png',
    1478         ],
    1479         [
    1480             2+$ID_IMAGEVIEWER_CTX_MENU,
    1481             gettext("Preview"),
    1482             gettext("Display photo preview"),
    1483             '../res/mnu_preview.png',
    1484         ],
    1485     );
    1486    
    1487     $self->PopupMenu($ctx_mnu, wxDefaultPosition);
     1531   
     1532    $self->PopupMenu($self->imageviewer_mnu, wxDefaultPosition);
    14881533       
    14891534       
     
    16071652    if(WXK_DELETE == $event->GetKeyCode){
    16081653        $self->OnRemoveImages();
     1654       
     1655        my $index = $self->current_imageviewer_index < $self->imageviewer->GetItemCount ?
     1656            $self->current_imageviewer_index : $self->current_imageviewer_index -1 ;
    16091657        $self->imageviewer->SelectItem(
    1610             $self->current_imageviewer_index
     1658            $index
    16111659        );
    16121660    }   
Note: See TracChangeset for help on using the changeset viewer.