Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        void Menu_CopyFileLink(object sender, EventArgs e)
        {
            if (SharedFiles.SelectedItems.Count == 0)
            {
                return;
            }

            ShareItem item = SharedFiles.SelectedItems[0] as ShareItem;

            Clipboard.SetText(Sharing.GetFileLink(UserID, item.Share));
        }
Esempio n. 3
0
        private void SharedFiles_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (SharedFiles.SelectedItems.Count == 0)
            {
                return;
            }

            ShareItem item = SharedFiles.SelectedItems[0] as ShareItem;

            if (File.Exists(Sharing.GetFilePath(item.Share)))
            {
                Sharing.OpenFile(UserID, item.Share);
            }
            else
            {
                Sharing.DownloadFile(UserID, item.Share);
            }
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        private void SharedFiles_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            if (SharedFiles.SelectedItems.Count == 0)
            {
                return;
            }

            ShareItem item = SharedFiles.SelectedItems[0] as ShareItem;

            if (item == null)
            {
                return;
            }

            ContextMenuStripEx menu = new ContextMenuStripEx();

            if (item.Share.Public)
            {
                menu.Items.Add(new ToolStripMenuItem("Make Private", null, new EventHandler(Menu_MakePrivate)));
            }
            else
            {
                menu.Items.Add(new ToolStripMenuItem("Make Public", null, new EventHandler(Menu_MakePublic)));
            }

            menu.Items.Add(new ToolStripMenuItem("Copy File Link", null, new EventHandler(Menu_CopyFileLink)));


            menu.Items.Add("-");


            if (File.Exists(Sharing.GetFilePath(item.Share)))
            {
                menu.Items.Add(new ToolStripMenuItem("Open", null, (s, ea) =>
                                                     SharedFiles.SelectedItems.ForEach(i => Sharing.OpenFile(UserID, ((ShareItem)i).Share))));

                if (item.Share.SystemPath != null)
                {
                    menu.Items.Add(new ToolStripMenuItem("Open Containing Folder", null, (s, ea) =>
                                                         Utilities.OpenFolder(Path.GetDirectoryName(item.Share.SystemPath))));
                }
            }
            else
            {
                menu.Items.Add(new ToolStripMenuItem("Try Download", null, (s, ea) =>
                                                     SharedFiles.SelectedItems.ForEach(i => Sharing.DownloadFile(UserID, ((ShareItem)i).Share))));
            }


            if (item.Share.TransferActive)
            {
                menu.Items.Add(new ToolStripMenuItem("Transfer Details", null, (s, ea) =>
                                                     TransferView.Show(Core.Network)));
            }


            if (Local && item.Share.ClientID == Core.Network.Local.ClientID)
            {
                menu.Items.Add(new ToolStripMenuItem("Rename", null, new EventHandler(Menu_Rename)));

                menu.Items.Add("-");
                menu.Items.Add(new ToolStripMenuItem("Remove", null, new EventHandler(Menu_Remove)));
            }

            if (menu.Items.Count > 0)
            {
                menu.Show(SharedFiles, e.Location);
            }
        }