Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code tweaks to 'rename open file' code.

  • Loading branch information...
commit c1bc163a52a84b03a0fb698079a89515105132bd 1 parent aca9810
Adam Vandenberg adamv authored
92 src/EditorFrame.cpp
View
@@ -1279,7 +1279,7 @@ EditorCtrl* EditorFrame::GetEditorCtrlFromPage(size_t page_idx) {
//if (page->IsKindOf(CLASSINFO(DiffPanel))) return ((DiffPanel*)page)->GetActiveEditor();
if (page->IsKindOf(CLASSINFO(EditorBundlePanel))) return ((EditorBundlePanel*)page)->GetEditor();
- else return (EditorCtrl*)page;
+ return (EditorCtrl*)page;
}
void EditorFrame::BringToFront() {
@@ -1609,7 +1609,7 @@ bool EditorFrame::OpenFile(const wxFileName& path, wxFontEncoding enc, const wxS
return DoOpenFile(filepath, enc, NULL, mate);
}
-void EditorFrame::UpdateRenamedFileIsOpen(const wxFileName& path, const wxFileName& newPath) {
+void EditorFrame::UpdateRenamedFile(const wxFileName& path, const wxFileName& newPath) {
// Check if there is a mirror that matches the file
const wxString filepath = path.GetFullPath();
@@ -1620,40 +1620,28 @@ void EditorFrame::UpdateRenamedFileIsOpen(const wxFileName& path, const wxFileNa
isMirror = catalyst.GetFileMirror(filepath, di, modifiedDate);
cxENDLOCK
- if(!isMirror) {
- return;
- }
+ if(!isMirror) return;
- // Check if the file is already open
- for (unsigned int i = 0; i < m_tabBar->GetPageCount(); ++i) {
- EditorCtrl* page = GetEditorCtrlFromPage(i);
+ unsigned int i;
+ EditorCtrl* existingControl = this->GetEditorCtrlFromFile(filepath, i);
+ if (!existingControl) return;
-#ifdef __WXMSW__
- if (filepath.CmpNoCase(page->GetPath()) == 0) { // paths on windows are case-insensitive
-#else
- if (filepath == page->GetPath()) {
-#endif
- cxLOCK_WRITE(m_catalyst)
- catalyst.SetFileMirror(newPath.GetFullPath(), di, modifiedDate);
- cxENDLOCK
+ cxLOCK_WRITE(m_catalyst)
+ catalyst.SetFileMirror(newPath.GetFullPath(), di, modifiedDate);
+ cxENDLOCK
- cxLOCKDOC_WRITE(page->GetDocument())
- doc.SetPropertyName(wxFileName(newPath.GetLongPath()).GetFullName());
- cxENDLOCK
+ cxLOCKDOC_WRITE(existingControl->GetDocument())
+ doc.SetPropertyName(wxFileName(newPath.GetLongPath()).GetFullName());
+ cxENDLOCK
- m_tabBar->SetSelection(i);
- page->SetPath(newPath.GetFullPath());
- UpdateWindowTitle();
- page->ReDraw();
-
- // Bring frame to front
- BringToFront();
- page->SetFocus();
- break;
- }
- }
+ m_tabBar->SetSelection(i);
+ existingControl->SetPath(newPath.GetFullPath());
+ UpdateWindowTitle();
+ existingControl->ReDraw();
- return;
+ // Bring frame to front
+ BringToFront();
+ existingControl->SetFocus();
}
bool EditorFrame::OpenRemoteFile(const wxString& url, const RemoteProfile* rp) {
@@ -1732,7 +1720,25 @@ bool EditorFrame::AskRemoteLogin(const RemoteProfile* rp) {
return true;
}
-bool EditorFrame::DoOpenFile(wxString filepath, wxFontEncoding enc, const RemoteProfile* rp, const wxString& mate) {
+EditorCtrl* EditorFrame::GetEditorCtrlFromFile(const wxString& filepath, unsigned int& page_idx) {
+ for (unsigned int i = 0; i < m_tabBar->GetPageCount(); ++i) {
+ EditorCtrl* editorCtrl = GetEditorCtrlFromPage(i);
+
+ // paths on windows are case-insensitive
+#ifdef __WXMSW__
+ if (filepath.CmpNoCase(editorCtrl->GetPath()) == 0) {
+#else
+ if (filepath == page->GetPath()) {
+#endif
+ page_idx = i;
+ return editorCtrl;
+ }
+ }
+
+ return NULL;
+}
+
+bool EditorFrame::DoOpenFile(const wxString& filepath, wxFontEncoding enc, const RemoteProfile* rp, const wxString& mate) {
wxBusyCursor busy;
bool isCurrent = false;
@@ -1744,7 +1750,7 @@ bool EditorFrame::DoOpenFile(wxString filepath, wxFontEncoding enc, const Remote
wxFAIL_MSG(wxT("No editorCtrl in OpenFile"));
AddTab();
}
- EditorCtrl* ec = editorCtrl;
+ EditorCtrl* ec = this->editorCtrl;
// Check if there is a mirror that matches the file
doc_id di;
@@ -1755,20 +1761,12 @@ bool EditorFrame::DoOpenFile(wxString filepath, wxFontEncoding enc, const Remote
cxENDLOCK
if(isMirror) {
- // Check if the file is already open
- for (unsigned int i = 0; i < m_tabBar->GetPageCount(); ++i) {
- EditorCtrl* page = GetEditorCtrlFromPage(i);
-
-#ifdef __WXMSW__
- if (filepath.CmpNoCase(page->GetPath()) == 0) { // paths on windows are case-insensitive
-#else
- if (filepath == page->GetPath()) {
-#endif
- m_tabBar->SetSelection(i);
- ec = editorCtrl;
- isCurrent = true;
- break;
- }
+ unsigned int i;
+ EditorCtrl* existingControl = this->GetEditorCtrlFromFile(filepath, i);
+ if (existingControl) {
+ m_tabBar->SetSelection(i);
+ ec = existingControl;
+ isCurrent = true;
}
}
5 src/EditorFrame.h
View
@@ -202,7 +202,7 @@ class EditorFrame : public KeyHookable<wxFrame>,
bool Open(const wxString& path, const wxString& mate=wxEmptyString); // file or project
virtual bool OpenFile(const wxFileName& path, wxFontEncoding enc=wxFONTENCODING_SYSTEM, const wxString& mate=wxEmptyString);
virtual bool OpenRemoteFile(const wxString& url, const RemoteProfile* rp=NULL);
- virtual void UpdateRenamedFileIsOpen(const wxFileName& path, const wxFileName& newPath);
+ virtual void UpdateRenamedFile(const wxFileName& path, const wxFileName& newPath);
bool OpenTxmtUrl(const wxString& url);
bool AskToSaveMulti(int keep_tab=-1);
@@ -289,6 +289,7 @@ class EditorFrame : public KeyHookable<wxFrame>,
void InitMemberSettings();
EditorCtrl* GetEditorCtrlFromPage(size_t page_idx);
+ EditorCtrl* GetEditorCtrlFromFile(const wxString& filepath, unsigned int& page_idx);
// Menu & statusdbar handling
wxMenu* GetBundleMenu();
@@ -299,7 +300,7 @@ class EditorFrame : public KeyHookable<wxFrame>,
void UpdateRecentFiles();
// Loading files
- bool DoOpenFile(wxString filepath, wxFontEncoding enc, const RemoteProfile* rp=NULL, const wxString& mate=wxEmptyString);
+ bool DoOpenFile(const wxString& filepath, wxFontEncoding enc, const RemoteProfile* rp=NULL, const wxString& mate=wxEmptyString);
// Changed files
void AskToReloadMulti(const vector<unsigned int>& pathToPages, const vector<wxDateTime>& modDates);
3  src/IFrameProjectService.h
View
@@ -8,7 +8,6 @@ class wxFileName;
class wxString;
class RemoteProfile;
class DirWatcher;
-class wxAuiNotebook;
// EditorFrame services as used by the ProjectPane
class IFrameProjectService : public IFrameRemoteThread {
@@ -17,7 +16,7 @@ class IFrameProjectService : public IFrameRemoteThread {
virtual bool OpenFile(const wxFileName& path, wxFontEncoding enc=wxFONTENCODING_SYSTEM, const wxString& mate=wxEmptyString) = 0;
virtual bool OpenRemoteFile(const wxString& url, const RemoteProfile* rp=NULL) = 0;
virtual bool CloseTab(unsigned int tab_id, bool removetab) = 0;
- virtual void UpdateRenamedFileIsOpen(const wxFileName& path, const wxFileName& newPath) = 0;
+ virtual void UpdateRenamedFile(const wxFileName& path, const wxFileName& newPath) = 0;
// Prompting for remote credentials.
virtual bool AskRemoteLogin(const RemoteProfile* rp) = 0;
3  src/ProjectPane.cpp
View
@@ -20,6 +20,7 @@
#include <wx/dir.h>
#include <wx/tokenzr.h>
#include <wx/artprov.h>
+#include <wx/aui/aui.h>
#include "IFrameProjectService.h"
#include "ProjectSettings.h"
@@ -1026,7 +1027,7 @@ void ProjectPane::OnEndEditItem(wxTreeEvent &event)
//m_projectService.OpenFile(new_path);
//m_projectService.CloseTab(1, true);
//wxAuiNotebook tabBar = m_projectService.GetTabBar();
- m_projectService.UpdateRenamedFileIsOpen(oldPath, new_path);
+ m_projectService.UpdateRenamedFile(oldPath, new_path);
}
}
1  src/ProjectPane.h
View
@@ -22,7 +22,6 @@
#include <wx/treectrl.h>
#include <wx/filename.h>
#include <wx/dnd.h>
-#include <wx/aui/aui.h>
#include <wx/imaglist.h>
#include "ProjectInfoHandler.h"
Please sign in to comment.
Something went wrong with that request. Please try again.