Commits

Thibaut Colar committed bfd12d4

Open folder command and started suport for pod groups

  • Participants
  • Parent commits 7c852c0

Comments (0)

Files changed (13)

File src/brie/fan/Frame.fan

         MenuItem{ text= "Save File"; command = sys.commands.save.asCommand},
         MenuItem{ text= "New File"; command = sys.commands.newFile.asCommand},
         MenuItem{ text= "Reload File"; command = sys.commands.reload.asCommand},
+        MenuItem{ text= "Open Folder"; command = sys.commands.openFolder.asCommand},
         MenuItem{ text= "Exit"; command = sys.commands.exit.asCommand},
       },
       Menu {

File src/brie/fan/Shortcuts.fan

   const Str newFile               := "Ctrl+N"
   @Setting
   const Str reloadFile            := "Ctrl+R"
+  @Setting
+  const Str openFolder            := "Ctrl+O"
 
   @Setting
   const Str build                 := "F4"

File src/brie/fan/command/Commands.fan

     exit        = ExitCmd{}
     reload      = ReloadCmd{key = Key(sys.shortcuts.reloadFile)}
     save        = SaveCmd{key = Key(sys.shortcuts.saveFile)}
+    openFolder  = OpenFolderCmd{key = Key(sys.shortcuts.openFolder)}
     consoleToggle=ToggleConsoleCmd{key = Key(sys.shortcuts.consoleToggle)}
     recentToggle= ToggleRecentCmd{key = Key(sys.shortcuts.recentToggle)}
     docsToggle  = ToggleHelpCmd{key = Key(sys.shortcuts.docsToggle)}
   const Cmd searchDocs
   const Cmd mostRecent
   const Cmd newFile
+  const Cmd openFolder
   const Cmd recent := RecentCmd {}
 }
 

File src/brie/fan/command/FileCommands.fan

     }
 
     Str:Str tpls := [:] {ordered = true}
-    tpls["Empty File"] = ""
     Options.file.parent.listFiles.findAll |file->Bool|
       {return file.ext == "tpl"}
       .each{tpls[it.basename] = it.readAllStr
     }
+    tpls["Empty File"] = ""
 
     ok := Dialog.ok
     cancel := Dialog.cancel
   new make(|This| f) {f(this)}
 }
 
+internal const class OpenFolderCmd : Cmd
+{
+  override const Str name := "OpenFolder"
+  override Void invoke(Event event)
+  {
+    File? f := FileDialog
+    {
+      mode = FileDialogMode.openDir
+    }.open(frame)
+
+    if(f!=null)
+      frame.goto(Item(f))
+  }
+  new make(|This| f) {f(this)}
+}
+

File src/brie/fan/index/Index.fan

     if (id === "matchFiles")  return Unsafe(c.matchFiles(msg.a, msg.b))
     if (id === "addPodSrc")   return c.addPodSrc(msg.a, msg.b, msg.c)
     if (id === "addPodLib")   return c.addPodLib(msg.a, msg.b, msg.c)
+    if (id === "addGroup")   return c.addGroup(msg.a, msg.b)
     if (id === "clearAll")    return Actor.locals["cache"] = IndexCache(this)
 
     echo("ERROR: Unknown msg: $msg.id")

File src/brie/fan/index/IndexCache.fan

 
   Obj? addPodSrc(Str name, File srcDir, File[] srcFiles)
   {
-    //echo("$name -> $srcDir.osPath")
-    cur := pods[name] ?: PodInfo(name, null, TypeInfo[,], null, File#.emptyList)
+    cur := pods[name] ?: PodInfo(name, null, TypeInfo[,], null, File#.emptyList, null)
     if(cur.srcDir != null && cur.srcDir.uri !=  srcDir.uri)
       echo("WARNING: Ignoring second source root for pod $name : $cur.srcDir.osPath .. $srcDir.osPath")
     else
-      pods[name] = PodInfo(name, cur.podFile, cur.types, srcDir, srcFiles)
+      pods[name] = PodInfo(name, cur.podFile, cur.types, srcDir, srcFiles, findGroup(srcDir))
     return null
   }
 
+  ** If those pods are under a pod group, return it (ldeepest one)
+  private PodGroup? findGroup(File srcDir)
+  {
+    PodGroup? result := null
+    Str path := ""
+    groups.vals.each
+    {
+       cur := it.srcDir
+       if(srcDir.osPath.startsWith(cur.osPath))
+       {
+        if(cur.osPath.size > path.size)
+        {
+          path = cur.osPath
+          result = it
+        }
+       }
+    }
+    return result
+  }
+
   Obj? addPodLib(Str name, File podFile, TypeInfo[] types)
   {
-    //echo("$name -> $podFile.osPath")
-    cur := pods[name] ?: PodInfo(name, null, TypeInfo[,], null, File#.emptyList)
+    cur := pods[name] ?: PodInfo(name, null, TypeInfo[,], null, File#.emptyList, null)
     if(cur.podFile != null && cur.podFile.uri !=  podFile.uri)
       echo("WARNING: Ignoring second pod file for pod $name : $cur.podFile.osPath .. $podFile.osPath")
     else
-      pods[name] = PodInfo(name, podFile, types, cur.srcDir, cur.srcFiles)
+      pods[name] = PodInfo(name, podFile, types, cur.srcDir, cur.srcFiles, null)
+    return null
+  }
+
+  Obj? addGroup(File groupDir, Str? curGroup)
+  {
+    groups[groupDir.name] = PodGroup(groupDir, curGroup == null ? null : groups[curGroup])
     return null
   }
 
   }
 
   private Str:PodInfo pods := [:]
+  private Str:PodGroup groups := [:]
 }
 
 enum class MatchKind

File src/brie/fan/index/IndexCrawler.fan

 
 
   ** Index a folder of sources as provided by the user
-  private Void indexSrcDir(File dir)
+  private Void indexSrcDir(File dir, Str? curGroup := null)
   {
     if (!dir.isDir) return
     name := dir.name.lower
     if (name.startsWith(".")) return
     if (name == "temp" || name == "tmp" || name == "dist") return
 
+    // if buildgroup build file
+    if(isGroupSrcDir(dir))
+    {
+      index.cache.send(Msg("addGroup", dir, curGroup)).get
+      curGroup = dir.name
+    }
+
     // if build.fan with BuildPod
     if (isPodSrcDir(dir))
     {
     }
 
     // recurse
-    dir.listDirs.each |subDir| { indexSrcDir(subDir) }
+    dir.listDirs.each |subDir| { indexSrcDir(subDir, curGroup) }
   }
 
   ** Index a folder of pods(libraries) as provided by the user
   }
 
 
+  ** Whether this is dir has a roup build file
+  private Bool isGroupSrcDir(File dir)
+  {
+    if(dir.name == "src")
+      return false
+    return FileUtil.findBuildGroup(dir) != null
+  }
+
+  ** Whether this is dir has a pod build file
   private Bool isPodSrcDir(File dir)
   {
+    if(dir.name == "src")
+      return false
     return FileUtil.findBuildPod(dir, dir) != null
   }
 

File src/brie/fan/index/IndexModel.fan

 using concurrent
 
 ** Group is a dir with a BuilGroup type build file
-** And might contain multiple child pods
-/*const class PodGroup
+** And might contain multiple child pods (and maybe subgroups)
+const class PodGroup
 {
-   const Str name // folder name based
-   const File srcDir
-   const File builFile // Might be build.fan or buildall.fan ...
-} */
+  new make(File dir, PodGroup? parent)
+  {
+    this.srcDir = dir
+    this.name = dir.name
+    this.parent = parent
+  }
+  const Str name
+  const File srcDir
+  const PodGroup? parent
+}
 
 const class PodInfo
 {
-  new make(Str name, File? podFile, TypeInfo[] types, File? srcDir, File[] srcFiles)
+  new make(Str name, File? podFile, TypeInfo[] types,
+      File? srcDir, File[] srcFiles, PodGroup? group)
   {
     this.name       = name
     this.podFile    = podFile
     this.types      = types
     this.srcDir     = srcDir
     this.srcFiles   = srcFiles
-    // todo set parent if it's a group child
-    types.each |t| { t.podRef.val = this }
+    this.group      = group
+    types.each |t| { t.podRef.val = this; }
   }
 
   const Str name
   const TypeInfo[] types
   const File? srcDir
   const File[] srcFiles
-  //const PodGroup? parent
+  const PodGroup? group
 }
 
 const class TypeInfo

File src/brie/fan/space/FileSpace.fan

 
     // if path is file, make view for it
     Widget? view := null
+    echo(x.uri)
     if (!x.isDir) view = View.makeBest(frame, x)
 
     return EdgePane

File src/brie/fan/space/PodSpace.fan

   override Int match(Item item)
   {
     if (!FileUtil.contains(this.dir, item.file)) return 0
-      return 100
+      return 1000
   }
 
   override This goto(Item item)

File src/brie/fan/util/ActorUtil.fan

 **
 internal const class Msg
 {
-  new make(Str id, Obj? a := null, Obj? b := null, Obj? c := null)
+  new make(Str id, Obj? a := null, Obj? b := null, Obj? c := null, Obj? d :=null)
   {
     this.id = id
     this.a  = a
     this.b  = b
     this.c  = c
+    this.d  = d
   }
 
   const Str id
   const Obj? a
   const Obj? b
   const Obj? c
+  const Obj? d
 }

File src/brie/fan/util/FileUtil.fan

     if(dir == null)
       return null
     build :=  dir + `build.fan`
-    if(isBuildPod(build))
+    if(isBuildPod(build, "BuildPod"))
      return build
     build = dir + `src/build.fan`
-    if(isBuildPod(build))
+    if(isBuildPod(build, "BuildPod"))
      return build
     while(dir!=null && dir != upTo)
     {
       build = dir + `build.fan`
-      if(isBuildPod(build))
+      if(isBuildPod(build, "BuildPod"))
        return build
       dir = dir.parent
     }
     return null
   }
 
+  ** Look for a buildgroup build file
+  static File? findBuildGroup(File dir)
+  {
+    build :=  dir + `buildall.fan`
+    if(isBuildPod(build, "BuildGroup"))
+     return build
+    build =  dir + `build.fan`
+    if(isBuildPod(build, "BuildGroup"))
+     return build
+    build =  dir + `src/build.fan`
+    if(isBuildPod(build, "BuildGroup"))
+     return build
+    build =  dir + `src/buildall.fan`
+    if(isBuildPod(build, "BuildGroup"))
+     return build
+    return null
+  }
 
-  private static Bool isBuildPod(File buildFile)
+  private static Bool isBuildPod(File buildFile, Str type)
   {
     if(! buildFile.exists)
       return false
         if (line.contains("class ")) break
       }
       in.close
-      return line.contains("BuildPod")
+      return line.contains(type)
     }
     catch (Err e) e.trace
     return false
   }
+
 }

File src/brie/todo.txt

 rename file
 duplicate file
 
+replace in file
+replace in space
+
 allow copy from console output
 
 space nav pill -> right click: find in space (so don't need to open file to do it)
 If file is opened in file view but file exists in pod view - open it in pod view ??
 -> or if opening  folder in file view that is a pod, the juts open it has a pod (show pod icon in file nav ?)
 
-File space -> Make new source root checkbox ? -> -> what if alreday in source roots
-file view / dir -> Open as new space
-file space -> show only name rather than full path (full path on rollover)
-
 when file nav is used, highlight current file and stay on it (not reset navbar each time)
 or when open file -> highlight in navbar / scroll to
 
 if build group dir name is "src" use parent folder name / dir as root
 same for pod ? if src is the folder of build.fan then use the parent as root ?p
 
-F3 -> Goto (if on a type name) ... if multiple choices -> ask
-
 stack trace links in console ?
 
 icons for pod group parent , pod group child