public FormsViewModel
        (
            PropertyChangedEventHandler propertyChangedEventHandlerDelegate,
            Dictionary <String, TIcon> actionIconImages,
            FileDialogInfo settingsFileDialogInfo
        ) :
            this()
        {
            try
            {
                //(and the delegate it contains
                if (propertyChangedEventHandlerDelegate != default(PropertyChangedEventHandler))
                {
                    this.PropertyChanged += new PropertyChangedEventHandler(propertyChangedEventHandlerDelegate);
                }

                _actionIconImages = actionIconImages;

                _settingsFileDialogInfo = settingsFileDialogInfo;

                ActionIconImage = _actionIconImages["Save"];
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
        }
Ejemplo n.º 2
0
        }                        //Note: not called, but need to be present to compile--SJS

        public MVCViewModel
        (
            PropertyChangedEventHandler propertyChangedEventHandlerDelegate,
            Dictionary <String, Bitmap> actionIconImages,
            FileDialogInfo settingsFileDialogInfo
        ) :
            base(propertyChangedEventHandlerDelegate, actionIconImages, settingsFileDialogInfo)
        {
            try
            {
            }
            catch (Exception ex)
            {
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
        }
 public FormsViewModel
 (
     PropertyChangedEventHandler propertyChangedEventHandlerDelegate,
     Dictionary <String, TIcon> actionIconImages,
     FileDialogInfo settingsFileDialogInfo,
     TView view //= default(TView) //(In VB 2010, )VB caller cannot differentiate between members which differ only by an optional param--SJS
 ) :
     this(propertyChangedEventHandlerDelegate, actionIconImages, settingsFileDialogInfo)
 {
     try
     {
         View = view;
     }
     catch (Exception ex)
     {
         Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
     }
 }
        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));
            }
        }
        /// <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));
            }
        }
Ejemplo n.º 6
0
        protected void InitViewModel()
        {
            Dictionary <String, Bitmap> d = default(Dictionary <String, Bitmap>);

            try
            {
                //tell controller how model should notify view about non-persisted properties AND including model properties that may be part of settings
                ModelController <MVCModel> .DefaultHandler = PropertyChangedEventHandlerDelegate;

                //tell controller how settings should notify view about persisted properties
                SettingsController <MVCSettings> .DefaultHandler = PropertyChangedEventHandlerDelegate;

                InitModelAndSettings();

                FileDialogInfo settingsFileDialogInfo =
                    new FileDialogInfo
                    (
                        SettingsController <MVCSettings> .FILE_NEW,
                        null,
                        null,
                        MVCSettings.FileTypeExtension,
                        MVCSettings.FileTypeDescription,
                        MVCSettings.FileTypeName,
                        new String[]
                {
                    "XML files (*.xml)|*.xml",
                    "All files (*.*)|*.*"
                },
                        false,
                        default(Environment.SpecialFolder),
                        PathExtensions.WithTrailingSeparator(Environment.GetFolderPath(Environment.SpecialFolder.Personal))
                    );

                //set dialog caption
                settingsFileDialogInfo.Title = this.Text;

                d = new Dictionary <String, Bitmap>();
                d.Add("New", MVCForms.Properties.Resources.New);
                d.Add("Open", MVCForms.Properties.Resources.Open);
                d.Add("Save", MVCForms.Properties.Resources.Save);
                d.Add("Print", MVCForms.Properties.Resources.Print);
                d.Add("Undo", MVCForms.Properties.Resources.Undo);
                d.Add("Redo", MVCForms.Properties.Resources.Redo);
                d.Add("Cut", MVCForms.Properties.Resources.Cut);
                d.Add("Copy", MVCForms.Properties.Resources.Copy);
                d.Add("Paste", MVCForms.Properties.Resources.Paste);
                d.Add("Delete", MVCForms.Properties.Resources.Delete);
                d.Add("Find", MVCForms.Properties.Resources.Find);
                d.Add("Replace", MVCForms.Properties.Resources.Replace);
                d.Add("Refresh", MVCForms.Properties.Resources.Reload);
                d.Add("Preferences", MVCForms.Properties.Resources.Preferences);
                d.Add("Properties", MVCForms.Properties.Resources.Properties);
                d.Add("Contents", MVCForms.Properties.Resources.Contents);
                d.Add("About", MVCForms.Properties.Resources.About);

                //class to handle standard behaviors
                ViewModelController <Bitmap, MVCViewModel> .New
                (
                    ViewName,
                    new MVCViewModel
                    (
                        this.PropertyChangedEventHandlerDelegate,
                        d,
                        settingsFileDialogInfo
                    )
                );

                //select a viewmodel by view name
                ViewModel = ViewModelController <Bitmap, MVCViewModel> .ViewModel[ViewName];

                BindFormUi();

                //Init config parameters
                if (!LoadParameters())
                {
                    throw new Exception(String.Format("Unable to load config file parameter(s)."));
                }

                //DEBUG:filename coming in is being converted/passed as DOS 8.3 format equivalent
                //Load
                if ((SettingsController <MVCSettings> .FilePath == null) || (SettingsController <MVCSettings> .Filename == SettingsController <MVCSettings> .FILE_NEW))
                {
                    //NEW
                    ViewModel.FileNew();
                }
                else
                {
                    //OPEN
                    ViewModel.FileOpen(false);
                }

#if debug
                //debug view
                menuEditProperties_Click(sender, e);
#endif

                //Display dirty state
                ModelController <MVCModel> .Model.Refresh();
            }
            catch (Exception ex)
            {
                if (ViewModel != null)
                {
                    ViewModel.ErrorMessage = ex.Message;
                }
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
        }
Ejemplo n.º 7
0
 public static extern bool SaveFileDialog(ref FileDialogInfo openFileInfo);