public CommandBase(Action <object> action, Func <object, bool> canExecuteMethod, INotifyPropertyChanged monitorPropertiesChanged = null) { _action = action; _canExecuteMethod = canExecuteMethod; if (monitorPropertiesChanged != null) { _componentToMonitorPropertiesChanged = Optional <INotifyPropertyChanged> .Some(monitorPropertiesChanged); } _componentToMonitorPropertiesChanged.Do(c => c.PropertyChanged += monitorPropertiesChanged_PropertyChanged); }
public Process Run(string arguments, Optional <Action <string> > stdOutReceived) { Console.WriteLine("Starting '" + _fuse.NativePath + "' with arguments '" + arguments + "'"); var p = Process.Start(new ProcessStartInfo(_fuse.NativePath) { Arguments = arguments, UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true }); if (p == null) { throw new TestFailure("Failed to start process"); } p.OutputDataReceived += (sender, args) => { Console.WriteLine(" >" + args.Data); stdOutReceived.Do(a => { if (args.Data != null) { a(args.Data); } }); }; p.ErrorDataReceived += (sender, args) => { Console.Error.WriteLine(" >" + args.Data); }; p.BeginErrorReadLine(); p.BeginOutputReadLine(); return(p); }
private void DoLazyLoad() { _lazyLoadIndicator.Do(indicator => { indicator.IsLoading = true; _lazyLoadIndicator = Optional <LazyLoadingIndicatorExplorerBarItem> .None(); StartBusyAction(() => { var appServices = this.ServiceLocator.GetInstance <IApplicationServices>(); IEnumerable <IExplorerBarItem> items = new IExplorerBarItem[0]; try { items = GetLazyLoadedItems(); } finally { appServices.ExecuteOnUIThread(() => { indicator.IsLoading = false; this.Items.Remove(indicator); }); } appServices.ExecuteOnUIThread(() => { foreach (var item in items) { this.Items.Add(item); } }); }); }); }
public override void Execute(object parameter) { _featureBranchBuilder.Do(builder => builder.PropertyChanged -= Builder_PropertyChanged); _featureBranchBuilder = Optional <IFeatureBranchBuilderViewModel> .Some(_mainBranchWorkspaceItem.StartNewFeatureBranch()); _featureBranchBuilder.Do(builder => builder.PropertyChanged += Builder_PropertyChanged); RaiseCanExecuteChanged(); }
public static void BindNativeProperty <TValue>( this IMountLocation control, IScheduler dispatcher, string name, Optional <IObservable <TValue> > value, Action <TValue> update) { value.Do(v => BindNativeProperty(control.IsRooted, dispatcher, name, v, update)); }
private void LoadFeatureBranches() { if (MainBranch.GetFeatureBranches().Any()) { _featureBranchesItem = Optional <IExplorerBarItem> .Some(CreateFaturesBranchesExplorerBarItem(MainBranch)); _featureBranchesItem.Do(item => this.Items.Add(item)); } }
public int GetFramebufferHandle(Size <Pixels> size) { if (_backbuffer.HasValue && _backbuffer.Value.Size == size) { return(_backbuffer.Value.Handle); } _backbuffer.Do(buffer => buffer.Dispose()); _backbuffer = new IOSurfaceRenderTargetBuffer(size); return(_backbuffer.Value.Handle); }
public TintedImage(Optional <NSImage> nsImage = default(Optional <NSImage>), bool cloneOnTint = true) { _cloneOnTint = cloneOnTint; _imageView = new NSImageView() { ImageScaling = NSImageScale.ProportionallyDown }; AddSubview(_imageView); nsImage.Do(img => CurrentImage = img); }
public void Focus() { _parent.Do(win => win.Dispatcher.InvokeAsync(() => { if (win.WindowState == System.Windows.WindowState.Minimized) { win.WindowState = System.Windows.WindowState.Normal; } win.Activate(); })); }
static IControl ImageImpl( IScheduler dispatcher, IObservable <IImage> streams, Optional <IObservable <Color> > overlayColor, Optional <IObservable <IColorMap> > colorMap, Optional <IObservable <Ratio <Pixels, Points> > > dpiOverride) { BehaviorSubject <Size <Points> > desiredSize = new BehaviorSubject <Size <Points> >(Size.Zero <Points>()); return(Control.Create( ctrl => { var dummyControl = new DpiAwareView() { AutoresizesSubviews = true }; ctrl.BindNativeDefaults(dummyControl, dispatcher); var tintedImage = new TintedImage() { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable }; dummyControl.AddSubview(tintedImage); ctrl.BindNativeProperty(dispatcher, "image", dpiOverride.Or(dummyControl.GetDpi()) .CombineLatest(streams, colorMap.Select(x => x.Select(Optional.Some)).Or(Observable.Return <Optional <IColorMap> >(Optional.None())), (dpi, imgStreams, cm) => new { dpi, imgStreams, colorMap = cm }), x => { var iv = x.imgStreams.Load <NSImage>(x.dpi, x.colorMap); tintedImage.CurrentImage = iv.Image; tintedImage.SetFrameSize(dummyControl.Frame.Size); var size = Size.Create <Pixels>((double)iv.Image.Size.Width, (double)iv.Image.Size.Height) / iv.ScaleFactor; desiredSize.OnNext(size); }); overlayColor.Do( colorObs => { ctrl.BindNativeProperty( dispatcher, "tintColor", colorObs, color => tintedImage.TintColor = color.ToNSColor()); }); return dummyControl; }).WithSize(desiredSize.Transpose())); }
public void Navigate <TViewModel>(TViewModel viewModel) where TViewModel : ISideBarItem, IActivationAware { _currentItem.Do(item => item.Deactivate()); Optional <ISideBarItem> _previousItem = _currentItem; ServiceLocator.GetInstance <IRegionManager>().NavigateToViewModel(GetSidebarRegionName(), viewModel); _currentItem = Optional <ISideBarItem> .Some(viewModel); _previousItem.Do(item => item.Dispose()); this.IsCollapsed = false; }
private void SubToInput(IInputObservable input) { var enabledEvts = from evt in input.InputEvents where Enabled select evt; var primSelects = from evt in enabledEvts where evt.Input == InputType.PrimarySelect select evt; var multiSelects = from evt in enabledEvts where evt.Input == InputType.MultiSelect select evt; subs.Add(multiSelects.Subscribe(inpt => { multiModifierDown = inpt.State != InputState.Finish; })); subs.Add(primSelects.Where(ps => ps.State == InputState.Finish).Subscribe(inpt => { Optional <T> selectedItem = SelectionFunction(); selectedItem.Do(item => NewSelection(item), () => DeselectAll()); })); }
private Optional <InputFile> ReadInputFileFromDisk(Optional <string> optionalFile) { var result = Optional <InputFile> .None(); optionalFile.Do(file => { if (!_fileSystem.FileExists(file)) { throw new InvalidCommandLineArgumentsException($"Can't find file {file}"); } result = Optional <InputFile> .Some(new InputFile(Path.GetFileName(file), _fileSystem.ReadAllText(file), new PathDescriptor(file))); }); return(result); }
public override void DrawRect(CGRect dirtyRect) { _imageView.Frame = Bounds; _tintColor.Do(tintColor => _currentImage.Do( currentImage => { var image = _cloneOnTint ? new NSImage(currentImage.CGImage.Clone(), currentImage.Size) : currentImage; image.LockFocus(); tintColor.SetFill(); RectFillUsingOperation(new CGRect(0, 0, image.Size.Width, image.Size.Height), NSCompositingOperation.SourceIn); image.UnlockFocus(); if (_cloneOnTint) { _imageView.Image = image; } })); base.DrawRect(dirtyRect); }
protected override System.Windows.DependencyObject CreateShell() { var mainWindow = new TShell(); mainWindow.Title = GetApplicationFriendlyName(); _appIcon.Do(icon => { mainWindow.Icon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); }); if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed && System.Deployment.Application.ApplicationDeployment.CurrentDeployment != null) { mainWindow.Title += string.Format(" [{0}]", System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()); } return(mainWindow); }
Stream ConvertToPng(Ratio <Pixels, Points> scaleFactor, Optional <IColorMap> colorMap) { using (var s = _svgStreamFactory()) { // Started out with 16x16 oversampling here, but that's just ridiculous and too expensive. // Setting to 4x4 as I'm not able to notice a difference going above that. var oversampling = 4; var xmlDocument = new XmlDocument(); xmlDocument.Load(s); colorMap.Do(cm => ApplyColorMap(xmlDocument, cm)); var svgDoc = SvgDocument.Open(xmlDocument); using (var bitmap = RenderSvg(svgDoc, scaleFactor.Value, oversampling)) using (var scaledBitmap = DownscaleByFactor(bitmap, oversampling)) { var memoryStream = new MemoryStream(); scaledBitmap.Save(memoryStream, ImageFormat.Png); memoryStream.Seek(0, SeekOrigin.Begin); return(memoryStream); } } }
public void Run() { _documentApp.Do(d => d.RunHost()); _app.Run(); }
private void SubscribeToMergeBuilderPropertyChanged() { _mergeBuilder.Do(builder => builder.PropertyChanged += Builder_PropertyChanged); }
void DoPreTermination() { _serviceRunner.Do(r => r.Dispose()); }
public void Dispose() { _framebufferInfo.Do(Delete); Surface.Dispose(); }
public void Execute(object parameter) { _execute.Do(x => x()); }
public void Focus() { _parent.Do(window => Fusion.Application.MainThread.Schedule(() => window.MakeKeyAndOrderFront(window))); }
public void Dispose() { _texture.Do(texture => GL.DeleteTexture(texture)); Surface.Dispose(); }