示例#1
0
        //
        public void ClearImg(bool pushToUndoStack = true)
        {
            PropertyMementos mementos = CreateNewPropertyMementos();

            mementos.AddPropertyMemento(new PropertyMemento("ItemHeight", ItemHeight, ItemHeight));
            mementos.AddPropertyMemento(new PropertyMemento("ItemWidth", ItemWidth, ItemWidth));
            mementos.AddPropertyMemento(new PropertyMemento("Opacity", Opacity, Opacity));
            ClearImageCommand imgCmd = new ClearImageCommand(this, _imageStream, _isAutosize);

            //reader = File.OpenRead(openFile.FileName);

            _nailStream  = null;
            _imageStream = null;
            (_model as ImageModel).ImageStream = _imageStream;
            BackgroundShow = Visibility.Visible;
            Opacity        = 1;
            FirePropertyChanged("ImgSource");
            CreateNailStreamAndShow();
            if (pushToUndoStack && CurrentUndoManager != null)
            {
                mementos.SetPropertyNewValue("ItemHeight", ItemHeight);
                mementos.SetPropertyNewValue("ItemWidth", ItemWidth);
                mementos.SetPropertyNewValue("Opacity", Opacity);
                PropertyChangeCommand propCmd = new PropertyChangeCommand(this, mementos);

                UndoCompositeCommand cmds = new UndoCompositeCommand();
                cmds.AddCommand(imgCmd);
                cmds.AddCommand(propCmd);

                cmds.DeselectAllWidgetsFirst();
                CurrentUndoManager.Push(cmds);
            }
        }
示例#2
0
        public void WdgMgrHideAllWidgets(bool bIsHide)
        {
            if (_busyIndicator.IsShow == true)
            {
                return;
            }


            //TODO:
            if (Items.Count == 0)
            {
                return;
            }

            Naver.Compass.InfoStructure.CompositeCommand cmds = new Naver.Compass.InfoStructure.CompositeCommand();
            foreach (WidgetViewModBase item in Items)
            {
                if (bIsHide != item.IsHidden)
                {
                    CreatePropertyChangeUndoCommand(cmds, item, "IsHidden", item.IsHidden, bIsHide);
                    item.IsHidden = bIsHide;
                }
            }
            PushToUndoStack(cmds);
        }
示例#3
0
        private void DaletePageExecute(object cmdParameter)
        {
            if ((!GetOperationNode().IsRootNode) && _bVisible)
            {
                INodeViewModel Node   = NodeInfo.SelectedNode;
                INodeViewModel parent = Node.Parent;
                int            index  = Node.IndexInParent;

                Node.Remove();

                PageTreeChanged();

                if (index >= 0)
                {
                    DeletePageCommand cmd = new DeletePageCommand(this, Node, parent, index, _pageTree);
                    _undoManager.Push(cmd);
                }
            }
            else if (this._isMultiSelected)
            {
                var multiSelected = GetAllNodes(RootNode).Where(n => n.IsMultiSelected);
                if (multiSelected.Count() > 0)
                {
                    var cmds = new Naver.Compass.InfoStructure.CompositeCommand();
                    var multiSelectedClone = multiSelected.ToList();
                    foreach (var node in multiSelectedClone)
                    {
                        var _node   = node;
                        var _parent = node.Parent;
                        var _index  = node.IndexInParent;
                        if (_index >= 0)
                        {
                            var cmd = new DeletePageCommand(this, _node, _parent, _index, _pageTree);
                            cmds.AddCommand(cmd);
                        }
                    }

                    foreach (var node in multiSelectedClone)
                    {
                        node.Remove();
                    }

                    PageTreeChanged();

                    _undoManager.Push(cmds);
                    this.ClearMultiSelected();
                }
            }

            if (_pageTree != null)
            {
                _pageTree.Focus();
            }
        }
示例#4
0
 /// <summary>
 /// Undo add every widget in the group to object list.
 /// </summary>
 /// <param name="targetObject"> group</param>
 /// <param name="cmds"></param>
 private void UndoAddGroupTarget(IGroup targetGroup, UndoCompositeCommand cmds)
 {
     foreach (IGroup group in targetGroup.Groups)
     {
         UndoAddGroupTarget(group, cmds);
     }
     foreach (IWidget target in targetGroup.Widgets)
     {
         AddTargetCommand cmd = new AddTargetCommand(this, target.Guid, _selectedWidget == null ? Guid.Empty : _selectedWidget.Guid);
         cmds.AddCommand(cmd);
     }
 }
        private void MasterBreakAwayCommandHandler(object parameter)
        {
            MasterWidgetViewModel master = _selectionService.GetSelectedWidgets()[0] as MasterWidgetViewModel;

            if (master == null)
            {
                return;
            }

            Naver.Compass.InfoStructure.CompositeCommand cmds = new Naver.Compass.InfoStructure.CompositeCommand();
            var delCmd = new DeleteWidgetCommand(this, master);

            cmds.AddCommand(delCmd);
            Items.Remove(master);

            IObjectContainer container = _model.BreakMaster2Dom(master.widgetGID);

            AddObjects2Page2(container, _curAdaptiveViewGID, null, false, master.ZOrder, cmds);

            //TODO:Master Parent group operation
        }
        private void MasterLock2LocationCommandHandler(object parameter)
        {
            MasterWidgetViewModel master = _selectionService.GetSelectedWidgets()[0] as MasterWidgetViewModel;

            if (master == null)
            {
                return;
            }


            //Change UI
            Naver.Compass.InfoStructure.CompositeCommand cmds = new Naver.Compass.InfoStructure.CompositeCommand();
            List <Guid> updateGroupList = new List <Guid>();

            CreatePropertyChangeUndoCommand(cmds, master, "IsLocked2MasterLocation", master.IsLocked2MasterLocation, !master.IsLocked2MasterLocation);
            master.IsLocked2MasterLocation = !master.IsLocked2MasterLocation;

            //Update X and Y
            if (master.IsLocked2MasterLocation == true)
            {
                if (master.MasterLockedLocationX != master.Left)
                {
                    CreatePropertyChangeUndoCommand(cmds, master, "Left", master.Left, master.MasterLockedLocationX);
                    master.ForceSetX(master.MasterLockedLocationX);
                }
                if (master.MasterLockedLocationY != master.Top)
                {
                    CreatePropertyChangeUndoCommand(cmds, master, "Top", master.Top, master.MasterLockedLocationY);
                    master.ForceSetY(master.MasterLockedLocationY);
                }
            }

            //Update Group
            if (master.ParentID != Guid.Empty)
            {
                updateGroupList.Add(master.ParentID);
                UpdateGroup(master.ParentID);
            }
            PushToUndoStack(cmds, updateGroupList);
        }
示例#7
0
        public void BuildCompositeCommandAndPush(IUndoableCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException();
            }

            CompositeCommand commandToPush = command as CompositeCommand;

            if (commandToPush == null)
            {
                // If the push command is not CompositeCommand, then build a  CompositeCommand
                // to hold it as we should change to the page in which target widgets located first when undo/redo
                CompositeCommand cmds = new CompositeCommand();
                cmds.AddCommand(command);
                commandToPush = cmds;
            }


            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null && null != selectionService.GetCurrentPage())
            {
                // Add change page command in the first item.
                commandToPush.InsertCommand(0, new ChangePageCommand());
            }


            if (_undoStack.Count >= _undoLimit)
            {
                _undoStack.RemoveAt(0);
            }

            _undoStack.Add(commandToPush);

            Debug.WriteLine("Pushed a IUndoableCommand into undo stack. Undo stack count is : {0}.", _undoStack.Count);

            // New command is pushed in, clear the redo stack.
            _redoStack.Clear();
        }
        private void ConvertToMasterCommandHandler(object parameter)
        {
            try
            {
                MasterNameWindow win = new MasterNameWindow();
                win.NewName = MasterListViewModel.GetNextDataName();
                win.Owner   = Application.Current.MainWindow;
                win.ShowDialog();

                if (win.Result.HasValue && win.Result.Value)
                {
                    string masterName = win.NewName;

                    string           objectName = string.Empty;
                    ISerializeWriter writer     = GetSerializeWriter(ref objectName);
                    if (writer == null)
                    {
                        return;
                    }

                    var page = _document.CreateMasterPage(writer, masterName, CreateIconImage(false));
                    if (page != null)
                    {
                        //Add converted master to master list
                        _ListEventAggregator.GetEvent <AddConvertedMasterEvent>().Publish(page);
                        //keep widgets status when library editing mode
                        if (_document.DocumentType == DocumentType.Library)
                        {
                            return;
                        }

                        double minLeft = double.MaxValue;
                        double minTop  = double.MaxValue;
                        foreach (WidgetViewModBase wdgItem in _selectionService.GetSelectedWidgets())
                        {
                            if (minLeft > wdgItem.Left)
                            {
                                minLeft = wdgItem.Left;
                            }
                            if (minTop > wdgItem.Top)
                            {
                                minTop = wdgItem.Top;
                            }
                        }

                        //remove selected widgets
                        UndoCompositeCommand cmds = new UndoCompositeCommand();
                        RemoveSelectedWidget(cmds);

                        //add converted master to current page.
                        AddMasterItem(page.Guid, minLeft, minTop, cmds);

                        _undoManager.Push(cmds);

                        this.EditorCanvas.Focus();
                    }
                }
                else
                {
                    MasterListViewModel.RollBackDataName();
                }
            }
            catch (Exception ex)
            {
                NLogger.Debug("Convert Master failed: " + ex.Message);
            }
        }
示例#9
0
        private void CreateImageFromPath(string path)
        {
            Stream oldStream;

            if (_imageStream != null)
            {
                oldStream = new MemoryStream((int)_imageStream.Length);
                _imageStream.Seek(0, SeekOrigin.Begin);
                _imageStream.CopyTo(oldStream);
                oldStream.Seek(0, SeekOrigin.Begin);
            }
            else
            {
                oldStream = null;
            }

            bool             isAutosizeOldValue = _isAutosize;
            PropertyMementos mementos           = CreateNewPropertyMementos();

            mementos.AddPropertyMemento(new PropertyMemento("ItemHeight", ItemHeight, ItemHeight));
            mementos.AddPropertyMemento(new PropertyMemento("ItemWidth", ItemWidth, ItemWidth));

            _isAutosize = true;

            try
            {
                //reader = File.OpenRead(openFile.FileName);
                _imageStream = new MemoryStream(File.ReadAllBytes(path));
                (_model as ImageModel).ImageStream = _imageStream;

                // Get ImgSource so that ItemHeight and ItemWidth have the actual size value of the new image.
                // Here, FirePropertyChanged("ImgSource"); will not go into ImgSource get method when dragging a image file
                // on canvas, this cause hight and width are not updated to actual image size.
                // FirePropertyChanged("ImgSource") works well when importing image via file dialog, I don't know why
                // it doesn't work when dragging.
                // This is a workaround, remove this when you figure out the root cause.
                // ImageSource temp = ImgSource;

                FirePropertyChanged("ImgSource");

                if (CurrentUndoManager != null)
                {
                    mementos.SetPropertyNewValue("ItemHeight", ItemHeight);
                    mementos.SetPropertyNewValue("ItemWidth", ItemWidth);

                    PropertyChangeCommand propCmd = new PropertyChangeCommand(this, mementos);
                    ImportImageCommand    imgCmd  = new ImportImageCommand(this, oldStream, _imageStream, isAutosizeOldValue, _isAutosize);

                    UndoCompositeCommand cmds = new UndoCompositeCommand();
                    cmds.AddCommand(imgCmd);
                    cmds.AddCommand(propCmd);

                    cmds.DeselectAllWidgetsFirst();
                    CurrentUndoManager.Push(cmds);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, GlobalData.FindResource("Common_Error"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#10
0
        /// <summary>
        /// Delete all from doc in Global GuideBoxViewModel, and clear global guides in view.
        /// Clear page guides in view
        /// </summary>
        private void DeleteAllGuides()
        {
            if (GuideType == GuideType.Global)
            {
                if (_document != null && _page != null && _pageView != null)
                {
                    Naver.Compass.InfoStructure.CompositeCommand cmds = new Naver.Compass.InfoStructure.CompositeCommand();

                    #region delete local guides(only current view)
                    if (_pageView.Guides.Count > 0)
                    {
                        List <IGuide> guides = new List <IGuide>();

                        foreach (IGuide guide in _pageView.Guides)
                        {
                            if (guide.IsLocked == false)
                            {
                                guides.Add(guide);
                            }
                        }

                        //delete from doc
                        foreach (IGuide guide in guides)
                        {
                            _pageView.DeleteGuide(guide.Guid);
                        }

                        // Redo/Undo for page guides
                        DeletePageGuideCommand cmd = new DeletePageGuideCommand(_pageView, guides);
                        cmds.AddCommand(cmd);
                    }
                    #endregion

                    #region delete global guides.

                    if (_document.GlobalGuides.Count > 0)
                    {
                        List <IGuide> golbalGuides = new List <IGuide>();
                        foreach (IGuide guide in _document.GlobalGuides)
                        {
                            if (guide.IsLocked == false)
                            {
                                golbalGuides.Add(guide);
                            }
                        }

                        //delete from doc
                        foreach (IGuide guide in golbalGuides)
                        {
                            _document.DeleteGlobalGuide(guide.Guid);
                        }

                        // Redo/Undo for Global Guides
                        DeleteGlobalGuideCommand gCmd = new DeleteGlobalGuideCommand(_document, golbalGuides);
                        cmds.AddCommand(gCmd);
                    }
                    #endregion

                    if (cmds.Count > 0)
                    {
                        CurrentUndoManager.Push(cmds);
                    }

                    LoadGlobalGuide();
                }
            }
            else
            {
                LoadPageGuide();
            }
        }