private void InitializeViewElements() { dialogManager = new DialogManager("NUnit Project Editor"); messageDisplay = new MessageDisplay("NUnit Project Editor"); browseProjectBaseCommand = new ButtonElement(projectBaseBrowseButton); editConfigsCommand = new ButtonElement(editConfigsButton); browseConfigBaseCommand = new ButtonElement(configBaseBrowseButton); addAssemblyCommand = new ButtonElement(addAssemblyButton); removeAssemblyCommand = new ButtonElement(removeAssemblyButton); browseAssemblyPathCommand = new ButtonElement(assemblyPathBrowseButton); projectPath = new TextElement(projectPathLabel); projectBase = new TextElement(projectBaseTextBox); processModel = new ComboBoxElement(processModelComboBox); domainUsage = new ComboBoxElement(domainUsageComboBox); runtime = new ComboBoxElement(runtimeComboBox); runtimeVersion = new ComboBoxElement(runtimeVersionComboBox); activeConfigName = new TextElement(activeConfigLabel); configList = new ComboBoxElement(configComboBox); applicationBase = new TextElement(applicationBaseTextBox); configurationFile = new TextElement(configFileTextBox); binPathType = new RadioButtonGroup("BinPathType", autoBinPathRadioButton, manualBinPathRadioButton, noBinPathRadioButton); privateBinPath = new TextElement(privateBinPathTextBox); assemblyPath = new TextElement(assemblyPathTextBox); assemblyList = new ListBoxElement(assemblyListBox); }
internal static bool SelectionIsReadOnly(IDocument document, ISelection sel) { if (document.TextEditorProperties.SupportReadOnlySegments) return document.MarkerStrategy.GetMarkers(sel.Offset, sel.Length).Exists(m=>m.IsReadOnly); else return false; }
public Game(BoardView boardView) { m_boardView = boardView; GameBoardBuilder builder = new GameBoardBuilder (); AddGameUnity (builder,Point.Make(0,4)); m_logicBoard = builder.GetBoard (); m_currentSelection = m_logicBoard.Select (Point.Make(-1,-1)); m_boardView.OnCellClicked.Register((x,y) =>{ //TODO: Usar state pattern var point = Point.Make(x,y); Debug.Log(point); if(m_currentSelection.IsEmpty) { m_currentSelection = m_logicBoard.Select(point); } else { var visitor = new WalkVisitor(point); m_currentSelection.Commands.Visit(visitor); m_boardView.AddResult(visitor.Result); m_currentSelection = m_logicBoard.Select (Point.Make(-1,-1)); } }); }
static Population AdvanceGeneration(Population population, ISelection selection, ICrossover crossover, IMutation mutation) { var chromosomes = new List<Chromosome>(); population = new Population(population.Take((int)(truncationRate * population.Count()))); // TRUNCATION chromosomes.AddRange(population.Take((int)(elitismRate * chromosomeCount))); //ELITE (assuming that the chromosomes in the population are sorted by fitness (the fitter are at the top of the list) do { Chromosome chosen1 = selection.Select(population), chosen2 = selection.Select(population); if (random.NextDouble() < crossoverRate) { var children = crossover.Crossover(chosen1, chosen2); // CROSSOVER chosen1 = children.Item1; chosen2 = children.Item2; } if (random.NextDouble() < mutationRate) { chosen1 = mutation.Mutate(chosen1); // MUTATION } if (random.NextDouble() < mutationRate) { chosen2 = mutation.Mutate(chosen2); // MUTATION } chromosomes.Add(chosen1); chromosomes.Add(chosen2); } while (chromosomes.Count < chromosomeCount); return new Population(chromosomes); }
public Population(int size, IFitnessFunction fitnessFunction, IReproduction reproductionFunction, INodeMutator mutator, ISelection selection) { this.populationSize = size; this.fitnessFunction = fitnessFunction; this.reproductionFunction = reproductionFunction; this.mutator = mutator; this.selector = selection; this.fitnessFunction.Initialise(); // Create the initial population for (int i = 0; i < size; i++) { try { NodeContext zeroContext = new NodeContext(); zeroContext.AvailableCollections = fitnessFunction.GetCollections(); zeroContext.AvailableInputs = fitnessFunction.GetInputs(); INode candidateNode = NodeFactory.GenerateNode(zeroContext); // Make sure we have a decent candidate (i.e. not too large) double fitness = this.fitnessFunction.CalculateFitness(candidateNode); if (fitness == Double.MaxValue) continue; this.population.Add(NodeFactory.GenerateNode(zeroContext)); } catch (StackOverflowException) { } } }
public FindJumpInstructionsVisitor(MethodDeclaration method, ISelection selection) { this.method = method; this.selection = selection; this.labels = new List<LabelStatement>(); this.cases = new List<CaseLabel>(); }
/// <summary> /// Constructor /// </summary> public Population(int size, IIndividual ancestor, IFitnessFunction fitnessFunction, ISelection selectionMethod, int numberIterations) { FitnessFunction = fitnessFunction; Selection = Replacement = selectionMethod; PopulationSize = size; firstSelectionCount = size; firstReplacementCount = ((int)(size / 2)) % 2 == 0 ? (int)(size / 2) : (int)(size / 2) + 1; iterations = numberIterations; // Agregar el ancestro a la poblacion ancestor.Evaluate(fitnessFunction); Individuals.Add(ancestor); // Se agregan mas cromosomas a la poblacion for (int i = 1; i < size; i++) { // Se crea un nuevo cromosoma al azar IIndividual c = ancestor.CreateRandomIndividual(); // se calcula su aptitud c.Evaluate(fitnessFunction); // Se lo agrega a la poblacion Individuals.Add(c); } }
public ProxySelection(ISelection selection) { _selection = selection; _numberOfGoodStarts = 0; _numberOfBadStarts = 0; _progressList = new List<double> { 1 }; _progress = OneHundredPercent; }
public MethodExtractorBase(ICSharpCode.TextEditor.TextEditorControl textEditor, ISelection selection) { this.currentDocument = textEditor.Document; this.textEditor = textEditor; this.currentSelection = selection; this.start = new Location(this.currentSelection.StartPosition.Column + 1, this.currentSelection.StartPosition.Line + 1); this.end = new Location(this.currentSelection.EndPosition.Column + 1, this.currentSelection.EndPosition.Line + 1); }
/// <summary> /// Constructor /// </summary> public Population(int size, IIndividual ancestor, IFitnessFunction fitnessFunction, ISelection selectionMethod, double randomSelectionPortion, int iterations) : this(size, ancestor, fitnessFunction, selectionMethod, iterations) { randomSelectionPortion = Math.Max(0, Math.Min(0.5, randomSelectionPortion)); }
public DecreaseSelection(IDocument document, ISelection selection) { if (document == null) throw new ArgumentNullException("document"); if (selection == null) throw new ArgumentNullException("selection"); this.itsDocument = document; itsOffset = selection.Offset + 1; itsEndOffset = selection.EndOffset - 1;; itsSelectedText = document.TextContent.Substring(Offset, EndOffset-Offset); }
public static IProject getProjectFromSelection(ISelection selection) { var resource = getResourceFromSelection(selection); if (resource == null) { return null; } if (resource.getType() == IResource.PROJECT) { return (IProject)resource; } else { return resource.getProject(); } }
internal static bool SelectionIsReadOnly(IDocument document, ISelection sel) { //johnny //if (document.TextEditorProperties.SupportReadOnlySegments) // return document.MarkerStrategy.GetMarkers(sel.Offset, sel.Length).Exists(m=>m.IsReadOnly); if (document.TextEditorProperties.SupportReadOnlySegments) { return document.MarkerStrategy.GetMarkers(sel.Offset, sel.Length).Exists(delegate(TextMarker m) { return m.IsReadOnly; }); } else return false; }
public static Complex[] GetComplexArrayFrom1DSelection(ISelection selection) { int size = selection.Size; var result = new Complex[size]; var i = 0; foreach(var v in selection){ result[i] = new Complex(v[0], 0); i++; } return result; }
internal static void CallAllProperties(ISelection selection) { selection.ContainsOffset(0); selection.ContainsPosition(TextLocation.Empty); int offset = selection.EndOffset; TextLocation position = selection.EndPosition; bool empty = selection.IsEmpty; bool rectangularSelection = selection.IsRectangularSelection; int length = selection.Length; int offset2 = selection.Offset; string text = selection.SelectedText; TextLocation startPosition = selection.StartPosition; }
private static ISelection ReverseSelection(ISelection selection) { var list = new ArrayList(); if (selection != null && selection.Items != null) { foreach (object o in selection.Items) list.Add(o); list.Reverse(); } return new Selection(list); }
/// <summary> /// Initialize a new instance of the ExtendBlockSelection class. /// </summary> /// <param name="document">Object that implements the IDocument interface.</param> /// <param name="selection">The current selection.</param> public ExtendBlockSelection(IDocument document, ISelection selection) { if (document == null) throw new ArgumentNullException("document"); if (selection == null) throw new ArgumentNullException("selection"); itsDocument = document; itsOffset = selection.Offset; itsEndOffset = selection.EndOffset; ExtendCurrentSelection(); }
public TwoIslandsPopulation(int size, IFitnessFunction fitnessFunction, IReproduction reproductionFunction, INodeMutator mutator, ISelection selection) { this.populationSize = size; this.fitnessFunction = fitnessFunction; this.reproductionFunction = reproductionFunction; this.mutator = mutator; this.selector = selection; this.fitnessFunction.Initialise(); // The main population needs initializing this.IntialisePopulation(this.mainPopulation); this.IntialisePopulation(this.secondaryPopulation); }
public GeneticAlgorithm(double crossoverRate, double mutationRate, double elitism, double truncation, double chromosomeCount, ISelection selection, ICrossover crossover, IMutation mutation, FitnessCalculator fitnessCalculator) { CrossoverRate = crossoverRate; MutationRate = mutationRate; ElitismRate = elitism; TruncationRate = truncation; ChromosomeCount = chromosomeCount; this.selection = selection; this.mutation = mutation; this.crossover = crossover; this.fitnessCalculator = fitnessCalculator; random = new Random(); }
public GEngine(AbstractTrack[] tracks, int pCrossingover, int pMutation, IFitnessFunction fitnessFunction, IMutation mutation, ICrossingover crossingover, ISelection selection) { _countOfPerson = tracks.Length; _tracks = new AbstractTrack[_countOfPerson]; _tracks = tracks; _pCrossingover = pCrossingover; _pMutation = pMutation; _fitnessFunction = fitnessFunction; _mutation = mutation; _crossingover = crossingover; _selection = selection; _geneticsDataSet = new DB_GeneticsDataSet(); _launchId = Guid.NewGuid(); _launchTableAdapter = new DB_GeneticsDataSetTableAdapters.LaunchesTableAdapter(); _personsTableAdapter = new DB_GeneticsDataSetTableAdapters.PersonsTableAdapter(); }
public void RunCounterTest() { _mutation = new NotRandomMutation(); _selection = new TournamentSelection(); _crossingover = new CyclicalCrossingover(); int expectCountOfGeneration = 12000; IFitnessFunction fitnessFunction = new GenerationCounter(expectCountOfGeneration); int pCrossingover = 80; int pMutation = 60; Array.Sort(_closedTracks); double preBestResult = _closedTracks[0].GetTrackLength(); GEngine target = new GEngine(_closedTracks, pCrossingover, pMutation, fitnessFunction, _mutation, _crossingover, _selection); target.Run(); Assert.AreEqual(expectCountOfGeneration, target.FitnessFunction.ActualCountOfReps); Assert.IsTrue(preBestResult >= target.FitnessFunction.BestResult); }
/// <remarks> /// Clears the selection and sets a new selection /// using the given <see cref="ISelection"/> object. /// </remarks> public void SetSelection(ISelection selection) { if (selection != null) { if (SelectionCollection.Count == 1 && selection.StartPosition == SelectionCollection[0].StartPosition && selection.EndPosition == SelectionCollection[0].EndPosition ) { return; } ClearWithoutUpdate(); selectionCollection.Add(selection); document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, selection.StartPosition.Y, selection.EndPosition.Y)); document.OnUpdateCommited(); OnSelectionChanged(EventArgs.Empty); } else { ClearSelection(); } }
void InsertTabs(IDocument document, ISelection selection, int y1, int y2) { string indentationString = GetIndentationString(document); for (int i = y2; i >= y1; --i) { LineSegment line = document.GetLineSegment(i); if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) { continue; } // this bit is optional - but useful if you are using block tabbing to sort out // a source file with a mixture of tabs and spaces // string newLine = document.GetText(line.Offset,line.Length); // document.Replace(line.Offset,line.Length,newLine); document.Insert(line.Offset, indentationString); } }
void InsertTabs(IDocument document, ISelection selection, int y1, int y2) { int redocounter = 0; string indentationString = GetIndentationString(document); for (int i = y2; i >= y1; --i) { LineSegment line = document.GetLineSegment(i); if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) { continue; } document.Insert(line.Offset, indentationString); ++redocounter; } if (redocounter > 0) { document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes) } }
public static IResource getResourceFromSelection(ISelection selection) { IResource resource = null; if (selection instanceof IStructuredSelection) { var it = ((IStructuredSelection)selection).iterator(); while (it.hasNext()) { var next = it.next(); if (next instanceof IResource) { resource = (IResource)next; } else if (next instanceof IAdaptable) { resource = (IResource)((IAdaptable)next).getAdapter(typeof(IResource)); } if (resource != null) { break; } } } return resource; }
public Polynomial Approximate(ISelection xy, int order){ var a = new Matrix(order, order); var b = new Matrix(order, 1); for (var i = 0; i < order; i++) { for (var j = 0; j < order; j++) { for (var k = 0; k < xy.Size; k++) { a[i, j] += Math.Pow(xy[k][0], i) * Math.Pow(xy[k][0], j); } } } for (var i = 0; i < order; i++) { for(var k=0; k < xy.Size; k++){ b[i, 0] += Math.Pow(xy[k][0], i) * xy[k][1]; } } ISLE sle = new SLEGausse(); return new Polynomial(sle.Solve(a, b)); }
void InsertTabs(IDocument document, ISelection selection, int y1, int y2) { int redocounter = 0; string indentationString = GetIndentationString(document); for (int i = y2; i >= y1; --i) { LineSegment line = document.GetLineSegment(i); if (i == y2 && i == selection.EndPosition.Y && selection.EndPosition.X == 0) { continue; } // this bit is optional - but useful if you are using block tabbing to sort out // a source file with a mixture of tabs and spaces // string newLine = document.GetText(line.Offset,line.Length); // document.Replace(line.Offset,line.Length,newLine); // ++redocounter; document.Insert(line.Offset, indentationString); ++redocounter; } if (redocounter > 0) { document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes) } }
public ICriteriaQuery Select(ISelection selection) { _selections.Add(selection); return(this); }
bool IDropTarget.DragLeave(DragLeaveEvent evt, IEnumerable <ISelectable> selection, IDropTarget leftTarget, ISelection dragSource) { RemoveDragIndicator(); return(true); }
public void DeleteFromSelection(ISelection selection) { Selections.Remove(selection); }
void DoubleClickSelectionExtend() { Point mousepos; mousepos = textArea.mousepos; textArea.SelectionManager.ClearSelection(); if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { marker.IsFolded = false; textArea.MotherTextAreaControl.AdjustScrollBars(); } if (textArea.Caret.Offset < textArea.Document.TextLength) { switch (textArea.Document.GetCharAt(textArea.Caret.Offset)) { case '"': if (textArea.Caret.Offset < textArea.Document.TextLength) { int next = FindNext(textArea.Document, textArea.Caret.Offset + 1, '"'); minSelection = textArea.Caret.Position; if (next > textArea.Caret.Offset && next < textArea.Document.TextLength) { next += 1; } maxSelection = textArea.Document.OffsetToPosition(next); } break; default: minSelection = textArea.Document.OffsetToPosition(FindWordStart(textArea.Document, textArea.Caret.Offset)); maxSelection = textArea.Document.OffsetToPosition(FindWordEnd(textArea.Document, textArea.Caret.Offset)); break; } textArea.Caret.Position = maxSelection; textArea.SelectionManager.ExtendSelection(minSelection, maxSelection); } if (textArea.SelectionManager.selectionCollection.Count > 0) { ISelection selection = textArea.SelectionManager.selectionCollection[0]; selection.StartPosition = minSelection; selection.EndPosition = maxSelection; textArea.SelectionManager.SelectionStart = minSelection; } // after a double-click selection, the caret is placed correctly, // but it is not positioned internally. The effect is when the cursor // is moved up or down a line, the caret will take on the column first // clicked on for the double-click textArea.SetDesiredColumn(); // HACK WARNING !!! // must refresh here, because when a error tooltip is showed and the underlined // code is double clicked the textArea don't update corrctly, updateline doesn't // work ... but the refresh does. // Mike textArea.Refresh(); } }
protected Task <string> SerializeAsync <T>(ISelection <T> selection, IExpressionTree <T> fields) where T : class { return(SerializeCorrectedFieldsAsync(new RddJsonResult <T>(selection, fields))); }
public Configuration(int selectionType, int crossType, int mutaType, int reinsertionType, int terminationType) { // Initialize(); //IMPORTANT SelectionID = selectionType; Selection = new TournamentSelection(); if (selectionType == 1) { Selection = new EliteSelection(); } else if (selectionType == 2) { Selection = new RouletteWheelSelection(); } else if (selectionType == 3) { Selection = new StochasticUniversalSamplingSelection(); } else if (selectionType == 4) { Selection = new TournamentSelection(); //check options } CrossoverID = crossType; Crossover = new UniformCrossover(0.5f); if (crossType == 1) { Crossover = new CutAndSpliceCrossover(); } else if (crossType == 2) { Crossover = new CycleCrossover(); } else if (crossType == 3) { Crossover = new OnePointCrossover(); //options swapPoint } else if (crossType == 4) { Crossover = new OrderBasedCrossover(); } else if (crossType == 5) { Crossover = new OrderedCrossover(); } else if (crossType == 6) { Crossover = new PartiallyMappedCrossover(); } else if (crossType == 7) { Crossover = new ThreeParentCrossover(); } else if (crossType == 8) { Crossover = new TwoPointCrossover(); //options SwapPoint } else if (crossType == 9) { Crossover = new UniformCrossover(0.5f); //mix probability is 5 } MutationID = mutaType; Mutation = new UniformMutation(true); if (mutaType == 1) { Mutation = new ReverseSequenceMutation(); } else if (mutaType == 2) { Mutation = new TworsMutation(); } else if (mutaType == 3) { Mutation = new UniformMutation(true); //options } ReinsertionID = reinsertionType; Reinsertion = null; if (reinsertionType == 1) { Reinsertion = new ElitistReinsertion(); } else if (reinsertionType == 2) { Reinsertion = new FitnessBasedReinsertion(); } else if (reinsertionType == 3) { Reinsertion = new PureReinsertion(); } else if (reinsertionType == 4) { Reinsertion = new UniformReinsertion(); } else if (reinsertionType == 5) { Reinsertion = null; } TerminationID = terminationType; Termination = new TimeEvolvingTermination(); if (terminationType == 1) { Termination = new GenerationNumberTermination(); } else if (terminationType == 2) { Termination = new TimeEvolvingTermination(new System.TimeSpan(0, 3, 0)); } else if (terminationType == 3) { Termination = new FitnessStagnationTermination(200); //options } else if (terminationType == 4) { Termination = new FitnessThresholdTermination(); // expected fitness } else if (terminationType == 5) { Termination = new AndTermination(); } else if (terminationType == 6) { Termination = new OrTermination(); } }
protected void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } m_Active = false; m_Dragging = false; m_AddedByMouseDown = false; if (target == null) { return; } selectionContainer = target.GetFirstAncestorOfType <ISelection>(); if (selectionContainer == null) { // Keep for potential later use in OnMouseUp (where e.target might be different then) selectionContainer = target.GetFirstOfType <ISelection>(); selectedElement = e.target as GraphElement; return; } selectedElement = target.GetFirstOfType <GraphElement>(); if (selectedElement == null) { return; } // Since we didn't drag after all, update selection with current element only if (!selectionContainer.selection.Contains(selectedElement)) { if (!e.actionKey) { selectionContainer.ClearSelection(); } selectionContainer.AddToSelection(selectedElement); m_AddedByMouseDown = true; } if (e.button == (int)activateButton) { // avoid starting a manipulation on a non movable object if (!selectedElement.IsDroppable()) { return; } // Reset drag and drop m_DragAndDropDelay.Init(e.localMousePosition); m_Active = true; target.CaptureMouse(); e.StopPropagation(); } }
private void SetSampleOperatorsToComboxes() { SetSampleOperatorToCombobox(CrossoverService.GetCrossoverTypes, m_sampleController.CreateCrossover, (c) => m_crossover = c, cmbCrossover); SetSampleOperatorToCombobox(MutationService.GetMutationTypes, m_sampleController.CreateMutation, (c) => m_mutation = c, cmbMutation); SetSampleOperatorToCombobox(SelectionService.GetSelectionTypes, m_sampleController.CreateSelection, (c) => m_selection = c, cmbSelection); SetSampleOperatorToCombobox(TerminationService.GetTerminationTypes, m_sampleController.CreateTermination, (c) => m_termination = c, cmbTermination); }
/// <summary>Sets the region to search. The region is updated /// automatically as the document changes.</summary> public void SetScanRegion(ISelection sel) { SetScanRegion(sel.Offset, sel.Length); }
/// <summary> /// Inverts the selection based on the current SelectionMode /// </summary> /// <param name="self">The ISelection to invert</param> /// <param name="region">The geographic region to reverse the selected state</param> public static bool InvertSelection(this ISelection self, Envelope region) { Envelope ignoreMe; return(self.InvertSelection(region, out ignoreMe)); }
/// <summary> /// Adds a node to the end of the list. /// </summary> public void Add(ISelection selection) { SelectionsList.Add(selection ?? throw new ArgumentNullException(nameof(selection))); }
/// <summary> /// Creates a new instance of FeatureLayerSelectionEventArgs /// </summary> public FeatureLayerSelectionEventArgs(IFeatureLayer fl, ISelection selection) : base(fl) { _selection = selection; }
void ExtendSelectionToMouse() { Point mousepos; mousepos = textArea.mousepos; TextLocation realmousepos = textArea.TextView.GetLogicalPosition( Math.Max(0, mousepos.X - textArea.TextView.DrawingPosition.X), mousepos.Y - textArea.TextView.DrawingPosition.Y); int y = realmousepos.Y; realmousepos = textArea.Caret.ValidatePosition(realmousepos); TextLocation oldPos = textArea.Caret.Position; if (oldPos == realmousepos && textArea.SelectionManager.selectFrom.where != WhereFrom.Gutter) { return; } // the selection is from the gutter if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter) { if (realmousepos.Y < textArea.SelectionManager.SelectionStart.Y) { // the selection has moved above the startpoint textArea.Caret.Position = new TextLocation(0, realmousepos.Y); } else { // the selection has moved below the startpoint textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y); } } else { textArea.Caret.Position = realmousepos; } // moves selection across whole words for double-click initiated selection if (!minSelection.IsEmpty && textArea.SelectionManager.SelectionCollection.Count > 0 && textArea.SelectionManager.selectFrom.where == WhereFrom.TArea) { // Extend selection when selection was started with double-click ISelection selection = textArea.SelectionManager.SelectionCollection[0]; TextLocation min = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? maxSelection : minSelection; TextLocation max = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? minSelection : maxSelection; if (textArea.SelectionManager.GreaterEqPos(max, realmousepos) && textArea.SelectionManager.GreaterEqPos(realmousepos, min)) { textArea.SelectionManager.SetSelection(min, max); } else if (textArea.SelectionManager.GreaterEqPos(max, realmousepos)) { int moff = textArea.Document.PositionToOffset(realmousepos); min = textArea.Document.OffsetToPosition(FindWordStart(textArea.Document, moff)); textArea.SelectionManager.SetSelection(min, max); } else { int moff = textArea.Document.PositionToOffset(realmousepos); max = textArea.Document.OffsetToPosition(FindWordEnd(textArea.Document, moff)); textArea.SelectionManager.SetSelection(min, max); } } else { textArea.SelectionManager.ExtendSelection(oldPos, textArea.Caret.Position); } textArea.SetDesiredColumn(); }
/// <summary> /// Adds a node to the start of the list. /// </summary> public void Prepend(ISelection selection) { SelectionsList.Insert(0, selection ?? throw new ArgumentNullException(nameof(selection))); }
public override void Draw(object dc, ShapeRenderer renderer, BaseShape shape, ISelection selection, double dx, double dy) { }
void RemoveTabs(IDocument document, ISelection selection, int y1, int y2) { int redocounter = 0; for (int i = y2; i >= y1; --i) { LineSegment line = document.GetLineSegment(i); if (i == y2 && line.Offset == selection.EndOffset) { continue; } if (line.Length > 0) { /**** TextPad Strategy: * /// first convert leading whitespace to tabs (controversial! - not all editors work like this) * string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset,line.Length),document.Properties.Get("TabIndent", 4)); * if(newLine.Length > 0 && newLine[0] == '\t') { * document.Replace(line.Offset,line.Length,newLine.Substring(1)); ++redocounter; * } * else if(newLine.Length > 0 && newLine[0] == ' ') { * /// there were just some leading spaces but less than TabIndent of them * int leadingSpaces = 1; * for(leadingSpaces = 1; leadingSpaces < newLine.Length && newLine[leadingSpaces] == ' '; leadingSpaces++) { * /// deliberately empty * } * document.Replace(line.Offset,line.Length,newLine.Substring(leadingSpaces)); ++redocounter; * } * /// else * /// there were no leading tabs or spaces on this line so do nothing * /// MS Visual Studio 6 strategy: ****/ // string temp = document.GetText(line.Offset,line.Length); if (line.Length > 0) { int charactersToRemove = 0; if (document.GetCharAt(line.Offset) == '\t') // first character is a tab - just remove it { charactersToRemove = 1; } else if (document.GetCharAt(line.Offset) == ' ') { int leadingSpaces = 1; int tabIndent = document.TextEditorProperties.TabIndent; for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++) { // deliberately empty } if (leadingSpaces >= tabIndent) { // just remove tabIndent charactersToRemove = tabIndent; } else if (line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t') { // remove the leading spaces and the following tab as they add up // to just one tab stop charactersToRemove = leadingSpaces + 1; } else { // just remove the leading spaces charactersToRemove = leadingSpaces; } } if (charactersToRemove > 0) { document.Remove(line.Offset, charactersToRemove); ++redocounter; } } } } if (redocounter > 0) { document.UndoStack.UndoLast(redocounter); // redo the whole operation (not the single deletes) } }
public void SortSelection(ISelection selection) { Selections.Sort(); }
public JumpToSelectedActorsHotkeyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, World world, Dictionary <string, MiniYaml> logicArgs) : base(widget, modData, "JumpToSelectedActorsKey", "WORLD_KEYHANDLER", logicArgs) { viewport = worldRenderer.Viewport; selection = world.Selection; }
public void SelectionChanged(IAction action, ISelection selection) { }
public void ExtendSelection(Point oldPosition, Point newPosition) { if (oldPosition == newPosition) { Console.WriteLine("BLUB"); return; } Point min; Point max; bool oldIsGreater = GreaterEqPos(oldPosition, newPosition); if (oldIsGreater) { min = newPosition; max = oldPosition; } else { min = oldPosition; max = newPosition; } if (!HasSomethingSelected) { SetSelection(new DefaultSelection(document, min, max)); Console.WriteLine("SET"); return; } ISelection selection = this.selectionCollection[0]; bool changed = false; if (selection.ContainsPosition(newPosition)) { if (oldIsGreater) { if (selection.EndPosition != newPosition) { selection.EndPosition = newPosition; changed = true; } } else { if (selection.StartPosition != newPosition) { selection.StartPosition = newPosition; changed = true; } } } else { if (oldPosition == selection.StartPosition) { if (GreaterEqPos(newPosition, selection.EndPosition)) { if (selection.StartPosition != selection.EndPosition || selection.EndPosition != newPosition) { selection.StartPosition = selection.EndPosition; selection.EndPosition = newPosition; changed = true; } } else { if (selection.StartPosition != newPosition) { selection.StartPosition = newPosition; changed = true; } } } else { if (GreaterEqPos(selection.StartPosition, newPosition)) { if (selection.EndPosition != selection.StartPosition || selection.StartPosition != newPosition) { changed = true; } selection.EndPosition = selection.StartPosition; selection.StartPosition = newPosition; changed = true; } else { if (selection.EndPosition != newPosition) { selection.EndPosition = newPosition; changed = true; } } } } if (changed) { document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, min.Y, max.Y)); document.OnUpdateCommited(); OnSelectionChanged(EventArgs.Empty); } }
bool IDropTarget.DragEnter(DragEnterEvent evt, IEnumerable <ISelectable> selection, IDropTarget enteredTarget, ISelection dragSource) { return(true); }
protected static bool IsInSel(Location location, ISelection sel) { bool result = (sel.ContainsPosition(new ICSharpCode.TextEditor.TextLocation(location.Column - 1, location.Line - 1))); return(result); }
public SelectParents(int replaceByGeneration, ISelection <T> selection) { ReplaceByGeneration = replaceByGeneration; Selection = selection; }
void Initialize() { this._selectionPattern = new SelectionImplementation <SelectionSliderItem>(uiObject: this, itemFactory: SelectionSliderItem.Factory); }
public void ExtendSelection(TextLocation oldPosition, TextLocation newPosition) { // where oldposition is where the cursor was, // and newposition is where it has ended up from a click (both zero based) if (oldPosition == newPosition) { return; } TextLocation min; TextLocation max; int oldnewX = newPosition.X; bool oldIsGreater = GreaterEqPos(oldPosition, newPosition); if (oldIsGreater) { min = newPosition; max = oldPosition; } else { min = oldPosition; max = newPosition; } if (min == max) { return; } if (!HasSomethingSelected) { SetSelection(new DefaultSelection(document, min, max)); // initialise selectFrom for a cursor selection if (selectFrom.where == WhereFrom.None) { SelectionStart = oldPosition; //textArea.Caret.Position; } return; } ISelection selection = this.selectionCollection[0]; if (min == max) { //selection.StartPosition = newPosition; return; } else { // changed selection via gutter if (selectFrom.where == WhereFrom.Gutter) { // selection new position is always at the left edge for gutter selections newPosition.X = 0; } if (GreaterEqPos(newPosition, SelectionStart)) // selecting forward { selection.StartPosition = SelectionStart; // this handles last line selection if (selectFrom.where == WhereFrom.Gutter) //&& newPosition.Y != oldPosition.Y) { selection.EndPosition = new TextLocation(textArea.Caret.Column, textArea.Caret.Line); } else { newPosition.X = oldnewX; selection.EndPosition = newPosition; } } else // selecting back { if (selectFrom.where == WhereFrom.Gutter && selectFrom.first == WhereFrom.Gutter) { // gutter selection selection.EndPosition = NextValidPosition(SelectionStart.Y); } else // internal text selection { selection.EndPosition = SelectionStart; //selection.StartPosition; } selection.StartPosition = newPosition; } } document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, min.Y, max.Y)); document.CommitUpdate(); OnSelectionChanged(EventArgs.Empty); }
bool SelectionsOverlap(ISelection s1, ISelection s2) { return((s1.Offset <= s2.Offset && s2.Offset <= s1.Offset + s1.Length) || (s1.Offset <= s2.Offset + s2.Length && s2.Offset + s2.Length <= s1.Offset + s1.Length) || (s1.Offset >= s2.Offset && s1.Offset + s1.Length <= s2.Offset + s2.Length)); }
public override bool CanHandle(ISelection selection) => selection.Field.Member is {
public void AddToSelection(ISelection selection) { Selections.Add(selection); }
// subscribe will use the subscribe resolver to create a source stream that yields // the event messages from the underlying pub/sub-system. private async ValueTask <ISourceStream> SubscribeAsync() { OperationContext operationContext = _operationContextPool.Get(); try { // first we will create the root value which essentially // is the subscription object. In some cases this object is null. object?rootValue = RootValueResolver.Resolve( _requestContext, _requestContext.Services, _subscriptionType, ref _cachedRootValue); // next we need to initialize our operation context so that we have access to // variables services and other things. // The subscribe resolver will use a noop dispatcher and all DataLoader are // dispatched immediately. operationContext.Initialize( _requestContext, _requestContext.Services, NoopBatchDispatcher.Default, _requestContext.Operation !, rootValue, _requestContext.Variables !); // next we need a result map so that we can store the subscribe temporarily // while executing the subscribe pipeline. ResultMap resultMap = operationContext.Result.RentResultMap(1); ISelection rootSelection = _rootSelections.Selections[0]; // we create a temporary middleware context so that we can use the standard // resolver pipeline. var middlewareContext = new MiddlewareContext(); middlewareContext.Initialize( operationContext, rootSelection, resultMap, 1, rootValue, Path.New(rootSelection.ResponseName), ImmutableDictionary <string, object?> .Empty); // it is important that we correctly coerce the arguments before // invoking subscribe. if (!rootSelection.Arguments.TryCoerceArguments( middlewareContext.Variables, middlewareContext.ReportError, out IReadOnlyDictionary <NameString, ArgumentValue>?coercedArgs)) { // the middleware context reports errors to the operation context, // this means if we failed, we need to grab the coercion errors from there // and just throw a GraphQLException. throw new GraphQLException(operationContext.Result.Errors); } // if everything is fine with the arguments we still need to assign them. middlewareContext.Arguments = coercedArgs; // last but not least we can invoke the subscribe resolver which will subscribe // to the underlying pub/sub-system yielding the source stream. ISourceStream sourceStream = await rootSelection.Field.SubscribeResolver !.Invoke(middlewareContext) .ConfigureAwait(false); if (operationContext.Result.Errors.Count > 0) { // again if we have any errors we will just throw them and not opening // any subscription context. throw new GraphQLException(operationContext.Result.Errors); } return(sourceStream); } finally { operationContext.Result.DropResult(); _operationContextPool.Return(operationContext); } }
/// <remarks> /// Returns true if <code>selection</code> is read only /// </remarks> public bool IsReadOnly(ISelection selection, bool defaultReadOnly) { int startLine = selection.StartPosition.Y; int endLine = selection.EndPosition.Y; foreach (CustomLine customLine in lines) { if (customLine.ReadOnly == false) continue; if (startLine < customLine.StartLineNr && endLine < customLine.StartLineNr) continue; if (startLine > customLine.EndLineNr && endLine > customLine.EndLineNr) continue; return true; } return defaultReadOnly; }
public override void Move(ISelection selection, double dx, double dy) { throw new NotImplementedException(); }