Fixed problems with new documents

This commit is contained in:
Zane U. Ji 2014-08-21 23:01:53 +08:00
parent 412479f400
commit 19dc55f89e
1 changed files with 24 additions and 33 deletions

View File

@ -1454,14 +1454,11 @@ void MyFrame::OnCloseAll ( wxCommandEvent& WXUNUSED ( event ) )
for ( size_t i = 0; i < maxTabs; ++i ) for ( size_t i = 0; i < maxTabs; ++i )
{ {
doc = ( XmlDoc * ) mainBook->GetPage ( i ); doc = ( XmlDoc * ) mainBook->GetPage ( i );
if ( doc ) if ( doc && !doc->getDirectory().empty() )
{ {
fullPath = doc->getFullFileName(); fullPath = doc->getFullFileName();
if ( !fullPath.empty() ) openTabsOnClose.Append ( fullPath );
{ openTabsOnClose.Append ( _T ( "|" ) );
openTabsOnClose.Append ( fullPath );
openTabsOnClose.Append ( _T ( "|" ) );
}
} }
} }
} }
@ -2347,7 +2344,7 @@ void MyFrame::OnExportMSWord ( wxCommandEvent& event )
WrapTempFileName wtfn ( _T ( "" ) ); WrapTempFileName wtfn ( _T ( "" ) );
wxString sourceFileName = doc->getFullFileName(); wxString sourceFileName = doc->getFullFileName();
if ( sourceFileName.empty() ) if ( doc->getDirectory().empty() )
{ {
sourceFileName = wtfn.wideName(); sourceFileName = wtfn.wideName();
std::fstream ofs ( wtfn.name().c_str() ); std::fstream ofs ( wtfn.name().c_str() );
@ -2424,7 +2421,7 @@ void MyFrame::OnBrowser ( wxCommandEvent& WXUNUSED ( event ) )
wxString sourceFileName = doc->getFullFileName(); wxString sourceFileName = doc->getFullFileName();
WrapTempFileName wtfn ( sourceFileName, _T ( ".html" ) ); WrapTempFileName wtfn ( sourceFileName, _T ( ".html" ) );
if ( sourceFileName.empty() || doc->GetModify() ) if ( doc->getDirectory().empty() || doc->GetModify() )
{ {
sourceFileName = wtfn.wideName(); sourceFileName = wtfn.wideName();
@ -2954,12 +2951,9 @@ void MyFrame::OnOpen ( wxCommandEvent& event )
XmlDoc *doc; XmlDoc *doc;
if ( ( doc = getActiveDocument() ) != NULL ) if ( ( doc = getActiveDocument() ) != NULL )
{ {
defaultFile = doc->getFullFileName(); defaultDir = doc->getDirectory();
if ( !defaultFile.empty() ) if ( defaultDir.empty() )
{ defaultDir = mLastDir;
wxFileName fn ( defaultFile );
defaultDir = fn.GetPath();
}
} }
else else
defaultDir = mLastDir; defaultDir = mLastDir;
@ -3519,14 +3513,14 @@ void MyFrame::save()
if ( ( doc = getActiveDocument() ) == NULL ) if ( ( doc = getActiveDocument() ) == NULL )
return; return;
wxString fileName; if ( doc->getDirectory().empty() )
if ( ( fileName = doc->getFullFileName() ) == _T ( "" ) )
{ {
wxCommandEvent event; wxCommandEvent event;
OnSaveAs ( event ); OnSaveAs ( event );
return; return;
} }
wxString fileName = doc->getFullFileName();
if ( !saveFile ( doc, fileName, true ) ) if ( !saveFile ( doc, fileName, true ) )
{} // handle messages in saveFile {} // handle messages in saveFile
} }
@ -3560,11 +3554,10 @@ void MyFrame::saveAs()
wxString defaultFile, defaultDir; wxString defaultFile, defaultDir;
defaultFile = doc->getFullFileName(); defaultFile = doc->getFullFileName();
if ( !defaultFile.empty() ) defaultDir = doc->getDirectory();
{ if ( defaultDir.empty() )
wxFileName fn ( defaultFile ); defaultDir = mLastDir;
defaultDir = fn.GetPath();
}
auto_ptr<wxFileDialog> fd ( new wxFileDialog ( auto_ptr<wxFileDialog> fd ( new wxFileDialog (
this, this,
_ ( "Save As" ), _ ( "Save As" ),
@ -3631,7 +3624,7 @@ void MyFrame::OnUpdateReload ( wxUpdateUIEvent& event )
event.Enable ( false ); event.Enable ( false );
return; return;
} }
event.Enable ( !doc->getFullFileName().empty() ); event.Enable ( !doc->getDirectory().empty() );
} }
void MyFrame::OnUpdateCutCopy ( wxUpdateUIEvent& event ) void MyFrame::OnUpdateCutCopy ( wxUpdateUIEvent& event )
@ -3655,7 +3648,7 @@ void MyFrame::OnUpdateSavedOnly ( wxUpdateUIEvent& event )
event.Enable ( false ); event.Enable ( false );
return; return;
} }
event.Enable ( !doc->getFullFileName().empty() ); event.Enable ( !doc->getDirectory().empty() );
} }
void MyFrame::OnUpdateDocRange ( wxUpdateUIEvent& event ) void MyFrame::OnUpdateDocRange ( wxUpdateUIEvent& event )
@ -3813,11 +3806,10 @@ void MyFrame::OnValidateRelaxNG ( wxCommandEvent& event )
wxString defaultFile, defaultDir; wxString defaultFile, defaultDir;
defaultFile = doc->getFullFileName(); defaultFile = doc->getFullFileName();
if ( !defaultFile.empty() ) defaultDir = doc->getDirectory();
{ if ( defaultDir.empty() )
wxFileName fn ( defaultFile ); defaultDir = mLastDir;
defaultDir = fn.GetPath();
}
AssociateDialog ad ( AssociateDialog ad (
this, this,
_ ( "Select RELAX NG grammar" ), _ ( "Select RELAX NG grammar" ),
@ -4104,11 +4096,10 @@ void MyFrame::OnXslt ( wxCommandEvent& event )
wxString defaultFile, defaultDir; wxString defaultFile, defaultDir;
defaultFile = doc->getFullFileName(); defaultFile = doc->getFullFileName();
if ( !defaultFile.empty() ) defaultDir = doc->getDirectory();
{ if ( defaultDir.empty() )
wxFileName fn ( defaultFile ); defaultDir = mLastDir;
defaultDir = fn.GetPath();
}
AssociateDialog ad ( AssociateDialog ad (
this, this,
_ ( "Select stylesheet" ), _ ( "Select stylesheet" ),