Esempio n. 1
0
        public void Enable()
        {
            MagicLaboratory.UnBlur(Contents);

            _pBar.Visibility      = Visibility.Collapsed;
            _pBar.IsIndeterminate = false;
        }
Esempio n. 2
0
        public void Disable()
        {
            MagicLaboratory.Blur(Contents);

            _pBar.Visibility = Visibility.Visible;

            _pBar.IsIndeterminate = true;
        }
Esempio n. 3
0
 private void MakeThumbnail(string path)
 {
     try
     {
         var thumbnail = Template.FindName("Thumbnail", this) as Rectangle;
         var bmp       = new Bitmap(Path);
         thumbnail.Fill = new ImageBrush(MagicLaboratory.ImageSourceForBitmap(bmp));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Esempio n. 4
0
 private void MakeThumbnail()
 {
     try
     {
         var thumbnail = Template.FindName("Thumbnail", this) as Rectangle;
         var icon      = System.Drawing.Icon.ExtractAssociatedIcon(Path);
         var bmp       = icon.ToBitmap();
         thumbnail.Fill = new ImageBrush(MagicLaboratory.ImageSourceForBitmap(bmp));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Esempio n. 5
0
        private void NewItemMenu(MenuItem item)
        {
            var folder_tb = new TextBlock();

            folder_tb.Inlines.Add(new Run("📁")
            {
                Foreground = Brushes.LightGoldenrodYellow,
                FontSize   = 16,
                FontFamily = new FontFamily("Vendana")
            });
            folder_tb.Inlines.Add(new Run(" New Folder.")
            {
                Foreground = Brushes.White
            });
            var file_tb = new TextBlock();

            file_tb.Inlines.Add(new Run("🗋")
            {
                Foreground = Brushes.LightGoldenrodYellow,
                FontSize   = 16,
                FontFamily = new FontFamily("Vendana")
            });
            file_tb.Inlines.Add(new Run(" New Folder.")
            {
                Foreground = Brushes.White
            });
            var folder = new MenuItem
            {
                Header = folder_tb
            };

            folder.Click += (s, e) =>
            {
                var name = MagicLaboratory.RandomString(6);
                Directory.CreateDirectory(Item.Path + @"\" + name);
                Item.AddFolder(name, "", Item.Path + @"\" + name);
                Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
                                       new Action(() => { Item.Items[Item.Items.Count - 1].Rename("New folder..."); }));
            };
            var file = new MenuItem
            {
                Header = file_tb
            };

            item.Items.Add(folder);
            item.Items.Add(file);
        }
Esempio n. 6
0
 private void ReadFile_DataChanged(object sender, EventArgs e)
 {
     if (OutputPorts[0].Data.Value != _tb.Text)
         _tb.Text = MagicLaboratory.CorrectWindowsPath(OutputPorts[0].Data.Value);
 }
Esempio n. 7
0
        public ObjectPort(VirtualControl host, PortTypes portType, string text, RTypes type)
        {
            Text = text;
            Data = new RVariable(type);
            Host = host;
            // Focusable = false;
            Data.ParentPort = this;


            if (portType == PortTypes.Input)
            {
                if (type == RTypes.ArrayOrFactorOrListOrMatrix)
                {
                    Style = (Style)FindResource("InArrayPortStyle");
                }
                else
                {
                    Style = (Style)FindResource("InObjectPortStyle");
                }
                PortTypes = PortTypes.Input;
            }
            else
            {
                if (type == RTypes.ArrayOrFactorOrListOrMatrix)
                {
                    Style = (Style)FindResource("OutArrayPortStyle");
                }
                else
                {
                    Style = (Style)FindResource("OutObjectPortStyle");
                }
                PortTypes = PortTypes.Output;
            }
            Loaded += (sender, args) =>
            {
                Host   = host;
                _panel = (StackPanel)Template.FindName("ControlsPanel", this);
                _pin   = (UIElement)Template.FindName("Pin", this);
                if (_pin != null)
                {
                    _pin.PreviewMouseDown += OnMouseDown;
                }
                if (_panel == null)
                {
                    return;
                }
                if (Control != null)
                {
                    try
                    {
                        _panel.Children.Remove(Control);
                        _panel.Children.Add(Control);
                    }
                    catch (Exception)
                    {
                        MagicLaboratory.unLinkChild(Control);
                        _panel.Children.Add(Control);
                    }
                }
            };

            PreviewMouseUp   += OnMouseUp;
            PreviewMouseMove += ObjectPort_PreviewMouseMove;
            MouseLeave       += (sender, args) =>
            {
                Host.HideLinkingPossiblity();
                ParentNode.Refresh();
                args.Handled = true;
            };

            Control.Loaded      += Control_Loaded;
            Control.SizeChanged += Control_SizeChanged;
        }
Esempio n. 8
0
        private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (WireMode == WireMode.FirstPortSelected && MouseMode == MouseMode.DraggingPort)
            {
                TempConn.EndPoint = new Point(mouseEventArgs.GetPosition(this).X - 1,
                                              mouseEventArgs.GetPosition(this).Y);
                if (_wiresDisabled)
                {
                    return;
                }
                for (var index = 0; index < Children.Count - 1; index++)
                {
                    var uielement = Children[index];
                    if (uielement is Wire)
                    {
                        MagicLaboratory.GrayWiresOut(uielement as Wire);
                    }
                }
                _wiresDisabled = true;
                return;
            }
            if (mouseEventArgs.LeftButton == MouseButtonState.Released)
            {
                if (_wiresDisabled)
                {
                    for (var index = 0; index < Children.Count - 1; index++)
                    {
                        var uielement = Children[index];
                        if (uielement is Wire)
                        {
                            MagicLaboratory.GrayWiresOut_Reverse(uielement as Wire);
                        }
                    }
                    _wiresDisabled = false;
                }
            }

            if (mouseEventArgs.LeftButton != MouseButtonState.Released && MouseMode == MouseMode.SelectionRectangle)
            {
                if (!Children.Contains(_selectionZone))
                {
                    AddChildren(_selectionZone);
                }
                var pos = mouseEventArgs.GetPosition(this);
                var x   = Math.Min(pos.X, _startPoint.X);
                var y   = Math.Min(pos.Y, _startPoint.Y);
                var w   = Math.Max(pos.X, _startPoint.X) - x;
                var h   = Math.Max(pos.Y, _startPoint.Y) - y;
                _selectionZone.Width  = w;
                _selectionZone.Height = h;
                SetLeft(_selectionZone, x);
                SetTop(_selectionZone, y);
                SelectionZoneWorkerOnDoWork();
                return;
            }
            if (MouseMode == MouseMode.ResizingComment && mouseEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                Cursor = Cursors.SizeNWSE;
                var currentPoint = Mouse.GetPosition(this);
                if (currentPoint.Y - TempComment.Y > 0 && currentPoint.X - TempComment.X > 0)
                {
                    TempComment.Height = /*TempComment.Top +*/ currentPoint.Y - TempComment.Y;
                    TempComment.Width  = /* TempComment.Left +*/ currentPoint.X - TempComment.X;
                    TempComment.LocateHandler();
                }
                else
                {
                    TempComment.Height = 32;
                    TempComment.Width  = 32;
                    TempComment.LocateHandler();
                }
                return;
            }
            if (NeedsRefresh)
            {
                foreach (var node in Nodes)
                {
                    node.Refresh();
                }

                TemExecPort   = null;
                TemObjectPort = null;
                NeedsRefresh  = false;
            }
        }
Esempio n. 9
0
        public Grep([Import("host")] VirtualControl host, [Import("bool")] bool spontaneousAddition = false) : base(
                host, NodeTypes.Basic, spontaneousAddition)
        {
            Title = "Grep";
            Host  = host;

            Category = "Characters";
            AddObjectPort(this, "Text", PortTypes.Input, RTypes.Character, false, _t);
            AddObjectPort(this, "Pattern", PortTypes.Input, RTypes.Generic, false, _p);
            AddObjectPort(this, "Case sensitive", PortTypes.Input, RTypes.Logical, false, _cbc);
            AddObjectPort(this, "Normal Text", PortTypes.Input, RTypes.Logical, false, _cb);
            AddObjectPort(this, "Extracted value", PortTypes.Output, RTypes.Character, true);
            MouseRightButtonDown += (sender, args) => GenerateCode();
            _t.TextChanged       += (sender, args) =>
            {
                InputPorts[0].Data.Value = _t.Text;
                GenerateCode();
            };
            _p.TextChanged += (sender, args) =>
            {
                InputPorts[1].Data.Value = _p.Text;
                GenerateCode();
            };
            _cbc.Checked += (sender, args) =>
            {
                InputPorts[2].Data.Value = _cbc.IsChecked.ToString().ToUpper();
                GenerateCode();
            };
            _cb.Checked += (sender, args) =>
            {
                InputPorts[3].Data.Value = _cb.IsChecked.ToString().ToUpper();
                GenerateCode();
            };
            foreach (var port in InputPorts)
            {
                port.DataChanged += (sender, args) => { GenerateCode(); }
            }
            ;
            InputPorts[1].LinkChanged += (sender, args) =>
            {
                if (!InputPorts[1].Linked)
                {
                    InputPorts[1].Data.Value = _p.Text;
                }
            };
            InputPorts[0].LinkChanged += (sender, args) =>
            {
                if (!InputPorts[0].Linked)
                {
                    InputPorts[0].Data.Value = _t.Text;
                }
            };
            InputPorts[3].LinkChanged += (sender, args) =>
            {
                if (!InputPorts[3].Linked)
                {
                    InputPorts[3].Data.Value = _cb.IsChecked.ToString().ToUpper();
                }
            };
            InputPorts[2].LinkChanged += (sender, args) =>
            {
                if (!InputPorts[2].Linked)
                {
                    InputPorts[2].Data.Value = _cbc.IsChecked.ToString().ToUpper();
                }
            };
            InputPorts[0].DataChanged += (s, e) =>
            {
                if (_t.Text != InputPorts[0].Data.Value)
                {
                    _t.Text = InputPorts[0].Data.Value;
                }
            };
            InputPorts[1].DataChanged += (s, e) =>
            {
                if (_p.Text != InputPorts[1].Data.Value)
                {
                    _p.Text = InputPorts[1].Data.Value;
                }
            };
            InputPorts[3].DataChanged += (s, e) =>
            {
                if (_cb.IsChecked.ToString().ToUpper() != InputPorts[3].Data.Value)
                {
                    _cb.IsChecked = MagicLaboratory.ConvertFromString(InputPorts[3].Data.Value);
                }
            };
            InputPorts[2].DataChanged += (s, e) =>
            {
                if (_cb.IsChecked.ToString().ToUpper() != InputPorts[2].Data.Value)
                {
                    _cbc.IsChecked = MagicLaboratory.ConvertFromString(InputPorts[2].Data.Value);
                }
            };
        }
Esempio n. 10
0
 public ContentsBrowser()
 {
     Style = FindResource("ContentsBrowser") as Style;
     _item.MouseDoubleClick += _item_MouseDoubleClick;
     Item.Container          = this;
     Loaded += (s, e) =>
     {
         ApplyTemplate();
         Item.Items.CollectionChanged += Items_CollectionChanged;
         FoldersTree                      = Template.FindName("FoldersTree", this) as TreeView;
         Contents                         = Template.FindName("Contents", this) as ListView;
         Contents.ContextMenu             = contentsMenu();
         FoldersTree.SelectedItemChanged += FoldersTree_SelectedItemChanged;
         _import     = (Border)Template.FindName("Import", this);
         _prev       = (Border)Template.FindName("Prev", this);
         _next       = (Border)Template.FindName("Next", this);
         _pBar       = (ProgressBar)Template.FindName("pBar", this);
         Item.Parent = Item;
         if (Hub.WorkSpace[Hub.WorkSpace.Length - 1] == '\\')
         {
             Hub.WorkSpace = Hub.WorkSpace.Remove(Hub.WorkSpace.Length - 1);
         }
         Item.Load(Hub.WorkSpace);
         ListDirectory(FoldersTree, Hub.WorkSpace);
         _next.IsEnabled = false;
         MagicLaboratory.Blur(_next);
         //Import item
         _import.PreviewMouseLeftButtonUp += _import_PreviewMouseLeftButtonUp;
         //Previous folder
         _prev.PreviewMouseLeftButtonUp += (ps, pe) =>
         {
             if (Item.Path != "")
             {
                 var di = new DirectoryInfo(Item.Path);
                 if (di.Parent != null && Item.Path != Hub.WorkSpace)
                 {
                     Item.NextPath = Item.Path;
                     Item.Load(di.Parent.FullName);
                     Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
                     {
                         _next.IsEnabled = true;
                         MagicLaboratory.UnBlur(_next);
                     }));
                 }
             }
         };
         KeyDown += ContentsBrowser_KeyDown;
         //Next folder
         _next.PreviewMouseLeftButtonUp += (ns, ne) =>
         {
             if (Item.Path != "")
             {
                 if (Item.NextPath != "")
                 {
                     Item.Load(Item.NextPath);
                 }
             }
             _next.IsEnabled = false;
             MagicLaboratory.Blur(_next);
         };
         _selectedItems.CollectionChanged += (c, ch) =>
         {
             foreach (var item in _selectedItems)
             {
                 var explorerItem = item;
                 if (explorerItem != null)
                 {
                     explorerItem.IsSelected        = true;
                     explorerItem.MouseDoubleClick += ExplorerItem_MouseDoubleClick;
                 }
             }
         };
         if (Contents != null)
         {
             Contents.ItemsSource       = Item.Items;
             Contents.SelectionChanged += Contents_SelectionChanged;
             Contents.PreviewKeyDown   += Contents_PreviewKeyDown;
         }
         var DTimer = new DispatcherTimer();
         DTimer.Interval  = new TimeSpan(0, 0, 3);
         DTimer.IsEnabled = true;
         DTimer.Tick     += (ss, ee) =>
         {
             var numOfElement = Directory.GetDirectories(Item.Path).Length +
                                Directory.GetFiles(Item.Path).Length;
             if (numOfElement != Item.Items.Count)
             {
                 Refresh();
             }
         };
     };
 }
Esempio n. 11
0
        private void ApplyNewName()
        {
            _tag.Visibility       = Visibility.Visible;
            _renameBox.Visibility = Visibility.Collapsed;
            var oldPAth = Path;
            var newPath = Parent.Path + @"\" + _renameBox.Text;

            MagicLaboratory.CleanPath(ref newPath);
            try
            {
                if (!Folder)
                {
                    if (File.Exists(Path))
                    {
                        File.Move(Path
                                  , newPath);
                        ItemName = _renameBox.Text;
                        var itemName = ItemName;
                        MagicLaboratory.CleanPath(ref itemName);
                        ItemName = itemName;
                        Path     = newPath;
                    }
                }

                if (Directory.Exists(Path) && Path != newPath)
                {
                    Directory.Move(Path
                                   , Uri.UnescapeDataString(newPath));
                    ItemName = _renameBox.Text;
                    var itemName = ItemName;
                    MagicLaboratory.CleanPath(ref itemName);
                    ItemName = itemName;
                    Path     = newPath;
                    var node       = Parent.Container.GetNode(oldPAth, Parent.Container.FoldersTree.Items);
                    var parentNode = Parent.Container.GetNode(Parent.Path, Parent.Container.FoldersTree.Items);
                    if (node == null)
                    {
                        parentNode.Items.Add(new TreeViewItem {
                            Header = new FolderItem(Path, ItemName)
                        });
                    }
                    else
                    {
                        var folderItem = node.Header as FolderItem;
                        if (folderItem != null)
                        {
                            folderItem.FolderName = itemName;
                            folderItem.Path       = Path;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var result = MessageBox.Show(ex.Message + "\n" + "Try again?", "Couldn't modify the name.",
                                             MessageBoxButton.YesNo, MessageBoxImage.Error);
                Parent.Container.Disable();
                if (result == MessageBoxResult.Yes)
                {
                    Parent.Container.Enable();
                    Rename();
                }
            }
        }
Esempio n. 12
0
 private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     _next.IsEnabled = false;
     MagicLaboratory.Blur(_next);
 }