File: NodeJSDebuggerDlg.cpp

package info (click to toggle)
codelite 10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 71,364 kB
  • sloc: cpp: 415,397; ansic: 18,277; php: 9,547; lex: 4,181; yacc: 2,820; python: 2,294; sh: 383; makefile: 51; xml: 13
file content (147 lines) | stat: -rw-r--r-- 5,132 bytes parent folder | download | duplicates (2)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "NodeJSDebuggerDlg.h"
#include <wx/filename.h>
#include "cl_config.h"
#include "clTernServer.h"
#include "globals.h"
#include "imanager.h"
#include "NodeJSWorkspaceUserConfiguration.h"
#include "NoteJSWorkspace.h"
#include "ColoursAndFontsManager.h"

NodeJSDebuggerDlg::NodeJSDebuggerDlg(wxWindow* parent, eDialogType type)
    : NodeJSDebuggerDlgBase(parent)
    , m_type(type)
{
    if(m_type == kDebug) {
        SetLabel(_("Debug script"));
        m_staticTextScript->SetLabel(_("Script to debug:"));
    } else {
        SetLabel(_("Execute script"));
        m_staticTextScript->SetLabel(_("Script to execute:"));
        m_staticTextDebuggerPort->Disable();
        m_textCtrlPort->Disable();
    }

    m_stcCommandLineArguments->SetEOLMode(wxSTC_EOL_LF);
    wxFileName fnNodejs;
    wxString nodejs = clConfig::Get().Read("webtools/nodejs/debugger/executable", wxString());
    if(nodejs.IsEmpty()) {
        if(clTernServer::LocateNodeJS(fnNodejs)) {
            nodejs = fnNodejs.GetFullPath();
        }
    }

    NodeJSWorkspaceUser userConf(NodeJSWorkspace::Get()->GetFilename().GetFullPath());
    userConf.Load();
    wxString script = userConf.GetScriptToExecute();
    if(script.IsEmpty()) {
        if(clGetManager()->GetActiveEditor()) {
            script = clGetManager()->GetActiveEditor()->GetFileName().GetFullPath();
        }
    }

    m_filePickerNodeJS->SetPath(nodejs);
    m_filePickerScript->SetPath(script);
    m_textCtrlPort->ChangeValue(wxString() << userConf.GetDebuggerPort());
    m_dirPickerWorkingDirectory->SetPath(userConf.GetWorkingDirectory());
    
    m_stcCommandLineArguments->SetText(::wxJoin(userConf.GetCommandLineArgs(), '\n'));
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("javascript");
    if(lexer) {
        lexer->Apply(m_stcCommandLineArguments);
    }
    CenterOnParent();
}

NodeJSDebuggerDlg::NodeJSDebuggerDlg(wxWindow* parent,
                                     eDialogType type,
                                     const wxFileName& script,
                                     const wxArrayString& args)
    : NodeJSDebuggerDlgBase(parent)
    , m_type(type)
{
    if(m_type == kDebug) {
        SetLabel(_("Debug script"));
        m_staticTextScript->SetLabel(_("Script to debug:"));
    } else {
        SetLabel(_("Execute script"));
        m_staticTextScript->SetLabel(_("Script to execute:"));
        m_staticTextDebuggerPort->Disable();
        m_textCtrlPort->Disable();
    }

    m_stcCommandLineArguments->SetEOLMode(wxSTC_EOL_LF);
    wxFileName fnNodejs;
    wxString nodejs = clConfig::Get().Read("webtools/nodejs/debugger/executable", wxString());
    if(nodejs.IsEmpty()) {
        if(clTernServer::LocateNodeJS(fnNodejs)) {
            nodejs = fnNodejs.GetFullPath();
        }
    }

    NodeJSWorkspaceUser userConf(NodeJSWorkspace::Get()->GetFilename().GetFullPath());
    userConf.Load();

    m_filePickerNodeJS->SetPath(nodejs);
    m_filePickerScript->SetPath(script.GetFullPath());
    m_textCtrlPort->ChangeValue(wxString() << userConf.GetDebuggerPort());
    m_stcCommandLineArguments->SetText(::wxJoin(args, '\n'));
    m_dirPickerWorkingDirectory->SetPath(userConf.GetWorkingDirectory());
    
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("javascript");
    if(lexer) {
        lexer->Apply(m_stcCommandLineArguments);
    }
    CenterOnParent();
}

NodeJSDebuggerDlg::~NodeJSDebuggerDlg()
{
    clConfig::Get().Write("webtools/nodejs/debugger/executable", m_filePickerNodeJS->GetPath());
    NodeJSWorkspaceUser userConf(NodeJSWorkspace::Get()->GetFilename().GetFullPath());
    userConf.Load();
    userConf.SetScriptToExecute(m_filePickerScript->GetPath());

    long nPort;
    m_textCtrlPort->GetValue().ToCLong(&nPort);
    userConf.SetDebuggerPort(nPort);
    wxArrayString commandLineArgs = ::wxStringTokenize(m_stcCommandLineArguments->GetText(), "\n", wxTOKEN_STRTOK);
    userConf.SetCommandLineArgs(commandLineArgs);
    userConf.SetWorkingDirectory(m_dirPickerWorkingDirectory->GetPath());
    userConf.Save();
}

void NodeJSDebuggerDlg::OnOKUI(wxUpdateUIEvent& event)
{
    event.Enable(wxFileName::Exists(m_filePickerNodeJS->GetPath()) &&
                 wxFileName::Exists(m_filePickerScript->GetPath()));
}

wxString NodeJSDebuggerDlg::GetCommand()
{
    wxString command, nodejs, script;
    nodejs << m_filePickerNodeJS->GetPath();
    script << m_filePickerScript->GetPath();
    ::WrapWithQuotes(nodejs);
    ::WrapWithQuotes(script);

    if(m_type == kDebug) {
        wxString sport = m_textCtrlPort->GetValue();
        long port = 5858;
        if(!sport.Trim().ToCLong(&port)) {
            port = 5858;
        }
        command << nodejs << " --debug-brk=" << port << " " << script;
    } else {
        command << nodejs << " " << script;
    }

    wxArrayString args = ::wxStringTokenize(m_stcCommandLineArguments->GetText(), "\n", wxTOKEN_STRTOK);
    if(!args.IsEmpty()) {
        command << " ";
    }
    for(size_t i = 0; i < args.size(); ++i) {
        command << ::WrapWithQuotes(args.Item(i)) << " ";
    }
    return command;
}