Example #1
0
        private void SetOpenWithButtonAndPath()
        {
            // share icon
            buttonShare.Visibility = ShareHelper.IsShareSupported(_path) ? Visibility.Visible : Visibility.Collapsed;

            // open icon
            if (Directory.Exists(_path))
            {
                buttonOpen.ToolTip = string.Format(TranslationHelper.Get("MW_BrowseFolder"), Path.GetFileName(_path));
                return;
            }

            var isExe = FileHelper.IsExecutable(_path, out var appFriendlyName);

            if (isExe)
            {
                buttonOpen.ToolTip = string.Format(TranslationHelper.Get("MW_Run"), appFriendlyName);
                return;
            }

            // not an exe
            var found = FileHelper.GetAssocApplication(_path, out appFriendlyName);

            if (found)
            {
                buttonOpen.ToolTip = string.Format(TranslationHelper.Get("MW_OpenWith"), appFriendlyName);
                return;
            }

            // assoc not found
            buttonOpen.ToolTip = string.Format(TranslationHelper.Get("MW_Open"), Path.GetFileName(_path));
        }
Example #2
0
        private void SetOpenWithButtonAndPath()
        {
            // share icon
            buttonShare.Visibility = ShareHelper.IsShareSupported(_path) ? Visibility.Visible : Visibility.Collapsed;

            // open icon
            buttonOpenText.Inlines.Clear();

            if (Directory.Exists(_path))
            {
                AddToInlines("MW_BrowseFolder", Path.GetFileName(_path));
                return;
            }

            var isExe = FileHelper.IsExecutable(_path, out var appFriendlyName);

            if (isExe)
            {
                AddToInlines("MW_Run", appFriendlyName);
                return;
            }

            // not an exe
            var found = FileHelper.GetAssocApplication(_path, out appFriendlyName);

            if (found)
            {
                AddToInlines("MW_OpenWith", appFriendlyName);
                return;
            }

            // assoc not found
            AddToInlines("MW_Open", Path.GetFileName(_path));

            void AddToInlines(string str, string replaceWith)
            {
                // limit str length
                if (replaceWith.Length > 16)
                {
                    replaceWith = replaceWith.Substring(0, 8) + "…" + replaceWith.Substring(replaceWith.Length - 8);
                }

                str = TranslationHelper.Get(str);
                var elements = str.Split(new[] { "{0}" }, StringSplitOptions.None).ToList();

                while (elements.Count < 2)
                {
                    elements.Add(string.Empty);
                }

                buttonOpenText.Inlines.Add(
                    new Run(elements[0])
                {
                    FontWeight = FontWeights.Normal
                });                                                          // text beforehand
                buttonOpenText.Inlines.Add(
                    new Run(replaceWith)
                {
                    FontWeight = FontWeights.SemiBold
                });                                                            // appFriendlyName
                buttonOpenText.Inlines.Add(
                    new Run(elements[1])
                {
                    FontWeight = FontWeights.Normal
                });                                                          // text afterward
            }
        }