Skip to content

Commit

Permalink
Setup to run copy operations in the background to make them abortable
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldeicaza committed Jan 28, 2011
1 parent b45bcfc commit 3a72ebf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ File Management:
Rename, Move, Delete.
Background operations

Copy:
Disable copying ..

Panel:
Do not render .. on nested views

Viewer:
Hex mode
Formated mode (nroff pages, html pages)
Expand Down
37 changes: 28 additions & 9 deletions panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Mono.Unix;
using Mono.Unix.Native;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace MouselessCommander {

Expand Down Expand Up @@ -646,33 +647,51 @@ public void Copy (string target_dir)
else
d.Add (new Label (1, 0, String.Format (msg_file, listing.GetPathAt (selected).Ellipsize (ilen-msg_file.Length))));

bool proceed = false;

var e = new Entry (1, 1, ilen, target_dir ?? "");
d.Add (e);

bool proceed = false;
var b = new Button (0, 0, "Ok", true);
b.Clicked += delegate {
d.Running = false;
proceed = true;
};
d.AddButton (b);
b = new Button (0, 0, "Cancel", true);
b = new Button (0, 0, "Cancel", false);
b.Clicked += (o,s) => d.Running = false;
d.AddButton (b);

Application.Run (d);
if (!proceed)
return;

Application.MainLoop.AddTimeout (TimeSpan.FromSeconds (1), ml => {
Log ("Updating GUI at {0}", DateTime.Now);
// Update GUI here every second
return true;
});

var progress = new ProgressInteraction ("Copying", marked > 0 ? marked : 1);
using (var ctx = new CopyOperation (progress)){
foreach (var node in Selection ()){
bool isDir = node is Listing.DirNode;
var r = ctx.Perform (CurrentPath, listing.GetPathAt (node.StartIdx), isDir, node.Info.Protection, target_dir);
if (r == FileOperation.Result.Cancel)
break;
}
var runstate = Application.Begin (progress);
using (var copyOperation = new CopyOperation (progress)){
Task t = Task.Factory.StartNew (delegate {
for (int i = 0; i < 10; i++){
System.Threading.Thread.Sleep (333);
}
#if false
foreach (var node in Selection ()){
bool isDir = node is Listing.DirNode;
var r = copyOperation.Perform (CurrentPath, listing.GetPathAt (node.StartIdx), isDir, node.Info.Protection, target_dir);
if (r == FileOperation.Result.Cancel)
break;
}
#endif
Application.Stop ();
}, null);
Application.RunLoop (runstate, true);
}
Application.End (runstate);
}

public override bool ProcessKey (int key)
Expand Down

0 comments on commit 3a72ebf

Please sign in to comment.