Index: src/interface/resources/xrc/menus.xrc
===================================================================
--- src/interface/resources/xrc/menus.xrc (revision 6055)
+++ src/interface/resources/xrc/menus.xrc (working copy)
@@ -597,6 +597,9 @@
+
Index: src/interface/search.cpp
===================================================================
--- src/interface/search.cpp (revision 6055)
+++ src/interface/search.cpp (working copy)
@@ -201,6 +201,7 @@
EVT_BUTTON(XRCID("ID_STOP"), CSearchDialog::OnStop)
EVT_CONTEXT_MENU(CSearchDialog::OnContextMenu)
EVT_MENU(XRCID("ID_MENU_SEARCH_DOWNLOAD"), CSearchDialog::OnDownload)
+EVT_MENU(XRCID("ID_MENU_SEARCH_EDIT"), CSearchDialog::OnEdit)
EVT_MENU(XRCID("ID_MENU_SEARCH_DELETE"), CSearchDialog::OnDelete)
EVT_CHAR_HOOK(CSearchDialog::OnCharHook)
END_EVENT_TABLE()
@@ -690,6 +691,159 @@
}
}
+void CSearchDialog::OnEdit(wxCommandEvent&)
+{
+ if (!m_pState->IsRemoteIdle())
+ return;
+
+ // Find all selected files and directories
+ std::list selected_dirs;
+ std::list selected_files;
+ ProcessSelection(selected_files, selected_dirs);
+
+ if (selected_files.empty() && selected_dirs.empty())
+ return;
+
+ if (selected_dirs.size() > 0)
+ {
+ wxMessageBoxEx(_("Editing directories is not supported"), _("Editing search results"), wxICON_EXCLAMATION);
+ return;
+ }
+
+ CEditHandler* pEditHandler = CEditHandler::Get();
+ if (!pEditHandler)
+ {
+ wxBell();
+ return;
+ }
+
+ const wxString& localDir = pEditHandler->GetLocalDirectory();
+ if (localDir.empty())
+ {
+ wxMessageBoxEx(_("Could not get temporary directory to download file into."), _("Cannot edit file"), wxICON_STOP);
+ return;
+ }
+
+ const CServer* pServer = m_pState->GetServer();
+ if (!pServer)
+ {
+ wxBell();
+ return;
+ }
+
+ if (selected_files.size() > 10)
+ {
+ CConditionalDialog dlg(this, CConditionalDialog::many_selected_for_edit, CConditionalDialog::yesno);
+ dlg.SetTitle(_("Confirmation needed"));
+ dlg.AddText(_("You have selected more than 10 files for editing, do you really want to continue?"));
+
+ if (!dlg.Run())
+ return;
+ }
+
+ for (std::list::const_iterator iter = selected_files.begin(); iter != selected_files.end(); ++iter)
+ {
+ const CDirentry& entry = m_results->m_fileData[*iter];
+ const CServerPath path = m_results->m_fileData[*iter].path;
+
+ bool dangerous = false;
+ bool program_exists = false;
+ wxString cmd = pEditHandler->CanOpen(CEditHandler::remote, entry.name, dangerous, program_exists);
+ if (cmd.empty())
+ {
+ CNewAssociationDialog dlg(this);
+ if (!dlg.Run(entry.name))
+ continue;
+ cmd = pEditHandler->CanOpen(CEditHandler::remote, entry.name, dangerous, program_exists);
+ if (cmd.empty())
+ {
+ 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);
+ continue;
+ }
+ }
+ if (!program_exists)
+ {
+ 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);
+ wxMessageBoxEx(msg, _("Cannot edit file"), wxICON_EXCLAMATION);
+ continue;
+ }
+ if (dangerous)
+ {
+ 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);
+ if (res != wxYES)
+ {
+ wxBell();
+ continue;
+ }
+ }
+
+ CEditHandler::fileState state = pEditHandler->GetFileState(entry.name, path, *pServer);
+ switch (state)
+ {
+ case CEditHandler::download:
+ case CEditHandler::upload:
+ case CEditHandler::upload_and_remove:
+ case CEditHandler::upload_and_remove_failed:
+ wxMessageBoxEx(_("A file with that name is already being transferred."), _("Cannot view/edit selected file"), wxICON_EXCLAMATION);
+ continue;
+ case CEditHandler::removing:
+ if (!pEditHandler->Remove(entry.name, path, *pServer))
+ {
+ wxMessageBoxEx(_("A file with that name is still being edited. Please close it and try again."), _("Selected file is already opened"), wxICON_EXCLAMATION);
+ continue;
+ }
+ break;
+ case CEditHandler::edit:
+ {
+ wxDialogEx dlg;
+ if (!dlg.Load(this, _T("ID_EDITEXISTING")))
+ {
+ wxBell();
+ continue;
+ }
+ dlg.SetChildLabel(XRCID("ID_FILENAME"), entry.name);
+ if (dlg.ShowModal() != wxID_OK)
+ {
+ wxBell();
+ continue;
+ }
+
+ if (XRCCTRL(dlg, "ID_REOPEN", wxRadioButton)->GetValue())
+ {
+ pEditHandler->StartEditing(entry.name, path, *pServer);
+ continue;
+ }
+ else
+ {
+ if (!pEditHandler->Remove(entry.name, path, *pServer))
+ {
+ wxMessageBoxEx(_("The selected file is still opened in some other program, please close it."), _("Selected file is still being edited"), wxICON_EXCLAMATION);
+ continue;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ wxString file = entry.name;
+ if (!pEditHandler->AddFile(CEditHandler::remote, file, path, *pServer))
+ {
+ wxFAIL;
+ wxBell();
+ continue;
+ }
+
+ wxString localFile;
+ CLocalPath localPath(file, &localFile);
+
+ m_pQueue->QueueFile(false, true, entry.name, (localFile != entry.name) ? localFile : wxString(),
+ localPath, path, *pServer, entry.size, CEditHandler::remote, QueuePriority::high);
+ m_pQueue->QueueFile_Finish(true);
+ }
+}
+
void CSearchDialog::OnDelete(wxCommandEvent&)
{
if (!m_pState->IsRemoteIdle())
Index: src/interface/search.h
===================================================================
--- src/interface/search.h (revision 6055)
+++ src/interface/search.h (working copy)
@@ -49,6 +49,7 @@
void OnStop(wxCommandEvent& event);
void OnContextMenu(wxContextMenuEvent& event);
void OnDownload(wxCommandEvent&);
+ void OnEdit(wxCommandEvent&);
void OnDelete(wxCommandEvent&);
void OnCharHook(wxKeyEvent& event);