public void MoveUIElement() { // we want to move // MainUIMap.UIScanJourCaptia104915Window.UIF1Frame1.UICaptiaFrontpgDocument.UIDocuments2Cell // to // MainUIMap.UICaptiaWindow.UICaptiaAppFrameFrame.UIAppFrameDocument.UIF1Frame.UIF1Document.UIDocuments2Cell const string srcElementPath = "MainUIMap.UIScanJourCaptia104915Window.UIF1Frame1.UICaptiaFrontpgDocument.UIDocuments2Cell"; const string destElementPath = "MainUIMap.UICaptiaWindow.UICaptiaAppFrameFrame.UIAppFrameDocument.UIF1Frame.UIF1Document.UIDocuments2Cell"; const string destElementParentPath = "MainUIMap.UICaptiaWindow.UICaptiaAppFrameFrame.UIAppFrameDocument.UIF1Frame.UIF1Document"; UIMapFile uiMap = UIMapFile.Create(@"TestData\MainUIMap.uitest"); Assert.IsFalse(uiMap.IsModified); // verify that element hasn't been moved yet UIObject srcElement = uiMap.FindUIObject(destElementPath); Assert.IsNull(srcElement); // find element and verify that it is in expected place srcElement = uiMap.FindUIObject(srcElementPath); Assert.IsNotNull(srcElement, "Could not find UI Object 'UIDocuments2Cell'"); uiMap.MoveUIObject(srcElementPath, destElementParentPath); Assert.IsTrue(uiMap.IsModified); // save, load and verify structure uiMap.Save("MainUIMap_MovedObject.uitest"); uiMap = UIMapFile.Create("MainUIMap_MovedObject.uitest"); // verify that element now has been moved srcElement = uiMap.FindUIObject(destElementPath); Assert.IsNotNull(srcElement); }
private void SaveUIMapFile() { if (String.IsNullOrWhiteSpace(txtFileName.Text)) { return; } // save backup string uiMapFileName = txtFileName.Text; string backupFileName = String.Empty; try { FileInfo fi = new FileInfo(txtFileName.Text); backupFileName = String.Format(@"{0}\UIMapEditorBackups\{1}_{2:yyyyMMdd_hhmmss}{3}", fi.DirectoryName, fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length), DateTime.Now, fi.Extension); Directory.CreateDirectory(Path.GetDirectoryName(backupFileName)); File.Copy(uiMapFileName, backupFileName); } catch (Exception ex) { DialogResult answer = MessageBox.Show( String.Format("An error occured while trying to save backup: {0}\n\nFile name: {1}\n\nSave file anyway (without backup file)?", ex.Message, backupFileName), Program.ApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (answer != DialogResult.Yes) { return; } } if (this.uiMapFileSystemWatcher != null) { this.uiMapFileSystemWatcher.EnableRaisingEvents = false; } try { _uiMapFile.Save(uiMapFileName); MessageBox.Show("File saved.\n\nRemember to load file in Visual Studio and save it, in order to regenerate C# code.", Program.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show( String.Format("An error occured while trying to save UIMap file: {0}\n\nFile name: {1}\n\nA possible cause might be that the file is not checked out from source control.", ex.Message, uiMapFileName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } finally { if (this.uiMapFileSystemWatcher != null) { this.uiMapFileSystemWatcher.EnableRaisingEvents = true; } } }
public void RenameUIElement() { // we want to rename // NotepadUIMapWithActions.UIUntitledNotepadWindow // to // NotepadUIMapWithActions.UINotepadWindow // and verify that actions are still intact const string originalElementPath = "NotepadUIMapWithActions.UIUntitledNotepadWindow"; const string newName = "UINotepadWindow"; const string newElementPath = "NotepadUIMapWithActions.UINotepadWindow"; UIMapFile uiMap = UIMapFile.Create(@"TestData\NotepadUIMapWithActions.uitest"); // not modified yet Assert.IsFalse(uiMap.IsModified); // verify that element hasn't been renamed yet UIObject srcElement = uiMap.FindUIObject(newElementPath); Assert.IsNull(srcElement); // find element and verify that it is in expected place srcElement = uiMap.FindUIObject(originalElementPath); Assert.IsNotNull(srcElement, String.Format("Could not find source UI Object '{0}'", originalElementPath)); // verify actions before we move element Assert.AreEqual(8, uiMap.ExecuteActions.Count, "Unexpected number of actions in UIMap"); Assert.AreEqual("NotepadUIMapWithActions.UIUntitledNotepadWindow.UIApplicationMenuBar.UIHelpMenuItem.UIAboutNotepadMenuItem", uiMap.ExecuteActions.Actions[0].UIObjectName); uiMap.RenameUIObject(originalElementPath, newName); Assert.IsTrue(uiMap.IsModified); // save, load and verify structure uiMap.Save("NotepadUIMapWithActions_RenamedObject.uitest"); uiMap = UIMapFile.Create("NotepadUIMapWithActions_RenamedObject.uitest"); // verify that element has been renamed srcElement = uiMap.FindUIObject(newElementPath); Assert.IsNotNull(srcElement); // and verify actions Assert.AreEqual(8, uiMap.ExecuteActions.Count, "Unexpected number of actions in UIMap"); Assert.AreEqual("NotepadUIMapWithActions.UINotepadWindow.UIApplicationMenuBar.UIHelpMenuItem.UIAboutNotepadMenuItem", uiMap.ExecuteActions.Actions[0].UIObjectName); Assert.IsFalse(uiMap.IsModified); }
public void VerifyActionIsStillValidAfterMovingUIElement() { // we want to move // NotepadUIMapWithActions.UITesttxtNotepadWindow.UIApplicationMenuBar // to // NotepadUIMapWithActions.UIUntitledNotepadWindow // and verify that actions are still intact const string srcElementPath = "NotepadUIMapWithActions.UITesttxtNotepadWindow.UIApplicationMenuBar"; const string destElementPath = "NotepadUIMapWithActions.UIUntitledNotepadWindow.UIApplicationMenuBar.UIFileMenuItem"; const string destElementParentPath = "NotepadUIMapWithActions.UIUntitledNotepadWindow"; UIMapFile uiMap = UIMapFile.Create(@"TestData\NotepadUIMapWithActions.uitest"); // verify that element hasn't been moved yet UIObject srcElement = uiMap.FindUIObject(destElementPath); Assert.IsNull(srcElement); // find element and verify that it is in expected place srcElement = uiMap.FindUIObject(srcElementPath); Assert.IsNotNull(srcElement, String.Format("Could not find source UI Object '{0}'", srcElementPath)); // verify actions before we move element Assert.AreEqual(8, uiMap.ExecuteActions.Count, "Unexpected number of actions in UIMap"); Assert.AreEqual("NotepadUIMapWithActions.UITesttxtNotepadWindow.UIApplicationMenuBar.UIFileMenuItem.UIPageSetupMenuItem", uiMap.ExecuteActions.Actions[3].UIObjectName); uiMap.MoveUIObject(srcElementPath, destElementParentPath); // save, load and verify structure uiMap.Save("NotepadUIMapWithActions_MovedObject.uitest"); uiMap = UIMapFile.Create("NotepadUIMapWithActions_MovedObject.uitest"); // verify that element now has been moved srcElement = uiMap.FindUIObject(destElementPath); Assert.IsNotNull(srcElement); // and verify actions Assert.AreEqual(8, uiMap.ExecuteActions.Count, "Unexpected number of actions in UIMap"); Assert.AreEqual("NotepadUIMapWithActions.UIUntitledNotepadWindow.UIApplicationMenuBar.UIFileMenuItem.UIPageSetupMenuItem", uiMap.ExecuteActions.Actions[3].UIObjectName); }