Esempio n. 1
0
        public bool SaveBeforeExit()
        {
            foreach (var wordPair in flp_cards.Controls.OfType <QuizEditorCard>())
            {
                if (wordPair.EditCardSynonyms != null)
                {
                    if (!wordPair.EditCardSynonyms.ApplyChanges(true))
                    {
                        return(false);
                    }
                    wordPair.DisposeEditWordSynonyms();
                }
            }

            var saveDontSave = new SaveDontSave(this, SystemIcons.Warning, true);

            saveDontSave.ShowDialog();
            if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Save)
            {
                if (!SaveQuiz())
                {
                    return(false);
                }
            }
            else if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Cancel)
            {
                return(false);
            }

            ChangedSinceLastSave = false;
            return(true);
        }
Esempio n. 2
0
        private void NewQuiz()
        {
            if (ChangedSinceLastSave)
            {
                //var msg = MessageBox.Show("You have unsaved changes. Save before creating a new quiz?", "SteelQuiz", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                var saveDontSave = new SaveDontSave(this, SystemIcons.Warning, true, "The project contains unsaved changes. Save before creating a new quiz?",
                                                    "Save before creating new quiz? - SteelQuiz");
                saveDontSave.ShowDialog();
                if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Save)
                {
                    if (!SaveQuiz())
                    {
                        return;
                    }
                }
                else if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Cancel)
                {
                    return;
                }
            }

            Program.OpenQuizEditor(null, null, false);
            //var quizEditor = new QuizEditor(false);
            //quizEditor.Show();
        }
Esempio n. 3
0
        public void LoadQuiz(Quiz quiz = null, string quizPath = null, bool fromRecovery = false)
        {
            if (ChangedSinceLastSave)
            {
                //var msg = MessageBox.Show("You have unsaved changes. Save before loading a new quiz?", "SteelQuiz", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                var saveDontSave = new SaveDontSave(this, SystemIcons.Warning, true, "The project contains unsaved changes. Save before loading a new quiz?",
                                                    "Save before loading new quiz? - SteelQuiz");
                saveDontSave.ShowDialog();
                if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Save)
                {
                    if (!SaveQuiz())
                    {
                        return;
                    }
                }
                else if (saveDontSave.SaveDialogResult == SaveDontSave.SaveResult.Cancel)
                {
                    return;
                }
            }

            if (!fromRecovery)
            {
                DeleteRecovery();
            }

            if (quiz == null)
            {
                //ofd_quiz.InitialDirectory = ConfigManager.Config.SyncConfig.QuizFolders[0];
                var ofd = ofd_quiz.ShowDialog();
                if (ofd == DialogResult.OK)
                {
                    QuizPath = ofd_quiz.FileName;
                }
                else
                {
                    return;
                }

                try
                {
                    quiz = JsonConvert.DeserializeObject <Quiz>(AtomicIO.AtomicRead(QuizPath));
                }
                catch (AtomicException ex)
                {
                    // Should never be reached as path exists
                    throw ex;
                }
            }

            if (quizPath != null)
            {
                QuizPath = quizPath;
            }

            UpdateUndoRedoStacks = false;

            SetCards(quiz.Cards.Count + 2);

            QuizGuid       = quiz.GUID;
            cmb_lang1.Text = quiz.CardFrontType;
            cmb_lang2.Text = quiz.CardBackType;

            for (int i = 0; i < quiz.Cards.Count; ++i)
            {
                var ctrl = flp_cards.Controls.OfType <QuizEditorCard>().ElementAt(i);
                var card = quiz.Cards[i];

                ctrl.Guid                 = card.Guid;
                ctrl.txt_front.Text       = card.Front;
                ctrl.FrontSynonyms        = card.FrontSynonyms;
                ctrl.txt_back.Text        = card.Back;
                ctrl.BackSynonyms         = card.BackSynonyms;
                ctrl.ComparisonRules.Data = (StringComp.Rules)FixEnum(card.SmartComparisonRules);
            }

            if (!fromRecovery)
            {
                QuizRecoveryData     = new QuizRecoveryData(QuizPath);
                ChangedSinceLastSave = false;
            }

            UndoStack.Clear();
            RedoStack.Clear();
            UpdateUndoRedoStacks = true;

            SetGlobalSmartComparisonState();
        }