private Task <ObservableDiagram> RenderChordAsync(IChordFinderResult result) { return(Task <ObservableDiagram> .Factory.StartNew(() => { ObservableDiagram od = null; AppVM.AppView.DoOnUIThread(() => { try { od = new ObservableDiagram(result.ToDiagram(Style), name: Strings.FinderResultDiagramName); od.PostEditCallback = (changed) => { if (changed) { od.Refresh(); } }; } catch (Exception ex) { ExceptionUtils.HandleException(ex); } }); return od; })); }
private Action <bool> GetDiagramPostEditCallback(ObservableDiagram od) { ObservableDiagram originalObservableDiagram = od; Diagram originalDiagram = od.Diagram; return((changed) => { if (changed) { if (Collection.Contains(originalDiagram)) { // We edited an existing diagram, so we need to replace the pre-edited Diagram still in the library // with the newly minted Diagram from the editor Collection.Replace(originalDiagram, originalObservableDiagram.Diagram); } else { // This was a new diagram, so we need to add it to the library collection Collection.Add(originalObservableDiagram.Diagram); // Then add it to the list of visible diagrams Diagrams.Add(originalObservableDiagram); } // Now we need to refresh the individual image originalObservableDiagram.Refresh(); // Now that the internal Diagram has changed, we need to rebuild the callback so that the new Diagram is // cached correctly for any future calls to edit this od originalObservableDiagram.PostEditCallback = GetDiagramPostEditCallback(originalObservableDiagram); } }); }
private ObservableDiagram CreateObservableDiagram(Diagram diagram) { ObservableDiagram od = new ObservableDiagram(diagram); od.PostEditCallback = GetDiagramPostEditCallback(od); return(od); }
void ObservableDiagram_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (!ObservableDiagram.IsCursorProperty(e.PropertyName)) { Dirty = true; if (e.PropertyName == nameof(Style)) { RaisePropertyChanged(nameof(Style)); } } }
public DiagramEditorViewModel(ObservableDiagram diagram, bool isNew) { OriginalObservableDiagram = diagram ?? throw new ArgumentNullException(nameof(diagram)); ObservableDiagram = new ObservableDiagram(diagram.Diagram.Clone()) { IsEditMode = true }; if (isNew) { _dirty = true; } ObservableDiagram.PropertyChanged += ObservableDiagram_PropertyChanged; ObservableDiagram.Style.PropertyChanged += Style_PropertyChanged; }
public ShowDiagramEditorMessage(ObservableDiagram diagram, bool isNew, Action <bool> callback = null) : base() { Diagram = diagram; IsNew = isNew; Callback = callback; }