1. Thibaut Colar
  2. camembert

Commits

Thibaut Colar  committed da4576c

Added delete command and rename/move command on items(nav file & folders)

  • Participants
  • Parent commits 5c949eb
  • Branches default

Comments (0)

Files changed (4)

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

View file
   const Cmd newFile
   const Cmd openFolder
   const Cmd recent := RecentCmd {}
+  const Cmd delete := DeleteFileCmd {}
+  const Cmd move := MoveFileCmd {}
 }
 
 **************************************************************************

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

View file
 **************************************************************************
 ** New file
 **************************************************************************
-
 internal const class NewFileCmd : Cmd
 {
-  override const Str name := "New File"
+  override const Str name := "New File / Folder"
   override Void invoke(Event event)
   {
     newFile(frame.curFile?.parent, frame)
     f.out.print(text).close
 
     frame.goto(Item(f))
+  }
+  new make(|This| f) {f(this)}
+}
 
-    // TODO: contextual create file (from nav item)
+**************************************************************************
+** Move / rename file
+**************************************************************************
+internal const class MoveFileCmd : Cmd
+{
+  override const Str name := "Move / Rename File"
+  override Void invoke(Event event)
+  {
+    // contextual only for now
+  }
+
+  Void moveFile(File file, Frame frame)
+  {
+    ok := Dialog.ok
+    cancel := Dialog.cancel
+    name := Text {text = file.name; prefCols = 60}
+    path := Text
+    {
+      prefCols = 60
+      text = file.parent.osPath + "/"
+    }
+
+    dialog := Dialog(frame)
+    {
+      title = "Move File"
+      commands = [ok, cancel]
+      body = GridPane
+      {
+        Label{ text = "File Name:" },
+        name,
+        Label{ text = "Folder: (Any new folders will get created automatically)" },
+        path,
+      }
+    }
+    name.focus
+
+    // open dialog
+    if (dialog.open != Dialog.ok) return
+
+    FileUtils.mkDirs(path.text.toUri)
+
+    dest := path.text.toUri.plusSlash + name.text.toUri
+    if(file.isDir)
+      dest = dest.plusSlash
+    file.moveTo(File(dest))
+  }
+  new make(|This| f) {f(this)}
+}
+
+**************************************************************************
+** Delete file
+**************************************************************************
+internal const class DeleteFileCmd : Cmd
+{
+  override const Str name := "Delete File / Folder"
+  override Void invoke(Event event)
+  {
+    // only used contextually. for now anyway
+  }
+
+  Void delFile(File file, Frame frame)
+  {
+    r := Dialog.openQuestion(frame, "Delete $file.name ?", "Full path : $file.pathStr", Dialog.okCancel)
+
+    if (r != Dialog.ok) return
+
+    file.delete
   }
   new make(|This| f) {f(this)}
 }
 
 internal const class OpenFolderCmd : Cmd
 {
-  override const Str name := "OpenFolder"
+  override const Str name := "Open Folder"
   override Void invoke(Event event)
   {
     File? f := FileDialog

File src/brie/fan/widget/Item.fan

View file
         it.onAction.add |e|
           { (frame.sys.commands.newFile as NewFileCmd).newFile(dir, frame) }
       },
+      MenuItem
+      {
+        it.text = "Delete \"$file.name\""
+        it.onAction.add |e|
+        {
+          (frame.sys.commands.delete as DeleteFileCmd).delFile(file, frame)
+          frame.goto(this) // refresh
+        }
+      },
+      MenuItem
+      {
+        it.text = "Rename/Move \"$file.name\""
+        it.onAction.add |e|
+        {
+          (frame.sys.commands.move as MoveFileCmd).moveFile(file, frame)
+          frame.goto(this) // refresh
+        }
+      },
     }
   }
 

File todo.txt

View file
-delete file/folder
-rename file/folder (& move)
 
 find/replace .. local / global