Ejemplo n.º 1
0
        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private static void OnOpenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            MainControl control = (MainControl)sender;

            // Show a file open dialog
            OpenFileDialog dialog = new OpenFileDialog();

            if (!BrowserInteropHelper.IsBrowserHosted)
            {
                dialog.CheckFileExists = true;
            }
            dialog.Multiselect = false;
            dialog.Filter      = "Code files (*.cs;*.vb;*.js;*.py;*.xml;*.txt)|*.cs;*.vb;*.js;*.py;*.xml;*.txt|All files (*.*)|*.*";
            if (dialog.ShowDialog() == true)
            {
                // Open a document
                if (BrowserInteropHelper.IsBrowserHosted)
                {
                    // Use dialog to help open the file because of security restrictions
                    using (Stream stream = dialog.OpenFile()) {
                        // Read the file
                        control.editor.Document.LoadFile(stream, Encoding.UTF8);
                    }
                }
                else
                {
                    // Security is not an issue in a Windows app so use simple method
                    control.editor.Document.LoadFile(dialog.FileName);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private static void OnPrintPreviewExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            MainControl control = (MainControl)sender;

            // Show a print preview dialog
            control.editor.ShowPrintPreviewDialog();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private static void OnNewExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            MainControl control = (MainControl)sender;

            // Create a new document
            control.editor.Document.SetText(String.Empty);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">An <see cref="ExecutedRoutedEventArgs"/> that contains the event data.</param>
        private static void OnSaveExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            MainControl control = (MainControl)sender;

            // NOTE: Save the document here
            MessageBox.Show("Save the document here.");

            // Flag as not modified
            control.editor.Document.IsModified = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Occurs when the <see cref="RoutedCommand"/> needs to determine whether it can execute.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">A <see cref="CanExecuteRoutedEventArgs"/> that contains the event data.</param>
        private static void OnSaveCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            MainControl control = (MainControl)sender;

            e.CanExecute = control.editor.Document.IsModified;
        }