Beispiel #1
0
        public void GetDirectoryStructure(DirectoryTreeItemViewModel dir)
        {
            if (CancelOperation)
            {
                return;
            }

            if (dir != null)
            {
                if (dir.Directory != null)
                {
                    var subItems = dir.Directory.ListFilesAndDirectories().OfType <CloudFileDirectory>()
                                   .Select(x => new DirectoryTreeItemViewModel()
                    {
                        Directory = x, Name = x.Name, IsDirectory = true, FullPath = x.Uri?.LocalPath, ParentNode = dir
                    })
                                   .ToList();

                    foreach (var item in subItems)
                    {
                        GetDirectoryStructure(item);
                    }
                }
            }
        }
Beispiel #2
0
        public DirectoryTreeItemViewModel RecalculateIndex()
        {
            var indexFile = GetDirectoryIndexFile();

            if (indexFile != null)
            {
                DirectoryTreeItemViewModel rootDir = new DirectoryTreeItemViewModel();
                rootDir.IsDirectory = true;
                rootDir.Directory   = rootDirectory;
                rootDir.FullPath    = rootDirectory.Uri.LocalPath;
                rootDir.Name        = "Documents";
                rootDir.ParentNode  = null;
                rootDir.Items       = new ObservableCollection <DirectoryTreeItemViewModel>();
                DirectoryTreeItemViewModel calculatedIndexes = CalculateDirectoryIndex(rootDir);

                string serialized = JsonConvert.SerializeObject(calculatedIndexes, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                    Formatting            = Formatting.None
                });

                indexFile.UploadText(serialized);

                return(calculatedIndexes);
            }
            return(null);
        }
Beispiel #3
0
        public DirectoryTreeItemViewModel CalculateDirectoryIndex(DirectoryTreeItemViewModel dir)
        {
            IndexingDirectoryChanged?.Invoke(dir.FullPath, 0);
            if (dir != null)
            {
                if (dir.Directory != null)
                {
                    //var files = dir.Directory.ListFilesAndDirectories().OfType<CloudFile>();
                    var directories = dir.Directory.ListFilesAndDirectories().OfType <CloudFileDirectory>();
                    if (dir.Items == null)
                    {
                        dir.Items = new ObservableCollection <DirectoryTreeItemViewModel>();
                    }

                    //if(files != null && files.Count() > 0)
                    //{
                    //    foreach (var item in files)
                    //    {
                    //        item.FetchAttributes();
                    //        DirectoryTreeItemViewModel file = new DirectoryTreeItemViewModel();
                    //        file.Name = item.Name;
                    //        file.IsDirectory = false;
                    //        file.ParentNode = dir;
                    //        file.FullPath = item.Uri.LocalPath;
                    //        if (item.Properties != null)
                    //        {
                    //            file.CreatedAt = item.Properties.LastModified?.DateTime ?? DateTime.MinValue;
                    //            file.FileSize = item.Properties.Length / 1024;
                    //        }
                    //        dir.Items.Add(file);
                    //    }
                    //}

                    if (directories != null && directories.Count() > 0)
                    {
                        foreach (var item in directories)
                        {
                            DirectoryTreeItemViewModel directory = new DirectoryTreeItemViewModel();
                            directory.Name        = item.Name;
                            directory.IsDirectory = true;
                            directory.ParentNode  = dir;
                            directory.FullPath    = item.Uri.LocalPath;

                            directory.Directory = item;

                            dir.Items.Add(directory);
                            directory = CalculateDirectoryIndex(directory);
                        }
                    }
                }
            }
            return(dir);
        }
Beispiel #4
0
        private void btnConfirmFolder_Click(object sender, RoutedEventArgs e)
        {
            var selectedDoc = documentExplorer?.SelectedDocument;

            if (selectedDoc == null)
            {
                MainWindow.ErrorMessage = "Morate odabrati folder da biste potvrdili putanju!";
                return;
            }


            // TODO: Zameni tip dokumenta
            SelectedDocument  = null;//selectedDoc;
            this.DialogResult = true;
        }
Beispiel #5
0
 private void btnCancelFolder_Click(object sender, RoutedEventArgs e)
 {
     SelectedDocument  = null;
     this.DialogResult = false;
     this.Close();
 }
        public DirectoryTree()
        {
            InitializeComponent();
            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                return;
            }

            DataContext             = RootModel = new DirectoryTreeViewModel();
            RootModel.RootDirectory = DirectoryInfoEx.DesktopDirectory;
            Commands = new DirectoryTreeCommands(this, RootModel);

            RootModel.OnProgress += (ProgressEventHandler) delegate(object sender, ProgressEventArgs e)
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new ThreadStart(delegate
                {
                    RaiseEvent(new ProgressRoutedEventArgs(ProgressEvent, e));
                }));
            };

            W7TreeViewItemUtils.SetIsEnabled(this, true);

            #region Selection
            this.AddHandler(TreeViewItem.SelectedEvent, new RoutedEventHandler(
                                (RoutedEventHandler) delegate(object obj, RoutedEventArgs args)
            {
                if (SelectedValue is DirectoryTreeItemViewModel)
                {
                    DirectoryTreeItemViewModel selectedModel = SelectedValue as DirectoryTreeItemViewModel;
                    SelectedDirectory = selectedModel.EmbeddedDirectoryModel.EmbeddedDirectoryEntry;
                    if (args.OriginalSource is TreeViewItem)
                    {
                        (args.OriginalSource as TreeViewItem).BringIntoView();
                    }

                    _lastSelectedContainer = (args.OriginalSource as TreeViewItem);
                }
            }));

            //this.SelectedDirectoryPath <---> this.SelectedDirectory
            Binding selectedDirectoryPathBinding = new Binding("SelectedDirectory");
            selectedDirectoryPathBinding.Mode                = BindingMode.TwoWay;
            selectedDirectoryPathBinding.Converter           = new ExToStringConverter();
            selectedDirectoryPathBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            selectedDirectoryPathBinding.Source              = this;
            this.SetBinding(DirectoryTree.SelectedDirectoryPathProperty, selectedDirectoryPathBinding);

            //this.SelectedDirectory <---> RootModel.SelectedDirectory
            Binding selectedDirectoryBinding = new Binding("SelectedDirectory");
            selectedDirectoryBinding.Mode = BindingMode.TwoWay;
            selectedDirectoryBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            selectedDirectoryBinding.Source = RootModel;
            this.SetBinding(DirectoryTree.SelectedDirectoryProperty, selectedDirectoryBinding);

            //this.AutoCollapse <---> RootModel.AutoCollapse
            Binding autoCollapseBinding = new Binding("AutoCollapse");
            autoCollapseBinding.Mode = BindingMode.OneWayToSource;
            autoCollapseBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            autoCollapseBinding.Source = RootModel;
            this.SetBinding(DirectoryTree.AutoCollapseProperty, autoCollapseBinding);
            #endregion

            #region ContextMenuWrapper - Obsoluted
            //_cmw = new ContextMenuWrapper();

            //this.AddHandler(TreeViewItem.MouseRightButtonUpEvent, new MouseButtonEventHandler(
            //    (MouseButtonEventHandler)delegate(object sender, MouseButtonEventArgs args)
            //    {
            //        if (SelectedValue is DirectoryTreeItemViewModel)
            //        {
            //            DirectoryTreeItemViewModel selectedModel = SelectedValue as DirectoryTreeItemViewModel;
            //            Point pt = this.PointToScreen(args.GetPosition(this));
            //            string command = _cmw.Popup(new FileSystemInfoEx[] { selectedModel.EmbeddedDirectoryModel.EmbeddedDirectoryEntry },
            //                new System.Drawing.Point((int)pt.X, (int)pt.Y));
            //            switch (command)
            //            {
            //                case "rename":
            //                    if (this.SelectedValue != null)
            //                    {
            //                        if (_lastSelectedContainer != null)
            //                        {
            //                            SetIsEditing(_lastSelectedContainer, true);
            //                        }
            //                    }
            //                    break;
            //                case "refresh":
            //                    if (this.SelectedValue is DirectoryTreeItemViewModel)
            //                    {
            //                        (this.SelectedValue as DirectoryTreeItemViewModel).Refresh();
            //                    }
            //                    break;
            //            }
            //        }
            //    }));
            #endregion
        }