Beispiel #1
0
        //


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (sym_expo_textbox.Focused)
            {
                return;
            }
            e.Handled = true;
            switch (e.KeyCode)
            {
            case Keys.Oemplus:
                vp.projection_scale *= 2;
                break;

            case Keys.OemMinus:
                vp.projection_scale /= 2;
                break;

            case Keys.Delete:     // Delete geometry or point
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)
                    {
                        if (symbol.geometry[selected_geometry_idx].points.Count() != 1)     // if only one point left - not need to delete it
                        {
                            symbol.geometry[selected_geometry_idx].removePoint(selected_point_idx);

                            selected_point_idx = -1;
                        }
                    }
                    else
                    {
                        symbol.geometry.RemoveAt(geom_explorer.SelectedIndex);
                        selected_geometry_idx = -1;
                        updateExplorerList();
                    }
                }

                break;

            case Keys.Left:

                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(-1, 0);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(-1, 0);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(-1, 0);
                }


                break;

            case Keys.Right:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(1, 0);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(1, 0);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(1, 0);
                }

                break;

            case Keys.Up:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(0, -1);
                    }
                    else
                    {     // else move whole geometry
                        symbol.geometry[selected_geometry_idx].move(0, -1);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(0, -1);
                }

                break;

            case Keys.Down:
                if (selected_geometry_idx != -1)
                {
                    if (selected_point_idx != -1)     // if point selected - move point
                    {
                        moveSelectedPoint(0, 1);
                    }
                    else       // else move whole geometry

                    {
                        symbol.geometry[selected_geometry_idx].move(0, 1);
                    }
                }

                if (_edit_mode == Edit_mode.EDIT_SYMBOL)
                {
                    symbol.move(0, 1);
                }

                break;

            // Copy
            case Keys.C:

                if (e.Control && selected_geometry_idx != -1)
                {
                    var selected_geometry = symbol.geometry[selected_geometry_idx];
                    Clipboard.Clear();

                    // Set data to clipboard

                    Clipboard.SetDataObject(selected_geometry);
                    e.SuppressKeyPress = true;
                }
                break;

            //Paste
            case Keys.V:
                if (e.Control)
                {
                    // Get data from clipboard
                    HGeometry paste_result = null;

                    IDataObject data_object = Clipboard.GetDataObject();

                    if (Clipboard.ContainsData("S52_HPGL_Editor.HLineString"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HLineString");
                    }
                    else if (Clipboard.ContainsData("S52_HPGL_Editor.HPolygon"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HPolygon");
                    }
                    if (Clipboard.ContainsData("S52_HPGL_Editor.HPoint"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HPoint");
                    }
                    else if (Clipboard.ContainsData("S52_HPGL_Editor.HCircle"))
                    {
                        paste_result = (HGeometry)Clipboard.GetData("S52_HPGL_Editor.HCircle");
                    }

                    if (paste_result != null)
                    {
                        symbol.geometry.Add(paste_result);
                        updateExplorerList();
                        geom_explorer.SelectedIndex = symbol.geometry.Count() - 1;
                        selectGeometry(symbol.geometry.Count() - 1);
                    }
                    e.SuppressKeyPress = true;
                }
                break;

            default:
                e.Handled = false;
                return;
                //break;
            }

            updatePointPosition();
            Refresh();
        }
        /// <summary>
        /// Checks if there is a project item in the clipboard
        /// </summary>
        /// <returns>True if there is a project item in the clipboard</returns>
        public bool HaveProjectItemInClipboard()
        {
            var dataFormat = DataFormats.GetDataFormat(typeof(ClipboardData).FullName);

            return(Clipboard.ContainsData(dataFormat.Name));
        }
Beispiel #3
0
        public override bool CanExecute(object parameter)
        {
            var canExecute = Clipboard.ContainsData(Globals.FormatCML) || Clipboard.ContainsData(Globals.FormatSDFile) || Clipboard.ContainsText();

            return(canExecute);
        }
Beispiel #4
0
 public static bool HasCopyData()
 {
     return(Clipboard.ContainsData(CadClipBoard.TypeNameBin));
 }
Beispiel #5
0
        // This performs the paste. Returns false when paste was cancelled.
        private static void DoPasteSelection(PasteOptions options)
        {
            // Check if possible to copy/paste
            if (General.Editing.Mode.Attributes.AllowCopyPaste)
            {
                bool havepastedata    = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT);              //mxd
                bool havedb2pastedata = Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT_DB2);          //mxd

                // Anything to paste?
                if (havepastedata || havedb2pastedata)
                {
                    // Cancel volatile mode
                    General.Editing.DisengageVolatileMode();

                    // Let the plugins know
                    if (General.Plugins.OnPasteBegin(options))
                    {
                        // Ask the editing mode to prepare selection for pasting.
                        if (General.Editing.Mode.OnPasteBegin(options.Copy()))
                        {
                            // Create undo
                            General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements.");
                            General.Map.UndoRedo.CreateUndo("Paste");

                            // Mark all current geometry
                            General.Map.Map.ClearAllMarks(true);

                            // Read from clipboard
                            if (havepastedata)
                            {
                                using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT))
                                {
                                    // Rewind before use
                                    memstream.Seek(0, SeekOrigin.Begin);

                                    // Read data stream
                                    ClipboardStreamReader reader = new ClipboardStreamReader();                                     //mxd
                                    General.Map.Map.BeginAddRemove();
                                    bool success = reader.Read(General.Map.Map, memstream);
                                    General.Map.Map.EndAddRemove();
                                    if (!success)                                    //mxd
                                    {
                                        General.Map.UndoRedo.WithdrawUndo();         // This will also mess with the marks...
                                        General.Map.Map.ClearAllMarks(true);         // So re-mark all current geometry...
                                    }
                                }
                            }
                            // mxd. DB2/DB64 interop
                            else if (havedb2pastedata)
                            {
                                using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT_DB2))
                                {
                                    // Read data stream
                                    UniversalStreamReader reader = new UniversalStreamReader(new Dictionary <MapElementType, Dictionary <string, UniversalType> >());
                                    reader.StrictChecking = false;
                                    General.Map.Map.BeginAddRemove();
                                    reader.Read(General.Map.Map, memstream);
                                    General.Map.Map.EndAddRemove();
                                }
                            }
                            else
                            {
                                throw new NotImplementedException("Unknown clipboard data format!");
                            }

                            // The new geometry is not marked, so invert the marks to get it marked
                            General.Map.Map.InvertAllMarks();

                            // Check if anything was pasted
                            List <Thing> things      = General.Map.Map.GetMarkedThings(true);                       //mxd
                            int          totalpasted = things.Count;
                            totalpasted += General.Map.Map.GetMarkedVertices(true).Count;
                            totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count;
                            totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count;
                            totalpasted += General.Map.Map.GetMarkedSectors(true).Count;

                            if (totalpasted > 0)
                            {
                                // Convert UDMF fields back to flags and activations, if needed
                                if (!(General.Map.FormatInterface is UniversalMapSetIO))
                                {
                                    General.Map.Map.TranslateFromUDMF();
                                }

                                // Modify tags and actions if preferred
                                if (options.ChangeTags == PasteOptions.TAGS_REMOVE)
                                {
                                    Tools.RemoveMarkedTags();
                                }
                                if (options.ChangeTags == PasteOptions.TAGS_RENUMBER)
                                {
                                    Tools.RenumberMarkedTags();
                                }
                                if (options.RemoveActions)
                                {
                                    Tools.RemoveMarkedActions();
                                }

                                foreach (Thing t in things)
                                {
                                    t.UpdateConfiguration();                                                        //mxd
                                }
                                General.Map.ThingsFilter.Update();
                                General.Editing.Mode.OnPasteEnd(options.Copy());
                                General.Plugins.OnPasteEnd(options);
                            }
                        }
                    }
                }
                else
                {
                    // Nothing useful on the clipboard
                    // [ZZ] don't beep if 3D mode is currently engaged. the 3D mode allows you to copy/paste non-geometry stuff.
                    //      note that this is a hack and probably needs to be fixed properly by making it beep elsewhere so that the current active mode can decide this.
                    if (!(General.Editing.Mode is VisualMode))
                    {
                        General.MessageBeep(MessageBeepType.Warning);
                    }
                }
            }
            else
            {
                // Paste not allowed
                General.MessageBeep(MessageBeepType.Warning);
            }
        }
Beispiel #6
0
 private void Paste_CanExecute(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = Clipboard.ContainsData(DataFormats.StringFormat);
 }
        private void MyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (Clipboard.ContainsData(DataFormats.Text))
            {
                try
                {
                    // get all text
                    string data = Clipboard.GetText();
                    // split to lines
                    string[] array = data.Split('\n');
                    // First line is nomer norma
                    WorkContext.Work.Number = array[0];

                    // Second line is Name of process
                    WorkContext.Work.Name = array[1];
                    // Third line is measure of process without "Измеритель"
                    WorkContext.Work.Measure = array[2].Replace("Измеритель", "");
                    // 4, 5, 6, 7, 8, 9, 10 are useless's lines

                    List <PriborContext> priborContexts = new List <PriborContext>();

                    using (var db = new SmetaApplication.DbContexts.SmetaDbAppContext())
                    {
                        foreach (var item in db.Pribors)
                        {
                            priborContexts.Add(new PriborContext(item));
                        }

                        int  i          = 9;
                        bool IsMaterial = true;
                        for (; IsMaterial && i < array.Length; i++)
                        {
                            int      code;
                            string[] split = array[i].Split('\t');
                            // first column is code of pribor, if it isn't pribor, then set IsMaterial = false
                            //MessageBox.Show(array[i]);
                            if (int.TryParse(split[0], out code))
                            {
                                PriborContext priborContext = priborContexts.Find(x => int.Parse(x.Pribor.Code) == code);

                                if (priborContext == null)
                                {
                                    throw new NullReferenceException("Прибор нет: " + split[0] + " : " + split[1]);
                                }

                                priborContext.PriborGroup.Count = 1;
                                WorkContext.PriborContexts.Add(priborContext);

                                // 2 column is name of pribor
                                // 3 column is measure of pribor
                                // begin from 4
                                if (i == 9)
                                {
                                    double time;
                                    bool   IsBegin = true;
                                    if (double.TryParse(split[3].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time1 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[4].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time2 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[5].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time3 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[6].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time4 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[7].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time5 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }
                                }
                            }
                            else
                            {
                                IsMaterial = false;
                            }
                        }

                        List <MaterialContext> materialContexts = new List <MaterialContext>();
                        foreach (var item in db.Materials)
                        {
                            materialContexts.Add(new MaterialContext(item));
                        }

                        // Materials
                        for (; i < array.Length; i++)
                        {
                            int      code;
                            string[] split = array[i].Split('\t');
                            // first column is code of material, if it isn't material, then for does'nt work
                            //MessageBox.Show(array[i]);
                            if (int.TryParse(split[0], out code))
                            {
                                MaterialContext materialContext = materialContexts.Find(x => int.Parse(x.Material.Code) == code);
                                WorkContext.MaterailContexts.Add(materialContext);

                                if (materialContext == null)
                                {
                                    throw new NullReferenceException("Материал нет: " + split[0] + " : " + split[1]);
                                }

                                // 2 column is name of material
                                // 3 column is measure of material
                                // begin from 4

                                double time;
                                bool   IsBegin = true;
                                //MessageBox.Show(split[3]);
                                if (double.TryParse(split[3].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count1 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[4].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count2 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[5].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count3 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[6].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count4 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[7].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count5 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }
                            }
                        }
                    }
                    //WorkContext.Work.PriceMaterial = WorkContext.MaterailContexts.Sum(x => x.Material.Price * x.MaterialGroup.Count1);
                    //WorkContext.Work.PricePribor = WorkContext.PriborContexts.Sum(x => x.Pribor.Price * x.PriborGroup.Count);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Ошибка формата: " + exc.ToString());
                }
            }
            else
            {
                MessageBox.Show("Ошибка формата");
            }
        }
        //-----------------------------------------------------------------------
        public override void Paste()
        {
            if (Clipboard.ContainsData(CopyKey))
            {
                var flat = Clipboard.GetData(CopyKey) as string;
                var root = XElement.Parse(flat);

                var sdef = Definition as ComplexDataDefinition;

                var             prevChildren = Children.ToList();
                List <DataItem> newChildren  = null;

                List <DataItem> oldAtts = null;
                List <DataItem> newAtts = null;

                using (UndoRedo.DisableUndoScope())
                {
                    var item = sdef.LoadData(root, UndoRedo);

                    if (item.Children.Count == 0 && item.Attributes.Count == 0)
                    {
                        item = sdef.CreateData(UndoRedo);
                    }

                    newChildren = item.Children.ToList();

                    if (item is ComplexDataItem)
                    {
                        oldAtts = (this as ComplexDataItem).Attributes.ToList();
                        newAtts = (item as ComplexDataItem).Attributes.ToList();
                    }
                }

                UndoRedo.ApplyDoUndo(
                    delegate
                {
                    Children.Clear();
                    foreach (var child in newChildren)
                    {
                        Children.Add(child);
                    }

                    if (this is ComplexDataItem)
                    {
                        var si = this as ComplexDataItem;
                        Attributes.Clear();
                        foreach (var att in newAtts)
                        {
                            Attributes.Add(att);
                        }
                    }

                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    delegate
                {
                    Children.Clear();
                    foreach (var child in prevChildren)
                    {
                        Children.Add(child);
                    }

                    if (this is ComplexDataItem)
                    {
                        var si = this as ComplexDataItem;
                        Attributes.Clear();
                        foreach (var att in oldAtts)
                        {
                            Attributes.Add(att);
                        }
                    }

                    RaisePropertyChangedEvent("HasContent");
                    RaisePropertyChangedEvent("Description");
                },
                    Name + " pasted");
            }
        }
Beispiel #9
0
 public void Clipboard_SetData_Invoke_GetReturnsExpected(string format, object data)
 {
     Clipboard.SetData(format, data);
     Assert.Equal(data, Clipboard.GetData(format));
     Assert.True(Clipboard.ContainsData(format));
 }
Beispiel #10
0
        protected override void OnKeyDown(KeyEventArgs e) //Tool hotkeys
        {
            Tool.KeyDown(e);
            ShiftDown = e.Shift;
            //CtrlDown = e.Control;
            AltDown     = e.Alt;
            SwitchBlock = e.Alt;
            if (e.KeyCode == Keys.Q)
            {
                ChangeBlock = true;
            }
            if (e.Control && e.KeyCode == Keys.V)
            {
                if (!MainForm.selectionTool)
                {
                    MainForm.SetMarkTool();
                }
                string[][,] data = (string[][, ])Clipboard.GetData("EEData");
                if (data?.Length == 9)
                {
                    Tool.CleanUp(false);
                    SetMarkBlock(data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8]);
                }
            }
            if ((int)Keys.D0 <= (int)e.KeyCode && (int)e.KeyCode <= (int)Keys.D9)
            {
                MainForm.SetActiveBrick((int)e.KeyCode - (int)Keys.D0);
            }

            if (!e.Control)
            {
                if (e.KeyCode == Keys.F1)
                {
                    MainForm.SetTool(13); // About window
                }
                if (e.KeyCode == Keys.F2) //debug mode
                {
                    if (MainForm.debug)
                    {
                        MainForm.debug = false;
                        MainForm.Text  = "EEditor " + MainForm.ProductVersion;
                        MainForm.rebuildGUI(false);
                    }
                    else
                    {
                        MainForm.Text  = "EEditor " + MainForm.ProductVersion + " - Using Debug";
                        MainForm.debug = true;
                        MainForm.rebuildGUI(false);
                    }
                }
                if (e.KeyCode == Keys.F5)
                {
                    MainForm.SetTool(7);                       // Reload level
                }
                if (e.KeyCode == Keys.F6)
                {
                    MainForm.SetTool(6);                       // LevelTextbox
                }
                if (e.KeyCode == Keys.F7)
                {
                    MainForm.SetTool(8);                       // CodeTextbox
                }
                if (e.KeyCode == Keys.Z && e.KeyCode != Keys.Control)
                {
                    MainForm.SetPenTool();
                }
                if (e.KeyCode == Keys.X)
                {
                    MainForm.SetFillTool();
                }
                if (e.KeyCode == Keys.C)
                {
                    MainForm.SetSprayTool();
                }
                if (e.KeyCode == Keys.V)
                {
                    MainForm.SetMarkTool();
                }

                if (e.KeyCode == Keys.I)
                {
                    MainForm.SetTool(17);                      // Rotate selection left
                }
                if (e.KeyCode == Keys.K)
                {
                    MainForm.SetTool(18);                      // Rotate selection right
                }
                if (e.KeyCode == Keys.J)
                {
                    MainForm.SetTool(19);                      // Rotate selection left
                }
                if (e.KeyCode == Keys.L)
                {
                    MainForm.SetTool(20);                      // Rotate selection right
                }
                if (e.KeyCode == Keys.N)
                {
                    MainForm.SetTool(10);                      //Hide blocks
                }
                if (e.KeyCode == Keys.M && e.KeyCode != Keys.Control)
                {
                    MainForm.SetTool(11);                                                   // Minimap
                }
                if (e.KeyCode == Keys.Oemcomma)
                {
                    MainForm.SetRectTool();
                }
                if (e.KeyCode == Keys.OemPeriod)
                {
                    MainForm.SetCircleTool();
                }
                if (e.KeyCode == Keys.OemMinus)
                {
                    MainForm.SetLineTool();
                }
                if (e.KeyCode == Keys.Pause)
                {
                    if (ToolFill.filling)
                    {
                        if (!ToolFill.stopfill)
                        {
                            ToolFill.stopfill = true;
                        }
                    }
                }
                if (e.KeyCode == Keys.Insert)
                {
                    random rnd = new random();
                    rnd.ShowDialog();
                }
                // OemMinus is wrong, actually this should be used but idk how: https://social.msdn.microsoft.com/Forums/silverlight/en-US/aab11ce4-bdb8-4776-80fb-1f7491f73a46/platform-neutral-key-code-for-dash?forum=silverlightnet
            }
            else
            {
                if (e.Control && e.KeyCode == Keys.N)
                {
                    MainForm.SetTool(0);                                   // New
                }
                if (e.Control && e.KeyCode == Keys.O)
                {
                    MainForm.SetTool(1);                                   // Open
                }
                if (e.Control && e.KeyCode == Keys.S)
                {
                    MainForm.SetTool(2);                                   // Save
                }
                if (e.Control && e.KeyCode == Keys.Z)
                {
                    MainForm.SetTool(14);                                   // Undo
                }
                if (e.Control && e.KeyCode == Keys.Y)
                {
                    MainForm.SetTool(15);                                   // Redo
                }
                if (e.Control && e.Shift && e.KeyCode == Keys.H)
                {
                    MainForm.SetTool(16);                                              // History
                }
                if (e.Control && e.KeyCode == Keys.Oemcomma)
                {
                    MainForm.SetFilledRectTool();
                }
                //if (e.Control && e.KeyCode == Keys.OemPeriod) MainForm.SetFilledCircleTool();

                if (e.Control && e.KeyCode == Keys.I)
                {
                    MainForm.SetTool(3);                                   // Insert image
                }
                if (e.Control && e.KeyCode == Keys.T)
                {
                    MainForm.SetTool(4);                                   // Insert text
                }
                if (e.Control && e.KeyCode == Keys.P)
                {
                    MainForm.SetColorPicker();                                   // Find a block by color
                }
                if (e.Control && e.KeyCode == Keys.F)
                {
                    MainForm.SetTool(5);                                   // Find&replace
                }
                if (e.Control && e.KeyCode == Keys.H)
                {
                    MainForm.SetTool(5);                                   // Find&replace
                }
                if (e.Control && e.KeyCode == Keys.U)
                {
                    MainForm.SetTool(9);                                   // Upload level
                }
                if (e.Control && e.KeyCode == Keys.Tab)
                {
                    MainForm.SetView();                                     // Next block tab
                }

                /*if (e.Control && e.KeyCode == Keys.Add || e.KeyCode == Keys.Oemplus)
                 * {
                 *  if (MainForm.Zoom < 32)
                 *  {
                 *      MainForm.Zoom += 4;
                 *  }
                 *  zoomRefresh();
                 * }
                 * if (e.Control && e.KeyCode == Keys.Subtract || e.KeyCode == Keys.OemMinus)
                 * {
                 *  if (MainForm.Zoom > 4)
                 *  {
                 *      MainForm.Zoom -= 4;
                 *      zoomRefresh();
                 *  }
                 * }
                 * if (e.Control && e.KeyCode == Keys.D0)
                 * {
                 *  MainForm.Zoom = 16;
                 *  zoomRefresh();
                 * }*/
                if (e.Control && e.KeyCode == Keys.F5)
                {
                    MainForm.rebuildGUI(false); // Rebuild GUI
                    if (Clipboard.ContainsData("EEBrush"))
                    {
                        Clipboard.Clear();
                    }
                }
                else
                {
                    CtrlDown = e.Control;
                }
            }
        }
 public bool ContainsData(string format)
 => Clipboard.ContainsData(format);
Beispiel #12
0
        string get_element_html()
        {
            List <string> lines = new List <string>();

            lines.Add("<HTML>");
            lines.AddRange(HTML.GetHead("Plot Point", "Plot Point", Session.Preferences.TextSize));
            lines.Add("<BODY>");

            lines.Add("<P>");
            lines.Add("This plot point does not contain a game element (such as an encounter or a skill challenge).");
            lines.Add("The list of available game elements is below.");
            lines.Add("You can add a game element to this plot point by clicking on one of the links.");
            lines.Add("</P>");

            lines.Add("<P class=table>");
            lines.Add("<TABLE>");

            lines.Add("<TR class=heading>");
            lines.Add("<TD><B>Select a Game Element</B></TD>");
            lines.Add("</TR>");

            lines.Add("<TR>");
            lines.Add("<TD>Add a <A href=\"element:encounter\">combat encounter</A></TD>");
            lines.Add("</TR>");

            lines.Add("<TR>");
            lines.Add("<TD>Add a <A href=\"element:challenge\">skill challenge</A></TD>");
            lines.Add("</TR>");

            lines.Add("<TR>");
            lines.Add("<TD>Add a <A href=\"element:trap\">trap or hazard</A></TD>");
            lines.Add("</TR>");

            lines.Add("<TR>");
            lines.Add("<TD>Add a <A href=\"element:quest\">quest</A></TD>");
            lines.Add("</TR>");

            lines.Add("<TR>");
            lines.Add("<TD>Add a <A href=\"element:map\">tactical map</A></TD>");
            lines.Add("</TR>");

            if (Clipboard.ContainsData(typeof(Encounter).ToString()))
            {
                lines.Add("<TR>");
                lines.Add("<TD><A href=\"element:pasteencounter\">Paste the encounter from the clipboard</A></TD>");
                lines.Add("</TR>");
            }

            if (Clipboard.ContainsData(typeof(SkillChallenge).ToString()))
            {
                lines.Add("<TR>");
                lines.Add("<TD><A href=\"element:pastechallenge\">Paste the skill challenge from the clipboard</A></TD>");
                lines.Add("</TR>");
            }

            if (Clipboard.ContainsData(typeof(TrapElement).ToString()))
            {
                lines.Add("<TR>");
                lines.Add("<TD><A href=\"element:pastetrap\">Paste the trap from the clipboard</A></TD>");
                lines.Add("</TR>");
            }

            if (Clipboard.ContainsData(typeof(Quest).ToString()))
            {
                lines.Add("<TR>");
                lines.Add("<TD><A href=\"element:pastequest\">Paste the quest from the clipboard</A></TD>");
                lines.Add("</TR>");
            }

            if (Clipboard.ContainsData(typeof(MapElement).ToString()))
            {
                lines.Add("<TR>");
                lines.Add("<TD><A href=\"element:pastemap\">Paste the map from the clipboard</A></TD>");
                lines.Add("</TR>");
            }

            lines.Add("</TABLE>");
            lines.Add("</P>");

            lines.Add("</BODY>");
            lines.Add("</HTML>");

            return(HTML.Concatenate(lines));
        }
Beispiel #13
0
        //-----------------------------------------------------------------------
        protected override void AddContextMenuItems(ContextMenu menu)
        {
            MenuItem addNewItem = new MenuItem();

            addNewItem.Header = "Add New";

            addNewItem.Click += delegate
            {
                AddNew();
            };

            menu.Items.Add(addNewItem);

            MenuItem DuplicateItem = new MenuItem();

            DuplicateItem.Header = "Duplicate";

            DuplicateItem.Click += delegate
            {
                Duplicate();
            };

            menu.Items.Add(DuplicateItem);

            MenuItem CopyItem = new MenuItem();

            CopyItem.Header = "Copy";

            CopyItem.Click += delegate
            {
                Copy();
            };

            menu.Items.Add(CopyItem);

            if (WrappedItem is ReferenceItem)
            {
                var ri = WrappedItem as ReferenceItem;

                MenuItem pasteItem = new MenuItem();
                pasteItem.Header    = "Paste";
                pasteItem.Click    += (e, args) => { Paste(); };
                pasteItem.IsEnabled = ri.ReferenceDef.Definitions.Any(e => Clipboard.ContainsData(e.Value.CopyKey));

                menu.Items.Add(pasteItem);

                if ((ri.Definition as ReferenceDefinition).Definitions.Count > 1)
                {
                    menu.Items.Add(new Separator());

                    MenuItem swapItem = new MenuItem();
                    swapItem.Header = "Swap";
                    menu.Items.Add(swapItem);

                    foreach (var def in (ri.Definition as ReferenceDefinition).Definitions.Values)
                    {
                        if (def != ri.ChosenDefinition)
                        {
                            MenuItem doSwapItem = new MenuItem();
                            doSwapItem.Header           = def.Name;
                            doSwapItem.Command          = ri.SwapCMD;
                            doSwapItem.CommandParameter = def;

                            swapItem.Items.Add(doSwapItem);
                        }
                    }
                }
            }
            else if (WrappedItem is GraphReferenceItem)
            {
                var ri = WrappedItem as GraphReferenceItem;

                MenuItem pasteItem = new MenuItem();
                pasteItem.Header    = "Paste";
                pasteItem.Click    += (e, args) => { Paste(); };
                pasteItem.IsEnabled = ri.ReferenceDef.Definitions.Any(e => Clipboard.ContainsData(e.Value.CopyKey));

                menu.Items.Add(pasteItem);
            }
            else
            {
                MenuItem pasteItem = new MenuItem();
                pasteItem.Header  = "Paste";
                pasteItem.Command = PasteCMD;

                menu.Items.Add(pasteItem);
            }

            if (WrappedItem is CollectionItem)
            {
                var ci = WrappedItem as CollectionItem;

                if (ci.Children.Count > 1)
                {
                    menu.AddSeperator();

                    menu.AddItem("Multiedit Children", () =>
                    {
                        var otherChildren = new List <DataItem>();
                        for (int i = 1; i < Children.Count; i++)
                        {
                            otherChildren.Add(Children[i]);
                        }

                        Children[0].MultiEdit(otherChildren, otherChildren.Count);

                        DataModel.Selected = new List <DataItem>()
                        {
                            Children[0]
                        };
                    });
                }
            }
        }
        // This performs the paste. Returns false when paste was cancelled.
        private static void DoPasteSelection(PasteOptions options)
        {
            // Check if possible to copy/paste
            if (General.Editing.Mode.Attributes.AllowCopyPaste)
            {
                // Anything to paste?
                if (Clipboard.ContainsData(CLIPBOARD_DATA_FORMAT))
                {
                    // Cancel volatile mode
                    General.Editing.DisengageVolatileMode();

                    // Let the plugins know
                    if (General.Plugins.OnPasteBegin(options))
                    {
                        // Ask the editing mode to prepare selection for pasting.
                        if (General.Editing.Mode.OnPasteBegin(options.Copy()))
                        {
                            // Create undo
                            General.MainWindow.DisplayStatus(StatusType.Action, "Pasted selected elements.");
                            General.Map.UndoRedo.CreateUndo("Paste");

                            // Mark all current geometry
                            General.Map.Map.ClearAllMarks(true);

                            // Read from clipboard
                            using (Stream memstream = (Stream)Clipboard.GetData(CLIPBOARD_DATA_FORMAT))
                            {
                                // Rewind before use
                                memstream.Seek(0, SeekOrigin.Begin);

                                // Read data stream
                                ClipboardStreamReader reader = new ClipboardStreamReader();                                 //mxd
                                General.Map.Map.BeginAddRemove();
                                bool success = reader.Read(General.Map.Map, memstream);
                                General.Map.Map.EndAddRemove();
                                if (!success)                                //mxd
                                {
                                    General.Map.UndoRedo.WithdrawUndo();     // This will also mess with the marks...
                                    General.Map.Map.ClearAllMarks(true);     // So re-mark all current geometry...
                                }
                            }

                            // The new geometry is not marked, so invert the marks to get it marked
                            General.Map.Map.InvertAllMarks();

                            // Check if anything was pasted
                            List <Thing> things      = General.Map.Map.GetMarkedThings(true);                       //mxd
                            int          totalpasted = things.Count;
                            totalpasted += General.Map.Map.GetMarkedVertices(true).Count;
                            totalpasted += General.Map.Map.GetMarkedLinedefs(true).Count;
                            totalpasted += General.Map.Map.GetMarkedSidedefs(true).Count;
                            totalpasted += General.Map.Map.GetMarkedSectors(true).Count;

                            if (totalpasted > 0)
                            {
                                // Convert UDMF fields back to flags and activations, if needed
                                if (!(General.Map.FormatInterface is UniversalMapSetIO))
                                {
                                    General.Map.Map.TranslateFromUDMF();
                                }

                                // Modify tags and actions if preferred
                                if (options.ChangeTags == PasteOptions.TAGS_REMOVE)
                                {
                                    Tools.RemoveMarkedTags();
                                }
                                if (options.ChangeTags == PasteOptions.TAGS_RENUMBER)
                                {
                                    Tools.RenumberMarkedTags();
                                }
                                if (options.RemoveActions)
                                {
                                    Tools.RemoveMarkedActions();
                                }

                                foreach (Thing t in things)
                                {
                                    t.UpdateConfiguration();                                                        //mxd
                                }
                                General.Map.ThingsFilter.Update();
                                General.Editing.Mode.OnPasteEnd(options.Copy());
                                General.Plugins.OnPasteEnd(options);
                            }
                        }
                    }
                }
                else
                {
                    // Nothing usefull on the clipboard
                    General.MessageBeep(MessageBeepType.Warning);
                }
            }
            else
            {
                // Paste not allowed
                General.MessageBeep(MessageBeepType.Warning);
            }
        }
        protected void OnPaste(object target, ExecutedRoutedEventArgs args)
        {
            if (target != textEditor.textArea)
            {
                return;
            }
            TextArea textArea = textEditor.textArea;

            if (textArea != null && textArea.Document != null)
            {
                Debug.WriteLine(Clipboard.GetText(TextDataFormat.Html));

                // convert text back to correct newlines for this document
                string   newLine    = TextUtilities.GetNewLineFromDocument(textArea.Document, textArea.Caret.Line);
                string   text       = TextUtilities.NormalizeNewLines(Clipboard.GetText(), newLine);
                string[] commands   = text.Split(new String[] { newLine }, StringSplitOptions.None);
                string   scriptText = "";
                if (commands.Length > 1)
                {
                    text = newLine;
                    foreach (string command in commands)
                    {
                        text       += "... " + command + newLine;
                        scriptText += command.Replace("\t", "   ") + newLine;
                    }
                }

                if (!string.IsNullOrEmpty(text))
                {
                    bool fullLine    = textArea.Options.CutCopyWholeLine && Clipboard.ContainsData(LineSelectedType);
                    bool rectangular = Clipboard.ContainsData(RectangleSelection.RectangularSelectionDataType);
                    if (fullLine)
                    {
                        DocumentLine currentLine = textArea.Document.GetLineByNumber(textArea.Caret.Line);
                        if (textArea.ReadOnlySectionProvider.CanInsert(currentLine.Offset))
                        {
                            textArea.Document.Insert(currentLine.Offset, text);
                        }
                    }
                    else if (rectangular && textArea.Selection.IsEmpty)
                    {
                        if (!RectangleSelection.PerformRectangularPaste(textArea, textArea.Caret.Position, text, false))
                        {
                            textEditor.Write(text, false);
                        }
                    }
                    else
                    {
                        textEditor.Write(text, false);
                    }
                }
                textArea.Caret.BringCaretToView();
                args.Handled = true;

                if (commands.Length > 1)
                {
                    lock (this.scriptText)
                    {
                        this.scriptText = scriptText;
                    }
                    dispatcherWindow.Dispatcher.BeginInvoke(new Action(delegate() { ExecuteStatements(); }));
                }
            }
        }
Beispiel #16
0
 public void Clipboard_SetDataObject_InvokeObjectNotIComDataObject_GetReturnsExpected(object data)
 {
     Clipboard.SetDataObject(data);
     Assert.Equal(data, Clipboard.GetDataObject().GetData(data.GetType()));
     Assert.True(Clipboard.ContainsData(data.GetType().FullName));
 }
Beispiel #17
0
 private void CommandBinding_CanExecuteIfClipboard(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = Clipboard.ContainsData(CLIPBOARD_BLOCKS_FORMAT);
 }
Beispiel #18
0
 public void Clipboard_SetDataObject_InvokeObjectBoolIntIntNotIComDataObject_GetReturnsExpected(object data, bool copy, int retryTimes, int retryDelay)
 {
     Clipboard.SetDataObject(data, copy, retryTimes, retryDelay);
     Assert.Equal(data, Clipboard.GetDataObject().GetData(data.GetType()));
     Assert.True(Clipboard.ContainsData(data.GetType().FullName));
 }
Beispiel #19
0
        private int ExecWorker(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // preprocessing
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                switch ((VSConstants.VSStd97CmdID)nCmdID)
                {
                case VSConstants.VSStd97CmdID.Paste:
                    if (Clipboard.ContainsData("VisualStudioEditorOperationsLineCutCopyClipboardTag"))
                    {
                        // Copying a full line, so we won't strip prompts.
                        // Deferring to VS paste also inserts the entire
                        // line rather than breaking up the current one.
                        break;
                    }
                    string updated = RemoveReplPrompts(_pyService, Clipboard.GetText(), _textView.Options.GetNewLineCharacter());
                    if (updated != null)
                    {
                        _editorOps.ReplaceSelection(updated);
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd97CmdID.GotoDefn: GotoDefinition(); return(VSConstants.S_OK);

                case VSConstants.VSStd97CmdID.FindReferences: FindAllReferences(); return(VSConstants.S_OK);
                }
            }
            else if (pguidCmdGroup == CommonConstants.Std2KCmdGroupGuid)
            {
                SnapshotPoint?pyPoint;
                OutliningTaggerProvider.OutliningTagger tagger;
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.RETURN:
                    pyPoint = _textView.GetPythonCaret();
                    if (pyPoint != null)
                    {
                        // https://github.com/Microsoft/PTVS/issues/241
                        // If the current line is a full line comment and we
                        // are splitting the text, automatically insert the
                        // comment marker on the new line.
                        var line     = pyPoint.Value.GetContainingLine();
                        var lineText = pyPoint.Value.Snapshot.GetText(line.Start, pyPoint.Value - line.Start);
                        int comment  = lineText.IndexOf('#');
                        if (comment >= 0 &&
                            pyPoint.Value < line.End &&
                            line.Start + comment < pyPoint.Value &&
                            string.IsNullOrWhiteSpace(lineText.Remove(comment))
                            )
                        {
                            int extra = lineText.Skip(comment + 1).TakeWhile(char.IsWhiteSpace).Count() + 1;
                            using (var edit = line.Snapshot.TextBuffer.CreateEdit()) {
                                edit.Insert(
                                    pyPoint.Value.Position,
                                    _textView.Options.GetNewLineCharacter() + lineText.Substring(0, comment + extra)
                                    );
                                edit.Apply();
                            }

                            return(VSConstants.S_OK);
                        }
                    }
                    break;

                case VSConstants.VSStd2KCmdID.FORMATDOCUMENT:
                    pyPoint = _textView.GetPythonCaret();
                    if (pyPoint != null)
                    {
                        FormatCode(new SnapshotSpan(pyPoint.Value.Snapshot, 0, pyPoint.Value.Snapshot.Length), false);
                    }
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.FORMATSELECTION:
                    foreach (var span in _textView.BufferGraph.MapDownToFirstMatch(
                                 _textView.Selection.StreamSelectionSpan.SnapshotSpan,
                                 SpanTrackingMode.EdgeInclusive,
                                 EditorExtensions.IsPythonContent
                                 ))
                    {
                        FormatCode(span, true);
                    }
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST:
                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    var controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        IntellisenseController.ForceCompletions = true;
                        try {
                            controller.TriggerCompletionSession(
                                (VSConstants.VSStd2KCmdID)nCmdID == VSConstants.VSStd2KCmdID.COMPLETEWORD,
                                true
                                );
                        } finally {
                            IntellisenseController.ForceCompletions = false;
                        }
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.QUICKINFO:
                    controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        controller.TriggerQuickInfo();
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.PARAMINFO:
                    controller = _textView.Properties.GetProperty <IntellisenseController>(typeof(IntellisenseController));
                    if (controller != null)
                    {
                        controller.TriggerSignatureHelp();
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL:
                    tagger = _textView.GetOutliningTagger();
                    if (tagger != null)
                    {
                        tagger.Disable();
                    }
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING:
                    tagger = _textView.GetOutliningTagger();
                    if (tagger != null)
                    {
                        tagger.Enable();
                    }
                    // let VS get the event as well
                    break;

                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                    if (_textView.CommentOrUncommentBlock(comment: true))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                    if (_textView.CommentOrUncommentBlock(comment: false))
                    {
                        return(VSConstants.S_OK);
                    }
                    break;

                case VSConstants.VSStd2KCmdID.EXTRACTMETHOD:
                    ExtractMethod();
                    return(VSConstants.S_OK);

                case VSConstants.VSStd2KCmdID.RENAME:
                    RefactorRename();
                    return(VSConstants.S_OK);
                }
            }
            else if (pguidCmdGroup == GuidList.guidPythonToolsCmdSet)
            {
                switch (nCmdID)
                {
                case PkgCmdIDList.cmdidRefactorRenameIntegratedShell:
                    RefactorRename();
                    return(VSConstants.S_OK);

                case PkgCmdIDList.cmdidExtractMethodIntegratedShell:
                    ExtractMethod();
                    return(VSConstants.S_OK);
                }
            }

            return(_next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Beispiel #20
0
 private void ClipboardEvents_ClipboardChanged(object sender, EventArgs e)
 {
     butPaste.Enabled = _editor.Mode != EditorMode.Map2D && Clipboard.ContainsData(typeof(ObjectClipboardData).FullName);
 }
        public SelectedGeometryContextMenu(Editor editor, IWin32Window owner, Room targetRoom, RectangleInt2 targetArea, VectorInt2 targetBlock)
            : base(editor, owner)
        {
            Items.Add(new ToolStripMenuItem("Paste object", Properties.Resources.general_clipboard_16, (o, e) =>
            {
                EditorActions.PasteObject(targetBlock, targetRoom);
            })
            {
                Enabled = Clipboard.ContainsData(typeof(ObjectClipboardData).FullName)
            });
            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Move Lara", null, (o, e) =>
            {
                EditorActions.MoveLara(this, targetRoom, targetBlock);
            }));
            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Add trigger", null, (o, e) =>
            {
                EditorActions.AddTrigger(targetRoom, targetArea, this);
            }));

            Items.Add(new ToolStripMenuItem("Add portal", null, (o, e) =>
            {
                EditorActions.AddPortal(targetRoom, targetArea, this);
            }));
            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Add camera", Properties.Resources.objects_Camera_16, (o, e) =>
            {
                EditorActions.PlaceObject(targetRoom, targetBlock, new CameraInstance());
            }));

            Items.Add(new ToolStripMenuItem("Add fly-by camera", Properties.Resources.objects_movie_projector_16, (o, e) =>
            {
                EditorActions.PlaceObject(targetRoom, targetBlock, new FlybyCameraInstance(editor.SelectedObject));
            }));

            Items.Add(new ToolStripMenuItem("Add sink", Properties.Resources.objects_tornado_16, (o, e) =>
            {
                EditorActions.PlaceObject(targetRoom, targetBlock, new SinkInstance());
            }));

            Items.Add(new ToolStripMenuItem("Add sound source", Properties.Resources.objects_speaker_16, (o, e) =>
            {
                EditorActions.PlaceObject(targetRoom, targetBlock, new SoundSourceInstance());
            }));

            Items.Add(new ToolStripMenuItem("Add imported geometry", Properties.Resources.objects_custom_geometry, (o, e) =>
            {
                EditorActions.PlaceObject(targetRoom, targetBlock, new ImportedGeometryInstance());
            }));

            Items.Add(new ToolStripSeparator());

            Items.Add(new ToolStripMenuItem("Crop room", Properties.Resources.general_crop_16, (o, e) =>
            {
                EditorActions.CropRoom(targetRoom, targetArea, this);
            }));

            Items.Add(new ToolStripMenuItem("Split room", Properties.Resources.actions_Split_16, (o, e) =>
            {
                EditorActions.SplitRoom(this);
            }));
        }
        public void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ControlKey)
            {
                this.EmitInvalidate();
            }

            if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Right)
            {
                this.ShowDropDown();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Down && e.Control)
            {
                this.ShowDropDown();
                //int index = this.dropdownItems.IndexOf(this.selectedObject);
                //this.selectedObject = this.dropdownItems[(index + 1) % this.dropdownItems.Count];
                //this.EmitEdited();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Up && e.Control)
            {
                this.ShowDropDown();
                //int index = this.dropdownItems.IndexOf(this.selectedObject);
                //this.selectedObject = this.dropdownItems[(index + this.dropdownItems.Count - 1) % this.dropdownItems.Count];
                //this.EmitEdited();
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.C)
            {
                if (this.selectedObject != null)
                {
                    DataObject data = new DataObject();
                    data.SetText(this.selectedObjStr);
                    data.SetData(ClipboardDataFormat, this.selectedObject);
                    Clipboard.SetDataObject(data);
                }
                else
                {
                    Clipboard.Clear();
                }
                e.Handled = true;
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                bool success = false;
                if (Clipboard.ContainsData(ClipboardDataFormat) || Clipboard.ContainsText())
                {
                    object pasteObjProxy = null;
                    if (Clipboard.ContainsData(ClipboardDataFormat))
                    {
                        object pasteObj = Clipboard.GetData(ClipboardDataFormat);
                        pasteObjProxy = this.dropdownItems.FirstOrDefault(obj => object.Equals(obj, pasteObj));
                    }
                    else if (Clipboard.ContainsText())
                    {
                        string pasteObj = Clipboard.GetText();
                        pasteObjProxy = this.dropdownItems.FirstOrDefault(obj => obj != null && obj.ToString() == pasteObj);
                    }
                    if (pasteObjProxy != null)
                    {
                        if (this.selectedObject != pasteObjProxy)
                        {
                            this.selectedObject = pasteObjProxy;
                            this.selectedObjStr = this.DefaultValueStringGenerator(this.selectedObject);
                            this.EmitInvalidate();
                            this.EmitEdited(this.selectedObject);
                        }
                        success = true;
                    }
                }
                if (!success)
                {
                    System.Media.SystemSounds.Beep.Play();
                }
                e.Handled = true;
            }
        }
Beispiel #23
0
 public bool ContainsData(string format)
 {
     return(Clipboard.ContainsData(format));
 }
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------
        public void ClipboardPaste(View TargetView, bool AsIdeaShortcut = false, Point TargetPosition = default(Point), bool IsDroppingFiles = false)
        {
            if (IsClipboardTransferring && TargetView == ClipboardTransferSourceView)
            {
                UnmarkSelectedObjectsForCut();
                return;
            }

            try
            {
                // Paste Intra-Composition content ............................................................
                if (General.Execute(() => Clipboard.ContainsData(IdeaTransferFormat.Name),
                                    "Cannot access Windows Clipboard!").Result || AsIdeaShortcut)
                {
                    InjectCompositionContentToView(TargetView, AsIdeaShortcut);
                    return;
                }

                // Determine target types
                ExtensionPanel       ExtraOptions = null;
                IEnumerable <string> FilePaths    = null;
                if (General.Execute(() => Clipboard.ContainsFileDropList(),
                                    "Cannot access Windows Clipboard!").Result)
                {
                    FilePaths = General.Execute(() => Clipboard.GetFileDropList().Cast <string>(),
                                                "Cannot access Windows Clipboard!").Result;
                }

                var TargetIdeas = new List <Idea>();
                //- TargetIdeas.Add(TargetView.VisualizedCompositeIdea);

                if (TargetPosition == default(Point) || TargetPosition == Display.NULL_POINT)
                {
                    TargetPosition = TargetView.CurrentPresentationCenter;
                }

                var TargetRep = TargetView.SelectedObjects.Where(vobj => vobj is VisualElement)
                                .Select(vobj => ((VisualElement)vobj).OwnerRepresentation).FirstOrDefault();

                if (General.Execute(() => Clipboard.ContainsText(), "Cannot access Windows Clipboard!").Result ||
                    General.Execute(() => Clipboard.ContainsImage(), "Cannot access Windows Clipboard!").Result ||
                    FilePaths != null)
                {
                    ExtraOptions = CreatePastingExtraOptions(ExtraOptions, TargetRep, FilePaths);
                }

                // Determine target
                string Selection = DetermineTargetRepresentations(TargetView, TargetPosition, ExtraOptions, TargetIdeas, TargetRep, FilePaths);
                if (Selection == null)
                {
                    return;
                }

                if (Selection == VisualComplement.__ClassDefinitor.TechName)
                {
                    ClipboardPasteCreatingComplements(TargetView, TargetPosition, FilePaths);
                }
                else
                {
                    ClipboardPasteIntoIdeas(TargetView, ExtraOptions, FilePaths, TargetIdeas);
                }
            }
            catch (Exception Problem)
            {
                if (TargetView.EditEngine.IsVariating)
                {
                    TargetView.EditEngine.CompleteCommandVariation();
                    TargetView.EditEngine.Undo();
                }
                Console.WriteLine("Cannot Paste content. Problem: " + Problem.Message);
            }
        }
Beispiel #25
0
        public MainViewModel()
        {
            Voices         = new ObservableCollection <VoiceViewModel>();
            SelectedVoices = Array.Empty <VoiceViewModel>();

            OpenCommand   = new RelayCommand(ExecuteOpenCommand);
            SaveCommand   = new RelayCommand(ExecuteSaveCommand, () => IsFileLoaded);
            SaveAsCommand = new RelayCommand(ExecuteSaveAsCommand, () => IsFileLoaded);
            CloseCommand  = new RelayCommand(ExecuteCloseCommand);

            MoveUpCommand   = new RelayCommand(ExecuteMoveUpCommand, CanExecuteMoveUpCommand);
            MoveDownCommand = new RelayCommand(ExecuteMoveDownCommand, CanExecuteMoveDownCommand);

            CopyCommand  = new RelayCommand(ExecuteCopyCommand, () => SelectedVoices.Count > 0);
            PasteCommand = new RelayCommand(ExecutePasteCommand, () => SelectedVoices.Count > 0 && Clipboard.ContainsData("X9AVoice"));

            UndoChangesCommand           = new RelayCommand(ExecuteUndoChangesCommand, () => SelectedVoices.Count > 0);
            ResetToFactorySettingCommand = new RelayCommand(ExecuteResetToFactorySettingCommand, () => SelectedVoices.Count > 0);
            InitializeCommand            = new RelayCommand(ExecuteInitializeCommand, () => SelectedVoices.Count > 0);

            GitHubCommand = new RelayCommand(ExecuteGitHubCommand);
            AboutCommand  = new RelayCommand(ExecuteAboutCommand);
        }
Beispiel #26
0
 public static Result ContainsData(string format, out bool result)
 {
     return(TryAgain(() => Clipboard.ContainsData(format), out result));
 }
 private void Paste_Enabled(object sender, CanExecuteRoutedEventArgs e)
 {
     e.CanExecute = Clipboard.ContainsData(DataFormats.Xaml);
 }
Beispiel #28
0
        private void BluePrints_Load(object sender, EventArgs e)
        {
            this.BackColor         = MainForm.themecolors.background;
            this.ForeColor         = MainForm.themecolors.foreground;
            LoadButton.FlatStyle   = FlatStyle.Flat;
            LoadButton.ForeColor   = MainForm.themecolors.foreground;
            LoadButton.BackColor   = MainForm.themecolors.background;
            buttonImport.FlatStyle = FlatStyle.Flat;
            buttonImport.ForeColor = MainForm.themecolors.foreground;
            buttonImport.BackColor = MainForm.themecolors.background;
            SaveBPButton.FlatStyle = FlatStyle.Flat;
            SaveBPButton.ForeColor = MainForm.themecolors.foreground;
            SaveBPButton.BackColor = MainForm.themecolors.background;
            tBOwner.BackColor      = MainForm.themecolors.background;
            tBOwner.ForeColor      = MainForm.themecolors.foreground;

            LoadButton.Enabled   = true;
            buttonImport.Enabled = false;
            SaveBPButton.Enabled = false;
            Bitmap   bmp = new Bitmap(25 * 16, 25 * 16);
            Graphics gr2 = Graphics.FromImage(bmp);

            gr2.Clear(Color.DarkGray);
            pictureBox1.Image = bmp;

            if (Clipboard.ContainsData("EEBlueprints"))
            {
                LoadButton.Enabled   = false;
                buttonImport.Enabled = false;
                SaveBPButton.Enabled = false;
                string[][,] data     = (string[][, ])Clipboard.GetData("EEBlueprints");
                if (data?.Length == 9)
                {
                    if (data[0].GetLength(1) <= 25 && data[0].GetLength(0) <= 25)
                    {
                        using (Graphics gr = Graphics.FromImage(img4))
                        {
                            gr.Clear(Color.Gray);
                        }
                        container.width  = data[0].GetLength(1);
                        container.height = data[0].GetLength(0);
                        for (int y = 0; y < data[1].GetLength(0); y++)
                        {
                            for (int x = 0; x < data[1].GetLength(1); x++)
                            {
                                int bid1 = Convert.ToInt32(data[1][y, x]);


                                if (bid1 >= 500 && bid1 <= 999)
                                {
                                    if (MainForm.backgroundBMI[bid1] != 0 || bid1 == 500)
                                    {
                                        container.Blocks.Add(new Block()
                                        {
                                            BlockID = bid1, Layer = 1, X = x, Y = y
                                        });
                                        using (Graphics gr1 = Graphics.FromImage(img4))
                                        {
                                            gr1.DrawImage(MainForm.backgroundBMD.Clone(new Rectangle(MainForm.backgroundBMI[bid1] * 16, 0, 16, 16), MainForm.backgroundBMD.PixelFormat), x * 16, y * 16);
                                        }
                                    }
                                }
                            }
                        }
                        for (int y = 0; y < data[0].GetLength(0); y++)
                        {
                            for (int x = 0; x < data[0].GetLength(1); x++)
                            {
                                int bid = Convert.ToInt32(data[0][y, x]);

                                using (Graphics gr = Graphics.FromImage(img4))
                                {
                                    if (bid < 500 || bid >= 1001)
                                    {
                                        if (MainForm.decosBMI[bid] != 0)
                                        {
                                            img1 = bdata.getRotation(bid, Convert.ToInt32(data[2][y, x]));
                                            if (img1 != null)
                                            {
                                                gr.DrawImage(img1, new Rectangle(x * 16, y * 16, 16, 16));
                                                container.Blocks.Add(new Block()
                                                {
                                                    BlockID = bid, Layer = 0, X = x, Y = y, Param = Convert.ToInt32(data[2][y, x])
                                                });
                                            }
                                            else
                                            {
                                                container.Blocks.Add(new Block()
                                                {
                                                    BlockID = bid, Layer = 0, X = x, Y = y
                                                });
                                                gr.DrawImage(MainForm.decosBMD.Clone(new Rectangle(MainForm.decosBMI[Convert.ToInt32(data[0][y, x])] * 16, 0, 16, 16), MainForm.decosBMD.PixelFormat), x * 16, y * 16);
                                            }
                                        }
                                        else if (MainForm.miscBMI[bid] != 0 || bid == 119)
                                        {
                                            img1 = bdata.getRotation(bid, Convert.ToInt32(data[2][y, x]));
                                            if (img1 != null)
                                            {
                                                gr.DrawImage(img1, new Rectangle(x * 16, y * 16, 16, 16));
                                                container.Blocks.Add(new Block()
                                                {
                                                    BlockID = bid, Layer = 0, X = x, Y = y, Param = Convert.ToInt32(data[2][y, x])
                                                });
                                            }
                                            else
                                            {
                                                container.Blocks.Add(new Block()
                                                {
                                                    BlockID = bid, Layer = 0, X = x, Y = y
                                                });
                                                gr.DrawImage(MainForm.miscBMD.Clone(new Rectangle(MainForm.miscBMI[Convert.ToInt32(data[0][y, x])] * 16, 0, 16, 16), MainForm.miscBMD.PixelFormat), x * 16, y * 16);
                                            }
                                        }
                                        else if (bid != 0)
                                        {
                                            container.Blocks.Add(new Block()
                                            {
                                                BlockID = bid, Layer = 0, X = x, Y = y
                                            });
                                            gr.DrawImage(MainForm.foregroundBMD.Clone(new Rectangle(MainForm.foregroundBMI[Convert.ToInt32(data[0][y, x])] * 16, 0, 16, 16), MainForm.foregroundBMD.PixelFormat), x * 16, y * 16);
                                        }
                                    }
                                }
                            }
                        }
                        using (Graphics gr = Graphics.FromImage(img4))
                        {
                            gr.DrawRectangle(new Pen(Color.Black), new Rectangle(0, 0, data[0].GetLength(1) * 16 - 1, data[0].GetLength(0) * 16 - 1));
                        }
                        //Clipboard.Clear();
                        //Console.WriteLine(data[0]);
                        pictureBox1.Image    = img4;
                        pictureBox1.Width    = data[0].GetLength(1) * 16;
                        pictureBox1.Height   = data[0].GetLength(0) * 16;
                        SaveBPButton.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Your BluePrint is too big. Max size: 25 x 25");
                        Clipboard.Clear();
                        this.Close();
                    }
                    //;
                    //Console.WriteLine(data[0]);
                }

                Clipboard.Clear();
            }

            // Clipboard.Clear();
        }
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedCells.Count == 1 && Clipboard.ContainsText())
            {
                dataGridView.SelectedCells[0].Value = Clipboard.GetText();
                return;
            }

            if (!Clipboard.ContainsData("Csv"))
            {
                return;
            }

            var cells = dataGridView.SelectedCells.Cast <DataGridViewCell>();
            int xmin = cells.Min(cell => cell.ColumnIndex);
            int xmax = cells.Max(cell => cell.ColumnIndex);
            int ymin = cells.Min(cell => cell.RowIndex);
            int ymax = cells.Max(cell => cell.RowIndex);
            int w = xmax - xmin + 1, h = ymax - ymin + 1;

            if (w * h != dataGridView.SelectedCells.Count)
            {
                MessageBox.Show(
                    this,
                    "Cannot paste from clipboard into a non-rectangular cell selection.",
                    null,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            object[,] data;

            object rawData = Clipboard.GetData("Csv");

            using (var stream = rawData as Stream)
                using (var reader = (stream == null) ? (TextReader) new StringReader(rawData.ToString()) : new StreamReader(stream))
                {
                    data = CSV.Parse(reader);
                }

            if (data.GetLength(0) != h || data.GetLength(1) != w)
            {
                MessageBox.Show(
                    this,
                    string.Format(
                        "Cannot paste block of cells of size {0}x{1} from clipboard into cell selection of size {2}x{3}.",
                        data.GetLength(0), data.GetLength(1),
                        w, h),
                    null,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            int i = 0, j = 0;

            try
            {
                for (i = 0; i < h; ++i)
                {
                    for (j = 0; j < w; ++j)
                    {
                        Document.Data.Rows[ymin + i][xmin + j] = data[i, j];
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    string.Format("Error while pasting cell at row {0}, column {1}: {2}", i, j, ex.Message),
                    null,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Beispiel #30
0
 public bool CanPasteAction()
 {
     return(Clipboard.ContainsData(ACB_File.CLIPBOARD_ACB_ACTION));
 }