private void lvDropboxFiles_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null && content.Is_dir) { OpenDirectory(content.Path); } } }
private void tsmiCopyPublicLink_Click(object sender, EventArgs e) { if (lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null && !content.Is_dir && content.Path.StartsWith("/Public/", StringComparison.InvariantCultureIgnoreCase)) { string url = Dropbox.GetPublicURL(dropboxAccountInfo.Uid, content.Path); ClipboardHelpers.CopyText(url); } } }
private void lvDropboxFiles_SelectedIndexChanged(object sender, EventArgs e) { if (lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null) { isSelectedFile = !content.Is_dir; isSelectedPublic = content.Path.StartsWith("/Public/", StringComparison.InvariantCultureIgnoreCase); } } RefreshMenu(); }
public void OpenDirectory(string path) { lvDropboxFiles.Items.Clear(); DropboxContentInfo contentInfo = null; TaskEx.Run(() => { contentInfo = dropbox.GetMetadata(path, true); }, () => { if (contentInfo != null) { lvDropboxFiles.Tag = contentInfo; ListViewItem lvi = GetParentFolder(contentInfo.Path); if (lvi != null) { lvDropboxFiles.Items.Add(lvi); } foreach (DropboxContentInfo content in contentInfo.Contents.OrderBy(x => !x.Is_dir)) { string filename = Path.GetFileName(content.Path); lvi = new ListViewItem(filename); lvi.SubItems.Add(content.Is_dir ? "" : content.Size); DateTime modified; if (DateTime.TryParse(content.Modified, out modified)) { lvi.SubItems.Add(modified.ToString()); } lvi.ImageKey = ilm.AddImage(content.Icon); lvi.Tag = content; lvDropboxFiles.Items.Add(lvi); } CurrentFolderPath = contentInfo.Path.Trim('/'); Text = "Dropbox - " + CurrentFolderPath; } else { MessageBox.Show(Resources.DropboxFilesForm_OpenDirectory_Path_not_exist_ + " " + path, Resources.UploadersConfigForm_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
public ListViewItem GetParentFolder(string currentPath) { if (!string.IsNullOrEmpty(currentPath)) { string parentFolder = currentPath.Remove(currentPath.LastIndexOf('/')); DropboxContentInfo content = new DropboxContentInfo { Icon = "folder", Is_dir = true, Path = parentFolder }; ListViewItem lvi = new ListViewItem(".."); lvi.ImageKey = ilm.AddImage(content.Icon); lvi.Tag = content; return lvi; } return null; }
private void tsmiDelete_Click(object sender, EventArgs e) { if (lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null) { if (MessageBox.Show("Are you sure you want to delete '" + Path.GetFileName(content.Path) + "' from your Dropbox?", "Dropbox - Delete file?", MessageBoxButtons.YesNo) == DialogResult.Yes) { dropbox.Delete(content.Path); RefreshDirectory(); } } } }
private void tsmiDelete_Click(object sender, EventArgs e) { if (lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null) { if (MessageBox.Show(string.Format(Resources.DropboxFilesForm_tsmiDelete_Click_Are_you_sure_you_want_to_delete___0___from_your_Dropbox_, Path.GetFileName(content.Path)), "Dropbox - " + Resources.DropboxFilesForm_tsmiDelete_Click_Delete_file_, MessageBoxButtons.YesNo) == DialogResult.Yes) { dropbox.Delete(content.Path); RefreshDirectory(); } } } }
private void tsmiDownloadFile_Click(object sender, EventArgs e) { if (lvDropboxFiles.SelectedItems.Count > 0) { DropboxContentInfo content = lvDropboxFiles.SelectedItems[0].Tag as DropboxContentInfo; if (content != null && !content.Is_dir) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.FileName = Path.GetFileName(content.Path); if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName)) { using (FileStream fileStream = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write, FileShare.Read)) { dropbox.DownloadFile(content.Path, fileStream); } } } } } }