Inheriting from IntelliPromptMemberListItem

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by Sven Thorsen
Avatar
I need to be able to show a dialog when a IntelliPromptMemberListItem is selected from the list.

What i want is to display a dialog where the user can select a file, and the insert the path to that file in the syntax editor.

Ex. the user enters: "<file src=". I handle the trigger for "=" and add a new iten named "Select file...". When the user selects this item i want to show the select file dialog. When the dialog returns i want the returned file opath to be inserted in the document.

I've tried to inherit from IntelliPromptMemberListItem and overriding the AutoCompletePreText and AutoCompletePostText properties calling my ShowDialog method in the geter, but it seems the properties are never called by the syntax editor. Now how can I do it then?

This can hopefully be done in some way. I would think having a IntelliPromptMemberListItemBase class or something would be nice as the IntelliPromptMemberListItem class evidently has some internal thingamajiging that I can't get at.

Here's the code for my latest attempt at creating my own itemtype:

public class IntelliPromptMemberListDialogItem : IntelliPromptMemberListItem
    {
        private string _acPostText;
        private string _acPreText;
        private Form _dialog;
        private IWin32Window _owner;

        public IntelliPromptMemberListDialogItem(string text, int imageIndex, string description, 
            Form dialog, IWin32Window owner) : base (text, imageIndex, description, "", "")
        {
            _dialog = dialog;
            _owner = owner;
        }

        public void ShowDialog()
        {
            
            _dialog.ShowDialog(_owner);
            _acPreText = _dialog.Tag is string ? (string) _dialog.Tag : null;
        }

        public new string AutoCompletePostText
        {
            get
            {
                ShowDialog();
                return _acPostText;
            }
            set { _acPostText = value; }
        }

        public new string AutoCompletePreText
        {
            get
            {
                ShowDialog();
                return _acPreText;
            }
            set { _acPreText = value; }
        }
    }

Comments (6)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
By "selected" do you mean when it is highlighted or when it is highlighted AND tab is pressed (which normally accepts the selection and closes the member list)?


Actipro Software Support

Posted 18 years ago by Sven Thorsen
Avatar
In this case i mean when the user gets the dropdown, selects the item he wants to activate and presses enter to "activate" the item.

I.e. the event that triggers the syntax editor to insert text should open a dialog that returns the text to be inserted.
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, you should do this... handle the SyntaxEditor.IntelliPromptMemberListClosing event and set e.Cancel to true if that particular item is selected. Then in that event (or maybe better in the IntelliPromptMemberListClosed event), show your dialog.


Actipro Software Support

Posted 18 years ago by Sven Thorsen
Avatar
Thanks for the pointer.

It works, but there's another issue. When i do not select the item, or even press escape when the member list is visible, my code in the IntelliPromptMemberListClosed event handler still opens the dialog.

I'd expect IntelliPrompt.MemberList.SelectedItem to return null or something else if no item was selected, but it seems SelectedItem contains the item, so my check kicks in and opens the dialog.

Is there another way to check if an item was selected? Or am I maybe way off here :)

void editor_IntelliPromptMemberListClosing(object sender, CancelEventArgs e)
        {
            IntelliPromptMemberListItem item = ((SyntaxEditor) sender).IntelliPrompt.MemberList.SelectedItem;
            if (item is IntelliPromptMemberListSelectResourceDialogItem)
            {
                e.Cancel = true;
            }
        }

        void editor_IntelliPromptMemberListClosed(object sender, CancelEventArgs e)
        {
            IntelliPromptMemberListItem item = ((SyntaxEditor) sender).IntelliPrompt.MemberList.SelectedItem;
            if (item is IntelliPromptMemberListSelectResourceDialogItem)
            {
                IntelliPromptMemberListSelectResourceDialogItem dlgItem = (IntelliPromptMemberListSelectResourceDialogItem) item;
                dlgItem.ShowDialog();
                if (dlgItem.Dialog.SelectedResource != null)
                {
                    string url = dlgItem.Dialog.SelectedResource.GetFullPath();
                    url = "\"/" + url.Replace(@"\", @"/") + "\"";
                    editor.SelectedView.InsertText(url);
                }
            }
        }
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good point... hmm, how about this instead. Instead of setting e.Cancel at all, leave it alone.
Then in the Closed event, you can check that to see if it was cancelled (pressing Escape makes
it true, etc.) or not. So the only thing remaining is to make sure it doesn't insert anything.
You could probably set the pre-text of the item to "" to make it not do anything.

Try that out and let me know if it works. If not, we can tweak things for the next maintenance release.


Actipro Software Support

Posted 18 years ago by Sven Thorsen
Avatar
Worked like a charm it seems. Thanks!
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.