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;
-
download for full patch...
History
olorin 2006-05-10 21:10
This patch:
* moves DDE related functionalities from app.h to app.c
* does a little DDE and __WXMSW__ reorder/cleanup
* add an unnamed namespace for local global data
* renames DelayLoadDdeFiles to LoadDelayedFiles (as it is also used for command line files), same for s_DdeFilesToOpen -> s_DelayedFilesToOpen
* reorders data members of CodeBlocksApp to lightly reduce memory usage
Maybe too much modifications, but they should be almost completely armless
thomasdenk 2006-05-15 15:57
Hmm... I dare not apply a patch that has the word "DDE" in it.
We just have DDE working somehow, and it is such a backbiter :-(
artoj 2006-10-07 20:42
I've updated the patch to be compatible with the latest revision (3032 at the time of writing).