Ejemplo n.º 1
0
        public void AddVertGuideLineHandler(object obj)
        {
            if (GuideType == GuideType.Global || _page == null || _pageView == null)
            {
                return;
            }

            var values = (object[])obj;

            Ruler ruler = values[0] as Ruler;
            PageEditorViewModel editor = values[1] as PageEditorViewModel;

            System.Windows.Point point = Mouse.GetPosition(ruler);
            IGuide            guide    = _pageView.CreateGuide(Orientation.Vertical, (point.X + ruler.CountShift) / Scale, 0);
            VerticalGuideLine vLine    = new VerticalGuideLine(guide, GuideType.Local, editor.EditorScale);

            editor.EditorCanvas.Focus();
            GuideItems.Add(vLine);
            _document.IsDirty = true;

            List <IGuide> guides = new List <IGuide>();

            guides.Add(guide);
            CreatePageGuideCommand cmd = new CreatePageGuideCommand(_pageView, guides);

            CurrentUndoManager.Push(cmd);

            ShowGuide(editor);
        }
Ejemplo n.º 2
0
        private void LinkPageExecute(object obj)
        {
            PageNode node = obj as PageNode;

            if (node == null)
            {
                return;
            }

            // Selected page changed
            if (_widgetOpenAction != null && _widgetOpenAction.LinkPageGuid != node.Guid)
            {
                if (CurrentUndoManager != null)
                {
                    SelectPageCommand cmd = new SelectPageCommand(this, _widgetOpenAction.LinkPageGuid, node.Guid,
                                                                  _selectedWidget == null ? Guid.Empty : _selectedWidget.Guid);

                    CurrentUndoManager.Push(cmd);
                }

                _widgetOpenAction.LinkPageGuid = node.Guid;

                Document.IsDirty = true;
            }
        }
Ejemplo n.º 3
0
        public void AddTarget(IUniqueObject targetObject)
        {
            if (WidgetShowHideAction != null)
            {
                WidgetShowHideAction.AddTargetObject(targetObject.Guid);

                SetShowHideAction();

                //current action is not "Check All"
                if (!_isCheckAllAction)
                {
                    if (CurrentUndoManager != null)
                    {  //widget
                        AddTargetCommand cmd = new AddTargetCommand(this, targetObject.Guid, _selectedWidget == null ? Guid.Empty : _selectedWidget.Guid);
                        CurrentUndoManager.Push(cmd);
                    }

                    //if all is checked , set IsCheckAll to true.
                    var node = WidgetList.FirstOrDefault(a => a.IsSelected == false);
                    if (node == null)
                    {
                        _isCheckAll = true;
                        FirePropertyChanged("IsCheckAll");
                    }
                }
                FirePropertyChanged("ShowHideType");
                FirePropertyChanged("AnimateType");
                FirePropertyChanged("AnimateTime");
                FirePropertyChanged("IsShowHideEnabled");
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        private void CreateGuides()
        {
            _guideList = new List <IGuide>();

            if (ColumnsCount > 0)
            {
                CreateVerticalGuides();
            }

            if (RowsCount > 0)
            {
                CreateHorizontalGuides();
            }

            if (_isGlobalChecked)
            {
                CreateGlobalGuideCommand cmd = new CreateGlobalGuideCommand(_document, _guideList);
                CurrentUndoManager.Push(cmd);
            }
            else
            {
                IPageView pageView = _page.PageViews.GetPageView(SelectionService.GetCurrentPage().CurAdaptiveViewGID);
                if (pageView == null)
                {
                    pageView = _page.PageViews.GetPageView(_document.AdaptiveViewSet.Base.Guid);
                }
                if (pageView == null)
                {
                    return;
                }
                CreatePageGuideCommand cmd = new CreatePageGuideCommand(pageView, _guideList);
                CurrentUndoManager.Push(cmd);
            }
        }
Ejemplo n.º 6
0
        private void LockExecute(object obj)
        {
            GuidePropertyChangeCommand cmd = new GuidePropertyChangeCommand(_guide, "IsLocked", IsLocked, !IsLocked);

            CurrentUndoManager.Push(cmd);

            IsLocked = !IsLocked;
        }
Ejemplo n.º 7
0
        private void DeleteGlobalGuide(IGuide guide)
        {
            if (_document != null)
            {
                List <IGuide> guides = new List <IGuide>();
                guides.Add(guide);
                DeleteGlobalGuideCommand cmd = new DeleteGlobalGuideCommand(_document, guides);
                CurrentUndoManager.Push(cmd);

                //Remove from View
                GuideItems.Remove(GuideItems.FirstOrDefault(x => x.Guide == guide));
                //Remove from doc
                _document.DeleteGlobalGuide(guide.Guid);
            }
        }
Ejemplo n.º 8
0
        private void ClearExecute(object obj)
        {
            EditorFocus();

            Stream oldStream = GetStream();

            if (oldStream == null)
            {
                return;
            }

            ClearIcon();
            if (CurrentUndoManager != null)
            {
                ClearPageIconCommand clearCmd = new ClearPageIconCommand(this, oldStream);
                CurrentUndoManager.Push(clearCmd);
            }
        }
Ejemplo n.º 9
0
        private void ImportExecute(object obj)
        {
            EditorFocus();
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = CommonDefine.ImageFilter;
            if (openFile.ShowDialog() == false)
            {
                return;
            }

            try
            {
                if (_page != null)
                {
                    Stream oldStream;
                    if (ImgSource != null)
                    {
                        oldStream = new MemoryStream((int)_page.Icon.Length);
                        _page.Icon.Seek(0, SeekOrigin.Begin);
                        _page.Icon.CopyTo(oldStream);
                        oldStream.Seek(0, SeekOrigin.Begin);
                    }
                    else
                    {
                        oldStream = null;
                    }

                    MemoryStream stream = new MemoryStream(File.ReadAllBytes(openFile.FileName));
                    ImportIcon(stream);
                    if (CurrentUndoManager != null)
                    {
                        ImportPageIconCommand imgCmd = new ImportPageIconCommand(this, oldStream, stream);
                        CurrentUndoManager.Push(imgCmd);
                    }
                }
            }
            catch (System.Exception e)
            {
                NLogger.Warn("Import page icon failed: ", e.Message);
            }
        }
Ejemplo n.º 10
0
        private void EditListExecute(object obj)
        {
            List <IWidget> list = new List <IWidget>();

            foreach (var item in _VMItems)
            {
                //Fore Undo
                ListBaseWidgetViewModel listVM = item as ListBaseWidgetViewModel;
                listVM.StoreOldItems();

                list.Add(listVM.IWidget);
            }
            if (list.Count <= 0)
            {
                return;
            }

            EditListWindow win = new EditListWindow(list, _IsItemsSame);

            win.Owner = Application.Current.MainWindow;

            bool?bRValue = win.ShowDialog();

            if ((bool)bRValue)
            {
                Naver.Compass.InfoStructure.CompositeCommand cmds = new Naver.Compass.InfoStructure.CompositeCommand();
                foreach (var item in _VMItems)
                {
                    ListBaseWidgetViewModel listVM = item as ListBaseWidgetViewModel;
                    listVM.LoadList();

                    //Undo
                    EditListCommand cmd = new EditListCommand(listVM, listVM.OldItems, listVM.IWidget.Items);
                    cmds.AddCommand(cmd);
                    listVM.ClearOldItems();
                }
                CurrentUndoManager.Push(cmds);

                RefreshItemsList(true);
            }
        }
Ejemplo n.º 11
0
        public void EditListItems()
        {
            List <IWidget> list = new List <IWidget>();

            list.Add(IWidget);
            StoreOldItems();

            EditListWindow win = new EditListWindow(list);

            win.Owner = Application.Current.MainWindow;

            bool?bRValue = win.ShowDialog();

            if ((bool)bRValue)
            {
                LoadList();
                EditListCommand cmd = new EditListCommand(this, OldItems, IWidget.Items);
                CurrentUndoManager.Push(cmd);
                ClearOldItems();
            }
        }
Ejemplo n.º 12
0
        public void DeleteTaget(IUniqueObject targetObject)
        {
            if (WidgetShowHideAction != null)
            {
                WidgetShowHideAction.DeleteTagetObject(targetObject.Guid);

                //current action is not "Check All"
                if (!_isCheckAllAction)
                {
                    if (CurrentUndoManager != null)
                    {
                        DeleteTargetCommand cmd = new DeleteTargetCommand(this, targetObject.Guid, _selectedWidget == null ? Guid.Empty : _selectedWidget.Guid);
                        CurrentUndoManager.Push(cmd);
                    }

                    SetShowHideAction();

                    // Set IsCheckAll to false if one widget is unchecked.
                    _isCheckAll = false;
                    FirePropertyChanged("IsCheckAll");
                }
                FirePropertyChanged("IsShowHideEnabled");
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
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();
            }
        }