示例#1
0
        private void DisplayDiff(PatchDisplay patchDisplay, Paragraph paragraph)
        {
            _lastPatchDisplayed = patchDisplay;
            var displayMode = _diffDisplayMode;

            paragraph.Inlines.Clear();

            IPatchDisplay display;

            if (!_patchDisplays.TryGetValue(displayMode, out display))
            {
                throw new ArgumentOutOfRangeException(
                          nameof(displayMode), displayMode.ToString(),
                          "Internal error. Unknown type display type.");
            }

            display.Display(_history, patchDisplay, paragraph);
        }
示例#2
0
        public MainWindow()
        {
            var bo = new BlameOptions();

            _options = GitGooeyOptions.Load();

            AppDomain.CurrentDomain.ProcessExit += (e, s) => {
                _options.Save();
            };

            var args = Environment.GetCommandLineArgs();

            var filename = args[1];

            InitializeComponent();

            filename = Path.IsPathRooted(filename)
                ? filename
                : Path.Combine(Directory.GetCurrentDirectory(), filename);

            var directoryHistory = new List <string>(
                Path.GetDirectoryName(filename)
                .Split(Path.DirectorySeparatorChar));

            string gitDir = null;

            while (directoryHistory.Count > 0)
            {
                var testDir = string.Join(
                    Path.DirectorySeparatorChar + "", directoryHistory);

                if (Directory.GetDirectories(testDir, ".git").Any())
                {
                    gitDir = testDir;
                    break;
                }

                directoryHistory.RemoveAt(directoryHistory.Count - 1);
            }

            if (gitDir == null)
            {
                throw new Exception("File not in git.");
            }

            // +1 to eat the directory char.
            filename = filename.Substring(gitDir.Length + 1);

            Title = $"GitGooey - {filename}";

            _repo    = new Repository(gitDir);
            _history = new GitGooeyHistory(_repo, filename);

            var m = _repo.Blame(filename, bo);

            _blameHunks = m.ToArray();

            var existingChangesetShas = new HashSet <string>();

            foreach (var asd in PatchDisplay
                     .FromBlameHunks(filename, _blameHunks, existingChangesetShas))
            {
                Patches.Add(asd);
            }

            UXPatchDisplay.Document = new FlowDocument(_viewerParagraph);

            DataContext = this;

            if (_options.WindowWidth > 0 && _options.WindowHeight > 0)
            {
                Width  = _options.WindowWidth;
                Height = _options.WindowHeight;
            }
        }