Commits

Thibaut Colar committed 4a93a7f

Menubar that can run all the commands

  • Participants
  • Parent commits 835e0d6

Comments (0)

Files changed (3)

File src/brie/fan/Commands.fan

   Options options() { sys.options }
   Frame frame() { sys.frame }
   Console console() { frame.console }
+  
+  Command asCommand()
+  {
+    Command(name, null, |Event e| {invoke(e)})
+  }
 }
 
 **************************************************************************

File src/brie/fan/Frame.fan

 class Frame : Window
 {
 
-//////////////////////////////////////////////////////////////////////////
-// Constructor
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Constructor
+  //////////////////////////////////////////////////////////////////////////
 
   ** Construct for given system
   new make(Sys sys) : super(null)
     this.sys = sys
     this.icon = Image(`fan://icons/x32/blueprints.png`)
     Actor.locals["frame"] = this
+   
+    // menu
+    menuBar = Menu{
+      Menu {
+        text = "File"
+        MenuItem{ text= "Save"; command = sys.commands.save.asCommand},
+        MenuItem{ text= "Reload"; command = sys.commands.reload.asCommand},
+        MenuItem{ text= "Exit"; command = sys.commands.exit.asCommand},
+      },
+      Menu {
+        text = "Navigation"
+        MenuItem{ text= "Recent"; command = sys.commands.recent.asCommand},
+        MenuItem{ text= "Prev mark"; command = sys.commands.prevMark.asCommand},
+        MenuItem{ text= "Next mark"; command = sys.commands.nextMark.asCommand},
+        MenuItem{ text= "Find"; command = sys.commands.find.asCommand},
+        MenuItem{ text= "Find in space"; command = sys.commands.findInSpace.asCommand},
+        MenuItem{ text= "Goto"; command = sys.commands.goto.asCommand},
+      },
+      Menu {
+        text = "Run"
+        MenuItem{ text= "Build"; command = sys.commands.build.asCommand},
+        MenuItem{ text= "Quit process"; command = sys.commands.esc.asCommand},
+      },
+    }
 
     // eventing
     onClose.add |Event e| { e.consume; sys.commands.exit.invoke(e) }
     load(curSpace, 0, null)
   }
 
-//////////////////////////////////////////////////////////////////////////
-// Access
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Access
+  //////////////////////////////////////////////////////////////////////////
 
   ** System services
   const Sys sys
   ** Navigation history
   History history := History() { private set }
 
-//////////////////////////////////////////////////////////////////////////
-// Space Lifecycle
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Space Lifecycle
+  //////////////////////////////////////////////////////////////////////////
 
   ** Select given space
   Void select(Space space)
     // check if current view is on item
     if (curView?.file == item.file) { curView.onGoto(item); return }
 
-    // find best space to handle item, or create new one
+      // find best space to handle item, or create new one
     best := matchSpace(item)
     if (best != null)
     {
     {
       c := create(item).goto(item)
       if (c == null) { echo("WARN: Cannot create space $item.dis"); return }
-      load(c, null, item)
+        load(c, null, item)
     }
   }
 
   {
     i := spaceIndex(space)
     if (i == 0) return
-    spaces = spaces.dup { removeAt(i) }.toImmutable
+      spaces = spaces.dup { removeAt(i) }.toImmutable
     if (curSpace == space)
       curSpace = spaces.getSafe(i) ?: spaces.last
     reload
     // current always trumps others
     if (curSpace.match(item) > 0) return curSpace
 
-    // find best match
+      // find best match
     Space? bestSpace := null
     Int bestPriority := 0
     this.spaces.each |s|
     {
       priority := s.match(item)
       if (priority == 0) return
-      if (priority > bestPriority) { bestSpace = s; bestPriority = priority }
-    }
+        if (priority > bestPriority) { bestSpace = s; bestPriority = priority }
+      }
     return bestSpace
   }
 
   {
     if (item.space != null) return item.space
 
-    file := item.file
+      file := item.file
     if (file == null) return null
 
-    pod := sys.index.podForFile(file)
+      pod := sys.index.podForFile(file)
     if (pod != null) return PodSpace(sys, pod.name, pod.srcDir)
 
-    dir := file.isDir ? file : file.parent
+      dir := file.isDir ? file : file.parent
     return FileSpace(sys, dir)
   }
 
     // confirm if we should close
     if (!confirmClose) return
 
-    // save current file line number
+      // save current file line number
     if (curView != null)
       filePosHis[curView.file] = curView.curPos
 
     // save curItem and push into history
     if (item != null) history.push(space, item)
 
-    // relayout
+      // relayout
     spaceBar.relayout
     spacePane.relayout
     relayout
       {
         pos := filePosHis[curView.file]
         if (pos != null) item = Item { it.dis = pos.toStr; it.line = pos.line; it.col = pos.col }
+        }
+      if (item != null) curView.onGoto(item)
       }
-      if (item != null) curView.onGoto(item)
-    }
   }
 
   private static View? findView(Widget w)
   {
     if (w is View) return w
-    return w.children.eachWhile |kid| { findView(kid) }
+      return w.children.eachWhile |kid| { findView(kid) }
   }
 
   private Int spaceIndex(Space space)
     spaces.indexSame(space) ?: throw Err("Space not open: $space.typeof")
   }
 
-//////////////////////////////////////////////////////////////////////////
-// Marks (build errors/finds)
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Marks (build errors/finds)
+  //////////////////////////////////////////////////////////////////////////
 
   Item[] marks := Item[,]
   {
     set
     {
       if (it >= marks.size) it = marks.size - 1
-      if (it < 0) it = 0
-      &curMark = it
+        if (it < 0) it = 0
+        &curMark = it
       if (!marks.isEmpty) goto(marks[it])
-    }
+      }
   }
 
-//////////////////////////////////////////////////////////////////////////
-// View Lifecycle
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // View Lifecycle
+  //////////////////////////////////////////////////////////////////////////
 
   private Bool confirmClose()
   {
     if (curView == null || !curView.dirty) return true
-    r := Dialog.openQuestion(this, "Save changes to $curView.file.name?",
+      r := Dialog.openQuestion(this, "Save changes to $curView.file.name?",
       [Dialog.yes, Dialog.no, Dialog.cancel])
     if (r == Dialog.cancel) return false
-    if (r == Dialog.yes) save
-    return true
+      if (r == Dialog.yes) save
+      return true
   }
 
   Void save()
   {
     if (curView == null) return
-    if (curView.dirty) curView.onSave
-    curView.dirty = false
+      if (curView.dirty) curView.onSave
+      curView.dirty = false
     updateStatus
   }
 
     {
       title += " $curView.file.name"
       if (curView.dirty) title += "*"
-    }
+      }
     this.title = title
     this.statusBar.update
   }
 
-//////////////////////////////////////////////////////////////////////////
-// Eventing
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Eventing
+  //////////////////////////////////////////////////////////////////////////
 
   internal Void trapKeyDown(Event event)
   {
     cmd := sys.commands.findByKey(event.key)
     if (cmd != null) cmd.invoke(event)
-  }
+    }
 
   private Void doDrop(Obj data)
   {
     files := data as File[]
     if (files == null || files.isEmpty) return
-    file := files.first
+      file := files.first
     goto(Item(file))
   }
 
-//////////////////////////////////////////////////////////////////////////
-// Session State
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Session State
+  //////////////////////////////////////////////////////////////////////////
 
   internal Void loadSession()
   {
     props := Str:Str[:]
     try
       if (sessionFile.exists) props = sessionFile.readProps
-    catch (Err e)
+      catch (Err e)
       sys.log.err("Cannot load session: $sessionFile", e)
 
     // read bounds
       type := props[typeKey]
       if (type == null) break
 
-      // get all "space.nn.xxxx" props
+        // get all "space.nn.xxxx" props
       spaceProps := Str:Str[:]
       props.each |val, key|
       {
         spaces.add(space)
       }
       catch (Err e) sys.log.err("ERROR: Cannot load space $type", e)
-    }
+      }
 
     // always insert HomeSpace
     if (spaces.first isnot HomeSpace)
       sys.log.err("Cannot save $sessionFile", e)
   }
 
-//////////////////////////////////////////////////////////////////////////
-// Private Fields
-//////////////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////////////
+  // Private Fields
+  //////////////////////////////////////////////////////////////////////////
 
   private File sessionFile := Env.cur.workDir + `etc/camenbert/session.props`
   private SpaceBar spaceBar

File src/brie/fan/Options.fan

   }
 
   ** Directories to crawl looking for for pod, file navigation
-  const Uri[] indexDirs := [,]
+  const Uri[] indexDirs := [Env.cur.homeDir.uri + `etc/camembert/`]
 
   ** Home directory to use for fan/build commands
   const Uri fanHomeUri := Env.cur.homeDir.uri