private void LoadedPackages(LoadedPackagesFromRepository data) { ReadPackageLocalStateCommand localStateCommand = new ReadPackageLocalStateCommand(); localStateCommand.Execute(data); WpfHelpers.DispatchToMainThread(() => _allPackages.AddRange(data.Packages)); }
public Tracker() { InitializeComponent(); this.Loaded += (sender, args) => { WpfHelpers.AddFlyout <AddEditProductFlyout>(this, nameof(TrackerViewModel.IsAddEditProductVisible), nameof(TrackerViewModel.EditingProduct)); }; }
private void InputByNumbers() { _variables = (int)MintermNumbers.Value; try { if (string.IsNullOrEmpty(MintermInput.Text)) { throw new Exception("No minterm numbers entered"); } string[] items = MintermInput.Text.Split(','); string[] dontcare = null; if (!string.IsNullOrEmpty(DontcarInput.Text)) { dontcare = DontcarInput.Text.Split(','); if (dontcare.Length < 1) { items = DontcarInput.Text.Split(' '); } } if (items.Length < 1) { items = MintermInput.Text.Split(' '); } if (items.Length < 1) { throw new Exception("Incorrect input"); } List <LogicItem> litems = new List <LogicItem>(); foreach (var item in items) { litems.Add(new LogicItem() { Index = Convert.ToInt32(item), BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables), Checked = true }); } if (dontcare != null) { foreach (var item in dontcare) { litems.Add(new LogicItem() { Index = Convert.ToInt32(item), BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables), Checked = null }); } } SimpleMinterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, false); SimpleMaxterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, true); } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
public static void ClearMintermtable(Grid Minterm) { var chbox = WpfHelpers.FindChildren <CheckBox>(Minterm); foreach (var ch in chbox) { ch.IsChecked = false; } }
private void LoadedPackages(LoadedPackagesFromRepository data) { PackageRepositoryViewModel repositoryViewModel = _packageRepositories.FirstOrDefault(repo => repo.Name == data.Repository.Name); if (repositoryViewModel != null) { WpfHelpers.DispatchToMainThread(() => repositoryViewModel.SetPackages(data.Packages)); } }
private void SaveDirectory(string directorypath) { _dir = directorypath; string newkey = GetKey(FilePanel.SelectedIndex); _files[newkey] = Editor.Text; if (Directory.GetFiles(_dir).Length > 0) { WpfHelpers.ExceptionDialog("Target directory is not empty, can't save sketch"); return; } var sketchname = Path.GetFileName(_dir) + ".ino"; if (!_files.ContainsKey(sketchname)) { MainSelectorWindow ms = new MainSelectorWindow(); ms.ListItems = (from i in _files.Keys select i).ToArray(); if (ms.ShowDialog() == true) { string selected = ms.SelectedFile; if (string.IsNullOrEmpty(selected)) { WpfHelpers.ExceptionDialog("Save can't be completeted, because no main file is selected"); return; } string content = _files[selected]; _files.Remove(selected); _files.Add(sketchname + ".ino", content); } else { WpfHelpers.ExceptionDialog("Save can't be completeted, because no main file is selected"); return; } } foreach (var file in _files) { try { var text = File.CreateText(directorypath + "\\" + file.Key + ".new"); text.Write(file.Value); text.Close(); File.Move(directorypath + "\\" + file.Key + ".new", directorypath + "\\" + file.Key); } catch (IOException ex) { WpfHelpers.ExceptionDialog("Error saving sketch: " + directorypath, ex); break; } } Load(_dir); }
private void SetPinModes() { _pins = WpfHelpers.FindChildren <PinControl>((TabItem)Models.SelectedItem); foreach (var c in _pins) { c.PinMode = PinModes.Input; Thread.Sleep(15); c.PinMode = PinModes.Output; } }
public void Attach(AutoGridColumnContext context) { if (!typeof(ICommand).IsAssignableFrom(context.Property.PropertyType)) { return; } var icon = context.GetAttribute <IconAttribute>()?.Name; context.Args.Column = WpfHelpers.CreateButtonColumn(context.Property.Name, icon); }
public static Dictionary <int, bool?> GetMintermTableValues(Grid Minterm) { Dictionary <int, bool?> ret = new Dictionary <int, bool?>(); var chbox = WpfHelpers.FindChildren <CheckBox>(Minterm); foreach (var ch in chbox) { ret.Add(Convert.ToInt32(ch.Content), ch.IsChecked); } return(ret); }
public void Attach(AutoGridColumnContext context) { var style = context.GetAttribute <StyleAttribute>(); if (style == null) { return; } WpfHelpers.SetCellHorizontalAlignment(context.Args.Column, style.HorizontalAlignment); }
public static void SetMintermTableValues(Grid Minterm, List <LogicItem> items) { var chbox = WpfHelpers.FindChildren <CheckBox>(Minterm); foreach (var item in items) { var box = (from chb in chbox where chb.Content.ToString() == item.Index.ToString() select chb).FirstOrDefault(); if (box != null) { box.IsChecked = item.Checked; } } }
private void Fill_Click(object sender, RoutedEventArgs e) { if (!_loaded) { return; } var items = WpfHelpers.FindChildren <Rectangle>(Grid8x); foreach (Rectangle item in items) { item.Fill = new SolidColorBrush(Colors.Red); } }
private int CalculateSize(int value) { int multiply = 1; foreach (var radio in WpfHelpers.FindChildren <RadioButton>(MultiplySelect)) { if (radio.IsChecked == true) { multiply = Convert.ToInt32(radio.Content); break; } } return(multiply * value); }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (SaveButton != null) { if (!string.IsNullOrWhiteSpace(textBox1.Text) || textBox1.Text == TextBoxDefaultValue) { SaveButton.IsEnabled = false; if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { } } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (_loaded) { return; } _loaded = true; Button_Click(this, e); _controls = WpfHelpers.FindChildren <AnalogSampler>(this); _timer = new DispatcherTimer(); _timer.IsEnabled = false; _timer.Tick += _timer_Tick; Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; }
public void Attach(AutoGridColumnContext context) { var path = context.GetAttribute <TooltipSourceAttribute>()?.Path; if (path == null) { return; } var style = WpfHelpers.EnsureDefaultCellStyle(context.Args.Column); var binding = new Binding(path); style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, binding)); }
public static void Save(LauncherConfig cf, string path) { try { XmlSerializer xs = new XmlSerializer(typeof(LauncherConfig)); using (var file = File.Create(path)) { xs.Serialize(file, cf); } } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
private string Save() { try { XmlSerializer ser = new XmlSerializer(typeof(UserCode)); StringWriter textWriter = new StringWriter(); ser.Serialize(textWriter, _codes.ToArray()); return(ser.ToString()); } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); return(null); } }
public static LauncherConfig Load(string path) { try { XmlSerializer xs = new XmlSerializer(typeof(LauncherConfig)); using (var file = File.OpenRead(path)) { return((LauncherConfig)xs.Deserialize(file)); } } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); return(null); } }
private void BtnLoadBMP_Click(object sender, RoutedEventArgs e) { try { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Filter = "Bitmap files | *.bmp"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { LoadBmp(ofd.FileName); } } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
private void BtnExpand_Click(object sender, RoutedEventArgs e) { if (BtnExpand.IsChecked == true) { BtnExpand.Content = "Colapse All"; } else { BtnExpand.Content = "Expand All"; } foreach (var expander in WpfHelpers.FindChildren <Expander>(FunctionL)) { expander.IsExpanded = (bool)BtnExpand.IsChecked; } }
private void PopOut_Click(object sender, RoutedEventArgs e) { UIElement control = null; UIElement clone = null; ShaderTabPopoutWin popout; bool disposeable; if (Tabs.Items.Count < 1) { return; } control = GetCurrentControl(); disposeable = control is IDisposable; if (control is IFixedTool) { WpfHelpers.ExceptionDialog("The Current tool doesn't support this function"); return; } if (disposeable) { MessageBoxResult r = MessageBox.Show("Warning. Poping out this tool to a new window will reset it's workflow.\r\nDo you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (r == MessageBoxResult.No) { return; } clone = (UIElement)Activator.CreateInstance(control.GetType()); DestroyObject(control as IDisposable); } popout = new ShaderTabPopoutWin(); popout.Width = this.ActualWidth; popout.Height = this.ActualHeight; popout.GlassTitle = (Tabs.Items[Tabs.SelectedIndex] as TabItem).Header.ToString(); RemoveCurrenctontrol(); if (disposeable) { popout.TabContent = clone; } else { popout.TabContent = control; } popout.Show(); }
void Book_Click(object sender, RoutedEventArgs e) { var d = sender.ToString(); if (!BookManager.PDFReaderInstalled()) { WpfHelpers.ExceptionDialog("No PDF Readers installed. To view documents a PDF reader must be installed"); return; } string f = _books.GetFilePath(d); Process p = new Process(); p.StartInfo.UseShellExecute = true; p.StartInfo.FileName = f; p.Start(); App._Config.UsageStats[d] += 1; }
private void ListDirectory(TreeView treeView, string path) { if (!File.Exists(path + "\\arduino.exe")) { WpfHelpers.ExceptionDialog("This is not a valid arduino directory. No Arduino.exe was found"); return; } treeView.Items.Clear(); var rootDirectoryInfo = new DirectoryInfo(path); treeView.Items.Add(CreateDirectoryNode(rootDirectoryInfo)); if (treeView.Items.Count > 0) { (treeView.Items[0] as TreeViewItem).IsExpanded = true; } }
private void BtnSaveBmp_Click(object sender, RoutedEventArgs e) { try { System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog(); sfd.DefaultExt = "*.bmp"; sfd.Filter = "Bitmap files | *.bmp"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SaveBmp(sfd.FileName); } } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (SaveButton != null) { if (string.IsNullOrWhiteSpace(textBox1.Text) || SavedTextBoxTexts.IndexOf(textBox1.Text) >= 0) { SaveButton.IsEnabled = false; if (WpfHelpers.Confirmation(resources.QuitWithoutSaving, resources.Changes)) { } } else { SaveButton.IsEnabled = true; } } }
private void UpdateVariableScope() { try { if (!(bool)BtnEnable.IsChecked) { return; } StringBuilder sb = new StringBuilder(); int count = Convert.ToInt32((ToggleNumber.SelectedItem as ComboBoxItem).Content); ToggleButton btn; for (int i = 0; i < count; i++) { btn = TogleButtons.Children[i] as ToggleButton; sb.Append(letters[i]); sb.Append(" = "); if (btn.IsChecked == true) { sb.Append("1"); } else { sb.Append("0"); } sb.Append("\r\n"); } ScriptSource source = _engine.CreateScriptSourceFromString(sb.ToString(), SourceCodeKind.AutoDetect); source.Execute(_scope); foreach (var f in _collection) { source = _engine.CreateScriptSourceFromString(f.Formula, SourceCodeKind.AutoDetect); object result = source.Execute(_scope); f.Res = result.ToString(); } Formulas.ItemsSource = null; Formulas.ItemsSource = _collection; } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
public void Save() { try { XmlSerializer ser = new XmlSerializer(typeof(Config)); StringWriter textWriter = new StringWriter(); Config conf = new Config(); conf.Stats = this._stats.Pack(); conf.Configs = this._subconfigs; ser.Serialize(textWriter, conf); Settings.Default.UserConfigXML = textWriter.ToString(); Settings.Default.Save(); conf = null; textWriter.Close(); } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
private void Load(string serializeddata) { try { if (string.IsNullOrEmpty(serializeddata)) { return; } XmlSerializer ser = new XmlSerializer(typeof(UserCode)); StringReader stringReader = new StringReader(serializeddata); UserCode[] loaded = (UserCode[])ser.Deserialize(stringReader); _codes.Clear(); _codes.AddRange(loaded); loaded = null; } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }
public void Load(string fileName) { if (!File.Exists(fileName)) { MessageBox.Show("File not found: " + fileName, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { DynamicFileByteProvider dynamicFileByteProvider; try { // try to open in write mode dynamicFileByteProvider = new DynamicFileByteProvider(fileName); } catch (IOException) // write mode failed { try { // try to open in read-only mode dynamicFileByteProvider = new DynamicFileByteProvider(fileName, true); if (MessageBox.Show("File is readonly. Open in reafonly mode?", "Question", MessageBoxButton.YesNo) == MessageBoxResult.No) { dynamicFileByteProvider.Dispose(); return; } } catch (IOException) // read-only also failed { // file cannot be opened MessageBox.Show("File open failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } hexBox.ByteProvider = dynamicFileByteProvider; } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }