@pymethod |PyCEditView|LoadFile|Loads a file into the view.
| 757 | |
| 758 | // @pymethod |PyCEditView|LoadFile|Loads a file into the view. |
| 759 | static PyObject * |
| 760 | ui_edit_window_load_file(PyObject *self, PyObject *args) |
| 761 | { |
| 762 | USES_CONVERSION; |
| 763 | TCHAR *fileName; |
| 764 | PyObject *obfileName; |
| 765 | // @pyparm string|fileName||The name of the file to be loaded. |
| 766 | if (!PyArg_ParseTuple(args, "O:LoadFile", &obfileName)) |
| 767 | return NULL; |
| 768 | |
| 769 | CPythonEditView *pView; |
| 770 | if (!(pView=GetEditViewPtr(self))) |
| 771 | return NULL; |
| 772 | if (!PyWinObject_AsTCHAR(obfileName, &fileName, FALSE)) |
| 773 | return NULL; |
| 774 | CFile file; |
| 775 | CFileException fe; |
| 776 | if (!file.Open(fileName, CFile::modeRead | CFile::shareDenyWrite, &fe)) { |
| 777 | PyWinObject_FreeTCHAR(fileName); |
| 778 | long errCode = fe.m_lOsError; |
| 779 | CString csMessage = GetAPIErrorString(errCode); |
| 780 | if (csMessage.GetLength()){ |
| 781 | LPTSTR msg=csMessage.GetBuffer(csMessage.GetLength()); |
| 782 | PyErr_SetString(PyExc_IOError, T2A(msg)); |
| 783 | csMessage.ReleaseBuffer(); |
| 784 | } |
| 785 | else |
| 786 | PyErr_SetString(PyExc_IOError, "Unknown IO error?"); |
| 787 | return NULL; |
| 788 | } |
| 789 | PyWinObject_FreeTCHAR(fileName); |
| 790 | |
| 791 | GUI_BGN_SAVE; |
| 792 | pView->DeleteContents(); |
| 793 | CArchive loadArchive(&file, CArchive::load | CArchive::bNoFlushOnDelete); |
| 794 | TRY |
| 795 | { |
| 796 | pView->BeginWaitCursor(); |
| 797 | pView->SerializeRaw(loadArchive); // load me |
| 798 | loadArchive.Close(); |
| 799 | file.Close(); |
| 800 | } |
| 801 | CATCH_ALL(e) |
| 802 | { |
| 803 | file.Abort(); // will not throw an exception |
nothing calls this directly
no test coverage detected