privatedef remove_overlay(): Unit = { val state = current_state.value for (command <- state.location) {
editor.remove_overlay(command, print_function, state.instance :: state.query)
}
}
/* content update */
privatedef content_update(): Unit = {
editor.require_dispatcher {}
/* snapshot */
val state0 = current_state.value
val (output, removed) =
state0.location match { case Some(cmd) => val snapshot = editor.node_snapshot(cmd.node_name) val results = snapshot.command_results(cmd) val messages =
List.from( for { case (_, msg@XML.Elem(Markup(Markup.RESULT, props@Markup.Instance(instance)), _))
<- results.iterator if instance == state0.instance
} yield msg) val removed = !snapshot.get_node(cmd.node_name).commands.contains(cmd)
(Editor.Output(snapshot, results, messages), removed) case None => (Editor.Output.init, true)
}
/* resolve sendback: static command id */
def resolve_sendback(body: XML.Body): XML.Body = {
state0.location match { case None => body case Some(command) => def resolve(body: XML.Body): XML.Body =
body map { case XML.Wrapped_Elem(m, b1, b2) => XML.Wrapped_Elem(m, resolve(b1), resolve(b2)) case XML.Elem(Markup(Markup.SENDBACK, props), b) => val props1 =
props.map({ case (Markup.ID, Value.Long(id)) if id == state0.exec_id =>
(Markup.ID, Value.Long(command.id)) case p => p
})
XML.Elem(Markup(Markup.SENDBACK, props1), resolve(b)) case XML.Elem(m, b) => XML.Elem(m, resolve(b)) case t => t
}
resolve(body)
}
}
/* output */
val new_output = for { case XML.Elem(_, List(XML.Elem(markup, body))) <- output.messages if Markup.messages.contains(markup.name)
body1 = resolve_sendback(body)
} yield Protocol.make_message(body1, markup.name, props = markup.properties)
/* status */
def get_status(name: String, status: Query_Operation.Status): Option[Query_Operation.Status] =
output.messages.collectFirst(
{ case XML.Elem(_, List(elem: XML.Elem)) if elem.name == name => status })
val new_status = if (removed) Query_Operation.Status.finished else
get_status(Markup.FINISHED, Query_Operation.Status.finished) orElse
get_status(Markup.RUNNING, Query_Operation.Status.running) getOrElse
Query_Operation.Status.waiting
/* state update */
if (new_status == Query_Operation.Status.running)
output.messages.collectFirst(
{ case XML.Elem(Markup(_, Position.Id(id)), List(elem: XML.Elem)) if elem.name == Markup.RUNNING => id
}).foreach(id => current_state.change(_.copy(exec_id = id)))
def cancel_query(): Unit =
editor.require_dispatcher { editor.session.cancel_exec(current_state.value.exec_id) }
def apply_query(query: List[String]): Unit = {
editor.require_dispatcher {}
editor.current_node_snapshot(editor_context) match { case Some(snapshot) =>
remove_overlay()
current_state.change(_ => Query_Operation.State.empty)
consume_output(Editor.Output.init)
editor.current_command(editor_context, snapshot) match { case Some(command) => val state = Query_Operation.State.make(command, query)
current_state.change(_ => state)
editor.insert_overlay(command, print_function, state.instance :: query) case None =>
}
consume_status(current_state.value.status)
editor.flush() case None =>
}
}
def query_command(): Option[(Document.Snapshot, Command)] =
editor.require_dispatcher { val state = current_state.value for {
command <- state.location
snapshot = editor.node_snapshot(command.node_name) if !snapshot.is_outdated
} yield (snapshot, command)
}
def locate_query(): Unit = for {
(snapshot, command) <- query_command()
link <- editor.hyperlink_command(snapshot, command.id, focus = true)
} link.follow(editor_context)
/* main */
privateval main =
Session.Consumer[Session.Commands_Changed](getClass.getName) { case changed => val state = current_state.value
state.location match { case Some(command) if state.update_pending ||
(state.status != Query_Operation.Status.finished &&
changed.commands.contains(command)) =>
editor.send_dispatcher { content_update() } case _ =>
}
}
def activate(): Unit = {
editor.session.commands_changed += main
}
def deactivate(): Unit = {
editor.session.commands_changed -= main
remove_overlay()
current_state.change(_ => Query_Operation.State.empty)
consume_output(Editor.Output.init)
consume_status(Query_Operation.Status.finished)
}
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.