Пример #1
0
		public RegexToolkitWindow () : base(Gtk.WindowType.Toplevel)
		{
			this.Build ();
			this.TransientFor = IdeApp.Workbench.RootWindow;
			optionsStore = new ListStore (typeof(bool), typeof(string), typeof(Options));
			resultStore = new Gtk.TreeStore (typeof(string), typeof(string), typeof(int), typeof(int));
			
			FillOptionsBox ();
			
			this.buttonCancel.Clicked += delegate {
				this.Destroy ();
			};
			
			var isWindows = System.IO.Path.DirectorySeparatorChar == '\\';
			this.buttonLibrary.Visible = !isWindows;
			this.buttonStart.Sensitive = false;
			this.entryRegEx.Changed += UpdateStartButtonSensitivity;
			this.inputTextview.Buffer.Changed += UpdateStartButtonSensitivity;
			
			this.buttonStart.Clicked += delegate {
				if (regexThread != null && regexThread.IsAlive) {
					regexThread.Abort ();
					regexThread.Join ();
					SetButtonStart (GettextCatalog.GetString ("_Start Regular Expression"), "gtk-media-play");
					regexThread = null;
					return;
				}
				
				regexThread = new Thread (delegate() {
					PerformQuery (inputTextview.Buffer.Text, this.entryRegEx.Text, this.entryReplace.Text, GetOptions ());
				});
				
				regexThread.IsBackground = true;
				regexThread.Name = "regex thread";
				regexThread.Start ();
				SetButtonStart (GettextCatalog.GetString ("_Stop execution"), "gtk-media-stop");
				
				SetFindMode (!checkbuttonReplace.Active);
			};
			
			this.buttonLibrary.Clicked += delegate {
				if (regexLib == null) {
					regexLib = new RegexLibraryWindow ();
					regexLib.TransientFor = this;
					regexLib.Destroyed += delegate {
						regexLib = null;
					};
					regexLib.Show ();
				}
			};
			
			SetFindMode (true);
			
			var cellRendText = new CellRendererText ();
			cellRendText.Ellipsize = Pango.EllipsizeMode.End;
			var pix = new CellRendererPixbuf ();
			
			this.optionsTreeview.Model = this.optionsStore;
			this.optionsTreeview.HeadersVisible = false;
			
			CellRendererToggle cellRendToggle = new CellRendererToggle ();
			cellRendToggle.Toggled += new ToggledHandler (OptionToggled);
			cellRendToggle.Activatable = true;
			this.optionsTreeview.AppendColumn ("", cellRendToggle, "active", 0);
			this.optionsTreeview.AppendColumn ("", cellRendText, "text", 1);
			
			this.resultsTreeview.Model = this.resultStore;
			this.resultsTreeview.HeadersVisible = false;
			var col = new TreeViewColumn ();
			this.resultsTreeview.AppendColumn (col);
			col.PackStart (pix, false);
			col.AddAttribute (pix, "stock_id", 0);
			col.PackStart (cellRendText, true);
			col.AddAttribute (cellRendText, "text", 1);
			
			this.resultsTreeview.RowActivated += delegate(object sender, RowActivatedArgs e) {
				Gtk.TreeIter iter;
				if (resultStore.GetIter (out iter, e.Path)) {
					int index = (int)resultStore.GetValue (iter, 2);
					int length = (int)resultStore.GetValue (iter, 3);
					if (index >= 0) {
						this.inputTextview.Buffer.SelectRange (this.inputTextview.Buffer.GetIterAtOffset (index),
						                                       this.inputTextview.Buffer.GetIterAtOffset (index + length));
					} else {
						this.inputTextview.Buffer.SelectRange (this.inputTextview.Buffer.GetIterAtOffset (0), this.inputTextview.Buffer.GetIterAtOffset (0));
					}
				}
			};
			
			elementsStore = new Gtk.TreeStore (typeof(string), typeof(string), typeof(string), typeof(string));
			this.elementsTreeview.Model = this.elementsStore;
			this.elementsTreeview.HeadersVisible = false;
			this.elementsTreeview.Selection.Mode = SelectionMode.Browse;
			
			col = new TreeViewColumn ();
			this.elementsTreeview.AppendColumn (col);
			col.PackStart (pix, false);
			col.AddAttribute (pix, "stock_id", 0);
			col.PackStart (cellRendText, true);
			
			col.AddAttribute (cellRendText, "text", 1);
			
			var cellRendText2 = new CellRendererText ();
			col.PackStart (cellRendText2, false);
			col.SetCellDataFunc (cellRendText2, ElementDescriptionFunc);
			
			this.elementsTreeview.Selection.Changed += delegate {
				ShowTooltipForSelectedEntry ();
			};
			
			this.LeaveNotifyEvent += delegate {
				this.HideTooltipWindow ();
			};
			
			
			this.elementsTreeview.MotionNotifyEvent += HandleMotionNotifyEvent;
			
			this.elementsTreeview.RowActivated += delegate (object sender, RowActivatedArgs e) {
				Gtk.TreeIter iter;
				if (elementsStore.GetIter (out iter, e.Path)) {
					string text = elementsStore.GetValue (iter, 3) as string;
					if (!System.String.IsNullOrEmpty (text)) {
						this.entryRegEx.InsertText (text);
					}
				}
			};
			this.entryReplace.Sensitive = this.checkbuttonReplace.Active = false;
			this.checkbuttonReplace.Toggled += delegate {
				this.entryReplace.Sensitive = this.checkbuttonReplace.Active;
			};
			FillElementsBox ();
			this.vbox4.Hide ();
		}
Пример #2
0
        public RegexToolkitWindow() : base(Gtk.WindowType.Toplevel)
        {
            this.Build();
            this.TransientFor = IdeApp.Workbench.RootWindow;
            optionsStore      = new ListStore(typeof(bool), typeof(string), typeof(Options));
            resultStore       = new Gtk.TreeStore(typeof(string), typeof(string), typeof(int), typeof(int));

            FillOptionsBox();

            this.buttonCancel.Clicked += delegate {
                this.Destroy();
            };

            var isWindows = System.IO.Path.DirectorySeparatorChar == '\\';

            this.buttonLibrary.Visible         = !isWindows;
            this.buttonStart.Sensitive         = false;
            this.entryRegEx.Changed           += UpdateStartButtonSensitivity;
            this.inputTextview.Buffer.Changed += UpdateStartButtonSensitivity;

            this.buttonStart.Clicked += delegate {
                if (regexThread != null && regexThread.IsAlive)
                {
                    regexThread.Abort();
                    regexThread.Join();
                    SetButtonStart(GettextCatalog.GetString("_Start Regular Expression"), "gtk-media-play");
                    regexThread = null;
                    return;
                }

                regexThread = new Thread(delegate() {
                    PerformQuery(inputTextview.Buffer.Text, this.entryRegEx.Text, this.entryReplace.Text, GetOptions());
                });

                regexThread.IsBackground = true;
                regexThread.Name         = "regex thread";
                regexThread.Start();
                SetButtonStart(GettextCatalog.GetString("_Stop execution"), "gtk-media-stop");

                SetFindMode(!checkbuttonReplace.Active);
            };

            this.buttonLibrary.Clicked += delegate {
                if (regexLib == null)
                {
                    regexLib = new RegexLibraryWindow();
                    regexLib.TransientFor = this;
                    regexLib.Destroyed   += delegate {
                        regexLib = null;
                    };
                    regexLib.Show();
                }
            };

            SetFindMode(true);

            var cellRendText = new CellRendererText();

            cellRendText.Ellipsize = Pango.EllipsizeMode.End;
            var pix = new CellRendererPixbuf();

            this.optionsTreeview.Model          = this.optionsStore;
            this.optionsTreeview.HeadersVisible = false;

            CellRendererToggle cellRendToggle = new CellRendererToggle();

            cellRendToggle.Toggled    += new ToggledHandler(OptionToggled);
            cellRendToggle.Activatable = true;
            this.optionsTreeview.AppendColumn("", cellRendToggle, "active", 0);
            this.optionsTreeview.AppendColumn("", cellRendText, "text", 1);

            this.resultsTreeview.Model          = this.resultStore;
            this.resultsTreeview.HeadersVisible = false;
            var col = new TreeViewColumn();

            this.resultsTreeview.AppendColumn(col);
            col.PackStart(pix, false);
            col.AddAttribute(pix, "stock_id", 0);
            col.PackStart(cellRendText, true);
            col.AddAttribute(cellRendText, "text", 1);

            this.resultsTreeview.RowActivated += delegate(object sender, RowActivatedArgs e) {
                Gtk.TreeIter iter;
                if (resultStore.GetIter(out iter, e.Path))
                {
                    int index  = (int)resultStore.GetValue(iter, 2);
                    int length = (int)resultStore.GetValue(iter, 3);
                    if (index >= 0)
                    {
                        this.inputTextview.Buffer.SelectRange(this.inputTextview.Buffer.GetIterAtOffset(index),
                                                              this.inputTextview.Buffer.GetIterAtOffset(index + length));
                    }
                    else
                    {
                        this.inputTextview.Buffer.SelectRange(this.inputTextview.Buffer.GetIterAtOffset(0), this.inputTextview.Buffer.GetIterAtOffset(0));
                    }
                }
            };

            elementsStore = new Gtk.TreeStore(typeof(string), typeof(string), typeof(string), typeof(string));
            this.elementsTreeview.Model          = this.elementsStore;
            this.elementsTreeview.HeadersVisible = false;
            this.elementsTreeview.Selection.Mode = SelectionMode.Browse;

            col = new TreeViewColumn();
            this.elementsTreeview.AppendColumn(col);
            col.PackStart(pix, false);
            col.AddAttribute(pix, "stock_id", 0);
            col.PackStart(cellRendText, true);

            col.AddAttribute(cellRendText, "text", 1);

            var cellRendText2 = new CellRendererText();

            col.PackStart(cellRendText2, false);
            col.SetCellDataFunc(cellRendText2, ElementDescriptionFunc);

            this.elementsTreeview.Selection.Changed += delegate {
                ShowTooltipForSelectedEntry();
            };

            this.LeaveNotifyEvent += delegate {
                this.HideTooltipWindow();
            };


            this.elementsTreeview.MotionNotifyEvent += HandleMotionNotifyEvent;

            this.elementsTreeview.RowActivated += delegate(object sender, RowActivatedArgs e) {
                Gtk.TreeIter iter;
                if (elementsStore.GetIter(out iter, e.Path))
                {
                    string text = elementsStore.GetValue(iter, 3) as string;
                    if (!System.String.IsNullOrEmpty(text))
                    {
                        this.entryRegEx.InsertText(text);
                    }
                }
            };
            this.entryReplace.Sensitive      = this.checkbuttonReplace.Active = false;
            this.checkbuttonReplace.Toggled += delegate {
                this.entryReplace.Sensitive = this.checkbuttonReplace.Active;
            };
            FillElementsBox();
            this.vbox4.Hide();
        }