File: main_app.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (93 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "main_app.h"
#include "file_logger.h"
#include <cl_standard_paths.h>
#include <wx/filename.h>
#include "ChildProcess.h"
#include "LSP/Request.h"
#include "LSP/InitializeRequest.h"
#include "LSP/DidOpenTextDocumentRequest.h"
#include <processreaderthread.h>
#include <wx/filename.h>
#include <fileutils.h>
#include <wx/evtloop.h>

#ifdef __WXMSW__
#define CL_HOME "C:\\src\\codelite"
#elif defined(__WXGTK__)
#define CL_HOME "/home/eran/devl/codelite"
#else
#define CL_HOME "/Users/eranif/devl/codelite"
#endif

IMPLEMENT_APP_CONSOLE(MainApp)

MainApp::MainApp() {}

MainApp::~MainApp() { wxDELETE(m_child); }

int MainApp::OnExit() { return TRUE; }

bool MainApp::OnInit()
{
    SetAppName("codelite-stdio");

    // Open the log file
    wxFileName logfile(clStandardPaths::Get().GetUserDataDir(), "codelite-stdio.log");
    logfile.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
    FileLogger::OpenLog(logfile.GetFullName(), 2);

    clSYSTEM() << "Started";

    if(argc < 2) { return false; }

    wxArrayString argvArr = this->argv.GetArguments();
    argvArr.RemoveAt(0);
    m_argv.swap(argvArr);

    wxCmdLineParser parser(argc, this->argv);
    if(!DoParseCommandLine(parser)) { return false; }

    CallAfter(&MainApp::DoStartup);
    return true;
}

bool MainApp::DoParseCommandLine(wxCmdLineParser& parser)
{
    wxUnusedVar(parser);
    return true;
}

void MainApp::OnProcessOutput(clProcessEvent& event) { clDEBUG() << "STDOUT:" << event.GetOutput(); }

void MainApp::OnProcessStderr(clProcessEvent& event) { clDEBUG() << "STDERR:" << event.GetOutput(); }

void MainApp::OnProcessTerminated(clProcessEvent& event)
{
    clDEBUG() << "Process terminated";
    wxDELETE(m_child);
    wxExit();
}

void MainApp::DoStartup()
{
    m_child = new ChildProcess();
    m_child->Bind(wxEVT_ASYNC_PROCESS_OUTPUT, &MainApp::OnProcessOutput, this);
    m_child->Bind(wxEVT_ASYNC_PROCESS_STDERR, &MainApp::OnProcessStderr, this);
    m_child->Bind(wxEVT_ASYNC_PROCESS_TERMINATED, &MainApp::OnProcessTerminated, this);
    m_child->Start(m_argv);

    // For testing purposes, write here something to clangd
    wxFileName fn(CL_HOME, "frame.cpp");
    fn.AppendDir("LiteEditor");
    LSP::InitializeRequest::Ptr_t r = LSP::MessageWithParams::MakeRequest(new LSP::InitializeRequest(CL_HOME));

    // place your initialization code here
    m_child->Write(r->ToString());

    wxString fileContent;
    FileUtils::ReadFileContent(fn, fileContent);
    LSP::DidOpenTextDocumentRequest::Ptr_t openReq =
        LSP::MessageWithParams::MakeRequest(new LSP::DidOpenTextDocumentRequest(fn, fileContent, "cpp"));
    m_child->Write(openReq->ToString());
    wxDELETE(m_child);
}