Example #1
0
void ApiHandler::IpcEditorWatchChanges(EditorCtrl& editor, IConnection& conn) {
	// Register notifier
	const unsigned int notifier_id = GetNextNotifierId();
	m_notifiers[notifier_id] = &conn;

	// Add to watch list
	const EditorWatch ew = {WATCH_EDITOR_CHANGE, editor.GetId(), editor.GetChangeToken(), notifier_id};
	m_editorWatchers.push_back(ew);

	// Return notifier id
	hessian_ipc::Writer& writer = conn.get_reply_writer();
	writer.write_reply(notifier_id);
}
Example #2
0
void ApiHandler::OnIdle(wxIdleEvent& WXUNUSED(event)) {
	// Do we have ipc connections watching for editor changes
	vector<EditorWatch>::iterator p = m_editorWatchers.begin();
	while (p != m_editorWatchers.end()) {
		if (p->type == WATCH_EDITOR_CHANGE) {
			EditorCtrl* editor = m_app.GetEditorCtrl(p->editorId);
			if (!editor){
				// the editor has been closed
				OnEditorChanged(p->notifierId, false); // Send notification
				m_notifiers.erase(p->notifierId);
				p = m_editorWatchers.erase(p); // remove entry	
				continue; 
			}

			const unsigned int token = editor->GetChangeToken();
			if (token != p->changeToken) {
				wxLogDebug(wxT("token: %d"), token);
				OnEditorChanged(p->notifierId, true); // Send notification
				p->changeToken = token;
			}
		}
		++p;
	}
}
Example #3
0
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);
			}
		}
	}
}
Example #4
0
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();
}