/// <summary> /// Return a list of all the selected KListViewItems that are directories. /// </summary> /// <param name="items"></param> /// <returns></returns> private List<KListViewItem> DirectoriesInSelection(KListViewItem[] items) { List<KListViewItem> dirs = new List<KListViewItem>(); foreach (KListViewItem item in items) { if (item.Status == PathStatus.Directory) { dirs.Add(item); } } return dirs; }
/// <summary> /// This method is used by Drag and Drop events to set the appropriate /// allowed effect on the Listview. /// We allow drop if the destination is different than the source. /// </summary> private void SetLvDragDropEffect(DragEventArgs e) { bool isKfsItem = IsDragDropKfsItem(e); bool isFileDrop = IsDragDropFileDrop(e); bool isMsoDrop = IsDragDropMsoDrop(e); bool isASubDir = false; // Allow only FileDrop and KfsItem data format to be dropped in here. if (!(isKfsItem || isFileDrop || isMsoDrop) || !m_canDrop || !m_canDrag) { e.Effect = DragDropEffects.None; return; } // Set the selected node properly. Point pt = lvFileList.PointToClient(new Point(e.X, e.Y)); KListViewItem itemUnder = (KListViewItem)lvFileList.GetItemAt(pt.X, pt.Y); // Unselect the temp item. if (m_dragDropLvTempDest != null && !IsPathInDragSelection(m_dragDropLvTempDest.Path, e)) m_dragDropLvTempDest.Selected = false; // See if we must select another temp item. if (itemUnder != null && itemUnder.Status == PathStatus.Directory) { if (isMsoDrop || !IsPathInDragSelection(itemUnder.Path, e)) { // If the mouse is over a directory, select it. itemUnder.Selected = true; m_dragDropLvTempDest = itemUnder; } } // Validate if the destination is valid. if (isMsoDrop) { if (itemUnder != null && itemUnder.Status != PathStatus.Directory) e.Effect = DragDropEffects.None; else e.Effect = DragDropEffects.Copy; return; } string srcFullPath = GetDragDropSourceDir(e); string dstRelativePath = GetLvDragDropDestDir(e); if (isKfsItem) { if (srcFullPath == dstRelativePath || itemUnder == null || itemUnder.Status != PathStatus.Directory || IsPathInDragSelection(itemUnder.Path, e)) e.Effect = DragDropEffects.None; else e.Effect = DragDropEffects.Copy; } else if (isFileDrop) { foreach (string p in (string[])e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop)) { if (Directory.Exists(p) && KfsPath.GetWindowsFilePath(SrcApp.Share.MakeAbsolute(dstRelativePath), true).StartsWith(p)) { isASubDir = true; break; } } if (srcFullPath == KfsPath.GetWindowsFilePath(SrcApp.Share.MakeAbsolute(dstRelativePath), false) || (itemUnder != null && IsPathInDragSelection(itemUnder.Path, e)) || isASubDir) e.Effect = DragDropEffects.None; else e.Effect = DragDropEffects.Copy; } }
private void tvFileTree_DragDrop(object sender, DragEventArgs e) { try { Logging.Log(1, "tvFileTree_DragDrop"); m_updateLvOnTvSelectionChange = true; tvFileTree.SelectedNode = m_dragDropTvOriginalSelectedNode; m_dragDropLvTempDest = null; bool IsKfsItem = IsDragDropKfsItem(e); bool IsFileDrop = IsDragDropFileDrop(e); Debug.Assert(IsKfsItem || IsFileDrop); if (IsKfsItem) { string[] FileNames = GetKListViewItemPath((KListViewItem[])e.Data.GetData("KfsItem")); Gate.MovePath(new List<string>(FileNames), GetTvDragDropDestDir(e)); } else if (IsFileDrop) { string[] FileNames = (String[])e.Data.GetData(DataFormats.FileDrop); Gate.AddExternalFiles(GetTvDragDropDestDir(e), FileNames, false, new GateConfirmActions()); } m_isDraggingItem = false; m_dragDropLvTempDest = null; m_isDragDropInsideControls = false; Gate.GateExit("tvFileTree_DragDrop"); } catch (Exception ex) { Base.HandleException(ex); } }
private void lvFileList_DragDrop(object sender, DragEventArgs e) { try { Logging.Log(1, "lvFileList_DragDrop"); bool IsKfsItem = IsDragDropKfsItem(e); bool IsFileDrop = IsDragDropFileDrop(e); bool IsMsoDrop = IsDragDropMsoDrop(e); Debug.Assert(IsKfsItem || IsFileDrop || IsMsoDrop); // Add files to the share if they come from outside the KWM, // move them if they come from inside. if (IsKfsItem) { // Unselect the destination. if (m_dragDropLvTempDest != null) m_dragDropLvTempDest.Selected = false; string[] FileNames = GetKListViewItemPath((KListViewItem[])e.Data.GetData("KfsItem")); Gate.MovePath(new List<string>(FileNames), GetLvDragDropDestDir(e)); } else if (IsFileDrop) { string[] FileNames = (String[])e.Data.GetData(DataFormats.FileDrop); Gate.AddExternalFiles(GetLvDragDropDestDir(e), FileNames, false, new GateConfirmActions()); } else if (IsMsoDrop) { // Wrap standard IDataObject in OutlookDataObject OutlookDataObject dataObject = new OutlookDataObject(e.Data); // Get the names and data streams of the dropped files. string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents"); // This directory will contain the files to add to the share. We do not // save the data from the Outlook item directly there since we want to // change file names when dupes exist. String finalDir = Path.GetTempPath() + Path.GetRandomFileName(); Directory.CreateDirectory(finalDir); for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { // Use the fileindex to get the name and data stream string filename = filenames[fileIndex]; MemoryStream filestream = filestreams[fileIndex]; // Save the file stream to a random directory under its desired filename. String tempDir = Path.GetTempPath() + Path.GetRandomFileName(); String tmpFilePath = tempDir + "\\" + filename; Directory.CreateDirectory(tempDir); using (FileStream outputStream = File.Create(tmpFilePath)) { filestream.WriteTo(outputStream); } String errorMessage = ""; if (Misc.CopyFileAndRenameOnCol(tmpFilePath, finalDir + "\\", ref errorMessage) == ShellLib.ShellFileOperation.CopyFileResult.Failed) throw new Exception("operation failed: " + errorMessage); Directory.Delete(tempDir, true); } List<String> toAdd = new List<string>(); DirectoryInfo di = new DirectoryInfo(finalDir); foreach (FileInfo i in di.GetFiles()) toAdd.Add(i.FullName); Gate.AddExternalFiles(GetLvDragDropDestDir(e), toAdd.ToArray(), false, new GateConfirmActions()); // Remove the final dir. di.Delete(true); } } catch (Exception ex) { Base.HandleException(ex); } finally { SetItemDraggingStatus(false); m_dragDropLvTempDest = null; m_isDragDropInsideControls = false; Gate.GateExit("lvFileList_DragDrop"); } }
private void lvFileList_DragLeave(object sender, EventArgs e) { try { Logging.Log(1, "lvFileList_DragLeave"); if (m_dragDropLvTempDest != null) m_dragDropLvTempDest.Selected = false; m_dragDropLvTempDest = null; m_isDragDropInsideControls = false; if (!m_isDraggingItem) Gate.GateExit("lvFileList_DragLeave : not dragging anymore."); } catch (Exception ex) { Base.HandleException(ex); } }
private string[] GetKListViewItemPath(KListViewItem[] items) { return Array.ConvertAll<KListViewItem, string>(items, delegate(KListViewItem src) { return src.Path; }); }
/// <summary> /// Check if a generic action can be taken on a given item /// (Open, Delete) /// </summary> /// <param name="itm"></param> /// <returns></returns> private bool IsItemValidForAction(KListViewItem itm) { return (itm.Status == PathStatus.Directory || itm.Status == PathStatus.ModifiedCurrent || itm.Status == PathStatus.NotDownloaded || itm.Status == PathStatus.UnmodifiedCurrent || itm.Status == PathStatus.UnmodifiedStale || itm.Status == PathStatus.NotAdded); }
/// <summary> /// Return true if the file path specified can be saved as. /// </summary> public bool CanSaveAs(KListViewItem itm) { if (itm.Status != PathStatus.NotAdded && itm.Status != PathStatus.ModifiedCurrent && itm.Status != PathStatus.ModifiedStale && itm.Status != PathStatus.UnmodifiedCurrent && itm.Status != PathStatus.UnmodifiedStale) { return false; } // Allow only if the file is not being transfered, unless we are uploading it. return !Share.IsTransferringFile(itm.Path) || itm.Status == PathStatus.ModifiedCurrent; }
/// <summary> /// Return true if the ListViewItem specified can be synchronized. /// </summary> /// <param name="itm"></param> /// <returns></returns> public bool CanSynchronize(KListViewItem itm) { if (Share.AllowedOp == AllowedOpStatus.None) return false; // Assume a directory present server-side // can be synchronized. If nothing inside of // it can be synchronized, so be it. if (itm.Status == PathStatus.Directory && itm.OnServer) return true; if ((itm.Status == PathStatus.ModifiedCurrent && Share.AllowedOp == AllowedOpStatus.All) || (itm.Status == PathStatus.NotDownloaded && itm.HasCurrentVersion && (Share.AllowedOp == AllowedOpStatus.All || Share.AllowedOp == AllowedOpStatus.Download)) || itm.Status == PathStatus.UnmodifiedStale && (Share.AllowedOp == AllowedOpStatus.All || Share.AllowedOp == AllowedOpStatus.Download)) { return !Share.IsTransferringFile(itm.Path); } // Other statuses can't be synchronized return false; }
public bool CanResolveFileConflict(KListViewItem itm) { if (Share.AllowedOp == AllowedOpStatus.None) return false; return (itm.Status == PathStatus.ModifiedStale && !Share.IsTransferringFile(itm.Path)); }
/// <summary> /// Return true if the file path specified can be reverted to the latest /// server version. /// </summary> public bool CanRevert(KListViewItem itm) { return (itm.Status == PathStatus.ModifiedCurrent && !Share.IsTransferringFile(itm.Path)); }
/// <summary> /// Return true if the file path specified can be opened. /// </summary> /// <param name="itm"></param> /// <returns></returns> public bool CanOpen(KListViewItem itm) { if (Share.AllowedOp == AllowedOpStatus.None) return false; if (itm.Status != PathStatus.NotAdded && itm.Status != PathStatus.ModifiedCurrent && itm.Status != PathStatus.ModifiedStale && itm.Status != PathStatus.UnmodifiedCurrent && itm.Status != PathStatus.UnmodifiedStale && itm.Status != PathStatus.NotDownloaded && itm.Status != PathStatus.Undetermined) { return false; } // Allow opening if the file is not being downloaded. Since we don't yet // have the transfer direction handy, we assume NotAdded or ModifiedCurrent files // currently in transfer are necessarily being uploaded. A file being uploaded can // safely be opened. return !Share.IsTransferringFile(itm.Path) || itm.Status == PathStatus.NotAdded || itm.Status == PathStatus.ModifiedCurrent; }
/// <summary> /// Return true if the ListviewItem specified can be deleted or moved. /// </summary> public bool CanDeleteOrMove(KListViewItem itm) { return CanDeleteOrMoveInternal(Share.StatusView.GetPathArray(itm.Path, false)); }
/// <summary> /// Return true if the KListViewItem can be copied in the clipboard. /// </summary> public bool CanCopy(KListViewItem itm) { return CanCopy(itm.Path); }
/// <summary> /// Return true if the ListviewItem can /// be added to the share. /// </summary> /// <param name="itm"></param> /// <returns></returns> public bool CanAdd(KListViewItem itm) { if (Share.AllowedOp != AllowedOpStatus.All) return false; if (itm.Status != PathStatus.NotAdded && !(itm.Status == PathStatus.Directory && !itm.OnServer) || (itm.Status != PathStatus.Directory && Share.IsTransferringFile(itm.Path))) { return false; } return true; }
/// <summary> /// Populates the objects contained in this directory. /// </summary> /// <param name="obj"></param> private void CreateChilds(KfsStatusPath obj) { foreach (KeyValuePair<string, KfsStatusPath> content in obj.ChildTree) { KfsStatusPath val = content.Value as KfsStatusPath; Debug.Assert(val != null); KListViewItem newItem = new KListViewItem(val, m_helper); if (val.Status == PathStatus.Directory) newItem.ImageKey = "FolderClosed"; else if (val.HasLocalFile() && NeedsIconCheck(newItem.FileName)) newItem.ImageKey = m_lvImageListMgr.GetImageKey(val.Share.MakeAbsolute(val.Path)); else newItem.ImageKey = m_lvImageListMgr.GetImageKey(Path.GetExtension(newItem.FileName)); newItem.Name = val.Name; m_childs.Add(val.Name, newItem); } }