src/Tools/jEdit/src/isabelle_vfs.scala
changeset 75393 87ebf5a50283
parent 71601 97ccf48c2f0c
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    31     (if (delete) VFS.DELETE_CAP else 0) |
    31     (if (delete) VFS.DELETE_CAP else 0) |
    32     (if (rename) VFS.RENAME_CAP else 0) |
    32     (if (rename) VFS.RENAME_CAP else 0) |
    33     (if (mkdir) VFS.MKDIR_CAP else 0) |
    33     (if (mkdir) VFS.MKDIR_CAP else 0) |
    34     (if (low_latency) VFS.LOW_LATENCY_CAP else 0) |
    34     (if (low_latency) VFS.LOW_LATENCY_CAP else 0) |
    35     (if (case_insensitive) VFS.CASE_INSENSITIVE_CAP else 0) |
    35     (if (case_insensitive) VFS.CASE_INSENSITIVE_CAP else 0) |
    36     (if (non_awt_session) VFS.NON_AWT_SESSION_CAP else 0))
    36     (if (non_awt_session) VFS.NON_AWT_SESSION_CAP else 0)
    37 {
    37 ) {
    38   /* URL structure */
    38   /* URL structure */
    39 
    39 
    40   def explode_name(s: String): List[String] = space_explode(getFileSeparator, s)
    40   def explode_name(s: String): List[String] = space_explode(getFileSeparator, s)
    41   def implode_name(elems: Iterable[String]): String = elems.mkString(getFileSeparator.toString)
    41   def implode_name(elems: Iterable[String]): String = elems.mkString(getFileSeparator.toString)
    42 
    42 
    43   def explode_url(url: String, component: Component = null): Option[List[String]] =
    43   def explode_url(url: String, component: Component = null): Option[List[String]] = {
    44   {
       
    45     Library.try_unprefix(prefix, url) match {
    44     Library.try_unprefix(prefix, url) match {
    46       case Some(path) => Some(explode_name(path).filter(_.nonEmpty))
    45       case Some(path) => Some(explode_name(path).filter(_.nonEmpty))
    47       case None =>
    46       case None =>
    48         if (component != null) VFSManager.error(component, url, "ioerror.badurl", Array(url))
    47         if (component != null) VFSManager.error(component, url, "ioerror.badurl", Array(url))
    49         None
    48         None
    50     }
    49     }
    51   }
    50   }
    52   def implode_url(elems: Iterable[String]): String = prefix + implode_name(elems)
    51   def implode_url(elems: Iterable[String]): String = prefix + implode_name(elems)
    53 
    52 
    54   override def constructPath(parent: String, path: String): String =
    53   override def constructPath(parent: String, path: String): String = {
    55   {
       
    56     if (parent == "") path
    54     if (parent == "") path
    57     else if (parent(parent.length - 1) == getFileSeparator || parent == prefix) parent + path
    55     else if (parent(parent.length - 1) == getFileSeparator || parent == prefix) parent + path
    58     else parent + getFileSeparator + path
    56     else parent + getFileSeparator + path
    59   }
    57   }
    60 
    58 
    61 
    59 
    62   /* directory content */
    60   /* directory content */
    63 
    61 
    64   override def isMarkersFileSupported: Boolean = false
    62   override def isMarkersFileSupported: Boolean = false
    65 
    63 
    66   def make_entry(path: String, is_dir: Boolean = false, size: Long = 0L): VFSFile =
    64   def make_entry(path: String, is_dir: Boolean = false, size: Long = 0L): VFSFile = {
    67   {
       
    68     val entry = explode_name(path).lastOption getOrElse ""
    65     val entry = explode_name(path).lastOption getOrElse ""
    69     val url = prefix + path
    66     val url = prefix + path
    70     new VFSFile(entry, url, url, if (is_dir) VFSFile.DIRECTORY else VFSFile.FILE, size, false)
    67     new VFSFile(entry, url, url, if (is_dir) VFSFile.DIRECTORY else VFSFile.FILE, size, false)
    71   }
    68   }
    72 
    69 
    73   override def _getFile(vfs_session: AnyRef, url: String, component: Component): VFSFile =
    70   override def _getFile(vfs_session: AnyRef, url: String, component: Component): VFSFile = {
    74   {
       
    75     val parent = getParentOfPath(url)
    71     val parent = getParentOfPath(url)
    76     if (parent == prefix) new VFSFile(prefix, prefix, prefix, VFSFile.DIRECTORY, 0L, false)
    72     if (parent == prefix) new VFSFile(prefix, prefix, prefix, VFSFile.DIRECTORY, 0L, false)
    77     else {
    73     else {
    78       val files = _listFiles(vfs_session, parent, component)
    74       val files = _listFiles(vfs_session, parent, component)
    79       if (files == null) null
    75       if (files == null) null