Index: app.cpp
===================================================================
--- app.cpp	(revision 2438)
+++ app.cpp	(working copy)
@@ -62,8 +62,69 @@
 
 #include "appglobals.h"
 
+namespace {
+
+// this list will be filled with files
+// (received through DDE or command line)
+// to be loaded after the app has started up
+wxArrayString s_DelayedFilesToOpen;
+
+#ifdef __WXMSW__
+
+bool s_Loading = false;
+
+class DDEServer : public wxServer
+{
+	public:
+		DDEServer(MainFrame* frame) : m_Frame(frame) {}
+		wxConnectionBase *OnAcceptConnection(const wxString& topic);
+		MainFrame* GetFrame(){ return m_Frame; }
+		void SetFrame(MainFrame* frame){ m_Frame = frame; }
+	private:
+		MainFrame* m_Frame;
+};
+
+class DDEConnection : public wxConnection
+{
+	public:
+		DDEConnection(MainFrame* frame) : m_Frame(frame) {}
+		bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format);
+	private:
+		MainFrame* m_Frame;
+};
+
+wxConnectionBase* DDEServer::OnAcceptConnection(const wxString& topic)
+{
+    return topic==DDE_TOPIC ? new DDEConnection(m_Frame) : 0L;
+}
+
+bool DDEConnection::OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format)
+{
+	wxString strData(data);
+
+	if (!strData.StartsWith(_T("[Open(\"")))
+		return false;
+
+	wxRegEx reCmd(_T("\"(.*)\""));
+	if (reCmd.Matches(strData))
+	{
+		const wxString file = reCmd.GetMatch(strData, 1);
+		if (s_Loading)
+		{
+            s_DelayedFilesToOpen.Add(file);
+		}
+        else if (m_Frame)
+        {
+            m_Frame->Open(file, true); // add to history, files that open through DDE
+        }
+	}
+    return true;
+}
+
+DDEServer* g_DDEServer = 0L;
+
 #if wxUSE_CMDLINE_PARSER
-static const wxCmdLineEntryDesc cmdLineDesc[] =
+const wxCmdLineEntryDesc cmdLineDesc[] =
 {
     { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
 #ifdef __WXMSW__
@@ -86,14 +147,10 @@
 };
 #endif // wxUSE_CMDLINE_PARSER
 
-#ifdef __WXMSW__
-DDEServer* g_DDEServer = 0L;
+}
+
 #endif
 
-// this list will be filled with DDE files to load after the app has started up
-wxArrayString s_DdeFilesToOpen;
-bool s_Loading = false;
-
 IMPLEMENT_APP(CodeBlocksApp)
 
 BEGIN_EVENT_TABLE(CodeBlocksApp, wxApp)
@@ -140,9 +197,9 @@
     return true;
 }
 
-void CodeBlocksApp::InitAssociations(MainFrame* frame)
+#ifdef __WXMSW__
+void CodeBlocksApp::InitAssociations()
 {
-#ifdef __WXMSW__
 	ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("app"));
 	if (!m_NoAssocs && cfg->ReadBool(_T("/environment/check_associations"), true))
 	{
@@ -168,8 +225,8 @@
 
         }
     }
+}
 #endif
-}
 
 void CodeBlocksApp::InitDebugConsole()
 {
@@ -324,16 +381,27 @@
     cfg->Write(_T("/locale/language"), (int)lng);
 }
 
+
+
+#ifdef __WXMSW__
+        HINSTANCE m_ExceptionHandlerLib;
+		bool m_NoDDE; // no DDE
+		bool m_NoAssocs; // no associations check
+#endif
+
+
 bool CodeBlocksApp::OnInit()
 {
+#ifdef __WXMSW__
     s_Loading = true;
+#endif
+    m_pBatchBuildDialog = 0;
+    m_BatchExitCode = 0;
     m_Batch = false;
     m_BatchNotify = false;
     m_Build = false;
     m_ReBuild = false;
-    m_BatchExitCode = 0;
     m_BatchWindowAutoClose = true;
-    m_pBatchBuildDialog = 0;
 
 	wxTheClipboard->Flush();
 
@@ -403,8 +471,10 @@
 
         if (m_Batch)
         {
+#ifdef __WXMSW__
             s_Loading = false;
-            DelayLoadDdeFiles(frame);
+            LoadDelayedFiles(frame);
+#endif
             BatchJob();
             frame->Close();
             return true;
@@ -426,11 +496,14 @@
         frame->Show();
 
         frame->ShowTips(); // this func checks if the user wants tips, so no need to check here
-        InitAssociations(frame);
 
+#ifdef __WXMSW__
+        InitAssociations();
         s_Loading = false;
-        DelayLoadDdeFiles(frame);
+#endif
 
+        LoadDelayedFiles(frame);
+
         return true;
     }
     catch (cbException& exception)
@@ -454,11 +527,11 @@
 	wxTheClipboard->Flush();
 
 #ifdef __WXMSW__
-	if (g_DDEServer)
-		delete g_DDEServer;
+    delete g_DDEServer;
     if (m_ExceptionHandlerLib)
         FreeLibrary(m_ExceptionHandlerLib);
 #endif
+
     if (m_pSingleInstance)
         delete m_pSingleInstance;
     // WX docs say that this function's return value is ignored,
@@ -677,14 +750,14 @@
                         if (ft == ftCodeBlocksProject)
                         {
                             hasProj = true;
-                            s_DdeFilesToOpen.Add(parser.GetParam(param));
+                            s_DelayedFilesToOpen.Add(parser.GetParam(param));
                         }
                         else if (ft == ftCodeBlocksWorkspace)
                         {
                             // only one workspace can be opened
                             hasWksp = true;
-                            s_DdeFilesToOpen.Clear(); // remove all other files
-                            s_DdeFilesToOpen.Add(parser.GetParam(param)); // and add only the workspace
+                            s_DelayedFilesToOpen.Clear(); // remove all other files
+                            s_DelayedFilesToOpen.Add(parser.GetParam(param)); // and add only the workspace
                             break; // and stop processing any more files
                         }
                     }
@@ -700,9 +773,6 @@
 #ifdef __WXMSW__
 					m_NoDDE = parser.Found(_T("no-dde"));
 					m_NoAssocs = parser.Found(_T("no-check-associations"));
-#else
-                    m_NoDDE = false;
-                    m_NoAssocs = false;
 #endif
 					m_NoSplash = parser.Found(_T("no-splash-screen"));
 					m_ClearConf = parser.Found(_T("clear-configuration"));
@@ -764,49 +834,15 @@
         Manager::Get()->GetPersonalityManager()->SetPersonality(personality, true);
 }
 
-void CodeBlocksApp::DelayLoadDdeFiles(MainFrame* frame)
+void CodeBlocksApp::LoadDelayedFiles(MainFrame *const frame)
 {
-    for (size_t i = 0; i < s_DdeFilesToOpen.GetCount(); ++i)
+    for (size_t i = 0; i < s_DelayedFilesToOpen.GetCount(); ++i)
     {
-        frame->Open(s_DdeFilesToOpen[i], true);
+        frame->Open(s_DelayedFilesToOpen[i], true);
     }
-    s_DdeFilesToOpen.Clear();
+    s_DelayedFilesToOpen.Clear();
 }
 
-#ifdef __WXMSW__
-//// DDE
-
-wxConnectionBase* DDEServer::OnAcceptConnection(const wxString& topic)
-{
-    if (topic == DDE_TOPIC)
-        return new DDEConnection(m_Frame);
-
-    // unknown topic
-    return 0L;
-}
-
-bool DDEConnection::OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format)
-{
-	wxString strData = data;
-	if (!strData.StartsWith(_T("[Open(\"")))
-		return false;
-
-	wxRegEx reCmd(_T("\"(.*)\""));
-	if (reCmd.Matches(strData))
-	{
-		wxString file = reCmd.GetMatch(strData, 1);
-		if (s_Loading)
-            s_DdeFilesToOpen.Add(file);
-        else
-        {
-            if(m_Frame)
-                m_Frame->Open(file, true); // add to history, files that open through DDE
-        }
-	}
-    return true;
-}
-#endif
-
 // event handlers
 
 void CodeBlocksApp::OnAppActivate(wxActivateEvent& event)
Index: app.h
===================================================================
--- app.h	(revision 2438)
+++ app.h	(working copy)
@@ -49,7 +49,6 @@
     protected:
         void OnBatchBuildDone(CodeBlocksEvent& event);
         bool LoadConfig();
-        void InitAssociations(MainFrame* frame);
         void InitDebugConsole();
         void InitExceptionHandler();
         void InitImageHandlers();
@@ -65,56 +64,38 @@
         void HideSplashScreen();
         bool CheckResource(const wxString& res);
         void SetupPersonality(const wxString& personality);
-        void DelayLoadDdeFiles(MainFrame* frame);
 
-		bool m_NoDDE; // no DDE
-		bool m_NoAssocs; // no associations check
-		bool m_NoSplash; // no splash screen
-		bool m_HasDebugLog; // display debug log
-		bool m_ClearConf; // clear configuration
-		wxString m_Prefix; // --prefix switch
+        void LoadDelayedFiles(MainFrame* frame); // command line or DDE (if available) files
+
 #ifdef __WXMSW__
+        void InitAssociations();
         HINSTANCE m_ExceptionHandlerLib;
+		bool m_NoDDE; // no DDE
+		bool m_NoAssocs; // no associations check
 #endif
+
         // batch jobs - start
+		wxDialog* m_pBatchBuildDialog;
+        wxString m_BatchTarget;
+        int m_BatchExitCode;
         bool m_Batch;
         bool m_BatchNotify;
-        wxString m_BatchTarget;
+        bool m_BatchWindowAutoClose; // default: true
         bool m_Build;
         bool m_ReBuild;
-        int m_BatchExitCode;
-        bool m_BatchWindowAutoClose; // default: true
-		wxDialog* m_pBatchBuildDialog;
         // batch jobs - end
 
+		bool m_NoSplash; // no splash screen
+		bool m_HasDebugLog; // display debug log
+		bool m_ClearConf; // clear configuration
+		wxString m_Prefix; // --prefix switch
+
         cbSplashScreen* m_pSplash;
 		wxSingleInstanceChecker* m_pSingleInstance;
 
         DECLARE_EVENT_TABLE()
 };
+
 DECLARE_APP(CodeBlocksApp);
 
-#ifdef __WXMSW__
-class DDEServer : public wxServer
-{
-	public:
-		DDEServer(MainFrame* frame) : m_Frame(frame) {}
-		wxConnectionBase *OnAcceptConnection(const wxString& topic);
-		MainFrame* GetFrame(){ return m_Frame; }
-		void SetFrame(MainFrame* frame){ m_Frame = frame; }
-	private:
-		MainFrame* m_Frame;
-};
-
-class DDEConnection : public wxConnection
-{
-	public:
-		DDEConnection(MainFrame* frame) : m_Frame(frame) {}
-		bool OnExecute(const wxString& topic, wxChar *data, int size, wxIPCFormat format);
-	private:
-		MainFrame* m_Frame;
-};
-#endif
-
-
 #endif // CODEBLOCKS_APP_H
