Exemplo n.º 1
0
void clTreeCtrlPanel::OnDeleteFile(wxCommandEvent& event)
{
    wxArrayString folders, files;
    wxArrayTreeItemIds folderItems, fileItems;
    GetSelections(folders, folderItems, files, fileItems);
    if(files.empty()) return;

    wxString message;
    message << _("Are you sure you want to delete the selected files?");

    wxRichMessageDialog dialog(EventNotifier::Get()->TopFrame(),
                               message,
                               _("Confirm"),
                               wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER | wxICON_WARNING);
    dialog.SetYesNoLabels(_("Delete Files"), _("No"));

    wxWindowUpdateLocker locker(GetTreeCtrl());
    wxArrayTreeItemIds deletedItems;
    if(dialog.ShowModal() == wxID_YES) {
        wxLogNull nl;
        for(size_t i = 0; i < files.size(); ++i) {
            if(::wxRemoveFile(files.Item(i))) {
                deletedItems.Add(fileItems.Item(i));
            }
        }
    }

    // Update the UI
    for(size_t i = 0; i < deletedItems.size(); ++i) {
        // Before we delete the item from the tree, update the parent cache
        UpdateItemDeleted(deletedItems.Item(i));
        // And now remove the item from the tree
        GetTreeCtrl()->Delete(deletedItems.Item(i));
    }
}
Exemplo n.º 2
0
void clTreeCtrlPanel::OnDeleteFolder(wxCommandEvent& event)
{
    wxTreeItemId item = GetTreeCtrl()->GetFocusedItem();
    clTreeCtrlData* cd = GetItemData(item);
    CHECK_PTR_RET(cd);
    CHECK_COND_RET(cd->IsFolder());

    wxString message;
    message << _("Are you sure you want to delete folder:\n'") << cd->GetPath() << _("'");

    wxRichMessageDialog dialog(EventNotifier::Get()->TopFrame(),
                               message,
                               _("Confirm"),
                               wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER | wxICON_WARNING);
    dialog.SetYesNoLabels(_("Delete Folder"), _("Don't Delete"));
    if(dialog.ShowModal() == wxID_YES) {
        if(wxFileName::Rmdir(cd->GetPath(), wxPATH_RMDIR_RECURSIVE)) {
            // Remove this item from its parent cache
            UpdateItemDeleted(item);
            // Remove the item from the UI
            GetTreeCtrl()->Delete(item);
        }
    }
}
Exemplo n.º 3
0
void clTreeCtrlPanel::OnDeleteSelections(wxCommandEvent& event)
{
    wxArrayString folders, files;
    wxArrayTreeItemIds folderItems, fileItems;
    GetSelections(folders, folderItems, files, fileItems);
    if(files.empty() && folders.empty()) return;

    std::set<wxTreeItemId> selectedItems;
    std::vector<FileOrFolder> v;

    selectedItems.insert(folderItems.begin(), folderItems.end());
    selectedItems.insert(fileItems.begin(), fileItems.end());

    // loop over the selections and remove all items that their parents
    // also exists in the selected items list
    for(size_t i = 0; i < folderItems.size(); ++i) {
        wxTreeItemId item = folderItems.Item(i);
        bool foundParent = false;
        wxTreeItemId itemParent = GetTreeCtrl()->GetItemParent(item);
        while(itemParent.IsOk()) {
            if(selectedItems.count(itemParent)) {
                // item's parent is in the list, don't delete it as it will get deleted
                // by its parent
                foundParent = true;
                break;
            }
            itemParent = GetTreeCtrl()->GetItemParent(itemParent);
        }

        if(!foundParent) {
            FileOrFolder fof;
            fof.folder = true;
            fof.item = item;
            fof.path = folders.Item(i);
            v.push_back(fof);
        }
    }

    for(size_t i = 0; i < fileItems.size(); ++i) {
        wxTreeItemId item = fileItems.Item(i);
        bool foundParent = false;
        wxTreeItemId itemParent = GetTreeCtrl()->GetItemParent(item);
        while(itemParent.IsOk()) {
            if(selectedItems.count(itemParent)) {
                // item's parent is in the list, don't delete it as it will get deleted
                // by its parent
                foundParent = true;
                break;
            }
            itemParent = GetTreeCtrl()->GetItemParent(itemParent);
        }

        if(!foundParent) {
            FileOrFolder fof;
            fof.folder = false;
            fof.item = item;
            fof.path = files.Item(i);
            v.push_back(fof);
        }
    }

    // At this point "v" contains a unique list of items to delete
    // the items in "v" have no common parent
    wxString message;
    message << _("Are you sure you want to delete the selected items?");

    wxRichMessageDialog dialog(EventNotifier::Get()->TopFrame(),
                               message,
                               _("Confirm"),
                               wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER | wxICON_WARNING);

    wxWindowUpdateLocker locker(GetTreeCtrl());
    wxArrayTreeItemIds deletedItems;
    if(dialog.ShowModal() == wxID_YES) {
        wxLogNull nl;
        for(size_t i = 0; i < v.size(); ++i) {
            if(v.at(i).folder) {
                if(wxFileName::Rmdir(v.at(i).path, wxPATH_RMDIR_RECURSIVE)) {
                    deletedItems.Add(v.at(i).item);
                }
            } else {
                if(::wxRemoveFile(v.at(i).path)) {
                    deletedItems.Add(v.at(i).item);
                }
            }
        }
    }

    // Update the UI
    for(size_t i = 0; i < deletedItems.size(); ++i) {
        // Before we delete the item from the tree, update the parent cache
        UpdateItemDeleted(deletedItems.Item(i));
        // And now remove the item from the tree
        GetTreeCtrl()->Delete(deletedItems.Item(i));
    }
}