private void DoFocusChange() { if (Visibility == Visibility.Visible) { MainGrid.Focus(); } }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Up) { if (MainGrid.Rows.Count > 0) { int pos = MainGrid.CurrentCell.RowIndex; if (pos == 0) { Txtnombre.Focus(); return(true); } } } if (keyData == Keys.Down) { if (MainGrid.Rows.Count > 0 && focus == true) { MainGrid.Focus(); return(true); } } return(base.ProcessCmdKey(ref msg, keyData)); }
public void FixMainGridCurrentRowIndexOnRefocus() { AddDataForSetList(); CreateControllers(typeof(SetList)); ParentGrid.Focus(); Assert.AreEqual(1, View.SetMouseCursorToDefaultCount, "SetMouseCursorToDefaultCount after focusing parent grid"); Controller.Populate(); // Populate parent and main grids Assert.IsTrue(ParentGrid.Focused, "ParentGrid.Focused after Populate"); Assert.AreEqual(2, View.SetMouseCursorToDefaultCount, "SetMouseCursorToDefaultCount after Populate"); MainGrid.Focus(); Assert.AreEqual(3, View.SetMouseCursorToDefaultCount, "SetMouseCursorToDefaultCount after focusing main grid"); MainGridController.CreateAndGoToNewRow(); int mainGridNewRowIndex = MainGrid.CurrentRowIndex; ParentGrid.Focus(); // Simulate the problem that occurs when switching focus from the main grid to the // parent grid. If the main grid's current row is the new row before focusing the // parent grid, then, on focusing the parent grid, the new row is removed, so the // main grid's last existing row becomes its current row. MainGrid.MakeRowCurrent(mainGridNewRowIndex - 1); Assert.AreEqual(mainGridNewRowIndex - 1, MainGrid.CurrentRowIndex, "Main grid current row index after focus switched back to parent grid"); // Now test the fix. When focus is switched back to the main grid, we want to // restore currency to the new row. MainGrid.Focus(); Assert.AreEqual(mainGridNewRowIndex, MainGrid.CurrentRowIndex, "Main grid current row index after focus switched back to main grid"); Assert.IsTrue(ParentGrid.Enabled, "Parent grid enabled after focus switched back to main grid"); }
private void MainGrid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (TxtBoxToken.IsFocused) { MainGrid.Focus(); if (TxtBoxToken.Text == "") { TxtBoxToken.Text = "Synchronization token"; TxtBoxToken.Foreground = Brushes.Gray; } else { TxtBoxToken.Foreground = Brushes.Black; } } }
private void EntityNameBox_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { (sender as TextBox).Text = m_originalEntityName; MainGrid.Focus(); } else if (e.Key == Key.Return || e.Key == Key.Enter) { m_originalEntityName = (sender as TextBox).Text; ICommand command = (DataContext as CInspectorViewModel).RenameEntityCommand; if (command.CanExecute(m_originalEntityName)) { command.Execute(m_originalEntityName); } MainGrid.Focus(); } }
public Button(string Text = "") { this.Text = Text; MainGrid.Background = BGBrush; MainGrid.Focusable = true; Label.HorizontalAlignment = HorizontalAlignment.Stretch; Label.VerticalAlignment = VerticalAlignment.Stretch; Label.HorizontalContentAlignment = HorizontalAlignment.Center; Label.VerticalContentAlignment = VerticalAlignment.Center; Label.Padding = new Thickness(0); Label.Foreground = FGBrush; MainGrid.Children.Add(Label); MainGrid.SizeChanged += (object sender, System.Windows.SizeChangedEventArgs e) => { if (MainGrid.ActualHeight > 1) { Label.FontSize = MainGrid.ActualHeight * 0.5; } }; MainGrid.MouseEnter += (object sender, System.Windows.Input.MouseEventArgs e) => { if (GlobalSettings.Animations) { Animators.Animate( HToken, (double h) => { H = h; UpdateColors(); }, GlobalSettings.AnimationSpeed * 2, H, 1); } else { H = 1; UpdateColors(); } }; MainGrid.MouseLeave += (object sender, System.Windows.Input.MouseEventArgs e) => { if (GlobalSettings.Animations) { Animators.Animate( HToken, (double h) => { H = h; UpdateColors(); }, GlobalSettings.AnimationSpeed, H, 0); if (ClickPotential) { Animators.AnimateNatural( PToken, (double p) => { P = p; UpdateColors(); }, GlobalSettings.AnimationSpeed / 2, P, 0); } } else { H = 0; P = 0; UpdateColors(); } ClickPotential = false; }; MainGrid.MouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) => { ClickPotential = true; if (GlobalSettings.Animations) { Animators.Animate( PToken, (double p) => { P = p; UpdateColors(); }, GlobalSettings.AnimationSpeed * 4, P, 1); } else { P = 1; UpdateColors(); } MainGrid.Focus(); }; MainGrid.MouseUp += (object sender, System.Windows.Input.MouseButtonEventArgs e) => { if (ClickPotential) { ClickPotential = false; OnClick?.Invoke(); } if (GlobalSettings.Animations) { Animators.Animate( PToken, (double p) => { P = p; UpdateColors(); }, PSpeed, P, 0); } else { P = 0; UpdateColors(); } }; }
public Toggle(string Text = "", bool InitialValue = false) { this.Text = Text; ToggleState = InitialValue; ThumbPosition = ToggleState ? 1 : 0; MainGrid.Background = BGBrush; MainGrid.Focusable = true; Label.HorizontalAlignment = HorizontalAlignment.Stretch; Label.VerticalAlignment = VerticalAlignment.Stretch; Label.HorizontalContentAlignment = HorizontalAlignment.Center; Label.VerticalContentAlignment = VerticalAlignment.Center; Label.Foreground = FGBrush; MainGrid.Children.Add(Label); ThumbHolderGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; ThumbHolderGrid.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; MainGrid.Children.Add(ThumbHolderGrid); ThumbGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; ThumbGrid.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; ThumbGrid.Background = FGBrush; ThumbHolderGrid.Children.Add(ThumbGrid); UpdatePosition(); UpdateSize(); UpdateColors(); MainGrid.SizeChanged += (object sender, System.Windows.SizeChangedEventArgs e) => { UpdatePosition(); UpdateSize(); if (MainGrid.ActualHeight > 1) { Label.FontSize = MainGrid.ActualHeight * 0.4; } }; MainGrid.MouseMove += (object sender, System.Windows.Input.MouseEventArgs e) => { Point pos = e.MouseDevice.GetPosition(MainGrid); pos.X /= MainGrid.ActualWidth / 2; pos.Y /= MainGrid.ActualHeight / 2; pos.X -= 1; pos.Y -= 1; pos.X *= pos.X; pos.Y *= pos.Y; pos.X = 1 - pos.X; pos.Y = 1 - pos.Y; if (GlobalSettings.Animations) { Animators.Tail( ShrinkToken, (double x) => { ThumbShrinkage = x; UpdateSize(); }, ThumbShrinkage, 1 - pos.X * pos.Y ); } else { ThumbShrinkage = 1 - pos.X * pos.Y; UpdateSize(); } }; MainGrid.MouseLeave += (object sender, System.Windows.Input.MouseEventArgs e) => { ClickPotential = false; if (GlobalSettings.Animations) { Animators.Tail( ShrinkToken, (double x) => { ThumbShrinkage = x; UpdateSize(); }, ThumbShrinkage, 1 ); } else { ThumbShrinkage = 1; UpdateSize(); } }; MainGrid.MouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) => { ClickPotential = true; MainGrid.Focus(); }; MainGrid.MouseUp += (object sender, System.Windows.Input.MouseButtonEventArgs e) => { if (ClickPotential) { ClickPotential = false; Value = !Value; } }; }
private void Window_MouseDown(object sender, MouseButtonEventArgs e) { MainGrid.Focus(); }
private void MainGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { MainGrid.Focus(); }
public void RemoveFocus(object sender, EventArgs e) { MainGrid.Focus(); }
public async Task doInstall() { try { MainGrid.Focus(); updateDoing("Contacting GitHub"); animateProgress(dotProgress, 33); RestClient client = new RestClient("https://api.github.com/repos/dothq/browser/"); RestRequest request = new RestRequest("releases"); var response = await client.ExecuteAsync(request); if (!response.Content.StartsWith("[")) { throw new Exception("Server sent an invalid response"); } updateDoing("Parsing Data"); animateProgress(dotProgress, 66); Debug.WriteLine(response.Content); JArray releases = JArray.Parse(response.Content); JObject latestRelease = releases[0].Value <JObject>(); JArray assets = latestRelease["assets"].Value <JArray>(); JObject asset = null; for (int i = 0; i < assets.Count; i++) { JObject thisAsset = assets[i].Value <JObject>(); if (thisAsset["content_type"].Value <string>() == "application/x-zip-compressed") { asset = thisAsset; break; } } if (asset == null) { throw new Exception("Unable to find archive"); } updateDoing("Downloading archive"); animateProgress(dotProgress, 100); WebClient dlClient = new WebClient(); DateTime lastUpdate = DateTime.Now; dlClient.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { if (lastUpdate.Second == DateTime.Now.Second) { return; } lastUpdate = DateTime.Now; Debug.WriteLine("Downloaded " + (double)e.BytesReceived); Debug.WriteLine("To Download " + (double)e.TotalBytesToReceive); Debug.WriteLine("Percent " + ((100 * e.BytesReceived / e.TotalBytesToReceive)).ToString()); animateProgress(dotProgress, Convert.ToInt32(((100 * e.BytesReceived / e.TotalBytesToReceive) + 100))); }; string tempFileName = System.IO.Path.GetTempFileName(); await dlClient.DownloadFileTaskAsync(new Uri(asset["browser_download_url"].Value <string>()), tempFileName); if (Directory.Exists(InstallationPath)) { deleteFolder(InstallationPath); } Directory.CreateDirectory(InstallationPath); updateDoing("Unpacking"); ZipFile.ExtractToDirectory(tempFileName, InstallationPath); string DotBinary = ""; string[] files = Directory.GetFiles(InstallationPath); for (int i = 0; i < files.Length; i++) { if (files[i].EndsWith(".exe")) { DotBinary = files[i]; } } if (createShortcut) { updateDoing("Creating Shortcut"); object shDesktop = "Desktop"; WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut((string)shell.SpecialFolders.Item(ref shDesktop) + @"\Dot Browser.lnk"); shortcut.Description = "Start Dot Browser"; shortcut.TargetPath = DotBinary; shortcut.Save(); } updateDoing("Dot is now installed"); animateProgress(dotProgress, 300, 1000); animate(dotProgress, false, 1000); await Task.Delay(1000); Process.Start(DotBinary); await Task.Delay(5000); Process.GetCurrentProcess().Kill(); } catch (Exception e) { updateDoing(e.Message); Close.Visibility = Visibility.Visible; dotProgress.Foreground = Brushes.Red; } }
public void OnParentGridRowEntered() { AddDataForSetList(); CreateControllers(typeof(SetList)); Assert.IsFalse(MainGrid.Focused, "MainGrid.Focused initially"); Assert.IsFalse(ParentGrid.Focused, "ParentGrid.Focused initially"); Assert.IsFalse(MainGridController.IsFixingFocus, "IsFixingFocus initially"); MainGrid.Focus(); Assert.AreEqual(1, View.SetMouseCursorToDefaultCount, "SetMouseCursorToDefaultCount after focusing main grid"); Controller.Populate(); // Populate parent and main grids Assert.AreEqual("Event 2 of 2", View.StatusBarText, "StatusBarText after Populate"); Assert.AreEqual(1, View.OnParentAndMainGridsShownAsyncCount, "OnParentAndMainGridsShownAsyncCount after Populate"); Assert.IsFalse(MainGrid.Focused, "MainGrid.Focused after Populate"); Assert.IsTrue(ParentGrid.Focused, "ParentGrid.Focused after Populate"); Assert.AreEqual(2, MainGrid.CellColorScheme.InvertCount, "MainGrid.CellColorScheme.InvertCount after Populate"); Assert.AreEqual(2, ParentGridController.BindingList.Count, "Parent list count after Populate"); Assert.AreEqual(2, MainGridController.FirstVisibleColumnIndex, "Main grid FirstVisibleColumnIndex after Populate"); Assert.IsFalse(MainGridController.GetBindingColumn("Date").IsVisible, "Is Date column to be shown?"); Assert.IsTrue(MainGridController.GetBindingColumn("SetNo").IsVisible, "Is SetNo column to be shown?"); Assert.AreEqual(6, MainGridController.BindingList.Count, "Main list count after Populate"); // Includes new row Assert.IsTrue(MainGridController.IsFixingFocus, "IsFixingFocus after Populate"); Assert.AreEqual(0, ParentGridController.FirstVisibleColumnIndex, "Main grid FirstVisibleColumnIndex after Populate"); Assert.AreEqual(2, View.SetMouseCursorToDefaultCount, "SetMouseCursorToDefaultCount after Populate"); // Emulate the unwanted internal logic of DataGridView that, following the end of // Populate, causes an extra validation of the first main grid row, even though the // parent grid is focused. Without the workaround we are about to test, this // would switch focus to the main grid and make its first row current, neither of // which we want. See the documentation for MainGridController.IsFixingFocus. MainGridController.OnRowValidated(0); // Confirm that the workaround was executed. Assert.IsFalse(MainGridController.IsFixingFocus, "IsFixingFocus after OnRowValidated"); MainGrid.Focus(); Assert.AreEqual("Set 6 of 6", View.StatusBarText, "StatusBarText when main grid focused"); MainGridController.OnRowEnter(1); Assert.AreEqual("Set 2 of 6", View.StatusBarText, "StatusBarText when 2nd main grid row entered"); ParentGrid.Focus(); Assert.AreEqual("Event 2 of 2", View.StatusBarText, "StatusBarText after focusing parent grid"); ParentGridController.OnRowEnter(0); Assert.AreEqual("Event 1 of 2", View.StatusBarText, "StatusBarText when 1st parent selected"); Assert.AreEqual(4, MainGridController.BindingList.Count, "Main list count when 1st parent selected"); // Includes insertion row View.StatusBarText = string.Empty; // Simulates editor window deactivated. ParentGridController.OnWindowActivated(); Assert.AreEqual("Event 1 of 2", View.StatusBarText, "StatusBarText when editor window reactivated"); }