Пример #1
0
 private void btPasteShape_Click(object sender, EventArgs e) {
     ToolStripItem contextMenuItem = (ToolStripItem)sender;
     System.Drawing.Point NewPos, Ctxtpos;
     if (contextMenuItem.Tag is System.Drawing.Point) {
         Ctxtpos = (System.Drawing.Point)contextMenuItem.Tag;  //Location is stored as point in tag
     } else {
         Ctxtpos = new System.Drawing.Point(0, 0);
     }
     System.Drawing.Size PosOffset = System.Drawing.Size.Empty;
     IDataObject Data = Clipboard.GetDataObject();
     ShapeInterface Shape = null;
     Core.CmdMacro Cmd = new Core.CmdMacro();
     String[] Formats = Data.GetFormats(false);
     // Determines whether the data is in a format you can use.
     if (Data.GetDataPresent("stream")) {
         //string test = Data.GetData(DataFormats.Text).ToString();
         SerializerXML _Stream = new SerializerXML("JKFLOW", "1.0.0.0");
         MemoryStream _MemStream = new MemoryStream((byte[])Data.GetData("stream"));
         _Stream.OpenInputStream(_MemStream);
         string NodeGroup;
         int StartNodeLevel = 0, CurrNodeLevel = 0;
         do {
             NodeGroup = _Stream.GetNodeName();
             CurrNodeLevel = _Stream.GetNodeLevel();
             if (CurrNodeLevel < StartNodeLevel) { break; }
             if (_Stream.GetNodeType() != Core.SerializerBase.NodeType.NodeEnd) {
                 if (NodeGroup == "Shape") {
                     ShapeInterface SourceShape = ShapeFactory.DeserializeShape(_Stream);
                     if (PosOffset.IsEmpty) {
                         PosOffset.Width = Ctxtpos.X - SourceShape.GetBoundingBox().Location.X;
                         PosOffset.Height = Ctxtpos.Y - SourceShape.GetBoundingBox().Location.Y;
                     }
                     NewPos = SourceShape.GetBoundingBox().Location + PosOffset;
                     Shape = ShapeFactory.CreateShape(SourceShape.GetShapeTypeName());
                     Cmd.AddCmd(new Core.CmdAddShape(GetModel(),
                         Shape, NewPos, NewPos + SourceShape.GetBoundingBox().Size));
                 }
             }
         } while (_Stream.ReadNext());
         _Stream.CloseInputStream();
         _Stream = null;
         GetModel().GetUndoStack().Push(Cmd);
     }
 }
Пример #2
0
        private void LoadFile()
        {
            string DocType = string.Empty;

            smartEdit.Core.SerializerXML _stream = null;
            try {
                _stream = new smartEdit.Core.SerializerXML("SMARTEDIT-APP", "1.0.0.0");
                _stream.OpenInputStream(GetIniFileName());
                if (_stream.GetDetectedSerializerName() != "SMARTEDIT-APP")
                {
                    throw new FormatException("");
                }
                string NodeGroup;
                do
                {
                    NodeGroup = _stream.GetNodeName();
                    if (_stream.GetNodeType() != Core.SerializerBase.NodeType.NodeEnd)
                    {
                        if (NodeGroup == "Application")
                        {
                            m_AppData.ReadFromSerializer(_stream);
                        }
                    }
                } while (_stream.ReadNext());

                _stream.CloseInputStream();
                _stream = null;
            } catch (Exception e) {
                MessageBox.Show(e.Message);
            } finally {
                if (_stream != null)
                {
                    _stream.CloseInputStream();
                }
            }
        }