Ejemplo n.º 1
0
        private void TreeView_Drop(object sender, DragEventArgs e)
        {
            var pkgInfo = (PackageSourceInfo)DataContext;

            var target = (FrameworkElement)e.Source;
            PackageHeirarchyItem  parent = target.DataContext as PackageHeirarchyItem;
            PackageFileSourceInfo file   = target.DataContext as PackageFileSourceInfo;

            if (parent == null && file != null)
            {
                parent = file.Parent;
            }
            if (parent == null)
            {
                parent = pkgInfo.Root;
            }

            if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
            {
                foreach (string filePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                {
                    Add(parent, filePath);
                }
            }

            // Enabling/Disabling the Build button depending if the package is empty or not
            BuildButton.IsEnabled = (pkgInfo.Root.Children.Count > 0);

            e.Handled = true;
        }
Ejemplo n.º 2
0
        private void TreeView_Drop(object sender, DragEventArgs e)
        {
            var viewModel = (PackageBuilderViewModel)DataContext;
            var pkgInfo   = viewModel.PackageSourceInfo;

            var target = (FrameworkElement)e.Source;
            PackageHeirarchyItem  parent = target.DataContext as PackageHeirarchyItem;
            PackageFileSourceInfo file   = target.DataContext as PackageFileSourceInfo;

            if (parent == null && file != null)
            {
                parent = file.Parent;
            }
            if (parent == null)
            {
                parent = pkgInfo.Root;
            }

            if (e.Data is System.Windows.DataObject && ((System.Windows.DataObject)e.Data).ContainsFileDropList())
            {
                foreach (string filePath in ((System.Windows.DataObject)e.Data).GetFileDropList())
                {
                    Add(parent, filePath);
                }
            }

            e.Handled = true;
        }
Ejemplo n.º 3
0
        private void AddFile(PackageHeirarchyItem parent, string filePath)
        {
            var name = System.IO.Path.GetFileName(filePath);

            if (parent != null && !Contains(parent, name))
            {
                var newItem = new PackageFileSourceInfo(filePath);
                newItem.Name   = name;
                newItem.Parent = parent;

                parent.Children.Add(newItem);
            }
        }
Ejemplo n.º 4
0
        private void AddNodeToTreeModel(PackageFileSourceInfo node, TreeIter parentNode)
        {
            parentNode = m_packageContentStore.AppendValues(parentNode, node);

            PackageHeirarchyItem hierarchyItem = node as PackageHeirarchyItem;

            if (hierarchyItem != null)
            {
                foreach (PackageFileSourceInfo childNode in hierarchyItem.Children)
                {
                    AddNodeToTreeModel(childNode, parentNode);
                }
            }
        }
Ejemplo n.º 5
0
        private void TreeListView_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete || e.Key == Key.Back)
            {
                TreeListView          view   = (TreeListView)sender;
                PackageSourceInfo     source = (PackageSourceInfo)view.DataContext;
                PackageFileSourceInfo info   = view.SelectedItem as PackageFileSourceInfo;
                if (info != source.Root && info != null)
                {
                    info.Parent.Children.Remove(info);
                    view.Focus();
                }

                // Enabling/Disabling the Build button depending if the package is empty or not
                var pkgInfo = (PackageSourceInfo)DataContext;
                BuildButton.IsEnabled = (pkgInfo.Root.Children.Count > 0);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds item and its content (file or folder) to package.
        /// </summary>
        /// <param name="pPkg">Package being created.</param>
        /// <param name="item">Item to be added.</param>
        /// <returns>True is there was no error during the operation, false otherwise.</returns>
        private bool AddItemToPackage(TraceLab.Core.PackageSystem.Package pkg, PackageFileSourceInfo item)
        {
            bool   noError    = true;
            string targetPath = System.IO.Path.Combine(pkg.Location, item.GetPath());

            PackageHeirarchyItem dir = item as PackageHeirarchyItem;

            if (dir != null)
            {
                if (item.Parent != null)
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }

                foreach (PackageFileSourceInfo child in dir.Children)
                {
                    noError = noError && AddItemToPackage(pkg, child);
                }

                if (dir.HasComponents)
                {
                    pkg.SetDirectoryHasComponents(dir.GetPath(), true);
                }
                if (dir.HasTypes)
                {
                    pkg.SetDirectoryHasTypes(dir.GetPath(), true);
                }
            }
            else
            {
                System.IO.File.Copy(item.SourceFilePath, targetPath);
                //Add reference to this created package to all experiments and composite components
                if (this.isExperimentPackage && targetPath.EndsWith(".teml") || targetPath.EndsWith(".tcml"))
                {
                    noError = noError && AddPkgRefToExperiment(pkg, targetPath);
                }
                System.IO.File.SetAttributes(targetPath, System.IO.File.GetAttributes(targetPath) & ~System.IO.FileAttributes.ReadOnly);
                pkg.AddFile(targetPath);
            }

            return(noError);
        }
Ejemplo n.º 7
0
 protected void HandleKeyPress(object o, KeyPressEventArgs args)
 {
     if (args.Event.Key == Gdk.Key.Delete)
     {
         foreach (TreePath treePath in treeView.Selection.GetSelectedRows())
         {
             TreeIter iter;
             if (treeView.Model.GetIter(out iter, treePath))
             {
                 PackageFileSourceInfo info = treeView.Model.GetValue(iter, 0) as PackageFileSourceInfo;
                 PackageFileSourceInfo root = m_viewModel.PackageSourceInfo.Root;
                 //remove only if it is not a root
                 if (info != root && info != null)
                 {
                     info.Parent.Children.Remove(info);
                     m_packageContentStore.Remove(ref iter);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
        private void TreeListView_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete || e.Key == Key.Back)
            {
                TreeListView view = (TreeListView)sender;

                //data context of the view is multibinding to two objects - the first one is the packageBuilder,
                //the second one is that currentState (so that when it changes the view gets notification)
                List <object> values = view.DataContext as List <object>;
                if (values != null)
                {
                    PackageBuilderViewModel viewModel = (PackageBuilderViewModel)values[0];
                    PackageSourceInfo       source    = viewModel.PackageSourceInfo;
                    PackageFileSourceInfo   info      = view.SelectedItem as PackageFileSourceInfo;
                    if (info != source.Root && info != null)
                    {
                        info.Parent.Children.Remove(info);
                        view.Focus();
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void HandleDragDataReceived(object o, DragDataReceivedArgs args)
        {
            TreeView treeView = (TreeView)o;
            bool     success  = false;

            //1. check if we can drop at the given position
            TreePath             path;
            TreeViewDropPosition pos;

            if (!treeView.GetDestRowAtPos(args.X, args.Y, out path, out pos))
            {
                args.RetVal = false;
                Gtk.Drag.Finish(args.Context, success, false, args.Time);
                return;
            }

            //2. check if given position can find corresponding iter (iter holds value with PackageSourceInfo)
            Gtk.TreeIter folderIter;
            if (!m_packageContentStore.GetIter(out folderIter, path))
            {
                args.RetVal = false;
                Gtk.Drag.Finish(args.Context, success, false, args.Time);
                return;
            }

            //if user drop the item not on the folder then return false
            PackageHeirarchyItem folder = this.treeView.Model.GetValue(folderIter, 0) as PackageHeirarchyItem;

            if (folder == null)
            {
                args.RetVal = false;
                Gtk.Drag.Finish(args.Context, success, false, args.Time);
                return;
            }

            if (pos == TreeViewDropPosition.Before)
            {
                treeView.SetDragDestRow(path, TreeViewDropPosition.IntoOrBefore);
            }
            else if (pos == TreeViewDropPosition.After)
            {
                treeView.SetDragDestRow(path, TreeViewDropPosition.IntoOrAfter);
            }

            Gdk.Drag.Status(args.Context, args.Context.SuggestedAction, args.Time);

            string        data  = System.Text.Encoding.UTF8.GetString(args.SelectionData.Data);
            List <string> paths = new List <string>(System.Text.RegularExpressions.Regex.Split(data, "\r\n"));

            paths.RemoveAll(string.IsNullOrEmpty);
            paths.RemoveAt(paths.Count - 1); // I don't know what last object is, but I tested and noticed that it is not a path

            foreach (string uriPath in paths)
            {
                string localPath = new Uri(uriPath).LocalPath;
                System.Console.WriteLine("Got Path {0}", localPath);
                PackageFileSourceInfo newItem = m_viewModel.Add(folder, localPath);

                //update also a view
                if (newItem != null)
                {
                    AddNodeToTreeModel(newItem, folderIter);
                }
            }

            success = true;
            Gtk.Drag.Finish(args.Context, success, false, args.Time);
        }
Ejemplo n.º 10
0
        private void RenderName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            PackageFileSourceInfo value = (PackageFileSourceInfo)model.GetValue(iter, 0);

            (cell as CellRendererText).Text = value.Name;
        }