mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
[win-nix] refactoring
This commit is contained in:
@ -558,6 +558,10 @@ bool CAscApplicationManagerWrapper::processCommonEvent(NSEditorApi::CAscCefMenuE
|
||||
break;
|
||||
}
|
||||
|
||||
case ASC_MENU_EVENT_TYPE_CEF_LOCALFILE_SAVE: {
|
||||
CEditorTools::processLocalFileSaveAs(event);
|
||||
return true; }
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
@ -87,3 +87,7 @@ void CCefEventsGate::onDocumentLoadFinished(int uid)
|
||||
void CCefEventsGate::onDocumentReady(int)
|
||||
{
|
||||
}
|
||||
|
||||
void CCefEventsGate::onLocalFileSaveAs(void *)
|
||||
{
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ public slots:
|
||||
virtual void onDocumentType(int id, int type);
|
||||
|
||||
virtual void onFileLocation(int id, QString path) = 0;
|
||||
virtual void onLocalFileSaveAs(void *) = 0;
|
||||
virtual void onLocalFileSaveAs(void *);
|
||||
|
||||
virtual void onEditorAllowedClose(int) = 0;
|
||||
virtual void onKeyDown(void *);
|
||||
|
||||
@ -34,12 +34,12 @@
|
||||
#include "qascprinter.h"
|
||||
#include "cprintprogress.h"
|
||||
#include "cascapplicationmanagerwrapper.h"
|
||||
#include "applicationmanager_events.h"
|
||||
#include "cfiledialog.h"
|
||||
#include "defines.h"
|
||||
#include "utils.h"
|
||||
#include "cfilechecker.h"
|
||||
#include "OfficeFileFormats.h"
|
||||
#include "cmessage.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
@ -235,4 +235,56 @@ namespace CEditorTools
|
||||
|
||||
return etUndefined;
|
||||
}
|
||||
|
||||
auto processLocalFileSaveAs(const CAscCefMenuEvent * event) -> void {
|
||||
CAscLocalSaveFileDialog * pData = static_cast<CAscLocalSaveFileDialog *>(event->m_pData);
|
||||
|
||||
QFileInfo info(QString::fromStdWString(pData->get_Path()));
|
||||
if ( !info.fileName().isEmpty() ) {
|
||||
bool _keep_path = false;
|
||||
QString _full_path;
|
||||
if ( info.exists() )
|
||||
_full_path = info.absoluteFilePath();
|
||||
else _full_path = Utils::lastPath(LOCAL_PATH_SAVE) + "/" + info.fileName(),
|
||||
_keep_path = true;
|
||||
|
||||
ParentHandle _parent = AscAppManager::windowHandleFromId(event->m_nSenderId);
|
||||
CFileDialogWrapper dlg(_parent);
|
||||
dlg.setFormats(pData->get_SupportFormats());
|
||||
|
||||
CAscLocalSaveFileDialog * pSaveData = new CAscLocalSaveFileDialog();
|
||||
pSaveData->put_Id(pData->get_Id());
|
||||
pSaveData->put_Path(L"");
|
||||
|
||||
if ( dlg.modalSaveAs(_full_path) ) {
|
||||
if ( _keep_path )
|
||||
Utils::keepLastPath(LOCAL_PATH_SAVE, QFileInfo(_full_path).absoluteDir().absolutePath());
|
||||
|
||||
bool _allowed = true;
|
||||
switch ( dlg.getFormat() ) {
|
||||
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV: {
|
||||
CMessage mess(_parent, CMessageOpts::moButtons::mbOkDefCancel);
|
||||
_allowed = MODAL_RESULT_CUSTOM == mess.warning(QCoreApplication::translate("CEditorWindow", "Some data will lost.<br>Continue?"));
|
||||
break; }
|
||||
default: break;
|
||||
}
|
||||
|
||||
if ( _allowed ) {
|
||||
pSaveData->put_Path(_full_path.toStdWString());
|
||||
int format = dlg.getFormat() > 0 ? dlg.getFormat() :
|
||||
AscAppManager::GetFileFormatByExtentionForSave(pSaveData->get_Path());
|
||||
|
||||
pSaveData->put_FileType(format > -1 ? format : 0);
|
||||
}
|
||||
}
|
||||
|
||||
CAscMenuEvent* pEvent = new CAscMenuEvent(ASC_MENU_EVENT_TYPE_CEF_LOCALFILE_SAVE_PATH);
|
||||
pEvent->m_pData = pSaveData;
|
||||
|
||||
AscAppManager::getInstance().Apply(pEvent);
|
||||
|
||||
// RELEASEINTERFACE(pData)
|
||||
// RELEASEINTERFACE(pEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +61,7 @@ namespace CEditorTools
|
||||
|
||||
auto createEditorPanel(const COpenOptions& opts, const QRect& rect = QRect()) -> CTabPanel *;
|
||||
auto editorTypeFromFormat(int format) -> AscEditorType;
|
||||
auto processLocalFileSaveAs(const NSEditorApi::CAscCefMenuEvent * event) -> void;
|
||||
}
|
||||
|
||||
#endif // CEDITORTOOLS_H
|
||||
|
||||
@ -428,56 +428,6 @@ const QObject * CEditorWindow::receiver()
|
||||
return d_ptr.get();
|
||||
}
|
||||
|
||||
void CEditorWindow::onLocalFileSaveAs(void * d)
|
||||
{
|
||||
CAscLocalSaveFileDialog * pData = static_cast<CAscLocalSaveFileDialog *>(d);
|
||||
|
||||
QFileInfo info(QString::fromStdWString(pData->get_Path()));
|
||||
if ( !info.fileName().isEmpty() ) {
|
||||
bool _keep_path = false;
|
||||
QString _full_path;
|
||||
|
||||
if ( info.exists() ) _full_path = info.absoluteFilePath();
|
||||
else _full_path = Utils::lastPath(LOCAL_PATH_SAVE) + "/" + info.fileName(), _keep_path = true;
|
||||
|
||||
CFileDialogWrapper dlg(handle());
|
||||
dlg.setFormats(pData->get_SupportFormats());
|
||||
|
||||
CAscLocalSaveFileDialog * pSaveData = new CAscLocalSaveFileDialog();
|
||||
pSaveData->put_Id(pData->get_Id());
|
||||
pSaveData->put_Path(L"");
|
||||
|
||||
if ( dlg.modalSaveAs(_full_path) ) {
|
||||
if ( _keep_path )
|
||||
Utils::keepLastPath(LOCAL_PATH_SAVE, QFileInfo(_full_path).absoluteDir().absolutePath());
|
||||
|
||||
bool _allowed = true;
|
||||
if ( dlg.getFormat() == AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV ) {
|
||||
CMessage mess(handle(), CMessageOpts::moButtons::mbOkDefCancel);
|
||||
_allowed = MODAL_RESULT_CUSTOM == mess.warning(tr("Some data will lost.<br>Continue?"));
|
||||
}
|
||||
|
||||
if ( _allowed ) {
|
||||
pSaveData->put_Path(_full_path.toStdWString());
|
||||
int format = dlg.getFormat() > 0 ? dlg.getFormat() :
|
||||
AscAppManager::GetFileFormatByExtentionForSave(pSaveData->get_Path());
|
||||
|
||||
pSaveData->put_FileType(format > -1 ? format : 0);
|
||||
}
|
||||
}
|
||||
|
||||
CAscMenuEvent* pEvent = new CAscMenuEvent(ASC_MENU_EVENT_TYPE_CEF_LOCALFILE_SAVE_PATH);
|
||||
pEvent->m_pData = pSaveData;
|
||||
|
||||
AscAppManager::getInstance().Apply(pEvent);
|
||||
|
||||
// RELEASEINTERFACE(pData)
|
||||
// RELEASEINTERFACE(pEvent)
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pData);
|
||||
}
|
||||
|
||||
QString CEditorWindow::documentName() const
|
||||
{
|
||||
return d_ptr.get()->panel()->data()->title(true);
|
||||
|
||||
@ -88,8 +88,6 @@ protected:
|
||||
void setScreenScalingFactor(int) override;
|
||||
int calcTitleCaptionWidth() override;
|
||||
|
||||
void onLocalFileSaveAs(void *);
|
||||
|
||||
private slots:
|
||||
void onClickButtonHome();
|
||||
|
||||
|
||||
@ -451,11 +451,6 @@ public:
|
||||
AscAppManager::getInstance().commonEvents().signal(&_event);
|
||||
}
|
||||
|
||||
void onLocalFileSaveAs(void * d) override
|
||||
{
|
||||
window->onLocalFileSaveAs(d);
|
||||
}
|
||||
|
||||
void onScreenScalingFactor(int f)
|
||||
{
|
||||
if ( window->isCustomWindowStyle() ) {
|
||||
|
||||
@ -1056,51 +1056,6 @@ void CMainPanel::onDocumentPrint(void * opts)
|
||||
|
||||
void CMainPanel::onLocalFileSaveAs(void * d)
|
||||
{
|
||||
CAscLocalSaveFileDialog * pData = static_cast<CAscLocalSaveFileDialog *>(d);
|
||||
|
||||
QFileInfo info( QString::fromStdWString(pData->get_Path()) );
|
||||
if ( !info.fileName().isEmpty() ) {
|
||||
bool _keep_path = false;
|
||||
QString fullPath;
|
||||
if ( info.exists() ) fullPath = info.absoluteFilePath();
|
||||
else fullPath = Utils::lastPath(LOCAL_PATH_SAVE) + "/" + info.fileName(), _keep_path = true;
|
||||
|
||||
CFileDialogWrapper dlg(TOP_NATIVE_WINDOW_HANDLE);
|
||||
dlg.setFormats(pData->get_SupportFormats());
|
||||
|
||||
CAscLocalSaveFileDialog * pSaveData = new CAscLocalSaveFileDialog();
|
||||
pSaveData->put_Id(pData->get_Id());
|
||||
pSaveData->put_Path(L"");
|
||||
|
||||
if ( dlg.modalSaveAs(fullPath) ) {
|
||||
if ( _keep_path )
|
||||
Utils::keepLastPath(LOCAL_PATH_SAVE, QFileInfo(fullPath).absoluteDir().absolutePath());
|
||||
|
||||
bool _allowed = true;
|
||||
if ( dlg.getFormat() == AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV ) {
|
||||
CMessage mess(TOP_NATIVE_WINDOW_HANDLE, CMessageOpts::moButtons::mbOkDefCancel);
|
||||
_allowed = MODAL_RESULT_CUSTOM == mess.warning(tr("Some data will lost.<br>Continue?"));
|
||||
}
|
||||
|
||||
if ( _allowed ) {
|
||||
pSaveData->put_Path(fullPath.toStdWString());
|
||||
int format = dlg.getFormat() > 0 ? dlg.getFormat() :
|
||||
AscAppManager::GetFileFormatByExtentionForSave(pSaveData->get_Path());
|
||||
|
||||
pSaveData->put_FileType(format > -1 ? format : 0);
|
||||
}
|
||||
}
|
||||
|
||||
CAscMenuEvent* pEvent = new CAscMenuEvent(ASC_MENU_EVENT_TYPE_CEF_LOCALFILE_SAVE_PATH);
|
||||
pEvent->m_pData = pSaveData;
|
||||
|
||||
AscAppManager::getInstance().Apply(pEvent);
|
||||
|
||||
// RELEASEINTERFACE(pData)
|
||||
// RELEASEINTERFACE(pEvent)
|
||||
}
|
||||
|
||||
RELEASEINTERFACE(pData);
|
||||
}
|
||||
|
||||
void CMainPanel::onFullScreen(int id, bool apply)
|
||||
|
||||
Reference in New Issue
Block a user