src/Pure/System/options.scala
changeset 49245 cb70157293c0
parent 48992 0518bf89c777
child 49246 248e66e8321f
equal deleted inserted replaced
49244:fb669aff821e 49245:cb70157293c0
     5 */
     5 */
     6 
     6 
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
       
    10 import java.util.Locale
    10 import java.util.Calendar
    11 import java.util.Calendar
    11 
    12 
    12 
    13 
    13 object Options
    14 object Options
    14 {
    15 {
    19 
    20 
    20   /* representation */
    21   /* representation */
    21 
    22 
    22   sealed abstract class Type
    23   sealed abstract class Type
    23   {
    24   {
    24     def print: String = toString.toLowerCase
    25     def print: String = toString.toLowerCase(Locale.ENGLISH)
    25   }
    26   }
    26   private case object Bool extends Type
    27   private case object Bool extends Type
    27   private case object Int extends Type
    28   private case object Int extends Type
    28   private case object Real extends Type
    29   private case object Real extends Type
    29   private case object String extends Type
    30   private case object String extends Type
   126   def print: String =
   127   def print: String =
   127     cat_lines(options.toList.sortBy(_._1).map({ case (name, opt) =>
   128     cat_lines(options.toList.sortBy(_._1).map({ case (name, opt) =>
   128       "option " + name + " : " + opt.typ.print + " = " +
   129       "option " + name + " : " + opt.typ.print + " = " +
   129         (if (opt.typ == Options.String) quote(opt.value) else opt.value) +
   130         (if (opt.typ == Options.String) quote(opt.value) else opt.value) +
   130       (if (opt.description == "") "" else "\n  -- " + quote(opt.description)) }))
   131       (if (opt.description == "") "" else "\n  -- " + quote(opt.description)) }))
       
   132 
       
   133   def title(strip: String, name: String): String =
       
   134   {
       
   135     check_name(name)
       
   136     val words = space_explode('_', name)
       
   137     val words1 =
       
   138       words match {
       
   139         case word :: rest if word == strip => rest
       
   140         case _ => words
       
   141       }
       
   142     words1.map(Library.capitalize).mkString(" ")
       
   143   }
       
   144 
       
   145   def description(name: String): String = check_name(name).description
   131 
   146 
   132 
   147 
   133   /* check */
   148   /* check */
   134 
   149 
   135   private def check_name(name: String): Options.Opt =
   150   private def check_name(name: String): Options.Opt =
   300     Options.PREFS.file renameTo Options.PREFS_BACKUP.file
   315     Options.PREFS.file renameTo Options.PREFS_BACKUP.file
   301     File.write(Options.PREFS,
   316     File.write(Options.PREFS,
   302       "(* generated by Isabelle " + Calendar.getInstance.getTime + " *)\n\n" + prefs)
   317       "(* generated by Isabelle " + Calendar.getInstance.getTime + " *)\n\n" + prefs)
   303   }
   318   }
   304 }
   319 }
       
   320 
       
   321 
       
   322 class Options_Variable
       
   323 {
       
   324   // owned by Swing thread
       
   325   @volatile private var options = Options.empty
       
   326 
       
   327   def value: Options = options
       
   328   def update(new_options: Options)
       
   329   {
       
   330     Swing_Thread.require()
       
   331     options = new_options
       
   332   }
       
   333 
       
   334   def + (name: String, x: String)
       
   335   {
       
   336     Swing_Thread.require()
       
   337     options = options + (name, x)
       
   338   }
       
   339 
       
   340   val bool = new Object
       
   341   {
       
   342     def apply(name: String): Boolean = options.bool(name)
       
   343     def update(name: String, x: Boolean)
       
   344     {
       
   345       Swing_Thread.require()
       
   346       options = options.bool.update(name, x)
       
   347     }
       
   348   }
       
   349 
       
   350   val int = new Object
       
   351   {
       
   352     def apply(name: String): Int = options.int(name)
       
   353     def update(name: String, x: Int)
       
   354     {
       
   355       Swing_Thread.require()
       
   356       options = options.int.update(name, x)
       
   357     }
       
   358   }
       
   359 
       
   360   val real = new Object
       
   361   {
       
   362     def apply(name: String): Double = options.real(name)
       
   363     def update(name: String, x: Double)
       
   364     {
       
   365       Swing_Thread.require()
       
   366       options = options.real.update(name, x)
       
   367     }
       
   368   }
       
   369 
       
   370   val string = new Object
       
   371   {
       
   372     def apply(name: String): String = options.string(name)
       
   373     def update(name: String, x: String)
       
   374     {
       
   375       Swing_Thread.require()
       
   376       options = options.string.update(name, x)
       
   377     }
       
   378   }
       
   379 }
       
   380