| 694 | void CSearchDialog::OnEdit(wxCommandEvent&) |
| 695 | { |
| 696 | if (!m_pState->IsRemoteIdle()) |
| 697 | return; |
| 698 | |
| 699 | // Find all selected files and directories |
| 700 | std::list<CServerPath> selected_dirs; |
| 701 | std::list<int> selected_files; |
| 702 | ProcessSelection(selected_files, selected_dirs); |
| 703 | |
| 704 | if (selected_files.empty() && selected_dirs.empty()) |
| 705 | return; |
| 706 | |
| 707 | if (selected_dirs.size() > 0) |
| 708 | { |
| 709 | wxMessageBoxEx(_("Editing directories is not supported"), _("Editing search results"), wxICON_EXCLAMATION); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | CEditHandler* pEditHandler = CEditHandler::Get(); |
| 714 | if (!pEditHandler) |
| 715 | { |
| 716 | wxBell(); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | const wxString& localDir = pEditHandler->GetLocalDirectory(); |
| 721 | if (localDir.empty()) |
| 722 | { |
| 723 | wxMessageBoxEx(_("Could not get temporary directory to download file into."), _("Cannot edit file"), wxICON_STOP); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | const CServer* pServer = m_pState->GetServer(); |
| 728 | if (!pServer) |
| 729 | { |
| 730 | wxBell(); |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | if (selected_files.size() > 10) |
| 735 | { |
| 736 | CConditionalDialog dlg(this, CConditionalDialog::many_selected_for_edit, CConditionalDialog::yesno); |
| 737 | dlg.SetTitle(_("Confirmation needed")); |
| 738 | dlg.AddText(_("You have selected more than 10 files for editing, do you really want to continue?")); |
| 739 | |
| 740 | if (!dlg.Run()) |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | for (std::list<int>::const_iterator iter = selected_files.begin(); iter != selected_files.end(); ++iter) |
| 745 | { |
| 746 | const CDirentry& entry = m_results->m_fileData[*iter]; |
| 747 | const CServerPath path = m_results->m_fileData[*iter].path; |
| 748 | |
| 749 | bool dangerous = false; |
| 750 | bool program_exists = false; |
| 751 | wxString cmd = pEditHandler->CanOpen(CEditHandler::remote, entry.name, dangerous, program_exists); |
| 752 | if (cmd.empty()) |
| 753 | { |
| 754 | CNewAssociationDialog dlg(this); |
| 755 | if (!dlg.Run(entry.name)) |
| 756 | continue; |
| 757 | cmd = pEditHandler->CanOpen(CEditHandler::remote, entry.name, dangerous, program_exists); |
| 758 | if (cmd.empty()) |
| 759 | { |
| 760 | wxMessageBoxEx(wxString::Format(_("The file '%s' could not be opened:\nNo program has been associated on your system with this file type."), entry.name), _("Opening failed"), wxICON_EXCLAMATION); |
| 761 | continue; |
| 762 | } |
| 763 | } |
| 764 | if (!program_exists) |
| 765 | { |
| 766 | wxString msg = wxString::Format(_("The file '%s' cannot be opened:\nThe associated program (%s) could not be found.\nPlease check your filetype associations."), entry.name, cmd); |
| 767 | wxMessageBoxEx(msg, _("Cannot edit file"), wxICON_EXCLAMATION); |
| 768 | continue; |
| 769 | } |
| 770 | if (dangerous) |
| 771 | { |
| 772 | int res = wxMessageBoxEx(_("The selected file would be executed directly.\nThis can be dangerous and damage your system.\nDo you really want to continue?"), _("Dangerous filetype"), wxICON_EXCLAMATION | wxYES_NO); |
| 773 | if (res != wxYES) |
| 774 | { |
| 775 | wxBell(); |
| 776 | continue; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | CEditHandler::fileState state = pEditHandler->GetFileState(entry.name, path, *pServer); |
| 781 | switch (state) |
| 782 | { |
| 783 | case CEditHandler::download: |
| 784 | case CEditHandler::upload: |
| 785 | case CEditHandler::upload_and_remove: |
| 786 | case CEditHandler::upload_and_remove_failed: |
| 787 | wxMessageBoxEx(_("A file with that name is already being transferred."), _("Cannot view/edit selected file"), wxICON_EXCLAMATION); |
| 788 | continue; |
| 789 | case CEditHandler::removing: |
| 790 | if (!pEditHandler->Remove(entry.name, path, *pServer)) |
| 791 | { |
| 792 | wxMessageBoxEx(_("A file with that name is still being edited. Please close it and try again."), _("Selected file is already opened"), wxICON_EXCLAMATION); |
| 793 | continue; |
| 794 | } |
| 795 | break; |
| 796 | case CEditHandler::edit: |
| 797 | { |
| 798 | wxDialogEx dlg; |
| 799 | if (!dlg.Load(this, _T("ID_EDITEXISTING"))) |
| 800 | { |
| 801 | wxBell(); |
| 802 | continue; |
| 803 | } |
| 804 | dlg.SetChildLabel(XRCID("ID_FILENAME"), entry.name); |
| 805 | if (dlg.ShowModal() != wxID_OK) |
| 806 | { |
| 807 | wxBell(); |
| 808 | continue; |
| 809 | } |
| 810 | |
| 811 | if (XRCCTRL(dlg, "ID_REOPEN", wxRadioButton)->GetValue()) |
| 812 | { |
| 813 | pEditHandler->StartEditing(entry.name, path, *pServer); |
| 814 | continue; |
| 815 | } |
| 816 | else |
| 817 | { |
| 818 | if (!pEditHandler->Remove(entry.name, path, *pServer)) |
| 819 | { |
| 820 | wxMessageBoxEx(_("The selected file is still opened in some other program, please close it."), _("Selected file is still being edited"), wxICON_EXCLAMATION); |
| 821 | continue; |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | break; |
| 826 | default: |
| 827 | break; |
| 828 | } |
| 829 | |
| 830 | wxString file = entry.name; |
| 831 | if (!pEditHandler->AddFile(CEditHandler::remote, file, path, *pServer)) |
| 832 | { |
| 833 | wxFAIL; |
| 834 | wxBell(); |
| 835 | continue; |
| 836 | } |
| 837 | |
| 838 | wxString localFile; |
| 839 | CLocalPath localPath(file, &localFile); |
| 840 | |
| 841 | m_pQueue->QueueFile(false, true, entry.name, (localFile != entry.name) ? localFile : wxString(), |
| 842 | localPath, path, *pServer, entry.size, CEditHandler::remote, QueuePriority::high); |
| 843 | m_pQueue->QueueFile_Finish(true); |
| 844 | } |
| 845 | } |
| 846 | |