示例#1
0
        /// <summary>
        /// Adds a command to the list of commands
        /// </summary>
        public void AddCommand(JsonCommand _Command)
        {
            // Item
            ListBoxItem _Item = new ListBoxItem()
            {
                Content = _Command.CommandName,
                Tag     = _Command
            };

            // Event
            _Item.Selected += delegate {
                // Prevent crashing
                if (Directory.Exists(_Command.CommandPath))
                {
                    // Edit title
                    this.Title = string.Format(Langs.Get("profile_window_title"), Profile, _Command.CommandName);

                    // Save selected command
                    if (CurrentBoard != null)
                    {
                        CurrentBoard.SaveCommand();
                    }

                    // Set
                    CurrentBoard = new CommandBoard(_Command, _Item);
                    Utils.EmbedUserControl(CurrentBoard, Grid);
                }
            };

            // Add
            CommandsBox.Items.Add(_Item);
        }
示例#2
0
        private void SaveExit()
        {
            // If window is closing
            if (IsClosing)
            {
                return;
            }
            IsClosing = true;

            // Variables
            string _ProfileName = Profiles.GetProfile();
            string _ProfilePath = Profiles.GetProfilePath();

            // Save profile
            if (CurrentBoard != null)
            {
                CurrentBoard.SaveCommand();
            }

            #region Edit profile name

            // New profile name
            string _NewProfileName = Utils.GetSafeFilename(ProfileName.Text.Trim()).Trim();

            // Profile name is different & is not empty
            if (!string.IsNullOrEmpty(_NewProfileName) && _NewProfileName != _ProfileName)
            {
                // New profile path
                string _NewProfilePath = Path.Combine(Reference.ProfilesPath, _NewProfileName);

                // Profile doesn't exist
                if (!Directory.Exists(_NewProfilePath))
                {
                    // Edit profile name
                    Directory.Move(_ProfilePath, _NewProfilePath);

                    // Profile vars
                    _ProfileName = _NewProfileName;
                    _ProfilePath = _NewProfilePath;
                }
                else
                {
                    Utils.Log(string.Format(Langs.Get("profile_already_exist"), _ProfileName));
                }
            }

            #endregion

            // Clear current board (prevent crashing)
            CurrentBoard = null;

            // Refresh list
            Profiles.RefreshList(null);
            // Select profile
            Profiles.Select(_ProfileName);
        }