static public void Show(ArrayList itemList, bool autoHide) { // check controls ScintillaControl sci = UITools.MainForm.CurSciControl; ListBox cl = completionList; try { if ((itemList == null) || (itemList.Count == 0)) { if (isActive) { Hide(); } return; } if (sci == null) { if (isActive) { Hide(); } return; } if (InfoTip.CallTipActive) { InfoTip.Hide(); } } catch (Exception ex) { ErrorHandler.ShowError("Completion list Control exception.", ex); } // state allItems = itemList; autoHideList = autoHide; word = ""; if (currentWord != null) { word = currentWord; currentWord = null; } fullList = (word.Length == 0) || !autoHide || !autoFilterList; lastIndex = 0; exactMatchInList = false; startPos = sci.CurrentPos - word.Length; currentPos = sci.CurrentPos; // lock keys isActive = true; UITools.LockControl(sci); // populate list tempo.Enabled = autoHide && (displayDelay > 0); if (tempo.Enabled) { tempo.Interval = displayDelay; } FindWordStartingWith(word); }
static public void OnUIRefresh(ScintillaControl sci) { if (sci != null && sci.IsActive) { int position = sci.CurrentPos; if (CompletionList.Active && CompletionList.CheckPosition(position)) return; if (InfoTip.CallTipActive && InfoTip.CheckPosition(position)) return; } CompletionList.Hide(); InfoTip.Hide(); }
static public void UpdateTip() { if (currentItem == null) { return; } InfoTip.Text = currentItem.Description; // update & show InfoTip InfoTip.Location = new Point(completionList.Left + completionList.Width, completionList.Top); InfoTip.AutoSize(); InfoTip.Show(); }
static public void Init(IMainForm mainForm) { /** * CONTROLS */ instance = new UITools(); UITools.mainForm = mainForm; try { CompletionList.CreateControl(mainForm); InfoTip.CreateControl(mainForm); } catch(Exception ex) { ErrorHandler.ShowError("Error while creating editor controls.", ex); } /** * SETTINGS */ if (!MainForm.MainSettings.HasKey(SETTING_DELAY_HOVER)) { MainForm.MainSettings.AddValue(SETTING_DELAY_HOVER, "1000"); } if (!MainForm.MainSettings.HasKey(SETTING_FILTER)) { MainForm.MainSettings.AddValue(SETTING_FILTER, "true"); } if (!MainForm.MainSettings.HasKey(SETTING_DELAY)) { MainForm.MainSettings.AddValue(SETTING_DELAY, "100"); } if (!MainForm.MainSettings.HasKey(SETTING_HIDE)) { MainForm.MainSettings.AddValue(SETTING_HIDE, "false"); } if (!MainForm.MainSettings.HasKey(SETTING_DETAILS)) { MainForm.MainSettings.AddValue(SETTING_DETAILS, "false"); } if (!MainForm.MainSettings.HasKey(SETTING_WRAP)) { MainForm.MainSettings.AddValue(SETTING_WRAP, "false"); } if (!MainForm.MainSettings.HasKey(SETTING_INSERTIONKEYS)) { MainForm.MainSettings.AddValue(SETTING_INSERTIONKEYS, ".()[],;!+*/%=-><"); } ReadSettings(); // always ignore these keys MainForm.IgnoredKeys.Add(Keys.Space | Keys.Control); // complete member MainForm.IgnoredKeys.Add(Keys.Space | Keys.Control|Keys.Shift); // complete method }
static public void ReplaceText(ScintillaControl sci, string tail) { if (InfoTip.CallTipActive) { InfoTip.Hide(); return; } if (completionList.SelectedIndex >= 0) { ICompletionListItem item = (ICompletionListItem)completionList.Items[completionList.SelectedIndex]; sci.SetSel(startPos, sci.CurrentPos); string replace = item.Value; if (replace != null) { sci.ReplaceSel(replace + tail); } } Hide(); }
static public void Hide() { if ((completionList != null) && isActive) { // list tempo.Enabled = false; isActive = false; fullList = false; completionList.Visible = false; if (completionList.Items.Count > 0) { completionList.Items.Clear(); } currentItem = null; allItems = null; InfoTip.Hide(); // InfoTip UITools.UnlockControl(); // unlock keys } }
static private void OnChar(ScintillaControl sci, int value) { if (sci == null) return; if (!CompletionList.Active && !InfoTip.CallTipActive) { if (OnCharAdded != null) OnCharAdded(sci, value); return; } if (lockedSciControl.IsAlive) sci = (ScintillaControl)lockedSciControl.Target; else { CompletionList.Hide(); if (OnCharAdded != null) OnCharAdded(sci, value); return; } if (InfoTip.CallTipActive) { InfoTip.OnChar(sci, value); return; } else CompletionList.OnChar(sci, value); return; }
static public bool HandleKeys(ScintillaControl sci, Keys key) { switch (key) { case Keys.Multiply: case Keys.Subtract: case Keys.Divide: case Keys.Decimal: case Keys.Add: return(false); case Keys.Right: sci.CharRight(); currentPos = sci.CurrentPos; if (sci.LineFromPosition(sci.CurrentPos) != currentLine) { Hide(); } else if (OnUpdateCallTip != null) { OnUpdateCallTip(sci, currentPos); } return(true); case Keys.Left: sci.CharLeft(); currentPos = sci.CurrentPos; if (currentPos < startPos) { Hide(); } else { if (sci.LineFromPosition(sci.CurrentPos) != currentLine) { Hide(); } else if (OnUpdateCallTip != null) { OnUpdateCallTip(sci, currentPos); } } return(true); case Keys.Back: sci.DeleteBack(); currentPos = sci.CurrentPos; if (currentPos < startPos) { Hide(); } else if (OnUpdateCallTip != null) { OnUpdateCallTip(sci, currentPos); } return(true); case Keys.Tab: case Keys.Space: return(false); default: InfoTip.Hide(); return(false); } }
static public bool HandleKeys(Keys key) { // UITools is currently broadcasting a shortcut, ignore! if (ignoreKeys) return false; // list/tip shortcut dispatching if ((key == (Keys.Control | Keys.Space)) || (key == (Keys.Shift | Keys.Control | Keys.Space))) { if (CompletionList.Active || InfoTip.CallTipActive) { UnlockControl(); CompletionList.Hide(); InfoTip.Hide(); } // offer to handle the shortcut ignoreKeys = true; KeyEvent ke = new KeyEvent(EventType.Shortcut, key); MainForm.DispatchEvent(ke); ignoreKeys = false; // if not handled: if (!ke.Handled) MainForm.CallCommand("InsertSnippet", "null"); return true; } // are we currently displaying something? if (!CompletionList.Active && !InfoTip.CallTipActive) return false; // hide if pressing Esc or Ctrl+Key combination if (!lockedSciControl.IsAlive || (key == Keys.Escape) || ((Control.ModifierKeys & Keys.Control) != 0 && Control.ModifierKeys != (Keys.Control|Keys.Alt)) ) { UnlockControl(); CompletionList.Hide(); InfoTip.Hide(); return false; } ScintillaControl sci = (ScintillaControl)lockedSciControl.Target; // chars string ks = key.ToString(); if ((ks.Length == 1) || ks.EndsWith(", Shift") || ks.StartsWith("NumPad")) { return false; } // toggle "long-description" if (key == Keys.F1) { showDetails = !showDetails; if (InfoTip.CallTipActive) InfoTip.UpdateTip(sci); else CompletionList.UpdateTip(); return true; } // switches else if (((key & Keys.ShiftKey) == Keys.ShiftKey) || ((key & Keys.ControlKey) == Keys.ControlKey) || ((key & Keys.Menu) == Keys.Menu)) { return false; } // calltip keys handler if (InfoTip.CallTipActive) return InfoTip.HandleKeys(sci, key); // completion keys handler return CompletionList.HandleKeys(sci, key); }