public static IDisplayBinding CreateDisplayBinding( FilePath fileName, string mimeType, OpenWithFileViewer fileViewer) { var lazyFileViewer = fileViewer as LazyOpenWithFileViewer; if (lazyFileViewer != null) { return(CreateDisplayBinding(fileName, mimeType, lazyFileViewer)); } if (fileViewer.IsDisplayBinding) { return(new OpenWithViewDisplayBinding(fileViewer)); } else if (fileViewer.IsApplication) { return(new OpenWithDesktopApplicationDisplayBinding( fileName, mimeType, fileViewer.GetApplication())); } return(null); }
public void SetAsDefault(FilePath fileName, string mimeType, OpenWithFileViewer fileViewer) { ClearDefault(fileName, mimeType); if (fileViewer == null) { return; } var key = GetKey(fileName, mimeType); var userDefinedFileViewer = fileViewer as UserDefinedOpenWithFileViewer; if (userDefinedFileViewer != null) { defaultDisplayBindings [key] = userDefinedFileViewer.DisplayBinding; userDefinedFileViewer.SetAsDefault(); return; } key.IsApplication = fileViewer.IsApplication; key.IsDisplayBinding = fileViewer.IsDisplayBinding; mappings [key] = fileViewer.GetMappingKey(); var displayBinding = DisplayBindingFactory.CreateDisplayBinding(fileName, mimeType, fileViewer); defaultDisplayBindings [key] = displayBinding; DisplayBindingService.RegisterRuntimeDisplayBinding(displayBinding); }
public string GetTitle(OpenWithFileViewer fileViewer) { if (fileViewer == defaultFileViewer) { return(GettextCatalog.GetString("{0} (Default)", fileViewer.Title)); } return(fileViewer.Title); }
public IEnumerable <OpenWithFileViewer> GetFileViewers() { if (fileViewers != null) { return(fileViewers); } fileViewers = OpenWithFileViewer.GetFileViewers(fileName, mimeType, project).ToList(); fileViewers.AddRange(OpenWithServices.Mappings.GetUserDefinedFileViewers(fileName, mimeType)); ConfigureDefaultFileViewer(); return(fileViewers); }
public bool IsCustomDefault(FilePath fileName, string mimeType, OpenWithFileViewer fileViewer) { var userDefinedFileViewer = fileViewer as UserDefinedOpenWithFileViewer; if (userDefinedFileViewer != null) { return(userDefinedFileViewer.IsDefault); } string mapping = null; var key = GetKey(fileName, mimeType); if (!mappings.TryGetValue(key, out mapping)) { return(false); } return(mapping == fileViewer.GetMappingKey()); }
public void RemoveSelectedItem() { if (selectedItem == null) { return; } removedFileViewers.Add((UserDefinedOpenWithFileViewer)selectedItem); fileViewers.Remove(selectedItem); if (selectedItem == defaultFileViewer) { defaultFileViewer = nonOverriddenOriginalDefaultFileViewer; } selectedItem = null; OnSelectedItemChanged(); }
void ConfigureDefaultFileViewer() { // Find the default file viewer ignoring any customisation. nonOverriddenOriginalDefaultFileViewer = fileViewers .FirstOrDefault(fileViewer => fileViewer.CanUseAsDefault); originalDefaultFileViewer = nonOverriddenOriginalDefaultFileViewer; defaultFileViewer = nonOverriddenOriginalDefaultFileViewer; // Find custom default file viewer. foreach (var fileViewer in fileViewers) { if (OpenWithServices.Mappings.IsCustomDefault(fileName, mimeType, fileViewer)) { originalDefaultFileViewer = fileViewer; defaultFileViewer = fileViewer; } } }
OpenWithFileViewer FindMappedFileViewer( FilePath fileName, KeyValuePair <DisplayBindingMappingKey, string> keyValuePair) { if (keyValuePair.Key.IsDisplayBinding) { var fileViewers = OpenWithFileViewer.GetFileViewers( fileName, keyValuePair.Key.MimeType, null); return(fileViewers .FirstOrDefault(fileViewer => fileViewer.GetMappingKey() == keyValuePair.Value)); } // Application default mapping. This cannot be found at this point // until we have the full file name to an existing file. The application // will not be found so it has to be done later on. return(new LazyOpenWithFileViewer(keyValuePair.Key, keyValuePair.Value)); }
void LoadDefaultDisplayBindingMappings(OpenWithSettings settings) { foreach (var keyValuePair in settings.Mappings) { var dummyFileName = new FilePath("a.txt") .ChangeExtension(keyValuePair.Key.FileExtension); OpenWithFileViewer openFileViewer = FindMappedFileViewer(dummyFileName, keyValuePair); if (openFileViewer != null) { SetAsDefault(dummyFileName, keyValuePair.Key.MimeType, openFileViewer); } else { LoggingService.LogWarning( "Unable to find display binding for mapping. {0} Extension={1}, MimeType={2}", keyValuePair.Value, keyValuePair.Key.FileExtension, keyValuePair.Key.MimeType); } } }
void FindDisplayBinding (FilePath fileName, string mimeType, Project ownerProject) { findingDisplayBinding = true; try { string mappingKey = lazyFileViewer.GetMappingKey (); var fileViewer = OpenWithFileViewer.GetFileViewers ( fileName, mimeType, ownerProject).FirstOrDefault (item => item.GetMappingKey () == mappingKey); if (fileViewer != null) { displayBinding = DisplayBindingFactory.CreateDisplayBinding ( fileName, mimeType, fileViewer) as IExternalDisplayBinding; } } finally { findingDisplayBinding = false; } }
bool IsNewUserDefinedFileViewer(OpenWithFileViewer fileViewer) { var userDefinedFileViewer = fileViewer as UserDefinedOpenWithFileViewer; return(userDefinedFileViewer?.IsNew == true); }
public void SetSelectedItemAsDefault() { defaultFileViewer = selectedItem; CanSetAsDefault = false; }
public OpenWithViewDisplayBinding(OpenWithFileViewer fileViewer) { Name = fileViewer.Title; }