Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / C#

EnvMan 1.3 - Windows Environment Variables Manager

Rate me:
Please Sign up or sign in to vote.
4.34/5 (21 votes)
1 Feb 2008GPL36 min read 148.5K   360   83  
Environment Variables Manager (EnvMan) is a tool written in C# .Net intended to handle the administration of Windows Shell Environment Variables. It is designed to replace Control Panel System Environment Manager and easily manage long variable values.
/*
   EnvMan - The Open-Source Windows Environment Variables Manager
   Copyright (C) 2006-2007 Vlad Setchin <v_setchin@yahoo.com.au>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using EnvManager.Properties;

namespace EnvManager.Handlers
{
    /// <summary>
    /// Holds list of executed commands for Undo, Redo Functionality
    /// </summary>
    public class UndoRedoCommandList
    {
        #region Variables
        private List<ICommand> commandsList = null;
        private int currentCommandIndex = -1;   // -1 no command executed
        private string undoMsg = "";
        private string redoMsg = "";
        #endregion Variables

        public UndoRedoCommandList()
        {
            commandsList = new List<ICommand>();
            SetUndoRedoMessages();
        }

        #region Properties
        public string UndoMsg
        {
            get { return undoMsg; }
        }
        public string RedoMsg
        {
            get { return redoMsg; }
        }
        public bool CanUndo
        {
            get
            {
                return currentCommandIndex != -1;
            }
        }
        public bool CanRedo
        {
            get
            {
                return commandsList.Count > 0
                    && currentCommandIndex != commandsList.Count - 1;
            }
        }
        #endregion Properties

        #region Functions
        /// <summary>
        /// Executes Undo of the current command from the list.
        /// </summary>
        public void Undo()
        {
            ICommand command = commandsList[currentCommandIndex] as ICommand;
            command.Undo();
            currentCommandIndex -= 1;
            SetUndoRedoMessages();
        }
        /// <summary>
        /// Executes Undo of the next command from the list after current.
        /// </summary>
        public void Redo()
        {
            ICommand command = commandsList[++currentCommandIndex] as ICommand;
            command.Redo();
            SetUndoRedoMessages();
        }
        /// <summary>
        /// Adds the specified command to a list.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Add(ICommand command)
        {
            if (commandsList.Count > 0 && currentCommandIndex != commandsList.Count - 1)
            {   // remove all the commands after current
                if(currentCommandIndex == -1)
                {
                    commandsList.RemoveRange(0, commandsList.Count);
                }
                else
                {
                    commandsList.RemoveRange(currentCommandIndex + 1,
                        commandsList.Count - (currentCommandIndex == -1 ? 0 : currentCommandIndex) - 1);
                }   
            }

            // add command to a list and increment index
            commandsList.Add(command);
            currentCommandIndex += 1;
            SetUndoRedoMessages();
        }
        private void SetUndoRedoMessages()
        {
            undoMsg = (this.CanUndo == true
                ? Resources.ToolTipUndo + " " + (commandsList[currentCommandIndex] as ICommand).CommandName
                : Resources.ToolTipUndo);
            redoMsg = (this.CanRedo == true
                ? Resources.ToolTipRedo + " " + (commandsList[currentCommandIndex + 1] as ICommand).CommandName
                : Resources.ToolTipRedo);
        }
        #endregion Functions

        /// <summary>
        /// Clears list of commands.
        /// </summary>
        public void Clear()
        {
            this.commandsList.Clear();
            this.currentCommandIndex = -1;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Australia Australia
I have never shared my work online before. Now time has come. I recently started a Software Development Toolbox project. Anyone is welcome to view and add your share to it.

Comments and Discussions