public MainWindowViewModel()
        {
            // Initializing the lists.
            ApiList     = new ObservableCollection <ApiNames>(Enum.GetValues(typeof(ApiNames)).Cast <ApiNames>().ToList());
            SelectedApi = ApiNames.BlockchainInfo;

            WalletTypeList = new ObservableCollection <Transaction.WalletType>(Enum.GetValues(typeof(Transaction.WalletType)).Cast <Transaction.WalletType>().ToList());

            SendAddressList = new BindingList <SendingAddress>();
            UtxoList        = new BindingList <UTXO>();
            ReceiveList     = new BindingList <ReceivingAddress>();

            // Initializing Commands.
            GetUTXOCommand        = AsyncCommand.Create(() => GetUTXO());
            MakeTxCommand         = new BindableCommand(MakeTx, CanMakeTx);
            CopyTxCommand         = new RelayCommand(CopyTx, () => !string.IsNullOrEmpty(RawTx));
            ShowQrWindowCommand   = new RelayCommand(ShowQrWindow, () => !string.IsNullOrEmpty(RawTx));
            ShowJsonWindowCommand = new RelayCommand(ShowJsonWindow, () => !string.IsNullOrEmpty(RawTx));
            ShowEditWindowCommand = new RelayCommand(ShowEditWindow);

            // These moved below to avoid throwing null exception.
            ReceiveList.ListChanged += ReceiveList_ListChanged;
            SelectedUTXOs            = new ObservableCollection <UTXO>();
            SelectionChangedCommand  = new BindableCommand(SelectionChanged);
            SelectedWalletType       = Transaction.WalletType.Normal;
        }
Пример #2
0
 public ItemsViewModel()
 {
     Title             = "Products";
     Items             = new ObservableCollection <IComponent>();
     LoadItemsCommand  = new BindableCommand(async() => await ExecuteLoadItemsCommand());
     SelectItemCommand = new BindableCommand <IComponent>(SelectItem);
 }
 public void GenericBindableCommand_Throws_Error_When_Action_Is_Null()
 {
     Assert.Throws <ArgumentNullException>(
         () => {
         var command = new BindableCommand <string>(null);
     });
 }
Пример #4
0
        public MainWindowViewModel()
        {
            // Initializing the lists.
            ApiList = new ObservableCollection <TxApiNames>(Enum.GetValues(typeof(TxApiNames)).Cast <TxApiNames>().ToList());

            WalletTypeList  = new ObservableCollection <WalletType>(Enum.GetValues(typeof(WalletType)).Cast <WalletType>().ToList());
            txVersion       = 1;
            SendAddressList = new BindingList <SendingAddress>();
            UtxoList        = new BindingList <UTXO>();
            ReceiveList     = new BindingList <ReceivingAddress>();

            // Initializing Commands.
            GetUTXOCommand              = new RelayCommand(GetUTXO, () => !IsReceiving);
            MakeTxCommand               = new BindableCommand(MakeTx, CanMakeTx);
            CopyTxCommand               = new RelayCommand(CopyTx, () => !string.IsNullOrEmpty(RawTx));
            ShowQrWindowCommand         = new RelayCommand(ShowQrWindow, () => !string.IsNullOrEmpty(RawTx));
            ShowJsonWindowCommand       = new RelayCommand(ShowJsonWindow, () => !string.IsNullOrEmpty(RawTx));
            ChangeAddressCheckedCommand = new BindableCommand(ChangeAddressChecked, () => IsChangeAddrEnabled);
            ShowEditWindowCommand       = new RelayCommand(ShowEditWindow);

            // These moved below to avoid throwing null exception.
            ReceiveList.ListChanged += ReceiveList_ListChanged;
            SelectedUTXOs            = new ObservableCollection <UTXO>();
            SelectionChangedCommand  = new BindableCommand(SelectionChanged);
            SelectedWalletType       = WalletType.Normal;
        }
Пример #5
0
        public MainWindowViewModel()
        {
            AddressList              = new BindingList <GroestlcoinAddress>(DataManager.ReadFile <List <GroestlcoinAddress> >(DataManager.FileType.Wallet));
            AddressList.ListChanged += AddressList_ListChanged;

            SettingsInstance = DataManager.ReadFile <SettingsModel>(DataManager.FileType.Settings);

            if (string.IsNullOrEmpty(SettingsInstance.LocalCurrencySymbol))
            {
                SettingsInstance.LocalCurrencySymbol = SettingsInstance.SelectedCurrency.ToString();
            }

            GetBalanceCommand = new BindableCommand(GetBalance, () => !IsReceiving);
            SettingsCommand   = new BindableCommand(OpenSettings);

            ImportFromTextCommand = new BindableCommand(ImportFromText);
            ImportFromFileCommand = new BindableCommand(ImportFromFile);

            refreshTimer          = new DispatcherTimer();
            refreshTimer.Interval = new TimeSpan(0, 0, 5);
            refreshTimer.Tick    += RefreshBalances;
            refreshTimer.Start();

            var ver = Assembly.GetExecutingAssembly().GetName().Version;

            VersionString = $"Version {ver.Major}.{ver.Minor}.{ver.Build}";

            try{
                UpdatePrices();
            }
            catch {
                Status = "Error Updating Prices...";
            }
        }
Пример #6
0
        public SettingsViewModel()
        {
            BalanceApiList = new ObservableCollection <BalanceServiceNames>((BalanceServiceNames[])Enum.GetValues(typeof(BalanceServiceNames)));
            PriceApiList   = new ObservableCollection <PriceServiceNames>((PriceServiceNames[])Enum.GetValues(typeof(PriceServiceNames)));

            UpdatePriceCommand = new BindableCommand(UpdatePrice, () => !IsReceiving);
        }
Пример #7
0
        public bool Execute(BindableCommand command)
        {
            if ((int)command < 10000)
            {
                NativeScintilla.SendMessageDirect((uint)command, IntPtr.Zero, IntPtr.Zero);
                return(true);
            }

            switch (command)
            {
            case BindableCommand.DropMarkerCollect:
                Scintilla.DropMarkers.Collect();
                return(false);

            case BindableCommand.DropMarkerDrop:
                Scintilla.DropMarkers.Drop();
                return(true);

            case BindableCommand.Print:
                Scintilla.Printing.Print();
                return(true);

            case BindableCommand.PrintPreview:
                Scintilla.Printing.PrintPreview();
                return(true);

            case BindableCommand.LineComment:
                Scintilla.Lexing.LineComment();
                return(true);

            case BindableCommand.LineUncomment:
                Scintilla.Lexing.LineUncomment();
                return(true);

            case BindableCommand.DocumentNavigateForward:
                Scintilla.DocumentNavigation.NavigateForward();
                return(true);

            case BindableCommand.DocumentNavigateBackward:
                Scintilla.DocumentNavigation.NavigateBackward();
                return(true);

            case BindableCommand.ToggleLineComment:
                Scintilla.Lexing.ToggleLineComment();
                return(true);

            case BindableCommand.StreamComment:
                Scintilla.Lexing.StreamComment();
                return(true);

            case BindableCommand.ShowGoTo:
                Scintilla.GoTo.ShowGoToDialog();
                break;
            }

            return(false);
        }
Пример #8
0
        public SettingsViewModel()
        {
            BalanceApiList        = new ObservableCollection <BalanceServiceNames>((BalanceServiceNames[])Enum.GetValues(typeof(BalanceServiceNames)));
            PriceApiList          = new ObservableCollection <PriceServiceNames>((PriceServiceNames[])Enum.GetValues(typeof(PriceServiceNames)));
            SupportedCurrencyList = new ObservableCollection <SupportedCurrencies>((SupportedCurrencies[])Enum.GetValues(typeof(SupportedCurrencies)));

            UpdatePriceCommand = new BindableCommand(UpdatePrice, () => !IsReceiving);

            RaisePropertyChanged("ConversionRateLabelText");
        }
Пример #9
0
        public void BindableCommand_Throws_Error_When_Action_Is_Not_Null_And_Predicate_Is_Null()
        {
            var action = new Mock <Action>();

            Assert.Throws <ArgumentNullException>(
                () => {
                var command = new BindableCommand(action.Object, null);
            }
                );
        }
Пример #10
0
 /* ----------------------------------------------------------------- */
 ///
 /// InsertViewModel
 ///
 /// <summary>
 /// Initializes a new instance of the InsertViewModel with the
 /// specified argumetns.
 /// </summary>
 ///
 /// <param name="callback">Callback function.</param>
 /// <param name="i">Selected index.</param>
 /// <param name="n">Number of pages.</param>
 /// <param name="io">I/O handler.</param>
 /// <param name="context">Synchronization context.</param>
 ///
 /* ----------------------------------------------------------------- */
 public InsertViewModel(Action <int, IEnumerable <FileItem> > callback,
                        int i, int n, IO io, SynchronizationContext context) :
     base(() => Properties.Resources.TitleInsert, new Messenger(), context)
 {
     Model    = new InsertFacade(i, n, io, context);
     Position = new InsertPosition(Data);
     DragMove = new InsertDropTarget((f, t) => Model.Move(f, t));
     DragAdd  = new BindableCommand <string[]>(e => Model.Add(e), e => true);
     SetCommands(callback);
 }
        public void GenericBindableCommand_Throws_Error_When_Action_Is_Not_Null_And_Predicate_Is_Null()
        {
            var action = new Mock <Action <string> >();

            action.Setup(x => x(It.IsAny <string>()));

            Assert.Throws <ArgumentNullException>(
                () => {
                var command = new BindableCommand <string>(action.Object, null);
            });
        }
        public MainWindowViewModel()
        {
            NetworkList = new ObservableCollection <Networks>((Networks[])Enum.GetValues(typeof(Networks)));
            SetApiList();

            BroadcastTxCommand = new BindableCommand(BroadcastTx, CanBroadcast);

            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            versionString = $"Version {ver.Major}.{ver.Minor}.{ver.Build}";
        }
Пример #13
0
        public ButtonModel(OP op, bool enabled, Action <object> methodToRun)
        {
            Name   = $"OP__{op.ToString()}";
            OpCode = op;

            DescriptionAttribute[] desc = GetDescriptions(op);
            Description = (desc == null || desc.Length == 0) ? Name : desc[0].Description;

            RunCommand = new BindableCommand(methodToRun);
            Enabled    = enabled;
        }
Пример #14
0
        /// <summary>
        /// Removes a keyboard shortcut / command combination
        /// </summary>
        /// <param name="shortcut">Key to trigger command</param>
        /// <param name="modifiers">Shift, alt, ctrl</param>
        /// <param name="command">Command to execute</param>
        public void RemoveBinding(Keys shortcut, Keys modifiers, BindableCommand command)
        {
            KeyBinding kb = new KeyBinding(shortcut, modifiers);

            if (!_boundCommands.ContainsKey(kb))
            {
                return;
            }

            _boundCommands[kb].Remove(command);
        }
Пример #15
0
        public MainViewModel()
        {
            SwitchTo2DCommand  = new BindableCommand(SwitchTo2D);
            SwitchTo3DCommand  = new BindableCommand(SwitchTo3D);
            SwitchToMPRCommand = new BindableCommand(SwitchToMPR);

            VolumeViewer  = new VolumeViewerViewModel();
            ImageViewer   = new ImageViewerViewModel();
            MPRViewer     = new MPRViewerViewModel();
            CurrentViewer = new StartViewModel();
        }
        public void GenericBindableCommand_Action_Is_Executed_Only_Once()
        {
            var action = new Mock <Action <string> >();

            action.Setup(x => x(It.IsAny <string>()));

            var command = new BindableCommand <string>(action.Object);

            command.Execute("");

            action.Verify(a => a(""), Times.AtMostOnce());
        }
Пример #17
0
        public void BindableCommand_Action_Is_Executed_Only_Once()
        {
            var action = new Mock <Action>();

            action.Setup(x => x());

            var command = new BindableCommand(action.Object);

            command.Execute();

            action.Verify(a => a(), Times.AtMostOnce());
        }
 public AlarmControlPanelViewModel(AlarmControlPanel entity)
     : base(entity)
 {
     Title          = "Alarm Control Panel";
     ArmAwayCommand = new BindableCommand(OnArmAway)
     {
         Text = "ARM AWAY"
     };
     ArmHomeCommand = new BindableCommand(OnArmHome)
     {
         Text = "ARM HOME"
     };
 }
Пример #19
0
        public MainWindowViewModel(NetworkType network)
        {
            Network           = network;
            WinMan            = new WindowManager();
            DisconnectCommand = new BindableCommand(Disconnect, CanDisconnect);

            FileMan = new FileManager(network);
            Configuration config = FileMan.ReadConfig();

            if (config is not null && !config.IsDefault)
            {
                IsInitialized = true;
                Init(config);
            }
Пример #20
0
        public MainWindowViewModel()
        {
            AddressList              = new BindingList <BitcoinAddress>(DataManager.ReadFile <List <BitcoinAddress> >(DataManager.FileType.Wallet));
            AddressList.ListChanged += AddressList_ListChanged;

            SettingsInstance = DataManager.ReadFile <SettingsModel>(DataManager.FileType.Settings);

            GetBalanceCommand = new BindableCommand(GetBalance, () => !IsReceiving);
            SettingsCommand   = new BindableCommand(() => OpenSettings());

            var ver = Assembly.GetExecutingAssembly().GetName().Version;

            VersionString = string.Format("Version {0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
        }
Пример #21
0
        /// <summary>
        /// Returns a list of KeyBindings bound to a given command
        /// </summary>
        /// <param name="command">Command to execute</param>
        /// <returns>List of KeyBindings bound to the given command</returns>
        public List <KeyBinding> GetKeyBindings(BindableCommand command)
        {
            List <KeyBinding> ret = new List <KeyBinding>();

            foreach (KeyValuePair <KeyBinding, List <BindableCommand> > item in _boundCommands)
            {
                if (item.Value.Contains(command))
                {
                    ret.Add(item.Key);
                }
            }

            return(ret);
        }
Пример #22
0
        public ImageViewerViewModel()
        {
            var root = new Space();

            Camera               = new Camera(root);
            Tools                = new ToolSelectorViewModel(this);
            InteractorRight      = new PanCameraInteractor();
            TogglePlayCommand    = new BindableCommand(TogglePlay);
            NextImageCommand     = new BindableCommand(NextImage);
            PreviousImageCommand = new BindableCommand(PreviousImage);

            _playTimer          = new DispatcherTimer(DispatcherPriority.Normal);
            _playTimer.Interval = TimeSpan.FromMilliseconds(1000 / 25);
            _playTimer.Tick    += OnTimerTick;
        }
Пример #23
0
        public MainWindowViewModel()
        {
            NetworkList = new ObservableCollection <Networks>((Networks[])Enum.GetValues(typeof(Networks)));
            _selNet     = NetworkList[0];
            SetApiList();
            _selApi = ApiList[0];

            BroadcastTxCommand = new BindableCommand(BroadcastTx, CanBroadcast);

            Version ver = Assembly.GetExecutingAssembly().GetName().Version ?? new Version(0, 0, 0);

            VersionString = ver.ToString(3);

            _rawTx = string.Empty;
        }
Пример #24
0
        private static ICommand GetCommand(ref ICommand command, Action <object> action, bool isCanExecute = true)
        {
            if (command != null)
            {
                return(command);
            }

            var cmd = new BindableCommand {
                IsCanExecute = isCanExecute
            };

            cmd.ExecuteAction += action;
            command            = cmd;

            return(command);
        }
Пример #25
0
        /// <summary>
        /// Adds a key combination to a Command
        /// </summary>
        /// <param name="shortcut">Key to trigger command</param>
        /// <param name="modifiers">Shift, alt, ctrl</param>
        /// <param name="command">Command to execute</param>
        public void AddBinding(Keys shortcut, Keys modifiers, BindableCommand command)
        {
            KeyBinding kb = new KeyBinding(shortcut, modifiers);

            if (!_boundCommands.ContainsKey(kb))
            {
                _boundCommands.Add(kb, new List <BindableCommand>());
            }

            List <BindableCommand> l = _boundCommands[kb];

            if (_allowDuplicateBindings || !l.Contains(command))
            {
                l.Add(command);
            }
        }
Пример #26
0
        public MainWindowViewModel()
        {
            ApiList = new ObservableCollection <Api>
            {
                new Blockr(),
                new Smartbit(),
                new BlockCypher(),
                new BlockExplorer(),
                new BlockchainInfo()
            };

            BroadcastTxCommand = new BindableCommand(BroadcastTx, CanBroadcast);

            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            versionString = string.Format("Version {0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
        }
        public void GenericBindableCommand_CanExecuteAction_Is_Executed_Only_Once()
        {
            var action = new Mock <Action <string> >();

            action.Setup(x => x(It.IsAny <string>()));

            var canExecuteAction = new Mock <Func <string, bool> >();

            canExecuteAction.Setup(x => x(It.IsAny <string>())).Returns(false);

            var command  = new BindableCommand <string>(action.Object, canExecuteAction.Object);
            var actual   = command.CanExecute("");
            var expected = false;

            using (new AssertionScope()) {
                canExecuteAction.Verify(a => a(""), Times.AtMostOnce());
                Assert.Equal(expected, actual);
            }
        }
Пример #28
0
 /// <summary>
 ///     Initializes a new instance of the CommandBindingConfig structure.
 /// </summary>
 public CommandBindingConfig(KeyBinding keyBinding, bool? replaceCurrent, BindableCommand bindableCommand)
 {
     KeyBinding = keyBinding;
     ReplaceCurrent = replaceCurrent;
     BindableCommand = bindableCommand;
 }
Пример #29
0
		private void readCommands(XmlReader reader)
		{
			if (reader.HasAttributes)
			{
				while (reader.MoveToNextAttribute())
				{
					string attrName = reader.Name.ToLower();
					switch (attrName)
					{
						case "Inherit":
							_commands_KeyBindingList.Inherit = getBool(reader.Value);
							break;
						case "AllowDuplicateBindings":
							_commands_KeyBindingList.AllowDuplicateBindings = getBool(reader.Value);
							break;
					}
				}

				reader.MoveToElement();
			}

			if (!reader.IsEmptyElement)
			{
				while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals("commands", StringComparison.OrdinalIgnoreCase)))
				{
					reader.Read();
					if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("binding", StringComparison.OrdinalIgnoreCase))
					{
						if (reader.HasAttributes)
						{
							KeyBinding kb = new KeyBinding();
							BindableCommand cmd = new BindableCommand();
							bool? replaceCurrent = null;

							while (reader.MoveToNextAttribute())
							{
								string attrName = reader.Name.ToLower();
								switch (attrName)
								{
									case "key":
										kb.KeyCode = Utilities.GetKeys(reader.Value);
										break;
									case "modifier":
										if (reader.Value != string.Empty)
										{
											foreach (string modifier in reader.Value.Split(' '))
												kb.Modifiers |= (Keys)Enum.Parse(typeof(Keys), modifier.Trim(), true);
										}
										break;
									case "command":
										cmd = (BindableCommand)Enum.Parse(typeof(BindableCommand), reader.Value, true);
										break;
									case "replacecurrent":
										replaceCurrent = getBool(reader.Value);
										break;
								}
							}

							_commands_KeyBindingList.Add(new CommandBindingConfig(kb, replaceCurrent, cmd));
						}

						reader.MoveToElement();
					}
				}
			}
			reader.Read();
		}
Пример #30
0
        /// <summary>
        /// Executes a Command
        /// </summary>
        /// <param name="command">Any <see cref="BindableCommand"/></param>
        /// <returns>Value to indicate whether other bound commands should continue to execute</returns>
        public bool Execute(BindableCommand command)
        {
            if ((int)command < 10000)
            {
                NativeScintilla.SendMessageDirect((uint)command, IntPtr.Zero, IntPtr.Zero);
                return(true);
            }

            switch (command)
            {
            case BindableCommand.AutoCShow:
                Scintilla.AutoComplete.Show();
                return(true);

            case BindableCommand.AcceptActiveSnippets:
                return(Scintilla.Snippets.AcceptActiveSnippets());

            case BindableCommand.CancelActiveSnippets:
                return(Scintilla.Snippets.CancelActiveSnippets());

            case BindableCommand.DoSnippetCheck:
                return(Scintilla.Snippets.DoSnippetCheck());

            case BindableCommand.NextSnippetRange:
                return(Scintilla.Snippets.NextSnippetRange());

            case BindableCommand.PreviousSnippetRange:
                return(Scintilla.Snippets.PreviousSnippetRange());

            case BindableCommand.DropMarkerCollect:
                Scintilla.DropMarkers.Collect();
                return(false);

            case BindableCommand.DropMarkerDrop:
                Scintilla.DropMarkers.Drop();
                return(true);

            case BindableCommand.Print:
                Scintilla.Printing.Print();
                return(true);

            case BindableCommand.PrintPreview:
                Scintilla.Printing.PrintPreview();
                return(true);

            case BindableCommand.ShowFind:
                Scintilla.FindReplace.ShowFind();
                return(true);

            case BindableCommand.ShowReplace:
                Scintilla.FindReplace.ShowReplace();
                return(true);

            case BindableCommand.FindNext:
                Scintilla.FindReplace.Window.FindNext();
                return(true);

            case BindableCommand.FindPrevious:
                Scintilla.FindReplace.Window.FindPrevious();
                return(true);

            case BindableCommand.IncrementalSearch:
                Scintilla.FindReplace.IncrementalSearch();
                return(true);

            case BindableCommand.LineComment:
                Scintilla.Lexing.LineComment();
                return(true);

            case BindableCommand.LineUncomment:
                Scintilla.Lexing.LineUncomment();
                return(true);

            case BindableCommand.DocumentNavigateForward:
                Scintilla.DocumentNavigation.NavigateForward();
                return(true);

            case BindableCommand.DocumentNavigateBackward:
                Scintilla.DocumentNavigation.NavigateBackward();
                return(true);

            case BindableCommand.ToggleLineComment:
                Scintilla.Lexing.ToggleLineComment();
                return(true);

            case BindableCommand.StreamComment:
                Scintilla.Lexing.StreamComment();
                return(true);

            case BindableCommand.ShowSnippetList:
                Scintilla.Snippets.ShowSnippetList();
                return(true);

            case BindableCommand.ShowGoTo:
                Scintilla.GoTo.ShowGoToDialog();
                break;
            }

            return(false);
        }
Пример #31
0
 /// <summary>
 /// Removes a keyboard shortcut / command combination
 /// </summary>
 /// <param name="shortcut">Character corresponding to a (keyboard) key to trigger command</param>
 /// <param name="modifiers">Shift, alt, ctrl</param>
 /// <param name="command">Command to execute</param>
 public void RemoveBinding(char shortcut, Keys modifiers, BindableCommand command)
 {
     RemoveBinding(Utilities.GetKeys(shortcut), modifiers, command);
 }
Пример #32
0
 /// <summary>
 /// Removes a keyboard shortcut / command combination
 /// </summary>
 /// <param name="shortcut">Character corresponding to a (keyboard) key to trigger command</param>
 /// <param name="command">Command to execute</param>
 public void RemoveBinding(char shortcut, BindableCommand command)
 {
     RemoveBinding(Utilities.GetKeys(shortcut), Keys.None, command);
 }