void CContextManager::DestroyAllStates() { m_current_context = -1; NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false); while (!m_contexts.empty()) { CState* pState = m_contexts.back(); m_contexts.pop_back(); NotifyHandlers(pState, STATECHANGE_REMOVECONTEXT, _T(""), 0, false); delete pState; } }
bool CState::SetRemoteDir(const CDirectoryListing *pDirectoryListing, bool modified /*=false*/) { if (!pDirectoryListing) { if (modified) return false; if (m_pDirectoryListing) { const CDirectoryListing* pOldListing = m_pDirectoryListing; m_pDirectoryListing = 0; NotifyHandlers(STATECHANGE_REMOTE_DIR); delete pOldListing; } return true; } if (modified) { if (!m_pDirectoryListing || m_pDirectoryListing->path != pDirectoryListing->path) { // We aren't interested in these listings delete pDirectoryListing; return true; } } else COptions::Get()->SetOption(OPTION_LASTSERVERPATH, pDirectoryListing->path.GetSafePath()); if (m_pDirectoryListing && m_pDirectoryListing->path == pDirectoryListing->path && pDirectoryListing->m_failed) { // We still got an old listing, no need to display the new one delete pDirectoryListing; return true; } const CDirectoryListing *pOldListing = m_pDirectoryListing; m_pDirectoryListing = pDirectoryListing; if (!modified) NotifyHandlers(STATECHANGE_REMOTE_DIR); else NotifyHandlers(STATECHANGE_REMOTE_DIR_MODIFIED); delete pOldListing; return true; }
void CState::RefreshLocalFile(wxString file) { wxFileName fn(file); if (!fn.IsOk()) return; if (!fn.IsAbsolute()) return; wxString path = fn.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); if (path == _T("")) return; if (path == m_localDir) { file = fn.GetFullName(); if (file == _T("")) return; } else if (path.Left(m_localDir.Len()) == m_localDir) { path = path.Mid(m_localDir.Len()); int pos = path.Find(wxFileName::GetPathSeparator()); if (pos < 1) return; file = path.Left(pos); } NotifyHandlers(STATECHANGE_LOCAL_REFRESH_FILE, file); }
bool CState::SetSyncBrowse(bool enable, const CServerPath& assumed_remote_root /*=CServerPath()*/) { if (enable != m_sync_browse.local_root.empty()) return enable; if (!enable) { wxASSERT(assumed_remote_root.empty()); m_sync_browse.local_root.clear(); m_sync_browse.remote_root.clear(); m_sync_browse.is_changing = false; NotifyHandlers(STATECHANGE_SYNC_BROWSE); return false; } if (!m_pDirectoryListing && assumed_remote_root.empty()) { NotifyHandlers(STATECHANGE_SYNC_BROWSE); return false; } m_sync_browse.is_changing = false; m_sync_browse.local_root = m_localDir; if (assumed_remote_root.empty()) m_sync_browse.remote_root = m_pDirectoryListing->path; else { m_sync_browse.remote_root = assumed_remote_root; m_sync_browse.is_changing = true; m_sync_browse.compare = false; } while (m_sync_browse.local_root.HasParent() && m_sync_browse.remote_root.HasParent() && m_sync_browse.local_root.GetLastSegment() == m_sync_browse.remote_root.GetLastSegment()) { m_sync_browse.local_root.MakeParent(); m_sync_browse.remote_root = m_sync_browse.remote_root.GetParent(); } NotifyHandlers(STATECHANGE_SYNC_BROWSE); return true; }
CState* CContextManager::CreateState(CMainFrame* pMainFrame) { wxASSERT(pMainFrame); CState* pState = new CState(pMainFrame); m_contexts.push_back(pState); NotifyHandlers(pState, STATECHANGE_NEWCONTEXT, _T(""), 0, false); return pState; }
void CContextManager::SetCurrentContext(CState* pState) { if (GetCurrentContext() == pState) return; for (unsigned int i = 0; i < m_contexts.size(); i++) { if (m_contexts[i] != pState) continue; m_current_context = i; NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false); } }
void CContextManager::DestroyState(CState* pState) { for (unsigned int i = 0; i < m_contexts.size(); i++) { if (m_contexts[i] != pState) continue; m_contexts.erase(m_contexts.begin() + i); if ((int)i < m_current_context) m_current_context--; else if ((int)i == m_current_context) { if (i >= m_contexts.size()) m_current_context--; NotifyHandlers(GetCurrentContext(), STATECHANGE_CHANGEDCONTEXT, _T(""), 0, false); } break; } NotifyHandlers(pState, STATECHANGE_REMOVECONTEXT, _T(""), 0, false); delete pState; }
bool CState::SetLocalDir(wxString dir, wxString *error /*=0*/) { dir = Canonicalize(m_localDir, dir, error); if (dir == _T("")) return false; m_localDir = dir; COptions::Get()->SetOption(OPTION_LASTLOCALDIR, dir); NotifyHandlers(STATECHANGE_LOCAL_DIR); return true; }
void CState::LocalDirCreated(const CLocalPath& path) { if (!path.IsSubdirOf(m_localDir)) return; wxString next_segment = path.GetPath().Mid(m_localDir.GetPath().Len()); int pos = next_segment.Find(CLocalPath::path_separator); if (pos <= 0) { // Shouldn't ever come true return; } // Current local path is /foo/ // Called with /foo/bar/baz/ // -> Refresh /foo/bar/ next_segment = next_segment.Left(pos); NotifyHandlers(STATECHANGE_LOCAL_REFRESH_FILE, next_segment); }
void CState::SetServer(const CServer* server) { if (m_pServer) { if (server && *server == *m_pServer && server->GetName() == m_pServer->GetName() && server->MaximumMultipleConnections() == m_pServer->MaximumMultipleConnections()) { // Nothing changes return; } SetRemoteDir(0); delete m_pServer; delete m_pCertificate; m_pCertificate = 0; delete m_pSftpEncryptionInfo; m_pSftpEncryptionInfo = 0; } if (server) { if (m_last_server != *server) m_last_path.Clear(); m_last_server = *server; m_pServer = new CServer(*server); const wxString& name = server->GetName(); if (!name.IsEmpty()) m_title = name + _T(" - ") + server->FormatServer(); else m_title = server->FormatServer(); } else { m_pServer = 0; m_title = _("Not connected"); } m_successful_connect = false; NotifyHandlers(STATECHANGE_SERVER); }
void CState::RefreshLocalFile(wxString file) { wxString file_name; CLocalPath path(file, &file_name); if (path.empty()) return; if (file_name.empty()) { if (!path.HasParent()) return; path.MakeParent(&file_name); wxASSERT(!file_name.empty()); } if (path != m_localDir) return; NotifyHandlers(STATECHANGE_LOCAL_REFRESH_FILE, file_name); }
void CState::RefreshLocal() { NotifyHandlers(STATECHANGE_LOCAL_DIR); }
bool CState::SetRemoteDir(std::shared_ptr<CDirectoryListing> const& pDirectoryListing, bool modified) { if (!pDirectoryListing) { SetSyncBrowse(false); if (modified) return false; if (m_pDirectoryListing) { m_pDirectoryListing = 0; NotifyHandlers(STATECHANGE_REMOTE_DIR); } m_previouslyVisitedRemoteSubdir = _T(""); return true; } wxASSERT(pDirectoryListing->m_firstListTime.IsValid()); if (pDirectoryListing && m_pDirectoryListing && pDirectoryListing->path == m_pDirectoryListing->path.GetParent()) m_previouslyVisitedRemoteSubdir = m_pDirectoryListing->path.GetLastSegment(); else m_previouslyVisitedRemoteSubdir = _T(""); if (modified) { if (!m_pDirectoryListing || m_pDirectoryListing->path != pDirectoryListing->path) { // We aren't interested in these listings return true; } } else m_last_path = pDirectoryListing->path; if (m_pDirectoryListing && m_pDirectoryListing->path == pDirectoryListing->path && pDirectoryListing->failed()) { // We still got an old listing, no need to display the new one return true; } m_pDirectoryListing = pDirectoryListing; if (!modified) NotifyHandlers(STATECHANGE_REMOTE_DIR); else NotifyHandlers(STATECHANGE_REMOTE_DIR_MODIFIED); if (m_sync_browse.is_changing && !modified) { m_sync_browse.is_changing = false; if (m_pDirectoryListing->path != m_sync_browse.remote_root && !m_pDirectoryListing->path.IsSubdirOf(m_sync_browse.remote_root, false)) { SetSyncBrowse(false); wxString msg = wxString::Format(_("Current remote directory (%s) is not below the synchronization root (%s).\nSynchronized browsing has been disabled."), m_pDirectoryListing->path.GetPath(), m_sync_browse.remote_root.GetPath()); wxMessageBoxEx(msg, _("Synchronized browsing")); } else { CLocalPath local_path = GetSynchronizedDirectory(m_pDirectoryListing->path); if (local_path.empty()) { SetSyncBrowse(false); wxString msg = wxString::Format(_("Could not obtain corresponding local directory for the remote directory '%s'.\nSynchronized browsing has been disabled."), m_pDirectoryListing->path.GetPath()); wxMessageBoxEx(msg, _("Synchronized browsing")); return true; } wxString error; if (!local_path.Exists(&error)) { SetSyncBrowse(false); wxString msg = error + _T("\n") + _("Synchronized browsing has been disabled."); wxMessageBoxEx(msg, _("Synchronized browsing")); return true; } m_localDir = local_path; COptions::Get()->SetOption(OPTION_LASTLOCALDIR, m_localDir.GetPath()); NotifyHandlers(STATECHANGE_LOCAL_DIR); if (m_sync_browse.compare) m_pComparisonManager->CompareListings(); } } return true; }
void CState::SetSecurityInfo(CSftpEncryptionNotification const& info) { m_pCertificate.reset(); m_pSftpEncryptionInfo = make_unique<CSftpEncryptionNotification>(info); NotifyHandlers(STATECHANGE_ENCRYPTION); }
bool CState::SetLocalDir(const wxString& dir, wxString *error /*=0*/) { if (m_sync_browse.is_changing) { wxMessageBox(_T("Cannot change directory, there already is a synchronized browsing operation in progress."), _("Synchronized browsing")); return false; } CLocalPath p(m_localDir); #ifdef __WXMSW__ if (dir == _T("..") && !p.HasParent() && p.HasLogicalParent()) { // Parent of C:\ is drive list if (!p.MakeParent()) return false; } else #endif if (!p.ChangePath(dir)) return false; if (!p.Exists(error)) return false; if (!m_sync_browse.local_root.empty()) { wxASSERT(m_pServer); if (p != m_sync_browse.local_root && !p.IsSubdirOf(m_sync_browse.local_root)) { wxString msg = wxString::Format(_("The local directory '%s' is not below the synchronization root (%s).\nDisable synchronized browsing and continue changing the local directory?"), p.GetPath().c_str(), m_sync_browse.local_root.GetPath().c_str()); if (wxMessageBox(msg, _("Synchronized browsing"), wxICON_QUESTION | wxYES_NO) != wxYES) return false; SetSyncBrowse(false); } else if (!IsRemoteIdle()) { wxString msg(_("A remote operation is in progress and synchronized browsing is enabled.\nDisable synchronized browsing and continue changing the local directory?")); if (wxMessageBox(msg, _("Synchronized browsing"), wxICON_QUESTION | wxYES_NO) != wxYES) return false; SetSyncBrowse(false); } else { CServerPath remote_path = GetSynchronizedDirectory(p); if (remote_path.IsEmpty()) { SetSyncBrowse(false); wxString msg = wxString::Format(_("Could not obtain corresponding remote directory for the local directory '%s'.\nSynchronized browsing has been disabled."), p.GetPath().c_str()); wxMessageBox(msg, _("Synchronized browsing")); return false; } m_sync_browse.is_changing = true; m_sync_browse.compare = m_pComparisonManager->IsComparing(); CListCommand *pCommand = new CListCommand(remote_path); m_pCommandQueue->ProcessCommand(pCommand); return true; } } m_localDir = p; COptions::Get()->SetOption(OPTION_LASTLOCALDIR, m_localDir.GetPath()); NotifyHandlers(STATECHANGE_LOCAL_DIR); return true; }
void CState::ApplyCurrentFilter() { NotifyHandlers(STATECHANGE_APPLYFILTER); }
void CState::LinkIsNotDir(const CServerPath& path, const wxString& subdir) { m_sync_browse.is_changing = false; NotifyHandlers(STATECHANGE_REMOTE_LINKNOTDIR, subdir, &path); }
bool CState::SetLocalDir(CLocalPath const& dir, wxString *error, bool rememberPreviousSubdir) { if (m_sync_browse.is_changing) { wxMessageBoxEx(_T("Cannot change directory, there already is a synchronized browsing operation in progress."), _("Synchronized browsing")); return false; } if (!dir.Exists(error)) return false; if (!m_sync_browse.local_root.empty()) { wxASSERT(m_pServer); if (dir != m_sync_browse.local_root && !dir.IsSubdirOf(m_sync_browse.local_root)) { wxString msg = wxString::Format(_("The local directory '%s' is not below the synchronization root (%s).\nDisable synchronized browsing and continue changing the local directory?"), dir.GetPath(), m_sync_browse.local_root.GetPath()); if (wxMessageBoxEx(msg, _("Synchronized browsing"), wxICON_QUESTION | wxYES_NO) != wxYES) return false; SetSyncBrowse(false); } else if (!IsRemoteIdle()) { wxString msg(_("A remote operation is in progress and synchronized browsing is enabled.\nDisable synchronized browsing and continue changing the local directory?")); if (wxMessageBoxEx(msg, _("Synchronized browsing"), wxICON_QUESTION | wxYES_NO) != wxYES) return false; SetSyncBrowse(false); } else { CServerPath remote_path = GetSynchronizedDirectory(dir); if (remote_path.empty()) { SetSyncBrowse(false); wxString msg = wxString::Format(_("Could not obtain corresponding remote directory for the local directory '%s'.\nSynchronized browsing has been disabled."), dir.GetPath()); wxMessageBoxEx(msg, _("Synchronized browsing")); return false; } m_sync_browse.is_changing = true; m_sync_browse.compare = m_pComparisonManager->IsComparing(); CListCommand *pCommand = new CListCommand(remote_path); m_pCommandQueue->ProcessCommand(pCommand); return true; } } if (dir == m_localDir.GetParent() && rememberPreviousSubdir) { #ifdef __WXMSW__ if (dir.GetPath() == _T("\\")) { m_previouslyVisitedLocalSubdir = m_localDir.GetPath(); m_previouslyVisitedLocalSubdir.RemoveLast(); } else #endif m_previouslyVisitedLocalSubdir = m_localDir.GetLastSegment(); } else m_previouslyVisitedLocalSubdir = _T(""); m_localDir = dir; COptions::Get()->SetOption(OPTION_LASTLOCALDIR, m_localDir.GetPath()); NotifyHandlers(STATECHANGE_LOCAL_DIR); return true; }