Commits

Thibaut Colar committed 6ac1e06

Moved theme away from being static and made Sys a service so not to have to pass it all over the place

Comments (0)

Files changed (14)

src/brie/fan/Commands.fan

           it.col  = col
           it.span = span
           it.dis  = dis
-          it.icon = Theme.iconMark
+          it.icon = this.sys.theme.iconMark
         })
         col = chars.index(str, col+str.size)
       }

src/brie/fan/Frame.fan

 
   internal Void updateStatus()
   {
-    title := "Brie"
+    title := "Camembert"
     if (curView != null)
     {
       title += " $curView.file.name"
 // Private Fields
 //////////////////////////////////////////////////////////////////////////
 
-  private File sessionFile := Env.cur.workDir + `etc/brie/session.props`
+  private File sessionFile := Env.cur.workDir + `etc/camenbert/session.props`
   private SpaceBar spaceBar
   private ContentPane spacePane
   private StatusBar statusBar

src/brie/fan/History.fan

 
 internal class HistoryPickerModel : TableModel
 {
+  const Sys? sys := Service.find(Sys#) as Sys
+
   new make(Item[] items) { this.items = items }
 
   override Int numCols() { return 3 }
     }
   }
   Item[] items
-  Image def := Theme.iconFile
+  Image def := sys.theme.iconFile
   Font accFont := Desktop.sysFont.toSize(Desktop.sysFont.size-1)
   Color accColor := Color("#666")
 }

src/brie/fan/Main.fan

 
 class Main
 {
-  static Void main() { Frame(Sys()).open }
+  static Void main() 
+  {
+    sys := Sys()
+    sys.install 
+    Frame(sys).open 
+  }
 }
 

src/brie/fan/Options.fan

   ** Reload options
   static Options load()
   {
-    f := Env.cur.workDir + `etc/brie/options.fog`
+    f := Env.cur.workDir + `etc/camenbert/options.fog`
     try
       if (f.exists) return f.readObj
     catch (Err e)
 
   ** File of `fanHomeUri`
   const File fanHome
+  
+  ** Name of theme to use (saved in etc/camembert/theme-name.fog)
+  const Str theme := "default"
 }
 

src/brie/fan/Sys.fan

 **
 ** Sys manages references to system services
 **
-const class Sys
+const class Sys : Service
 {
   ** Configuration options
   const Options options := Options.load
 
+  ** Theme
+  const Theme theme := Theme.load(options.theme)
+  
   ** Indexing service
   const Index index := Index(this)
 
   Frame frame() { Actor.locals["frame"] ?: throw Err("Not on UI thread") }
 
   ** Logger
-  const Log log := Log.get("brie")
+  const Log log := Log.get("camembert")
 }
 

src/brie/fan/space/FileSpace.fan

 
   override const Str dis
 
-  override Image icon() { Theme.iconDir }
+  override Image icon() { sys.theme.iconDir }
 
   override Str:Str saveSession()
   {

src/brie/fan/space/HomeSpace.fan

   new make(Sys sys) : super(sys) {}
 
   override Str dis() { "home" }
-  override Image icon() { Theme.iconHome }
+  override Image icon() { sys.theme.iconHome }
 
   override Str:Str saveSession()
   {

src/brie/fan/space/PodSpace.fan

 
   override Str dis() { name }
 
-  override Image icon() { Theme.iconPod }
+  override Image icon() { sys.theme.iconPod }
 
   override File? curFile() { file }
 

src/brie/fan/util/Console.fan

       it.dis  = text
       it.line = line-1
       it.col  = col-1
-      it.icon = Theme.iconErr
+      it.icon = sys.theme.iconErr
     }
   }
 
     {
       it.dis  = text
       it.line = line-1
-      it.icon = Theme.iconErr
+      it.icon = sys.theme.iconErr
     }
   }
 

src/brie/fan/util/Item.fan

 **
 const class Item
 {
+  const Sys? sys := Service.find(Sys#) as Sys
+  
   static Item[] makeFiles(File[] files)
   {
     acc := Item[,]
   new makePod(PodInfo p, |This|? f := null)
   {
     this.dis  = p.name
-    this.icon = Theme.iconPod
+    this.icon = sys.theme.iconPod
     this.file = p.srcDir + `build.fan`
     this.pod  = p
     if (f != null) f(this)
   new makeType(TypeInfo t, |This|? f := null)
   {
     this.dis  = t.qname
-    this.icon = Theme.iconType
+    this.icon = sys.theme.iconType
     this.file = t.toFile
     this.line = t.line
     this.pod  = t.pod
   new makeSlot(SlotInfo s, |This|? f := null)
   {
     this.dis  = s.qname
-    this.icon = s is FieldInfo ? Theme.iconField : Theme.iconMethod
+    this.icon = s is FieldInfo ? sys.theme.iconField : sys.theme.iconMethod
     this.file = s.type.toFile
     this.line = s.line
     this.col  = 2

src/brie/fan/util/SpaceBar.fan

     }
     menu.open(e.widget, e.pos)
   }
+  static const Sys? sys := Service.find(Sys#) as Sys
 
   static const Font font   := Desktop.sysFont
-  static const Color bgBar := Theme.wallpaper
+  static const Color bgBar := sys.theme.wallpaper
   static const Color bgTab := Color(0xee_ee_ee)
   static const Color bgCur := Color.green
   static const Color fgTab := Color(0x66_66_66)

src/brie/fan/util/StatusBar.fan

   Void update()
   {
     // console up/down
-    console.image = frame.console.isOpen ? Theme.iconSlideDown : Theme.iconSlideUp
+    console.image = frame.console.isOpen ? sys.theme.iconSlideDown : sys.theme.iconSlideUp
 
     // indexing
-    index.image = sys.index.isIndexing ? Theme.iconIndexing : Theme.iconOk
+    index.image = sys.index.isIndexing ? sys.theme.iconIndexing : sys.theme.iconOk
 
     // view file
     v := frame.curView
     if (v != null)
     {
       file.text = FileUtil.pathDis(v.file)
-      file.image = v.dirty ? Theme.iconDirty : Theme.iconNotDirty
+      file.image = v.dirty ? sys.theme.iconDirty : sys.theme.iconNotDirty
       view.text = v.curStatus
     }
     else

src/brie/fan/util/Theme.fan

 **
 ** Theme constants
 **
+@Serializable
 const class Theme
 {
-  static const Image iconHome      := Image(`fan://brie/res/home.png`)
-  static const Image iconFile      := Image(`fan://icons/x16/file.png`)
-  static const Image iconDir       := Image(`fan://icons/x16/folder.png`)
-  static const Image iconImage     := Image(`fan://icons/x16/fileImage.png`)
-  static const Image iconFan       := Image(`fan://icons/x16/fileFan.png`)
-  static const Image iconJava      := Image(`fan://icons/x16/fileJava.png`)
-  static const Image iconJs        := Image(`fan://icons/x16/fileJs.png`)
-  static const Image iconCs        := Image(`fan://icons/x16/fileCs.png`)
-  static const Image iconErr       := Image(`fan://icons/x16/err.png`)
-  static const Image iconOk        := Image(`fan://brie/res/ok.png`)
-  static const Image iconIndexing  := Image(`fan://icons/x16/sync.png`)
-  static const Image iconSlideUp   := Image(`fan://brie/res/slideUp.png`)
-  static const Image iconSlideDown := Image(`fan://brie/res/slideDown.png`)
-  static const Image iconDirty     := Image(`fan://brie/res/dirty.png`)
-  static const Image iconNotDirty  := Image(`fan://brie/res/notDirty.png`)
-  static const Image iconPod       := Image(`fan://icons/x16/database.png`)
-  static const Image iconType      := Image(`fan://brie/res/type.png`)
-  static const Image iconField     := Image(`fan://brie/res/field.png`)
-  static const Image iconMethod    := Image(`fan://brie/res/method.png`)
-  static const Image iconMark      := Image(`fan://icons/x16/tag.png`)
+  @Transient
+  const Str name := "default"
+  
+  ** Reload options
+  static Theme load(Str name)
+  {
+    template := Env.cur.workDir + `etc/camenbert/template.fog`
+    try
+      if (template.exists) return template.readObj
+    catch (Err e)
+      echo("ERROR: Cannot load $template\n  $e")
+    return Theme()
+  }
+
+  ** Default constructor with it-block
+  new make(|This|? f := null)
+  {
+    if (f != null) f(this)
+  }
+
+  const Color wallpaper := Color.white
+  const Color bg := Color.white
+  const Color itemHeadingBg := Color(0xdd_dd_dd)
+  
+  const Image iconHome      := Image(`fan://camembert/res/home.png`)
+  const Image iconFile      := Image(`fan://icons/x16/file.png`)
+  const Image iconDir       := Image(`fan://icons/x16/folder.png`)
+  const Image iconImage     := Image(`fan://icons/x16/fileImage.png`)
+  const Image iconFan       := Image(`fan://icons/x16/fileFan.png`)
+  const Image iconJava      := Image(`fan://icons/x16/fileJava.png`)
+  const Image iconJs        := Image(`fan://icons/x16/fileJs.png`)
+  const Image iconCs        := Image(`fan://icons/x16/fileCs.png`)
+  const Image iconErr       := Image(`fan://icons/x16/err.png`)
+  const Image iconOk        := Image(`fan://camembert/res/ok.png`)
+  const Image iconIndexing  := Image(`fan://icons/x16/sync.png`)
+  const Image iconSlideUp   := Image(`fan://camembert/res/slideUp.png`)
+  const Image iconSlideDown := Image(`fan://camembert/res/slideDown.png`)
+  const Image iconDirty     := Image(`fan://camembert/res/dirty.png`)
+  const Image iconNotDirty  := Image(`fan://camembert/res/notDirty.png`)
+  const Image iconPod       := Image(`fan://icons/x16/database.png`)
+  const Image iconType      := Image(`fan://camembert/res/type.png`)
+  const Image iconField     := Image(`fan://camembert/res/field.png`)
+  const Image iconMethod    := Image(`fan://camembert/res/method.png`)
+  const Image iconMark      := Image(`fan://icons/x16/tag.png`)
 
   static Image fileToIcon(File f)
   {
-    if (f.isDir) return iconDir
-    if (f.mimeType?.mediaType == "image") return iconImage
-    if (f.ext == "fan")  return iconFan
-    if (f.ext == "java") return iconJava
-    if (f.ext == "js")   return iconJs
-    if (f.ext == "cs")   return iconCs
-    return iconFile
+    Sys? sys := Service.find(Sys#) as Sys
+    t := sys.theme
+
+    if (f.isDir) return t.iconDir
+    if (f.mimeType?.mediaType == "image") return t.iconImage
+    if (f.ext == "fan")  return t.iconFan
+    if (f.ext == "java") return t.iconJava
+    if (f.ext == "js")   return t.iconJs
+    if (f.ext == "cs")   return t.iconCs
+    return t.iconFile
   }
 
-  static const Color wallpaper := Panel.wallpaperColor
-  static const Color bg := Color(0xff_ff_ff)
-  static const Color itemHeadingBg := Color(0xdd_dd_dd)
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.