Пример #1
0
        public void GivenTheDropDownListAs(string dropDownList)
        {
            var expectedList = string.IsNullOrEmpty(dropDownList) ? new string[] { } : dropDownList.Split(',');
            var calc         = ScenarioContext.Current.Get <bool>("IsInCalculate");

            var context = new IntellisenseProviderContext
            {
                CaretPosition        = ScenarioContext.Current.Get <int>("cursorIndex"),
                CaretPositionOnPopup = ScenarioContext.Current.Get <int>("cursorIndex"),
                InputText            = ScenarioContext.Current.Get <string>("inputText"),
                DesiredResultSet     = calc ? IntellisenseDesiredResultSet.ClosestMatch : IntellisenseDesiredResultSet.Default,
                FilterType           = ScenarioContext.Current.Get <enIntellisensePartType>("filterType"),
                IsInCalculateMode    = calc
            };

            ScenarioContext.Current.Add("context", context);

            IIntellisenseProvider provider = ScenarioContext.Current.Get <IIntellisenseProvider>("provider");

            var getResults = provider.GetIntellisenseResults(context);
            var actualist  = getResults.Where(i => !i.IsError).Select(i => i.Name).ToArray();

            Assert.AreEqual(expectedList.Length, actualist.Length);
            CollectionAssert.AreEqual(expectedList, actualist);
        }
 public bool BeginEdit(string value)
 {
     if (this.selectedNode != null)
     {
         if (string.IsNullOrEmpty(this.selectedNode.Label))
         {
             MessageBox.Show(this, SR.NodeNameRequiredPrompt, SR.NodeNameRequiredCaption,
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else if (IsTextEditable(this.selectedNode))
         {
             // see if control has possible values that cannot be known in xsd
             IIntellisenseProvider provider = this.IntellisenseProvider;
             string text = value != null ? value : GetNodeText(this.selectedNode);
             if (provider != null)
             {
                 provider.SetContextNode(this.selectedNode);
                 if (!provider.IsValueEditable)
                 {
                     return(false);
                 }
             }
             bool cancel = false;
             text = CheckTextLength(text, out cancel);
             if (cancel)
             {
                 return(false);
             }
             this.editor.BeginEdit(text, provider, EditMode.Value, this.selectedNode.ForeColor, this.Focused);
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        public void BeginEdit(string text, IIntellisenseProvider provider, EditMode mode, Color color, bool focus)
        {
            IXmlBuilder builder = null;

            IIntellisenseList list = null;

            if (focus)
            {
                switch (mode)
                {
                case EditMode.Value:
                    builder            = provider.Builder;
                    this._cset.Builder = builder;
                    this._editor       = provider.Editor;
                    if (this._editor != null)
                    {
                        this._editor.Site = this._site;
                    }
                    list = provider.GetExpectedValues();
                    break;

                case EditMode.Name:
                    list = provider.GetExpectedNames();
                    break;
                }
            }
            this._schemaType = provider.GetSchemaType();

            if (this._editor != null)
            {
                this._currentEditor = this._editor.Editor as Control;
                _parent.Controls.Add(this._currentEditor);
                this._editor.SchemaType      = this._schemaType;
                this._currentEditor.KeyDown += new KeyEventHandler(editor_KeyDown);
                this._editor.XmlValue        = text;
            }
            else
            {
                this._currentEditor      = this._textEditor;
                this._currentEditor.Text = text;
            }

            this._currentEditor.ForeColor = color;
            PerformLayout();
            this._currentEditor.Visible = true;
            if (focus)
            {
                this._currentEditor.Focus();
                if (this._currentEditor == this._textEditor)
                {
                    this._textEditor.SelectAll();
                }

                // see if this node needs a dropdown.
                if (builder != null || (list != null && list.Count > 0))
                {
                    _cset.BeginEdit(list, this._schemaType);
                }
            }
        }
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string description)
 {
     _provider    = provider;
     _name        = name;
     _description = description;
     _isPopup     = true;
 }
Пример #5
0
        IIntellisenseProvider PerformInsertFromDropDown(object item, IIntellisenseProvider currentProvider, ref string appendText, ref bool isInsert)
        {
            var provider = currentProvider;

            if (item is IntellisenseProviderResult intellisenseProviderResult)
            {
                provider = intellisenseProviderResult.Provider;
            }

            var selectedItem = item;

            if (SelectionAdapter != null)
            {
                if (selectedItem is IDataListVerifyPart verifyPart)
                {
                    appendText = verifyPart.DisplayValue;
                }
                else
                {
                    if (selectedItem != null)
                    {
                        appendText = selectedItem.ToString();
                    }
                }

                isInsert = true;
                CloseDropDown(true, false);
            }
            return(provider);
        }
        public void EnsureIntellisenseResults(string text, bool forceUpdate, IntellisenseDesiredResultSet desiredResultSet)
        {
            if (text == null)
            {
                text = string.Empty;
            }
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                bool calculateMode = false;

                if (AllowUserCalculateMode)
                {
                    if (text.Length > 0 && text[0] == '=')
                    {
                        calculateMode = true;
                        text          = text.Substring(1);
                    }

                    IsInCalculateMode = calculateMode;
                }
                else if (IsInCalculateMode)
                {
                    calculateMode = true;
                }

                if (forceUpdate)
                {
                    IIntellisenseProvider provider = IntellisenseProvider;
                    var context = new IntellisenseProviderContext {
                        FilterType = FilterType, DesiredResultSet = desiredResultSet, InputText = text, CaretPosition = CaretIndex
                    };

                    if ((context.IsInCalculateMode = calculateMode) && AllowUserCalculateMode)
                    {
                        if (CaretIndex > 0)
                        {
                            context.CaretPosition = CaretIndex - 1;
                        }
                    }

                    IList <IntellisenseProviderResult> results = null;

                    try
                    {
                        results = provider.GetIntellisenseResults(context);
                        _intellisenseResults = results.ToList();
                    }
                    // ReSharper disable EmptyGeneralCatchClause
                    catch
                    // ReSharper restore EmptyGeneralCatchClause
                    {
                        //This try catch is to prevent the intellisense box from ever being crashed from a provider.
                        //This catch is intentionally blanks since if a provider throws an exception the intellisense
                        //box should simbly ignore that provider.
                    }
                    ProcessResults(text, results, false);
                }
            }
        }
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, bool isError)
 {
     _provider            = provider;
     _name                = name;
     _dropdownDescription = dropdownDescription;
     _description         = description;
     _isError             = isError;
 }
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, bool isError, int startIndex, int endIndex)
 {
     _provider            = provider;
     _name                = name;
     _dropdownDescription = dropdownDescription;
     _description         = description;
     _isError             = isError;
     _startIndex          = startIndex;
     _endIndex            = endIndex;
 }
Пример #9
0
        public IntellisenseService(IEnvironmentService environment, ICommandManagementService commandManagement)
        {
            externalProviders = new Dictionary <string, IIntellisenseProvider>(StringComparer.OrdinalIgnoreCase);

            commandDefinition = new CommandDefinitionIntellisenseProvider(commandManagement);
            commandList       = new CommandListIntellisenseProvider();
            command           = new CommandIntellisenseProvider(commandManagement);
            path     = new PathIntellisenseProvider();
            variable = new VariableIntellisenseService(environment);
        }
        public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, string[] arguments, string[] argumentDescriptions)
        {
            _provider = provider;
            _name = name;
            _dropdownDescription = dropdownDescription;
            _description = description;
            _arguments = arguments;
            _argumentDescriptions = argumentDescriptions;

            if(_arguments != null && _arguments.Length != 0)
            {
                List<string> args = new List<string>(_arguments);
                for(int i = args.Count - 1; i >= 0; i--)
                    if(String.IsNullOrEmpty(args[i]))
                        args.RemoveAt(i);

                _arguments = args.ToArray();
            }
        }
Пример #11
0
        void AppendText(ref string appendText, bool isInsert, ref int index, IIntellisenseProvider currentProvider)
        {
            var currentText = Text;
            var foundLength = 0;

            if (isInsert)
            {
                if (currentProvider.HandlesResultInsertion)
                {
                    var context = new IntellisenseProviderContext {
                        CaretPosition = index, InputText = currentText
                    };

                    try
                    {
                        Text = currentProvider.PerformResultInsertion(appendText, context);
                    }
                    catch
                    {
                        //This try catch is to prevent the intellisense box from ever being crashed from a provider.
                        //This catch is intentionally blanks since if a provider throws an exception the intellisense
                        //box should simply ignore that provider.
                    }

                    TextBox?.Select(context.CaretPosition, 0);
                    IsDropDownOpen = false;
                    appendText     = null;
                }
                else
                {
                    PerformResultInsertion(appendText, ref index, ref currentText, ref foundLength);
                }
            }

            if (appendText != null)
            {
                AppendText(currentText, index, appendText);
            }
        }
Пример #12
0
        public void ThenTheResultHasErrors(string p0)
        {
            var calc = ScenarioContext.Current.Get <bool>("IsInCalculate");

            var context = new IntellisenseProviderContext
            {
                CaretPosition        = ScenarioContext.Current.Get <int>("cursorIndex"),
                CaretPositionOnPopup = ScenarioContext.Current.Get <int>("cursorIndex"),
                InputText            = ScenarioContext.Current.Get <string>("inputText"),
                DesiredResultSet     = calc ? IntellisenseDesiredResultSet.ClosestMatch : IntellisenseDesiredResultSet.Default,
                FilterType           = ScenarioContext.Current.Get <enIntellisensePartType>("filterType"),
                IsInCalculateMode    = calc
            };

            ScenarioContext.Current.Add("context", context);

            IIntellisenseProvider provider = ScenarioContext.Current.Get <IIntellisenseProvider>("provider");

            var getResults = provider.GetIntellisenseResults(context);
            var actualist  = getResults.Where(i => i.IsError);

            Assert.AreEqual(!actualist.Any(), bool.Parse(p0));
        }
        public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, string[] arguments, string[] argumentDescriptions)
        {
            _provider             = provider;
            _name                 = name;
            _dropdownDescription  = dropdownDescription;
            _description          = description;
            _arguments            = arguments;
            _argumentDescriptions = argumentDescriptions;

            if (_arguments != null && _arguments.Length != 0)
            {
                List <string> args = new List <string>(_arguments);
                for (int i = args.Count - 1; i >= 0; i--)
                {
                    if (String.IsNullOrEmpty(args[i]))
                    {
                        args.RemoveAt(i);
                    }
                }

                _arguments = args.ToArray();
            }
        }
Пример #14
0
 public void RegisterExternalHelpProvider(string command, IIntellisenseProvider provider)
 {
     externalProviders[command ?? string.Empty] = provider ?? throw new ArgumentNullException(nameof(provider));
 }
Пример #15
0
 public void EnableIntellisense(IIntellisenseProvider provider)
 {
     this.IntellisenseProvider = provider;
 }
 public IsValidCalculateRule(Func <string> getValue)
     : base(getValue)
 {
     _intellisenseProvider = new CalculateIntellisenseProvider();
 }
Пример #17
0
 protected override object GetService(Type service)
 {
     if (service == typeof(UndoManager)){
         return this.undoManager;
     } else if (service == typeof(SchemaCache)) {
         return this.model.SchemaCache;
     } else if (service == typeof(TreeView)) {
         XmlTreeView view = (XmlTreeView)GetService(typeof(XmlTreeView));
         return view.TreeView;
     } else if (service == typeof(XmlTreeView)) {
         if (this.xmlTreeView1 == null) {
             this.xmlTreeView1 = this.CreateTreeView();
         }
         return this.xmlTreeView1;
     } else if (service == typeof(XmlCache)) {
         if (null == this.model)
         {
             this.model = new XmlCache((IServiceProvider)this, (ISynchronizeInvoke)this);
         }
         return this.model;
     } else if (service == typeof(Settings)){
         return this.settings;
     } else if (service == typeof(IIntellisenseProvider)) {
         if (this.ip == null) this.ip = CreateIntellisenseProvider(this.model, this);
         return this.ip;
     } else if (service == typeof(HelpProvider)) {
         return this.helpProvider1;
     } else if (service == typeof(WebProxyService)) {
         if (this.proxyService == null)
             this.proxyService = new WebProxyService((IServiceProvider)this);
         return this.proxyService;
     } else if (service == typeof(UserSettings)) {
         return new UserSettings(this.settings);
     }
     return base.GetService (service);
 }
Пример #18
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose( bool disposing )
 {
     if( disposing ) {
         if (components != null) {
             components.Dispose();
         }
         if (this.settings != null) {
             this.settings.Dispose();
             this.settings = null;
         }
         if (this.model != null) {
             this.model.Dispose();
             this.model = null;
         }
         IDisposable d = this.ip as IDisposable;
         if (d != null) {
             d.Dispose();
         }
         this.ip = null;
     }
     base.Dispose( disposing );
 }
Пример #19
0
        public FormMain()
        {
            this.settings = new Settings();
            this.model = (XmlCache)GetService(typeof(XmlCache));
            this.ip = (XmlIntellisenseProvider)GetService(typeof(XmlIntellisenseProvider));
            //this.model = new XmlCache((ISynchronizeInvoke)this);
            this.undoManager = new UndoManager(1000);
            this.undoManager.StateChanged += new EventHandler(undoManager_StateChanged);

            this.SuspendLayout();

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Separated out so we can have virtual CreateTreeView without causing WinForms designer to barf.
            InitializeTreeView();

            this.xmlTreeView1.Dock = System.Windows.Forms.DockStyle.None;
            this.xmlTreeView1.Size = this.tabPageTreeView.ClientSize;
            this.xmlTreeView1.Dock = System.Windows.Forms.DockStyle.Fill;

            this.undoLabel = this.undoToolStripMenuItem.Text;
            this.redoLabel = this.redoToolStripMenuItem.Text;

            // this.xsltViewer.SetSite(this);
            // this.dynamicHelpViewer.SetSite(this);

            CreateTabControl();

            this.ResumeLayout();

            InitializeHelp(this.helpProvider1);

            /*
            this.dynamicHelpViewer.DefaultStylesheetResource = "XmlNotepad.DynamicHelp.xslt";
            this.dynamicHelpViewer.ShowFileStrip = false;
            */

            model.FileChanged += new EventHandler(OnFileChanged);
            model.ModelChanged += new EventHandler<ModelChangedEventArgs>(OnModelChanged);

            recentFiles = new RecentFilesMenu(recentFilesToolStripMenuItem, this.comboBoxLocation);
            this.recentFiles.RecentFileSelected += new RecentFileHandler(OnRecentFileSelected);

            //this.resizer.Pane1 = this.xmlTreeView1;
            this.resizer.Pane1 = this.tabControlViews;
            this.resizer.Pane2 = this.tabControlLists;
            this.Controls.SetChildIndex(this.resizer, 0);
            this.taskList.Site = this;

            // populate default settings and provide type info.
            Font f = new Font("Courier New", 10, FontStyle.Regular);
            this.Font = f;
            this.settings["Font"] = f;
            System.Collections.Hashtable colors = new System.Collections.Hashtable();
            colors["Element"] = Color.FromArgb(0, 64, 128);
            colors["Attribute"] = Color.Maroon;
            colors["Text"] = Color.Black;
            colors["Comment"] = Color.Green;
            colors["PI"] = Color.Purple;
            colors["CDATA"] = Color.Gray;
            colors["Background"] = Color.White;
            colors["ContainerBackground"] = Color.AliceBlue;

            this.settings["Colors"] = colors;
            this.settings["FileName"] = new Uri("/",UriKind.RelativeOrAbsolute);
            this.settings["WindowBounds"] = new Rectangle(0,0,0,0);
            this.settings["TaskListSize"] = 0;
            this.settings["TreeViewSize"] = 0;
            this.settings["RecentFiles"] = new Uri[0];
            this.settings["SchemaCache"] = this.model.SchemaCache;
            this.settings["SearchLocation"] = new Point(0, 0);
            this.settings["SearchSize"] = new Size(0, 0);
            this.settings["FindMode"] = false;
            this.settings["SearchXPath"] = false;
            this.settings["SearchWholeWord"] = false;
            this.settings["SearchRegex"] = false;
            this.settings["SearchMatchCase"] = false;

            this.settings["LastUpdateCheck"] = DateTime.Now;
            this.settings["UpdateFrequency"] = TimeSpan.FromDays(20);
            this.settings["UpdateLocation"] = "http://download.microsoft.com/download/6/e/e/6eef2361-33d4-48a2-b52e-5827c7f2ad68/Updates.xml";
            this.settings["UpdateEnabled"] = true;

            this.settings["AutoFormatOnSave"] = true;
            this.settings["IndentLevel"] = 2;
            this.settings["IndentChar"] = IndentChar.Space;
            this.settings["NewLineChars"] = "\r\n";

            this.settings.Changed += new SettingsEventHandler(settings_Changed);

            // now that we have a font, override the tabControlViews font setting.
            this.xmlTreeView1.Font = this.Font;

            // Event wiring
            this.xmlTreeView1.SetSite(this);
            this.xmlTreeView1.SelectionChanged += new EventHandler(treeView1_SelectionChanged);
            this.xmlTreeView1.ClipboardChanged += new EventHandler(treeView1_ClipboardChanged);
            this.xmlTreeView1.NodeChanged += new EventHandler<NodeChangeEventArgs>(treeView1_NodeChanged);
            this.xmlTreeView1.KeyDown += new KeyEventHandler(treeView1_KeyDown);
            this.taskList.GridKeyDown += new KeyEventHandler(taskList_KeyDown);

            this.toolStripButtonUndo.Enabled = false;
            this.toolStripButtonRedo.Enabled = false;

            this.statusBarToolStripMenuItem.Checked = true;

            this.duplicateToolStripMenuItem.Enabled = false;
            this.findToolStripMenuItem.Enabled = true;
            this.replaceToolStripMenuItem.Enabled = true;

            this.DragOver += new DragEventHandler(Form1_DragOver);
            this.xmlTreeView1.TreeView.DragOver += new DragEventHandler(Form1_DragOver);
            this.DragDrop += new DragEventHandler(Form1_DragDrop);
            this.xmlTreeView1.TreeView.DragDrop += new DragEventHandler(Form1_DragDrop);
            this.AllowDrop = true;

            this.urlFormat = DataFormats.GetFormat("UniformResourceLocatorW");

            ctxcutToolStripMenuItem.Click += new EventHandler(this.cutToolStripMenuItem_Click);
            ctxcutToolStripMenuItem.ImageIndex = this.cutToolStripMenuItem.ImageIndex;
            ctxMenuItemCopy.Click += new EventHandler(this.copyToolStripMenuItem_Click);
            ctxMenuItemCopy.ImageIndex = copyToolStripMenuItem.ImageIndex;
            ctxMenuItemPaste.Click += new EventHandler(this.pasteToolStripMenuItem_Click);
            ctxMenuItemPaste.ImageIndex = pasteToolStripMenuItem.ImageIndex;
            ctxMenuItemExpand.Click += new EventHandler(this.expandToolStripMenuItem_Click);
            ctxMenuItemCollapse.Click += new EventHandler(this.collapseToolStripMenuItem_Click);

            this.toolStripMenuItemUpdate.Visible = false;
            this.toolStripMenuItemUpdate.Click += new EventHandler(toolStripMenuItemUpdate_Click);

            // now set in virtual InitializeHelp()
            //
            // helpProvider1
            //
            //this.helpProvider1.HelpNamespace = Application.StartupPath + "\\Help.chm";
            //this.helpProvider1.Site = this;

            this.ContextMenuStrip = this.contextMenu1;
            New();
        }
Пример #20
0
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, bool isError, int startIndex, int endIndex)
 {
     _provider = provider;
     _name = name;
     _dropdownDescription = dropdownDescription;
     _description = description;
     _isError = isError;
     _startIndex = startIndex;
     _endIndex = endIndex;
 }
Пример #21
0
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string description)
 {
     _provider = provider;
     _name = name;
     _description = description;
     _isPopup = true;
 }
Пример #22
0
 public IntellisenseProviderResult(IIntellisenseProvider provider, string name, string dropdownDescription, string description, bool isError)
 {
     _provider = provider;
     _name = name;
     _dropdownDescription = dropdownDescription;
     _description = description;
     _isError = isError;
 }
Пример #23
0
        public void BeginEdit(string text, IIntellisenseProvider provider, EditMode mode, Color color, bool focus)
        {
            IXmlBuilder builder = null;

            IIntellisenseList list = null;
            if (focus) {
                switch (mode) {
                    case EditMode.Value:
                        builder = provider.Builder;
                        this.cset.Builder = builder;
                        this.editor = provider.Editor;
                        if (this.editor != null) {
                            this.editor.Site = this.site;
                        }
                        list = provider.GetExpectedValues();
                        break;
                    case EditMode.Name:
                        list = provider.GetExpectedNames();
                        break;
                }
            }
            this.schemaType = provider.GetSchemaType();

            if (this.editor != null) {
                this.currentEditor = this.editor.Editor;
                parent.Controls.Add(this.currentEditor);
                this.editor.SchemaType = this.schemaType;
                this.currentEditor.KeyDown += new KeyEventHandler(editor_KeyDown);
                this.editor.XmlValue = text;
            } else {
                this.currentEditor = this.textEditor;
                this.currentEditor.Text = text;
            }

            this.currentEditor.ForeColor = color;
            PerformLayout();
            this.currentEditor.Visible = true;
            if (focus) {
                this.currentEditor.Focus();
                if (this.currentEditor == this.textEditor) {
                    this.textEditor.SelectAll();
                }

                // see if this node needs a dropdown.
                if (builder != null || (list != null && list.Count > 0)) {
                    cset.BeginEdit(list, this.schemaType);
                }
            }
        }