Exemplo n.º 1
0
        private void View_FormClosing(Object sender, FormClosingEventArgs e)
        {
            try
            {
                ViewModel.StatusMessage = String.Format("{0} completing...", ViewName);

                DisposeSettings();

                ViewModel.StatusMessage = String.Format("{0} completed.", ViewName);
            }
            catch (Exception ex)
            {
                ViewModel.ErrorMessage  = ex.Message.ToString();
                ViewModel.StatusMessage = "";

                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
            finally
            {
                ViewModel = null;
            }
        }
Exemplo n.º 2
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);
            }
        }