private static Panel CreateViewFooter([NotNull] FormSparseWorkingCopyViewModel sparse, [NotNull] ToolTip tooltip, [NotNull] out Button btnSave, [NotNull] out Button btnCancel)
        {
            var tableFooterButtons = new TableLayoutPanel()
            {
                BackColor = SystemColors.ControlLightLight, Dock = DockStyle.Fill, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ColumnCount = 4, RowCount = 1, Margin = Padding.Empty, ColumnStyles = { new ColumnStyle(SizeType.Percent, 100) }, Padding = new Padding(10, 15, 10, 15), CellBorderStyle = TableLayoutPanelCellBorderStyle.None
            };

            CheckBox check;

            tableFooterButtons.Controls.Add(check = new CheckBox()
            {
                Text = Globalized.Strings.RefreshWorkingCopyUsingTheCurrentSettingsAndRules.Text, Checked = sparse.IsRefreshWorkingCopyOnSave, AutoSize = true, Dock = DockStyle.Fill, Margin = Padding.Empty
            });
            check.CheckedChanged += delegate { sparse.IsRefreshWorkingCopyOnSave = check.Checked; };
            tooltip.SetToolTip(check, string.Format(Globalized.Strings.RefreshWorkingCopyCheckboxHint.Text, FormSparseWorkingCopyViewModel.RefreshWorkingCopyCommandName));

            tableFooterButtons.Controls.Add(btnSave = new Button {
                Width = 75, Height = 23, Text = Globalized.Strings.Save.Text, DialogResult = DialogResult.OK, Dock = DockStyle.Bottom, UseVisualStyleBackColor = true, Margin = Padding.Empty
            });

            tableFooterButtons.Controls.Add(new Control {
                Width = 10, Dock = DockStyle.Fill
            });

            tableFooterButtons.Controls.Add(btnCancel = new Button {
                Width = 75, Height = 23, Text = Globalized.Strings.Cancel.Text, DialogResult = DialogResult.Cancel, Dock = DockStyle.Bottom, UseVisualStyleBackColor = true, Margin = Padding.Empty
            });

            return(tableFooterButtons);
        }
        public FormSparseWorkingCopy(GitUICommands commands)
            : base(commands)
        {
            var sparse = new FormSparseWorkingCopyViewModel(commands);

            BindToViewModelGlobal(sparse);
            CreateView(sparse);
            InitializeComplete();
        }
 public FormSparseWorkingCopy([CanBeNull] GitUICommands aCommands /* Translation tests set it to NULL */)
     : base(aCommands)
 {
     if(aCommands == null)
         return;
     var sparse = new FormSparseWorkingCopyViewModel(aCommands);
     BindToViewModelGlobal(sparse);
     CreateView(sparse);
     Translate();
 }
        public FormSparseWorkingCopy([CanBeNull] GitUICommands aCommands /* Translation tests set it to NULL */)
            : base(aCommands)
        {
            if (aCommands == null)
            {
                return;
            }
            var sparse = new FormSparseWorkingCopyViewModel(aCommands);

            BindToViewModelGlobal(sparse);
            CreateView(sparse);
            Translate();
        }
 private void BindToViewModelGlobal([NotNull] FormSparseWorkingCopyViewModel sparse)
 {
     if (sparse == null)
     {
         throw new ArgumentNullException(nameof(sparse));
     }
     sparse.ComfirmAdjustingRulesOnDeactRequested += (sender, args) =>
     {
         if (!args.Cancel)
         {
             args.Cancel |= MessageBox.Show(this, string.Format(Globalized.Strings.ConfirmDisableGitSparse.Text, (args.IsCurrentRuleSetEmpty ? Globalized.Strings.WithTheSparsePassFilterEmptyOrMissing.Text : Globalized.Strings.WithSomeRulesStillInTheSparsePassFilter.Text)), Globalized.Strings.DisableGitSparse.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes;
         }
     };
 }
        private void CreateView([NotNull] FormSparseWorkingCopyViewModel sparse)
        {
            Text          = Globalized.Strings.SparseWorkingCopy.Text;
            AutoScaleMode = AutoScaleMode.Dpi;
            StartPosition = FormStartPosition.CenterParent;
            MinimumSize   = new Size(800, 600);

            // Tooltips support for the form
            var componentcontainer = new Container();

            _disposable1 = componentcontainer;
            var tooltip = new ToolTip(componentcontainer)
            {
                AutomaticDelay = (int)TimeSpan.FromSeconds(10).TotalMilliseconds
            };

            Panel panelHeader = CreateViewHeader();

            Button btnSave;
            Button btnCancel;
            Panel  panelFooter = CreateViewFooter(sparse, tooltip, out btnSave, out btnCancel);

            Control panelOnOff = CreateViewOnOff(sparse, tooltip);

            Panel panelRules = CreateViewRules(sparse, tooltip, this);

            sparse.FirePropertyChanged(); // Initial binding

            Controls.Add(new TableLayoutPanel()
            {
                Dock = DockStyle.Fill, Padding = Padding.Empty, Margin = Padding.Empty, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Controls = { panelHeader, CreateViewSeparator(), panelOnOff, panelRules, CreateViewSeparator(), panelFooter }, RowStyles = { new RowStyle(), new RowStyle(), new RowStyle(), new RowStyle(SizeType.Percent, 100) }
            });

            AcceptButton = btnSave;
            CancelButton = btnCancel;

            BindSaveOnClose(sparse);

            // Special binding: as the editor takes Enter for itself, bind Ctrl+Enter to commit
            KeyPreview      = true;
            PreviewKeyDown += (sender, args) =>
            {
                if (args.KeyData == (Keys.Enter | Keys.Control))
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
            };
        }
Exemple #7
0
        private static Panel CreateViewRules([NotNull] FormSparseWorkingCopyViewModel sparse, [NotNull] ToolTip tooltip, [NotNull] IGitUICommandsSource cmdsource)
        {
            // Label
            var label1 = new Label()
            {
                AutoSize = true, Text = Globalized.Strings.SpecifyTheRulesForIncludingOrExcludingFilesAndDirectories.Text, Dock = DockStyle.Top, Padding = new Padding(10, 5, 10, 0)
            };
            var label2 = new Label()
            {
                AutoSize = true, Text = Globalized.Strings.SpecifyTheRulesForIncludingOrExcludingFilesAndDirectoriesLine2.Text, Dock = DockStyle.Top, Padding = new Padding(25, 3, 10, 3), ForeColor = SystemColors.GrayText
            };

            sparse.PropertyChanged += delegate { label1.Visible = label2.Visible = sparse.IsSparseCheckoutEnabled; };

            // Text editor
            var editor = new FileViewer()
            {
                Dock = DockStyle.Fill, UICommandsSource = cmdsource, IsReadOnly = false
            };

            editor.TextLoaded += (sender, args) => sparse.SetRulesTextAsOnDisk(editor.GetText());
            try
            {
                FileInfo sparsefile = sparse.GetPathToSparseCheckoutFile();
                if (sparsefile.Exists)
                {
                    editor.ViewFile(sparsefile.FullName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ActiveForm, Globalized.Strings.CannotLoadTheTextOfTheSparseFile.Text + "\n\n" + ex.Message, Globalized.Strings.SparseWorkingCopy.Text + " – " + Globalized.Strings.LoadFile.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            editor.TextChanged += (sender, args) => sparse.RulesText = editor.GetText() ?? "";
            tooltip.SetToolTip(editor, Globalized.Strings.EditsTheContentsOfTheGitInfoSparseCheckoutFile.Text);
            Control separator = CreateViewSeparator(DockStyle.Top);

            sparse.PropertyChanged += delegate { editor.Visible = separator.Visible = sparse.IsSparseCheckoutEnabled; };

            var panel = new Panel()
            {
                Margin = Padding.Empty, Padding = Padding.Empty, Controls = { editor, separator, label2, label1 }, AutoSize = true, Dock = DockStyle.Fill
            };

            return(panel);
        }
        private static Control CreateViewOnOff([NotNull] FormSparseWorkingCopyViewModel sparse, [NotNull] ToolTip tooltip)
        {
            // When disabled: hint-like panel to enable
            var panelWhenDisabled = new TableLayoutPanel()
            {
                BackColor = SystemColors.Info, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, Dock = DockStyle.Bottom, ColumnCount = 2, RowCount = 1, ColumnStyles = { new ColumnStyle(SizeType.Percent, 100) }, Margin = Padding.Empty, Padding = new Padding(10, 5, 10, 5)
            };

            panelWhenDisabled.Controls.Add(new Label()
            {
                ForeColor = SystemColors.InfoText, Text = Globalized.Strings.SparseWorkingCopySupportHasNotBeenEnabledForThisRepository.Text, Dock = DockStyle.Fill, AutoSize = true, TextAlign = ContentAlignment.MiddleLeft, Margin = Padding.Empty
            });
            Button btnEnable;

            panelWhenDisabled.Controls.Add(btnEnable = new Button {
                Width = 75, Height = 23, Text = Globalized.Strings.Enable.Text, Anchor = AnchorStyles.Bottom | AnchorStyles.Right, Dock = DockStyle.Right, UseVisualStyleBackColor = true, Margin = Padding.Empty
            });
            btnEnable.Click += delegate { sparse.IsSparseCheckoutEnabled = true; };
            tooltip.SetToolTip(btnEnable, string.Format(Globalized.Strings.SetsTheGitPropertyToTrueForTheLocalRepository.Text, FormSparseWorkingCopyViewModel.SettingCoreSparseCheckout));
            sparse.PropertyChanged += delegate { panelWhenDisabled.Visible = !sparse.IsSparseCheckoutEnabled; };

            // When-disabled case should have a separator
            Control separatorWhenDisabled = CreateViewSeparator(DockStyle.Bottom);

            sparse.PropertyChanged += delegate { separatorWhenDisabled.Visible = !sparse.IsSparseCheckoutEnabled; };

            // When enabled: a less bold link to disable
            string sLabelBeforeLink = Globalized.Strings.SparseWorkingCopySupportIsEnabled.Text + ' ';
            string sLabelWithLink   = sLabelBeforeLink + Globalized.Strings.DisableForThisRepository.Text;
            var    labelWhenEnabled = new LinkLabel()
            {
                Text = sLabelWithLink, Dock = DockStyle.Bottom, AutoSize = true, Padding = new Padding(10, 10, 10, 5), FlatStyle = FlatStyle.System, UseCompatibleTextRendering = true
            };

            labelWhenEnabled.Links.Add(new LinkLabel.Link(sLabelBeforeLink.Length, sLabelWithLink.Length - sLabelBeforeLink.Length));
            labelWhenEnabled.LinkClicked += delegate { sparse.IsSparseCheckoutEnabled = false; };
            tooltip.SetToolTip(labelWhenEnabled, string.Format(Globalized.Strings.SetsTheGitPropertyToFalseForTheLocalRepository.Text, FormSparseWorkingCopyViewModel.SettingCoreSparseCheckout));
            sparse.PropertyChanged += delegate { labelWhenEnabled.Visible = sparse.IsSparseCheckoutEnabled; };

            return(new Panel()
            {
                Dock = DockStyle.Fill, Controls = { panelWhenDisabled, separatorWhenDisabled, labelWhenEnabled }, Margin = Padding.Empty, Padding = Padding.Empty, AutoSize = true
            });
        }
        private void BindSaveOnClose(FormSparseWorkingCopyViewModel sparse)
        {
            if (sparse is null)
            {
                throw new ArgumentNullException(nameof(sparse));
            }

            Closing += (sender, args) =>
            {
                try
                {
                    // Save on OK — even if not dirty, to upd the rules if checkbox is ON
                    if (DialogResult == DialogResult.OK)
                    {
                        sparse.SaveChanges();
                        return;
                    }

                    // Closing/canceling, prompt to save if dirty
                    if (sparse.IsWithUnsavedChanges())
                    {
                        switch (MessageBox.Show(this, Globalized.Strings.YouHaveMadeChangesToSettingsOrRulesWouldYouLikeToSaveThem.Text, Globalized.Strings.SparseWorkingCopy.Text + " – " + Globalized.Strings.Cancel.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                        {
                        case DialogResult.Yes:
                            sparse.SaveChanges();
                            break;

                        case DialogResult.No:
                            // Just exit
                            break;

                        default:
                            // Cancel, or error
                            args.Cancel = true;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ActiveForm, Globalized.Strings.CouldNotSave.Text + "\n\n" + ex.Message, Globalized.Strings.SparseWorkingCopy.Text + " – " + Globalized.Strings.SaveFile.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };
        }