/// <summary> /// Load a workspace selected by the last recently used menu /// </summary> private void WorkspaceLoadLruMenuItem(object sender, EventArgs e) { string name = (sender as ToolStripMenuItem).Tag as string; // Save existing workspace before trying to load a new one if (ClassWorkspace.Save(null)) { if (ClassWorkspace.Load(name)) { App.DoRefresh(); } else { if (MessageBox.Show("The specified workspace file cannot be loaded, or the loading was cancelled." + Environment.NewLine + "Do you want to remove it from the list of recently used workspaces?", "Load Workspace", MessageBoxButtons.YesNo, MessageBoxIcon.Error) != DialogResult.Yes) { return; } // Remove the workspace file from the LRU list var lru = ClassWorkspace.GetLRU(); lru.Remove(name); ClassWorkspace.SetLRU(lru); } } }
/// <summary> /// Pull from one or more remote repositories. /// If the number of *selected* repos is 2 or more, this function will operate on /// those selected repos irrespective of the current one. Otherwise, pull the /// current repo. Stops if a repo operation fails. /// </summary> private void MenuRepoPull(object sender, EventArgs e) { List <ClassRepo> repos = PanelRepos.GetSelectedRepos(); if (repos.Count <= 1) // Disregard selected repos and use the current one { repos = new List <ClassRepo> { App.Repos.Current } } ; // By default, pull command will pull from a currently selected remote repo // If the user holds down the Control key, it will pull from all remote repos while trying to merge them bool allRemotes = Control.ModifierKeys == Keys.Control; foreach (var r in repos) { foreach (var remote in r.Remotes.GetListNames()) { if (allRemotes || remote == r.Remotes.Current) { string args = remote + " " + r.Branches.Current; PrintStatus("Pull from a remote repo \"" + args + "\" into \"" + r.Path + "\"", MessageType.General); if (!r.RunCmd("pull " + args).Success()) { goto Done; } } } } Done : App.DoRefresh(); }
/// <summary> /// Edit the list of remote repositories /// </summary> private void MenuEditRemoteRepos(object sender, EventArgs e) { FormRemoteEdit remoteEdit = new FormRemoteEdit(App.Repos.Current); if (remoteEdit.ShowDialog() == DialogResult.OK) { App.DoRefresh(); } }
/// <summary> /// User clicked on the Unstash menu item /// </summary> private void MenuMainUnstashClick(object sender, EventArgs e) { FormUnstash formUnstash = new FormUnstash(); if (formUnstash.ShowDialog() == DialogResult.OK) { App.DoRefresh(); } }
/// <summary> /// Select and load a specific workspace /// </summary> private void WorkspaceLoadMenuItem(object sender, EventArgs e) { if (loadWk.ShowDialog() == DialogResult.OK) { // Save existing workspace before trying to load a new one if (ClassWorkspace.Save(null)) { if (ClassWorkspace.Load(loadWk.FileName)) { App.DoRefresh(); } } } }
private void FormMainDragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Count() == 1 && Path.GetExtension(files[0]) == ".giw") { // Save the current workspace and load the one user dropped in if (ClassWorkspace.Save(null)) { if (ClassWorkspace.Load(files[0])) { App.DoRefresh(); } } } }
/// <summary> /// Create a new workspace at the specified (workspace) file location /// </summary> private void WorkspaceCreateMenuItem(object sender, EventArgs e) { // Save existing workspace before trying to create a new one if (ClassWorkspace.Save(null)) { // Ask user to select a new workspace file name if (createWk.ShowDialog() == DialogResult.OK) { // Create a new workspace by saving an empty one and then reloading it ClassWorkspace.Clear(); ClassWorkspace.Save(createWk.FileName); ClassWorkspace.Load(createWk.FileName); App.DoRefresh(); } } }
/// <summary> /// Sync file to the selected revision /// </summary> private void SyncMenuItemClick(object sender, EventArgs e) { if (MessageBox.Show("This will sync file to a previous version. Continue?", "Revision Sync", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string cmd = string.Format("checkout {1} -- {0}", file, lruSha[0]); ExecResult result = App.Repos.Current.RunCmd(cmd); if (result.Success()) { App.PrintStatusMessage("File checked out at a previous revision " + lruSha[0] + ": " + file, MessageType.General); App.DoRefresh(); } else { App.PrintStatusMessage("Sync error: " + result.stderr, MessageType.Error); MessageBox.Show(result.stderr, "Sync error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Pull from one or more remote repositories. /// If the number of *selected* repos is 2 or more, this function will operate on /// those selected repos irrespective of the current one. Otherwise, pull the /// current repo. Stops if a repo operation fails. /// </summary> private void MenuRepoPull(object sender, EventArgs e) { List <ClassRepo> repos = PanelRepos.GetSelectedRepos(); if (repos.Count <= 1) // Disregard selected repos and use the current one { repos = new List <ClassRepo> { App.Repos.Current } } ; foreach (var r in repos) { string args = r.Remotes.Current + " " + r.Branches.Current; PrintStatus("Pull from a remote repo \"" + args + "\" into \"" + r.Root + "\"", MessageType.General); if (!r.RunCmd("pull " + args).Success()) { break; } } App.DoRefresh(); }
/// <summary> /// Helper function that clears current workspace /// </summary> public static void Clear() { App.Repos.Repos.Clear(); App.Repos.Refresh(); App.DoRefresh(); }
/// <summary> /// Refresh Active Pane (do a global refresh for now) /// </summary> private void MenuRefreshAll(object sender, EventArgs e) { App.DoRefresh(); }
/// <summary> /// Runs a custom tool. /// Returns a string with a tool output to be printed out. /// This string can be empty, in which case nothing should be printed. /// </summary> public string Run(List <string> files) { App.PrintLogMessage(ToString(), MessageType.Command); string stdout = string.Empty; string args = DeMacroise(Args, files); // Add custom arguments if the checkbox to Prompt for Arguments was checked if (IsPromptForArgs) { // Description is used as a question for the arguments, shown in the window title bar string desc = Name; if (!string.IsNullOrEmpty(Desc)) { desc += ": " + Desc; } FormCustomToolArgs formCustomToolArgs = new FormCustomToolArgs(desc, args, IsAddBrowse); if (formCustomToolArgs.ShowDialog() == DialogResult.Cancel) { return(string.Empty); } args = formCustomToolArgs.GetArgs(); } App.StatusBusy(true); // Prepare the process to be run Process proc = new Process(); proc.StartInfo.FileName = "\"" + Cmd + "\""; proc.StartInfo.Arguments = args; proc.StartInfo.WorkingDirectory = DeMacroise(Dir, new List <string>()); proc.StartInfo.UseShellExecute = false; try { // Run the custom tool in two ways (console app and GUI app) if (IsConsoleApp) { // Start a console process proc.StartInfo.CreateNoWindow = false; // If we have to keep the window open (CMD/SHELL) after exit, // we start the command line app in a different way, using a // shell command (in which case we cannot redirect the stdout) if (IsCloseWindowOnExit) { App.MainForm.SetTitle("Waiting for " + Cmd + " to finish..."); // Redirect standard output to our status pane if requested if (IsWriteOutput) { proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.OutputDataReceived += ProcOutputDataReceived; proc.ErrorDataReceived += ProcErrorDataReceived; proc.Start(); proc.BeginOutputReadLine(); proc.WaitForExit(); } else { proc.Start(); proc.WaitForExit(); } } else { // We need to keep the CMD/SHELL window open, so start the process using // the CMD/SHELL as the root process and pass it our command to execute proc.StartInfo.Arguments = string.Format("{0} {1} {2}", ClassUtils.GetShellExecFlags(), proc.StartInfo.FileName, proc.StartInfo.Arguments); proc.StartInfo.FileName = ClassUtils.GetShellExecCmd(); App.PrintLogMessage(proc.StartInfo.Arguments, MessageType.Command); proc.Start(); } } else { // Start a GUI process proc.StartInfo.CreateNoWindow = true; // We can start the process and wait for it to finish only if we need to // refresh the app after the process has exited. proc.Start(); } if (IsRefresh) { App.MainForm.SetTitle("Waiting for " + Cmd + " to finish..."); proc.WaitForExit(); App.DoRefresh(); } } catch (Exception ex) { App.PrintStatusMessage(ex.Message, MessageType.Error); MessageBox.Show(ex.Message, "Error executing custom tool", MessageBoxButtons.OK, MessageBoxIcon.Error); } proc.Close(); App.StatusBusy(false); return(stdout); }