/// <summary> /// Execution of refactoring starts here. Data from context is initialized. /// </summary> public override bool Initialize(IDataContext context) { IParameter parameter; IMethod method; if (!IsAvailableInternal(context, out parameter, out method)) { return(false); } // Never reference DeclaredElements, References, Types, etc. from workflow. Use pointers! // Code can be edited during execution end elements (types, references) can be invalidated. MethodPointer = method.CreateElementPointer(); ParameterPointer = parameter.CreateElementPointer(); // use also: // PsiManager.GetInstance(Solution).CreateReferencePointer(...); // PsiManager.GetInstance(Solution).CreateTreeElementPointer(...); // following code produces name for type parameter using parameter name... NamingManager namingManager = method.GetPsiServices().Naming; var suggestionOptions = new SuggestionOptions { DefaultName = "T" }; TypeParameterName = namingManager.Suggestion.GetDerivedName(parameter, NamedElementKinds.TypeParameters, ScopeKind.Common, parameter.PresentationLanguage, suggestionOptions, null); return(true); }
/// <summary> /// Paste questions in certain position /// </summary> /// <param name="position">Position to paste questions</param> private void OnPasteQuestions(Point position) { this.ClearSelection(); // for the case when mouse position was out of UI change start position if (position.X < 0 || position.Y < 0) { position.X = position.Y = 30; } // calculate delta between topmost item and paste position BaseQuestionViewModel topmostItem = this.copiedQuestionsBuffer.OrderByDescending(x => x.Top).Last(); double deltaTop = topmostItem.Top - position.Y; double deltaLeft = topmostItem.Left - position.X; // buffer for undo/redo BaseQuestionViewModel[] copiedElements = new BaseQuestionViewModel[this.copiedQuestionsBuffer.Count]; for (int i = 0; i < this.copiedQuestionsBuffer.Count; i++) { // create new copy and update name and position BaseQuestionViewModel copy = this.copiedQuestionsBuffer[i].CreateCopy(); copy.Name = NamingManager.GetNextAvailableElementName(this.PageQuestions); copy.Top -= deltaTop; copy.Left -= deltaLeft; this.OnAddQuestion(copy); copy.IsSelected = true; copiedElements[i] = copy; } ActionTracker.TrackAction(new AddElementsAction(copiedElements, this.PageQuestions)); }
public static void ReplaceIdentifier([CanBeNull] this IFSharpIdentifier fsIdentifier, string name) { var token = fsIdentifier?.IdentifierToken; if (token == null) { return; } name = NamingManager.GetNamingLanguageService(fsIdentifier.Language).MangleNameIfNecessary(name); using (WriteLockCookie.Create(fsIdentifier.IsPhysical())) LowLevelModificationUtil.ReplaceChildRange(token, token, new FSharpIdentifierToken(name)); }
//default initialization of Singleton instance void Awake() { //Check if instance already exists if (i == null) { //if not, set instance to this i = this; } //If instance already exists and it's not this: else if (i != this) { //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of it. //Sets this to not be destroyed when reloading scene DontDestroyOnLoad(gameObject); } }
void IChangeNamingRuleWindowProvider.ShowSettingsDialog(string ruleName, NamingPolicy policyToChange, IDeclaredElement declaredElement, IPsiSourceFile psiSourceFile, ITextControl textControl, NamingManager namingManager, IUIApplicationSimple uiApplicationSimple, ISolution solution) { if (declaredElement is IField field && myUnityApi.IsSerialisedField(field)) { var optionsDialogOwner = solution.TryGetComponent <IOptionsDialogViewOwner>(); if (optionsDialogOwner != null) { Logger.Catch(() => optionsDialogOwner.Show(page: UnityOptionsPage.Name)); return; } } base.ShowSettingsDialog(ruleName, policyToChange, declaredElement, psiSourceFile, textControl, namingManager, uiApplicationSimple, solution); }
public static string SuggestShortReferenceName([NotNull] IReference reference, [NotNull] IDeclaredElement declaredElement) { var sourceName = declaredElement.GetSourceName(); var treeNode = reference.GetTreeNode(); if (declaredElement is ITypeElement) { var referenceName = treeNode as ITypeReferenceName; if (AttributeNavigator.GetByReferenceName(referenceName) != null && sourceName.EndsWith(FSharpImplUtil.AttributeSuffix, StringComparison.Ordinal) && sourceName != FSharpImplUtil.AttributeSuffix) { sourceName = sourceName.TrimFromEnd(FSharpImplUtil.AttributeSuffix); } } return(NamingManager.GetNamingLanguageService(treeNode.Language).MangleNameIfNecessary(sourceName)); }
/// <summary> /// Add new element via selection rectangle /// </summary> /// <param name="area">Element area</param> public void AddQuestion(Rect area) { string nextName = NamingManager.GetNextAvailableElementName(this.PageQuestions); BaseQuestionViewModel newQuestion; if (this.IsAddingChoiceBox) { newQuestion = new ChoiceBoxViewModel(nextName, area); this.IsAddingChoiceBox = false; } else { newQuestion = new GridViewModel(nextName, area); this.IsAddingGrid = false; } this.OnAddQuestion(newQuestion); newQuestion.IsSelected = true; ActionTracker.TrackAction(new AddElementsAction(new[] { newQuestion }, this.PageQuestions)); }
public static string SuggestShortReferenceName(string sourceName, PsiLanguageType language) => NamingManager.GetNamingLanguageService(language).MangleNameIfNecessary(sourceName);