public void Setup()
        {
            _repositoryDescriptionProvider = Substitute.For <IRepositoryDescriptionProvider>();
            _repositoryDescriptionProvider.Get(Arg.Any <string>()).Returns(ShortName);

            _appTitleGenerator = new AppTitleGenerator(_repositoryDescriptionProvider);
        }
Пример #2
0
        /// <summary>
        /// Adds the given working directory to the list of Recent for future quick access.
        /// </summary>
        public void AddToRecent(string workingDir)
        {
            if (!IsSupported)
            {
                return;
            }

            if (!ToolbarButtonsCreated)
            {
                _deferredAddToRecent = workingDir;
                return;
            }

            if (string.IsNullOrWhiteSpace(workingDir))
            {
                throw new ArgumentException(nameof(workingDir));
            }

            SafeInvoke(() =>
            {
                string repositoryDescription = _repositoryDescriptionProvider.Get(workingDir);
                if (string.IsNullOrWhiteSpace(repositoryDescription))
                {
                    return;
                }

                string baseFolder = Path.Combine(AppSettings.ApplicationDataPath.Value, "Recent");
                if (!Directory.Exists(baseFolder))
                {
                    Directory.CreateDirectory(baseFolder);
                }

                // sanitise
                StringBuilder sb = new(repositoryDescription);
                foreach (char c in Path.GetInvalidFileNameChars())
                {
                    sb.Replace(c, '_');
                }

                string path = Path.Combine(baseFolder, $"{sb}.gitext");
                File.WriteAllText(path, workingDir);
                JumpList.AddToRecent(path);

                if (!ToolbarButtonsCreated)
                {
                    return;
                }

                Validates.NotNull(_commitButton);
                Validates.NotNull(_pushButton);
                Validates.NotNull(_pullButton);

                _commitButton.Enabled = true;
                _pushButton.Enabled   = true;
                _pullButton.Enabled   = true;
            }, nameof(AddToRecent));
        }
Пример #3
0
        public void AddToRecent([NotNull] string workingDir)
        {
            if (!IsSupported)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(workingDir))
            {
                throw new ArgumentException(nameof(workingDir));
            }

            try
            {
                string repositoryDescription = _repositoryDescriptionProvider.Get(workingDir);
                if (string.IsNullOrWhiteSpace(repositoryDescription))
                {
                    return;
                }

                string baseFolder = Path.Combine(AppSettings.ApplicationDataPath.Value, "Recent");
                if (!Directory.Exists(baseFolder))
                {
                    Directory.CreateDirectory(baseFolder);
                }

                // sanitise
                var sb = new StringBuilder(repositoryDescription);
                foreach (char c in Path.GetInvalidFileNameChars())
                {
                    sb.Replace(c, '_');
                }

                string path = Path.Combine(baseFolder, $"{sb}.gitext");
                File.WriteAllText(path, workingDir);
                JumpList.AddToRecent(path);
            }
            catch (Exception ex)
                when(

                    // reported in https://github.com/gitextensions/gitextensions/issues/2269
                    ex is COMException ||

                    // reported in https://github.com/gitextensions/gitextensions/issues/6767
                    ex is UnauthorizedAccessException ||

                    // reported in https://github.com/gitextensions/gitextensions/issues/4549
                    // looks like a regression in Windows 10.0.16299 (1709)
                    ex is IOException)
                {
                    Trace.WriteLine(ex.Message, "UpdateJumplist");
                }
        }
Пример #4
0
        /// <summary>
        /// Generates main window title according to given repository.
        /// </summary>
        /// <param name="workingDir">Path to repository.</param>
        /// <param name="isValidWorkingDir">Indicates whether the given path contains a valid repository.</param>
        /// <param name="branchName">Current branch name.</param>
        public string Generate(string workingDir, bool isValidWorkingDir, string branchName)
        {
            if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
            {
                return(DefaultTitle);
            }
            string repositoryDescription = _repositoryDescriptionProvider.Get(workingDir);
            var    title = string.Format(RepositoryTitleFormat, repositoryDescription, (branchName ?? "no branch").Trim('(', ')'));

#if DEBUG
            title += " -> DEBUG <-";
#endif
            return(title);
        }
        /// <summary>
        /// Generates main window title according to given repository.
        /// </summary>
        /// <param name="workingDir">Path to repository.</param>
        /// <param name="isValidWorkingDir">Indicates whether the given path contains a valid repository.</param>
        /// <param name="branchName">Current branch name.</param>
        public string Generate(string workingDir = null, bool isValidWorkingDir = false, string branchName = null)
        {
            if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
            {
                return("Git Extensions");
            }

            branchName = branchName?.Trim('(', ')') ?? "no branch";

            var description = _description.Get(workingDir);

#if DEBUG
            return($"{description} ({branchName}) - Git Extensions [DEBUG]");
#else
            return($"{description} ({branchName}) - Git Extensions");
#endif
        }
Пример #6
0
        /// <summary>
        /// Generates main window title according to given repository.
        /// </summary>
        /// <param name="workingDir">Path to repository.</param>
        /// <param name="isValidWorkingDir">Indicates whether the given path contains a valid repository.</param>
        /// <param name="branchName">Current branch name.</param>
        public string Generate(string?workingDir = null, bool isValidWorkingDir = false, string?branchName = null)
        {
            if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
            {
                return(AppSettings.ApplicationName);
            }

            branchName = branchName?.Trim('(', ')') ?? "no branch";

            var description = _descriptionProvider.Get(workingDir);

#if DEBUG
            return($"{description} ({branchName}) - {AppSettings.ApplicationName}{_extraInfo}");
#else
            return($"{description} ({branchName}) - {AppSettings.ApplicationName}");
#endif
        }
Пример #7
0
        /// <inheritdoc />
        public string Generate(string?workingDir = null, bool isValidWorkingDir = false, string?branchName = null, string defaultBranchName = "", string?pathName = null)
        {
            if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
            {
                return(AppSettings.ApplicationName);
            }

            branchName = branchName?.Trim('(', ')') ?? defaultBranchName;

            // Pathname normally have quotes already
            pathName = GetFileName(pathName);

            var description = _descriptionProvider.Get(workingDir);

#if DEBUG
            return($"{pathName}{description} ({branchName}) - {AppSettings.ApplicationName}{_extraInfo}");
#else
            return($"{pathName}{description} ({branchName}) - {AppSettings.ApplicationName}");
#endif

            string?GetFileName(string?path)
            {
                if (string.IsNullOrWhiteSpace(pathName))
                {
                    return(null);
                }

                string filePart = Path.GetFileName(pathName.Trim('"')).QuoteNE();

                if (string.IsNullOrWhiteSpace(filePart))
                {
                    // No file, just quote the pathFilter
                    filePart = pathName.StartsWith(@"""") && pathName.EndsWith(@"""")
                        ? pathName
                        : $"{pathName.Quote()}";
                }

                return($"{filePart} ");
            }
        }
Пример #8
0
        /// <inheritdoc />
        public string Generate(string?workingDir = null, bool isValidWorkingDir = false, string?branchName = null, string defaultBranchName = "", string?pathName = null)
        {
            if (string.IsNullOrWhiteSpace(workingDir) || !isValidWorkingDir)
            {
                return(AppSettings.ApplicationName);
            }

            branchName = branchName?.Trim('(', ')') ?? defaultBranchName;

            // Pathname normally have quotes already
            pathName = string.IsNullOrWhiteSpace(pathName)
                ? ""
                    : pathName.StartsWith(@"""") && pathName.EndsWith(@"""")
                        ? $"{pathName} "
                        : $"{pathName.Quote()} ";

            var description = _descriptionProvider.Get(workingDir);

#if DEBUG
            return($"{description} ({branchName}) {pathName}- {AppSettings.ApplicationName}{_extraInfo}");
#else
            return($"{description} ({branchName}) {pathName}- {AppSettings.ApplicationName}");
#endif
        }