コード例 #1
0
        private void RenameSelectedElement()
        {
            if (tvUIMap.SelectedNode == null)
            {
                return;
            }

            try
            {
                string path = tvUIMap.SelectedNode.Tag as string;
                if (String.IsNullOrWhiteSpace(path))
                {
                    MessageBox.Show("No path for selected node in tree.", Program.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                string id = tvUIMap.SelectedNode.Text;
                if (InputBox.Show("Rename UI element", "Enter new id:", ref id) == DialogResult.OK)
                {
                    string newPath = _uiMapFile.RenameUIObject(path, id);

                    RedrawTree(newPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Program.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        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);
        }