Exemple #1
0
        /// <summary>
        /// Moves the currently displayed file
        /// </summary>
        /// <param name="mode">Optionally set as "remove" to remove the file.</param>
        public void MoveFile(string mode = "")
        {
            if (_displayItems.Count == 0)
            {
                return;
            }
            if (mode != "remove")
            {
                if (DirectoryTreeList.SelectedIndex == -1)
                {
                    return;
                }
            }

            _changed = true;

            try
            {
                if (mode == "remove")
                {
                    _currentItem.HasBeenDeleted = true;
                    RecyclingBin.MoveHere(_currentItem.GetFilePath());

                    //newPath = _deleteFolder + "\\" + _currentItem.GetFileName();
                }
                else
                {
                    var newPath = _originFolder.GetAllShownFolders()[DirectoryTreeList.SelectedIndex].GetFolderPath() +
                                  "\\" + _currentItem.GetFileName();

                    newPath = NewNameIfTaken(_currentItem.GetFilePath(), newPath);

                    File.Move(_currentItem.GetFilePath(), newPath);
                    _currentItem.SetFilePath(newPath);
                }



                // Update internal representation to reflect changes
                _movedItems.Insert(0, _currentItem);
                UndoMenu.IsEnabled = true;
                _displayItems.RemoveAt(_displayedItemIndex);
                isInCache.RemoveAt(_displayedItemIndex);
            }
            catch
            {
                Interaction.MsgBox("File is currently being used by another program or has been removed");
                return;
            }

            // When last file has been moved
            if (_displayItems.Count == 0)
            {
                MakeTypeVisible("");
            }
            else if (_displayedItemIndex == _displayItems.Count)
            {
                _displayedItemIndex--;
            }

            UpdateContent();
        }