/// <summary> /// Called when a bar has closed. /// </summary> protected virtual void OnBarUnloaded(object sender, EventArgs?args = null) { if (sender is PrimaryBarWindow window) { this.BarUnloaded?.Invoke(this, new BarEventArgs(window)); } }
private void LogForm_Load(object?sender, EventArgs?e) { _parent.LocationChanged += Parent_Move; _parent.SizeChanged += Parent_Move; _parent.Activated += Parent_Activated; _parent.VisibleChanged += Parent_VisibleChanged; }
/// <summary>Когда операция отменяется</summary> /// <param name="e">Аргумент события</param> protected virtual void OnCancelled(EventArgs?e) { if (!_IsDisposed) { Cancelled?.Invoke(this, e ?? EventArgs.Empty); } }
/// <summary> /// Send message, mark all as read /// </summary> private async void OnTextCompleted(object?sender = null, EventArgs?args = null) { var text = popupEntryView.Text; if (string.IsNullOrEmpty(text)) { return; } popupEntryView.Completed -= OnTextCompleted; activityIndicator.IsVisible = true; await dialogsManager.SetDialogAndMessagesReadAndPublish(dialogId); await NetExceptionCatchHelpers.CatchNetException( async() => { await messagesManager.SendMessage(dialogId, text, null); popupEntryView.Text = string.Empty; }, () => { OnTextCompleted(); return(Task.CompletedTask); }, LocalizedStrings.SendMessageNoInternetError); activityIndicator.IsVisible = false; popupEntryView.Completed += OnTextCompleted; }
private async void MoveToResource(object?sender, EventArgs?e) { await EnsureLoadedAsync().ConfigureAwait(false); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { var entry = await ExportProvider.GetExportedValue <IRefactorings>().MoveToResourceAsync().ConfigureAwait(true); if (entry == null) { return; } if (!Properties.Settings.Default.MoveToResourceOpenInResXManager) { return; } ShowToolWindow(); ExportProvider.GetExportedValue <IVsixShellViewModel>().SelectEntry(entry); } catch (Exception ex) { Tracer.TraceError(ex.ToString()); } }
public RaiseTests() { this.foo = A.Fake <IFoo>(); this.foo.SomethingHappened += this.Foo_SomethingHappened; this.sender = null; this.eventArguments = null; }
public static void Add() { var source = new ObservableCollection <int>(); using var modelView = source.AsMappingView(Collections.ReadOnlyViews.MappingViewTests.Model.Create); using var modelViewChanges = modelView.SubscribeAll(); using var indexedView = modelView.AsMappingView( Collections.ReadOnlyViews.MappingViewTests.Vm.Create, (x, i) => x); using var indexedChanges = indexedView.SubscribeAll(); using var vmView = modelView.AsMappingView(Collections.ReadOnlyViews.MappingViewTests.Vm.Create); using var vmViewChanges = vmView.SubscribeAll(); source.Add(1); var expected = new EventArgs?[] { CachedEventArgs.CountPropertyChanged, CachedEventArgs.IndexerPropertyChanged, null, }; expected[2] = Diff.CreateAddEventArgs(modelView[0], 0); CollectionAssert.AreEqual(expected, modelViewChanges, EventArgsComparer.Default); expected[2] = Diff.CreateAddEventArgs(vmView[0], 0); CollectionAssert.AreEqual(expected, vmViewChanges, EventArgsComparer.Default); expected[2] = Diff.CreateAddEventArgs(indexedView[0], 0); CollectionAssert.AreEqual(expected, indexedChanges, EventArgsComparer.Default); }
public static void Remove() { var source = new ObservableCollection <int> { 1 }; using var modelView = source.AsMappingView(Collections.ReadOnlyViews.MappingViewTests.Model.Create); using var modelViewChanges = modelView.SubscribeAll(); using var vmView = modelView.AsMappingView(Collections.ReadOnlyViews.MappingViewTests.Vm.Create); using var vmViewChanges = vmView.SubscribeAll(); var oldModel = modelView[0]; var oldView = vmView[0]; source.Remove(1); var expected = new EventArgs?[] { CachedEventArgs.CountPropertyChanged, CachedEventArgs.IndexerPropertyChanged, null, }; expected[2] = Diff.CreateRemoveEventArgs(oldModel, 0); CollectionAssert.AreEqual(expected, modelViewChanges, EventArgsComparer.Default); expected[2] = Diff.CreateRemoveEventArgs(oldView, 0); CollectionAssert.AreEqual(expected, vmViewChanges, EventArgsComparer.Default); }
private void btnOk_Click(object?sender, EventArgs?e) { DialogResult = DialogResult.OK; if (int.TryParse(txtMessageCount.Text, out var count)) { Count = count; } Peek = btnPeek.Checked; All = btnAll.Checked; if (cboReceiverInspector.SelectedIndex > 0) { Inspector = cboReceiverInspector.Text; } if (txtFromSequenceNumber.Enabled && !string.IsNullOrEmpty(txtFromSequenceNumber.Text)) { if (long.TryParse(txtFromSequenceNumber.Text, out var fromSequenceNumber)) { FromSequenceNumber = fromSequenceNumber; } } if (!string.IsNullOrEmpty(txtFromSession.Text)) { FromSession = txtFromSession.Text; } Close(); }
private void RemarkTextBox_TextChanged(object?sender, EventArgs?e) { BeginInvoke(new Action(() => { FilenameTextBox.Text = FilenameTextBox.Text = ModeEditorUtils.GetCustomModeRelativePath(RemarkTextBox.Text); })); }
#pragma warning disable VSTHRD100 // Avoid async void methods private async void MoveToResource(object?sender, EventArgs?e) #pragma warning restore VSTHRD100 // Avoid async void methods { FindToolWindow(); if (!Microsoft.VisualStudio.Shell.ThreadHelper.CheckAccess()) { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); } try { var entry = await ExportProvider.GetExportedValue <IRefactorings>().MoveToResourceAsync(Dte.ActiveDocument).ConfigureAwait(true); if (entry == null) { return; } if (!Properties.Settings.Default.MoveToResourceOpenInResXManager) { return; } ExportProvider.GetExportedValue <VsixShellViewModel>().SelectEntry(entry); } catch (Exception ex) { Tracer.TraceError(ex.ToString()); } }
public static void GetMessageHeaders(EventArgs?eventArgs, out IServiceRemotingRequestEventArgs?requestEventArgs, out IServiceRemotingRequestMessageHeader?messageHeaders) { requestEventArgs = null; messageHeaders = null; if (eventArgs == null) { Log.Warning("Unexpected null EventArgs."); return; } try { requestEventArgs = eventArgs.DuckAs <IServiceRemotingRequestEventArgs>(); messageHeaders = requestEventArgs?.Request?.GetHeader(); } catch (Exception ex) { Log.Error(ex, "Error accessing request headers."); return; } if (messageHeaders == null) { Log.Warning("Cannot access request headers."); } }
private async void ShowSelectedResourceFiles(object?sender, EventArgs?e) { try { var selectedResourceEntities = (await GetSelectedResourceEntitiesAsync().ConfigureAwait(false))?.Distinct().ToArray(); if (selectedResourceEntities == null) { return; } await JoinableTaskFactory.SwitchToMainThreadAsync(); // if we open the window the first time, make sure it does not select all entities by default. var settings = View.Properties.Settings.Default; settings.AreAllFilesSelected = false; settings.ResourceFilter = string.Empty; var selectedEntities = ExportProvider.GetExportedValue <ResourceViewModel>().SelectedEntities; selectedEntities.Clear(); selectedEntities.AddRange(selectedResourceEntities); ShowToolWindow(); } catch (Exception ex) { Tracer.TraceError("ShowSelectedResourceFiles failed: " + ex); } }
private void GridColumnWidthChanged(object?sender, EventArgs?e) { if (!_loaded) { return; } if (sender is GridViewColumn gridViewColumn) { // suppress column resizing for proportional and fixed columns if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn)) { return; } // ensure range column within the bounds if (RangeColumn.IsRangeColumn(gridViewColumn)) { // special case: auto column width - maybe conflicts with min/max range if (gridViewColumn.Width.Equals(double.NaN)) { _autoSizedColumn = gridViewColumn; return; // handled by the change header size event } // ensure column bounds if (Math.Abs(SetRangeColumnToBounds(gridViewColumn) - 0) > ZeroWidthRange) { return; } } } DoResizeColumns(); }
// Handler static void ResizeColumns(object?sender, EventArgs?e) { if (!(sender is DataGrid grid)) { return; } var widths = grid.Columns.Select(x => x.Width).ToList(); var total_width = grid.ActualWidth; if (double.IsNaN(total_width)) { return; } foreach (var(col, i) in grid.Columns.WithIndex()) { if (widths[i].UnitType == DataGridLengthUnitType.Pixel) { col.Width = widths[i]; } else { col.Width = new DataGridLength(widths[i].Value, DataGridLengthUnitType.Star); } } }
/// <summary> /// Check if all child jobs are finished; if so, mark this job as finished. /// </summary> private void OnChildJobStateChanged(object?sender, EventArgs?arguments) { if (JobStateInfo.State == JobState.NotStarted || JobStateInfo.State == JobState.Suspended) { SetJobState(JobState.Running); } if (_jobMode == TaskJobMode.Consecutive || _jobMode == TaskJobMode.ConsecutiveStopAtFailure) { // if no jobs are running, start the next queued job if (ChildJobs.All(j => j.IsFinished() || j.JobStateInfo.State == JobState.NotStarted)) { if (_queue != null) { if (_jobMode == TaskJobMode.ConsecutiveStopAtFailure && ChildJobs.Any(j => j.JobStateInfo.State == JobState.Failed)) { while (_queue.TryDequeue(out var failJob)) { failJob.Fail(); } } else { if (_queue.TryDequeue(out var nextJob)) { nextJob.StartJob(); } } } } } if (_acceptingChildJobs) { // do not conclude if more jobs may be added SetJobState(JobState.Suspended); return; } if (this.IsFinished()) { return; } var childJobs = ChildJobs.Cast <TaskChildJob>(); if (childJobs.All(j => j.IsCompleted)) { if (childJobs.Any(j => j.IsFaulted && !j.IsCanceled)) { SetJobState(JobState.Failed); } else if (childJobs.Any(j => j.IsCanceled)) { SetJobState(JobState.Stopped); } else { SetJobState(JobState.Completed); } } }
private void UpdateStartPositionEventHandler(object?sender, EventArgs?e) { if (StartNode != null) { Point arrowPos = StartNode !.GetBottomArrowAttachPoint(); (X1, Y1) = arrowPos; } }
private void UpdateEndPositionEventHandler(object?sender, EventArgs?e) { if (EndNode != null) { Point arrowPos = EndNode !.GetTopArrowAttachPoint(); (X2, Y2) = arrowPos; } }
private void HandleChannelBasicRecoverOk(object sender, EventArgs? @event) { if (@event is null) { return; } _loggingService.LogInformation("Connection has been reestablished"); }
private void Parent_Move(object?sender, EventArgs?e) { var cl = Location; var fl = _parent.Location; cl.X = fl.X + _parent.Width; cl.Y = fl.Y; Location = cl; }
void OnValueChanged(object?sender, EventArgs?e) { SetVirtualViewDate(); if (VirtualView != null) { VirtualView.IsFocused = true; } }
private static void ServiceRemotingServiceEvents_SendResponse(object?sender, EventArgs?e) { if (!_initialized || !Tracer.Instance.Settings.IsIntegrationEnabled(ServiceRemotingConstants.IntegrationId)) { return; } ServiceRemotingHelpers.FinishSpan(e, SpanKinds.Server); }
public void HandleEventCallback(string eventName, string argsAsJson) { if (eventName == null) { Console.WriteLine($"[WARN] Invalid event-name was passed from javascript."); return; } if (!_eventHandlerMapping.TryGetValue(eventName, out var eventArgsCallbackMapping)) { Console.WriteLine($"[WARN] Invalid event-name \"{eventName}\" was passed from javascript. No event-handlers registered."); return; } foreach (var curItem in eventArgsCallbackMapping) { EventArgs?parsedArgs = null; if (curItem.Key == typeof(EventArgs)) { // Ignore deserializing if user specified type "EventArgs" // -> User doesn't care for any arguments parsedArgs = EventArgs.Empty; } else if (string.IsNullOrEmpty(argsAsJson)) { Console.WriteLine($"[WARN] Passed argument-string from javascript cannot be deserialized. Skipping {curItem.Value.Count} event-handlers ..."); continue; } else { try { parsedArgs = JsonSerializer.Deserialize(argsAsJson, curItem.Key) as EventArgs; } catch (JsonException) { Console.WriteLine($"[WARN] Arguments for event \"{eventName}\" couldn't be deserialized to .NET type \"{curItem.Key.FullName}\". Skipping {curItem.Value.Count} event-handlers ..."); continue; } } // Invoke all callbacks/event-handler foreach (var curHandler in curItem.Value) { try { curHandler.Invoke(parsedArgs); } catch (Exception) { Console.WriteLine($"[WARN] An exception occured during executing an event-handler for event \"{eventName}\"."); } } } }
private void SairButton_Click(object?sender, EventArgs?e) { Main f1 = (Main)Application.OpenForms["Main"]; FormClosingEventArgs e1 = new FormClosingEventArgs(CloseReason.MdiFormClosing, true); if (MessageBox.Show("Sair do sistema?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { f1.Main_FormClosing(this, e1); } }
private void richTextBox1_TextChanged(object?sender, EventArgs?e) { if (!checkBox1.Checked) { return; } richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); }
private void CreatePopup(object?s = null, EventArgs?e = null) { refreshingPopup?.Dismiss(); refreshingPopup = new InformationPopup { IsProgressRunning = true, Text = LocalizedStrings.Loading }; refreshingPopup.Show(); }
internal static EventHandler <object> CreateWrapperHandler(EventHandler handler) { // Check whether it is a round-tripping case i.e. the sender is of the type eventArgs, // If so we use it else we pass EventArgs.Empty return((object?sender, object e) => { EventArgs?eventArgs = e as EventArgs; handler(sender, (eventArgs == null ? System.EventArgs.Empty : eventArgs)); }); }
private void TryTriggerSingleClickEvent() { if (m_singleClickEvents != null) { if (ItemClickedWithoutDoubleClick != null) { ItemClickedWithoutDoubleClick(this, m_singleClickEvents.Value); } m_singleClickEvents = null; } }
private void WaterMark_Toggle(object?sender, EventArgs?args) { if (this.Text.Length <= 0) { EnableWaterMark(); } else { DisbaleWaterMark(); } }
private void RemarkTextBox_TextChanged(object?sender, EventArgs?e) { if (!IsHandleCreated) { return; } BeginInvoke(() => { FilenameTextBox.Text = FilenameTextBox.Text = ModeEditorUtils.GetCustomModeRelativePath(RemarkTextBox.Text); }); }
private void TryTriggerSingleClickEvent() { if (m_singleClickEvents != null) { if (ItemClickedWithoutDoubleClick != null) ItemClickedWithoutDoubleClick(this, m_singleClickEvents.Value); m_singleClickEvents = null; } }
private void HandleNewMousePress(ref MyGuiControlBase captureInput) { bool cursorInItems = m_itemsRectangle.Contains(MyGuiManager.MouseCursorPosition); if (MyInput.Static.IsNewPrimaryButtonReleased() || MyInput.Static.IsNewSecondaryButtonReleased()) { if (cursorInItems) { int? mouseOverIndex = ComputeIndex(MyGuiManager.MouseCursorPosition); if (!IsValidIndex(mouseOverIndex.Value)) mouseOverIndex = null; SelectMouseOverItem(mouseOverIndex); if (SelectedIndex.HasValue && m_itemClicked.HasValue && m_lastClick.HasValue && mouseOverIndex.HasValue) { if (MyGuiManager.TotalTimeInMilliseconds - m_lastClick.Value < MyGuiConstants.CLICK_RELEASE_DELAY && m_itemClicked.Value.ItemIndex == mouseOverIndex.Value) { captureInput = this; MySharedButtonsEnum button = MySharedButtonsEnum.None; if (MyInput.Static.IsNewPrimaryButtonReleased()) button = MySharedButtonsEnum.Primary; else if (MyInput.Static.IsNewSecondaryButtonReleased()) button = MySharedButtonsEnum.Secondary; EventArgs args; MakeEventArgs(out args, SelectedIndex.Value, button); var handler = ItemReleased; if (handler != null) handler(this, args); } } } m_itemClicked = null; m_lastClick = null; } if (MyInput.Static.IsAnyNewMouseOrJoystickPressed() && cursorInItems) { m_lastClick = MyGuiManager.TotalTimeInMilliseconds; int? mouseOverIndex = ComputeIndex(MyGuiManager.MouseCursorPosition); if (!IsValidIndex(mouseOverIndex.Value)) mouseOverIndex = null; SelectMouseOverItem(mouseOverIndex); captureInput = this; if (SelectedIndex.HasValue && (ItemClicked != null || ItemClickedWithoutDoubleClick != null)) { MySharedButtonsEnum button = MySharedButtonsEnum.None; if (MyInput.Static.IsNewPrimaryButtonPressed()) button = MySharedButtonsEnum.Primary; else if (MyInput.Static.IsNewSecondaryButtonPressed()) button = MySharedButtonsEnum.Secondary; EventArgs args; MakeEventArgs(out args, SelectedIndex.Value, button); var handler = ItemClicked; if (handler != null) handler(this, args); m_singleClickEvents = args; m_itemClicked = args; if (MyInput.Static.IsAnyCtrlKeyPressed() || MyInput.Static.IsAnyShiftKeyPressed()) MyGuiSoundManager.PlaySound(GuiSounds.Item); } } if (MyInput.Static.IsNewPrimaryButtonPressed() && cursorInItems) { if (!m_doubleClickStarted.HasValue) { m_doubleClickStarted = MyGuiManager.TotalTimeInMilliseconds; m_doubleClickFirstPosition = MyGuiManager.MouseCursorPosition; } else if ((MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) <= MyGuiConstants.DOUBLE_CLICK_DELAY && (m_doubleClickFirstPosition - MyGuiManager.MouseCursorPosition).Length() <= 0.005f) { if (SelectedIndex.HasValue && TryGetItemAt(SelectedIndex.Value) != null && ItemDoubleClicked != null) { //Cancel click event when we double click m_singleClickEvents = null; EventArgs args; MakeEventArgs(out args, SelectedIndex.Value, MySharedButtonsEnum.Primary); Debug.Assert(GetItemAt(args.ItemIndex) != null, "Double click should not be reported when clicking on empty position."); ItemDoubleClicked(this, args); MyGuiSoundManager.PlaySound(GuiSounds.Item); } m_doubleClickStarted = null; captureInput = this; } } }