void ApiHandler::IpcEditorInsertAt(EditorCtrl& editor, IConnection& conn) { // Get the insert position const hessian_ipc::Call& call = *conn.get_call(); const size_t pos = call.GetParameter(1).GetInt(); if (pos > editor.GetLength()) return; // fault: invalid position // Get the text to insert const hessian_ipc::Value& v3 = call.GetParameter(2); const string& t = v3.GetString(); const wxString text(t.c_str(), wxConvUTF8, t.size()); // Insert the text // TODO: adjust selections const unsigned int cpos = editor.GetPos(); const size_t byte_len = editor.RawInsert(pos, text); if (cpos >= pos) editor.SetPos(cpos + byte_len); editor.ReDraw(); // Write the reply hessian_ipc::Writer& writer = conn.get_reply_writer(); writer.write_reply(byte_len); }
void SymbolList::OnIdle(wxIdleEvent& WXUNUSED(event)) { EditorCtrl* editorCtrl = m_parentFrame.GetEditorCtrl(); if (!editorCtrl) return; const int id = editorCtrl->GetId(); // In rare cases a new editorCtrl may get same address as // a previous one, so we also track the window id. const bool newEditorCtrl = (editorCtrl != m_editorCtrl || id != m_editorCtrlId); if (newEditorCtrl) m_changeToken = 0; // reset token const unsigned int currentChangeToken = editorCtrl->GetChangeToken(); // Only update if the editorCtrl has changed if (newEditorCtrl || m_changeToken != currentChangeToken) { // || m_pos != editorCtrl->GetPos()) { m_editorCtrl = editorCtrl; m_editorCtrlId = id; // Reload symbols m_symbols.clear(); m_symbolStrings.Empty(); const int res = editorCtrl->GetSymbols(m_symbols); if (res == 1) { // reload symbol strings for (vector<Styler_Syntax::SymbolRef>::const_iterator p = m_symbols.begin(); p != m_symbols.end(); ++p) { const Styler_Syntax::SymbolRef& sr = *p; m_symbolStrings.Add(editorCtrl->GetSymbolString(sr)); } m_listBox->SetAllItems(); } else if (res == 2) { // DEBUG: double implementation to view path in crash dump (remove when bug is solved) // reload symbol strings for (vector<Styler_Syntax::SymbolRef>::const_iterator p = m_symbols.begin(); p != m_symbols.end(); ++p) { const Styler_Syntax::SymbolRef& sr = *p; m_symbolStrings.Add(editorCtrl->GetSymbolString(sr)); } m_listBox->SetAllItems(); } else { m_listBox->SetAllItems(); // clear list return; } // Get editor state m_pos = editorCtrl->GetPos(); m_changeToken = currentChangeToken; // Keep scrollpos so we can stay at the same pos const unsigned int scrollPos = m_listBox->GetScrollPos(wxVERTICAL); // Set current symbol if (!m_symbols.empty()) { /*// Set new symbols bool currentSet = false; unsigned int id = 0; for (vector<Styler_Syntax::SymbolRef>::const_iterator p = m_symbols.begin(); p != m_symbols.end(); ++p) { // Select current if (!currentSet && m_pos < p->start) { if (p != m_symbols.begin()) { SetSelection(id-1, true); } currentSet = true; } ++id; } // Current symbol may be the last and therefore not checked above if (!currentSet && m_pos >= m_symbols.back().start) { SetSelection(id-1, true); }*/ // Keep same position if (!newEditorCtrl) { m_listBox->SetScrollPos(wxVERTICAL, scrollPos); } } } }
void ApiHandler::IpcEditorGetPos(EditorCtrl& editor, IConnection& conn) { hessian_ipc::Writer& writer = conn.get_reply_writer(); writer.write_reply(editor.GetPos()); }
void StatusBar::UpdateBarFromActiveEditor() { EditorCtrl* editorCtrl = m_parentFrame.GetEditorCtrl(); if (!editorCtrl) return; const unsigned int changeToken = editorCtrl->GetChangeToken(); const int id = editorCtrl->GetId(); const unsigned int pos = editorCtrl->GetPos(); // In rare cases a new editorCtrl may get same address as // a previous one, so we also track the window id. const bool newEditorCtrl = (editorCtrl != m_editorCtrl || id != m_editorCtrlId); // Only update if the editorCtrl has changed const bool updatePanels = newEditorCtrl || (m_changeToken != changeToken) || (m_pos != pos); if (!updatePanels) return; if (newEditorCtrl) m_changeToken = 0; // reset m_editorCtrl = editorCtrl; m_editorCtrlId = id; Freeze(); UpdateTabs(); if (editorCtrl) { // Caret position const unsigned int line = editorCtrl->GetCurrentLineNumber(); const unsigned int column = editorCtrl->GetCurrentColumnNumber(); if (line != m_line || column != m_column) { SetStatusText(wxString::Format(wxT("Line: %u Column: %u"), line, column), 0); m_line = line; m_column = column; } // Syntax SetPanelTextIfDifferent(editorCtrl->GetSyntaxName(), 1); // Only reload symbol list if doc has changed bool symbolsChanged = false; if (newEditorCtrl || m_changeToken != changeToken) { m_symbols.clear(); if (editorCtrl->GetSymbols(m_symbols)) { m_changeToken = editorCtrl->GetChangeToken(); // Track change state (so we only update on change) symbolsChanged = true; } } // Symbols if (newEditorCtrl || symbolsChanged || m_pos != pos) { SetStatusText(wxEmptyString, 3); for (std::vector<SymbolRef>::reverse_iterator p = m_symbols.rbegin(); p != m_symbols.rend(); ++p) { if (m_pos >= p->start) { const SymbolRef& sr = *p; SetStatusText(editorCtrl->GetSymbolString(sr), 3); break; } } } // Encoding wxFontEncoding enc = editorCtrl->GetEncoding(); wxTextFileType eol = editorCtrl->GetEOL(); wxString encoding = wxFontMapper::GetEncodingName(enc).Lower(); if (enc == wxFONTENCODING_DEFAULT) enc = wxLocale::GetSystemEncoding(); if (enc == wxFONTENCODING_UTF7 || enc == wxFONTENCODING_UTF8 || enc == wxFONTENCODING_UTF16LE || enc == wxFONTENCODING_UTF16BE || enc == wxFONTENCODING_UTF32LE || enc == wxFONTENCODING_UTF32BE) { if (editorCtrl->GetBOM()) encoding += wxT("+bom"); } if (eol == wxTextFileType_None) eol = wxTextBuffer::typeDefault; if (eol == wxTextFileType_Dos) encoding += wxT(" crlf"); else if (eol == wxTextFileType_Unix) encoding += wxT(" lf"); else if (eol == wxTextFileType_Mac) encoding += wxT(" cr"); SetStatusText(encoding, 4); m_pos = pos; } Thaw(); }