public static bool TriggerCodeSnippetInsertion() { if (InsertionActive) { return(false); // do no insert a snippet within a snippet! } string token = Npp.GetKeyword(Npp.CurrentPosition); var curPos = Npp.CurrentPosition; Point tokenPoints = new Point(curPos - token.Length, curPos); if (Contains(token)) { string replacement = GetTemplate(token); if (replacement != null) { int line = Npp.Line.CurrentLine; int lineStartPos = Npp.GetLine(line).Position; int horizontalOffset = tokenPoints.X - lineStartPos; //relative selection in the replacement text PrepareForIncertion(replacement, horizontalOffset, tokenPoints.X); var indic = Npp.GetIndicator(SnippetContext.IndicatorId); indic.Style = IndicatorStyle.Box; indic.ForeColor = Color.Blue; foreach (var point in LocSnippetContext.Parameters) { indic.Add(point.X, point.Y); } if (LocSnippetContext.CurrentParameter.HasValue) { Npp.SetSelection(LocSnippetContext.CurrentParameter.Value.X, LocSnippetContext.CurrentParameter.Value.Y); LocSnippetContext.CurrentParameterValue = Npp.GetTextBetween(LocSnippetContext.CurrentParameter.Value); } AutoComplete.Close(); if (LocSnippetContext.Parameters.Count <= 1) { FinalizeCurrent(); } } return(true); } return(false); }
private void DeviceInputField_PreviewKeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Down: AutoComplete.FocusNextCompletion(deviceInputFieldStack, deviceInputField); return; case Key.Escape: AutoComplete.Close(deviceInputFieldStack); return; //case Key.Up: // AutoComplete.FocusPreviousCompletion(deviceInputFieldStack); // return; default: return; } }
void OnGUI() { repaintLimiter.RecordRepaint(); if (WatchRegistry == null || watchList == null) { Init(DebugWatch.WatchRegistry.Instance); } watchCountLastUpdate = WatchRegistry.Watches.Count; if (OnGUIProcessInput()) { return; } InitStyles(); GUILayout.BeginVertical(Styles.BoxStyle); GUILayout.BeginHorizontal(); GUI.SetNextControlName("WatchName"); //int controlId = GUIUtility.GetControlID(FocusType.Passive) + 1; string addWatchTextNew = EditorGUILayout.TextField(addWatchText); if (addWatchTextNew != addWatchText) { addWatchText = addWatchTextNew; UpdateAutoComplete(); } var type = typeof(EditorGUIUtility); var field = type.GetField("s_LastControlID", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); var controlId = (int)field.GetValue(null); //GUIUtility.GetControlID(FocusType.Keyboard, //GUIContent content = new GUIContent("asdasdasd"); //addWatchText = EditorGUILayout.TextField(content, addWatchText); //int controlId = GUIUtility.GetControlID(content, FocusType.Keyboard); //GUILayout.TextArea() //GUI.Button(new Rect(), content); //addWatchText = GUILayout.TextField(addWatchText, content); //GUIUtility.hotControl //if (GUI.GetNameOfFocusedControl() == "WatchName") if (UpdateAfterAutoCompleteSelect) { UpdateAfterAutoCompleteSelect = false; GUI.FocusControl("WatchName"); GUIUtility.keyboardControl = controlId; //needs to be redefined after setting the FocusControl //var controlIdPassive = GUIUtility.GetControlID(FocusType.Passive); //var controlIdKeyboard = GUIUtility.GetControlID(FocusType.Keyboard); ////var controlIdNative = GUIUtility.GetControlID(FocusType.Native); //var tePassive = GUIUtility.GetStateObject(typeof(TextEditor), controlIdPassive); // GUIUtility.keyboardControl); //var teKeyboard = GUIUtility.GetStateObject(typeof(TextEditor), controlIdKeyboard); // GUIUtility.keyboardControl); var teo = GUIUtility.GetStateObject(typeof(TextEditor), controlId); // GUIUtility.keyboardControl); var te = (TextEditor)teo; if (te != null) { //if(te.controlID != controlId) //{ // te.controlID = controlId; //} te.SelectNone(); te.MoveLineEnd(); } } if (Event.current.type == EventType.Repaint) { if (GUIUtility.keyboardControl == controlId) { showAutoComplete = true; rectAutoComplete = GUILayoutUtility.GetLastRect(); rectAutoComplete.y += rectAutoComplete.height; rectAutoComplete.height = 100; UpdateAutoComplete(); //if (!hasFocusOnWatchField) //{ // hasFocusOnWatchField = true; // var rect = GUILayoutUtility.GetLastRect(); // rect = GUIUtility.GUIToScreenRect(rect); // rect.y += rect.height; // rect.height = 200; // Debug.Log("rect = " + rect); // if (AutoCompleteWind == null) // { // AutoCompleteWind = UnityEditor.EditorWindow.CreateWindow<AutoComplete>(); // AutoCompleteWind.ShowUtility(); // //AutoCompleteWind.ShowAsDropDown(rect, new Vector2(100, 100)); // //AutoCompleteWind = UnityEditor.EditorWindow.GetWindowWithRect<AutoComplete>(rect, true); // } // AutoCompleteWind.position = rect; // //GUI.Window(0, rect, DoMyWindow, "Allllll"); // //rect.y += rect.height; // //rect.height = 200; // //string[] l = new string[] { "allo", "allo2" }; // //EditorGUI.Popup(rect, 0, l); //} } else { if (AutoCompleteWind != null) { AutoCompleteWind.Close(); } AutoCompleteWind = null; hasFocusOnWatchField = false; //Debug.Log("keyboardControl = " + GUIUtility.keyboardControl + ", controlId = " + controlId); } } //GUIUtility. //GUIUtility.hotControl if (GUILayout.Button("Add")) { if (AutoCompleteGlobalContext.TryCreateWatch(addWatchText, addWatchText.Range(), out var w)) { WatchRegistry.AddWatch(w); } else { Debug.LogError($"Could not create watch at '{addWatchText}'"); } //if (glb.TryParseDeepest(addWatchText, ref cursor, out var ctx)) //{ // ParserUtils.TryParseAt(addWatchText, ref cursor, "."); // if(ctx.TryCreateWatch(addWatchText, cursor, out var w)) // { // WatchRegistry.AddWatch(w); // } //} } if (Event.current.type == EventType.MouseDown) { OnGUIAutoComplete(); } GUILayout.EndHorizontal(); watchList.OnGUI(GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true))); GUILayout.EndVertical(); //OnGUIAutoComplete(); if (Event.current.type != EventType.MouseDown) { OnGUIAutoComplete(); } //if (showAutoComplete) //{ // //Styles.LineEven.Draw // //EditorGUI.DrawRect(rectAutoComplete, Color.black); // //GUI.Box(rectAutoComplete, "", Styles.BoxStyle); // if (Event.current.type == EventType.Repaint) Styles.background.Draw(rectAutoComplete, GUIContent.none, false, false, false, false); // // int lineH = EditorStyles.standardFont.lineHeight; // int totH = AutoCompleteSuggestions.Count * lineH; // // AutoCompletePos = GUI.BeginScrollView(rectAutoComplete, AutoCompletePos, new Rect(0, 0, rectAutoComplete.width-20, totH), false, true); // var w = rectAutoComplete.width - 20; // Rect curRect = new Rect(0, 0, w*0.5f, lineH); // Rect curRectType = new Rect(curRect.xMax, 0, w * 0.5f, lineH); // bool even = true; // //int i = 0; // // foreach (var s in AutoCompleteSuggestions) // { // if (Event.current.type == EventType.Repaint) // { // // //if (even) // // Styles.LineEven.Draw(curRect, GUIContent.none, false, false, false, false); // //else // // Styles.LineOdd.Draw(curRect, GUIContent.none, false, false, false, false); // } // // if (curRect.Contains(Event.current.mousePosition)) // { // EditorGUI.DrawRect(curRect, GUI.skin.settings.selectionColor); // if (Event.current.type == EventType.MouseDown) // { // if (s.FieldInfo.Name == "..") // { // var cursor = addWatchText.Range(); // if (ParserUtils.TryExtractLastPathPart(addWatchText, ref cursor, out var lastPart)) // { // addWatchText = addWatchText.Substring(cursor); // } // } // else // { // // suggestion selected // if (AutoCompleteDeepestContext == AutoCompleteGlobalContext) // { // addWatchText = s.AsLocal(); // } // else // { // addWatchText = s.AddTo(AutoCompleteValidString); // } // } // //UpdateAutoComplete(); // showAutoComplete = false; // Debug.Log("Selected " + s); // UpdateAfterAutoCompleteSelect = true; // //GUIUtility.keyboardControl = controlId; // } // } // else // { // } // // GUI.Label(curRect, s.FieldInfo.Name, Styles.LabelStyle); // string sInfo =""; // //if (s.FieldInfo.IsOperator) sInfo += "[Op]"; // //if (s.TypeInfo.IsProperty) sInfo += "[Prop]"; // //if (s.TypeInfo.IsCollection) sInfo += "[Coll[" + s.TypeInfo.CollectionLenth + "]]"; // //if (s.TypeInfo.IsPropertyContainer) sInfo += "[PropCtnr]"; // if (s.TypeInfo.ValueType != null) // { // sInfo += " " + s.TypeInfo.ValueType.Name; // if (s.TypeInfo.IsCollection) sInfo += " [" + s.TypeInfo.CollectionLenth + "]"; // } else // { // sInfo += " unknown type"; // } // GUI.Label(curRectType, sInfo, Styles.LabelStyle); // // // curRect.y += lineH; // curRectType.y += lineH; // even = !even; // //++i; // } // GUI.EndScrollView(); // //} if (Event.current.type == EventType.MouseDown) { if (!rectAutoComplete.Contains(Event.current.mousePosition)) { showAutoComplete = false; } } }
/// <summary> /// Essentially, run GAM.GetDeviceId() on whatever is entered into the text field. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void SubmitDeviceId_Click(object sender, RoutedEventArgs e) { try { IsLoading = true; AutoComplete.Close(deviceInputFieldStack); if (deviceInputField.Text.Length < 1 || deviceInputField.Text.ToLower() == "enter a device id, asset id, serial number, query string or email...") { outputField.Text = "You must enter something into the field at the top."; return; } string input = deviceInputField.Text; List <BasicDeviceInfo> possibleDevices = await Task.Run(() => GAM.GetDeviceId(input)); BasicDeviceInfo deviceInfo = BasicDeviceInfo.HandleGetDeviceId(possibleDevices); Globals.ClearGlobals(); // clear the globals before adding new ones Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo); if (deviceInfo.Error) { outputField.Text = deviceInfo.ErrorText; return; } Globals.SetGlobalsFromBasicDeviceInfo(deviceInfo); NoteField.Text = !string.IsNullOrEmpty(deviceInfo.Notes) ? deviceInfo.Notes : ""; AssetIdField.Text = !string.IsNullOrEmpty(deviceInfo.AssetId) ? deviceInfo.AssetId : ""; LocationField.Text = !string.IsNullOrEmpty(deviceInfo.Location) ? deviceInfo.Location : ""; UserField.Text = !string.IsNullOrEmpty(deviceInfo.User) ? deviceInfo.User : ""; OrganizationalUnitField.Text = !string.IsNullOrEmpty(deviceInfo.OrgUnitPath) ? deviceInfo.OrgUnitPath : ""; if (!String.IsNullOrEmpty(deviceInfo.Status)) { switch (deviceInfo.Status) { case "ACTIVE": StatusActiveRadio.IsChecked = true; StatusDisabledRadio.IsEnabled = true; StatusActiveRadio.IsEnabled = true; StatusDeprovisionedRadio.IsEnabled = true; break; case "DISABLED": StatusDisabledRadio.IsChecked = true; StatusDisabledRadio.IsEnabled = true; StatusActiveRadio.IsEnabled = true; StatusDeprovisionedRadio.IsEnabled = true; break; case "DEPROVISIONED": StatusDeprovisionedRadio.IsChecked = true; StatusDeprovisionedRadio.IsEnabled = false; StatusActiveRadio.IsChecked = false; StatusActiveRadio.IsEnabled = false; StatusDisabledRadio.IsChecked = false; StatusDisabledRadio.IsEnabled = false; break; } } outputField.Text = "Found device. ID: " + deviceInfo.DeviceId + "."; if (!String.IsNullOrEmpty(deviceInfo.SerialNumber)) { outputField.Text += "\nSerial Number: " + deviceInfo.SerialNumber; } if (!String.IsNullOrEmpty(deviceInfo.LastSync)) { outputField.Text += "\nLast Sync: " + deviceInfo.LastSync; } AutoComplete.AddItemToList(input); IsLoading = false; //deviceInputField.Text = deviceId; } catch (Exception err) { Debug.CaptureRichException(err, CollectFieldsForRichException()); Debug.ShowErrorMessage(); } }
private void Page_Loaded(object sender, RoutedEventArgs e) { AutoComplete.Close(deviceInputFieldStack); }
/// <summary> /// Call this method to close all popup/autocompletion form and alike /// </summary> public static void ClosePopups() { AutoComplete.Close(); InfoToolTip.Close(); }