Exemplo n.º 1
0
		WPFToolbar (ToolBar toolbar) : base (toolbar)
		{
			this.toolbar = toolbar;

			toolbar.ConfigurationMenu.SelectionChanged += (o, e) => {
				var comboMenu = (ComboMenu<IConfigurationModel>)o;
				var newModel = e.Added;
				if (newModel == null)
					return;

				Runtime.RunInMainThread(() => {
					ActiveConfiguration = newModel;

					if (ConfigurationChanged != null)
						ConfigurationChanged(o, e);
				});
			};

			toolbar.RuntimeMenu.SelectionChanged += (o, e) => {
				var newModel = e.Added;
				if (newModel == null)
					return;

				using (var mutableModel = newModel.GetMutableModel()) {
					Runtime.RunInMainThread(() => {
						ActiveRuntime = newModel;

						var ea = new MonoDevelop.Components.MainToolbar.HandledEventArgs();
						if (RuntimeChanged != null)
							RuntimeChanged(o, ea);

						if (ea.Handled)
							ActiveRuntime = e.Removed;
					});
				}
			};

			toolbar.RunButton.Click += (o, e) => {
				if (RunButtonClicked != null)
					RunButtonClicked (o, e);
			};

			toolbar.SearchBar.SearchBar.TextChanged += (o, e) => {
				if (string.IsNullOrEmpty (SearchText) || SearchText == SearchPlaceholderMessage)
					return;

				if (SearchEntryChanged != null)
					SearchEntryChanged (o, e);
			};

			toolbar.SearchBar.SearchBar.LostKeyboardFocus += (o, e) => {
				if (SearchEntryLostFocus != null)
					SearchEntryLostFocus (o, e);
				toolbar.SearchBar.SearchText = toolbar.SearchBar.PlaceholderText;
			};

			toolbar.SearchBar.SearchBar.GotKeyboardFocus += (o, e) => {
				SearchEntryActivated?.Invoke (o, e);
			};

			toolbar.SearchBar.SearchBar.SizeChanged += (o, e) => {
				if (SearchEntryResized != null)
					SearchEntryResized (o, e);
			};

			toolbar.SearchBar.SearchBar.PreviewKeyDown += (o, e) => {
				var ka = new KeyEventArgs(KeyboardUtil.TranslateToXwtKey(e.Key), KeyboardUtil.GetModifiers(), e.IsRepeat, e.Timestamp);
				SendKeyPress(ka);
				e.Handled = ka.Handled;
			};

			toolbar.SearchBar.ClearIconClicked += (o, e) =>
			{
				SendKeyPress(new KeyEventArgs(Xwt.Key.Escape, KeyboardUtil.GetModifiers(), false, 0));
			};
        }
Exemplo n.º 2
0
        WPFToolbar(ToolBar toolbar) : base(toolbar)
        {
            this.toolbar = toolbar;

            toolbar.ConfigurationMenu.SelectionChanged += (o, e) => {
                var comboMenu = (ComboMenu <IConfigurationModel>)o;
                var newModel  = e.Added;
                if (newModel == null)
                {
                    return;
                }

                DispatchService.GuiDispatch(() => {
                    ActiveConfiguration = newModel;

                    if (ConfigurationChanged != null)
                    {
                        ConfigurationChanged(o, e);
                    }
                });
            };

            toolbar.RuntimeMenu.SelectionChanged += (o, e) => {
                var newModel = e.Added;
                if (newModel == null)
                {
                    return;
                }

                using (var mutableModel = newModel.GetMutableModel()) {
                    DispatchService.GuiDispatch(() => {
                        ActiveRuntime = newModel;

                        var ea = new MonoDevelop.Components.MainToolbar.HandledEventArgs();
                        if (RuntimeChanged != null)
                        {
                            RuntimeChanged(o, ea);
                        }

                        if (ea.Handled)
                        {
                            ActiveRuntime = e.Removed;
                        }
                    });
                }
            };

            toolbar.RunButton.Click += (o, e) => {
                if (RunButtonClicked != null)
                {
                    RunButtonClicked(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.TextChanged += (o, e) => {
                if (string.IsNullOrEmpty(SearchText) || SearchText == SearchPlaceholderMessage)
                {
                    return;
                }

                if (SearchEntryChanged != null)
                {
                    SearchEntryChanged(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.LostKeyboardFocus += (o, e) => {
                if (SearchEntryLostFocus != null)
                {
                    SearchEntryLostFocus(o, e);
                }
                toolbar.SearchBar.SearchText = toolbar.SearchBar.PlaceholderText;
            };

            toolbar.SearchBar.SearchBar.SizeChanged += (o, e) => {
                if (SearchEntryResized != null)
                {
                    SearchEntryResized(o, e);
                }
            };

            toolbar.SearchBar.SearchBar.PreviewKeyDown += (o, e) => {
                var ka = new KeyEventArgs(KeyboardUtil.TranslateToXwtKey(e.Key), KeyboardUtil.GetModifiers(), e.IsRepeat, e.Timestamp);
                SendKeyPress(ka);
                e.Handled = ka.Handled;
            };

            toolbar.SearchBar.ClearIconClicked += (o, e) =>
            {
                SendKeyPress(new KeyEventArgs(Xwt.Key.Escape, KeyboardUtil.GetModifiers(), false, 0));
            };
        }
Exemplo n.º 3
0
		void HandleRuntimeChanged (object sender, HandledEventArgs e)
		{
			if (ignoreRuntimeChangedCount == 0) {
				var runtime = (RuntimeModel)ToolbarView.ActiveRuntime;
				if (runtime != null && runtime.Command != null) {
					e.Handled = runtime.NotifyActivated ();
					return;
				}

				NotifyConfigurationChange ();
			}
		}
Exemplo n.º 4
0
			void CreateMenuItem (NSMenu menu, IRuntimeModel runtime)
			{
				var menuItem = new NSMenuItem {
					IndentationLevel = runtime.IsIndented ? 2 : 1,
					Enabled = runtime.Enabled,
					Hidden = !runtime.Visible,
					AttributedTitle = new NSAttributedString (runtime.DisplayString, new NSStringAttributes {
						Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont (menu.Font, NSFontTraitMask.Bold) : menu.Font,
					}),
				};

				var subMenu = CreateSubMenuForRuntime (runtime);
				if (subMenu != null) {
					menuItem.Submenu = subMenu;
					menuItem.Enabled = true;
				} else {
					menuItem.Activated += (o2, e2) => {
						string old = ActiveRuntime.FullDisplayString;
						ActiveRuntime = runtimeModel.First (r => r.FullDisplayString == runtime.FullDisplayString);
						var ea = new HandledEventArgs ();
						if (RuntimeChanged != null)
							RuntimeChanged (o2, ea);

						if (ea.Handled)
							ActiveRuntime = runtimeModel.First (r => r.FullDisplayString == old);
					};
				}
				menu.AddItem (menuItem);
			}
Exemplo n.º 5
0
		public MainToolbar ()
		{
			WidgetFlags |= Gtk.WidgetFlags.AppPaintable;

			AddWidget (button);
			AddSpace (8);

			configurationCombo = new Gtk.ComboBox ();
			configurationCombo.Model = configurationStore;
			var ctx = new Gtk.CellRendererText ();
			configurationCombo.PackStart (ctx, true);
			configurationCombo.AddAttribute (ctx, "text", 0);

			configurationCombosBox = new HBox (false, 8);

			var configurationComboVBox = new VBox ();
			configurationComboVBox.PackStart (configurationCombo, true, false, 0);
			configurationCombosBox.PackStart (configurationComboVBox, false, false, 0);

			// bold attributes for running runtime targets / (emulators)
			boldAttributes.Insert (new Pango.AttrWeight (Pango.Weight.Bold));

			runtimeCombo = new Gtk.ComboBox ();
			runtimeCombo.Model = runtimeStore;
			ctx = new Gtk.CellRendererText ();
			if (Platform.IsWindows)
				ctx.Ellipsize = Pango.EllipsizeMode.Middle;
			runtimeCombo.PackStart (ctx, true);
			runtimeCombo.SetCellDataFunc (ctx, RuntimeRenderCell);
			runtimeCombo.RowSeparatorFunc = RuntimeIsSeparator;

			var runtimeComboVBox = new VBox ();
			runtimeComboVBox.PackStart (runtimeCombo, true, false, 0);
			configurationCombosBox.PackStart (runtimeComboVBox, false, false, 0);
			AddWidget (configurationCombosBox);

			buttonBarBox = new Alignment (0.5f, 0.5f, 0, 0);
			buttonBarBox.LeftPadding = (uint) 7;
			buttonBarBox.Add (buttonBar);
			buttonBarBox.NoShowAll = true;
			AddWidget (buttonBarBox);
			AddSpace (24);

			statusArea = new StatusArea ();
			statusArea.ShowMessage (BrandingService.ApplicationName);

			var statusAreaAlign = new Alignment (0, 0, 1, 1);
			statusAreaAlign.Add (statusArea);
			contentBox.PackStart (statusAreaAlign, true, true, 0);
			AddSpace (24);

			statusAreaAlign.SizeAllocated += (object o, SizeAllocatedArgs args) => {
				Gtk.Widget toplevel = this.Toplevel;
				if (toplevel == null)
					return;

				int windowWidth = toplevel.Allocation.Width;
				int center = windowWidth / 2;
				int left = Math.Max (center - 300, args.Allocation.Left);
				int right = Math.Min (left + 600, args.Allocation.Right);
				uint left_padding = (uint) (left - args.Allocation.Left);
				uint right_padding = (uint) (args.Allocation.Right - right);

				if (left_padding != statusAreaAlign.LeftPadding || right_padding != statusAreaAlign.RightPadding)
					statusAreaAlign.SetPadding (0, 0, (uint) left_padding, (uint) right_padding);
			};

			matchEntry = new SearchEntry ();

			matchEntry.ForceFilterButtonVisible = true;
			matchEntry.Entry.FocusOutEvent += (o, e) => {
				if (SearchEntryLostFocus != null)
					SearchEntryLostFocus (o, e);
			};

			matchEntry.Ready = true;
			matchEntry.Visible = true;
			matchEntry.IsCheckMenu = true;
			matchEntry.WidthRequest = 240;
			if (!Platform.IsMac && !Platform.IsWindows)
				matchEntry.Entry.ModifyFont (Pango.FontDescription.FromString ("Sans 9")); // TODO: VV: "Segoe UI 9"
			matchEntry.RoundedShape = true;
			matchEntry.Entry.Changed += HandleSearchEntryChanged;
			matchEntry.Activated += HandleSearchEntryActivated;
			matchEntry.Entry.KeyPressEvent += HandleSearchEntryKeyPressed;
			SizeAllocated += (o, e) => {
				if (SearchEntryResized != null)
					SearchEntryResized (o, e);
			};

			contentBox.PackStart (matchEntry, false, false, 0);

			var align = new Gtk.Alignment (0, 0, 1f, 1f);
			align.Show ();
			align.TopPadding = (uint) 5;
			align.LeftPadding = (uint) 9;
			align.RightPadding = (uint) 18;
			align.BottomPadding = (uint) 10;
			align.Add (contentBox);

			Add (align);
			SetDefaultSizes (-1, 21);

			configurationCombo.Changed += (o, e) => {
				if (ConfigurationChanged != null)
					ConfigurationChanged (o, e);
			};
			runtimeCombo.Changed += (o, e) => {
				var ea = new HandledEventArgs ();
				if (RuntimeChanged != null)
					RuntimeChanged (o, ea);

				TreeIter it;
				if (runtimeCombo.GetActiveIter (out it)) {
					if (ea.Handled) {
						runtimeCombo.SetActiveIter (lastSelection);
						return;
					}
					lastSelection = it;
				}
			};

			button.Clicked += HandleStartButtonClicked;

			IdeApp.CommandService.ActiveWidgetChanged += (sender, e) => {
				lastCommandTarget = new WeakReference (e.OldActiveWidget);
			};

			this.ShowAll ();
			this.statusArea.statusIconBox.HideAll ();
		}
Exemplo n.º 6
0
			void CreateMenuItem (NSMenu menu, IRuntimeModel runtime)
			{
				NSMenuItem menuItem;
				string runtimeFullDisplayString;

				using (var mutableModel = runtime.GetMutableModel ()) {
					runtimeFullDisplayString = mutableModel.FullDisplayString;

					menuItem = new NSMenuItem {
						IndentationLevel = runtime.IsIndented ? 2 : 1,
						AttributedTitle = new NSAttributedString (mutableModel.DisplayString, new NSStringAttributes {
							Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont (menu.Font, NSFontTraitMask.Bold) : menu.Font,
						}),
						Enabled = mutableModel.Enabled,
						Hidden = !mutableModel.Visible,
					};
				}

				var subMenu = CreateSubMenuForRuntime (runtime);
				if (subMenu != null) {
					menuItem.Submenu = subMenu;
					menuItem.Enabled = true;
				} else {
					menuItem.Activated += (o2, e2) => {
						string old;
						using (var activeMutableModel = ActiveRuntime.GetMutableModel ())
							old = activeMutableModel.FullDisplayString;

						IRuntimeModel newRuntime = runtimeModel.FirstOrDefault (r => {
							using (var newRuntimeMutableModel = r.GetMutableModel ())
								return newRuntimeMutableModel.FullDisplayString == runtimeFullDisplayString;
						});
						if (newRuntime == null)
							return;

						ActiveRuntime = newRuntime;
						var ea = new HandledEventArgs ();
						if (RuntimeChanged != null)
							RuntimeChanged (o2, ea);

						if (ea.Handled)
							ActiveRuntime = runtimeModel.First (r => {
								using (var newRuntimeMutableModel = r.GetMutableModel ())
									return newRuntimeMutableModel.FullDisplayString == old;
							});
					};
				}
				menu.AddItem (menuItem);
			}
Exemplo n.º 7
0
        public MainToolbar()
        {
            WidgetFlags |= Gtk.WidgetFlags.AppPaintable;

            AddWidget(button);
            AddSpace(8);

            configurationCombosBox = new HBox(false, 8);

            var ctx = new Gtk.CellRendererText();

            runConfigurationCombo       = new Gtk.ComboBox();
            runConfigurationCombo.Model = runConfigurationStore;
            runConfigurationCombo.PackStart(ctx, true);
            runConfigurationCombo.AddAttribute(ctx, "text", 0);

            var runConfigurationComboVBox = new VBox();

            runConfigurationComboVBox.PackStart(runConfigurationCombo, true, false, 0);
            configurationCombosBox.PackStart(runConfigurationComboVBox, false, false, 0);

            configurationCombo       = new Gtk.ComboBox();
            configurationCombo.Model = configurationStore;
            configurationCombo.PackStart(ctx, true);
            configurationCombo.AddAttribute(ctx, "text", 0);

            var configurationComboVBox = new VBox();

            configurationComboVBox.PackStart(configurationCombo, true, false, 0);
            configurationCombosBox.PackStart(configurationComboVBox, false, false, 0);

            // bold attributes for running runtime targets / (emulators)
            boldAttributes.Insert(new Pango.AttrWeight(Pango.Weight.Bold));

            runtimeCombo       = new Gtk.ComboBox();
            runtimeCombo.Model = runtimeStore;
            ctx = new Gtk.CellRendererText();
            if (Platform.IsWindows)
            {
                ctx.Ellipsize = Pango.EllipsizeMode.Middle;
            }
            runtimeCombo.PackStart(ctx, true);
            runtimeCombo.SetCellDataFunc(ctx, RuntimeRenderCell);
            runtimeCombo.RowSeparatorFunc = RuntimeIsSeparator;

            var runtimeComboVBox = new VBox();

            runtimeComboVBox.PackStart(runtimeCombo, true, false, 0);
            configurationCombosBox.PackStart(runtimeComboVBox, false, false, 0);
            AddWidget(configurationCombosBox);

            buttonBarBox             = new Alignment(0.5f, 0.5f, 0, 0);
            buttonBarBox.LeftPadding = (uint)7;
            buttonBarBox.Add(buttonBar);
            buttonBarBox.NoShowAll = true;
            AddWidget(buttonBarBox);
            AddSpace(24);

            statusArea = new StatusArea();
            statusArea.ShowMessage(BrandingService.ApplicationName);

            var statusAreaAlign = new Alignment(0, 0, 1, 1);

            statusAreaAlign.Add(statusArea);
            contentBox.PackStart(statusAreaAlign, true, true, 0);
            AddSpace(24);

            statusAreaAlign.SizeAllocated += (object o, SizeAllocatedArgs args) => {
                Gtk.Widget toplevel = this.Toplevel;
                if (toplevel == null)
                {
                    return;
                }

                int  windowWidth   = toplevel.Allocation.Width;
                int  center        = windowWidth / 2;
                int  left          = Math.Max(center - 300, args.Allocation.Left);
                int  right         = Math.Min(left + 600, args.Allocation.Right);
                uint left_padding  = (uint)(left - args.Allocation.Left);
                uint right_padding = (uint)(args.Allocation.Right - right);

                if (left_padding != statusAreaAlign.LeftPadding || right_padding != statusAreaAlign.RightPadding)
                {
                    statusAreaAlign.SetPadding(0, 0, (uint)left_padding, (uint)right_padding);
                }
            };

            matchEntry = new SearchEntry();

            matchEntry.ForceFilterButtonVisible = true;
            matchEntry.Entry.FocusOutEvent     += (o, e) => {
                if (SearchEntryLostFocus != null)
                {
                    SearchEntryLostFocus(o, e);
                }
            };

            matchEntry.Ready        = true;
            matchEntry.Visible      = true;
            matchEntry.IsCheckMenu  = true;
            matchEntry.WidthRequest = 240;
            if (!Platform.IsMac && !Platform.IsWindows)
            {
                matchEntry.Entry.ModifyFont(Pango.FontDescription.FromString("Sans 9"));                   // TODO: VV: "Segoe UI 9"
            }
            matchEntry.RoundedShape         = true;
            matchEntry.Entry.Changed       += HandleSearchEntryChanged;
            matchEntry.Activated           += HandleSearchEntryActivated;
            matchEntry.Entry.KeyPressEvent += HandleSearchEntryKeyPressed;
            SizeAllocated += (o, e) => {
                if (SearchEntryResized != null)
                {
                    SearchEntryResized(o, e);
                }
            };

            contentBox.PackStart(matchEntry, false, false, 0);

            var align = new Gtk.Alignment(0, 0, 1f, 1f);

            align.Show();
            align.TopPadding    = (uint)5;
            align.LeftPadding   = (uint)9;
            align.RightPadding  = (uint)18;
            align.BottomPadding = (uint)10;
            align.Add(contentBox);

            Add(align);
            SetDefaultSizes(-1, 21);

            configurationCombo.Changed += (o, e) => {
                if (ConfigurationChanged != null)
                {
                    ConfigurationChanged(o, e);
                }
            };
            runConfigurationCombo.Changed += (o, e) => {
                if (RunConfigurationChanged != null)
                {
                    RunConfigurationChanged(o, e);
                }
            };
            runtimeCombo.Changed += (o, e) => {
                var ea = new HandledEventArgs();
                if (RuntimeChanged != null)
                {
                    RuntimeChanged(o, ea);
                }

                TreeIter it;
                if (runtimeCombo.GetActiveIter(out it))
                {
                    if (ea.Handled)
                    {
                        runtimeCombo.SetActiveIter(lastSelection);
                        return;
                    }
                    lastSelection = it;
                }
            };

            button.Clicked += HandleStartButtonClicked;

            IdeApp.CommandService.ActiveWidgetChanged += (sender, e) => {
                lastCommandTarget = new WeakReference(e.OldActiveWidget);
            };

            this.ShowAll();
            this.statusArea.statusIconBox.HideAll();
        }