public static void SetSavedStartingDirsToXml(OpenMode _mode, String _path, FileOperator.Side _s) { if (_path == String.Empty) { _path = Directory.GetCurrentDirectory(); } XDocument savedData = LoadSettingsDocument(); try { String modeDefiner = null; if (_mode == OpenMode.userDefined) { modeDefiner = "userDefinedPaths"; } else if (_mode == OpenMode.lastUsed) { modeDefiner = "lastUsedDirs"; } else { return; } XElement paths = savedData.Root.Element(modeDefiner); String side = (_s == FileOperator.Side.Left) ? "left" : "right"; paths.Element(side).Value = _path; savedData.Save(SavedPath); } catch (Exception ex) { throw ex; } }
public static FileContainer ChooseContainer(FileOperator.Side s) { if (s == FileOperator.Side.Left) { return(FC_Left); } else { return(FC_Right); } }
private void MakeDirActive(FileOperator.Side _s) { FileOperator.ActiveDirectory = _s; if (_s == FileOperator.Side.Left) { Dispatcher.Invoke(() => leftView.Background = Brushes.AliceBlue); Dispatcher.Invoke(() => rightView.Background = Brushes.White); } else if (_s == FileOperator.Side.Right) { Dispatcher.Invoke(() => rightView.Background = Brushes.AliceBlue); Dispatcher.Invoke(() => leftView.Background = Brushes.White); } }
async private Task DropHandler(object _sender, object _e, FileOperator.Side _side) { ListBox parent = (ListBox)_sender; if (parent == dragSource) { return; } String data = (String)(((DragEventArgs)_e).Data.GetData(typeof(String))); List <IFileObject> objToMove = ((IList <IFileObject>)dragSource.ItemsSource).Where((item) => item.Info.FullName == data).ToList(); File_Containers.FileContainer receiver = File_Containers.FileDualContainer.ChooseContainer(_side); try { await Task.Run(() => FileOperator.CopyFiles(objToMove, receiver)); } catch (Exception ex) { MessageBox.Show("Unable to copy in this directory", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ((IList <IFileObject>)dragSource.ItemsSource).Remove(objToMove[0]); await Task.Run(() => UpdateView(_side)); }
private void UpdateView(FileOperator.Side _s, IEnumerable <IFileObject> _files = null, bool isMakeActive = true) { ListBox someView = null; ComboBox someRootComboBox = null; TextBlock somePathRow = null; Grid someStatusStr = null; ComboBox someSortComboBox = null; if (_s == FileOperator.Side.Left) { Dispatcher.Invoke(() => someView = leftView); Dispatcher.Invoke(() => someRootComboBox = rootComboBoxL); Dispatcher.Invoke(() => somePathRow = pathRowL); Dispatcher.Invoke(() => someStatusStr = StatusStrL); Dispatcher.Invoke(() => someSortComboBox = leftSortChooseBox); } else if (_s == FileOperator.Side.Right) { Dispatcher.Invoke(() => someView = rightView); Dispatcher.Invoke(() => someRootComboBox = rootComboBoxR); Dispatcher.Invoke(() => somePathRow = pathRowR); Dispatcher.Invoke(() => someStatusStr = StatusStrR); Dispatcher.Invoke(() => someSortComboBox = rightSortChooseBox); } lock (synclock) { Dispatcher.Invoke(() => someView.ItemsSource = null); List <IFileObject> listOfContFiles = null; try { listOfContFiles = (_files == null) ? FileOperator.GetDirContainsList(_s).ToList() : _files.ToList(); } catch (Exception ex) { MessageBox.Show("Files list can not be get", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { Dispatcher.Invoke(() => someView.ItemsSource = FileOperator.SetActionForSort(listOfContFiles, someSortComboBox.SelectedIndex)); } catch (Exception ex) { MessageBox.Show($"Cannot sort items: {ex.Message}. Show unsorted list", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Dispatcher.Invoke(() => someView.ItemsSource = listOfContFiles); } List <String> drives = FileOperator.GetAllLogicalDrives().ToList(); String logicalDrive = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.LogicalDrive; try { Dispatcher.Invoke(() => someRootComboBox.ItemsSource = drives); } catch (Exception ex) { MessageBox.Show("This disk is not availbale. Chack other disk", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Dispatcher.Invoke(() => someRootComboBox.SelectedItem = drives.Find((item) => logicalDrive.Equals(item))); Dispatcher.Invoke(() => somePathRow.Text = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.ShortName); Dispatcher.Invoke(() => someStatusStr.DataContext = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info); if (isMakeActive) { MakeDirActive(_s); } } }