示例#1
0
文件: Block.cs 项目: zeta1999/eithne
 public void Invalidate()
 {
     Invalidate(true);
     schematic.QueueDraw();
 }
示例#2
0
        protected override bool OnButtonPressEvent(Gdk.EventButton args)
        {
            status.Pop(1);

            Schematic _t       = this;
            object    selected = _t.selected;

            object tmp = CheckSelection((int)args.X, (int)args.Y);

            if (selected != null && selected == tmp)
            {
                if (selected is Block)
                {
                    Block b = selected as Block;

                    if (args.Button == 1)
                    {
                        if (args.Type == Gdk.EventType.ButtonPress)
                        {
                            status.Push(1, Catalog.GetString("Move block to desired location"));

                            // move clicked block to the top
                            if (blocks[blocks.Count - 1] != selected)
                            {
                                blocks.Remove(selected);
                                blocks.Add(selected);
                                QueueDraw();
                            }

                            Action.m = Action.Mode.Move;
                            tmpx     = (int)args.X;
                            tmpy     = (int)args.Y;
                        }
                        else if (args.Type == Gdk.EventType.TwoButtonPress)
                        {
                            Action.m = Action.Mode.Normal;

                            if (b.Plugin is Plugin.Out && b.Plugin.WorkDone)
                            {
                                try
                                {
                                    (b.Plugin as Plugin.Out).DisplayResults();
                                }
                                catch (Exception e)
                                {
                                    b.ShowError = true;
                                    QueueDraw();
                                    new PluginError(e, b, true);
                                }
                            }
                            else if (b.Plugin.HasSetup)
                            {
                                try
                                {
                                    b.Plugin.Setup();
                                }
                                catch (Exception e)
                                {
                                    b.ShowError = true;
                                    QueueDraw();
                                    new PluginError(e, b, true);
                                }
                            }
                        }
                    }
                    else if (args.Button == 3)
                    {
                        ImageMenuItem mi;

                        status.Push(1, String.Format(Catalog.GetString("{0} menu"), b.Plugin.Info.Name));

                        Action.m = Action.Mode.Normal;

                        Menu m = new Menu();

                        if (b.Plugin is Plugin.Out)
                        {
                            mi            = new ImageMenuItem(Catalog.GetString("Display _results"));
                            mi.Image      = new Image(null, "system-search.png");
                            mi.Activated += PluginResults;
                            if (!b.Plugin.WorkDone)
                            {
                                mi.Sensitive = false;
                            }
                            m.Append(mi);
                        }

                        if (b.Plugin.HasSetup)
                        {
                            mi            = new ImageMenuItem(Catalog.GetString("_Setup"));
                            mi.Image      = new Image(null, "preferences-desktop.png");
                            mi.Activated += PluginSetup;
                            m.Append(mi);
                        }

                        if (b.Plugin.HasSetup || b.Plugin is Plugin.Out)
                        {
                            m.Append(new SeparatorMenuItem());
                        }

                        mi            = new ImageMenuItem(Catalog.GetString("D_isconnect all"));
                        mi.Image      = new Image(null, "edit-cut.png");
                        mi.Activated += delegate(object sender, EventArgs eargs)
                        {
                            b.Disconnect();
                            QueueDraw();
                            status.Pop(1);
                            status.Push(1, Catalog.GetString("Removed all block's connections"));
                        };
                        m.Append(mi);

                        mi       = new ImageMenuItem(Catalog.GetString("In_validate"));
                        mi.Image = new Image(null, "user-trash-full.png");
                        if (b.CheckState() != Block.State.Good)
                        {
                            mi.Sensitive = false;
                        }
                        mi.Activated += delegate(object sender, EventArgs eargs)
                        {
                            b.Invalidate();

                            status.Pop(1);
                            status.Push(1, Catalog.GetString("Invalidated results"));
                        };
                        m.Append(mi);

                        mi            = new ImageMenuItem(Catalog.GetString("_Delete"));
                        mi.Image      = new Image(null, "edit-delete.png");
                        mi.Activated += delegate(object sender, EventArgs eargs)
                        {
                            b.Disconnect();
                            blocks.Remove(selected);
                            QueueDraw();

                            status.Pop(1);
                            status.Push(1, String.Format(Catalog.GetString("Deleted {0} block"), b.Plugin.Info.Name));
                        };
                        m.Append(mi);

                        m.Append(new SeparatorMenuItem());

                        mi            = new ImageMenuItem(Catalog.GetString("_About"));
                        mi.Image      = new Image(null, "help-browser.png");
                        mi.Activated += delegate(object sender, EventArgs eargs) { new PluginAbout(b.Plugin); };
                        m.Append(mi);

                        m.ShowAll();
                        m.Popup();
                    }
                }
                else if (selected is Socket)
                {
                    Socket s = selected as Socket;

                    if (s.Other == null)
                    {
                        if (s.Type == Socket.T.Out)
                        {
                            if (args.Button == 1)
                            {
                                status.Push(1, Catalog.GetString("Connect block with another"));
                                Action.m    = Action.Mode.Connect;
                                Action.data = Connection.None;
                                tmpx        = (int)args.X;
                                tmpy        = (int)args.Y;
                                QueueDraw();
                            }
                        }
                    }
                    else
                    {
                        if (args.Button == 1 && args.Type == Gdk.EventType.TwoButtonPress)
                        {
                            status.Push(1, Catalog.GetString("Removed connection"));
                            s.Disconnect();
                            QueueDraw();
                        }
                        else if (args.Button == 3)
                        {
                            Menu          m  = new Menu();
                            ImageMenuItem mi = new ImageMenuItem(Catalog.GetString("_Disconnect"));
                            mi.Image      = new Image(null, "edit-cut.png");
                            mi.Activated += delegate(object sender, EventArgs eargs)
                            {
                                s.Disconnect();
                                _t.QueueDraw();

                                _t.status.Pop(1);
                                _t.status.Push(1, Catalog.GetString("Removed connection"));
                            };
                            m.Append(mi);

                            m.ShowAll();
                            m.Popup();
                        }
                    }
                }
            }
            else
            {
                Action.m = Action.Mode.Normal;
                selected = tmp;
                QueueDraw();
            }

            return(true);
        }