void NodeJSDebuggerPane::ParseRefsArray(const JSONElement& refs) { int refsCount = refs.arraySize(); for(int i = 0; i < refsCount; ++i) { JSONElement ref = refs.arrayItem(i); int handleId = ref.namedObject("handle").toInt(); Handle h; h.type = ref.namedObject("type").toString(); if(h.type == "undefined") { h.value = "undefined"; } else if(h.type == "number" || h.type == "boolean") { h.value = ref.namedObject("text").toString(); } else if(h.type == "string") { h.value << "\"" << ref.namedObject("text").toString() << "\""; } else if(h.type == "script" || h.type == "function") { h.value = ref.namedObject("name").toString(); } else if(h.type == "null") { h.value = "null"; } else if(h.type == "object") { h.value = "{...}"; JSONElement props = ref.namedObject("properties"); int propsCount = props.arraySize(); for(int n = 0; n < propsCount; ++n) { JSONElement prop = props.arrayItem(n); wxString propName = prop.namedObject("name").toString(); int propId = prop.namedObject("ref").toInt(); h.properties.insert(std::make_pair(propId, propName)); } } m_handles.insert(std::make_pair(handleId, h)); } }
void LLDBReply::FromJSON(const JSONElement& json) { m_replyType = json.namedObject("m_replyType").toInt(kReplyTypeInvalid); m_interruptResaon = json.namedObject("m_stopResaon").toInt(kInterruptReasonNone); m_line = json.namedObject("m_line").toInt(wxNOT_FOUND); m_filename = json.namedObject("m_filename").toString(); m_lldbId = json.namedObject("m_lldbId").toInt(); m_expression = json.namedObject("m_expression").toString(); m_debugSessionType = json.namedObject("m_debugSessionType").toInt(kDebugSessionTypeNormal); m_text = json.namedObject("m_text").toString(); m_breakpoints.clear(); JSONElement arr = json.namedObject("m_breakpoints"); for(int i = 0; i < arr.arraySize(); ++i) { LLDBBreakpoint::Ptr_t bp(new LLDBBreakpoint()); bp->FromJSON(arr.arrayItem(i)); m_breakpoints.push_back(bp); } m_variables.clear(); JSONElement localsArr = json.namedObject("m_locals"); m_variables.reserve(localsArr.arraySize()); for(int i = 0; i < localsArr.arraySize(); ++i) { LLDBVariable::Ptr_t variable(new LLDBVariable()); variable->FromJSON(localsArr.arrayItem(i)); m_variables.push_back(variable); } m_backtrace.Clear(); JSONElement backtrace = json.namedObject("m_backtrace"); m_backtrace.FromJSON(backtrace); m_threads = LLDBThread::FromJSON(json, "m_threads"); }
void GitCommandsEntries::FromJSON(const JSONElement& json) { m_commands.clear(); m_commandName = json.namedObject("m_commandName").toString(); m_lastUsed = json.namedObject("m_lastUsed").toInt(); JSONElement arrCommandChoices = json.namedObject("m_commands"); for(int i = 0; i < arrCommandChoices.arraySize(); ++i) { GitLabelCommand item; item.label = arrCommandChoices.arrayItem(i).namedObject("label").toString(); item.command = arrCommandChoices.arrayItem(i).namedObject("command").toString(); m_commands.push_back(item); } }
void LexerConf::FromJSON(const JSONElement& json) { m_name = json.namedObject("Name").toString(); m_lexerId = json.namedObject("Id").toInt(); m_themeName = json.namedObject("Theme").toString(); if(json.hasNamedObject("Flags")) { m_flags = json.namedObject("Flags").toSize_t(); } else { SetIsActive(json.namedObject("IsActive").toBool()); SetUseCustomTextSelectionFgColour(json.namedObject("UseCustomTextSelFgColour").toBool()); SetStyleWithinPreProcessor(json.namedObject("StylingWithinPreProcessor").toBool()); } SetKeyWords(json.namedObject("KeyWords0").toString(), 0); SetKeyWords(json.namedObject("KeyWords1").toString(), 1); SetKeyWords(json.namedObject("KeyWords2").toString(), 2); SetKeyWords(json.namedObject("KeyWords3").toString(), 3); SetKeyWords(json.namedObject("KeyWords4").toString(), 4); SetFileSpec(json.namedObject("Extensions").toString()); m_properties.clear(); JSONElement properties = json.namedObject("Properties"); int arrSize = properties.arraySize(); for(int i = 0; i < arrSize; ++i) { // Construct a style property StyleProperty p; p.FromJSON(properties.arrayItem(i)); m_properties.insert(std::make_pair(p.GetId(), p)); } }
void GitEntry::FromJSON(const JSONElement& json) { m_entries = json.namedObject("m_entries").toStringMap(); wxString track, diff; track = json.namedObject("m_colourTrackedFile").toString(); diff = json.namedObject("m_colourDiffFile").toString(); m_pathGIT = json.namedObject("m_pathGIT").toString(m_pathGIT); m_pathGITK = json.namedObject("m_pathGITK").toString(m_pathGITK); m_flags = json.namedObject("m_flags").toSize_t(m_flags); m_gitDiffDlgSashPos = json.namedObject("m_gitDiffDlgSashPos").toInt(m_gitDiffDlgSashPos); m_gitConsoleSashPos = json.namedObject("m_gitConsoleSashPos").toInt(m_gitConsoleSashPos); m_gitCommitDlgHSashPos = json.namedObject("m_gitCommitDlgHSashPos").toInt(m_gitCommitDlgHSashPos); m_gitCommitDlgVSashPos = json.namedObject("m_gitCommitDlgVSashPos").toInt(m_gitCommitDlgVSashPos); // override the colour only if it is a valid colour if(!track.IsEmpty()) { m_colourTrackedFile = track; } if(!diff.IsEmpty()) { m_colourDiffFile = diff; } m_recentCommits = json.namedObject("m_recentCommits").toArrayString(); // read the git commands JSONElement arrCommands = json.namedObject("Commands"); for(int i = 0; i < arrCommands.arraySize(); ++i) { GitCommandsEntries entry; entry.FromJSON(arrCommands.arrayItem(i)); m_commandsMap.insert(std::make_pair(entry.GetCommandname(), entry)); } }
NodeJSHandle NodeJSOuptutParser::ParseRef(const JSONElement& ref, std::map<int, NodeJSHandle>& handles) { int handleId = ref.namedObject("handle").toInt(); NodeJSHandle h; h.handleID = handleId; h.type = ref.namedObject("type").toString(); if(h.type == "undefined") { h.value = "undefined"; } else if(h.type == "number" || h.type == "boolean") { h.value = ref.namedObject("text").toString(); } else if(h.type == "string") { h.value << "\"" << ref.namedObject("text").toString() << "\""; } else if(h.type == "script" || h.type == "function") { h.value = ref.namedObject("name").toString(); } else if(h.type == "null") { h.value = "null"; } else if(h.type == "object") { h.value = "{...}"; JSONElement props = ref.namedObject("properties"); int propsCount = props.arraySize(); for(int n = 0; n < propsCount; ++n) { JSONElement prop = props.arrayItem(n); wxString propName = prop.namedObject("name").toString(); int propId = prop.namedObject("ref").toInt(); h.properties.insert(std::make_pair(propId, propName)); } } handles.insert(std::make_pair(handleId, h)); return h; }
clKeyboardBindingConfig& clKeyboardBindingConfig::Load() { wxFileName fn(clStandardPaths::Get().GetUserDataDir(), "keybindings.conf"); fn.AppendDir("config"); if(!fn.Exists()) return *this; m_bindings.clear(); JSONRoot root(fn); { JSONElement menus = root.toElement().namedObject("menus"); int arrSize = menus.arraySize(); for(int i = 0; i < arrSize; ++i) { JSONElement item = menus.arrayItem(i); MenuItemData binding; binding.action = item.namedObject("description").toString(); binding.accel = item.namedObject("accelerator").toString(); binding.parentMenu = item.namedObject("parentMenu").toString(); binding.resourceID = item.namedObject("resourceID").toString(); if(binding.resourceID == "text_word_complete") { // This entry was moved from Word Completion plugin to CodeLite Edit menu entry binding.resourceID = "simple_word_completion"; binding.parentMenu = "Edit"; binding.action = "Complete Word"; } else if(binding.resourceID == "complete_word") { // The "action" was changed binding.action = "Code Complete"; } else if(binding.resourceID == "word_complete") { binding.resourceID = "complete_word"; } m_bindings.insert(std::make_pair(binding.resourceID, binding)); } } return *this; }
void PHPWorkspace::FromJSON(const JSONElement& e) { m_projects.clear(); if(e.hasNamedObject("projects")) { PHPProject::Ptr_t firstProject; JSONElement projects = e.namedObject("projects"); int count = projects.arraySize(); for(int i = 0; i < count; ++i) { PHPProject::Ptr_t p(new PHPProject()); wxString project_file = projects.arrayItem(i).toString(); wxFileName fnProject(project_file); fnProject.MakeAbsolute(m_workspaceFile.GetPath()); p->Load(fnProject); m_projects.insert(std::make_pair(p->GetName(), p)); if(!firstProject) { firstProject = p; } } PHPProject::Ptr_t activeProject = GetActiveProject(); if(!activeProject && firstProject) { // No active project found, mark the first project as active activeProject = firstProject; SetProjectActive(firstProject->GetName()); } if(activeProject) { // Notify about active project been set clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED); evt.SetProjectName(activeProject->GetName()); evt.SetFileName(activeProject->GetFilename().GetFullPath()); EventNotifier::Get()->AddPendingEvent(evt); } } }
void clTernServer::ProcessOutput(const wxString& output, wxCodeCompletionBoxEntry::Vec_t& entries) { // code completion response: // ================================ // { // "start": 78, // "end": 78, // "isProperty": true, // "isObjectKey": false, // "completions": [ // { // "name": "concat", // "type": "fn(other: [?])", // "doc": "Returns a new array comprised of this array joined with other array(s) and/or value(s).", // "url": "https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/concat" // }, // { // "name": "every", // "type": "fn(test: fn(elt: ?, i: number) -> bool, context?: ?) -> bool", // "doc": "Tests whether all elements in the array pass the test implemented by the provided function.", // "url": "https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every" // }]} entries.clear(); JSONRoot root(output); JSONElement completionsArr = root.toElement().namedObject("completions"); for(int i = 0; i < completionsArr.arraySize(); ++i) { JSONElement item = completionsArr.arrayItem(i); wxString name = item.namedObject("name").toString(); wxString doc = item.namedObject("doc").toString(); wxString url = item.namedObject("url").toString(); bool isKeyword = item.namedObject("isKeyword").toBool(); int imgId; if(!isKeyword) { doc = this->PrepareDoc(doc, url); wxString type = item.namedObject("type").toString(); wxString sig, ret; ProcessType(type, sig, ret, imgId); // Remove double quotes name.StartsWith("\"", &name); name.EndsWith("\"", &name); wxCodeCompletionBoxEntry::Ptr_t entry = wxCodeCompletionBoxEntry::New(name /* + sig*/, imgId); entry->SetComment(doc); entries.push_back(entry); } else { imgId = 17; // keyword wxCodeCompletionBoxEntry::Ptr_t entry = wxCodeCompletionBoxEntry::New(name, imgId); entries.push_back(entry); } } }
void LLDBBacktrace::FromJSON(const JSONElement& json) { m_callstack.clear(); m_threadId = json.namedObject("m_threadId").toInt(0); JSONElement arr = json.namedObject("m_callstack"); for(int i=0; i<arr.arraySize(); ++i) { LLDBBacktrace::Entry entry; entry.FromJSON( arr.arrayItem(i) ); m_callstack.push_back( entry ); } }
void PluginInfoArray::FromJSON(const JSONElement& json) { m_disabledPlugins = json.namedObject("disabledPlugins").toArrayString(); m_plugins.clear(); JSONElement arr = json.namedObject("installed-plugins"); for(int i=0; i<arr.arraySize(); ++i) { PluginInfo pi; pi.FromJSON( arr.arrayItem(i) ); m_plugins.insert(std::make_pair(pi.GetName(), pi)); } }
void NodeJSDebuggerPane::OnUpdateCallstack(clDebugEvent& event) { event.Skip(); wxWindowUpdateLocker locker(m_dataviewLocals); ClearCallstack(); JSONRoot root(event.GetString()); JSONElement frames = root.toElement().namedObject("body").namedObject("frames"); JSONElement refs = root.toElement().namedObject("refs"); // Load the handlers into a map m_handles.clear(); ParseRefsArray(refs); int count = frames.arraySize(); for(int i = 0; i < count; ++i) { JSONElement frame = frames.arrayItem(i); int index = frame.namedObject("index").toInt(); int funcRef = frame.namedObject("func").namedObject("ref").toInt(); int fileRef = frame.namedObject("script").namedObject("ref").toInt(); int line = frame.namedObject("line").toInt() + 1; wxVector<wxVariant> cols; cols.push_back(wxString() << index); wxString file, func; if(m_handles.count(funcRef)) { func = m_handles.find(funcRef)->second.value; } if(m_handles.count(funcRef)) { file = m_handles.find(fileRef)->second.value; } cols.push_back(func); cols.push_back(file); cols.push_back(wxString() << line); FrameData* cd = new FrameData(); cd->file = file; cd->line = line; cd->function = func; cd->index = i; m_dvListCtrlCallstack->AppendItem(cols, (wxUIntPtr)cd); if(i == 0) { // Notify the debugger to use frame #0 for the indicator clDebugEvent event(wxEVT_NODEJS_DEBUGGER_MARK_LINE); event.SetLineNumber(line); event.SetFileName(file); EventNotifier::Get()->AddPendingEvent(event); BuildLocals(frame); BuildArguments(frame); } } }
void SFTPSettings::FromJSON(const JSONElement& json) { m_accounts.clear(); m_sshClient = json.namedObject("sshClient").toString(m_sshClient); JSONElement arrAccounts = json.namedObject("accounts"); int size = arrAccounts.arraySize(); for(int i=0; i<size; ++i) { SSHAccountInfo account; account.FromJSON(arrAccounts.arrayItem(i)); m_accounts.push_back( account ); } }
clKeyboardBindingConfig& clKeyboardBindingConfig::Load() { wxFileName fn(clStandardPaths::Get().GetUserDataDir(), "keybindings.conf"); fn.AppendDir("config"); if(!fn.Exists()) return *this; m_bindings.clear(); JSONRoot root(fn); { JSONElement menus = root.toElement().namedObject("menus"); int arrSize = menus.arraySize(); for(int i = 0; i < arrSize; ++i) { JSONElement item = menus.arrayItem(i); MenuItemData binding; binding.action = item.namedObject("description").toString(); binding.accel = item.namedObject("accelerator").toString(); binding.parentMenu = item.namedObject("parentMenu").toString(); binding.resourceID = item.namedObject("resourceID").toString(); m_bindings.insert(std::make_pair(binding.resourceID, binding)); } } #if 0 { JSONElement globals = root.toElement().namedObject("globals"); int arrSize = globals.arraySize(); for(int i = 0; i < arrSize; ++i) { JSONElement item = globals.arrayItem(i); MenuItemData binding; binding.action = item.namedObject("description").toString(); binding.accel = item.namedObject("accelerator").toString(); binding.parentMenu = item.namedObject("parentMenu").toString(); binding.resourceID = item.namedObject("actionId").toString(); m_globalBindings.insert(std::make_pair(binding.resourceID, binding)); } } #endif return *this; }
void DbExplorerSettings::FromJSON(const JSONElement& json) { m_recentFiles = json.namedObject("m_recentFiles").toArrayString(); m_sqlHistory = json.namedObject("m_sqlHistory").toArrayString(); // read the connections JSONElement arrConnections = json.namedObject("connections"); for(int i=0; i<arrConnections.arraySize(); ++i) { DbConnectionInfo ci; ci.FromJSON( arrConnections.arrayItem(i) ); m_connections.push_back( ci ); } }
void ColoursAndFontsManager::LoadJSON(const wxFileName& path) { if(!path.FileExists()) return; JSONRoot root(path); JSONElement arr = root.toElement(); int arrSize = arr.arraySize(); CL_DEBUG("Loading JSON file: %s (contains %d lexers)", path.GetFullPath(), arrSize); for(int i = 0; i < arrSize; ++i) { JSONElement json = arr.arrayItem(i); DoAddLexer(json); } CL_DEBUG("Loading JSON file...done"); }
void LLDBBreakpoint::FromJSON(const JSONElement& json) { m_children.clear(); m_id = json.namedObject("m_id").toInt(wxNOT_FOUND); m_type = json.namedObject("m_type").toInt(kInvalid); m_name = json.namedObject("m_name").toString(); SetFilename(json.namedObject("m_filename").toString()); m_lineNumber = json.namedObject("m_lineNumber").toInt(); JSONElement arr = json.namedObject("m_children"); for(int i=0; i<arr.arraySize(); ++i) { LLDBBreakpoint::Ptr_t bp(new LLDBBreakpoint() ); bp->FromJSON( arr.arrayItem(i) ); m_children.push_back( bp ); } }
void PHPFolder::FromJSON(const JSONElement& element) { m_children.clear(); m_name = element.namedObject("m_name").toString(); m_files = element.namedObject("m_files").toArrayString(); JSONElement children = element.namedObject("children"); int size = children.arraySize(); for(int i = 0; i < size; ++i) { PHPFolder::Ptr_t child(new PHPFolder()); child->FromJSON(children.arrayItem(i)); child->SetParent(this); m_children.push_back(child); } }
void NodeJSDebuggerPane::BuildLocals(const JSONElement& json) { wxVector<wxVariant> cols; cols.push_back("Locals"); cols.push_back(wxEmptyString); cols.push_back(wxEmptyString); wxDataViewItem locals = m_dataviewLocalsModel->AppendItem(wxDataViewItem(NULL), cols); JSONElement arr = json.namedObject("locals"); int count = arr.arraySize(); for(int i = 0; i < count; ++i) { JSONElement local = arr.arrayItem(i); AddLocal( locals, local.namedObject("name").toString(), local.namedObject("value").namedObject("ref").toInt(), 0); } if(m_dataviewLocalsModel->HasChildren(locals)) { m_dataviewLocals->Expand(locals); } }
void CompilationDatabase::ProcessCMakeCompilationDatabase(const wxFileName& compile_commands) { JSONRoot root(compile_commands); JSONElement arr = root.toElement(); try { wxString sql; sql = wxT("REPLACE INTO COMPILATION_TABLE (FILE_NAME, FILE_PATH, CWD, COMPILE_FLAGS) VALUES(?, ?, ?, ?)"); wxSQLite3Statement st = m_db->PrepareStatement(sql); m_db->ExecuteUpdate("BEGIN"); for(int i = 0; i < arr.arraySize(); ++i) { // Each object has 3 properties: // directory, command, file JSONElement element = arr.arrayItem(i); if(element.hasNamedObject("file") && element.hasNamedObject("directory") && element.hasNamedObject("command")) { wxString cmd = element.namedObject("command").toString(); wxString file = element.namedObject("file").toString(); wxString path = wxFileName(file).GetPath(); wxString cwd = element.namedObject("directory").toString(); cwd = wxFileName(cwd, "").GetPath(); file = wxFileName(file).GetFullPath(); st.Bind(1, file); st.Bind(2, path); st.Bind(3, cwd); st.Bind(4, cmd); st.ExecuteUpdate(); } } m_db->ExecuteUpdate("COMMIT"); } catch(wxSQLite3Exception& e) { wxUnusedVar(e); } }
void CompilersDetectorManager::MSWSuggestToDownloadMinGW(bool prompt) { #ifdef __WXMSW__ if(!prompt || ::wxMessageBox(_("Could not locate any MinGW compiler installed on your machine, would you like to " "install one now?"), "CodeLite", wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTER | wxICON_QUESTION) == wxYES) { // No MinGW compiler detected!, offer the user to download one wxStringMap_t mingwCompilers; wxArrayString options; // Load the compilers list from the website wxURL url("http://codelite.org/compilers.json"); if(url.GetError() == wxURL_NOERR) { wxInputStream* in_stream = url.GetInputStream(); if(!in_stream) { return; } unsigned char buffer[DLBUFSIZE + 1]; wxString dataRead; do { in_stream->Read(buffer, DLBUFSIZE); size_t bytes_read = in_stream->LastRead(); if(bytes_read > 0) { buffer[bytes_read] = 0; wxString buffRead((const char*)buffer, wxConvUTF8); dataRead.Append(buffRead); } } while(!in_stream->Eof()); JSONRoot root(dataRead); JSONElement compilers = root.toElement().namedObject("Compilers"); JSONElement arr = compilers.namedObject("MinGW"); int count = arr.arraySize(); for(int i = 0; i < count; ++i) { JSONElement compiler = arr.arrayItem(i); mingwCompilers.insert( std::make_pair(compiler.namedObject("Name").toString(), compiler.namedObject("URL").toString())); options.Add(compiler.namedObject("Name").toString()); } if(options.IsEmpty()) { ::wxMessageBox(_("Unable to fetch compilers list from the website\nhttp://codelite.org/compilers.json"), "CodeLite", wxOK | wxCENTER | wxICON_WARNING); return; } int sel = 0; wxString selection = ::wxGetSingleChoice(_("Select a compiler to download"), _("Choose compiler"), options, sel); if(!selection.IsEmpty()) { // Reset the compiler detection flag so next time codelite is restarted, it will // rescan the machine clConfig::Get().Write(kConfigBootstrapCompleted, false); // Open the browser to start downloading the compiler ::wxLaunchDefaultBrowser(mingwCompilers.find(selection)->second); ::wxMessageBox(_("After install is completed, click the 'Scan' button"), "CodeLite", wxOK | wxCENTER | wxICON_INFORMATION); } } } #endif // __WXMSW__ }