Exemple #1
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcElNode = (ResourceElementTreeNode)nodes[0];
            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var options = new ResourceElementOptions(rsrcElNode.ResourceElement);
            var data = new ResourceElementVM(options, module, OtherSettings.Instance.DeserializeResources);
            data.CanChangeType = false;
            var win = new ResourceElementDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var opts = data.CreateResourceElementOptions();
            string error;
            try {
                error = rsrcElNode.CheckCanUpdateData(opts.Create());
            }
            catch (Exception ex) {
                error = string.Format("Can't use this data: {0}", ex.Message);
            }
            if (!string.IsNullOrEmpty(error)) {
                MainWindow.Instance.ShowMessageBox(error);
                return;
            }

            UndoCommandManager.Instance.Add(new ResourceElementSettingsCommand(rsrcElNode, opts));
        }
Exemple #2
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IFileTreeViewSettings fileTreeViewSettings, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var rsrcElNode = (IResourceElementNode)nodes[0];
			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var options = new ResourceElementOptions(rsrcElNode.ResourceElement);
			var data = new ResourceElementVM(options, module, fileTreeViewSettings.DeserializeResources);
			data.CanChangeType = false;
			var win = new ResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.EditResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			string error;
			try {
				error = rsrcElNode.CheckCanUpdateData(opts.Create());
			}
			catch (Exception ex) {
				error = string.Format(dnSpy_AsmEditor_Resources.Error_InvalidResourceData, ex.Message);
			}
			if (!string.IsNullOrEmpty(error)) {
				Shared.App.MsgBox.Instance.Show(error);
				return;
			}

			undoCommandManager.Value.Add(new ResourceElementSettingsCommand(rsrcElNode, opts));
		}
Exemple #3
0
        static void Execute(ILSpyTreeNode[] nodes)
        {
            if (!CanExecute(nodes))
                return;

            var rsrcSetNode = nodes[0] as ResourceElementSetTreeNode;
            if (rsrcSetNode == null)
                rsrcSetNode = nodes[0].Parent as ResourceElementSetTreeNode;
            Debug.Assert(rsrcSetNode != null);

            var module = ILSpyTreeNode.GetModule(nodes[0]);
            Debug.Assert(module != null);
            if (module == null)
                throw new InvalidOperationException();

            var options = new ResourceElementOptions(new ResourceElement {
                Name = string.Empty,
                ResourceData = new BuiltInResourceData(ResourceTypeCode.String, string.Empty),
            });
            var data = new ResourceElementVM(options, module, OtherSettings.Instance.DeserializeResources);
            var win = new ResourceElementDlg();
            win.Title = CMD_NAME;
            win.DataContext = data;
            win.Owner = MainWindow.Instance;
            if (win.ShowDialog() != true)
                return;

            var opts = data.CreateResourceElementOptions();
            var node = ResourceFactory.Create(module, opts.Create());
            UndoCommandManager.Instance.Add(new CreateResourceElementCommand(rsrcSetNode, node));
        }
Exemple #4
0
		static void Execute(Lazy<IUndoCommandManager> undoCommandManager, IAppWindow appWindow, IResourceNodeFactory resourceNodeFactory, IFileTreeViewSettings fileTreeViewSettings, IFileTreeNodeData[] nodes) {
			if (!CanExecute(nodes))
				return;

			var rsrcSetNode = nodes[0] as IResourceElementSetNode;
			if (rsrcSetNode == null)
				rsrcSetNode = nodes[0].TreeNode.Parent.Data as IResourceElementSetNode;
			Debug.Assert(rsrcSetNode != null);

			var module = nodes[0].GetModule();
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();

			var options = new ResourceElementOptions(new ResourceElement {
				Name = string.Empty,
				ResourceData = new BuiltInResourceData(ResourceTypeCode.String, string.Empty),
			});
			var data = new ResourceElementVM(options, module, fileTreeViewSettings.DeserializeResources);
			var win = new ResourceElementDlg();
			win.Title = dnSpy_AsmEditor_Resources.CreateResourceCommand2;
			win.DataContext = data;
			win.Owner = appWindow.MainWindow;
			if (win.ShowDialog() != true)
				return;

			var opts = data.CreateResourceElementOptions();
			var treeView = appWindow.FileTreeView.TreeView;
			var treeNodeGroup = appWindow.FileTreeView.FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.ResourceElementTreeNodeGroup);
			var node = (IResourceElementNode)treeView.Create(resourceNodeFactory.Create(module, opts.Create(), treeNodeGroup)).Data;
			undoCommandManager.Value.Add(new CreateResourceElementCommand(rsrcSetNode, node));
			appWindow.FileTabManager.FollowReference(node);
		}