void Menu_Rename(object sender, EventArgs e) { if (SharedFiles.SelectedItems.Count == 0) { return; } ShareItem item = SharedFiles.SelectedItems[0] as ShareItem; GetTextDialog rename = new GetTextDialog("Rename File", "Enter new name for " + item.Share.Name, item.Share.Name); if (rename.ShowDialog() == DialogResult.OK) { if (rename.ResultBox.Text.Trim() == "" || rename.ResultBox.Text.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { MessageBox.Show("Name Contains Invalid Characters"); } else { item.Share.Name = rename.ResultBox.Text; } } SharedFiles.Invalidate(); }
private void SecondTimer_Tick(object sender, EventArgs e) { // sync items with local status, we can see our transfer in remote's view Sharing.Local.Files.LockReading(() => { foreach (SharedFile file in SharedFiles.Items.Cast <ShareItem>().Select(i => i.Share)) { SharedFile localStatus = Sharing.Local.Files.Where(f => f.FileID == file.FileID).FirstOrDefault(); if (localStatus == null) { continue; } file.FileStatus = localStatus.FileStatus; file.TransferStatus = localStatus.TransferStatus; file.TransferActive = localStatus.TransferActive; } }); foreach (ShareItem item in SharedFiles.Items) { item.RefreshStatus(); } ShareCollection collection; if (Sharing.Collections.SafeTryGetValue(UserID, out collection)) { StatusLabel.Text = collection.Status; } SharedFiles.Invalidate(); // update download progress, file colors, etc.. }
private void RefreshView() { SharedFiles.Items.Clear(); ShareCollection collection; if (Sharing.Collections.SafeTryGetValue(UserID, out collection)) { collection.Files.LockReading(() => { foreach (SharedFile share in collection.Files) { SharedFiles.Items.Add(new ShareItem(this, share)); } }); } SharedFiles.Invalidate(); }
void Sharing_FileUpdate(SharedFile share) { // only for local user if (UserID != Core.UserID) { return; } bool deleted = false; Sharing.Local.Files.LockReading(() => { deleted = !Sharing.Local.Files.Any(s => s == share); }); // if share exists ShareItem exists = SharedFiles.Items.Cast <ShareItem>().Where(s => s.Share == share).FirstOrDefault(); if (exists != null) { if (deleted) { SharedFiles.Items.Remove(exists); } else { exists.RefreshStatus(); } } else if (!deleted) { SharedFiles.Items.Add(new ShareItem(this, share)); } SharedFiles.Invalidate(); }