Use ErrorHandler::HandleError, instead of creating own message box

Change-Id: Ib4aeb52db1d81d9e3dcc4e0c6c880be8982b8120
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180219
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2025-01-14 13:56:31 +05:00
parent 94e9c45d9a
commit 2e498d7dba
3 changed files with 13 additions and 13 deletions

View File

@ -29,7 +29,7 @@
#define STR_BUTTONSELECT NC_("STR_BUTTONSELECT", "~Select")
#define STR_PREVIEW NC_("STR_PREVIEW", "File Preview")
#define STR_DEFAULT_DIRECTORY NC_("STR_DEFAULT_DIRECTORY", "My Documents")
#define RID_FILEOPEN_NOTEXISTENTFILE NC_("RID_FILEOPEN_NOTEXISTENTFILE", "The file $name$ does not exist.\nMake sure you have entered the correct file name.")
#define RID_FILEOPEN_NOTEXISTENTFILE NC_("RID_FILEOPEN_NOTEXISTENTFILE", "The file $(ARG1) does not exist.\nMake sure you have entered the correct file name.")
#define STR_SVT_NEW_FOLDER NC_("STR_SVT_NEW_FOLDER", "Folder")
#define STR_SVT_NOREMOVABLEDEVICE NC_("STR_SVT_NOREMOVABLEDEVICE", "No removable storage device detected.\nMake sure it is plugged in properly and try again.")

View File

@ -37,6 +37,7 @@
#include <unotools/ucbhelper.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/viewoptions.hxx>
#include <svtools/ehdl.hxx>
#include <svtools/sfxecode.hxx>
#include <fpicker/strings.hrc>
@ -892,16 +893,14 @@ void SvtFileDialog::OpenHdl_Impl(void const * pVoid)
if ( !bExists )
{
OUString sError(FpsResId(RID_FILEOPEN_NOTEXISTENTFILE));
OUString sInvalidFile( aFileObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ) );
// transform the URL into system notation
osl_getSystemPathFromFileURL(sInvalidFile.pData, &sInvalidFile.pData);
sError = sError.replaceFirst( "$name$", sInvalidFile );
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
VclMessageType::Warning, VclButtonsType::Ok, sError));
xBox->run();
static constexpr ErrMsgCode ids[]
= { { RID_FILEOPEN_NOTEXISTENTFILE, ERRCODE_IO_NOTEXISTS }, { {}, {} } };
SfxErrorHandler handler(ids, ErrCodeArea::Io, ErrCodeArea::Io, FpsResLocale());
ErrorHandler::HandleError({ ERRCODE_IO_NOTEXISTS, sInvalidFile },
m_xDialog.get());
return;
}
}
@ -1489,10 +1488,10 @@ bool SvtFileDialog::PrepareExecute()
= aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_ONLY );
if ( xResultSet.is() && !xResultSet->next() )
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
VclMessageType::Warning, VclButtonsType::Ok,
FpsResId(STR_SVT_NOREMOVABLEDEVICE)));
xBox->run();
static constexpr ErrMsgCode ids[]
= { { STR_SVT_NOREMOVABLEDEVICE, ERRCODE_IO_INVALIDDEVICE }, { {}, {} } };
SfxErrorHandler handler(ids, ErrCodeArea::Io, ErrCodeArea::Io, FpsResLocale());
ErrorHandler::HandleError(ERRCODE_IO_INVALIDDEVICE, m_xDialog.get());
return false;
}
}

View File

@ -10,6 +10,7 @@
#include <unotools/resmgr.hxx>
inline OUString FpsResId(TranslateId aId) { return Translate::get(aId, Translate::Create("fps")); };
inline std::locale FpsResLocale() { return Translate::Create("fps"); }
inline OUString FpsResId(TranslateId aId) { return Translate::get(aId, FpsResLocale()); };
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */