From 25af63d7d7b85f99f5327d1b97a3ac24fbfd93f0 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 15 Mar 2005 19:24:20 +0000 Subject: Fixed drag and drop of files. git-svn-id: http://svn.leocad.org/trunk@391 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- common/project.cpp | 65 +++++++++++++++++++++++------------------------------- common/project.h | 21 +++++++++--------- win/Mainfrm.cpp | 16 ++++++++++++++ win/Mainfrm.h | 1 + 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/common/project.cpp b/common/project.cpp index 8bb36c5..b478600 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1597,6 +1597,31 @@ bool Project::OnNewDocument() return true; } +bool Project::OpenProject(const char* FileName) +{ + if (!SaveModified()) + return false; // Leave the original one + +// CWaitCursor wait; + bool WasModified = IsModified(); + SetModifiedFlag(false); // Not dirty for open + + if (!OnOpenDocument(FileName)) + { + // Check if we corrupted the original document + if (!IsModified()) + SetModifiedFlag(WasModified); + else + OnNewDocument(); + + return false; // Open failed + } + + SetPathName(FileName, true); + + return true; +} + bool Project::OnOpenDocument (const char* lpszPathName) { FileDisk file; @@ -3626,24 +3651,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam) if (SystemDoDialog(LC_DLG_FILE_OPEN_PROJECT, filename)) { - if (!SaveModified()) - return; // leave the original one - -// CWaitCursor wait; - bool bWasModified = IsModified(); - SetModifiedFlag(false); // not dirty for open - - if (!OnOpenDocument(filename)) - { - // check if we corrupted the original document - if (!IsModified()) - SetModifiedFlag(bWasModified); - else - OnNewDocument(); - - return; // open failed - } - SetPathName(filename, true); + OpenProject(filename); } } break; @@ -4573,26 +4581,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam) case LC_FILE_RECENT: { - if (!SaveModified()) - break; // leave the original one - -// CWaitCursor wait; - bool bWasModified = IsModified(); - SetModifiedFlag(false); // not dirty for open - String filename = main_window->GetMRU (nParam); - - if (!OnOpenDocument (filename)) - { - // check if we corrupted the original document - if (!IsModified ()) - SetModifiedFlag (bWasModified); - else - OnNewDocument (); - - main_window->RemoveFromMRU (nParam); - return; // open failed - } - SetPathName (filename, true); + OpenProject(main_window->GetMRU(nParam)); } break; case LC_EDIT_UNDO: diff --git a/common/project.h b/common/project.h index 8c57eb7..42529ae 100644 --- a/common/project.h +++ b/common/project.h @@ -283,19 +283,20 @@ protected: Texture* m_pBackground; protected: - // File load/save implementation. - bool DoSave(char* lpszPathName, bool bReplace); - bool DoFileSave(); - bool FileLoad(File* file, bool bUndo, bool bMerge); - void FileSave(File* file, bool bUndo); - void FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray& FileArray); - void FileReadMPD(File& MPD, PtrArray& FileArray) const; + // File load/save implementation. + bool DoSave(char* lpszPathName, bool bReplace); + bool DoFileSave(); + bool FileLoad(File* file, bool bUndo, bool bMerge); + void FileSave(File* file, bool bUndo); + void FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor, int* nStep, PtrArray& FileArray); + void FileReadMPD(File& MPD, PtrArray& FileArray) const; public: // File helpers - bool OnNewDocument (); - bool OnOpenDocument (const char* lpszPathName); - bool SaveModified (); + bool OnNewDocument(); + bool OnOpenDocument(const char* FileName); + bool OpenProject(const char* FileName); + bool SaveModified(); protected: // mail enabling diff --git a/win/Mainfrm.cpp b/win/Mainfrm.cpp index 9b2e023..dba878f 100644 --- a/win/Mainfrm.cpp +++ b/win/Mainfrm.cpp @@ -108,6 +108,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) ON_WM_ACTIVATEAPP() ON_COMMAND(ID_VIEW_NEWVIEW, OnViewNewView) ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString) + ON_WM_DROPFILES() //}}AFX_MSG_MAP ON_COMMAND_RANGE(ID_PIECEBAR_ZOOMPREVIEW, ID_PIECEBAR_SUBPARTS, OnPieceBar) ON_UPDATE_COMMAND_UI_RANGE(ID_PIECEBAR_ZOOMPREVIEW, ID_PIECEBAR_SUBPARTS, OnUpdatePieceBar) @@ -1317,3 +1318,18 @@ void CMainFrame::UpdateMenuAccelerators() m_bmpMenu.Detach(); } + +void CMainFrame::OnDropFiles(HDROP hDropInfo) +{ + SetActiveWindow(); // activate us first ! + UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + + if (nFiles > 0) + { + TCHAR szFileName[_MAX_PATH]; + ::DragQueryFile(hDropInfo, 0, szFileName, _MAX_PATH); + + project->OpenProject(szFileName); + } + ::DragFinish(hDropInfo); +} diff --git a/win/Mainfrm.h b/win/Mainfrm.h index 1061cc9..2024c93 100644 --- a/win/Mainfrm.h +++ b/win/Mainfrm.h @@ -85,6 +85,7 @@ protected: afx_msg void OnActivateApp(BOOL bActive, HTASK hTask); afx_msg void OnViewNewView(); afx_msg LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam); + afx_msg void OnDropFiles(HDROP hDropInfo); //}}AFX_MSG // Status bar -- cgit v1.2.3