コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public string GetTitle(OpenWithFileViewer fileViewer)
        {
            if (fileViewer == defaultFileViewer)
            {
                return(GettextCatalog.GetString("{0} (Default)", fileViewer.Title));
            }

            return(fileViewer.Title);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        public void RemoveSelectedItem()
        {
            if (selectedItem == null)
            {
                return;
            }

            removedFileViewers.Add((UserDefinedOpenWithFileViewer)selectedItem);
            fileViewers.Remove(selectedItem);

            if (selectedItem == defaultFileViewer)
            {
                defaultFileViewer = nonOverriddenOriginalDefaultFileViewer;
            }

            selectedItem = null;

            OnSelectedItemChanged();
        }
コード例 #7
0
        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;
                }
            }
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
		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;
			}
		}
コード例 #11
0
        bool IsNewUserDefinedFileViewer(OpenWithFileViewer fileViewer)
        {
            var userDefinedFileViewer = fileViewer as UserDefinedOpenWithFileViewer;

            return(userDefinedFileViewer?.IsNew == true);
        }
コード例 #12
0
 public void SetSelectedItemAsDefault()
 {
     defaultFileViewer = selectedItem;
     CanSetAsDefault   = false;
 }
コード例 #13
0
 public OpenWithViewDisplayBinding(OpenWithFileViewer fileViewer)
 {
     Name = fileViewer.Title;
 }