Exemplo n.º 1
0
        /// <summary>
        /// Asks user to save the current file before doing something (e.g. exit, open a new file)
        /// </summary>
        /// <returns>true if user cancels the impending action</returns>
        private bool AskToSaveCurrentFile()
        {
            var viewModel = (PackageViewModel)DataContext;

            if (HasUnsavedChanges || (IsInEditFileMode && viewModel.FileEditorViewModel.HasEdit))
            {
                // if there is unsaved changes, ask user for confirmation
                bool?result = UIServices.ConfirmWithCancel("You have unsaved changes in the current package.", StringResources.Dialog_SaveQuestion);

                if (result == null)
                {
                    return(true);
                }
                else if (result == true)
                {
                    if (IsInEditFileMode)
                    {
                        // force a Save from outside the file editor.
                        // In this case, Content is the FileEditor user control
                        viewModel.FileEditorViewModel.SaveOnExit((IFileEditorService)Content);
                    }

                    ICommand     saveCommand = viewModel.SaveCommand;
                    const string parameter   = "ForceSave";
                    saveCommand.Execute(parameter);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asks user to save the current file before doing something (e.g. exit, open a new file)
        /// </summary>
        /// <returns>true if user cancels the impending action</returns>
        private bool AskToSaveCurrentFile()
        {
            if (HasUnsavedChanges)
            {
                // if there is unsaved changes, ask user for confirmation
                var result = UIServices.ConfirmWithCancel(StringResources.Dialog_SaveQuestion);
                if (result == null)
                {
                    return(true);
                }

                if (result == true)
                {
                    var          saveCommand = SaveMenuItem.Command;
                    const string parameter   = "ForceSave";
                    saveCommand.Execute(parameter);
                }
            }

            return(false);
        }