private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectedNode = treeView1.SelectedNode; if (selectedNode != null) { pQueue.clearUndo(); // We need to clear the UndoList. The problem is that we readded elements an these elements now have different hashes :-( XmlNode node = pXmlHandler.getXmlNode(selectedNode); // The element we want to delete int nodeHash = pXmlHandler.getHash(node); XmlNode parentNode = node.ParentNode; int parentNodeHash = pXmlHandler.getHash(parentNode); cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("deleteElement"); cmd.DoEvent += new cCommandQueue.EventHandler(eventDoElement); cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoElement); cmd.Helper = parentNodeHash; cmd.From = parentNode.OuterXml; // For from we need the parent outerxml, for to we dont need it replaceXmlNode(nodeHash, ""); // Delete Element cmd.To = parentNode.OuterXml; // Set the result pQueue.addSilentCmd(cmd); } }
private void _addElement(String type, String outerXml) { TreeNode selectedNode = treeView1.SelectedNode; if (selectedNode != null) { XmlNode node = pXmlHandler.getXmlNode(selectedNode); // The parent element where we want to add a child. This has to be screen !! while (node != null && node.Name != "screen") { node = node.ParentNode; } if (node != null) { int nodeHash = pXmlHandler.getHash(node); cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("addElement"); cmd.DoEvent += new cCommandQueue.EventHandler(eventDoElement); cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoElement); cmd.Helper = nodeHash; cmd.From = node.OuterXml; // For from we need the parent outerxml, for to we dont need it //-- XmlNode newXmlNode = null; if (outerXml == null) { String[] attributes = { type, "name", "new " + type, "position", "0, 0", "size", "10, 10" }; newXmlNode = pXmlHandler.XmlAppendNode(node, attributes); } else { newXmlNode = pXmlHandler.XmlAppendNode(node, outerXml); } TreeNode newTreeNode = pXmlHandler.XmlSyncAddTreeChild(nodeHash, pXmlHandler.getTreeNode(nodeHash), newXmlNode); pXmlHandler.XmlSyncTreeChilds(newTreeNode.GetHashCode(), newTreeNode); //-- cmd.To = node.OuterXml; // Set the result pQueue.addSilentCmd(cmd); refresh(); refreshPropertyGrid(); } } }
private void tabControl1_KeyDown(object sender, KeyEventArgs e) { if (!this.keyCapture) return; // If CTRL pressed, use margin 1, else margin 5 //Console.WriteLine(e.Control.ToString()); if (isCURSOR(e)) { int marging = 5; if (isCTRL(e)) marging = 1; if (propertyGrid1.SelectedObject != null) { int x = isLEFT(e) ? -marging : (isRIGHT(e) ? +marging : 0); int y = isUP(e) ? -marging : (isDOWN(e) ? +marging : 0); sAttribute _Attr = (sAttribute)propertyGrid1.SelectedObject; Int32 posX = (Int32)(_Attr.pRelativX + x); Int32 posY = (Int32)(_Attr.pRelativY + y); if (posX < 0) posX = 0; if (posY < 0) posY = 0; sAttribute.Position pos = new sAttribute.Position(); pos.X = ((UInt32)posX).ToString(); pos.Y = ((UInt32)posY).ToString(); cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("KeyboardChange"); cmd.Helper = propertyGrid1.SelectedObject; cmd.DoEvent += new cCommandQueue.EventHandler(eventDoPropertyGrid); cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoPropertyGrid); cmd.From = new Object[] { "Relativ", _Attr.Relativ }; cmd.To = new Object[] { "Relativ", pos }; pQueue.addCmd(cmd); _Attr.Relativ = pos; propertyGrid1.Refresh(); sAttribute subattr = (sAttribute)propertyGrid1.SelectedObject; pDesigner.redrawFog((int)subattr.pAbsolutX, (int)subattr.pAbsolutY, (int)subattr.pWidth, (int)subattr.pHeight); pictureBox1.Invalidate(); } e.Handled = true; } else if (isPLUS(e)) { pDesigner.zoomIn(); //pictureBox1.Scale(new SizeF((float)0.5, (float)0.5)); // //pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; panelDesignerInner.AutoScrollMinSize = new Size((int)(cDataBase.pResolution.getResolution().Xres * pDesigner.zoomLevel()) + 100, (int)(cDataBase.pResolution.getResolution().Yres * pDesigner.zoomLevel()) + 100); trackBarZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f)*100.0f); numericUpDownZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f); pictureBox1.Invalidate(); } else if (isMINUS(e)) { pDesigner.zoomOut(); panelDesignerInner.AutoScrollMinSize = new Size((int)(cDataBase.pResolution.getResolution().Xres * pDesigner.zoomLevel()) + 100, (int)(cDataBase.pResolution.getResolution().Yres * pDesigner.zoomLevel()) + 100); trackBarZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f); numericUpDownZoom.Value = (int)((pDesigner.zoomLevel() - 1.0f) * 100.0f); pictureBox1.Invalidate(); } /*else if (e.KeyCode == Keys.Z) //UNDO { pQueue.undoCmd(); } else if (e.KeyCode == Keys.Y) //REDO { pQueue.redoCmd(); }*/ }
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { if (e == null) return; if (pSemaphorePropertyGrid) return; //if (treeView1.SelectedNode != null) { cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("PropertyGridChanged"); cmd.Helper = (s as PropertyGrid).SelectedObject; String label = e.ChangedItem.Label; PropertyInfo pi = ((s as PropertyGrid).SelectedObject as sAttribute).GetType().GetProperty(label); Object oldValue = e.OldValue; if (pi == null) { //FIXME: This is just a workaround label = e.ChangedItem.Parent.Label; pi = ((s as PropertyGrid).SelectedObject as sAttribute).GetType().GetProperty(label); Object gi = e.ChangedItem.Parent.Value; if (gi != null) { if (gi is e2skinner2.Structures.sAttribute.Position) { if (e.ChangedItem.Label == "X") (gi as e2skinner2.Structures.sAttribute.Position).X = (String)e.OldValue; else (gi as e2skinner2.Structures.sAttribute.Position).Y = (String)e.OldValue; oldValue = (gi as e2skinner2.Structures.sAttribute.Position); } else if (gi is System.Drawing.Size) { System.Drawing.Size size; size = (System.Drawing.Size)gi; if (e.ChangedItem.Label == "Width") size.Width = Convert.ToInt32(e.OldValue); else size.Height = Convert.ToInt32(e.OldValue); oldValue = size; } else { Console.WriteLine("Error in propertyGrid1_PropertyValueChanged #1"); } } else { Console.WriteLine("Error in propertyGrid1_PropertyValueChanged #0"); } } if (pi != null) { Object newValue = pi.GetValue(((s as PropertyGrid).SelectedObject as sAttribute), null); cmd.From = new Object[] { label, oldValue }; cmd.To = new Object[] { label, newValue }; cmd.DoEvent += new cCommandQueue.EventHandler(eventDoPropertyGrid); cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoPropertyGrid); pQueue.addCmd(cmd); } else Console.WriteLine("Error in propertyGrid1_PropertyValueChanged #2"); } }
private void pictureBox1_MouseUp(object s, MouseEventArgs e) { //System.Console.WriteLine("pictureBox1_MouseUp"); if (mouseDown) { cCommandQueue.cCommand cmd = new cCommandQueue.cCommand("MouseChange"); cmd.Helper = propertyGrid1.SelectedObject; cmd.DoEvent += new cCommandQueue.EventHandler(eventDoPropertyGrid); cmd.UndoEvent += new cCommandQueue.EventHandler(eventUndoPropertyGrid); if ((propertyGrid1.SelectedObject as sAttribute).Size != remeberAttrSizeForUndo) { cmd.From = new Object[] {"Size", remeberAttrSizeForUndo}; cmd.To = new Object[] { "Size", (propertyGrid1.SelectedObject as sAttribute).Size }; pQueue.addCmd(cmd); } else if ((propertyGrid1.SelectedObject as sAttribute).Relativ.X != remeberAttrPositionForUndo.X || (propertyGrid1.SelectedObject as sAttribute).Relativ.Y != remeberAttrPositionForUndo.Y) { cmd.From = new Object[] {"Relativ", remeberAttrPositionForUndo}; cmd.To = new Object[] { "Relativ", (propertyGrid1.SelectedObject as sAttribute).Relativ }; pQueue.addCmd(cmd); } } mouseDown = false; isResize = false; this.Cursor = Cursors.Default; }