public async Task TestCreateDirectoryDialog() { var app = AvaloniaApp.GetApp(); var window = AvaloniaApp.GetMainWindow(); await FocusFilePanelStep.FocusFilePanelAsync(window); OpenCreateDirectoryDialogStep.OpenCreateDirectoryDialog(window); var isDialogOpened = await DialogOpenedCondition.CheckIfDialogIsOpenedAsync <CreateDirectoryDialog>(app); Assert.True(isDialogOpened); _dialog = app .Windows .OfType <CreateDirectoryDialog>() .Single(); var buttons = _dialog .GetVisualDescendants() .OfType <Button>() .ToArray(); Assert.Equal(2, buttons.Length); var createButton = buttons.SingleOrDefault(b => !b.Classes.Contains("transparentDialogButton")); Assert.NotNull(createButton); Assert.False(createButton.Command.CanExecute(null)); Assert.True(createButton.IsDefault); var directoryNameTextBox = _dialog .GetVisualDescendants() .OfType <TextBox>() .SingleOrDefault(); Assert.NotNull(directoryNameTextBox); Assert.True(string.IsNullOrEmpty(directoryNameTextBox.Text)); Assert.True(directoryNameTextBox.IsFocused); directoryNameTextBox.SendText("DirectoryName"); await WaitService.WaitForConditionAsync(() => createButton.Command.CanExecute(null)); var closeButton = buttons.SingleOrDefault(b => b.Classes.Contains("transparentDialogButton")); Assert.NotNull(closeButton); Assert.True(closeButton.Command.CanExecute(null)); Assert.False(closeButton.IsDefault); closeButton.Command.Execute(null); var isDialogClosed = await DialogClosedCondition.CheckIfDialogIsClosedAsync <CreateDirectoryDialog>(app); Assert.True(isDialogClosed); }
public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem selected = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>()); string directoryName = ""; using (CreateDirectoryDialog dlg = new CreateDirectoryDialog()) { DialogResult result = dlg.ShowDialog(e.Context); directoryName = dlg.NewDirectoryName; if (result != DialogResult.OK || string.IsNullOrEmpty(directoryName)) { return; } string log = dlg.LogMessage; // Handle special characters like on local path Uri uri = SvnTools.AppendPathSuffix(selected.Uri, directoryName); ProgressRunnerResult prResult = e.GetService <IProgressRunner>().RunModal( CommandStrings.CreatingDirectories, delegate(object sender, ProgressWorkerArgs ee) { SvnCreateDirectoryArgs args = new SvnCreateDirectoryArgs(); args.ThrowOnError = false; args.CreateParents = true; args.LogMessage = log; ee.Client.RemoteCreateDirectory(uri, args); } ); if (prResult.Succeeded) { selected.RefreshItem(false); } } }
/// <summary> /// Creates the directory specified by <see cref="uri"/> /// Returns false if the user cancelled creating the directory, true otherwise /// </summary> /// <param name="e"></param> /// <param name="title">The title of the Create dialog</param> /// <param name="uri">The directory to be created</param> /// <param name="cl"></param> /// <returns></returns> static bool RemoteCreateDirectory(CommandEventArgs e, string title, Uri uri, SvnClient cl) { using (CreateDirectoryDialog createDialog = new CreateDirectoryDialog()) { createDialog.Text = title; // Override dialog title with text from other dialog createDialog.NewDirectoryName = uri.ToString(); createDialog.NewDirectoryReadonly = true; if (createDialog.ShowDialog(e.Context) == DialogResult.OK) { // Create uri (including optional /trunk if required) SvnCreateDirectoryArgs cdArg = new SvnCreateDirectoryArgs(); cdArg.CreateParents = true; cdArg.LogMessage = createDialog.LogMessage; cl.RemoteCreateDirectory(uri, cdArg); return(true); } return(false); // bail out, we cannot continue without directory in the repository } }
/// <summary> /// Returns false if the AddToSubversionDialog has been cancelled, true otherwise /// </summary> /// <param name="e"></param> /// <param name="projectInfo"></param> /// <param name="solutionReposRoot"></param> /// <param name="shouldMarkAsManaged"></param> /// <param name="storeReference"></param> /// <returns></returns> static bool CheckoutWorkingCopyForProject(CommandEventArgs e, SccProject project, ISccProjectInfo projectInfo, Uri solutionReposRoot, out bool shouldMarkAsManaged, out bool storeReference) { shouldMarkAsManaged = false; storeReference = false; using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) using (AddProjectToSubversion dialog = new AddProjectToSubversion()) { dialog.Context = e.Context; dialog.PathToAdd = projectInfo.ProjectDirectory; dialog.RepositoryAddUrl = solutionReposRoot; if (e.Argument is IAnkhSccService) { dialog.CommitAllVisible = false; dialog.CommitAllFiles = false; } else { dialog.CommitAllFiles = true; } if (dialog.ShowDialog(e.Context) != DialogResult.OK) { return(false); // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh } if (!dialog.CommitAllFiles) { Collection <SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) { return(false); // Create failed; bail out } } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); } else { // Cache some values before thread marshalling HybridCollection <string> projectFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); string wcDir = dialog.WorkingCopyDir; Uri reposUrl = dialog.RepositoryAddUrl; string logMessage; projectFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOf(project)); using (CreateDirectoryDialog dlg = new CreateDirectoryDialog()) { dlg.Text = CommandStrings.ImportingTitle; dlg.NewDirectoryName = reposUrl.ToString(); dlg.NewDirectoryReadonly = true; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return(false); } logMessage = dlg.LogMessage; } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(projectFiles); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(projectFiles, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnImportArgs importArgs = new SvnImportArgs(); importArgs.LogMessage = logMessage; importArgs.Filter += delegate(object ieSender, SvnImportFilterEventArgs ie) { if (ie.NodeKind != SvnNodeKind.Directory) { ie.Filter = !projectFiles.Contains(ie.FullPath); } else { bool filter = true; foreach (string p in projectFiles) { if (SvnItem.IsBelowRoot(p, ie.FullPath)) { filter = false; break; } } if (filter) { ie.Filter = true; } } }; a.Client.Import(wcDir, reposUrl, importArgs); }); } } shouldMarkAsManaged = dialog.MarkAsManaged; storeReference = dialog.WriteCheckOutInformation; } return(true); }
static bool CheckoutWorkingCopyForSolution(CommandEventArgs e, ref bool confirmed) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) using (AddToSubversion dialog = new AddToSubversion()) { dialog.PathToAdd = e.Selection.SolutionFilename; if (e.Argument is IAnkhSccService) { dialog.CommitAllVisible = false; dialog.CommitAllFiles = false; } else { dialog.CommitAllFiles = true; } if (dialog.ShowDialog(e.Context) != DialogResult.OK) { return(false); // Don't set as managed by AnkhSVN } confirmed = true; if (dialog.CommitAllFiles) { HybridCollection <string> allFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); string logMessage; string wcPath = dialog.WorkingCopyDir; Uri reposUrl = dialog.RepositoryAddUrl; allFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOfAllProjects(true)); using (CreateDirectoryDialog dlg = new CreateDirectoryDialog()) { dlg.Text = CommandStrings.ImportingTitle; dlg.NewDirectoryName = dialog.RepositoryAddUrl.ToString(); dlg.NewDirectoryReadonly = true; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return(false); } logMessage = dlg.LogMessage; } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(allFiles); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(allFiles, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnImportArgs importArgs = new SvnImportArgs(); importArgs.LogMessage = logMessage; importArgs.Filter += delegate(object ieSender, SvnImportFilterEventArgs ie) { if (ie.NodeKind != SvnNodeKind.Directory) { ie.Filter = !allFiles.Contains(ie.FullPath); } else { bool filter = true; foreach (string p in allFiles) { if (SvnItem.IsBelowRoot(p, ie.FullPath)) { filter = false; break; } } if (filter) { ie.Filter = true; } } }; a.Client.Import(wcPath, reposUrl, importArgs); }); } } else { Collection <SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) { return(false); // Create failed; bail out } } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); // Add solutionfile so we can set properties (set managed) AddPathToSubversion(e, e.Selection.SolutionFilename); IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>(); IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); IFileStatusMonitor monitor = e.GetService <IFileStatusMonitor>(); settings.ProjectRoot = SvnTools.GetNormalizedFullPath(dialog.WorkingCopyDir); if (monitor != null && mapper != null) { // Make sure all visible glyphs are updated to reflect a new working copy monitor.ScheduleSvnStatus(mapper.GetAllFilesOfAllProjects()); } } return(true); } }