patch from Janos Vegh for improved template handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2393 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-05-10 16:01:45 +00:00
parent 121a3581d3
commit 6de2f8b9da

View File

@@ -43,7 +43,7 @@
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/list.h" #include "wx/list.h"
#include "wx/filedlg.h" #include "wx/filedlg.h"
#include <wx/intl.h> #include "wx/intl.h"
#endif #endif
#ifdef __WXGTK__ #ifdef __WXGTK__
@@ -178,14 +178,14 @@ bool wxDocument::DeleteAllViews()
return TRUE; return TRUE;
} }
wxView *wxDocument::GetFirstView(void) const wxView *wxDocument::GetFirstView() const
{ {
if (m_documentViews.Number() == 0) if (m_documentViews.Number() == 0)
return (wxView *) NULL; return (wxView *) NULL;
return (wxView *)m_documentViews.First()->Data(); return (wxView *)m_documentViews.First()->Data();
} }
wxDocManager *wxDocument::GetDocumentManager(void) const wxDocManager *wxDocument::GetDocumentManager() const
{ {
return m_documentTemplate->GetDocumentManager(); return m_documentTemplate->GetDocumentManager();
} }
@@ -372,7 +372,7 @@ bool wxDocument::GetPrintableName(wxString& buf) const
} }
} }
wxWindow *wxDocument::GetDocumentWindow(void) const wxWindow *wxDocument::GetDocumentWindow() const
{ {
wxView *view = GetFirstView(); wxView *view = GetFirstView();
if (view) if (view)
@@ -576,7 +576,7 @@ wxPrintout *wxView::OnCreatePrintout()
{ {
return new wxDocPrintout(this); return new wxDocPrintout(this);
} }
#endif #endif // wxUSE_PRINTING_ARCHITECTURE
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDocTemplate // wxDocTemplate
@@ -649,6 +649,13 @@ wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
} }
} }
// The default (very primitive) format detection: check is the extension is
// that of the template
bool wxDocTemplate::FileMatchesTemplate(const wxString& path)
{
return GetDefaultExtension().IsSameAs(FindExtension(path));
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDocManager // wxDocManager
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -847,7 +854,7 @@ void wxDocManager::OnRedo(wxCommandEvent& WXUNUSED(event))
doc->GetCommandProcessor()->Redo(); doc->GetCommandProcessor()->Redo();
} }
wxView *wxDocManager::GetCurrentView(void) const wxView *wxDocManager::GetCurrentView() const
{ {
if (m_currentView) if (m_currentView)
return m_currentView; return m_currentView;
@@ -1034,7 +1041,7 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
return FALSE; return FALSE;
} }
wxDocument *wxDocManager::GetCurrentDocument(void) const wxDocument *wxDocManager::GetCurrentDocument() const
{ {
if (m_currentView) if (m_currentView)
return m_currentView->GetDocument(); return m_currentView->GetDocument();
@@ -1112,7 +1119,7 @@ void wxDocManager::FileHistoryAddFilesToMenu()
m_fileHistory->AddFilesToMenu(); m_fileHistory->AddFilesToMenu();
} }
int wxDocManager::GetNoHistoryFiles(void) const int wxDocManager::GetNoHistoryFiles() const
{ {
if (m_fileHistory) if (m_fileHistory)
return m_fileHistory->GetNoHistoryFiles(); return m_fileHistory->GetNoHistoryFiles();
@@ -1121,24 +1128,18 @@ int wxDocManager::GetNoHistoryFiles(void) const
} }
// Given a path, try to find a matching template. Won't always work, of // Find out the document template via matching in the document file format
// course. // against that of the template
wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path) wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
{ {
wxString theExt = FindExtension(path);
if (!theExt)
return (wxDocTemplate *) NULL;
wxDocTemplate *theTemplate = (wxDocTemplate *) NULL; wxDocTemplate *theTemplate = (wxDocTemplate *) NULL;
if (m_templates.Number() == 1)
return (wxDocTemplate *)m_templates.First()->Data();
// Find the template which this extension corresponds to // Find the template which this extension corresponds to
int i; int i;
for (i = 0; i < m_templates.Number(); i++) for (i = 0; i < m_templates.Number(); i++)
{ {
wxDocTemplate *temp = (wxDocTemplate *)m_templates.Nth(i)->Data(); wxDocTemplate *temp = (wxDocTemplate *)m_templates.Nth(i)->Data();
if (wxStrcmp(temp->GetDefaultExtension(), theExt) == 0) if ( temp->FileMatchesTemplate(path) )
{ {
theTemplate = temp; theTemplate = temp;
break; break;
@@ -1180,8 +1181,11 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
wxString descrBuf = _T("*.*"); wxString descrBuf = _T("*.*");
#endif #endif
wxString pathTmp = wxFileSelector(_("Select a file"), _T(""), _T(""), _T(""), int FilterIndex = 0;
descrBuf, 0, wxTheApp->GetTopWindow()); wxString pathTmp = wxFileSelectorEx(_("Select a file"),
_T(""), _T(""), _T(""),
&FilterIndex,
descrBuf, 0, wxTheApp->GetTopWindow());
if (!pathTmp.IsEmpty()) if (!pathTmp.IsEmpty())
{ {
@@ -1195,6 +1199,9 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
// one. We really want to know exactly which template was // one. We really want to know exactly which template was
// chosen by using a more advanced file selector. // chosen by using a more advanced file selector.
wxDocTemplate *theTemplate = FindTemplateForPath(path); wxDocTemplate *theTemplate = FindTemplateForPath(path);
if ( !theTemplate )
theTemplate = templates[FilterIndex];
return theTemplate; return theTemplate;
} }
else else
@@ -1654,14 +1661,14 @@ bool wxCommandProcessor::Redo()
return FALSE; return FALSE;
} }
bool wxCommandProcessor::CanUndo(void) const bool wxCommandProcessor::CanUndo() const
{ {
if (m_currentCommand) if (m_currentCommand)
return ((wxCommand *)m_currentCommand->Data())->CanUndo(); return ((wxCommand *)m_currentCommand->Data())->CanUndo();
return FALSE; return FALSE;
} }
bool wxCommandProcessor::CanRedo(void) const bool wxCommandProcessor::CanRedo() const
{ {
if ((m_currentCommand != (wxNode*) NULL) && (m_currentCommand->Next() == (wxNode*) NULL)) if ((m_currentCommand != (wxNode*) NULL) && (m_currentCommand->Next() == (wxNode*) NULL))
return FALSE; return FALSE;