Permalink
Browse files

Global function GetAppPaths()

Introduce a global function "GetAppPaths" to get the IAppPaths interface
from eApp. This eliminates the need to do ugly dynamic_cast<> calls to
get at this information.

Also, moved function to create a temporary file over to the IAppPaths
interface and out of eDocumentPath.
  • Loading branch information...
1 parent 1526575 commit 1b1a24350a19f9a1bd253f34aced1e9b642336f6 @adamv adamv committed Oct 15, 2009
Showing with 36 additions and 26 deletions.
  1. +2 −2 src/BundleManager.cpp
  2. +1 −1 src/CygwinDlg.cpp
  3. +2 −2 src/EditorCtrl.cpp
  4. +1 −1 src/EditorFrame.cpp
  5. +1 −1 src/ExecuteWin.cpp
  6. +5 −2 src/IAppPaths.h
  7. +1 −1 src/PreviewDlg.cpp
  8. +3 −3 src/ShellRunner.cpp
  9. +16 −1 src/eApp.cpp
  10. +3 −2 src/eApp.h
  11. +1 −8 src/eDocumentPath.cpp
  12. +0 −2 src/eDocumentPath.h
View
@@ -412,7 +412,7 @@ void BundleManager::OnDeleteButton(wxCommandEvent& WXUNUSED(event)) {
if (m_currentBundleInfo->id == -1) {
// We have just installed it, so just delete dir
- const wxString installPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH + m_currentBundle->m_name;
+ const wxString installPath = GetAppPaths().AppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH + m_currentBundle->m_name;
DelTree(installPath);
m_installedBundles.erase(p);
@@ -479,7 +479,7 @@ bool BundleManager::InstallBundle() {
path.SetTimes(NULL, &m_currentBundle->m_modDate, NULL);
// Delete installed version (if any)
- wxString installPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH;
+ wxString installPath = GetAppPaths().AppDataPath() + wxT("InstalledBundles") + wxFILE_SEP_PATH;
if (!wxDirExists(installPath)) wxMkdir(installPath);
installPath += m_currentBundle->m_name;
if (wxDirExists(installPath)) DelTree(installPath);
View
@@ -67,7 +67,7 @@ CygwinDlg::CygwinDlg(wxWindow *parent, cxCygwinDlgMode mode):
}
void CygwinDlg::OnButtonOk(wxCommandEvent& WXUNUSED(event)) {
- const wxString appPath = wxGetApp().GetAppPath();
+ const wxString appPath = wxGetApp().AppPath();
const cxCygwinInstallMode install_mode = m_autoRadio->GetValue() ? cxCYGWIN_AUTO : cxCYGWIN_MANUAL;
new CygwinInstallThread(install_mode, appPath);
View
@@ -2880,7 +2880,7 @@ bool EditorCtrl::SetDocument(const doc_id& di, const wxString& path, const Remot
// If the path points to a remote file, we have to save it to a temp bufferfile first.
if (eDocumentPath::IsRemotePath(path)) {
m_remoteProfile = rp ? rp : m_parentFrame.GetRemoteProfile(path, false);
- m_path = eDocumentPath::GetAppDataTempPath();
+ m_path = GetAppPaths().CreateTempAppDataFile();
m_remotePath = path;
cxLOCKDOC_WRITE(m_doc)
@@ -6980,7 +6980,7 @@ void EditorCtrl::SetEnv(cxEnv& env, bool isUnix, const tmBundle* bundle) {
env.SetEnv(eGetSettings().env);
// Add app keys
- env.AddSystemVars(isUnix, dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath());
+ env.AddSystemVars(isUnix, GetAppPaths().AppPath());
// Add document/editor keys
View
@@ -1838,7 +1838,7 @@ wxString EditorFrame::DownloadFile(const wxString& url, const RemoteProfile* rp)
wxASSERT(rp && rp->IsValid());
// Create temp buffer file
- const wxString buffPath = eDocumentPath::GetAppDataTempPath();
+ const wxString buffPath = GetAppPaths().CreateTempAppDataFile();
// Download file
while(1) {
View
@@ -47,7 +47,7 @@ int cxExecute::Execute(const wxString& command, const vector<char>& input) {
wxFile logFile;
if (m_debugLog) {
// Create temp file with command
- wxFileName logfilePath = wxGetApp().GetAppDataPath();
+ wxFileName logfilePath = wxGetApp().AppDataPath();
logfilePath.SetFullName(wxT("tmcmd.log"));
logFile.Open(logfilePath.GetFullPath(), wxFile::write);
if (logFile.IsOpened()) {
View
@@ -3,8 +3,11 @@
class IAppPaths {
public:
- virtual const wxString& GetAppPath() const = 0;
- virtual const wxString& GetAppDataPath() const = 0;
+ virtual const wxString& AppPath() const = 0;
+ virtual const wxString& AppDataPath() const = 0;
+ virtual wxString CreateTempAppDataFile() = 0;
};
+IAppPaths& GetAppPaths(void);
+
#endif // __IAPPPATHS_H__
View
@@ -134,7 +134,7 @@ PreviewDlg::PreviewDlg(EditorFrame& parent)
// Do we have XULRunner installed?
bool xulrunner = false;
- const wxString xulrunner_path = wxGetApp().GetAppPath() + wxFILE_SEP_PATH + wxT("xr");
+ const wxString xulrunner_path = wxGetApp().AppPath() + wxFILE_SEP_PATH + wxT("xr");
if (wxDirExists(xulrunner_path)) {
xulrunner = wxWebControl::IsInitialized() || wxWebControl::InitEngine(xulrunner_path);
m_webcontrol = new wxWebControl(this, ID_WEBCONNECT);
View
@@ -26,7 +26,7 @@ long ShellRunner::RawShell(const vector<char>& command, const vector<char>& inpu
#endif
// Create temp file with command
- wxFileName tmpfilePath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath();
+ wxFileName tmpfilePath = GetAppPaths().AppDataPath();
tmpfilePath.SetFullName(isUnix ? wxT("tmcmd") : wxT("tmcmd.bat"));
wxFile tmpfile(tmpfilePath.GetFullPath(), wxFile::write);
if (!tmpfile.IsOpened()) return -1;
@@ -69,7 +69,7 @@ long ShellRunner::RawShell(const vector<char>& command, const vector<char>& inpu
s_bashCmd = wxT("bash \"") + tmpfilePath.GetFullPath() + wxT("\"");
#endif
- wxFileName initPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath();
+ wxFileName initPath = GetAppPaths().AppPath();
initPath.AppendDir(wxT("Support"));
initPath.AppendDir(wxT("lib"));
initPath.SetFullName(wxT("bash_init.sh"));
@@ -114,7 +114,7 @@ wxString ShellRunner::GetBashCommand(const wxString& cmd, cxEnv& env) {
#endif
if (s_bashEnv.empty()) {
- wxFileName initPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath();
+ wxFileName initPath = GetAppPaths().AppPath();
initPath.AppendDir(wxT("Support"));
initPath.AppendDir(wxT("lib"));
initPath.SetFullName(wxT("bash_init.sh"));
View
@@ -178,7 +178,7 @@ bool eApp::OnInit() {
// Parse syntax files
wxLogDebug(wxT("Loading bundles"));
- m_pListHandler = new PListHandler(GetAppPath(), GetAppDataPath(), clearBundleCache);
+ m_pListHandler = new PListHandler(m_appPath, m_appDataPath, clearBundleCache);
m_pSyntaxHandler = new TmSyntaxHandler(m_pCatalyst->GetDispatcher(), *m_pListHandler);
// Create the main windows
@@ -713,6 +713,16 @@ wxString eApp::GetAppTitle() {
return title;
}
+const wxString& eApp::AppPath() const {return m_appPath;}
+const wxString& eApp::AppDataPath() const {return m_appDataPath;}
+
+
+wxString eApp::CreateTempAppDataFile() {
+ const wxString tempPath = m_appPath + wxT("temp") + wxFILE_SEP_PATH;
+ if (!wxDirExists(tempPath)) wxMkdir(tempPath);
+ return wxFileName::CreateTempFileName(tempPath);
+}
+
void eApp::OnUpdatesAvailable(wxCommandEvent& WXUNUSED(event)) {
// Ask user if he wants to download new release
const int answer = wxMessageBox(_("A new release of e is available.\nDo you wish to go the the website to download it now?"), wxT("Program update!"), wxYES_NO|wxICON_EXCLAMATION, GetTopFrame());
@@ -752,3 +762,8 @@ void eApp::OnAssertFailure(const wxChar *file, int line, const wxChar *cond, con
eSettings& eGetSettings(void) {
return wxGetApp().GetSettings();
}
+
+// Global function to get eApp's App Path data.
+ IAppPaths& GetAppPaths(void) {
+ return wxGetApp();
+}
View
@@ -62,8 +62,9 @@ class eApp : public wxApp,
virtual bool ExecuteCmd(const wxString& cmd);
virtual bool ExecuteCmd(const wxString& cmd, wxString& result);
- virtual const wxString& GetAppPath() const {return m_appPath;};
- virtual const wxString& GetAppDataPath() const {return m_appDataPath;};
+ virtual const wxString& AppPath() const;
+ virtual const wxString& AppDataPath() const;
+ virtual wxString CreateTempAppDataFile();
// Settings functions
const wxLongLong& GetId() const {cxLOCK_READ((*m_catalyst)) return catalyst.GetId(); cxENDLOCK};
View
@@ -324,7 +324,7 @@ bool eDocumentPath::InitCygwin(const bool silent) {
}
// Get last cygwin update, and see if we need to reinstall
- const wxString supportPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppPath() + wxT("support\\bin\\cygwin-post-install.sh");
+ const wxString supportPath = GetAppPaths().AppPath() + wxT("support\\bin\\cygwin-post-install.sh");
const wxFileName supportFile(supportPath);
wxDateTime stampTime = get_last_cygwin_update();
@@ -369,10 +369,3 @@ bool eDocumentPath::IsRemotePath(const wxString& path) {
bool eDocumentPath::IsBundlePath(const wxString& path) {
return (path.StartsWith(wxT("bundle://")));
}
-
-wxString eDocumentPath::GetAppDataTempPath() {
- // Create temp buffer file
- const wxString tempPath = dynamic_cast<IAppPaths*>(wxTheApp)->GetAppDataPath() + wxT("temp") + wxFILE_SEP_PATH;
- if (!wxDirExists(tempPath)) wxMkdir(tempPath);
- return wxFileName::CreateTempFileName(tempPath);
-}
View
@@ -31,8 +31,6 @@ class eDocumentPath
static bool IsDotDirectory(const wxString& path);
- static wxString GetAppDataTempPath();
-
static bool MakeWritable(const wxString& path);
static FILE_PERMISSIONS GetPermissions(const wxString& path);
static bool SetPermissions(const wxString& path, FILE_PERMISSIONS permissions);

0 comments on commit 1b1a243

Please sign in to comment.