Exemplo n.º 1
0
        public static void CopyToClipboard(string text)
        {
            Exception caught = null;
            var       t      = new Thread(() =>
            {
                try
                {
                    if (OsUtils.IsWindowsOs())
                    {
                        // #warning Look into using Gtk.Clipboard?
                        Clipboard.SetData(DataFormats.Text, text);
                    }
                }
                catch (Exception e)
                {
                    caught = e;
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();

            if (caught != null)
            {
                throw new Exception("Creating window failed.", caught);
            }
        }
Exemplo n.º 2
0
 private static IEnumerable <string> FindProgramOnPath(string programName)
 {
     if (EnvironmentPaths == null)
     {
         EnvironmentPaths = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator).ToList();
         if (OsUtils.IsUnixOs())
         {
             // not sure why this path is not included in the environment variables
             // but couldn't find find p4merge without it.
             EnvironmentPaths.Add("/usr/local/bin");
         }
     }
     return(EnvironmentPaths.Select(path => Path.Combine(path, programName)).Where(File.Exists));
 }
Exemplo n.º 3
0
        public static IEnumerable <string> LocateFileFromEnvironmentPath(string toFind)
        {
            var results = new List <string>();

            if (File.Exists(toFind))
            {
                results.Add(Path.GetFullPath(toFind));
            }
            if (OsUtils.IsUnixOs())
            {
                if (0 <= toFind.IndexOf(".exe"))
                {
                    var trimmedToFind = toFind.Substring(0, toFind.Length - 4);
                    results.AddRange(FindProgramOnPath(trimmedToFind));
                }
            }

            results.AddRange(FindProgramOnPath(toFind));
            return(results.Distinct());
        }