Exemple #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;
            }
        }
Exemple #2
0
        protected void InitViewModel()
        {
            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),
                        Environment.GetFolderPath(Environment.SpecialFolder.Personal).WithTrailingSeparator()
                    );

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

                //class to handle standard behaviors
                ViewModelController <Bitmap, MVCViewModel> .New
                (
                    ViewName,
                    new MVCViewModel
                    (
                        this.PropertyChangedEventHandlerDelegate,
                        new Dictionary <String, Bitmap>()
                {         //TODO:ideally, should get these from library, but items added did not generated into resource class.
                    { "New", MvcForm.Core.Properties.Resources.New },
                    { "Open", MvcForm.Core.Properties.Resources.Open },
                    { "Save", MvcForm.Core.Properties.Resources.Save },
                    { "Print", MvcForm.Core.Properties.Resources.Print },
                    { "Undo", MvcForm.Core.Properties.Resources.Undo },
                    { "Redo", MvcForm.Core.Properties.Resources.Redo },
                    { "Cut", MvcForm.Core.Properties.Resources.Cut },
                    { "Copy", MvcForm.Core.Properties.Resources.Copy },
                    { "Paste", MvcForm.Core.Properties.Resources.Paste },
                    { "Delete", MvcForm.Core.Properties.Resources.Delete },
                    { "Find", MvcForm.Core.Properties.Resources.Find },
                    { "Replace", MvcForm.Core.Properties.Resources.Replace },
                    { "Refresh", MvcForm.Core.Properties.Resources.Refresh },
                    { "Preferences", MvcForm.Core.Properties.Resources.Preferences },
                    { "Properties", MvcForm.Core.Properties.Resources.Properties },
                    { "Contents", MvcForm.Core.Properties.Resources.Contents },
                    { "About", MvcForm.Core.Properties.Resources.About }
                },
                        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);
            }
        }