Inheritance: ObservableObject
Exemplo n.º 1
0
 private async Task<bool> SaveAsDocumentAsync(DocumentModel document)
 {
     var dlg = new SaveFileDialog();
     dlg.Filter = "NSwag file (*.nswag)|*.nswag|NSwag JSON file (*.json)|*.json";
     dlg.RestoreDirectory = true;
     dlg.AddExtension = true;
     if (dlg.ShowDialog() == DialogResult.OK)
     {
         document.Document.Path = dlg.FileName;
         await document.Document.SaveAsync();
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
        private async Task<bool> SaveDocumentAsync(DocumentModel document)
        {
            return await RunTaskAsync(async () =>
            {
                if (File.Exists(document.Document.Path))
                {
                    await document.Document.SaveAsync();
                    MessageBox.Show("The file has been saved.", "File saved");
                    return true;
                }
                else
                {
                    if (await SaveAsDocumentAsync(document))
                        return true;
                }

                return false;
            });
        }
Exemplo n.º 3
0
 public async Task OpenDocumentAsync(string filePath)
 {
     await RunTaskAsync(async () =>
     {
         var currentDocument = Documents.SingleOrDefault(d => d.Document.Path == filePath);
         if (currentDocument != null)
             SelectedDocument = currentDocument;
         else
         {
             var document = new DocumentModel(await NSwagDocument.LoadAsync(filePath));
             Documents.Add(document);
             SelectedDocument = document;
         }
     });
 }
Exemplo n.º 4
0
        public async Task<bool> CloseDocumentAsync(DocumentModel document)
        {
            if (document.Document.IsDirty)
            {
                var result = MessageBox.Show("Do you want to save the file " + document.Document.Name + " ?",
                    "Save file", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    var success = await SaveDocumentAsync(document);
                    if (!success)
                        return false;
                }
                else if (result == DialogResult.Cancel)
                    return false;
            }

            Documents.Remove(document);
            return true;
        }
Exemplo n.º 5
0
 private void CreateDocument()
 {
     var document = new DocumentModel(NSwagDocument.Create());
     Documents.Add(document);
     SelectedDocument = document;
 }