From 31cd62fb1e1526f6572ea784369e1ac40cde7858 Mon Sep 17 00:00:00 2001 From: shatty Date: Thu, 31 Jul 2003 09:33:33 +0000 Subject: [PATCH] more and more error checks and helpful dialogs explaining what is happening when things go bad git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4166 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/StyledEditWindow.cpp | 46 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 7867d446f4..2affccbf42 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -976,6 +976,27 @@ StyledEditWindow::RevertToSaved() entry_ref ref; const char *name; + fSaveMessage->FindRef("directory", &ref); + fSaveMessage->FindString("name", &name); + + BDirectory dir(&ref); + + BFile file(&dir, name, B_READ_ONLY); + status_t result; + result = file.InitCheck(); + if (result != B_OK) { + BAlert *vanishedAlert; + BString alertText; + alertText.SetTo("Cannot revert, file not found: \""); + alertText<< name; + alertText<<"\"."; + vanishedAlert = new BAlert("vanishedAlert",alertText.String(), "Bummer", 0, 0, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); + vanishedAlert->SetShortcut(0, B_ESCAPE); + vanishedAlert->Go(); + return; + } + int32 buttonIndex= 0; BAlert *revertAlert; BString alertText; @@ -991,14 +1012,25 @@ StyledEditWindow::RevertToSaved() return; } - fSaveMessage->FindRef("directory", &ref); - fSaveMessage->FindString("name", &name); - - BDirectory dir(&ref); - - BFile file(&dir, name, B_READ_ONLY | B_CREATE_FILE); fTextView->Reset(); //clear the textview... - fTextView->GetStyledText(&file); //and fill it from the file + result = fTextView->GetStyledText(&file); //he he he :) + + if (result != B_OK) { + BAlert *loadFailedAlert; + BString alertText; + if (result == B_TRANSLATION_ERROR_BASE) { + alertText.SetTo("Translation error loading \""); + } else { + alertText.SetTo("Unknown error loading \""); + } + alertText<< name; + alertText<<"\"."; + loadFailedAlert= new BAlert("loadFailedAlert",alertText.String(), "Bummer", 0, 0, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); + loadFailedAlert->SetShortcut(0, B_ESCAPE); + loadFailedAlert->Go(); + return; + } // update alignment switch (fTextView->Alignment()) {