Esempio n. 1
0
        private void DeleteModelImpl(DeleteModelCommand command)
        {
            List <ModelBase> modelsToDelete = new List <ModelBase>();

            if (command.ModelGuid != Guid.Empty)
            {
                modelsToDelete.Add(CurrentSpace.GetModelInternal(command.ModelGuid));
            }
            else
            {
                // When nothing is specified then it means all selected models.
                foreach (ISelectable selectable in DynamoSelection.Instance.Selection)
                {
                    if (selectable is ModelBase)
                    {
                        modelsToDelete.Add(selectable as ModelBase);
                    }
                }
            }

            model.DeleteModelInternal(modelsToDelete);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 2
0
        private void Undo()
        {
            _textEditor.Undo();

            RedoCommand.RaiseCanExecuteChanged();
            UndoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 3
0
        private void LeaseBook()
        {
            Action redo = () =>
            {
                SelectedBook.LeasedTo = Session.Current.LoggedInUser;

                LeaseCommand.RaiseCanExecuteChanged();
                OnPropertyChanged("SelectedBook");
                BookList.Refresh();
            };
            Action undo = () =>
            {
                SelectedBook.LeasedTo = string.Empty;

                LeaseCommand.RaiseCanExecuteChanged();
                OnPropertyChanged("SelectedBook");
                BookList.Refresh();
            };

            history.AddAndExecute(new RevertableCommand(redo, undo));
            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();

            ClientLogger.Log($"{Session.Current.LoggedInUser} leased book {selectedBook.BookName}", Common.LogLevel.Info);
        }
Esempio n. 4
0
        private void OnLoadText(TabInfo tabInfo)
        {
            if (tabInfo.Guid != _fileGuid || _textEditor == null)
            {
                return;
            }

            Reset(() =>
            {
                IsReadOnly   = tabInfo.IsReadOnly;
                IsShowEditor = tabInfo.IsShowEditor;

                _fileGuid        = tabInfo.Guid;
                _textEditor.Text = tabInfo.FileContent;
            });

            if (IsSelected)
            {
                CompileCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
                UndoCommand.RaiseCanExecuteChanged();

                _textEditor.Focus();
                CaretPosChanged();

                if (AutoCompile || IsReadOnly)
                {
                    Compile(tabInfo.FileContent);
                }
            }
        }
Esempio n. 5
0
        private void SendModelEventImpl(ModelEventCommand command)
        {
            CurrentSpace.SendModelEvent(command.ModelGuid, command.EventName);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
 /// <summary>
 /// Updates UI bound to the view model properties.
 /// </summary>
 private void UpdateView()
 {
     SyncModelProperties();
     UpdateBoard();
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
     MoveCommand.RaiseCanExecuteChanged();
 }
 private void ExecuteClearFormatCommand(object parameter)
 {
     txt.Text        = Strings.RadialMenuClear;
     _canExecuteUndo = true;
     _canExecuteRedo = false;
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
 }
Esempio n. 8
0
 private void ExecuteUndoCommand(object parameter)
 {
     txt.Text        = "Undo Command executed";
     _canExecuteUndo = false;
     _canExecuteRedo = true;
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
 }
Esempio n. 9
0
        private void UpdateModelValueImpl(UpdateModelValueCommand command)
        {
            CurrentSpace.UpdateModelValue(command.ModelGuid,
                                          command.Name, command.Value);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 10
0
        private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command)
        {
            CurrentSpace.ConvertNodesToCodeInternal(command.NodeId);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
            CurrentSpace.HasUnsavedChanges = true;
        }
Esempio n. 11
0
        private void CreateNoteImpl(CreateNoteCommand command)
        {
            NoteModel noteModel = Model.AddNoteInternal(command, null);

            CurrentSpace.RecordCreatedModel(noteModel);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 12
0
        public void SetComposition(Composition composition)
        {
            var lilypondText = LilypondFactory.GetLilypond(composition);

            LilypondTextLoaded(lilypondText);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
        private void UpdateCommands()
        {
            RemoveImageCommand.RaiseCanExecuteChanged();
            SaveCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
            UndoCommand.RaiseCanExecuteChanged();

            RemoveBackgroundCommand.RaiseCanExecuteChanged();
            RemoveOverlayCommand.RaiseCanExecuteChanged();
        }
Esempio n. 14
0
 public void LilypondTextLoaded(string text)
 {
     _textChangedByLoad = true;
     _caretaker.reset();
     LilypondText = text;
     _caretaker.change();
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
     _textChangedByLoad = false;
 }
Esempio n. 15
0
 private void OnLevelPropertyChanged(Object sender, PropertyChangedEventArgs e)
 {
     if ("CanUndo".Equals(e.PropertyName))
     {
         UndoCommand.RaiseCanExecuteChanged();
     }
     else if ("CanRedo".Equals(e.PropertyName))
     {
         RedoCommand.RaiseCanExecuteChanged();
     }
 }
        private void UndoRedoManagerOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            if (args.IsProperty<UndoRedoManager>(i => i.CanUndo))
            {
                UndoCommand.RaiseCanExecuteChanged();

                SaveDocumentCommand.RaiseCanExecuteChanged();
                SaveDocumentAsCommand.RaiseCanExecuteChanged();
            }

            if (args.IsProperty<UndoRedoManager>(i => i.CanRedo))
                RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 17
0
        private void UndoRedoImpl(UndoRedoCommand command)
        {
            if (command.CmdOperation == UndoRedoCommand.Operation.Undo)
            {
                CurrentSpace.Undo();
            }
            else if (command.CmdOperation == UndoRedoCommand.Operation.Redo)
            {
                CurrentSpace.Redo();
            }

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 18
0
        private void CreateNoteImpl(CreateNoteCommand command)
        {
            NoteModel noteModel = Model.CurrentWorkspace.AddNote(
                command.DefaultPosition,
                command.X,
                command.Y,
                command.NoteText,
                command.NodeId);

            CurrentSpace.RecordCreatedModel(noteModel);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
        //Summary
        //    Commit changes to data source, after commit, clear undo/redo list
        public void Commit()
        {
            _selectedVertices.Clear();
            _operations.Clear();
            _operationsRedo.Clear();

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
            HasChange = false;

            IsInEditing = false;

            PostStatusMessage("Ready");
        }
Esempio n. 20
0
        private void CreateNodeImpl(CreateNodeCommand command)
        {
            NodeModel nodeModel = CurrentSpace.AddNode(
                command.NodeId,
                command.NodeName,
                command.X,
                command.Y,
                command.DefaultPosition,
                command.TransformCoordinates);

            CurrentSpace.RecordCreatedModel(nodeModel);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
Esempio n. 21
0
        private void OnIsActiveChanged()
        {
            SaveCommand.RaiseCanExecuteChanged();

            CompileCommand.IsActive = IsActive;
            CompileCommand.RaiseCanExecuteChanged();

            RedoCommand.IsActive = IsActive;
            RedoCommand.RaiseCanExecuteChanged();

            UndoCommand.IsActive = IsActive;
            UndoCommand.RaiseCanExecuteChanged();

            IsActiveChanged?.Invoke(this, new EventArgs());
        }
Esempio n. 22
0
        private void RedoUndoModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "CanRedoOneStep":
                RedoCommand.RaiseCanExecuteChanged();
                break;

            case "CanUndoOneStep":
                UndoCommand.RaiseCanExecuteChanged();
                break;

            default:
                break;
            }
        }
Esempio n. 23
0
        public LilypondViewModel(MainViewModel mainViewModel, MusicLoader musicLoader)
        {
            // TODO: Can we use some sort of eventing system so the managers layer doesn't have to know the viewmodel layer and viewmodels don't know each other?
            // And viewmodels don't
            _mainViewModel = mainViewModel;
            _musicLoader   = musicLoader;
            _musicLoader.LilypondViewModel = this;

            _text           = new LilypondText();
            _caretaker      = new LilypondTextCaretaker(_text);
            _movedInHistory = false;

            LilypondText = "Your lilypond text will appear here.";
            _caretaker.change();
            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();
        }
        //Summary
        //    Execute new operaton and put the operation in to undoable list
        public void Do(IOperation operation)
        {
            operation.Do();
            HasChange = true;
            _operations.Insert(0, operation);

            foreach (var v in _operationsRedo)
            {
                v.Dispose();
            }

            _operationsRedo.Clear();

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();

            if (!string.IsNullOrEmpty(operation.Sammary))
            {
                PostStatusMessage(operation.Sammary);
            }
        }
        void ExecuteUndo()
        {
            var op = Operations.FirstOrDefault();

            if (op == null || !op.IsUnDoable)
            {
                return;
            }

            op.UnDo();

            Operations.Remove(op);
            OperationsRedo.Insert(0, op);

            UndoCommand.RaiseCanExecuteChanged();
            RedoCommand.RaiseCanExecuteChanged();

            if (!string.IsNullOrEmpty(op.Sammary))
            {
                PostStatusMessage("Undo " + op.Sammary);
            }
        }
Esempio n. 26
0
 private void TextChanged()
 {
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
 }
Esempio n. 27
0
 private void Current_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
 }
Esempio n. 28
0
 private void UpdateCommandStatus()
 {
     UndoCommand.RaiseCanExecuteChanged();
     RedoCommand.RaiseCanExecuteChanged();
 }
Esempio n. 29
0
        void OnModelCommandCompleted(DynamoModel.RecordableCommand command)
        {
            var name = command.GetType().Name;

            switch (name)
            {
            case "OpenFileCommand":
                this.AddToRecentFiles((command as DynamoModel.OpenFileCommand).XmlFilePath);
                this.VisualizationManager.UnPause();
                break;

            case "MutateTestCommand":
                var mutatorDriver = new Dynamo.TestInfrastructure.MutatorDriver(this);
                mutatorDriver.RunMutationTests();
                break;

            case "SelectInRegionCommand":
                var selectC = command as DynamoModel.SelectInRegionCommand;
                CurrentSpaceViewModel.SelectInRegion(selectC.Region, selectC.IsCrossSelection);
                break;

            case "DragSelectionCommand":
                var dragC = command as DynamoModel.DragSelectionCommand;

                if (DynamoModel.DragSelectionCommand.Operation.BeginDrag == dragC.DragOperation)
                {
                    CurrentSpaceViewModel.BeginDragSelection(dragC.MouseCursor);
                }
                else
                {
                    CurrentSpaceViewModel.EndDragSelection(dragC.MouseCursor);
                }
                break;

            case "DeleteModelCommand":
            case "CreateNodeCommand":
            case "CreateNoteCommand":
            case "UndoRedoCommand":
            case "ModelEventCommand":
            case "UpdateModelValueCommand":
            case "ConvertNodesToCodeCommand":
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
                break;

            case "SwitchTabCommand":
                if (command.IsInPlaybackMode)
                {
                    RaisePropertyChanged("CurrentWorkspaceIndex");
                }
                break;

            case "RunCancelCommand":
            case "ForceRunCancelCommand":
            case "SelectModelCommand":
            case "MakeConnectionCommand":
            case "CreateCustomNodeCommand":
                // for this commands there is no need
                // to do anything after execution
                break;

            default:
                throw new InvalidOperationException("Unhandled command name");
            }
        }
Esempio n. 30
0
        public MainViewModel(IDialogCoordinator _dialogCoordinator)
        {
            DialogCoordinator = _dialogCoordinator;

            MenuBar = new MenuBarViewModel(this);
            ToolBar = new ToolBarViewModel(this);

            try {
                NativeMethods.EnablePrivilege("SeBackupPrivilege");
                NativeMethods.EnablePrivilege("SeRestorePrivilege");
                IsAdmin = true;
            }
            catch {
            }

            ActiveView = this;

            var computer = new RegistryKeyItemSpecial(null)
            {
                Text       = "Computer",
                Icon       = "/images/workstation2.png",
                IsExpanded = true
            };

            computer.SubItems.Add(new RegistryKeyItem(computer, Registry.ClassesRoot));
            computer.SubItems.Add(new RegistryKeyItem(computer, Registry.CurrentUser));
            computer.SubItems.Add(new RegistryKeyItem(computer, Registry.LocalMachine));
            computer.SubItems.Add(new RegistryKeyItem(computer, Registry.CurrentConfig));
            computer.SubItems.Add(new RegistryKeyItem(computer, Registry.Users));

            _roots = new List <RegistryKeyItemBase> {
                computer,
                //new RegistryKeyItemSpecial(null) {
                //	Text = "Files",
                //	Icon = "/images/folder_blue.png"
                //},
                new RegistryKeyItemSpecial(null)
                {
                    Text       = "Favorites",
                    Icon       = "/images/favorites.png",
                    IsExpanded = true
                }
            };

            LoadFavorites();

            ExitCommand = new DelegateCommand(() => Application.Current.Shutdown());

            LaunchWithAdminRightsCommand = new DelegateCommand(() => {
                var pi = new ProcessStartInfo(Process.GetCurrentProcess().MainModule.FileName)
                {
                    Verb = "RunAs"
                };
                try {
                    if (Process.Start(pi) != null)
                    {
                        Environment.Exit(0);
                    }
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, App.Name);
                }
            }, () => !IsAdmin);

            EditNewKeyCommand = new DelegateCommand <RegistryKeyItem>(item => {
                var name = item.GenerateUniqueSubKeyName();
                CommandManager.AddCommand(Commands.CreateKey(new CreateKeyCommandContext {
                    Key  = item,
                    Name = name
                }));
                item.IsExpanded    = true;
                var newItem        = item.GetSubItem <RegistryKeyItem>(name);
                newItem.IsSelected = true;
                Dispatcher.CurrentDispatcher.InvokeAsync(() => IsEditMode = true, DispatcherPriority.Background);
            }, item => !IsReadOnlyMode && item is RegistryKeyItem)
                                .ObservesProperty(() => IsReadOnlyMode);

            EditPermissionsCommand = new DelegateCommand(() => {
                // TODO
            }, () => SelectedItem is RegistryKeyItem)
                                     .ObservesProperty(() => SelectedItem);

            CopyKeyNameCommand = new DelegateCommand <RegistryKeyItemBase>(_ => Clipboard.SetText(SelectedItem.Text),
                                                                           _ => SelectedItem != null).ObservesProperty(() => SelectedItem);

            CopyKeyPathCommand = new DelegateCommand(() => Clipboard.SetText(((RegistryKeyItem)SelectedItem).Path ?? SelectedItem.Text),
                                                     () => SelectedItem is RegistryKeyItem)
                                 .ObservesProperty(() => SelectedItem);

            RefreshCommand = new DelegateCommand(() => SelectedItem.Refresh(), () => SelectedItem != null)
                             .ObservesProperty(() => SelectedItem);

            EndEditingCommand = new DelegateCommand <string>(async name => {
                try {
                    var item = SelectedItem as RegistryKeyItem;
                    Debug.Assert(item != null);
                    if (name == null || name.Equals(item.Text, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return;
                    }

                    if (item.Parent.SubItems.Any(i => name.Equals(i.Text, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        await DialogCoordinator.ShowMessageAsync(this, App.Name, string.Format("Key name '{0}' already exists", name));
                        return;
                    }
                    CommandManager.AddCommand(Commands.RenameKey(new RenameKeyCommandContext {
                        Key     = item,
                        OldName = item.Text,
                        NewName = name
                    }));
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, App.Name);
                }
                finally {
                    IsEditMode = false;
                    CommandManager.UpdateChanges();
                    UndoCommand.RaiseCanExecuteChanged();
                    RedoCommand.RaiseCanExecuteChanged();
                }
            }, _ => IsEditMode).ObservesCanExecute(() => IsEditMode);

            BeginRenameCommand = new DelegateCommand(() => IsEditMode = true,
                                                     () => !IsReadOnlyMode && SelectedItem is RegistryKeyItem && !string.IsNullOrEmpty(((RegistryKeyItem)SelectedItem).Path))
                                 .ObservesProperty(() => SelectedItem).ObservesProperty(() => IsReadOnlyMode);

            UndoCommand = new DelegateCommand(() => {
                CommandManager.Undo();
                RedoCommand.RaiseCanExecuteChanged();
                UndoCommand.RaiseCanExecuteChanged();
            }, () => !IsReadOnlyMode && CommandManager.CanUndo).ObservesProperty(() => IsReadOnlyMode);

            RedoCommand = new DelegateCommand(() => {
                CommandManager.Redo();
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            }, () => !IsReadOnlyMode && CommandManager.CanRedo).ObservesProperty(() => IsReadOnlyMode);

            LoadHiveCommand = new DelegateCommand(async() => {
                var vm = DialogHelper.ShowDialog <LoadHiveViewModel, LoadHiveView>();
                if (vm.ShowDialog() == true)
                {
                    int error = NativeMethods.RegLoadKey(vm.Hive == "HKLM" ? Registry.LocalMachine.Handle : Registry.Users.Handle, vm.Name, vm.FileName);
                    if (error != 0)
                    {
                        await DialogCoordinator.ShowMessageAsync(this, App.Name, string.Format("Error opening file: {0}", error.ToString()));
                        return;
                    }

                    var item = _roots[0].SubItems[vm.Hive == "HKLM" ? 2 : 4];
                    item.Refresh();
                    ((RegistryKeyItem)item.SubItems.First(i => i.Text == vm.Name)).HiveKey = true;
                }
            }, () => IsAdmin && !IsReadOnlyMode)
                              .ObservesProperty(() => IsReadOnlyMode);

            DeleteCommand = new DelegateCommand(() => {
                var item = SelectedItem as RegistryKeyItem;
                Debug.Assert(item != null);

                if (!IsAdmin)
                {
                    if (MessageBox.Show("Running with standard user rights prevents undo for deletion. Delete anyway?",
                                        App.Name, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                    CommandManager.Clear();
                }
                var tempFile = Path.GetTempFileName();
                CommandManager.AddCommand(Commands.DeleteKey(new DeleteKeyCommandContext {
                    Key      = item,
                    TempFile = tempFile
                }));
                CommandManager.UpdateChanges();
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            }, () => !IsReadOnlyMode && SelectedItem is RegistryKeyItem && SelectedItem.Path != null).ObservesProperty(() => IsReadOnlyMode);

            ExportCommand = new DelegateCommand(() => {
                var dlg = new SaveFileDialog {
                    Title           = "Select output file",
                    Filter          = "Registry data files|*.dat",
                    OverwritePrompt = true
                };
                if (dlg.ShowDialog() == true)
                {
                    var item = SelectedItem as RegistryKeyItem;
                    Debug.Assert(item != null);
                    using (var key = item.Root.OpenSubKey(item.Path)) {
                        File.Delete(dlg.FileName);
                        int error = NativeMethods.RegSaveKeyEx(key.Handle, dlg.FileName, IntPtr.Zero, 2);
                        Debug.Assert(error == 0);
                    }
                }
            }, () => IsAdmin && SelectedItem is RegistryKeyItem)
                            .ObservesProperty(() => SelectedItem);

            CreateNewValueCommand = new DelegateCommand <ValueViewModel>(vm => {
            }, vm => !IsReadOnlyMode)
                                    .ObservesProperty(() => IsReadOnlyMode);

            AddToFavoritesCommand = new DelegateCommand(() => {
                var item = SelectedItem as RegistryKeyItem;
                Debug.Assert(item != null);

                _roots[1].SubItems.Add(new RegistryKeyItem(item.Parent as RegistryKeyItem, item.Text));
                SaveFavorites();
            }, () => SelectedItem is RegistryKeyItem && !string.IsNullOrEmpty(SelectedItem.Path))
                                    .ObservesProperty(() => SelectedItem);

            RemoveFromFavoritesCommand = new DelegateCommand(() => {
                _roots[1].SubItems.Remove(SelectedItem);
                SaveFavorites();
            }, () => SelectedItem != null && SelectedItem.Flags.HasFlag(RegistryKeyFlags.Favorite))
                                         .ObservesProperty(() => SelectedItem);
        }