OSDN Git Service

Mac: fix unstable behavior on drag-and-dropping a log file on the application icon.
authortoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Wed, 21 Mar 2018 23:46:44 +0000 (23:46 +0000)
committertoshinagata1964 <toshinagata1964@a2be9bc6-48de-4e38-9406-05402d4bc13c>
Wed, 21 Mar 2018 23:46:44 +0000 (23:46 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@612 a2be9bc6-48de-4e38-9406-05402d4bc13c

wxSources/MyApp.cpp
wxSources/MyApp.h
wxSources/MyDocument.h
wxSources/MyIPCSupport.cpp

index bc7e79a..d001298 100755 (executable)
@@ -88,7 +88,7 @@ IMPLEMENT_APP(MyApp)
 
 BEGIN_EVENT_TABLE(MyApp, wxApp)
        EVT_COMMAND(MyDocumentEvent_scriptMenuModified, MyDocumentEvent, MyApp::OnScriptMenuModified)
-       EVT_COMMAND(MyDocumentEvent_openFilesByIPC, MyDocumentEvent, MyApp::OnOpenFilesByIPC)
+       EVT_COMMAND(MyDocumentEvent_openFilesByEvent, MyDocumentEvent, MyApp::OnOpenFilesByEvent)
        EVT_UPDATE_UI_RANGE(myMenuID_MyFirstMenuItem, myMenuID_MyLastMenuItem, MyApp::OnUpdateUI)
        EVT_MENU(myMenuID_ExecuteScript, MyApp::OnExecuteScript)
        EVT_MENU(myMenuID_OpenConsoleWindow, MyApp::OnOpenConsoleWindow)
@@ -342,7 +342,7 @@ bool MyApp::OnInit(void)
                        files.append(argv[i]);
                        files.append(wxT("\n"));
                }
-               OnOpenFiles(files);
+               RequestOpenFilesByEvent(files);
        }
        
        gInitCompleted = true;
@@ -542,8 +542,8 @@ MyApp::MacNewFile()
 void
 MyApp::MacOpenFile(const wxString &fileName)
 {
-       wxString files(fileName);
-       OnOpenFiles(files);
+    wxString file(fileName);
+       RequestOpenFilesByEvent(file);
 }
 
 /*  Open given files: instead of calling MacOpenFile() for each entry, build a file list
@@ -1162,21 +1162,29 @@ MyApp::OnActivate(wxActivateEvent &event)
 }
 
 void
-MyApp::RequestOpenFilesByIPC(wxString& files)
+MyApp::RequestOpenFilesByEvent(wxString& files)
 {
        if (m_pendingFilesToOpen != NULL)
                m_pendingFilesToOpen->Append(files);
        else
                m_pendingFilesToOpen = new wxString(files);
-       wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openFilesByIPC);
+    if (!m_pendingFilesToOpen->EndsWith(wxT("\n")))
+        m_pendingFilesToOpen->Append(wxT("\n"));
+       wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openFilesByEvent);
        wxPostEvent(this, myEvent);
 }
 
 void
-MyApp::OnOpenFilesByIPC(wxCommandEvent& event)
+MyApp::OnOpenFilesByEvent(wxCommandEvent& event)
 {
        if (m_pendingFilesToOpen == NULL)
                return;
+    if (!gInitCompleted) {
+        //  Repost this event and try again later
+        wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openFilesByEvent);
+        wxPostEvent(this, myEvent);
+        return;
+    }
        OnOpenFiles(*m_pendingFilesToOpen);
        delete m_pendingFilesToOpen;
        m_pendingFilesToOpen = NULL;
index 34d272e..dc6a092 100755 (executable)
@@ -177,8 +177,8 @@ class MyApp: public wxApp
 
        void OnActivate(wxActivateEvent &event);
 
-       void RequestOpenFilesByIPC(wxString& files);
-       void OnOpenFilesByIPC(wxCommandEvent& event);
+       void RequestOpenFilesByEvent(wxString& files);
+       void OnOpenFilesByEvent(wxCommandEvent& event);
        
        bool OnOpenFiles(const wxString &files);
 
@@ -226,7 +226,7 @@ protected:
        MyDocument **m_TimerDocs;
        wxTimer *m_Timer;
 
-       wxString *m_pendingFilesToOpen;  /*  Files to be processed by OnOpenFilesByIPC()  */
+       wxString *m_pendingFilesToOpen;  /*  Files to be processed by OnOpenFilesByEvent()  */
 
        wxTopLevelWindow *m_frameToBeDestroyed;   /*  Used in CheckIfAllWindowsAreGone()  */
        
index cc050f5..4ca8b0b 100755 (executable)
@@ -37,7 +37,7 @@ enum {
        MyDocumentEvent_updateDisplay,
        MyDocumentEvent_insertFrameFromMD,
        MyDocumentEvent_threadTerminated,
-       MyDocumentEvent_openFilesByIPC,
+       MyDocumentEvent_openFilesByEvent,
        MyDocumentEvent_documentWillClose,
        MyDocumentEvent_openAuxiliaryDocuments
 };
index 2cae294..d413356 100755 (executable)
@@ -74,7 +74,7 @@ MyServerConnection::OnExecute(const wxString& topic, const void *data, size_t si
 {
        if (topic == MOLBY_IPC_TOPIC) {
                wxString files((wxChar *)data);
-               wxGetApp().RequestOpenFilesByIPC(files);
+               wxGetApp().RequestOpenFilesByEvent(files);
                return true;
        } else return false;
 }