コード例 #1
0
        protected override void OnThumbDragCompleted(DragCompletedEventArgs e)
        {
            base.OnThumbDragCompleted(e);
            if (_initialCornerRadius == Value)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            // Create undoable command for widgets
            foreach (RoundedRecWidgetViewModel item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("CornerRadius", item.CornerRadius);
                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                DesignerCanvas designerCanvas = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(this.designerItem))) as DesignerCanvas;
                ISupportUndo   pageVMUndo     = designerCanvas.DataContext as ISupportUndo;
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
    private void OnComboBoxChanged(object o, EventArgs args)
    {
        try {
            ComboBoxEntry comboBox = (ComboBoxEntry)o;
            string        s        = comboBox.ActiveText;

            // strip off comments from licenseTemplateTexts
            if (s == "non-redistributable (forbid sharing and modification of this level)")
            {
                s = s.Substring(0, s.IndexOf(" ("));
            }
            if (s == "GPL 2+ / CC-by-sa 3.0 (allow sharing and modification of this level)")
            {
                s = s.Substring(0, s.IndexOf(" ("));
            }

            if (s != (string)Field.GetValue(Object))                    //no change => no undo item
            {
                PropertyChangeCommand command = new PropertyChangeCommand(
                    "Changed value of " + Field.Name,
                    Field,
                    Object,
                    s);
                command.Do();
                UndoManager.AddCommand(command);
            }
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }
    }
コード例 #4
0
    private void OnChooseColor(object sender, EventArgs args)
    {
        Drawing.Color col = new Drawing.Color();
        col.Red   = ((float)colorButton.Color.Red) / 65535f;
        col.Blue  = ((float)colorButton.Color.Blue) / 65535f;
        col.Green = ((float)colorButton.Color.Green) / 65535f;
        col.Alpha = 1f;
        if (useAlpha)
        {
            col.Alpha = ((float)colorButton.Alpha) / 65535f;
        }

        if (col != (Drawing.Color)Field.GetValue(Object))
        {
            PropertyChangeCommand command = new PropertyChangeCommand(
                "Changed value of " + Field.Name,
                Field,
                Object,
                col);
            command.Do();
            UndoManager.AddCommand(command);
            //Console.WriteLine("ChooseColorWidget change col r{0},g{1},b{2},a{3}", col.Red, col.Green, col.Blue, col.Alpha);
            //Console.WriteLine("ChooseColorWidget change gtk color r{0},g{1},b{2},a{3}", colorButton.Color.Red, colorButton.Color.Green, colorButton.Color.Blue, colorButton.Alpha);
        }
    }
コード例 #5
0
 protected void Execute(PropertyChangeCommand cmd)
 {
     _cmdProcessor.Execute(cmd);
     cmd.CommandExecuted += Cmd_Action;
     cmd.CommandRedone   += Cmd_Action;
     cmd.CommandUndone   += Cmd_Action;
     OnPropertyChanged(cmd.PropertyName);
 }
コード例 #6
0
        private void PushUndoStack()
        {
            // Undo/Redo
            ISupportUndo    pageVMUndo  = designerCanvas.DataContext as ISupportUndo;
            IGroupOperation pageVMGroup = designerCanvas.DataContext as IGroupOperation;

            if (pageVMUndo == null)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            IPagePropertyData Page = designerCanvas.DataContext as IPagePropertyData;
            bool bHasGroup         = Page.GetSelectedwidgets().Any(a => a.IsGroup);

            // Create undoable command for widgets
            foreach (WidgetViewModBase item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left);
                item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top);

                if (item.WidgetType == WidgetType.Toast && item.Top != 0)
                {
                    item.PropertyMementos.SetPropertyNewValue("DisplayPosition", ToastDisplayPosition.UserSetting);
                }

                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Create undoable command for groups
            if (pageVMGroup != null)
            {
                List <Guid> groupGuids = _groups.Select(x => x.WidgetID).ToList();

                if (designerItem.ParentID != Guid.Empty)
                {
                    groupGuids.Add(designerItem.ParentID);
                }

                if (groupGuids.Count > 0)
                {
                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets();
                cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects));

                cmds.DeselectAllWidgetsFirst();
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
コード例 #7
0
    public void DeleteCurrentPath()
    {
        SetToolSelect();
        Command command = new PropertyChangeCommand("Deleted path from " + iPathToEdit.GetType().ToString(),
                                                    FieldOrProperty.Lookup(iPathToEdit.GetType().GetProperty("Path")), iPathToEdit, null);

        command.Do();
        UndoManager.AddCommand(command);
    }
コード例 #8
0
        private void SetGroupTargetObjectContinue(List <WidgetViewModBase> targetWidgets, CompositeCommand cmds, GroupViewModel NewGroupVM)
        {
            if (targetWidgets.Count < 1)
            {
                return;
            }

            int maxZOrder = targetWidgets.Max(a => a.ZOrder);
            int minZOrder = targetWidgets.Min(a => a.ZOrder);

            if (targetWidgets.Count() < (maxZOrder - minZOrder + 1))
            {
                targetWidgets.Sort(delegate(WidgetViewModBase a1, WidgetViewModBase a2)
                {
                    if (a1.ZOrder == a2.ZOrder)
                    {
                        return(0);
                    }
                    return((a1.ZOrder < a2.ZOrder) ? 1 : -1);
                });

                int maxZ = maxZOrder;
                foreach (WidgetViewModBase item in targetWidgets)
                {
                    //Undo command
                    if (cmds != null)
                    {
                        PropertyChangeCommand cmd = new PropertyChangeCommand(item, "ZOrder", item.ZOrder, maxZ);
                        cmds.AddCommand(cmd);
                    }
                    item.ZOrder = maxZ--;
                }

                List <WidgetViewModBase> widgets = items.OfType <WidgetViewModBase>().Where(a => a.ZOrder > minZOrder && a.ZOrder < maxZOrder && !(NewGroupVM.IsChild(a.widgetGID, false))).ToList <WidgetViewModBase>();
                widgets.Sort(delegate(WidgetViewModBase a1, WidgetViewModBase a2)
                {
                    if (a1.ZOrder == a2.ZOrder)
                    {
                        return(0);
                    }
                    return((a1.ZOrder > a2.ZOrder) ? 1 : -1);
                });

                int minZ = minZOrder;
                foreach (WidgetViewModBase item in widgets)
                {
                    //Undo command
                    if (cmds != null)
                    {
                        PropertyChangeCommand cmd = new PropertyChangeCommand(item, "ZOrder", item.ZOrder, minZ);
                        cmds.AddCommand(cmd);
                    }
                    item.ZOrder = minZ++;
                }
            }
        }
コード例 #9
0
    public void OnMouseButtonRelease(Vector mousePos, int button, ModifierType Modifiers)
    {
        if (dragging && selectedNode.Pos != originalPos)
        {
            Command command = new PropertyChangeCommand("Moved Path Node", FieldOrProperty.Lookup(typeof(Path.Node).GetProperty("Pos")), selectedNode, selectedNode.Pos, originalPos);
            UndoManager.AddCommand(command);
        }

        dragging = false;
    }
コード例 #10
0
        public ViewModelBase()
        {
            BackgroundColor.Value       = OuterColors[3];
            SeparatorColor.Value        = AccentColor;
            SelectedColor.Value         = BackColor;
            HeaderTextColor.Value       = DeepTextColor;
            HeaderBackgroundColor.Value = Color.Transparent;
            FooterTextColor.Value       = DeepTextColor;
            FooterBackgroundColor.Value = Color.Transparent;
            CellTitleColor.Value        = DeepTextColor;
            CellValueTextColor.Value    = PaleTextColor;
            CellDescriptionColor.Value  = PaleTextColor;
            CellBackgroundColor.Value   = CellBackColor;
            CellAccentColor.Value       = AccentColor;
            CellHintTextColor.Value     = AccentColor;

            HeaderFontSize.Value          = 10;
            HeaderHeight.Value            = 16;
            FooterFontSize.Value          = 10;
            CellTitleFontSize.Value       = 14;
            CellValueTextFontSize.Value   = 12;
            CellDescriptionFontSize.Value = 10;
            CellIconSize.Value            = new Size(30, 30);
            CellIconRadius.Value          = 4;
            CellHintFontSize.Value        = 9;

            HasUnevenRows.Value              = false;
            UseDescriptionAsValue.Value      = false;
            ShowSectionTopBottomBorder.Value = true;


            IconSource.Value          = null;
            IconSize.Value            = new Size();
            IconRadius.Value          = 0;
            Title.Value               = "Title";
            Description.Value         = "Description";
            HintText.Value            = "hint";
            ValueText.Value           = "value";
            BgColor.Value             = Color.Transparent;
            TitleColor.Value          = DeepTextColor;
            TitleFontSize.Value       = 12;
            ValueTextColor.Value      = PaleTextColor;
            ValueTextFontSize.Value   = 12;
            DescriptionColor.Value    = PaleTextColor;
            DescriptionFontSize.Value = 10;
            HintTextColor.Value       = Color.Red;
            HintFontSize.Value        = 9;


            PropertyChangeCommand.Subscribe(ParentChanged);
            CellChangeCommand.Subscribe(CellChanged);
        }
コード例 #11
0
ファイル: MoveThumb.cs プロジェクト: naver/protonow
        private void MoveThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            var designerItem = this.DataContext as Control;

            if (designerItem != null && _isMousePressMove)
            {
                MenuPageEditorViewModel menuPageEditor = designerItem.DataContext as MenuPageEditorViewModel;
                menuPageEditor.PropertyMementos.SetPropertyNewValue("Raw_EditorRectLeft", menuPageEditor.EditorRectLeft);
                menuPageEditor.PropertyMementos.SetPropertyNewValue("Raw_EditorRectTop", menuPageEditor.EditorRectTop);
                PropertyChangeCommand cmd = new PropertyChangeCommand(menuPageEditor, menuPageEditor.PropertyMementos);
                (_page as ISupportUndo).UndoManager.Push(cmd);
            }
        }
コード例 #12
0
    private void OnDeletePath(object o, EventArgs args)
    {
        IPathObject pathObject = (IPathObject)application.CurrentTilemap;

        if (pathObject.Path != null)
        {
            Command command = new PropertyChangeCommand("Removed path of Tilemap " + application.CurrentTilemap.Name + " (" + application.CurrentTilemap.ZPos + ")",
                                                        FieldOrProperty.Lookup(typeof(Tilemap).GetProperty("Path")),
                                                        application.CurrentTilemap,
                                                        null);
            command.Do();
            UndoManager.AddCommand(command);
        }
    }
コード例 #13
0
    private void OnDeletePath(object o, EventArgs args)
    {
        IPathObject pathObject = (IPathObject)selectedObjects[0];

        if (pathObject.Path != null)
        {
            Command command = new PropertyChangeCommand("Removed path from " + selectedObjects[0],
                                                        LispReader.FieldOrProperty.Lookup(typeof(IPathObject).GetProperty("Path")),
                                                        selectedObjects[0],
                                                        null);
            command.Do();
            UndoManager.AddCommand(command);
        }
    }
コード例 #14
0
ファイル: ScriptEditor.cs プロジェクト: slackstone/tuxjunior
    protected void OnOk(object o, EventArgs args)
    {
        try {
            PropertyChangeCommand command = new PropertyChangeCommand(
                "Changed value of " + field.Name,
                field,
                object_,
                scriptEditor.Buffer.Text);
            command.Do();
            UndoManager.AddCommand(command);
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }

        field.Changed -= OnFieldChanged;
        scriptDialog.Hide();
    }
コード例 #15
0
        /// <summary>
        /// Property Changed
        /// </summary>
        /// <returns>
        /// void
        /// </returns>
        public void PropertyChanged(GridItem itemChanged, object oldVal)
        {
            int i;
            int n        = _graphicsList.Count;
            var tempList = new ArrayList();

            for (i = n - 1; i >= 0; i--)
            {
                if (((DrawObject)_graphicsList[i]).Selected)
                {
                    tempList.Add(_graphicsList[i]);
                }
            }

            var cmd = new PropertyChangeCommand(tempList, itemChanged, oldVal);

            _undoRedo.AddCommand(cmd);
        }
コード例 #16
0
 private void OnComboBoxChanged(object o, EventArgs args)
 {
     try {
         ComboBox comboBox = (ComboBox)o;
         string   newText  = comboBox.ActiveText;
         string   oldText  = (string)Field.GetValue(Object);
         if (newText != oldText)
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + Field.Name,
                 Field,
                 Object,
                 newText);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
コード例 #17
0
 private void OnCheckButtonToggled(object o, EventArgs args)
 {
     try {
         Gtk.CheckButton checkButton = (Gtk.CheckButton)o;
         FieldOrProperty field       = fieldTable[widgetTable.IndexOf(checkButton)];
         bool            oldValue    = (bool)field.GetValue(Object);
         bool            newValue    = checkButton.Active;
         if (oldValue != newValue)                   //no change => no Undo action
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 newValue);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
コード例 #18
0
 private void OnComboBoxChanged(object o, EventArgs args)
 {
     try {
         Gtk.ComboBox    comboBox = (Gtk.ComboBox)o;
         FieldOrProperty field    = fieldTable[widgetTable.IndexOf(comboBox)];
         // Parse the string back to enum.
         Enum oldValue = (Enum)field.GetValue(Object);
         Enum newValue = (Enum)Enum.Parse(field.Type, comboBox.ActiveText);
         if (!oldValue.Equals(newValue))                     //no change => no Undo action
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 newValue);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
コード例 #19
0
 private void OnEntryChangeDone(object o, FocusOutEventArgs args)
 {
     try {
         Entry entry = (Entry)o;
         if ((string)Field.GetValue(Object) == entry.Text)
         {
             return;
         }
         PropertyChangeCommand command = new PropertyChangeCommand(
             "Changed value of " + Field.Name,
             Field,
             Object,
             entry.Text);
         command.Do();
         UndoManager.AddCommand(command);
     } catch (Exception e) {
         ErrorDialog.Exception(e);
         string val = (string)Field.GetValue(Object);
         if (val != null)
         {
             entry.Text = val;
         }
     }
 }
コード例 #20
0
 private void OnEntryChangeDone(object o, Gtk.FocusOutEventArgs args)
 {
     try {
         Gtk.Entry             entry = (Gtk.Entry)o;
         FieldOrProperty       field = fieldTable[widgetTable.IndexOf(entry)];
         PropertyChangeCommand command;
         if (field.Type == typeof(string))
         {
             if ((string)field.GetValue(Object) == entry.Text)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 entry.Text);
         }
         else if (field.Type == typeof(float))
         {
             float parsed = Single.Parse(entry.Text);
             if (parsed.ToString() != entry.Text && parsed.ToString() + "." != entry.Text)
             {
                 entry.Text = parsed.ToString();
             }
             if ((float)field.GetValue(Object) == parsed)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 parsed);
         }
         else if (field.Type == typeof(int))
         {
             int parsed = Int32.Parse(entry.Text);
             if (parsed.ToString() != entry.Text)
             {
                 entry.Text = parsed.ToString();
             }
             if ((int)field.GetValue(Object) == parsed)
             {
                 return;
             }
             command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 parsed);
         }
         else
         {
             throw new ApplicationException(
                       "PropertiesView.OnEntryChangeDone, \"" + field.Type.FullName + "\" is not implemented yet. " +
                       "If you are a developer, please fix it, else report this full error message and what you did to cause it to the supertux developers.");
         }
         command.Do();
         UndoManager.AddCommand(command);
     } catch (FormatException fe) {
         errorLabel.Text = fe.Message;
         return;
     } catch (Exception e) {
         ErrorDialog.Exception(e);
         return;
     }
     errorLabel.Text = String.Empty;
 }
コード例 #21
0
ファイル: RotateThumb.cs プロジェクト: naver/protonow
        private void RotateThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (_infoItems.Count <= 0)
            {
                return;
            }

            // Undo/Redo
            ISupportUndo    pageVMUndo  = canvas.DataContext as ISupportUndo;
            IGroupOperation pageVMGroup = canvas.DataContext as IGroupOperation;

            if (pageVMUndo == null)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            // Create undoable command for widgets
            foreach (WidgetViewModBase item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("RotateAngle", item.RotateAngle);

                if (this.designerItem.IsGroup)
                {
                    item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left);
                    item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top);
                }
                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Create undoable command for groups
            if (pageVMGroup != null)
            {
                List <Guid> groupGuids = new List <Guid>();

                if (designerItem.ParentID != Guid.Empty)
                {
                    groupGuids.Add(designerItem.ParentID);

                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }

                if (this.designerItem.IsGroup)
                {
                    groupGuids.Add((designerItem.DataContext as GroupViewModel).WidgetID);

                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets();
                cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects));

                cmds.DeselectAllWidgetsFirst();
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
コード例 #22
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);
            }
        }
コード例 #23
0
        protected void ChangeProperty(object model, object target, PropertyInfo propertyInfo, object?newValue)
        {
            var command = new PropertyChangeCommand(model, target, propertyInfo, newValue);

            undoRedoStack.Execute(command);
        }