예제 #1
0
파일: ApiHandler.cpp 프로젝트: BBkBlade/e
void ApiHandler::IpcEditorSelect(EditorCtrl& editor, IConnection& conn) {
	const hessian_ipc::Call& call = *conn.get_call();
	const int v2 = call.GetParameter(1).GetInt();
	const int v3 = call.GetParameter(2).GetInt();

	if (v2 != v3) {
		editor.Select(v2, v3);
		editor.MakeSelectionVisible();
	}
	editor.SetPos(v3);
	editor.ReDraw();

	hessian_ipc::Writer& writer = conn.get_reply_writer();
	writer.write_reply(true);
}
예제 #2
0
파일: ApiHandler.cpp 프로젝트: BBkBlade/e
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);
}
예제 #3
0
파일: ApiHandler.cpp 프로젝트: BBkBlade/e
void ApiHandler::IpcEditorInsertTabStops(EditorCtrl& editor, IConnection& conn) {
	const hessian_ipc::Call& call = *conn.get_call();
	const hessian_ipc::Value& v2 = call.GetParameter(1);
	const hessian_ipc::List& tabstops = v2.AsList();

	if (!tabstops.empty()) {
		SnippetHandler& sh = editor.GetSnippetHandler();
		sh.Clear();
		for (size_t i = 0; i < tabstops.size(); ++i) {
			const hessian_ipc::List& t = tabstops.get(i).AsList();
			const interval iv(t.get(0).GetInt(), t.get(1).GetInt());
			const string& s = t.get(2).GetString();
			const wxString text(s.c_str(), wxConvUTF8, s.size());

			sh.AddTabStop(iv, text);
		}
		sh.NextTab();
		editor.ReDraw();
	}

	hessian_ipc::Writer& writer = conn.get_reply_writer();
	writer.write_reply_null();
}
예제 #4
0
파일: ApiHandler.cpp 프로젝트: BBkBlade/e
void ApiHandler::OnIpcCall(wxCommandEvent& event) {
	IConnection* conn = (IConnection*)event.GetClientData();
	if (!conn) return;

	const hessian_ipc::Call* call = conn->get_call();
	hessian_ipc::Writer& writer = conn->get_reply_writer();
	if (!call) return;

	const string& m = call->GetMethod();
	const wxString method(m.c_str(), wxConvUTF8, m.size());

	wxLogDebug(wxT("IPC: %s"), method.c_str());

	// Call the function (if it exists)
	bool methodFound = true;
	if (call->IsObjectCall()) {
		const hessian_ipc::Call& call = *conn->get_call();
		const hessian_ipc::Value& v1 = call.GetParameter(0);
		const int editorId = -v1.GetInt();

		EditorCtrl* editor = m_app.GetEditorCtrl(editorId);
		if (!editor) {
			writer.write_fault(hessian_ipc::NoSuchObjectException, "Unknown object");
			conn->reply_done();
			return;
		}

		map<string, PIpcEdFun>::const_iterator p = m_ipcEditorFunctions.find(m.c_str());
		if (p != m_ipcEditorFunctions.end()) {
			try {
				(this->*p->second)(*editor, *conn);
			}
			catch (exception& e) {
				writer.write_fault(hessian_ipc::ServiceException, e.what());
				conn->reply_done();
				return;
			}
		}
		else {
			eMacroCmd cmd(method);
			for (size_t i = 1; i < call.GetParameterCount(); ++i) {
				const hessian_ipc::Value& v = call.GetParameter(i);

				if (v.IsBoolean()) cmd.AddArg(v.GetBoolean());
				else if (v.IsInt()) cmd.AddArg(v.GetInt());
				else if (v.IsString()) {
					const string& arg = v.GetString();
					const wxString argstr(arg.c_str(), wxConvUTF8, arg.size());
					cmd.AddArg(argstr);
				}
				else wxASSERT(false);
			}

			const wxVariant reply = editor->PlayCommand(cmd);
			if (reply.GetName() == wxT("Unknown method")) methodFound = false;
			else editor->ReDraw();

			//TODO: write variant
			writer.write_reply_null();
		}
	}
	else {
		map<string, PIpcFun>::const_iterator p = m_ipcFunctions.find(m.c_str());
		if (p != m_ipcFunctions.end()) {
			try {
				(this->*p->second)(*conn);
			}
			catch (exception& e) {
				writer.write_fault(hessian_ipc::ServiceException, e.what());
				conn->reply_done();
				return;
			}
		}
		else methodFound = false;
	}

	if (!methodFound) {
		writer.write_fault(hessian_ipc::NoSuchMethodException, "Unknown method");
	}

	// Notify connection that it can send the reply (threadsafe)
	conn->reply_done();
}