Ticket #8039: edit-from-remote-search-window.patch

File edit-from-remote-search-window.patch, 6.2 KB (added by Bruno Ramos, 10 years ago)

[Patch] Add View/Edit from the remote search window

  • src/interface/resources/xrc/menus.xrc

     
    597597    <object class="wxMenuItem" name="ID_MENU_SEARCH_DOWNLOAD">
    598598      <label>&amp;Download...</label>
    599599    </object>
     600    <object class="wxMenuItem" name="ID_MENU_SEARCH_EDIT">
     601      <label>&amp;View/Edit</label>
     602    </object>
    600603    <object class="wxMenuItem" name="ID_MENU_SEARCH_DELETE">
    601604      <label>D&amp;elete</label>
    602605    </object>
  • src/interface/search.cpp

     
    201201EVT_BUTTON(XRCID("ID_STOP"), CSearchDialog::OnStop)
    202202EVT_CONTEXT_MENU(CSearchDialog::OnContextMenu)
    203203EVT_MENU(XRCID("ID_MENU_SEARCH_DOWNLOAD"), CSearchDialog::OnDownload)
     204EVT_MENU(XRCID("ID_MENU_SEARCH_EDIT"), CSearchDialog::OnEdit)
    204205EVT_MENU(XRCID("ID_MENU_SEARCH_DELETE"), CSearchDialog::OnDelete)
    205206EVT_CHAR_HOOK(CSearchDialog::OnCharHook)
    206207END_EVENT_TABLE()
     
    690691    }
    691692}
    692693
     694void 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
    693847void CSearchDialog::OnDelete(wxCommandEvent&)
    694848{
    695849    if (!m_pState->IsRemoteIdle())
  • src/interface/search.h

     
    4949    void OnStop(wxCommandEvent& event);
    5050    void OnContextMenu(wxContextMenuEvent& event);
    5151    void OnDownload(wxCommandEvent&);
     52    void OnEdit(wxCommandEvent&);
    5253    void OnDelete(wxCommandEvent&);
    5354    void OnCharHook(wxKeyEvent& event);
    5455