Esempio n. 1
0
        /// <summary>
        /// Controller constructor
        /// </summary>
        /// <param name="mainForm">The form to use as the main form of the application</param>
        public Controller(MainForm mainForm)
        {
            _files = new List <PixelariaFile>();

            // Initialize the factories
            FrameFactory = new DefaultFrameFactory(this);

            // Initialize the validators and exporters
            DefaultValidator defValidator = new DefaultValidator(this);

            AnimationValidator      = defValidator;
            AnimationSheetValidator = defValidator;

            DefaultImporter = new DefaultPngImporter();

            // Initialize the Settings singleton
            Settings.GetSettings(Path.GetDirectoryName(Application.LocalUserAppDataPath) + "\\settings.ini");

            CurrentRecentFileList = new RecentFileList(10);

            if (mainForm != null)
            {
                mainForm.Controller = this;
                // Initialize the basic fields
                _mainForm = mainForm;
                _mainForm.UpdateRecentFilesList();

                // Start with a new empty bundle
                ShowNewBundle();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the RecentFileList class
        /// </summary>
        /// <param name="fileCount">The number of values to store at the list</param>
        public RecentFileList(int fileCount)
        {
            _fileList = new string[fileCount];

            // Load the values from the settings file
            Settings settings = Settings.GetSettings();

            for (int i = 0; i < fileCount; i++)
            {
                // Assert first to make sure the value exists
                settings.EnsureValue("Recent Files\\File" + i, EnsureValueType.String, "");

                _fileList[i] = settings.GetValue("Recent Files\\File" + i);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Stores the given file to the recent file list, and automatically
        /// saves the list down to the settings file
        /// </summary>
        /// <param name="file">The file to store on this list</param>
        public void StoreFile(string file)
        {
            Settings settings = Settings.GetSettings();

            string fullPath = Path.GetFullPath(file);

            // Don't do anything if the file is already at the top of the file list
            if (fullPath == _fileList[0])
            {
                return;
            }

            // Search if the file is not already in the list, and push it to the top
            int index = 0;

            for (int i = 1; i < _fileList.Length; i++)
            {
                if (fullPath == _fileList[i] || i == _fileList.Length - 1)
                {
                    index = (i == _fileList.Length - 1 ? i : i - 1);
                    break;
                }
            }

            // Push all current values down
            for (int i = index; i >= 0; i--)
            {
                if (i + 1 >= _fileList.Length)
                {
                    continue;
                }

                _fileList[i + 1] = _fileList[i];

                settings.SetValue("Recent Files\\File" + (i + 1), _fileList[i + 1]);
            }

            _fileList[0] = fullPath;

            settings.SetValue("Recent Files\\File" + 0, fullPath);
        }
Esempio n. 4
0
        /// <summary>
        /// Removes an index from this RecentFileList
        /// </summary>
        /// <param name="index">The index of the item to remove</param>
        public void RemoveFromList(int index)
        {
            Settings settings = Settings.GetSettings();

            if (index == _fileList.Length - 1)
            {
                _fileList[index] = "";
                settings.SetValue("Recent Files\\File" + index, "");
                return;
            }

            // Push all current values down
            for (int i = index; i < _fileList.Length - 1; i++)
            {
                _fileList[i] = _fileList[i + 1];

                settings.SetValue("Recent Files\\File" + i, _fileList[i]);
            }

            _fileList[_fileList.Length - 1] = "";
            settings.SetValue("Recent Files\\File" + (_fileList.Length - 1), "");
        }