public Task <bool?> OpenDialog()
 {
     _tcs  = new TaskCompletionSource <bool?>();
     State = null;
     DialogOpen?.Invoke(this, EventArgs.Empty);
     return(_tcs.Task);
 }
Exemple #2
0
        /// <summary>
        /// This callback will be called if the user selected the Open Configuration.
        /// </summary>
        /// <param name="sender">Standard event argument. Not used.</param>
        /// <param name="e">Standard event argument. Not used.</param>
        private void OpenMenuItem_Click(object sender, EventArgs e)
        {
            if (this.m_currentFile != null)
            {
                DialogOpen.InitialDirectory = this.m_filePath.Substring(0, this.m_filePath.LastIndexOf('\\'));
                DialogOpen.FileName         = "";
            }
            else
            {
                DialogOpen.InitialDirectory = CommonViewRoutines.GetFilesDirectory();
            }

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                // hide all the other guis
                if (this.m_ConfigView.Visible)
                {
                    this.m_ConfigView.Close();
                    if (CheckFormIsOpen("ConfigView"))
                    {
                        return;
                    }
                    else
                    {
                        this.m_ConfigView.Dispose();
                    }
                }

                try
                {
                    m_Controller.OpenConfig(DialogOpen.FileName);
                    m_filePath    = DialogOpen.FileName;
                    m_currentFile = DialogOpen.FileName.Substring(DialogOpen.FileName.LastIndexOf('\\') + 1);
                    Text          = m_currentFile;
                    if (!this.m_ConfigView.Visible)
                    {
                        ShowConfigView();
                    }
                    saveAsToolStripMenuItem.Enabled = true;
                }
                catch
                {
                    MessageBox.Show(Messages.ErrorFileLoad);
                    if (!this.m_ConfigView.Visible)
                    {
                        ShowConfigView();
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Create Madlib from a text file
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCreateFile_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult theResult = DialogOpen.ShowDialog();
         if (theResult == DialogResult.OK)
         {
             if (File.Exists(DialogOpen.FileName))
             {
                 madLib = new MadLib(File.ReadAllText(DialogOpen.FileName));
                 getError(madLib.create());
                 StoryBox.Text = madLib.MadLibText;
             }
         }
     }
     catch
     {
         getError(Error.UnknownException);
     }
 }
Exemple #4
0
        /// <summary>
        /// Button click event for opening a mad lib file and kick off the dialogs to read it
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult theResult = DialogOpen.ShowDialog();
                if (theResult == DialogResult.OK && File.Exists(DialogOpen.FileName))
                {
                    string MadLibText = File.ReadAllText(DialogOpen.FileName);

                    WordSelect theWordSelect = new WordSelect(MadLibText);
                    theResult = theWordSelect.ShowDialog();
                    if (theResult == DialogResult.OK)
                    {
                        StoryBox.Text = theWordSelect.retString;
                    }
                }
            }
            catch
            {
                getError(Error.UnknownException);
            }
        }