26 template<>
FileManager* Mgr<FileManager>::instance =
nullptr;
96 if (stream.get() ==
nullptr || stream->IsOk() ==
false)
105 while ((chunk = stream->Read(tmp,
sizeof(tmp)).LastRead()))
107 mBuffer.insert(mBuffer.end(), tmp, tmp + chunk);
113 data = mBuffer.data();
115 len = mBuffer.size();
116 const char Zeros4[] =
"\0\0\0\0";
117 mBuffer.insert(mBuffer.end(), Zeros4, Zeros4 + 4);
123 : fileLoaderThread(false),
124 uncLoaderThread(false),
125 urlLoaderThread(false)
169 if (file.
length() > 2 && file[0] ==
_T(
'\\') && file[1] ==
_T(
'\\'))
184 #if defined ( __WIN32__ ) || defined ( _WIN64 ) 192 return ::MoveFileEx(wxFNCONV(old_name), wxFNCONV(new_name), MOVEFILE_REPLACE_EXISTING);
224 #if wxCHECK_VERSION(3, 0, 0) 232 #endif // wxCHECK_VERSION(3, 0, 0) 242 wxLstat( name, &buff );
245 f.
Create(temp,
true, buff.st_mode);
247 if (f.
Write(data, len) == len)
272 #if wxCHECK_VERSION(3, 0, 0) 281 #endif // wxCHECK_VERSION(3, 0, 0) 291 wxLstat( name, &buff );
294 f.
Create(temp,
true, buff.st_mode);
317 const char* mark =
nullptr;
318 size_t mark_length = 0;
324 mark =
"\xEF\xBB\xBF";
336 mark =
"\x00\x00\xFE\xFF";
340 mark =
"\xFF\xFE\x00\x00";
348 if (f.
Write(mark, mark_length) != mark_length)
355 #if defined(UNICODE) || defined(_UNICODE) 357 size_t inlen = data.
Len(), outlen = 0;
362 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
367 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
371 wxMBConvUTF16BE conv;
372 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
376 wxMBConvUTF16LE conv;
377 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
381 wxMBConvUTF32BE conv;
382 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
386 wxMBConvUTF32LE conv;
387 mbBuff = conv.cWC2MB(data.
c_str(), inlen, &outlen);
396 char* tmp =
new char[2*inlen];
401 outlen = strlen(mbBuff);
407 mbBuff = csconv.cWC2MB(data.
c_str(), inlen, &outlen);
413 return f.
Write(mbBuff, outlen) == outlen;
420 if (!buf || !(size = strlen(buf)))
422 buf = data.
mb_str(wxConvUTF8);
424 if (!buf || !(size = strlen(buf)))
426 cbMessageBox(
_T(
"The file could not be saved because it contains characters " 427 "that can neither be represented in your current code page, " 428 "nor be converted to UTF-8.\n" 429 "The latter should actually not be possible.\n\n" 430 "Please check your language/encoding settings and try saving again." ),
437 _(
"The saved document contained characters\n" 438 "which were illegal in the selected encoding.\n\n" 439 "The file's encoding has been changed to UTF-8\n" 440 "to prevent you from losing data."), 8000);
444 return f.
Write(buf, size) == size;
static void Display(const wxString &title, const wxString &message, unsigned int delay=5000, unsigned int hysteresis=1)
bool wxRenameFile(const wxString &file1, const wxString &file2, bool overwrite=true)
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
wxFileOffset Length() const
bool Exists(int flags=wxFILE_EXISTS_ANY) const
bool wxFileExists(const wxString &filename)
BackgroundThread urlLoaderThread
const int wxInvalidOffset
wxString & append(const wxString &str, size_t pos, size_t n)
const wxCharBuffer mb_str(const wxMBConv &conv=wxConvLibc) const
bool Save(const wxString &file, const wxString &data, wxFontEncoding encoding, bool bom)
bool Create(const wxString &filename, bool overwrite=false, int access=wxS_DEFAULT)
wxURLError GetError() const
EditorManager * GetEditorManager() const
virtual const wxString & GetFilename() const
Get the editor's filename (if applicable).
cbStyledTextCtrl * GetControl() const
Returns a pointer to the underlying cbStyledTextCtrl object (which itself is the wxWindows implementa...
void Queue(AbstractJob *j)
wxInputStream * GetInputStream()
const wxStringCharType * wx_str() const
BackgroundThread uncLoaderThread
void SetProxy(const wxString &url_proxy)
static bool Access(const wxString &name, wxFile::OpenMode mode)
const wxString & _(const wxString &string)
EditorBase * GetEditor(int index)
cbEditor * GetBuiltinEditor(EditorBase *eb)
cb_must_consume_result LoaderBase * Load(const wxString &file, bool reuseEditors=false)
Loads a file, once this function is called, the actually loading process is done in the worker thread...
ssize_t Read(void *buffer, size_t count)
static wxString GetProxy()
void operator()() override
bool SaveUTF8(const wxString &file, const char *data, size_t len)
void operator()() override
bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method=wxCONVERT_STRICT)
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
bool Convert(const char *input, char *output) const
wxString GetText() const
Retrieve all the text in the document.
BackgroundThread fileLoaderThread
size_t Write(const void *buffer, size_t count)
bool GetModified() const override
Returns true if editor is modified, false otherwise.
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
bool WriteWxStringToFile(wxFile &f, const wxString &data, wxFontEncoding encoding, bool bom)