//may be used as-is, or overridden to handle differently

        public virtual void FileNew()
        {
            StatusMessage = String.Empty;
            ErrorMessage  = String.Empty;

            try
            {
                StartProgressBar("New...", null, _actionIconImages["New"], true, 33);

                if (SettingsController <TSettings> .Settings.Dirty)
                {
                    //prompt before saving
                    DialogResult messageBoxResult = MessageBox.Show("Save changes?", SettingsController <TSettings> .FilePath, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    switch (messageBoxResult)
                    {
                    case DialogResult.Yes:
                    {
                        //SAVE
                        FileSaveAs();

                        break;
                    }

                    case DialogResult.No:
                    {
                        break;
                    }

                    default:
                    {
                        throw new InvalidEnumArgumentException();
                    }
                    }
                }

                //NEW
                if
                (
                    !SettingsController <TSettings> .New()
                )
                {
                    throw new ApplicationException(String.Format("Unable to get New settings.\r\nPath: {0}", SettingsController <TSettings> .FilePath));
                }

                ModelController <TModel> .Model.Refresh();

                StopProgressBar("New completed.");
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                StopProgressBar("", String.Format("{0}", ex.Message));
            }
        }
        //public ICommand FileNewCommand { get; private set; }
        //public ICommand FileOpenCommand { get; private set; }
        //public ICommand FileSaveCommand { get; private set; }
        //public ICommand FileSaveAsCommand { get; private set; }
        //public ICommand FilePrintCommand { get; private set; }
        //public ICommand FileExitCommand { get; private set; }
        //public ICommand EditCopyToClipboardCommand { get; private set; }
        //public ICommand EditPropertiesCommand { get; private set; }
        //public ICommand HelpAboutCommand { get; private set; }
        #endregion Commands
        #endregion Declarations

        #region Constructors
        public FormsViewModel()
        {
            if (SettingsController <TSettings> .Settings == null)
            {
                SettingsController <TSettings> .New();
            }

            #region Commands
            //ActionIconWinformsImage =
            #endregion Commands
        }
        public virtual void FileSaveAs()
        {
            StatusMessage = String.Empty;
            ErrorMessage  = String.Empty;

            try
            {
                StartProgressBar
                (
                    "Saving As...",
                    null,
                    _actionIconImages["Save"],
                    true,
                    33
                );

                _settingsFileDialogInfo.Filename = SettingsController <TSettings> .FilePath;
                if (FileDialogInfo.GetPathForSave(_settingsFileDialogInfo))
                {
                    SettingsController <TSettings> .FilePath = _settingsFileDialogInfo.Filename;

                    //SAVE
                    if (!SettingsController <TSettings> .Save())
                    {
                        throw new ApplicationException(String.Format("Unable to Save settings.\r\nPath: {0}", SettingsController <TSettings> .FilePath));
                    }

                    ModelController <TModel> .Model.Refresh();

                    StopProgressBar("Save As completed.");
                }
                else
                {
                    StopProgressBar("Save As cancelled.");
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                StopProgressBar(null, String.Format("{0}", ex.Message));
            }
        }
示例#4
0
        //public ICommand FileNewCommand { get; private set; }
        //public ICommand FileOpenCommand { get; private set; }
        //public ICommand FileSaveCommand { get; private set; }
        //public ICommand FileSaveAsCommand { get; private set; }
        //public ICommand FilePrintCommand { get; private set; }
        //public ICommand FileExitCommand { get; private set; }
        //public ICommand EditCopyToClipboardCommand { get; private set; }
        //public ICommand EditPropertiesCommand { get; private set; }
        //public ICommand HelpAboutCommand { get; private set; }
        #endregion Commands
        #endregion Declarations

        #region Constructors
        public ConsoleViewModel()
        {
            if (SettingsController <TSettings> .Settings == null)
            {
                SettingsController <TSettings> .New();
            }

            #region Commands
            //this.FileNewCommand = new FileNewCommand(this);
            //this.FileOpenCommand = new FileOpenCommand(this);
            //this.FileSaveCommand = new FileSaveCommand(this);
            //this.FileSaveAsCommand = new FileSaveAsCommand(this);
            //this.FilePrintCommand = new FilePrintCommand(this);
            //this.FileExitCommand = new FileExitCommand(this);
            //this.EditCopyToClipboardCommand = new EditCopyToClipboardCommand(this);
            //this.EditPropertiesCommand = new EditPropertiesCommand(this);
            //this.HelpAboutCommand = new HelpAboutCommand(this);
            //ActionIconWinformsImage =
            #endregion Commands
        }
        /// <summary>
        /// Open object at SettingsController<TSettings>.FilePath.
        /// </summary>
        /// <param name="forceDialog">If false, just use SettingsController<TSettings>.FilePath</param>
        public virtual void FileOpen(Boolean forceDialog = true)
        {
            StatusMessage = String.Empty;
            ErrorMessage  = String.Empty;

            try
            {
                StartProgressBar
                (
                    "Opening...",
                    null,
                    _actionIconImages["Open"],
                    true,
                    33
                );

                if (SettingsController <TSettings> .Settings.Dirty)
                {
                    //prompt before saving
                    DialogResult messageBoxResult = System.Windows.Forms.MessageBox.Show("Save changes?", SettingsController <TSettings> .FilePath, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    switch (messageBoxResult)
                    {
                    case DialogResult.Yes:
                    {
                        //SAVE
                        FileSave();

                        break;
                    }

                    case DialogResult.No:
                    {
                        break;
                    }

                    default:
                    {
                        throw new InvalidEnumArgumentException();
                    }
                    }
                }

                if (forceDialog)
                {
                    _settingsFileDialogInfo.Filename = SettingsController <TSettings> .FilePath;
                    if (FileDialogInfo.GetPathForLoad(_settingsFileDialogInfo))
                    {
                        SettingsController <TSettings> .FilePath = _settingsFileDialogInfo.Filename;
                    }
                    else
                    {
                        StopProgressBar("Open cancelled.");
                        return; //if open was cancelled
                    }
                }

                //OPEN
                if (!SettingsController <TSettings> .Open())
                {
                    throw new ApplicationException(String.Format("Unable to Open settings.\r\nPath: {0}", SettingsController <TSettings> .FilePath));
                }

                ModelController <TModel> .Model.Refresh();

                StopProgressBar("Opened.");
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);

                StopProgressBar(null, String.Format("{0}", ex.Message));
            }
        }