Normalize file names before going any further
This commit is contained in:
parent
b12b7fadc4
commit
19b7a74641
|
@ -715,8 +715,8 @@ xmlChar *WrapLibxml::xmlFileNameToURL ( const wxString &fileName )
|
|||
return NULL;
|
||||
|
||||
wxFileName fn ( fileName );
|
||||
fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE);
|
||||
wxString url = fn.GetFullPath(wxPATH_NATIVE);
|
||||
fn.Normalize();
|
||||
wxString url = fn.GetFullPath();
|
||||
|
||||
return xmlPathToURI ( ( xmlChar * ) ( const char * ) url.utf8_str() );
|
||||
}
|
||||
|
|
|
@ -2983,19 +2983,13 @@ void MyFrame::OnOpen ( wxCommandEvent& event )
|
|||
break;
|
||||
}
|
||||
|
||||
bool MyFrame::openFile ( wxString& fileName, bool largeFile )
|
||||
bool MyFrame::openFile ( const wxString &file, bool largeFile )
|
||||
{
|
||||
#ifndef __WXMSW__
|
||||
// truncate string up to file:/ portion added by GNOME
|
||||
wxString filePrefix = _T ( "file:" );
|
||||
int index = fileName.Find ( filePrefix.c_str() );
|
||||
if ( index != -1 )
|
||||
{
|
||||
fileName = fileName.Mid ( ( size_t ) index + filePrefix.Length() );
|
||||
}
|
||||
#endif
|
||||
wxFileName fn = WrapLibxml::URLToFileName ( file );
|
||||
fn.Normalize();
|
||||
|
||||
if ( !wxFileExists ( fileName ) )
|
||||
wxString fileName = fn.GetFullPath();
|
||||
if ( !fn.IsFileReadable() )
|
||||
{
|
||||
wxString message;
|
||||
message.Printf ( _ ( "Cannot open %s." ), fileName.c_str() );
|
||||
|
@ -3012,15 +3006,6 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
|
|||
return false;
|
||||
}
|
||||
|
||||
wxString directory, name, extension;
|
||||
wxFileName::SplitPath ( fileName, NULL, &directory, &name, &extension );
|
||||
|
||||
if ( !extension.empty() )
|
||||
{
|
||||
name += _T ( "." );
|
||||
name += extension;
|
||||
}
|
||||
|
||||
wxString wideError;
|
||||
pair<int, int> posPair;
|
||||
XmlDoc *doc;
|
||||
|
@ -3238,21 +3223,16 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
|
|||
#endif
|
||||
|
||||
doc->setFullFileName ( fileName );
|
||||
doc->setShortFileName ( name );
|
||||
doc->setDirectory ( directory );
|
||||
openFileSet.insert ( fileName );
|
||||
history.AddFileToHistory ( fileName );
|
||||
updateFileMenu();
|
||||
wxFileName ofn ( fileName );
|
||||
doc->setLastModified ( ofn.GetModificationTime() );
|
||||
|
||||
mainBook->AddPage ( ( wxWindow * ) doc, name, _T ( "" ) );
|
||||
mainBook->AddPage ( ( wxWindow * ) doc, fn.GetFullName(), _T ( "" ) );
|
||||
}
|
||||
statusProgress ( wxEmptyString );
|
||||
|
||||
mainBook->Layout();
|
||||
|
||||
wxFileName fn ( fileName );
|
||||
doc->setLastModified ( fn.GetModificationTime() );
|
||||
doc->SetFocus();
|
||||
|
||||
|
@ -3614,8 +3594,6 @@ void MyFrame::saveAs()
|
|||
openFileSet.erase ( doc->getFullFileName() );
|
||||
|
||||
doc->setFullFileName ( path );
|
||||
doc->setShortFileName ( name );
|
||||
doc->setDirectory ( directory );
|
||||
|
||||
history.AddFileToHistory ( path ); // update history
|
||||
updateFileMenu();
|
||||
|
|
|
@ -349,7 +349,7 @@ class MyFrame : public wxFrame
|
|||
bool forcePane = false );
|
||||
|
||||
// public to allow IPC access
|
||||
bool openFile ( wxString& fileName, bool largeFile = false );
|
||||
bool openFile ( const wxString &fileName, bool largeFile = false );
|
||||
bool isOpen ( const wxString& fileName );
|
||||
bool activateTab ( const wxString& fileName );
|
||||
void reloadTab();
|
||||
|
|
|
@ -51,37 +51,38 @@ XmlDoc::XmlDoc (
|
|||
style )
|
||||
{ }
|
||||
|
||||
wxString& XmlDoc::getDirectory()
|
||||
wxString XmlDoc::getDirectory()
|
||||
{
|
||||
return directory;
|
||||
return mFileName.GetPath();
|
||||
}
|
||||
wxString& XmlDoc::getFullFileName()
|
||||
|
||||
wxString XmlDoc::getFullFileName()
|
||||
{
|
||||
return fullFileName;
|
||||
return mFileName.GetFullPath();
|
||||
}
|
||||
wxString& XmlDoc::getShortFileName()
|
||||
|
||||
wxString XmlDoc::getShortFileName()
|
||||
{
|
||||
return shortFileName;
|
||||
return mFileName.GetFullName();
|
||||
}
|
||||
wxDateTime XmlDoc::getLastModified()
|
||||
|
||||
const wxDateTime& XmlDoc::getLastModified()
|
||||
{
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
void XmlDoc::setDirectory ( const wxString& s )
|
||||
{
|
||||
directory = s;
|
||||
}
|
||||
|
||||
void XmlDoc::setFullFileName ( const wxString &s )
|
||||
{
|
||||
fullFileName = s;
|
||||
mFileName.Assign ( s );
|
||||
mFileName.Normalize();
|
||||
}
|
||||
|
||||
void XmlDoc::setShortFileName ( const wxString &s )
|
||||
{
|
||||
shortFileName = s;
|
||||
mFileName.SetFullName ( s );
|
||||
}
|
||||
void XmlDoc::setLastModified ( wxDateTime dt )
|
||||
|
||||
void XmlDoc::setLastModified ( const wxDateTime& dt )
|
||||
{
|
||||
lastModified = dt;
|
||||
}
|
||||
|
|
14
src/xmldoc.h
14
src/xmldoc.h
|
@ -23,6 +23,7 @@
|
|||
#include <wx/wx.h>
|
||||
#include <wx/datetime.h>
|
||||
#include <wx/print.h>
|
||||
#include <wx/filename.h>
|
||||
#include "xmlctrl.h"
|
||||
|
||||
class XmlDoc : public XmlCtrl
|
||||
|
@ -43,16 +44,15 @@ class XmlDoc : public XmlCtrl
|
|||
const wxPoint& position = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = 0 );
|
||||
wxString& getDirectory();
|
||||
wxString& getFullFileName();
|
||||
wxString& getShortFileName();
|
||||
wxDateTime getLastModified();
|
||||
void setDirectory ( const wxString& s );
|
||||
wxString getDirectory();
|
||||
wxString getFullFileName();
|
||||
wxString getShortFileName();
|
||||
const wxDateTime& getLastModified();
|
||||
void setFullFileName ( const wxString &s );
|
||||
void setShortFileName ( const wxString &s );
|
||||
void setLastModified ( wxDateTime dt );
|
||||
void setLastModified ( const wxDateTime &dt );
|
||||
private:
|
||||
wxString directory, fullFileName, shortFileName;
|
||||
wxFileName mFileName;
|
||||
wxDateTime lastModified;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue