private void _Initialize(TextFileModel textFile) { Name = textFile.FileInfo.FullName; _Text = textFile.Text; SaveAsCommand = new Command(arg => { if (arg as object[] == null) SaveAs(this.Name); else { string name = ""; foreach (var parts in arg as object[]) name += parts.ToString(); SaveAs(name); } }); FindTextCommand = new Command(arg => { string searchingText = (arg as object[])[0].ToString(); bool ignoreCase = (bool)(arg as object[])[1]; SelectionStart = FindNext(searchingText, ignoreCase); if (SelectionStart != -1) SelectionLength = (arg as object[])[0].ToString().Length; }); ChangeCaseCommand = new Command(arg => { if (arg.ToString().ToLower() == "down") ChangeCase(SelectionStart, SelectionLength, StringCase.Lower); if (arg.ToString().ToLower() == "up") ChangeCase(SelectionStart, SelectionLength, StringCase.Upper); }); ChangeCaseCommand.CanExecuteDelegate = arg => SelectionLength != 0; var htmlFile = textFile as HtmlFileModel; if (htmlFile != null) IsHtml = true; DisplayHtlFilesCommand = new Command(arg => { if (System.Convert.ToBoolean(arg)) FindHtmlFiles(); }); DisplayHtlFilesCommand.CanExecuteDelegate = arg => IsHtml; }
private void _Initialize(FolderModel newFolder) { #region //Присваеваем анонимные функции коммандам SetRenameEnableCommand = new Command(arg => IsNameReadOnly = !Convert.ToBoolean(arg)); SetRenameEnableCommand.CanExecuteDelegate = arg => this.GetType() == typeof(FolderViewModel); CreateSubFolderCommand = new Command(arg => { string name = FullName + "\\" + "Новая папка"; string newName = name; for (int i = 1; Directory.Exists(newName); ++i) newName = name + " (" + i.ToString() + ")"; FileSystem.CreateDirectory(newName); }); DeleteCommand = new Command(arg => Task.Run(() => FileSystem.DeleteDirectory(FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin, UICancelOption.DoNothing))); CopyCommand = new Command(arg => { foreach (var folder in DriveViewModel.CutedFolders) folder.IsCuted = false; DriveViewModel.CutedFolders.Clear(); StringCollection folderPath = new StringCollection(); folderPath.Add(FullName); Clipboard.SetFileDropList(folderPath); FileSystemViewModel.IsClipBoardItemsCuted = false; }); CopyCommand.CanExecuteDelegate = arg => this.GetType() == typeof(FolderViewModel); CutCommand = new Command(arg => { IsCuted = true; foreach (var folder in DriveViewModel.CutedFolders) folder.IsCuted = false; DriveViewModel.CutedFolders.Clear(); StringCollection folderPath = new StringCollection(); DriveViewModel.CutedFolders.Add(this); folderPath.Add(FullName); Clipboard.SetFileDropList(folderPath); FileSystemViewModel.IsClipBoardItemsCuted = true; }); CutCommand.CanExecuteDelegate = new Predicate<object>(arg => this.GetType() == typeof(FolderViewModel)); DeleteFilesCommand = new Command(arg => { foreach (var file in FolderFilesCollectionView.SelectedItems) file.Delete(); }); DeleteCommand.CanExecuteDelegate = new Predicate<object>(arg => this.GetType() == typeof(FolderViewModel)); OpenFilesCommand = new Command(arg => { foreach (var file in FolderFilesCollectionView.SelectedItems) file.Open(); }); CopyFilesCommand = new Command(arg => { foreach (var file in DriveViewModel.CutedFiles) file.IsCuted = false; DriveViewModel.CutedFiles.Clear(); StringCollection filePaths = new StringCollection(); foreach (var file in FolderFilesCollectionView.SelectedItems) filePaths.Add(file.FullName); Clipboard.SetFileDropList(filePaths); FileSystemViewModel.IsClipBoardItemsCuted = false; }); CutFilesCommand = new Command(arg => { foreach (var file in DriveViewModel.CutedFiles) file.IsCuted = false; DriveViewModel.CutedFiles.Clear(); StringCollection filePaths = new StringCollection(); foreach (var file in FolderFilesCollectionView.SelectedItems) { DriveViewModel.CutedFiles.Add(file); file.IsCuted = true; filePaths.Add(file.FullName); } Clipboard.SetFileDropList(filePaths); FileSystemViewModel.IsClipBoardItemsCuted = true; }); SortFilesCommand = new Command(arg => { if (_ListSortDirection == ListSortDirection.Descending) _ListSortDirection = ListSortDirection.Ascending; else _ListSortDirection = ListSortDirection.Descending; if (arg.ToString() == "Size") { FolderFilesCollectionView.CustomSort = new FileSizeSorter(_ListSortDirection); } else if (arg.ToString() == "LastWriteTime") { FolderFilesCollectionView.CustomSort = new DateTimeSorter(_ListSortDirection); } else { FolderFilesCollectionView.SortDescriptions.Clear(); FolderFilesCollectionView.CustomSort = null; FolderFilesCollectionView.SortDescriptions.Add(new SortDescription(arg.ToString(), _ListSortDirection)); } }); PasteCommand = new Command(arg => Paste(Clipboard.GetFileDropList(), FullName, FileSystemViewModel.IsClipBoardItemsCuted)); PasteCommand.CanExecuteDelegate = arg => Clipboard.ContainsFileDropList(); FindCommand = new Command(arg => FolderFilesCollectionView.Filter = new Predicate<object>(item => (((FileViewModel)item).Name.ToLower() + ((FileViewModel)item).Extension.ToLower()).Contains(arg.ToString().ToLower()))); RenameCommand = new Command(arg => { if (arg.ToString() != Name) try { FileSystem.RenameDirectory(FullName, arg.ToString()); } catch (ArgumentException) { NotifyPropertyChanged("Name"); IsWrongName = true; } catch (DirectoryNotFoundException) { } }); #endregion _SubFoldersClearTimer.Elapsed += _OnSubFoldersClearTimerElapsed; Name = newFolder.DirInfo.Name; FullName = newFolder.DirInfo.FullName; SubFolders = new ObservableRangeCollection<FolderViewModel>(); FolderFiles = new ObservableRangeCollection<FileViewModel>(); try { if (Directory.GetDirectories(FullName).Length != 0) SubFolders.Add(null); } catch { } FolderFilesCollectionView = new MultiSelectCollectionView<FileViewModel>(FolderFiles); }
private void _Initialize(FileModel newFile) { FullName = newFile.FileInfo.FullName; Extension = newFile.FileInfo.Extension; Name = newFile.Name; Path = newFile.FileInfo.DirectoryName; LastWriteTime = newFile.FileInfo.LastWriteTime; Size = newFile.FileInfo.Length; IsSplited = Extension.Contains(".part"); OpenCommand = new Command(argt => Open()); SetRenameEnableCommand = new Command(arg => IsNameReadOnly = !Convert.ToBoolean(arg)); RenameCommand = new Command(arg => { if (arg.ToString() != Name) try { FileSystem.RenameFile(FullName, arg.ToString() + Extension); } catch (ArgumentException) { NotifyPropertyChanged("Name"); IsWrongName = true; } catch (FileNotFoundException) { } }); SplitFileCommand = new Command(async arg => { _CTS = new CancellationTokenSource(); await SplitFileAsync(_CTS.Token); }); SplitFileCommand.CanExecuteDelegate = arg => !IsSplited && !IsProcessing; MergeCommand = new Command(async arg => { _CTS = new CancellationTokenSource(); await MergeFileAsync(_CTS.Token); }); MergeCommand.CanExecuteDelegate = arg => IsSplited && !IsProcessing; CancelProcessingCommand = new Command(arg => _CTS.Cancel()); CancelProcessingCommand.CanExecuteDelegate = arg => IsProcessing; }
private LocalizationManager() { CultureManager.UICulture = Thread.CurrentThread.CurrentCulture; CultureManager.UICultureChanged += new EventHandler(CultureManager_UICultureChanged); ChangeLangCommand = new Command(arg => ChangeLang(arg.ToString())); }