Ticket #1817: tracker-delete-options.patch

File tracker-delete-options.patch, 10.1 KB (added by scgtrp, 13 years ago)

A patch to split the 'ask on delete' option into 'ask on permanent delete' and 'ask on move to trash'.

  • src/kits/tracker/Commands.h

    diff --git a/src/kits/tracker/Commands.h b/src/kits/tracker/Commands.h
    index c2e19d3..d16b401 100644
    a b const uint32 kShowVolumeSpaceBar = 'ShSB';  
    140140const uint32 kSpaceBarColorChanged = 'SBcc';
    141141
    142142const uint32 kDontMoveFilesToTrashChanged = 'STdm';
     143const uint32 kAskBeforeTrashFileChanged = 'STat';
    143144const uint32 kAskBeforeDeleteFileChanged = 'STad';
    144145
    145146} // namespace BPrivate
  • src/kits/tracker/FSUtils.cpp

    diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp
    index f85df2d..f487c03 100644
    a b static const char* kDeleteConfirmationStr =  
    141141    B_TRANSLATE_MARK("Are you sure you want to delete the "
    142142    "selected item(s)? This operation cannot be reverted.");
    143143
     144static const char* kTrashConfirmationStr =
     145    B_TRANSLATE_MARK("Are you sure you want to move the "
     146    "selected item(s) to the trash?");
     147
    144148static const char* kReplaceStr =
    145149    B_TRANSLATE_MARK("You are trying to replace the item:\n"
    146150    "\t%name%dest\n"
    FSRestoreRefList(BObjectList<entry_ref> *list, bool async)  
    573577
    574578
    575579void
    576 FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList, bool async)
     580FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList, bool async,
     581    bool confirm)
    577582{
    578583    if (srcList->IsEmpty()) {
    579584        delete srcList;
    580585        delete pointList;
    581586        return;
    582587    }
     588   
     589    if (confirm && TrackerSettings().AskBeforeTrashFile()) {
     590        BAlert* alert = new BAlert("",
     591            B_TRANSLATE_NOCOLLECT(kTrashConfirmationStr),
     592            B_TRANSLATE("Cancel"), B_TRANSLATE("Move to Trash"), NULL,
     593            B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
     594        alert->SetShortcut(0, B_ESCAPE);
     595        alert->SetShortcut(1, 'm');
     596       
     597        if (!alert->Go())
     598            return;
     599    }
    583600
    584601    if (async)
    585602        LaunchInNewThread("MoveTask", B_NORMAL_PRIORITY, MoveTask, srcList,
    FSInTrashDir(const entry_ref *ref)  
    27382755void
    27392756FSEmptyTrash()
    27402757{
     2758    if (TrackerSettings().AskBeforeDeleteFile()) {
     2759        BAlert* alert = new BAlert("",
     2760            B_TRANSLATE_NOCOLLECT(kDeleteConfirmationStr),
     2761            B_TRANSLATE("Cancel"), B_TRANSLATE("Delete"), NULL,
     2762            B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
     2763
     2764        alert->SetShortcut(0, B_ESCAPE);
     2765        alert->SetShortcut(1, 'd');
     2766       
     2767        if (!alert->Go())
     2768            return;
     2769    }
     2770   
    27412771    if (find_thread("_tracker_empty_trash_") != B_OK) {
    27422772        resume_thread(spawn_thread(empty_trash, "_tracker_empty_trash_",
    27432773            B_NORMAL_PRIORITY, NULL));
    _DeleteTask(BObjectList<entry_ref> *list, bool confirm)  
    28352865                    delete list;
    28362866                    return B_OK;
    28372867                case 1:
    2838                     FSMoveToTrash(list, NULL, false);
     2868                    FSMoveToTrash(list, NULL, false, false);
    28392869                    return B_OK;
    28402870            }
    28412871        } else {
  • src/kits/tracker/FSUtils.h

    diff --git a/src/kits/tracker/FSUtils.h b/src/kits/tracker/FSUtils.h
    index d033e0b..ca741c1 100644
    a b _IMPEXP_TRACKER bool FSIsDeskDir(const BEntry *);  
    174174_IMPEXP_TRACKER bool FSIsHomeDir(const BEntry *);
    175175_IMPEXP_TRACKER bool FSIsRootDir(const BEntry *);
    176176_IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList = NULL,
    177     bool async = true);
     177    bool async = true, bool confirm = true);
    178178    // Deprecated
    179179
    180180void FSDeleteRefList(BObjectList<entry_ref> *, bool, bool confirm = true);
  • src/kits/tracker/FunctionObject.h

    diff --git a/src/kits/tracker/FunctionObject.h b/src/kits/tracker/FunctionObject.h
    index bcd8f6e..ea78c2d 100644
    a b NewFunctionObject(void (*function)(Param1, Param2, Param3),  
    514514}
    515515
    516516
     517template<class Param1, class Param2, class Param3, class Param4>
     518FourParamFunctionObject<Param1, Param2, Param3, Param4> *
     519NewFunctionObject(void (*function)(Param1, Param2, Param3, Param4),
     520    Param1 p1, Param2 p2, Param3 p3, Param4 p4)
     521{
     522    return new FourParamFunctionObject<Param1, Param2, Param3, Param4>(function, p1, p2, p3, p4);
     523}
     524
     525
    517526template<class T>
    518527PlainMemberFunctionObject<T> *
    519528NewMemberFunctionObject(void (T::*function)(), T *onThis)
  • src/kits/tracker/PoseView.cpp

    diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
    index 6d5d92e..8fab7e6 100644
    a b BPoseView::MoveListToTrash(BObjectList<entry_ref> *list, bool selectNext,  
    56055605        taskList->AddItem(NewFunctionObject(FSDeleteRefList, list, false, true));
    56065606    else
    56075607        taskList->AddItem(NewFunctionObject(FSMoveToTrash, list,
    5608             (BList *)NULL, false));
     5608            (BList *)NULL, false, true));
    56095609
    56105610    if (selectNext && ViewMode() == kListMode) {
    56115611        // next, if in list view mode try selecting the next item after
  • src/kits/tracker/SettingsViews.cpp

    diff --git a/src/kits/tracker/SettingsViews.cpp b/src/kits/tracker/SettingsViews.cpp
    index ce2ba4d..e0ad923 100644
    a b TrashSettingsView::TrashSettingsView()  
    942942        B_TRANSLATE("Don't move files to Trash"),
    943943            new BMessage(kDontMoveFilesToTrashChanged));
    944944
     945    fAskBeforeTrashFileCheckBox = new BCheckBox("",
     946        B_TRANSLATE("Ask before moving files into trash"),
     947            new BMessage(kAskBeforeTrashFileChanged));
     948   
    945949    fAskBeforeDeleteFileCheckBox = new BCheckBox("",
    946         B_TRANSLATE("Ask before delete"),
     950        B_TRANSLATE("Ask before deleting files permanently"),
    947951            new BMessage(kAskBeforeDeleteFileChanged));
    948952
    949953    const float spacing = be_control_look->DefaultItemSpacing();
    TrashSettingsView::TrashSettingsView()  
    953957    layout->SetSpacing(0);
    954958    BGroupLayoutBuilder(layout)
    955959        .Add(fDontMoveFilesToTrashCheckBox)
     960        .Add(fAskBeforeTrashFileCheckBox)
    956961        .Add(fAskBeforeDeleteFileCheckBox)
    957962        .AddGlue()
    958963        .SetInsets(spacing, spacing, spacing, spacing);
    void  
    964969TrashSettingsView::AttachedToWindow()
    965970{
    966971    fDontMoveFilesToTrashCheckBox->SetTarget(this);
     972    fAskBeforeTrashFileCheckBox->SetTarget(this);
    967973    fAskBeforeDeleteFileCheckBox->SetTarget(this);
    968974}
    969975
    TrashSettingsView::MessageReceived(BMessage *message)  
    984990            Window()->PostMessage(kSettingsContentsModified);
    985991            break;
    986992
     993        case kAskBeforeTrashFileChanged:
     994            settings.SetAskBeforeTrashFile(fAskBeforeTrashFileCheckBox->Value() == 1);
     995
     996            tracker->SendNotices(kAskBeforeTrashFileChanged);
     997            Window()->PostMessage(kSettingsContentsModified);
     998            break;
     999
    9871000        case kAskBeforeDeleteFileChanged:
    9881001            settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFileCheckBox->Value() == 1);
    9891002
    TrashSettingsView::IsDefaultable() const  
    10171030    TrackerSettings settings;
    10181031
    10191032    return settings.DontMoveFilesToTrash() != false
     1033        || settings.AskBeforeTrashFile() != true
    10201034        || settings.AskBeforeDeleteFile() != true;
    10211035}
    10221036
    TrashSettingsView::Revert()  
    10271041    TrackerSettings settings;
    10281042
    10291043    settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrash);
     1044    settings.SetAskBeforeTrashFile(fAskBeforeTrashFile);
    10301045    settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFile);
    10311046
    10321047    ShowCurrentSettings();
    TrashSettingsView::_SendNotices()  
    10421057        return;
    10431058
    10441059    tracker->SendNotices(kDontMoveFilesToTrashChanged);
     1060    tracker->SendNotices(kAskBeforeTrashFileChanged);
    10451061    tracker->SendNotices(kAskBeforeDeleteFileChanged);
    10461062}
    10471063
    TrashSettingsView::ShowCurrentSettings()  
    10521068    TrackerSettings settings;
    10531069
    10541070    fDontMoveFilesToTrashCheckBox->SetValue(settings.DontMoveFilesToTrash());
     1071    fAskBeforeTrashFileCheckBox->SetValue(settings.AskBeforeTrashFile());
    10551072    fAskBeforeDeleteFileCheckBox->SetValue(settings.AskBeforeDeleteFile());
    10561073}
    10571074
    TrashSettingsView::RecordRevertSettings()  
    10621079    TrackerSettings settings;
    10631080
    10641081    fDontMoveFilesToTrash = settings.DontMoveFilesToTrash();
     1082    fAskBeforeTrashFile = settings.AskBeforeTrashFile();
    10651083    fAskBeforeDeleteFile = settings.AskBeforeDeleteFile();
    10661084}
    10671085
    bool  
    10701088TrashSettingsView::IsRevertable() const
    10711089{
    10721090    return fDontMoveFilesToTrash != (fDontMoveFilesToTrashCheckBox->Value() > 0)
     1091        || fAskBeforeTrashFile != (fAskBeforeTrashFileCheckBox->Value() > 0)
    10731092        || fAskBeforeDeleteFile != (fAskBeforeDeleteFileCheckBox->Value() > 0);
    10741093}
    10751094
  • src/kits/tracker/SettingsViews.h

    diff --git a/src/kits/tracker/SettingsViews.h b/src/kits/tracker/SettingsViews.h
    index 89299ab..ac6e291 100644
    a b class TrashSettingsView : public SettingsView {  
    180180        void _SendNotices();
    181181
    182182        BCheckBox *fDontMoveFilesToTrashCheckBox;
     183        BCheckBox *fAskBeforeTrashFileCheckBox;
    183184        BCheckBox *fAskBeforeDeleteFileCheckBox;
    184185
    185186        bool fDontMoveFilesToTrash;
     187        bool fAskBeforeTrashFile;
    186188        bool fAskBeforeDeleteFile;
    187189
    188190        typedef SettingsView _inherited;
  • src/kits/tracker/TrackerSettings.cpp

    diff --git a/src/kits/tracker/TrackerSettings.cpp b/src/kits/tracker/TrackerSettings.cpp
    index b63ca2e..d57fc46 100644
    a b class TTrackerState : public Settings {  
    8282        HexScalarValueSetting *fWarningSpaceColor;
    8383
    8484        BooleanValueSetting *fDontMoveFilesToTrash;
     85        BooleanValueSetting *fAskBeforeTrashFile;
    8586        BooleanValueSetting *fAskBeforeDeleteFile;
    8687
    8788        Benaphore fInitLock;
    TTrackerState::LoadSettingsIfNeeded()  
    186187    Add(fWarningSpaceColor = new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", ""));
    187188
    188189    Add(fDontMoveFilesToTrash = new BooleanValueSetting("DontMoveFilesToTrash", false));
     190    Add(fAskBeforeTrashFile = new BooleanValueSetting("AskBeforeTrashFile", true));
    189191    Add(fAskBeforeDeleteFile = new BooleanValueSetting("AskBeforeDeleteFile", true));
    190192
    191193    TryReadingSettings();
    TrackerSettings::SetAskBeforeDeleteFile(bool enabled)  
    514516    gTrackerState.fAskBeforeDeleteFile->SetValue(enabled);
    515517}
    516518
     519
     520bool
     521TrackerSettings::AskBeforeTrashFile()
     522{
     523    return gTrackerState.fAskBeforeTrashFile->Value();
     524}
     525
     526
     527void
     528TrackerSettings::SetAskBeforeTrashFile(bool enabled)
     529{
     530    gTrackerState.fAskBeforeTrashFile->SetValue(enabled);
     531}
     532
  • src/kits/tracker/TrackerSettings.h

    diff --git a/src/kits/tracker/TrackerSettings.h b/src/kits/tracker/TrackerSettings.h
    index ed8ae46..309bfeb 100644
    a b class TrackerSettings {  
    121121
    122122        bool DontMoveFilesToTrash();
    123123        void SetDontMoveFilesToTrash(bool);
     124        bool AskBeforeTrashFile();
     125        void SetAskBeforeTrashFile(bool);
    124126        bool AskBeforeDeleteFile();
    125127        void SetAskBeforeDeleteFile(bool);
    126128