~ubuntu-branches/ubuntu/natty/shotwell/natty

« back to all changes in this revision

Viewing changes to .pc/01_lpi.patch/src/PhotoPage.vala

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-06-29 12:47:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100629124716-1hb2tj31ho45ttu9
Tags: 0.6.0-0ubuntu1
* New upstream release
* debian/watch:
  - Now tracking stable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        
27
27
        public override void execute() {
28
28
            try {
29
 
                fetched = to_fetch.get_pixbuf_with_exceptions(Scaling.for_original(),
 
29
                fetched = to_fetch.get_pixbuf_with_options(Scaling.for_original(),
30
30
                    TransformablePhoto.Exception.ADJUST);
31
31
            } catch (Error fetch_error) {
32
32
                critical("IsoSourceFetchJob: execute( ): can't get pixbuf from backing photo");
503
503
 
504
504
    private bool on_zoom_slider_drag_begin(Gdk.EventButton event) {
505
505
        enable_interactive_zoom_refresh = true;
 
506
        
 
507
        if (get_container() is FullscreenWindow)
 
508
            ((FullscreenWindow) get_container()).disable_toolbar_dismissal();
506
509
 
507
510
        return false;
508
511
    }
510
513
    private bool on_zoom_slider_drag_end(Gdk.EventButton event) {
511
514
        enable_interactive_zoom_refresh = false;
512
515
 
 
516
        if (get_container() is FullscreenWindow)
 
517
            ((FullscreenWindow) get_container()).enable_toolbar_dismissal();
 
518
 
513
519
        ZoomState zoom_state = ZoomState.rescale(get_zoom_state(), zoom_slider.get_value());
514
520
        set_zoom_state(zoom_state);
515
521
        
568
574
    }
569
575
 
570
576
    private void zoom_about_event_cursor_point(Gdk.EventScroll event, double zoom_increment) {
 
577
        if (photo_missing)
 
578
            return;
 
579
 
571
580
        Gdk.Point cursor_wrt_viewport_center = get_cursor_wrt_viewport_center(event);
572
581
        Gdk.Point iso_pixel_under_cursor = get_iso_pixel_under_cursor(event);
573
582
    
757
766
        get_view().clear();
758
767
    }
759
768
    
760
 
    public override void switching_to_fullscreen() {
761
 
        base.switching_to_fullscreen();
 
769
    public override void switching_to_fullscreen(FullscreenWindow fsw) {
 
770
        base.switching_to_fullscreen(fsw);
762
771
        
763
772
        deactivate_tool();
764
773
        
765
774
        cancel_zoom();
766
775
        is_pan_in_progress = false;
767
776
        
768
 
        if (controller != null)
769
 
            controller.items_selected.connect(on_selection_changed);
 
777
        Page page = fsw.get_current_page();
 
778
        if (page != null)
 
779
            page.get_view().items_selected.connect(on_selection_changed);
770
780
    }
771
781
    
772
 
    public override void returning_from_fullscreen() {
773
 
        base.returning_from_fullscreen();
774
 
                
 
782
    public override void returning_from_fullscreen(FullscreenWindow fsw) {
 
783
        base.returning_from_fullscreen(fsw);
 
784
        
775
785
        repaint();
776
786
        
777
 
        if (controller != null)
778
 
            controller.items_selected.disconnect(on_selection_changed);
 
787
        Page page = fsw.get_current_page();
 
788
        if (page != null)
 
789
            page.get_view().items_selected.disconnect(on_selection_changed);
779
790
    }
780
791
    
781
792
    private void on_selection_changed(Gee.Iterable<DataView> selected) {
910
921
        redeye_button.sensitive = sensitivity;
911
922
        adjust_button.sensitive = sensitivity;
912
923
        enhance_button.sensitive = sensitivity;
 
924
        zoom_slider.sensitive = sensitivity;
913
925
 
914
926
        deactivate_tool();
915
927
    }
952
964
        }
953
965
    }
954
966
 
 
967
    public bool get_photo_missing() {
 
968
        return photo_missing;
 
969
    }
 
970
 
955
971
    protected virtual bool confirm_replace_photo(TransformablePhoto? old_photo, TransformablePhoto new_photo) {
956
972
        return true;
957
973
    }
1030
1046
        // any time
1031
1047
        if (canvas != null && canvas.window != null)
1032
1048
            canvas.window.set_cursor(new Gdk.Cursor(Gdk.CursorType.LEFT_PTR));
 
1049
        
 
1050
        repaint();
1033
1051
    }
1034
1052
    
1035
1053
    private void quick_update_pixbuf() {
1036
 
        Gdk.Pixbuf pixbuf = cache.get_ready_pixbuf(get_photo());
 
1054
        Gdk.Pixbuf? pixbuf = cache.get_ready_pixbuf(get_photo());
1037
1055
        if (pixbuf != null) {
1038
1056
            set_pixbuf(pixbuf, get_photo().get_dimensions());
1039
1057
            pixbuf_dirty = false;
1132
1150
    
1133
1151
    private override bool on_shift_pressed(Gdk.EventKey? event) {
1134
1152
        // show quick compare of original only if no tool is in use, the original pixbuf is handy
1135
 
        if (current_tool == null && !ctrl_pressed && !alt_pressed) {
 
1153
        if (current_tool == null && !get_ctrl_pressed() && !get_alt_pressed()) {
1136
1154
            swap_in_original();
1137
1155
        }
1138
1156
        
1154
1172
    }
1155
1173
    
1156
1174
    private override bool on_alt_released(Gdk.EventKey? event) {
1157
 
        if (current_tool == null && shift_pressed && !ctrl_pressed)
 
1175
        if (current_tool == null && get_shift_pressed() && !get_ctrl_pressed())
1158
1176
            swap_in_original();
1159
1177
        
1160
1178
        return base.on_alt_released(event);
1436
1454
        switch (Gdk.keyval_name(event.keyval)) {
1437
1455
            case "Left":
1438
1456
            case "KP_Left":
 
1457
            case "KP_4":
1439
1458
                viewport_center.x -= PAN_INCREMENT_SIZE;
1440
1459
            break;
1441
1460
            
1442
1461
            case "Right":
1443
1462
            case "KP_Right":
 
1463
            case "KP_6":
1444
1464
                viewport_center.x += PAN_INCREMENT_SIZE;
1445
1465
            break;
1446
1466
 
1447
1467
            case "Down":
1448
1468
            case "KP_Down":
 
1469
            case "KP_2":
1449
1470
                viewport_center.y += PAN_INCREMENT_SIZE;
1450
1471
            break;
1451
1472
            
1452
1473
            case "Up":
1453
1474
            case "KP_Up":
 
1475
            case "KP_8":
1454
1476
                viewport_center.y -= PAN_INCREMENT_SIZE;
1455
1477
            break;
1456
1478
            
1457
1479
            default:
1458
 
                critical("EditingHostPage.on_keyboard_pan_event( ): event keyval isn't a known " +
1459
 
                    "navigation key");
1460
 
                return true;
 
1480
                return false;
1461
1481
        }
1462
1482
 
1463
1483
        ZoomState new_zoom_state = ZoomState.pan(current_zoom_state, viewport_center);
1473
1493
            if (current_tool.on_keypress(event))
1474
1494
                return true;
1475
1495
        }
 
1496
        
 
1497
        // if panning is possible, the pan handler (on MUNI?) gets second crack at the keypress
 
1498
        if (is_panning_possible()) {
 
1499
            if (on_keyboard_pan_event(event))
 
1500
                return true;
 
1501
        }
1476
1502
 
1477
1503
        // if the user pressed the "0", "1" or "2" keys then handle the event as if were
1478
1504
        // directed at the zoom slider ("0", "1" and "2" are hotkeys that jump to preset
1491
1517
            case "Left":
1492
1518
            case "KP_Left":
1493
1519
            case "BackSpace":
1494
 
                if (is_panning_possible())
1495
 
                    return on_keyboard_pan_event(event);
1496
 
 
1497
1520
                if (nav_ok) {
1498
1521
                    on_previous_photo();
1499
1522
                    last_nav_key = event.time;
1503
1526
            case "Right":
1504
1527
            case "KP_Right":
1505
1528
            case "space":
1506
 
                if (is_panning_possible())
1507
 
                    return on_keyboard_pan_event(event);
1508
 
 
1509
1529
                if (nav_ok) {
1510
1530
                    on_next_photo();
1511
1531
                    last_nav_key = event.time;
1515
1535
            // this block is only here to prevent base from moving focus to toolbar
1516
1536
            case "Down":
1517
1537
            case "KP_Down":
1518
 
                if (is_panning_possible())
1519
 
                    return on_keyboard_pan_event(event);
1520
 
            break;
1521
 
            
1522
 
            case "Up":
1523
 
            case "KP_Up":
1524
 
                if (is_panning_possible())
1525
 
                    return on_keyboard_pan_event(event);
1526
 
            break;
1527
 
            
 
1538
                ;
 
1539
            break;
 
1540
                       
1528
1541
            case "equal":
1529
1542
            case "plus":
1530
1543
            case "KP_Add":
1576
1589
    }
1577
1590
    
1578
1591
    public bool is_rotate_available(TransformablePhoto photo) {
1579
 
        return true;
 
1592
        return !photo_missing;
1580
1593
    }
1581
1594
 
1582
1595
    private void rotate(Rotation rotation, string name, string description) {
1609
1622
    }
1610
1623
    
1611
1624
    public void on_revert() {
 
1625
        if (photo_missing)
 
1626
            return;
 
1627
 
1612
1628
        deactivate_tool();
1613
1629
        
1614
1630
        if (!has_photo())
1615
1631
            return;
1616
1632
 
 
1633
        if (get_photo().has_editable()) {
 
1634
            if (!revert_editable_dialog(AppWindow.get_instance(), 
 
1635
                (Gee.Collection<Photo>) get_view().get_sources())) {
 
1636
                return;
 
1637
            }
 
1638
            
 
1639
            get_photo().revert_to_master();
 
1640
        }
 
1641
        
1617
1642
        cancel_zoom();
1618
1643
 
1619
1644
        set_photo_missing(false);
1622
1647
        get_command_manager().execute(command);
1623
1648
    }
1624
1649
    
1625
 
    public void on_revert_editable() {
1626
 
        deactivate_tool();
1627
 
        
1628
 
        if (!has_photo())
1629
 
            return;
1630
 
        
1631
 
        if (!get_photo().has_editable())
1632
 
            return;
1633
 
        
1634
 
        if (!revert_editable_dialog(AppWindow.get_instance(), 
1635
 
            (Gee.Collection<Photo>) get_view().get_sources())) {
1636
 
            return;
1637
 
        }
1638
 
        
1639
 
        cancel_zoom();
1640
 
        set_photo_missing(false);
1641
 
        
1642
 
        get_photo().revert_to_master();
1643
 
    }
1644
 
    
1645
1650
    public void on_rename() {
1646
1651
        LibraryPhoto item;
1647
1652
        if (get_photo() is LibraryPhoto)
1704
1709
        rotate_button.clicked.disconnect(on_rotate_counterclockwise);
1705
1710
        rotate_button.clicked.connect(on_rotate_clockwise);
1706
1711
 
1707
 
        if (current_tool == null && shift_pressed && !alt_pressed)
 
1712
        if (current_tool == null && get_shift_pressed() && !get_alt_pressed())
1708
1713
            swap_in_original();
1709
1714
        
1710
1715
        return base.on_ctrl_released(event);
1786
1791
    }
1787
1792
    
1788
1793
    public bool is_enhance_available(TransformablePhoto photo) {
1789
 
        return true;
 
1794
        return !photo_missing;
1790
1795
    }
1791
1796
    
1792
1797
    public void on_enhance() {
1863
1868
            tool_window.move(x, y);
1864
1869
        }
1865
1870
 
1866
 
        // we need both show & present so we get keyboard focus
 
1871
        // we need both show & present so we get keyboard focus in metacity, but due to a bug in
 
1872
        // compiz, we only want to show the window. 
 
1873
                // ticket #2141 prompted this: http://trac.yorba.org/ticket/2141
1867
1874
        tool_window.show();
1868
 
        tool_window.present();
 
1875
        if (!get_window_manager().contains("compiz"))
 
1876
            tool_window.present();
1869
1877
    }
1870
1878
    
1871
1879
    public void on_next_photo() {
1909
1917
    public bool has_current_tool() {
1910
1918
        return (current_tool != null);
1911
1919
    }
1912
 
    
1913
 
    protected void on_jump_to_file() {
1914
 
        if (!has_photo())
1915
 
            return;
1916
 
        
1917
 
        try {
1918
 
            AppWindow.get_instance().show_file_uri(get_photo().get_master_file().get_parent());
1919
 
        } catch (Error err) {
1920
 
            AppWindow.error_message(Resources.jump_to_file_failed(err));
1921
 
        }
1922
 
    }
1923
1920
}
1924
1921
 
1925
1922
//
1953
1950
#endif
1954
1951
 
1955
1952
#if !NO_SET_BACKGROUND
1956
 
        ui.add_ui(ui.new_merge_id(), "/PhotoMenuBar/PhotoMenu/SetBackgroundPlaceholder",
1957
 
            "SetBackground", "SetBackground", Gtk.UIManagerItemType.MENUITEM, false);
1958
 
        ui.add_ui(ui.new_merge_id(), "/PhotoContextMenu/ContextSetBackgroundPlaceholder",
 
1953
        ui.add_ui(ui.new_merge_id(), "/PhotoMenuBar/FileMenu/SetBackgroundPlaceholder",
1959
1954
            "SetBackground", "SetBackground", Gtk.UIManagerItemType.MENUITEM, false);
1960
1955
#endif
1961
1956
        
1969
1964
        LibraryPhoto.global.items_removed.connect(on_photos_removed);
1970
1965
        LibraryPhoto.global.item_destroyed.connect(on_photo_destroyed);
1971
1966
        LibraryPhoto.global.item_metadata_altered.connect(on_metadata_altered);
 
1967
        
 
1968
        // watch for updates to the external app settings
 
1969
        Config.get_instance().external_app_changed.connect(on_external_app_changed);
1972
1970
    }
1973
1971
    
1974
1972
    ~LibraryPhotoPage() {
2021
2019
        remove_from_library.tooltip = _("Remove the photo from the library");
2022
2020
        actions += remove_from_library;        
2023
2021
 
2024
 
        Gtk.ActionEntry move_to_trash = { "MoveToTrash", Gtk.STOCK_DELETE, TRANSLATABLE, "Delete",
 
2022
        Gtk.ActionEntry move_to_trash = { "MoveToTrash", "user-trash-full", TRANSLATABLE, "Delete",
2025
2023
            TRANSLATABLE, on_move_to_trash };
2026
2024
        move_to_trash.label = Resources.MOVE_TO_TRASH_MENU;
2027
2025
        move_to_trash.tooltip = _("Move the photo to the trash");
2105
2103
        revert.tooltip = Resources.REVERT_TOOLTIP;
2106
2104
        actions += revert;
2107
2105
        
2108
 
        Gtk.ActionEntry revert_editable = { "RevertEditable", null, TRANSLATABLE, null,
2109
 
            TRANSLATABLE, on_revert_editable };
2110
 
        revert_editable.label = Resources.REVERT_EDITABLE_MENU;
2111
 
        revert_editable.tooltip = Resources.REVERT_EDITABLE_TOOLTIP;
2112
 
        actions += revert_editable;
2113
 
        
2114
2106
        Gtk.ActionEntry rename = { "PhotoRename", null, TRANSLATABLE, "F2", TRANSLATABLE,
2115
2107
            on_rename };
2116
2108
        rename.label = Resources.RENAME_PHOTO_MENU;
2123
2115
        adjust_date_time.tooltip = Resources.ADJUST_DATE_TIME_TOOLTIP;
2124
2116
        actions += adjust_date_time;
2125
2117
        
2126
 
        Gtk.ActionEntry external_edit = { "ExternalEdit", Gtk.STOCK_EDIT, TRANSLATABLE, null,
2127
 
            TRANSLATABLE, on_external_edit };
 
2118
        Gtk.ActionEntry external_edit = { "ExternalEdit", Gtk.STOCK_EDIT, TRANSLATABLE,
 
2119
            "<Ctrl>Return", TRANSLATABLE, on_external_edit };
2128
2120
        external_edit.label = Resources.EXTERNAL_EDIT_MENU;
2129
2121
        external_edit.tooltip = Resources.EXTERNAL_EDIT_TOOLTIP;
2130
2122
        actions += external_edit;
2131
 
        
2132
 
        Gtk.ActionEntry edit_raw = { "ExternalEditRAW", null, TRANSLATABLE, null, TRANSLATABLE,
2133
 
            on_external_edit_raw };
 
2123
 
 
2124
#if !NO_RAW
 
2125
        Gtk.ActionEntry edit_raw = { "ExternalEditRAW", null, TRANSLATABLE, "<Ctrl><Shift>Return", 
 
2126
            TRANSLATABLE, on_external_edit_raw };
2134
2127
        edit_raw.label = Resources.EXTERNAL_EDIT_RAW_MENU;
2135
2128
        edit_raw.tooltip = Resources.EXTERNAL_EDIT_RAW_TOOLTIP;
2136
2129
        actions += edit_raw;
2137
 
        
2138
 
        Gtk.ActionEntry jump_to_file = { "JumpToFile", Gtk.STOCK_JUMP_TO, TRANSLATABLE, null, 
2139
 
            TRANSLATABLE, on_jump_to_file };
2140
 
        jump_to_file.label = Resources.JUMP_TO_FILE_MENU;
2141
 
        jump_to_file.tooltip = Resources.JUMP_TO_FILE_TOOLTIP;
2142
 
        actions += jump_to_file;
 
2130
#endif
2143
2131
        
2144
2132
#if !NO_SET_BACKGROUND
2145
2133
        Gtk.ActionEntry set_background = { "SetBackground", null, TRANSLATABLE, "<Ctrl>B",
2198
2186
    
2199
2187
    protected override void init_actions(int selected_count, int count) {
2200
2188
        set_action_sensitive("ExternalEdit", count > 0 && Config.get_instance().get_external_photo_app() != "");
2201
 
        set_action_hidden("ExternalEditRAW");
2202
 
        set_action_sensitive("RevertEditable", has_photo() && get_photo().has_editable());
 
2189
        
 
2190
        set_action_sensitive("Revert", has_photo() ?
 
2191
            (get_photo().has_transformations() || get_photo().has_editable()) : false);
 
2192
        
 
2193
#if !NO_SET_BACKGROUND
 
2194
        set_action_sensitive("SetBackground", has_photo());
 
2195
#endif
2203
2196
        
2204
2197
        base.init_actions(selected_count, count);
2205
2198
    }
2206
2199
    
2207
2200
    private void on_contents_altered() {
2208
 
        bool is_raw = has_photo() && get_photo().get_master_file_format() == PhotoFileFormat.RAW;
2209
 
        
2210
2201
        set_action_sensitive("ExternalEdit", has_photo() && Config.get_instance().get_external_photo_app() != "");
2211
 
        if (is_raw)
2212
 
            set_action_visible("ExternalEditRAW", Config.get_instance().get_external_raw_app() != "");
2213
 
        else
2214
 
            set_action_hidden("ExternalEditRAW");
2215
 
        set_action_sensitive("RevertEditable", has_photo() && get_photo().has_editable());
 
2202
                
 
2203
        set_action_sensitive("Revert", has_photo() ?
 
2204
            (get_photo().has_transformations() || get_photo().has_editable()) : false);
 
2205
        
 
2206
#if !NO_SET_BACKGROUND
 
2207
        set_action_sensitive("SetBackground", has_photo());
 
2208
#endif
2216
2209
    }
2217
2210
    
2218
2211
    private void on_photos_altered() {
2219
 
        set_action_sensitive("RevertEditable", has_photo() && get_photo().has_editable());
 
2212
        set_action_sensitive("Revert", has_photo() ?
 
2213
            (get_photo().has_transformations() || get_photo().has_editable()) : false);
2220
2214
    }
2221
2215
    
2222
2216
    public void display_for_collection(CollectionPage return_page, Photo photo) {
2270
2264
    }
2271
2265
 
2272
2266
    private void update_zoom_menu_item_sensitivity() {
2273
 
        set_item_sensitive("/PhotoMenuBar/ViewMenu/IncreaseSize", !get_zoom_state().is_max());
2274
 
        set_item_sensitive("/PhotoMenuBar/ViewMenu/DecreaseSize", !get_zoom_state().is_default());
 
2267
        set_item_sensitive("/PhotoMenuBar/ViewMenu/IncreaseSize", !get_zoom_state().is_max()
 
2268
            && !get_photo_missing());
 
2269
        set_item_sensitive("/PhotoMenuBar/ViewMenu/DecreaseSize", !get_zoom_state().is_default()
 
2270
            && !get_photo_missing());
2275
2271
    }
2276
2272
 
2277
2273
    protected override void on_increase_size() {
2299
2295
    }
2300
2296
 
2301
2297
    protected override void set_missing_photo_sensitivities(bool sensitivity) {
 
2298
        set_item_sensitive("/PhotoMenuBar/FileMenu/PublishPlaceholder/Publish", sensitivity);
 
2299
        set_item_sensitive("/PhotoMenuBar/FileMenu/PrintPlaceholder/Print", sensitivity);
 
2300
        set_item_sensitive("/PhotoMenuBar/FileMenu/JumpToFile", sensitivity);
 
2301
        set_item_sensitive("/PhotoMenuBar/EditMenu/Undo", sensitivity);
 
2302
        set_item_sensitive("/PhotoMenuBar/EditMenu/Redo", sensitivity);
 
2303
        set_item_sensitive("/PhotoMenuBar/ViewMenu/IncreaseSize", sensitivity);
 
2304
        set_item_sensitive("/PhotoMenuBar/ViewMenu/DecreaseSize", sensitivity);
2302
2305
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/RotateClockwise", sensitivity);
2303
2306
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/RotateCounterclockwise", sensitivity);
2304
2307
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Mirror", sensitivity);
2307
2310
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/Crop", sensitivity);
2308
2311
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/RedEye", sensitivity);
2309
2312
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/Adjust", sensitivity);
2310
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Revert", sensitivity);
 
2313
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/FavoriteUnfavorite", sensitivity);
 
2314
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/HideUnhide", sensitivity);
 
2315
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/PhotoRename", sensitivity);
 
2316
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/AdjustDateTime", sensitivity);
 
2317
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/ExternalEdit", sensitivity);
 
2318
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/ExternalEditRAW", sensitivity);
 
2319
                set_item_sensitive("/PhotoMenuBar/PhotoMenu/Revert", sensitivity);
 
2320
        set_item_sensitive("/PhotoMenuBar/TagsMenu/AddTags", sensitivity);
 
2321
        set_item_sensitive("/PhotoMenuBar/TagsMenu/ModifyTags", sensitivity);
 
2322
        //AppWindow.get_instance().set_common_action_sensitive("CommonFullscreen", sensitivity);
2311
2323
 
2312
 
        set_item_sensitive("/PhotoContextMenu/ContextRotateClockwise", sensitivity);
2313
 
        set_item_sensitive("/PhotoContextMenu/ContextRotateCounterclockwise", sensitivity);
2314
 
        set_item_sensitive("/PhotoContextMenu/PhotoRename", sensitivity);
2315
 
        set_item_sensitive("/PhotoContextMenu/AdjustDateTime", sensitivity);
2316
 
        set_action_sensitive("JumpToFile", sensitivity);
 
2324
        set_item_sensitive("/PhotoContextMenu/ContextEnhance", sensitivity);
 
2325
        set_item_sensitive("/PhotoContextMenu/ContextRevert", sensitivity);
 
2326
        set_item_sensitive("/PhotoContextMenu/ContextAddTags", sensitivity);
 
2327
        set_item_sensitive("/PhotoContextMenu/ContextModifyTags", sensitivity);
 
2328
        set_item_sensitive("/PhotoContextMenu/ContextFavoriteUnfavorite", sensitivity);
 
2329
        set_item_sensitive("/PhotoContextMenu/ContextHideUnhide", sensitivity);
 
2330
        set_item_sensitive("/PhotoContextMenu/ContextPhotoRename", sensitivity);
 
2331
        set_item_sensitive("/PhotoContextMenu/ContextExternalEdit", sensitivity);
 
2332
        set_item_sensitive("/PhotoContextMenu/ContextExternalEditRAW", sensitivity);
 
2333
        set_item_sensitive("/PhotoContextMenu/JumpToFile", sensitivity);
 
2334
        set_item_sensitive("/PhotoContextMenu/ContextMoveToTrash", sensitivity);
2317
2335
        
2318
2336
#if !NO_SET_BACKGROUND
2319
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/SetBackgroundPlaceholder/SetBackground",
2320
 
            sensitivity);
2321
 
        set_item_sensitive("/PhotoContextMenu/ContextSetBackgroundPlaceholder/SetBackground",
2322
 
            sensitivity);
 
2337
        set_action_sensitive("SetBackground", sensitivity);
2323
2338
#endif
2324
2339
 
2325
2340
        set_item_sensitive("/PhotoContextMenu/ContextHideUnhide", sensitivity);
2379
2394
    private override bool on_context_invoked() {
2380
2395
        if (!has_photo())
2381
2396
            return false;
 
2397
        
 
2398
#if !NO_RAW
 
2399
        bool is_raw = has_photo() && get_photo().get_master_file_format() == PhotoFileFormat.RAW;
 
2400
#endif  
2382
2401
 
2383
 
        set_item_sensitive("/PhotoContextMenu/ContextRotateClockwise", is_rotate_available(get_photo()));
2384
 
        set_item_sensitive("/PhotoContextMenu/ContextRotateCounterclockwise",
2385
 
            is_rotate_available(get_photo()));
2386
2402
        set_item_sensitive("/PhotoContextMenu/ContextEnhance", is_enhance_available(get_photo()));
2387
 
        set_item_sensitive("/PhotoContextMenu/ContextRevert", get_photo().has_transformations());
2388
2403
 
2389
2404
        set_hide_item_label("/PhotoContextMenu/ContextHideUnhide");
2390
2405
        set_favorite_item_label("/PhotoContextMenu/ContextFavoriteUnfavorite");
2391
 
 
 
2406
        
 
2407
#if !NO_RAW
 
2408
        if (is_raw)
 
2409
            set_item_visible("/PhotoContextMenu/ContextExternalEditRAW", 
 
2410
                Config.get_instance().get_external_raw_app() != "");
 
2411
        else
 
2412
            set_item_hidden("/PhotoContextMenu/ContextExternalEditRAW");
 
2413
#endif
 
2414
        
2392
2415
        return base.on_context_invoked();
2393
2416
    }
2394
2417
 
2479
2502
        PrintManager.get_instance().do_page_setup();
2480
2503
    }
2481
2504
#endif
 
2505
 
 
2506
    private void on_external_app_changed() {
 
2507
        set_action_sensitive("ExternalEdit", has_photo() && 
 
2508
            Config.get_instance().get_external_photo_app() != "");
 
2509
    }
2482
2510
    
2483
2511
    private void on_external_edit() {
2484
2512
        if (!has_photo())
2493
2521
            AppWindow.error_message(Resources.launch_editor_failed(err));
2494
2522
        }
2495
2523
    }
2496
 
    
 
2524
 
 
2525
#if !NO_RAW    
2497
2526
    private void on_external_edit_raw() {
2498
2527
        if (!has_photo())
2499
2528
            return;
2510
2539
            AppWindow.error_message(Resources.launch_editor_failed(err));
2511
2540
        }
2512
2541
    }
 
2542
#endif
2513
2543
    
2514
2544
    private void on_export() {
2515
2545
        if (!has_photo())
2539
2569
    
2540
2570
    private void on_file_menu() {
2541
2571
#if !NO_PRINTING
2542
 
        set_item_sensitive("/PhotoMenuBar/FileMenu/PrintPlaceholder/Print", has_photo());
 
2572
        set_item_sensitive("/PhotoMenuBar/FileMenu/PrintPlaceholder/Print", has_photo() && 
 
2573
            !get_photo_missing());
2543
2574
#endif
2544
2575
 
2545
 
        set_item_sensitive("/PhotoMenuBar/FileMenu/Export", has_photo());
 
2576
        set_item_sensitive("/PhotoMenuBar/FileMenu/Export", has_photo() && !get_photo_missing());
2546
2577
 
2547
2578
#if !NO_PUBLISHING
2548
 
        set_item_sensitive("/PhotoMenuBar/FileMenu/PublishPlaceholder/Publish", has_photo());
 
2579
        set_item_sensitive("/PhotoMenuBar/FileMenu/PublishPlaceholder/Publish", has_photo() && 
 
2580
            !get_photo_missing());
2549
2581
#endif
2550
2582
    }
2551
2583
    
2563
2595
    private void on_edit_menu() {
2564
2596
        decorate_undo_item("/PhotoMenuBar/EditMenu/Undo");
2565
2597
        decorate_redo_item("/PhotoMenuBar/EditMenu/Redo");
2566
 
        set_item_sensitive("/PhotoMenuBar/EditMenu/MoveToTrash", has_photo());
 
2598
        // Override the decorate calls of the photo is missing
 
2599
        if (get_photo_missing()) {
 
2600
            set_item_sensitive("/PhotoMenuBar/EditMenu/Undo", false);
 
2601
            set_item_sensitive("/PhotoMenuBar/EditMenu/Redo", false);
 
2602
        }
 
2603
        set_item_sensitive("/PhotoMenuBar/EditMenu/MoveToTrash", has_photo() && !get_photo_missing());
2567
2604
    }
2568
2605
    
2569
2606
    protected void set_favorite_item_label(string path) {
2585
2622
    
2586
2623
    private void on_photo_menu() {
2587
2624
        bool multiple = (get_controller() != null) ? get_controller().get_count() > 1 : false;
2588
 
        bool revert_possible = has_photo() ? get_photo().has_transformations() : false;
2589
2625
        bool rotate_possible = has_photo() ? is_rotate_available(get_photo()) : false;
 
2626
#if !NO_RAW
 
2627
        bool is_raw = has_photo() && get_photo().get_master_file_format() == PhotoFileFormat.RAW;
 
2628
#endif
2590
2629
        
2591
2630
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/PrevPhoto", multiple);
2592
2631
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/NextPhoto", multiple);
2594
2633
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/RotateCounterclockwise", rotate_possible);
2595
2634
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Mirror", rotate_possible);
2596
2635
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Flip", rotate_possible);
2597
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Revert", revert_possible);
2598
2636
        set_hide_item_label("/PhotoMenuBar/PhotoMenu/HideUnhide");
2599
2637
        set_favorite_item_label("/PhotoMenuBar/PhotoMenu/FavoriteUnfavorite");
 
2638
                
 
2639
#if !NO_RAW
 
2640
        if (is_raw)
 
2641
            set_item_visible("/PhotoMenuBar/PhotoMenu/ExternalEditRAW", 
 
2642
                Config.get_instance().get_external_raw_app() != "");
 
2643
        else
 
2644
            set_item_hidden("/PhotoMenuBar/PhotoMenu/ExternalEditRAW");
 
2645
#endif
2600
2646
    }
2601
2647
    
2602
2648
    private void on_tools() {
2727
2773
        
2728
2774
        DirectPhoto? photo = null;
2729
2775
        try {
2730
 
            photo = DirectPhoto.global.fetch(file);
 
2776
            DirectPhoto.global.fetch(file, out photo);
2731
2777
        } catch (Error error) {
2732
2778
            warning("Fetching photo failed: %s", error.message);
2733
2779
        }
2755
2801
        
2756
2802
        DirectPhoto? photo = null;
2757
2803
        try {
2758
 
            photo = DirectPhoto.global.fetch(file);
 
2804
            DirectPhoto.global.fetch(file, out photo);
2759
2805
        } catch (Error error) {
2760
2806
            warning("Fetching photo failed: %s", error.message);
2761
2807
        }
2792
2838
        
2793
2839
        DirectPhoto? photo = null;
2794
2840
        try {
2795
 
            photo = DirectPhoto.global.fetch(file);
 
2841
            DirectPhoto.global.fetch(file, out photo);
2796
2842
        } catch (Error error) {
2797
2843
            warning("Fetching photo failed: %s", error.message);
2798
2844
        }
2829
2875
        
2830
2876
        DirectPhoto? photo = null;
2831
2877
        try {
2832
 
            photo = DirectPhoto.global.fetch(file);
 
2878
            DirectPhoto.global.fetch(file, out photo);
2833
2879
        } catch (Error error) {
2834
2880
            warning("Fetching photo failed: %s", error.message);
2835
2881
        }
2905
2951
        ui.add_ui(ui.new_merge_id(), "/DirectMenuBar/FileMenu/PrintPlaceholder", "Print",
2906
2952
            "Print", Gtk.UIManagerItemType.MENUITEM, false);
2907
2953
#endif
 
2954
        
 
2955
#if !NO_SET_BACKGROUND
 
2956
        ui.add_ui(ui.new_merge_id(), "/DirectMenuBar/FileMenu/SetBackgroundPlaceholder",
 
2957
            "SetBackground", "SetBackground", Gtk.UIManagerItemType.MENUITEM, false);
 
2958
#endif
2908
2959
 
2909
2960
        context_menu = (Gtk.Menu) ui.get_widget("/DirectContextMenu");
 
2961
 
 
2962
        get_view().contents_altered.connect(on_contents_altered);
2910
2963
    }
2911
2964
    
2912
2965
    private Gtk.ActionEntry[] create_actions() {
3025
3078
        adjust_date_time.tooltip = Resources.ADJUST_DATE_TIME_TOOLTIP;
3026
3079
        actions += adjust_date_time;
3027
3080
        
3028
 
        Gtk.ActionEntry jump_to_file = { "JumpToFile", Gtk.STOCK_JUMP_TO, TRANSLATABLE, null,
3029
 
            TRANSLATABLE, on_jump_to_file };
3030
 
        jump_to_file.label = Resources.JUMP_TO_FILE_MENU;
3031
 
        jump_to_file.tooltip = Resources.JUMP_TO_FILE_TOOLTIP;
3032
 
        actions += jump_to_file;
3033
 
        
3034
3081
#if !NO_SET_BACKGROUND
3035
3082
        Gtk.ActionEntry set_background = { "SetBackground", null, TRANSLATABLE, "<Ctrl>B",
3036
3083
            TRANSLATABLE, on_set_background };
3081
3128
            base.realize();
3082
3129
        
3083
3130
        DirectPhoto photo = null;
 
3131
        ImportResult import_result = ImportResult.SUCCESS;
3084
3132
        try {
3085
 
            photo = DirectPhoto.global.fetch(initial_file);
 
3133
            import_result = DirectPhoto.global.fetch(initial_file, out photo);
3086
3134
        } catch (Error error) {
3087
3135
            warning("Fetching photo failed: %s", error.message);
3088
3136
        }
3089
3137
        
3090
3138
        if (photo == null) {
3091
 
            // dead in the water
 
3139
            AppWindow.error_message(import_result.to_string());
3092
3140
            Posix.exit(1);
3093
3141
        }
3094
3142
 
3107
3155
    }
3108
3156
 
3109
3157
    private void update_zoom_menu_item_sensitivity() {
3110
 
        set_item_sensitive("/DirectMenuBar/ViewMenu/IncreaseSize", !get_zoom_state().is_max());
3111
 
        set_item_sensitive("/DirectMenuBar/ViewMenu/DecreaseSize", !get_zoom_state().is_default());
 
3158
        set_item_sensitive("/DirectMenuBar/ViewMenu/IncreaseSize", !get_zoom_state().is_max()
 
3159
            && !get_photo_missing());
 
3160
        set_item_sensitive("/DirectMenuBar/ViewMenu/DecreaseSize", !get_zoom_state().is_default()
 
3161
            && !get_photo_missing());
3112
3162
    }
3113
3163
 
3114
3164
    protected override void on_increase_size() {
3126
3176
    protected override void set_missing_photo_sensitivities(bool sensitivity) {
3127
3177
        set_item_sensitive("/DirectMenuBar/FileMenu/Save", sensitivity);
3128
3178
        set_item_sensitive("/DirectMenuBar/FileMenu/SaveAs", sensitivity);
3129
 
        
 
3179
        set_item_sensitive("/DirectMenuBar/FileMenu/PublishPlaceholder/Publish", sensitivity);
 
3180
        set_item_sensitive("/DirectMenuBar/FileMenu/PrintPlaceholder/Print", sensitivity);
 
3181
        set_item_sensitive("/DirectMenuBar/FileMenu/JumpToFile", sensitivity);
 
3182
 
 
3183
        set_item_sensitive("/DirectMenuBar/ViewMenu/IncreaseSize", sensitivity);
 
3184
        set_item_sensitive("/DirectMenuBar/ViewMenu/IncreaseSize", sensitivity);
 
3185
        set_item_sensitive("/DirectMenuBar/ViewMenu/DecreaseSize", sensitivity);
 
3186
 
3130
3187
        set_item_sensitive("/DirectMenuBar/PhotoMenu/RotateClockwise", sensitivity);
3131
3188
        set_item_sensitive("/DirectMenuBar/PhotoMenu/RotateCounterclockwise", sensitivity);
3132
3189
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Mirror", sensitivity);
3133
3190
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Flip", sensitivity);
3134
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/Enhance", sensitivity);
3135
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/Crop", sensitivity);
3136
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/RedEye", sensitivity);
3137
 
        set_item_sensitive("/PhotoMenuBar/PhotoMenu/Tools/Adjust", sensitivity);
 
3191
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Tools/Enhance", sensitivity);
 
3192
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Tools/Crop", sensitivity);
 
3193
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Tools/RedEye", sensitivity);
 
3194
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Tools/Adjust", sensitivity);
3138
3195
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Revert", sensitivity);
 
3196
        set_item_sensitive("/DirectMenuBar/PhotoMenu/AdjustDateTime", sensitivity);
 
3197
        set_item_sensitive("/DirectMenuBar/PhotoMenu/Fullscreen", sensitivity);
3139
3198
 
3140
 
        set_item_sensitive("/DirectContextMenu/ContextRotateClockwise", sensitivity);
3141
 
        set_item_sensitive("/DirectContextMenu/ContextRotateCounterclockwise", sensitivity);
3142
3199
        set_item_sensitive("/DirectContextMenu/ContextEnhance", sensitivity);
3143
3200
        set_item_sensitive("/DirectContextMenu/ContextRevert", sensitivity);
 
3201
        set_item_sensitive("/DirectContextMenu/JumpToFile", sensitivity);
3144
3202
        
3145
3203
#if !NO_SET_BACKGROUND
3146
 
        set_item_sensitive("/DirectContextMenu/ContextSetBackgroundPlaceholder/ContextSetBackground", sensitivity);
 
3204
        set_action_sensitive("SetBackground", has_photo() && !get_photo_missing());
3147
3205
#endif
3148
 
    
 
3206
        
3149
3207
        base.set_missing_photo_sensitivities(sensitivity);
3150
3208
    }
3151
3209
    
 
3210
    protected override void init_actions(int selected_count, int count) {
 
3211
#if !NO_SET_BACKGROUND
 
3212
        set_action_sensitive("SetBackground", has_photo());
 
3213
#endif
 
3214
        
 
3215
        base.init_actions(selected_count, count);
 
3216
    }
 
3217
    
 
3218
    private void on_contents_altered() {
 
3219
#if !NO_SET_BACKGROUND
 
3220
        set_action_sensitive("SetBackground", has_photo());
 
3221
#endif
 
3222
    }
 
3223
    
3152
3224
    private override bool on_context_invoked() {
3153
3225
        if (get_photo() == null)
3154
3226
            return false;
3155
3227
        
3156
 
        set_item_sensitive("/DirectContextMenu/ContextRotateClockwise", is_rotate_available(get_photo()));
3157
 
        set_item_sensitive("/DirectContextMenu/ContextRotateCounterclockwise",
3158
 
            is_rotate_available(get_photo()));
3159
3228
        set_item_sensitive("/DirectContextMenu/ContextEnhance", is_enhance_available(get_photo()));
3160
 
        set_item_sensitive("/DirectContextMenu/ContextRevert", get_photo().has_transformations());
 
3229
        set_item_sensitive("/DirectContextMenu/ContextRevert", get_photo().has_transformations() &&
 
3230
            !get_photo_missing());
 
3231
        //set_item_sensitive("/DirectContextMenu/JumpToFile", !get_photo_missing());
3161
3232
        
3162
3233
        return base.on_context_invoked();
3163
3234
    }
3204
3275
    }
3205
3276
    
3206
3277
    private void on_file_menu() {
3207
 
        set_item_sensitive("/DirectMenuBar/FileMenu/Save", get_photo().has_alterations() && get_photo().get_file_format().can_write());
 
3278
        set_item_sensitive("/DirectMenuBar/FileMenu/Save", get_photo().has_alterations() && 
 
3279
            get_photo().get_file_format().can_write() && !get_photo_missing());
3208
3280
    }
3209
3281
    
3210
3282
    private void save(File dest, int scale, ScaleConstraint constraint, Jpeg.Quality quality,
3221
3293
        }
3222
3294
        
3223
3295
        DirectPhoto photo = null;
 
3296
        ImportResult fetch_result = ImportResult.SUCCESS;
3224
3297
        try {
3225
 
            photo = DirectPhoto.global.fetch(dest, true);
 
3298
            fetch_result = DirectPhoto.global.fetch(dest, out photo, true);
3226
3299
        } catch (Error error) {
3227
3300
            warning("Fetching photo failed: %s", error.message);
3228
3301
        }
3239
3312
    }
3240
3313
 
3241
3314
    private void on_save() {
3242
 
        if (!get_photo().has_alterations() && !get_photo().get_file_format().can_write())
 
3315
        if (!get_photo().has_alterations() || !get_photo().get_file_format().can_write() || 
 
3316
            get_photo_missing())
3243
3317
            return;
3244
3318
 
3245
3319
        // save full-sized version right on top of the current file
3320
3394
    private void on_edit_menu() {
3321
3395
        decorate_undo_item("/DirectMenuBar/EditMenu/Undo");
3322
3396
        decorate_redo_item("/DirectMenuBar/EditMenu/Redo");
 
3397
        // Override the decorate calls of the photo is missing
 
3398
        if (get_photo_missing()) {
 
3399
            set_item_sensitive("/PhotoMenuBar/EditMenu/Undo", false);
 
3400
            set_item_sensitive("/PhotoMenuBar/EditMenu/Redo", false);
 
3401
        }
3323
3402
    }
3324
3403
    
3325
3404
    private void on_photo_menu() {
3326
3405
        bool multiple = (get_controller() != null) ? get_controller().get_count() > 1 : false;
3327
 
        bool revert_possible = has_photo() ? get_photo().has_transformations() : false;
 
3406
        bool revert_possible = has_photo() ? get_photo().has_transformations() 
 
3407
            && !get_photo_missing() : false;
3328
3408
        bool rotate_possible = has_photo() ? is_rotate_available(get_photo()) : false;
3329
3409
 
3330
3410
        set_item_sensitive("/DirectMenuBar/PhotoMenu/PrevPhoto", multiple);