public DropDownBoxListWindow(IListDataProvider provider, WindowType windowType) : base(windowType)
        {
            this.DataProvider = provider;
            this.TransientFor = IdeApp.Workbench.RootWindow;
            this.TypeHint     = Gdk.WindowTypeHint.Menu;
            this.Decorated    = false;
            this.BorderWidth  = 1;
            list             = new ListWidget(this);
            list.SelectItem += delegate {
                var sel = list.Selection;
                if (sel >= 0 && sel < DataProvider.IconCount)
                {
                    DataProvider.ActivateItem(sel);
                    Destroy();
                }
            };
            SetSizeRequest(list.WidthRequest + WidthModifier, list.HeightRequest);
            vScrollbar = new ScrolledWindow();
            vScrollbar.VScrollbar.SizeAllocated += (o, args) => {
                var minWidth = list.WidthRequest + args.Allocation.Width;
                if (this.Allocation.Width < minWidth)
                {
                    SetSizeRequest(minWidth, list.HeightRequest);
                }
            };
            vScrollbar.Child = list;
            var vbox = new VBox();

            vbox.PackStart(vScrollbar, true, true, 0);
            Add(vbox);
        }
		public DropDownBoxListWindow (IListDataProvider provider) : base (WindowType.Popup)
		{
			this.DataProvider = provider;
			this.TransientFor = IdeApp.Workbench.RootWindow;
			this.TypeHint = Gdk.WindowTypeHint.Menu;
			this.BorderWidth = 1;
			this.Events |= Gdk.EventMask.KeyPressMask;
			list = new ListWidget (this);
			list.SelectItem += delegate {
				var sel = list.Selection;
				if (sel >= 0 && sel < DataProvider.IconCount) {
					DataProvider.ActivateItem (sel);
					Destroy ();
				}
			};
			SetSizeRequest (list.WidthRequest, list.HeightRequest);
			vScrollbar = new ScrolledWindow ();
			vScrollbar.VScrollbar.SizeAllocated += (o, args) => {
				var minWidth = list.WidthRequest + args.Allocation.Width;
				if (this.Allocation.Width < minWidth)
					SetSizeRequest (minWidth, list.HeightRequest);
			};
			vScrollbar.Child = list;
			var vbox = new VBox ();
			vbox.PackStart (vScrollbar, true, true, 0);
			Add (vbox);
		}
        public DropDownBoxListWindow(IListDataProvider provider) : base(Gtk.WindowType.Popup)
        {
            this.DataProvider = provider;
            this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
            this.TypeHint     = Gdk.WindowTypeHint.Menu;
            this.BorderWidth  = 1;
            this.Events      |= Gdk.EventMask.KeyPressMask;
            hBox             = new HBox();
            list             = new ListWidget(this);
            list.SelectItem += delegate {
                var sel = list.Selection;
                if (sel >= 0 && sel < DataProvider.IconCount)
                {
                    DataProvider.ActivateItem(sel);
                    Destroy();
                }
            };

            list.ScrollEvent   += HandleListScrollEvent;
            list.SizeAllocated += delegate {
                QueueResize();
            };
            list.PageChanged += HandleListPageChanged;
            hBox.PackStart(list, true, true, 0);

            vScrollbar = new VScrollbar(null);
            vScrollbar.ValueChanged += delegate {
                list.ForcePage((int)vScrollbar.Value);
            };

            hBox.PackStart(vScrollbar, false, false, 0);
            Add(hBox);
            ShowAll();
        }
		public DropDownBoxListWindow (IListDataProvider provider) : base(Gtk.WindowType.Popup)
		{
			this.DataProvider = provider;
			this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
			this.TypeHint = Gdk.WindowTypeHint.Menu;
			this.BorderWidth = 1;
			this.Events |= Gdk.EventMask.KeyPressMask;
			hBox = new HBox ();
			list = new ListWidget (this);
			list.SelectItem += delegate {
				var sel = list.Selection;
				if (sel >= 0 && sel < DataProvider.IconCount) {
					DataProvider.ActivateItem (sel);
					Destroy ();
				}
			};
			
			list.ScrollEvent += HandleListScrollEvent;
			list.SizeAllocated += delegate {
				QueueResize ();
			};
			list.PageChanged += HandleListPageChanged;
			hBox.PackStart (list, true, true, 0);
			
			vScrollbar = new VScrollbar (null);
			vScrollbar.ValueChanged += delegate {
				list.ForcePage ((int)vScrollbar.Value);
			};
			
			hBox.PackStart (vScrollbar, false, false, 0);
			Add (hBox);
			ShowAll ();
		}
        public DropDownBoxListWindow(IListDataProvider provider) : base(Gtk.WindowType.Popup)
        {
            this.DataProvider = provider;
            this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
            this.TypeHint     = Gdk.WindowTypeHint.Menu;
            this.BorderWidth  = 1;
            this.Events      |= Gdk.EventMask.KeyPressMask;
            list             = new ListWidget(this);
            list.SelectItem += delegate {
                var sel = list.Selection;
                if (sel >= 0 && sel < DataProvider.IconCount)
                {
                    DataProvider.ActivateItem(sel);
                    Destroy();
                }
            };
            SetSizeRequest(list.WidthRequest, list.HeightRequest);
            vScrollbar = new ScrolledWindow();
            vScrollbar.VScrollbar.SizeAllocated += (object o, SizeAllocatedArgs args) => {
                var minWidth = list.WidthRequest + args.Allocation.Width;
                if (this.Allocation.Width < minWidth)
                {
                    SetSizeRequest(minWidth, list.HeightRequest);
                }
            };
            vScrollbar.Child = list;
            var vbox = new VBox();

            vbox.PackStart(vScrollbar, true, true, 0);
            Add(vbox);
        }
        public DropDownBoxListWindow(IListDataProvider provider, WindowType windowType) : base(windowType)
        {
            Accessible.Name = "DropDownBoxListWindow";

            this.DataProvider = provider;
            this.TransientFor = IdeApp.Workbench.RootWindow;
            this.TypeHint     = Gdk.WindowTypeHint.DropdownMenu;
            this.Decorated    = false;
            this.BorderWidth  = 1;
            list = new ListWidget(this);
            list.Accessible.Name = "DropDownBoxListWindow.List";

            list.SelectItem += delegate {
                var sel = list.Selection;
                if (sel >= 0 && sel < DataProvider.IconCount)
                {
                    try {
                        DataProvider.ActivateItem(sel);
                        // This is so parent window of dropdown regains focus
                        TransientFor?.Present();
                    } catch (Exception ex) {
                        LoggingService.LogInternalError("Offset seems to be out of sync with the snapshot.", ex);
                    }

                    Destroy();
                }
            };
            SetSizeRequest(list.WidthRequest + WidthModifier, list.HeightRequest);
            vScrollbar = new ScrolledWindow();
            vScrollbar.VScrollbar.SizeAllocated += (o, args) => {
                var minWidth = list.WidthRequest + args.Allocation.Width;
                if (this.Allocation.Width < minWidth)
                {
                    SetSizeRequest(minWidth, list.HeightRequest);
                }
            };
            vScrollbar.Child = list;
            var vbox = new VBox();

            vbox.PackStart(vScrollbar, true, true, 0);
            Add(vbox);
        }
        public DropDownBoxListWindow(IListDataProvider provider) : base(Gtk.WindowType.Popup)
        {
            this.DataProvider = provider;
            this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
            this.TypeHint     = Gdk.WindowTypeHint.Menu;
            this.BorderWidth  = 1;

            hBox             = new HBox();
            list             = new ListWidget(this);
            list.SelectItem += delegate {
                DataProvider.ActivateItem(list.Selection);
                Destroy();
            };

            list.ScrollEvent += delegate(object o, ScrollEventArgs args) {
                if (args.Event.Direction == Gdk.ScrollDirection.Up)
                {
                    vScrollbar.Value--;
                }
                else if (args.Event.Direction == Gdk.ScrollDirection.Down)
                {
                    vScrollbar.Value++;
                }
            };
            list.SizeAllocated += delegate {
                QueueResize();
            };
            list.PageChanged += HandleListPageChanged;
            hBox.PackStart(list, true, true, 0);

            vScrollbar = new VScrollbar(null);
            vScrollbar.ValueChanged += delegate {
                list.ForcePage((int)vScrollbar.Value);
            };

            hBox.PackStart(vScrollbar, false, false, 0);
            Add(hBox);
            ShowAll();
        }
		public DropDownBoxListWindow (IListDataProvider provider) : base(Gtk.WindowType.Popup)
		{
			this.DataProvider = provider;
			this.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
			this.TypeHint = Gdk.WindowTypeHint.Menu;
			this.BorderWidth = 1;
			
			hBox = new HBox ();
			list = new ListWidget (this);
			list.SelectItem += delegate {
				DataProvider.ActivateItem (list.Selection);
				Destroy ();
			};
			
			list.ScrollEvent += delegate(object o, ScrollEventArgs args) {
				if (args.Event.Direction == Gdk.ScrollDirection.Up) {
					vScrollbar.Value--;
				} else if (args.Event.Direction == Gdk.ScrollDirection.Down) {
					vScrollbar.Value++;
				}
			};
			list.SizeAllocated += delegate {
				QueueResize ();
			};
			list.PageChanged += HandleListPageChanged;
			hBox.PackStart (list, true, true, 0);
			
			vScrollbar = new VScrollbar (null);
			vScrollbar.ValueChanged += delegate {
				list.ForcePage ((int)vScrollbar.Value);
			};
			
			hBox.PackStart (vScrollbar, false, false, 0);
			Add (hBox);
			ShowAll ();
		}
 public DropDownBoxListWindow(IListDataProvider provider) : this(provider, WindowType.Toplevel)
 {
 }
		public DropDownBoxListWindow (IListDataProvider provider) : this (provider, WindowType.Toplevel)
		{
		}
Example #11
0
        public TemplateResult FillVariables(TemplateContext context)
        {
            var    expansion  = CodeTemplateService.GetExpansionObject(this);
            var    result     = new TemplateResult();
            var    sb         = new StringBuilder();
            int    lastOffset = 0;
            string code       = context.Document.Editor.FormatString(context.InsertPosition, context.TemplateCode);

            result.TextLinks = new List <TextLink> ();
            foreach (Match match in variableRegEx.Matches(code))
            {
                string name = match.Groups [1].Value;
                sb.Append(code.Substring(lastOffset, match.Index - lastOffset));
                lastOffset = match.Index + match.Length;
                if (string.IsNullOrEmpty(name))                    // $$ is interpreted as $
                {
                    sb.Append("$");
                }
                else if (name == "end")
                {
                    result.CaretEndOffset = sb.Length;
                }
                else if (name == "selected")
                {
                    if (!string.IsNullOrEmpty(context.SelectedText))
                    {
                        string indent    = GetIndent(sb);
                        string selection = Reindent(context.SelectedText, indent);
                        sb.Append(selection);
                    }
                }
                if (!variableDecarations.ContainsKey(name))
                {
                    continue;
                }
                TextLink link  = result.TextLinks.Find(l => l.Name == name);
                bool     isNew = link == null;
                if (isNew)
                {
                    link = new TextLink(name);
                    if (!string.IsNullOrEmpty(variableDecarations [name].ToolTip))
                    {
                        link.Tooltip = GettextCatalog.GetString(variableDecarations [name].ToolTip);
                    }
                    link.Values = new CodeTemplateListDataProvider(variableDecarations [name].Values);
                    if (!string.IsNullOrEmpty(variableDecarations [name].Function))
                    {
                        link.Values = expansion.RunFunction(context, null, variableDecarations [name].Function);
                    }
                    result.TextLinks.Add(link);
                }
                link.IsEditable   = variableDecarations [name].IsEditable;
                link.IsIdentifier = variableDecarations [name].IsIdentifier;
                if (!string.IsNullOrEmpty(variableDecarations [name].Function))
                {
                    IListDataProvider <string> functionResult = expansion.RunFunction(context, null, variableDecarations [name].Function);
                    if (functionResult != null && functionResult.Count > 0)
                    {
                        string s = (string)functionResult [functionResult.Count - 1];
                        if (s == null)
                        {
                            if (variableDecarations.ContainsKey(name))
                            {
                                s = variableDecarations [name].Default;
                            }
                        }
                        if (s != null)
                        {
                            link.AddLink(new TextSegment(sb.Length, s.Length));
                            if (isNew)
                            {
                                link.GetStringFunc = delegate(Func <string, string> callback) {
                                    return(expansion.RunFunction(context, callback, variableDecarations [name].Function));
                                };
                            }
                            sb.Append(s);
                        }
                    }
                    else
                    {
                        AddDefaultValue(sb, link, name);
                    }
                }
                else
                {
                    AddDefaultValue(sb, link, name);
                }
            }
            sb.Append(code.Substring(lastOffset, code.Length - lastOffset));

            // format & indent template code
            var data = new TextEditorData();

            data.Text = sb.ToString();
            data.Document.TextReplaced += delegate(object sender, DocumentChangeEventArgs e) {
                int delta = e.ChangeDelta;

                foreach (var link in result.TextLinks)
                {
                    link.Links = new List <TextSegment> (link.Links.AdjustSegments(e));
                }
                if (result.CaretEndOffset > e.Offset)
                {
                    result.CaretEndOffset += delta;
                }
            };

            var formatter = CodeFormatterService.GetFormatter(context.Document.Editor.Document.MimeType);

            if (formatter != null && context.Document.HasProject)
            {
                formatter.OnTheFlyFormat(context.Document, 0, data.Length);
            }

            IndentCode(data, context.LineIndent);
            result.Code = data.Text;
            data.Dispose();
            return(result);
        }
Example #12
0
		public TemplateResult FillVariables (TemplateContext context)
		{
			ExpansionObject expansion = CodeTemplateService.GetExpansionObject (this);
			TemplateResult result = new TemplateResult ();
			StringBuilder sb = new StringBuilder ();
			int lastOffset = 0;
			string code = context.TemplateCode;
			result.TextLinks = new List<TextLink> ();
			foreach (Match match in variableRegEx.Matches (code)) {
				string name = match.Groups[1].Value;
				sb.Append (code.Substring (lastOffset, match.Index - lastOffset));
				lastOffset = match.Index + match.Length;
				if (string.IsNullOrEmpty (name)) { // $$ is interpreted as $
					sb.Append ("$");
				} else if (name == "end") {
					result.CaretEndOffset = sb.Length;
				} else if (name == "selected") {
					if (!string.IsNullOrEmpty (context.SelectedText)) {
						string indent = GetIndent (sb);
						string selection = Reindent (context.SelectedText, indent);
						sb.Append (selection);
					}
				}
				if (!variableDecarations.ContainsKey (name))
					continue;
				TextLink link = result.TextLinks.Find (l => l.Name == name);
				bool isNew = link == null;
				if (isNew) {
					link         = new TextLink (name);
					if (!string.IsNullOrEmpty (variableDecarations[name].ToolTip))
						link.Tooltip = GettextCatalog.GetString (variableDecarations[name].ToolTip);
					link.Values  = new CodeTemplateListDataProvider (variableDecarations[name].Values);
					if (!string.IsNullOrEmpty (variableDecarations[name].Function)) {
						link.Values  = expansion.RunFunction (context, null, variableDecarations[name].Function);
					}
					result.TextLinks.Add (link);
				}
				link.IsEditable = variableDecarations[name].IsEditable;
				link.IsIdentifier = variableDecarations[name].IsIdentifier;
				if (!string.IsNullOrEmpty (variableDecarations[name].Function)) {
					IListDataProvider<string> functionResult = expansion.RunFunction (context, null, variableDecarations[name].Function);
					if (functionResult != null && functionResult.Count > 0) {
						string s = (string)functionResult[functionResult.Count - 1] ?? variableDecarations[name].Default;
						link.AddLink (new Segment (sb.Length, s.Length));
						if (isNew) {
							link.GetStringFunc = delegate (Func<string, string> callback) {
								return expansion.RunFunction (context, callback, variableDecarations[name].Function);
							};
						}
						sb.Append (s);
					} else {
						AddDefaultValue (sb, link, name);
					}
				} else  {
					AddDefaultValue (sb, link, name);
				}
			}
			sb.Append (code.Substring (lastOffset, code.Length - lastOffset));
			result.Code = sb.ToString ();
			return result;
		}
Example #13
0
 public void Initialize(IListDataProvider provider, ICompletionViewEventSink eventSink)
 {
     this.provider  = provider;
     this.eventSink = eventSink;
 }