src/Tools/jEdit/src/proofdocument/session.scala
changeset 34813 f0107bc96961
parent 34810 9ad3431a34a5
child 34815 6bae73cd8e33
equal deleted inserted replaced
34812:4c875ed8b248 34813:f0107bc96961
     9 
     9 
    10 import scala.actors.Actor._
    10 import scala.actors.Actor._
    11 
    11 
    12 object Session
    12 object Session
    13 {
    13 {
       
    14   /* events */
       
    15 
    14   case object Global_Settings
    16   case object Global_Settings
       
    17 
       
    18 
       
    19   /* managed entities */
       
    20 
       
    21   type Entity_ID = String
       
    22 
       
    23   trait Entity
       
    24   {
       
    25     val id: Entity_ID
       
    26     def consume(session: Session, message: XML.Tree): Unit
       
    27   }
    15 }
    28 }
    16 
    29 
    17 
    30 
    18 class Session(system: Isabelle_System)
    31 class Session(system: Isabelle_System)
    19 {
    32 {
    28 
    41 
    29 
    42 
    30   /* unique ids */
    43   /* unique ids */
    31 
    44 
    32   private var id_count: BigInt = 0
    45   private var id_count: BigInt = 0
    33   def create_id(): String = synchronized { id_count += 1; "j" + id_count }
    46   def create_id(): Session.Entity_ID = synchronized { id_count += 1; "j" + id_count }
    34 
    47 
    35 
    48 
    36   /* document state information -- owned by session_actor */
    49   /* document state information -- owned by session_actor */
    37 
    50 
    38   @volatile private var outer_syntax = new Outer_Syntax(system.symbols)
    51   @volatile private var outer_syntax = new Outer_Syntax(system.symbols)
    88 
   101 
    89     def handle_result(result: Isabelle_Process.Result)
   102     def handle_result(result: Isabelle_Process.Result)
    90     {
   103     {
    91       raw_results.event(result)
   104       raw_results.event(result)
    92 
   105 
    93       val state =
   106       val target: Option[Session.Entity] =
    94         Position.id_of(result.props) match {
   107         Position.id_of(result.props) match {
    95           case None => None
   108           case None => None
    96           case Some(id) => commands.get(id) orElse states.get(id) orElse None
   109           case Some(id) => commands.get(id) orElse states.get(id) orElse None
    97         }
   110         }
    98       if (state.isDefined) state.get ! (this, result.message)
   111       if (target.isDefined) target.get.consume(this, result.message)
    99       else if (result.kind == Isabelle_Process.Kind.STATUS) {
   112       else if (result.kind == Isabelle_Process.Kind.STATUS) {
   100         //{{{ global status message
   113         //{{{ global status message
   101         for (elem <- result.body) {
   114         for (elem <- result.body) {
   102           elem match {
   115           elem match {
   103             // document edits
   116             // document edits
   109                     XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
   122                     XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
   110                     <- edits }
   123                     <- edits }
   111                   {
   124                   {
   112                     commands.get(cmd_id) match {
   125                     commands.get(cmd_id) match {
   113                       case Some(cmd) =>
   126                       case Some(cmd) =>
   114                         val state = new Command_State(cmd)
   127                         val state = new Command_State(state_id, cmd)
   115                         states += (state_id -> state)
   128                         states += (state_id -> state)
   116                         doc.states += (cmd -> state)
   129                         doc.states += (cmd -> state)
   117                         command_change.event(cmd)   // FIXME really!?
   130                         command_change.event(cmd)   // FIXME really!?
   118                       case None =>
   131                       case None =>
   119                     }
   132                     }