public void RegisterShortcut(Keys key, UICommands.UICommand command) { if (command != null && key != Keys.None) { mKeyBindings[key] = command; } }
public Keys GetKey(UICommands.UICommand command) { foreach (DictionaryEntry bindings in mKeyBindings) { if (bindings.Value == command) return (Keys)bindings.Key; } return Keys.None; }
private void PullClick(object sender, EventArgs e) { UICommands.StartPullDialog(this); }
private void CommitButtonClick(object sender, EventArgs e) { UICommands.StartCommitDialog(this); EnableButtons(); }
private void PruneWorktrees() { UICommands.StartCommandLineProcessDialog(this, "git", "worktree prune"); Initialize(); }
public bool Rebase() { return(UICommands.StartRebaseDialog(TreeViewNode.TreeView, FullPath)); }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && string.IsNullOrEmpty(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return(false); } if (PushToRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) { MessageBox.Show(owner, _selectRemote.Text); return(false); } if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { MessageBox.Show(owner, _selectTag.Text); return(false); } //Extra check if the branch is already known to the remote, give a warning when not. //This is not possible when the remote is an URL, but this is ok since most users push to //known remotes anyway. if (TabControlTagBranch.SelectedTab == BranchTab && PushToRemote.Checked && !Module.IsBareRepository()) { //If the current branch is not the default push, and not known by the remote //(as far as we know since we are disconnected....) if (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text, _NO_TRANSLATE_Branch.Text) && !Module.GetRefs(false, true).Any(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.Name == RemoteBranch.Text)) { //Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } } } if (PushToUrl.Checked) { Repositories.AddMostRecentRepository(PushDestination.Text); } AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { if (GitCommandHelpers.Plink()) { if (!File.Exists(AppSettings.Pageant)) { MessageBoxes.PAgentNotFound(owner); } else { Module.StartPageantForRemote(_NO_TRANSLATE_Remotes.Text); } } destination = _NO_TRANSLATE_Remotes.Text; remote = _NO_TRANSLATE_Remotes.Text.Trim(); } string pushCmd; if (TabControlTagBranch.SelectedTab == BranchTab) { bool track = ReplaceTrackingReference.Checked; if (!track && !string.IsNullOrWhiteSpace(RemoteBranch.Text)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; track = selectedLocalBranch != null && string.IsNullOrEmpty(selectedLocalBranch.TrackingRemote); string[] remotes = _NO_TRANSLATE_Remotes.DataSource as string[]; if (remotes != null) { foreach (string remoteBranch in remotes) { if (!string.IsNullOrEmpty(remoteBranch) && _NO_TRANSLATE_Branch.Text.StartsWith(remoteBranch)) { track = false; } } } if (track && !AppSettings.DontConfirmAddTrackingRef) { DialogResult result = MessageBox.Show(String.Format(_updateTrackingReference.Text, selectedLocalBranch.Name, RemoteBranch.Text), _pushCaption.Text, MessageBoxButtons.YesNoCancel); if (result == DialogResult.Cancel) { return(false); } track = result == DialogResult.Yes; } } // Try to make source rev into a fully qualified branch name. If that // doesn't exist, then it must be something other than a branch, so // fall back to using the name just as it was passed in. string srcRev = ""; bool pushAllBranches = false; if (_NO_TRANSLATE_Branch.Text == AllRefs) { pushAllBranches = true; } else { srcRev = GitCommandHelpers.GetFullBranchName(_NO_TRANSLATE_Branch.Text); if (String.IsNullOrEmpty(Module.RevParse(srcRev))) { srcRev = _NO_TRANSLATE_Branch.Text; } } pushCmd = GitCommandHelpers.PushCmd(destination, srcRev, RemoteBranch.Text, pushAllBranches, ForcePushBranches.Checked, track, RecursiveSubmodules.SelectedIndex); } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, ForcePushBranches.Checked); } else { // Push Multiple Branches Tab selected var pushActions = new List <GitPushAction>(); foreach (DataRow row in _branchTable.Rows) { var push = Convert.ToBoolean(row["Push"]); var force = Convert.ToBoolean(row["Force"]); var delete = Convert.ToBoolean(row["Delete"]); if (push || force) { pushActions.Add(new GitPushAction(row["Local"].ToString(), row["Remote"].ToString(), force)); } else if (delete) { pushActions.Add(new GitPushAction(row["Remote"].ToString())); } } pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); //controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _selectedBranchRemote = _NO_TRANSLATE_Remotes.Text; _selectedRemoteBranchName = RemoteBranch.Text; using (var form = new FormRemoteProcess(Module, pushCmd) { Remote = remote, Text = string.Format(_pushToCaption.Text, destination), HandleOnExitCallback = HandlePushOnExit }) { form.ShowDialog(owner); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) { UICommands.StartCreatePullRequest(owner); } return(true); } } return(false); }
private void StashClick(object sender, EventArgs e) { UICommands.StartStashDialog(this); }
public DialogResult PullChanges(IWin32Window owner) { if (!ShouldPullChanges()) { return(DialogResult.No); } UpdateSettingsDuringPull(); DialogResult dr = ShouldRebaseMergeCommit(); if (dr != DialogResult.Yes) { return(dr); } if (!Fetch.Checked && Branches.Text.IsNullOrWhiteSpace() && Module.IsDetachedHead()) { int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner, _notOnBranchCaption.Text, _notOnBranchMainInstruction.Text, _notOnBranch.Text, _notOnBranchButtons.Text, true); switch (idx) { case 0: if (!UICommands.StartCheckoutBranch(owner, new[] { "" })) { return(DialogResult.Cancel); } break; case -1: return(DialogResult.Cancel); } } if (PullFromUrl.Checked && Directory.Exists(comboBoxPullSource.Text)) { Repositories.RepositoryHistory.AddMostRecentRepository(comboBoxPullSource.Text); } var source = CalculateSource(); string curLocalBranch; string curRemoteBranch; if (!CalculateLocalBranch(source, out curLocalBranch, out curRemoteBranch)) { return(DialogResult.No); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); var stashed = CalculateStashedValue(owner); using (FormProcess process = CreateFormProcess(source, curLocalBranch, curRemoteBranch)) { ShowProcessDialogBox(owner, source, process); try { bool aborted = process != null && process.DialogResult == DialogResult.Abort; if (!aborted && !Fetch.Checked) { if (!ErrorOccurred) { if (!InitModules()) { UICommands.UpdateSubmodules(owner); } } else { CheckMergeConflictsOnError(owner); } } } finally { if (stashed) { PopStash(owner); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull); } return(DialogResult.OK); } }
private void settingsButton_Click(object sender, EventArgs e) { UICommands.StartSettingsDialog(this.ParentForm, DiffViewerSettingsPage.GetPageReference()); }
private DialogResult OkClick() { // Ok button set as the "AcceptButton" for the form // if the user hits [Enter] at any point, we need to trigger txtCustomBranchName Leave event Ok.Focus(); GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { IGitRef localBranchRef = GetLocalBranchRef(_localBranchName); IGitRef remoteBranchRef = GetRemoteBranchRef(cmd.BranchName); if (localBranchRef != null && remoteBranchRef != null) { string mergeBaseGuid = Module.GetMergeBase(localBranchRef.Guid, remoteBranchRef.Guid); bool isResetFastForward = localBranchRef.Guid.Equals(mergeBaseGuid); if (!isResetFastForward) { string mergeBaseText = mergeBaseGuid.IsNullOrWhiteSpace() ? "merge base" : GitRevision.ToShortSha(mergeBaseGuid); string warningMessage = string.Format(_resetNonFastForwardBranch.Text, _localBranchName, mergeBaseText); if (MessageBox.Show(this, warningMessage, resetCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { DialogResult = DialogResult.None; return(DialogResult.None); } } } cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } LocalChangesAction changes = ChangesMode; if (changes != LocalChangesAction.Reset && chkSetLocalChangesActionAsDefault.Checked) { AppSettings.CheckoutBranchAction = changes; } if ((Visible || AppSettings.UseDefaultCheckoutBranchAction) && IsThereUncommittedChanges()) { cmd.LocalChanges = changes; } else { cmd.LocalChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = false; if (changes == LocalChangesAction.Stash) { if (_isDirtyDir == null && Visible) { _isDirtyDir = Module.IsDirtyDir(); } stash = _isDirtyDir == true; if (stash) { UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash); } } ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); if (UICommands.StartCommandLineProcessDialog(cmd, owner)) { if (stash) { bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch; if (messageBoxResult == null) { DialogResult res = PSTaskDialog.cTaskDialog.MessageBox( this, _applyShashedItemsAgainCaption.Text, "", _applyShashedItemsAgain.Text, "", "", _dontShowAgain.Text, PSTaskDialog.eTaskDialogButtons.YesNo, PSTaskDialog.eSysIcons.Question, PSTaskDialog.eSysIcons.Question); messageBoxResult = (res == DialogResult.Yes); if (PSTaskDialog.cTaskDialog.VerificationChecked) { AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { UICommands.StashPop(this); } } UICommands.UpdateSubmodules(this); ScriptManager.RunEventScripts(this, ScriptEvent.AfterCheckout); return(DialogResult.OK); } return(DialogResult.None); }
private void Initialize() { var listWorktree = ThreadHelper.JoinableTaskFactory.Run(() => UICommands.CommandLineCommandAsync("git", "worktree list --porcelain")); var worktreesLines = listWorktree.Split('\n').GetEnumerator(); _worktrees = new List <WorkTree>(); WorkTree currentWorktree = null; while (worktreesLines.MoveNext()) { var current = (string)worktreesLines.Current; if (string.IsNullOrWhiteSpace(current)) { continue; } var strings = current.Split(' '); if (strings[0] == "worktree") { currentWorktree = new WorkTree { Path = current.Substring(9) }; currentWorktree.IsDeleted = !Directory.Exists(currentWorktree.Path); _worktrees.Add(currentWorktree); } else if (strings[0] == "HEAD") { currentWorktree.Sha1 = strings[1]; } else { switch (strings[0]) { case "bare": currentWorktree.Type = HeadType.Bare; break; case "branch": currentWorktree.Type = HeadType.Branch; currentWorktree.Branch = strings[1]; break; case "detached": currentWorktree.Type = HeadType.Detached; break; } } } Worktrees.DataSource = _worktrees; for (var i = 0; i < Worktrees.Rows.Count; i++) { if (i == 0) { Worktrees.Rows[i].Cells["Delete"].Value = Resources.IconBlank; if (IsCurrentlyOpenedWorktree(_worktrees[0])) { Worktrees.Rows[i].Cells["Open"].Value = Resources.IconBlank; } } else if (!CanDeleteWorkspace(_worktrees[i])) { Worktrees.Rows[i].Cells["Open"].Value = Resources.IconBlank; Worktrees.Rows[i].Cells["Delete"].Value = Resources.IconBlank; } } buttonPruneWorktrees.Enabled = _worktrees.Skip(1).Any(w => w.IsDeleted); }
public bool Merge() { return(UICommands.StartMergeBranchDialog(TreeViewNode.TreeView, FullPath)); }
public bool Checkout() { return(UICommands.StartCheckoutRemoteBranch(TreeViewNode.TreeView, FullPath)); }
public bool Delete() { var remoteBranchInfo = GetRemoteBranchInfo(); return(UICommands.StartDeleteRemoteBranchDialog(TreeViewNode.TreeView, remoteBranchInfo.Remote + '/' + remoteBranchInfo.BranchName)); }
bool ExcuteCommand(UICommands cmd, Transform chess) { bool excuted = false; switch(cmd){ case UICommands.Attack: excuted = AttackCommand(chess); break; case UICommands.Defense: excuted = DefenseCommand(chess); break; case UICommands.Move: excuted = MoveCommand(chess); break; case UICommands.Skill: excuted = SkillCommand(chess); break; case UICommands.Turnfinished: excuted = FinishCommand(chess); break; case UICommands.Summon: excuted = SummonCommand(chess); break; case UICommands.none: if(!chess.GetComponent<CharacterProperty>().Defensed || !chess.GetComponent<CharacterProperty>().Attacked) excuted = DefenseCommand(chess); break; } return excuted; }
internal void PopupManageRemotesForm(string remoteName) { UICommands.StartRemotesDialog(TreeViewNode.TreeView, remoteName); }
private void cloneItem_Click(object sender, EventArgs e) { UICommands.StartCloneDialog(this, null, false, OnModuleChanged); }
private void ApplyClick(object sender, EventArgs e) { UICommands.StashApply(this, GetStashName()); Initialize(); }
private void createItem_Click(object sender, EventArgs e) { UICommands.StartInitializeDialog(this, Module.WorkingDir, OnModuleChanged); }
private bool HandlePushOnExit(ref bool isError, FormProcess form) { if (!isError) { return(false); } //there is no way to pull to not current branch if (_selectedBranch != _currentBranch) { return(false); } //auto pull from URL not supported. See https://github.com/gitextensions/gitextensions/issues/1887 if (!PushToRemote.Checked) { return(false); } //auto pull only if current branch was rejected Regex IsRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranch) + ".*", RegexOptions.Compiled); if (IsRejected.IsMatch(form.GetOutputString()) && !Module.IsBareRepository()) { bool forcePush = false; IWin32Window owner = form; if (AppSettings.AutoPullOnPushRejectedAction == null) { bool cancel = false; string destination = PushToRemote.Checked ? _NO_TRANSLATE_Remotes.Text : PushDestination.Text; int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner, String.Format(_pullRepositoryCaption.Text, destination), _pullRepositoryMainInstruction.Text, _pullRepository.Text, "", "", _dontShowAgain.Text, _pullRepositoryButtons.Text, true, 0, 0); bool rememberDecision = PSTaskDialog.cTaskDialog.VerificationChecked; switch (idx) { case 0: if (rememberDecision) { AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.Default; } if (Module.LastPullAction == AppSettings.PullAction.None) { return(false); } Module.LastPullActionToFormPullAction(); break; case 1: AppSettings.FormPullAction = AppSettings.PullAction.Rebase; if (rememberDecision) { AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction; } break; case 2: AppSettings.FormPullAction = AppSettings.PullAction.Merge; if (rememberDecision) { AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction; } break; case 3: forcePush = true; break; default: cancel = true; if (rememberDecision) { AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.None; } break; } if (cancel) { return(false); } } if (forcePush) { if (!form.ProcessArguments.Contains(" -f ")) { form.ProcessArguments = form.ProcessArguments.Replace("push", "push -f"); } form.Retry(); return(true); } if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.None) { return(false); } if (AppSettings.FormPullAction == AppSettings.PullAction.Fetch) { form.AppendOutputLine(Environment.NewLine + "Can not perform auto pull, when merge option is set to fetch."); return(false); } if (IsRebasingMergeCommit()) { form.AppendOutputLine(Environment.NewLine + "Can not perform auto pull, when merge option is set to rebase " + Environment.NewLine + "and one of the commits that are about to be rebased is a merge."); return(false); } bool pullCompleted; UICommands.StartPullDialog(owner, true, null, _selectedBranchRemote, out pullCompleted, false); if (pullCompleted) { form.Retry(); return(true); } } return(false); }
public void RefreshContent() { InitDashboardLayout(); ApplyTheme(); userRepositoriesList.ShowRecentRepositories(); void ApplyTheme() { _selectedTheme = SystemColors.ControlText.IsLightColor() ? DashboardTheme.Dark : DashboardTheme.Light; BackColor = _selectedTheme.Primary; pnlLogo.BackColor = _selectedTheme.PrimaryVeryDark; flpnlStart.BackColor = _selectedTheme.PrimaryLight; flpnlContribute.BackColor = _selectedTheme.PrimaryVeryLight; lblContribute.ForeColor = _selectedTheme.SecondaryHeadingText; userRepositoriesList.BranchNameColor = AppSettings.BranchColor; // _selectedTheme.SecondaryText; userRepositoriesList.FavouriteColor = _selectedTheme.AccentedText; userRepositoriesList.ForeColor = _selectedTheme.PrimaryText; userRepositoriesList.HeaderColor = _selectedTheme.SecondaryHeadingText; userRepositoriesList.HeaderBackColor = _selectedTheme.PrimaryDark; userRepositoriesList.HoverColor = _selectedTheme.PrimaryLight; userRepositoriesList.MainBackColor = _selectedTheme.Primary; BackgroundImage = _selectedTheme.BackgroundImage; foreach (var item in flpnlContribute.Controls.OfType <LinkLabel>().Union(flpnlStart.Controls.OfType <LinkLabel>())) { item.LinkColor = _selectedTheme.PrimaryText; } } void InitDashboardLayout() { try { pnlLeft.SuspendLayout(); AddLinks(flpnlContribute, panel => { panel.Controls.Add(lblContribute); lblContribute.Font = new Font(AppSettings.Font.FontFamily, AppSettings.Font.SizeInPoints + 5.5f); CreateLink(panel, _develop.Text, Images.Develop, GitHubItem_Click); CreateLink(panel, _donate.Text, Images.DollarSign, DonateItem_Click); CreateLink(panel, _translate.Text, Images.Translate, TranslateItem_Click); var lastControl = CreateLink(panel, _issues.Text, Images.Bug, IssuesItem_Click); return(lastControl); }, (panel, lastControl) => { var height = lastControl.Location.Y + lastControl.Size.Height + panel.Padding.Bottom; panel.Height = height; panel.MinimumSize = new Size(0, height); }); AddLinks(flpnlStart, panel => { CreateLink(panel, _createRepository.Text, Images.RepoCreate, createItem_Click); CreateLink(panel, _openRepository.Text, Images.RepoOpen, openItem_Click); var lastControl = CreateLink(panel, _cloneRepository.Text, Images.CloneRepoGit, cloneItem_Click); foreach (var gitHoster in PluginRegistry.GitHosters) { lastControl = CreateLink(panel, string.Format(_cloneFork.Text, gitHoster.Description), Images.CloneRepoGitHub, (repoSender, eventArgs) => UICommands.StartCloneForkFromHoster(this, gitHoster, GitModuleChanged)); } return(lastControl); }, (panel, lastControl) => { var height = lastControl.Location.Y + lastControl.Size.Height + panel.Padding.Bottom; panel.MinimumSize = new Size(0, height); }); } finally { pnlLeft.ResumeLayout(false); pnlLeft.PerformLayout(); AutoScrollMinSize = new Size(0, pnlLogo.Height + flpnlStart.MinimumSize.Height + flpnlContribute.MinimumSize.Height); } void AddLinks(Panel panel, Func <Panel, Control> addLinks, Action <Panel, Control> onLayout) { panel.SuspendLayout(); panel.Controls.Clear(); var lastControl = addLinks(panel); panel.ResumeLayout(false); panel.PerformLayout(); onLayout(panel, lastControl); } Control CreateLink(Control container, string text, Image icon, EventHandler handler) { var padding24 = DpiUtil.Scale(24); var padding3 = DpiUtil.Scale(3); var linkLabel = new LinkLabel { AutoSize = true, AutoEllipsis = true, Font = AppSettings.Font, Image = DpiUtil.Scale(icon), ImageAlign = ContentAlignment.MiddleLeft, LinkBehavior = LinkBehavior.NeverUnderline, Margin = new Padding(padding3, 0, padding3, DpiUtil.Scale(8)), Padding = new Padding(padding24, padding3, padding3, padding3), TabStop = true, Text = text, TextAlign = ContentAlignment.MiddleLeft }; linkLabel.MouseHover += (s, e) => linkLabel.LinkColor = _selectedTheme.AccentedText; linkLabel.MouseLeave += (s, e) => linkLabel.LinkColor = _selectedTheme.PrimaryText; if (handler != null) { linkLabel.Click += handler; } container.Controls.Add(linkLabel); return(linkLabel); } } }
public bool Reset() { return(UICommands.StartResetCurrentBranchDialog(TreeViewNode.TreeView, FullPath)); }
private void diffToolRemoteLocalStripMenuItem_Click(object sender, EventArgs e) { UICommands.OpenWithDifftool(this, FileChanges.GetSelectedRevisions(), FileName, string.Empty, RevisionDiffKind.DiffBLocal, true); }
private void AddFilesClick(object sender, EventArgs e) { UICommands.StartAddFilesDialog(this); }
public void Checkout() { UICommands.StartCheckoutBranch(FullPath, false); }
private bool PushChanges(IWin32Window owner) { ErrorOccurred = false; if (PushToUrl.Checked && string.IsNullOrEmpty(PushDestination.Text)) { MessageBox.Show(owner, _selectDestinationDirectory.Text); return(false); } if (/* PushToRemote.Checked */ !CheckIfRemoteExist()) { return(false); } var selectedRemoteName = _selectedRemote.Name; if (TabControlTagBranch.SelectedTab == TagTab && string.IsNullOrEmpty(TagComboBox.Text)) { MessageBox.Show(owner, _selectTag.Text); return(false); } // Extra check if the branch is already known to the remote, give a warning when not. // This is not possible when the remote is an URL, but this is ok since most users push to // known remotes anyway. if (TabControlTagBranch.SelectedTab == BranchTab && PushToRemote.Checked && !Module.IsBareRepository()) { // If the current branch is not the default push, and not known by the remote // (as far as we know since we are disconnected....) if (_NO_TRANSLATE_Branch.Text != AllRefs && RemoteBranch.Text != _remoteManager.GetDefaultPushRemote(_selectedRemote, _NO_TRANSLATE_Branch.Text) && !IsBranchKnownToRemote(selectedRemoteName, RemoteBranch.Text)) { // Ask if this is really what the user wants if (!AppSettings.DontConfirmPushNewBranch && MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } } } if (PushToUrl.Checked) { var path = PushDestination.Text; ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(path)); } AppSettings.RecursiveSubmodules = RecursiveSubmodules.SelectedIndex; var remote = ""; string destination; if (PushToUrl.Checked) { destination = PushDestination.Text; } else { EnsurePageant(selectedRemoteName); destination = selectedRemoteName; remote = selectedRemoteName.Trim(); } string pushCmd; if (TabControlTagBranch.SelectedTab == BranchTab) { bool track = ReplaceTrackingReference.Checked; if (!track && !string.IsNullOrWhiteSpace(RemoteBranch.Text)) { GitRef selectedLocalBranch = _NO_TRANSLATE_Branch.SelectedItem as GitRef; track = selectedLocalBranch != null && string.IsNullOrEmpty(selectedLocalBranch.TrackingRemote) && !UserGitRemotes.Any(x => _NO_TRANSLATE_Branch.Text.StartsWith(x.Name, StringComparison.OrdinalIgnoreCase)); var autoSetupMerge = Module.EffectiveConfigFile.GetValue("branch.autoSetupMerge"); if (autoSetupMerge.IsNotNullOrWhitespace() && autoSetupMerge.ToLowerInvariant() == "false") { track = false; } if (track && !AppSettings.DontConfirmAddTrackingRef) { var result = MessageBox.Show(this, string.Format(_updateTrackingReference.Text, selectedLocalBranch.Name, RemoteBranch.Text), _pushCaption.Text, MessageBoxButtons.YesNoCancel); if (result == DialogResult.Cancel) { return(false); } track = result == DialogResult.Yes; } } if (ForcePushBranches.Checked) { if (GitCommandHelpers.VersionInUse.SupportPushForceWithLease) { var choice = MessageBox.Show(this, _useForceWithLeaseInstead.Text, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); switch (choice) { case DialogResult.Yes: ForcePushBranches.Checked = false; ckForceWithLease.Checked = true; break; case DialogResult.Cancel: return(false); } } } if (_NO_TRANSLATE_Branch.Text == AllRefs) { pushCmd = Module.PushAllCmd(destination, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } else { pushCmd = Module.PushCmd(destination, _NO_TRANSLATE_Branch.Text, RemoteBranch.Text, GetForcePushOption(), track, RecursiveSubmodules.SelectedIndex); } } else if (TabControlTagBranch.SelectedTab == TagTab) { string tag = TagComboBox.Text; bool pushAllTags = false; if (tag == AllRefs) { tag = ""; pushAllTags = true; } pushCmd = GitCommandHelpers.PushTagCmd(destination, tag, pushAllTags, GetForcePushOption()); } else { // Push Multiple Branches Tab selected var pushActions = new List <GitPushAction>(); foreach (DataRow row in _branchTable.Rows) { var push = Convert.ToBoolean(row[PushColumnName]); var force = Convert.ToBoolean(row[ForceColumnName]); var delete = Convert.ToBoolean(row[DeleteColumnName]); if (push || force) { pushActions.Add(new GitPushAction(row[LocalColumnName].ToString(), row[RemoteColumnName].ToString(), force)); } else if (delete) { pushActions.Add(GitPushAction.DeleteRemoteBranch(row[RemoteColumnName].ToString())); } } pushCmd = GitCommandHelpers.PushMultipleCmd(destination, pushActions); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePush); // controls can be accessed only from UI thread _selectedBranch = _NO_TRANSLATE_Branch.Text; _candidateForRebasingMergeCommit = PushToRemote.Checked && (_selectedBranch != AllRefs) && TabControlTagBranch.SelectedTab == BranchTab; _selectedRemoteBranchName = RemoteBranch.Text; using (var form = new FormRemoteProcess(Module, pushCmd) { Remote = remote, Text = string.Format(_pushToCaption.Text, destination), HandleOnExitCallback = HandlePushOnExit }) { form.ShowDialog(owner); ErrorOccurred = form.ErrorOccurred(); if (!Module.InTheMiddleOfAction() && !form.ErrorOccurred()) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPush); if (_createPullRequestCB.Checked) { UICommands.StartCreatePullRequest(owner); } return(true); } } return(false); }
public void DeleteAll() { var branches = Nodes.DepthEnumerator <LocalBranchNode>().Select(branch => branch.FullPath); UICommands.StartDeleteBranchDialog(ParentWindow(), branches); }
private void MergetoolClick(object sender, EventArgs e) { UICommands.StartResolveConflictsDialog(this); EnableButtons(); }
private void AddRemoteClick(object sender, EventArgs e) { UICommands.StartRemotesDialog(this); _NO_TRANSLATE_Remotes.DataSource = Module.GetRemoteNames(); }
private async Task <bool> DownloadChangeAsync(IWin32Window owner) { await this.SwitchToMainThreadAsync(); string change = _NO_TRANSLATE_Change.Text.Trim(); if (string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) { MessageBox.Show(owner, _selectRemote.Text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (string.IsNullOrEmpty(change)) { MessageBox.Show(owner, _selectChange.Text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } GerritUtil.StartAgent(owner, Module, _NO_TRANSLATE_Remotes.Text); var reviewInfo = await LoadReviewInfoAsync(); await this.SwitchToMainThreadAsync(); if (reviewInfo?["id"] == null) { MessageBox.Show(owner, _cannotGetChangeDetails.Text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // The user can enter both the Change-Id or the number. Here we // force the number to get prettier branches. change = (string)reviewInfo["number"]; string topic = _NO_TRANSLATE_TopicBranch.Text.Trim(); if (string.IsNullOrEmpty(topic)) { var topicNode = (JValue)reviewInfo["topic"]; topic = topicNode == null ? change : (string)topicNode.Value; } var authorValue = (string)((JValue)reviewInfo["owner"]["name"]).Value; string author = Regex.Replace(authorValue.ToLowerInvariant(), "\\W+", "_"); string branchName = "review/" + author + "/" + topic; var refspec = (string)((JValue)reviewInfo["currentPatchSet"]["ref"]).Value; var fetchCommand = UICommands.CreateRemoteCommand(); fetchCommand.CommandText = FetchCommand(_NO_TRANSLATE_Remotes.Text, refspec); if (!RunCommand(fetchCommand, change)) { return(false); } var checkoutCommand = UICommands.CreateRemoteCommand(); checkoutCommand.CommandText = GitCommandHelpers.BranchCmd(branchName, "FETCH_HEAD", true); checkoutCommand.Completed += (s, e) => { if (e.IsError) { if (e.Command.CommandText.Contains("already exists")) { // Recycle the current review branch. var recycleCommand = UICommands.CreateRemoteCommand(); recycleCommand.CommandText = "checkout " + branchName; if (!RunCommand(recycleCommand, change)) { return; } var resetCommand = UICommands.CreateRemoteCommand(); resetCommand.CommandText = GitCommandHelpers.ResetCmd(ResetMode.Hard, "FETCH_HEAD"); if (!RunCommand(resetCommand, change)) { return; } e = new GitRemoteCommandCompletedEventArgs(e.Command, false, e.Handled); } } }; return(RunCommand(checkoutCommand, change)); }
public DialogResult PullChanges(IWin32Window owner) { if (!ShouldPullChanges()) { return(DialogResult.No); } UpdateSettingsDuringPull(); DialogResult dr = ShouldRebaseMergeCommit(); if (dr != DialogResult.Yes) { return(dr); } if (!Fetch.Checked && string.IsNullOrWhiteSpace(Branches.Text) && Module.IsDetachedHead()) { int dialogResult = -1; using var dialog = new TaskDialog { OwnerWindowHandle = owner.Handle, Text = _notOnBranch.Text, InstructionText = Strings.ErrorInstructionNotOnBranch, Caption = Strings.ErrorCaptionNotOnBranch, StandardButtons = TaskDialogStandardButtons.Cancel, Icon = TaskDialogStandardIcon.Error, Cancelable = true, }; var btnCheckout = new TaskDialogCommandLink("Checkout", null, Strings.ButtonCheckoutBranch); btnCheckout.Click += (s, e) => { dialogResult = 0; dialog.Close(); }; var btnContinue = new TaskDialogCommandLink("Continue", null, Strings.ButtonContinue); btnContinue.Click += (s, e) => { dialogResult = 1; dialog.Close(); }; dialog.Controls.Add(btnCheckout); dialog.Controls.Add(btnContinue); dialog.Show(); switch (dialogResult) { case 0: if (!UICommands.StartCheckoutBranch(owner)) { return(DialogResult.Cancel); } break; case -1: return(DialogResult.Cancel); } } if (PullFromUrl.Checked && Directory.Exists(comboBoxPullSource.Text)) { var path = comboBoxPullSource.Text; ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(path)); } var source = CalculateSource(); if (!CalculateLocalBranch(source, out var curLocalBranch, out var curRemoteBranch)) { return(DialogResult.No); } executeBeforeScripts(); var stashed = CalculateStashedValue(owner); using (var form = CreateFormProcess(source, curLocalBranch, curRemoteBranch)) { if (!IsPullAll()) { form.Remote = source; } form.ShowDialog(owner); ErrorOccurred = form.ErrorOccurred(); bool executeScripts = false; try { bool aborted = form.DialogResult == DialogResult.Abort; executeScripts = !aborted && !ErrorOccurred; if (!aborted && !Fetch.Checked) { if (!ErrorOccurred) { if (!InitModules()) { UICommands.UpdateSubmodules(owner); } } else { executeScripts |= CheckMergeConflictsOnError(); } } } finally { if (stashed) { PopStash(); } if (executeScripts) { executeAfterScripts(); } } } return(DialogResult.OK); bool ShouldPullChanges() { if (PullFromUrl.Checked && string.IsNullOrEmpty(comboBoxPullSource.Text)) { MessageBox.Show(this, _selectSourceDirectory.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text) && !IsPullAll()) { MessageBox.Show(this, _selectRemoteRepository.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!Fetch.Checked && Branches.Text == "*") { MessageBox.Show(this, _fetchAllBranchesCanOnlyWithFetch.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); } string CalculateSource() { if (PullFromUrl.Checked) { return(comboBoxPullSource.Text); } LoadPuttyKey(); return(IsPullAll() ? "--all" : _NO_TRANSLATE_Remotes.Text); } bool InitModules() { if (!File.Exists(_fullPathResolver.Resolve(".gitmodules"))) { return(false); } if (!IsSubmodulesInitialized()) { if (AskIfSubmodulesShouldBeInitialized()) { UICommands.StartUpdateSubmodulesDialog(this); } return(true); } return(false); bool IsSubmodulesInitialized() { // Fast submodules check return(Module.GetSubmodulesLocalPaths() .Select(submoduleName => Module.GetSubmodule(submoduleName)) .All(submodule => submodule.IsValidGitWorkingDir())); } bool AskIfSubmodulesShouldBeInitialized() { return(MessageBox.Show(this, _questionInitSubmodules.Text, _questionInitSubmodulesCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes); } } bool CheckMergeConflictsOnError() { // Rebase failed -> special 'rebase' merge conflict if (Rebase.Checked && Module.InTheMiddleOfRebase()) { return(UICommands.StartTheContinueRebaseDialog(owner)); } else if (Module.InTheMiddleOfAction()) { return(MergeConflictHandler.HandleMergeConflicts(UICommands, owner)); } return(false); } void PopStash() { if (ErrorOccurred || Module.InTheMiddleOfAction()) { return; } bool?messageBoxResult = AppSettings.AutoPopStashAfterPull; if (messageBoxResult == null) { using var dialog = new TaskDialog { OwnerWindowHandle = owner.Handle, Text = _applyStashedItemsAgain.Text, Caption = _applyStashedItemsAgainCaption.Text, StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No, Icon = TaskDialogStandardIcon.Information, FooterCheckBoxText = _dontShowAgain.Text, FooterIcon = TaskDialogStandardIcon.Information, StartupLocation = TaskDialogStartupLocation.CenterOwner, }; messageBoxResult = dialog.Show() == TaskDialogResult.Yes; if (dialog.FooterCheckBoxChecked == true) { AppSettings.AutoPopStashAfterPull = messageBoxResult; } } if ((bool)messageBoxResult) { UICommands.StashPop(owner); } } void executeBeforeScripts() { // Request to pull/merge in addition to the fetch if (!Fetch.Checked) { ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforeFetch); } void executeAfterScripts() { ScriptManager.RunEventScripts(this, ScriptEvent.AfterFetch); // Request to pull/merge in addition to the fetch if (!Fetch.Checked) { ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull); } } }
public override bool Execute() { ResharperLogger.Debug("Initialize called on " + ProjectFilePath); EnsureWrapRepositoryIsInitialized(); if (!EnableVisualStudioIntegration) return true; ResharperHook.TryRegisterResharper(Environment, WrapDescriptorPath, PackageRepository); SolutionAddIn.Initialize(); if (_commands == null) { lock (this) if (_commands == null) { var repository = new CommandRepository(ReadCommands(Services.ServiceLocator.GetService<IEnvironment>())); _commands = new UICommands(repository); _commands.Initialize(); } } return true; }
private void AddPattern_Click(object sender, EventArgs e) { SaveGitIgnore(); UICommands.StartAddToGitIgnoreDialog(this, "*.dll"); LoadGitIgnore(); }