Esempio n. 1
0
        internal static string ShowSaveAsDialog(RazorTemplateViewModel template)
        {
            var dlg = new SaveFileDialog();

            dlg.DefaultExt = ".razorpad";
            dlg.Filter     = "RazorPad Documents|*.razorpad";
            dlg.Filter     = "C# Razor Documents|*.cshtml";
            dlg.Filter     = "VB Razor Documents|*.vbhtml";
            dlg.Filter     = "All Files|*.*";

            if (!string.IsNullOrWhiteSpace(template.Filename))
            {
                string directory = Path.GetDirectoryName(template.Filename);

                if (!string.IsNullOrWhiteSpace(directory))
                {
                    dlg.InitialDirectory = directory;
                }
            }

            if (dlg.ShowDialog().GetValueOrDefault())
            {
                return(dlg.FileName);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public void Close(RazorTemplateViewModel document, bool?save = null)
        {
            Log.Debug("Closing document...");

            if (document.IsDirty && save.GetValueOrDefault(true))
            {
                Log.Debug("Document is dirty confirming save or close...");

                var shouldSave = ConfirmSaveDirtyDocumentThunk(document);

                Log.Debug("User said {0}", shouldSave);

                switch (shouldSave)
                {
                case MessageBoxResult.Cancel:
                    return;

                case MessageBoxResult.Yes:
                    Save(document);
                    break;
                }
            }

            Templates.Remove(document);

            Log.Debug("Document closed");
        }
Esempio n. 3
0
        public void AddNewTemplateEditor(RazorTemplateViewModel template, bool current = true)
        {
            Log.Debug("Adding new template editor (current: {0})...", current);

            template.AutoExecute = AutoExecute;
            template.AutoSave    = AutoExecute;
            template.Messages    = Messages;

            template.Executing += OnAutoSave;

            Templates.Add(template);

            if (!string.IsNullOrWhiteSpace(template.Filename))
            {
                RecentFiles.Add(template.Filename);
            }

            if (current)
            {
                Log.Debug("Setting as current template");
                CurrentTemplate = template;
            }

            template.Execute();

            Log.Info("Added new template editor");
        }
Esempio n. 4
0
        public void AddNewTemplateEditor(string filename, bool current = true)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                Log.Info("Attempted to add new editor without specifying a filename -- returning");
                return;
            }

            RazorTemplateViewModel loadedTemplate =
                Templates
                .Where(x => !string.IsNullOrWhiteSpace(x.Filename))
                .SingleOrDefault(x => x.Filename.Equals(filename, StringComparison.OrdinalIgnoreCase));

            if (loadedTemplate != null)
            {
                if (current)
                {
                    CurrentTemplate = loadedTemplate;
                }

                return;
            }

            var document = _documentManager.Load(filename);

            document.Filename = filename;

            AddNewTemplateEditor(document, current);
        }
Esempio n. 5
0
 internal static MessageBoxResult ShowConfirmSaveDirtyDocumentMessageBox(RazorTemplateViewModel document)
 {
     return
         (MessageBox.Show(
              "You've made changes to this document - save them before closing?",
              "SaveAs Changes",
              MessageBoxButton.YesNoCancel,
              MessageBoxImage.Question
              ));
 }
Esempio n. 6
0
 internal static MessageBoxResult ShowConfirmSaveDirtyDocumentMessageBox(RazorTemplateViewModel document)
 {
     return
         MessageBox.Show(
             "You've made changes to this document - save them before closing?",
             "SaveAs Changes",
             MessageBoxButton.YesNoCancel,
             MessageBoxImage.Question
             );
 }
Esempio n. 7
0
        public void Save(RazorTemplateViewModel document)
        {
            var filename = document.Filename;

            if (!document.CanSaveToCurrentlyLoadedFile)
            {
                filename = null;
            }

            SaveAs(document, filename);
        }
Esempio n. 8
0
        public string SaveAs(RazorTemplateViewModel document, string filename = null)
        {
            try
            {
                if (filename == null)
                {
                    Log.Debug("Filename was null -- triggering SaveAs...");
                    filename = GetSaveAsFilenameThunk(document);
                }

                if (string.IsNullOrWhiteSpace(filename))
                {
                    Log.Warn("Filename is empty - skipping save");
                    return(filename);
                }

                Log.Debug("Saving document to {0}...", filename);

                _documentManager.Save(document.Document, filename);

                Log.Info("Document saved to {0}", filename);

                document.Filename = filename;

                if (!string.IsNullOrWhiteSpace(filename))
                {
                    RecentFiles.Add(filename);
                }

                if (AutoSaver != null)
                {
                    AutoSaver.Clear();
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException("Error saving document", ex);
                Error.SafeInvoke(ex.Message);
            }

            return(filename);
        }
Esempio n. 9
0
        internal static string ShowSaveAsDialog(RazorTemplateViewModel template)
        {
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".razorpad";
            dlg.Filter = "RazorPad Documents|*.razorpad";
            dlg.Filter = "C# Razor Documents|*.cshtml";
            dlg.Filter = "VB Razor Documents|*.vbhtml";
            dlg.Filter = "All Files|*.*";

            if (!string.IsNullOrWhiteSpace(template.Filename))
            {
                string directory = Path.GetDirectoryName(template.Filename);

                if (!string.IsNullOrWhiteSpace(directory))
                    dlg.InitialDirectory = directory;
            }

            if (dlg.ShowDialog().GetValueOrDefault())
                return dlg.FileName;
            else
                return null;
        }
Esempio n. 10
0
        public string SaveAs(RazorTemplateViewModel document, string filename = null)
        {
            try
            {
                if (filename == null)
                {
                    Log.Debug("Filename was null -- triggering SaveAs...");
                    filename = GetSaveAsFilenameThunk(document);
                }

                if (string.IsNullOrWhiteSpace(filename))
                {
                    Log.Warn("Filename is empty - skipping save");
                    return filename;
                }

                Log.Debug("Saving document to {0}...", filename);

                _documentManager.Save(document.Document, filename);

                Log.Info("Document saved to {0}", filename);

                document.Filename = filename;

                if (!string.IsNullOrWhiteSpace(filename))
                    RecentFiles.Add(filename);

                if(AutoSaver != null)
                    AutoSaver.Clear();
            }
            catch (Exception ex)
            {
                Log.ErrorException("Error saving document", ex);
                Error.SafeInvoke(ex.Message);
            }

            return filename;
        }
Esempio n. 11
0
        public void Save(RazorTemplateViewModel document)
        {
            var filename = document.Filename;

            if (!document.CanSaveToCurrentlyLoadedFile)
                filename = null;

            SaveAs(document, filename);
        }
Esempio n. 12
0
        public void Close(RazorTemplateViewModel document, bool? save = null)
        {
            Log.Debug("Closing document...");

            if (document.IsDirty && save.GetValueOrDefault(true))
            {
                Log.Debug("Document is dirty confirming save or close...");

                var shouldSave = ConfirmSaveDirtyDocumentThunk(document);

                Log.Debug("User said {0}", shouldSave);

                switch (shouldSave)
                {
                    case MessageBoxResult.Cancel:
                        return;

                    case MessageBoxResult.Yes:
                        Save(document);
                        break;
                }
            }

            Templates.Remove(document);

            Log.Debug("Document closed");
        }
Esempio n. 13
0
        public void AddNewTemplateEditor(RazorTemplateViewModel template, bool current = true)
        {
            Log.Debug("Adding new template editor (current: {0})...", current);

            template.AutoExecute = AutoExecute;
            template.AutoSave = AutoExecute;
            template.Messages = Messages;

            template.Executing += OnAutoSave;

            Templates.Add(template);

            if (!string.IsNullOrWhiteSpace(template.Filename))
                RecentFiles.Add(template.Filename);

            if (current)
            {
                Log.Debug("Setting as current template");
                CurrentTemplate = template;
            }

            template.Execute();

            Log.Info("Added new template editor");
        }