* remove messenger leak in save panel
* tell something if saving a file fails before it gets to TranslationUtils, fixes #2612 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27225 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
* Andrew Bachmann
|
* Andrew Bachmann
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "ColorMenuItem.h"
|
#include "ColorMenuItem.h"
|
||||||
#include "FindWindow.h"
|
#include "FindWindow.h"
|
||||||
@@ -16,6 +15,7 @@
|
|||||||
#include "StyledEditView.h"
|
#include "StyledEditView.h"
|
||||||
#include "StyledEditWindow.h"
|
#include "StyledEditWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <CharacterSet.h>
|
#include <CharacterSet.h>
|
||||||
@@ -35,8 +35,6 @@
|
|||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
@@ -733,33 +731,22 @@ StyledEditWindow::Quit()
|
|||||||
bool
|
bool
|
||||||
StyledEditWindow::QuitRequested()
|
StyledEditWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
int32 buttonIndex = 0;
|
|
||||||
|
|
||||||
if (fClean)
|
if (fClean)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
BAlert *saveAlert;
|
BString alertText("Save changes to the document \"");
|
||||||
BString alertText;
|
alertText<< Title() <<"\"? ";
|
||||||
alertText.SetTo("Save changes to the document \"");
|
int32 index = _ShowAlert(alertText, "Cancel", "Don't Save", "Save",
|
||||||
alertText<< Title();
|
B_WARNING_ALERT);
|
||||||
alertText<<"\"? ";
|
|
||||||
saveAlert = new BAlert("savealert",alertText.String(), "Cancel", "Don't Save","Save",
|
|
||||||
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
|
|
||||||
saveAlert->SetShortcut(0, B_ESCAPE);
|
|
||||||
saveAlert->SetShortcut(1, 'd');
|
|
||||||
saveAlert->SetShortcut(2, 's');
|
|
||||||
buttonIndex = saveAlert->Go();
|
|
||||||
|
|
||||||
if (buttonIndex == 0) {
|
if (index == 0)
|
||||||
// "cancel": dont save, dont close the window
|
return false; // "cancel": dont save, dont close the window
|
||||||
return false;
|
|
||||||
} else if (buttonIndex == 1) {
|
if (index == 1)
|
||||||
// "don't save": just close the window
|
return true; // "don't save": just close the window
|
||||||
return true;
|
|
||||||
} else if (!fSaveMessage) {
|
if (!fSaveMessage) {
|
||||||
// save as
|
SaveAs(new BMessage(SAVE_THEN_QUIT));
|
||||||
BMessage* message = new BMessage(SAVE_THEN_QUIT);
|
|
||||||
SaveAs(message);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,55 +757,39 @@ StyledEditWindow::QuitRequested()
|
|||||||
status_t
|
status_t
|
||||||
StyledEditWindow::Save(BMessage *message)
|
StyledEditWindow::Save(BMessage *message)
|
||||||
{
|
{
|
||||||
status_t err = B_OK;
|
if (!message)
|
||||||
|
|
||||||
if (!message){
|
|
||||||
message = fSaveMessage;
|
message = fSaveMessage;
|
||||||
|
|
||||||
if (!message)
|
if (!message)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
entry_ref dirRef;
|
entry_ref dirRef;
|
||||||
err = message->FindRef("directory", &dirRef);
|
|
||||||
if (err!= B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
const char* name;
|
const char* name;
|
||||||
err = message->FindString("name", &name);
|
if (message->FindRef("directory", &dirRef) != B_OK
|
||||||
if (err!= B_OK)
|
|| message->FindString("name", &name) != B_OK)
|
||||||
return err;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
BDirectory dir(&dirRef);
|
BDirectory dir(&dirRef);
|
||||||
err = dir.InitCheck();
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
BEntry entry(&dir, name);
|
BEntry entry(&dir, name);
|
||||||
err = entry.InitCheck();
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
|
status_t status = B_ERROR;
|
||||||
|
if (dir.InitCheck() == B_OK && entry.InitCheck() == B_OK) {
|
||||||
BFile file(&entry, B_READ_WRITE | B_CREATE_FILE);
|
BFile file(&entry, B_READ_WRITE | B_CREATE_FILE);
|
||||||
err = file.InitCheck();
|
if (file.InitCheck() == B_OK)
|
||||||
if (err != B_OK)
|
status = fTextView->WriteStyledEditFile(&file);
|
||||||
return err;
|
}
|
||||||
|
|
||||||
err = fTextView->WriteStyledEditFile(&file);
|
if (status != B_OK) {
|
||||||
if (err != B_OK) {
|
|
||||||
BAlert *saveFailedAlert;
|
|
||||||
BString alertText;
|
BString alertText;
|
||||||
if (err == B_TRANSLATION_ERROR_BASE)
|
if (status == B_TRANSLATION_ERROR_BASE)
|
||||||
alertText.SetTo("Translation error saving \"");
|
alertText.SetTo("Translation error saving \"");
|
||||||
else
|
else
|
||||||
alertText.SetTo("Unknown error saving \"");
|
alertText.SetTo("Unknown error saving \"");
|
||||||
|
|
||||||
alertText << name;
|
alertText << name << "\".";
|
||||||
alertText << "\".";
|
_ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);
|
||||||
saveFailedAlert = new BAlert("saveFailedAlert", alertText.String(), "Bummer",
|
|
||||||
0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT);
|
return status;
|
||||||
saveFailedAlert->SetShortcut(0, B_ESCAPE);
|
|
||||||
saveFailedAlert->Go();
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTitle(name);
|
SetTitle(name);
|
||||||
@@ -838,7 +809,7 @@ StyledEditWindow::Save(BMessage *message)
|
|||||||
fUndoCleans = false;
|
fUndoCleans = false;
|
||||||
fRedoCleans = false;
|
fRedoCleans = false;
|
||||||
fClean = true;
|
fClean = true;
|
||||||
return err;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -853,7 +824,8 @@ StyledEditWindow::SaveAs(BMessage *message)
|
|||||||
directory = new entry_ref(dirRef);
|
directory = new entry_ref(dirRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this),
|
BMessenger target(this);
|
||||||
|
fSavePanel = new BFilePanel(B_SAVE_PANEL, &target,
|
||||||
directory, B_FILE_NODE, false);
|
directory, B_FILE_NODE, false);
|
||||||
|
|
||||||
BMenuBar* menuBar = dynamic_cast<BMenuBar*>(
|
BMenuBar* menuBar = dynamic_cast<BMenuBar*>(
|
||||||
@@ -919,13 +891,10 @@ StyledEditWindow::_LoadFile(entry_ref* ref)
|
|||||||
if (entry.GetName(name) != B_OK)
|
if (entry.GetName(name) != B_OK)
|
||||||
strcpy(name, "???");
|
strcpy(name, "???");
|
||||||
|
|
||||||
char text[B_PATH_NAME_LENGTH + 100];
|
BString text("Error loading \"");
|
||||||
snprintf(text, sizeof(text), "Error loading \"%s\":\n\t%s", name,
|
text << name << "\":\n\t" << strerror(status);
|
||||||
strerror(status));
|
|
||||||
|
|
||||||
BAlert* alert = new BAlert("StyledEdit Load Failed", text,
|
_ShowAlert(text, "OK", "", "", B_STOP_ALERT);
|
||||||
"Bummer", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT);
|
|
||||||
alert->Go();
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -990,40 +959,23 @@ StyledEditWindow::RevertToSaved()
|
|||||||
BEntry entry;
|
BEntry entry;
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = entry.SetTo(&dir, name);
|
status = entry.SetTo(&dir, name);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
status = entry.GetRef(&ref);
|
status = entry.GetRef(&ref);
|
||||||
|
|
||||||
if (status != B_OK || !entry.Exists()) {
|
if (status != B_OK || !entry.Exists()) {
|
||||||
BAlert *vanishedAlert;
|
BString alertText("Cannot revert, file not found: \"");
|
||||||
BString alertText;
|
alertText << name << "\".";
|
||||||
alertText.SetTo("Cannot revert, file not found: \"");
|
_ShowAlert(alertText, "OK", "", "", B_STOP_ALERT);
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 buttonIndex = 0;
|
BString alertText("Revert to the last version of \"");
|
||||||
BAlert* revertAlert;
|
alertText << Title() << "\"? ";
|
||||||
BString alertText;
|
if (_ShowAlert(alertText, "Cancel", "OK", "", B_WARNING_ALERT) != 1)
|
||||||
alertText.SetTo("Revert to the last version of \"");
|
|
||||||
alertText << Title();
|
|
||||||
alertText << "\"? ";
|
|
||||||
revertAlert= new BAlert("revertAlert", alertText.String(), "Cancel", "OK", 0,
|
|
||||||
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
|
|
||||||
revertAlert->SetShortcut(0, B_ESCAPE);
|
|
||||||
revertAlert->SetShortcut(1, 'o');
|
|
||||||
buttonIndex = revertAlert->Go();
|
|
||||||
|
|
||||||
if (buttonIndex != 1) {
|
|
||||||
// some sort of cancel, don't revert
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
fTextView->Reset();
|
fTextView->Reset();
|
||||||
|
|
||||||
if (_LoadFile(&ref) != B_OK)
|
if (_LoadFile(&ref) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1341,6 +1293,7 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
|
|||||||
_UpdateCleanUndoRedoSaveRevert();
|
_UpdateCleanUndoRedoSaveRevert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
|
StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
|
||||||
{
|
{
|
||||||
@@ -1355,3 +1308,25 @@ StyledEditWindow::_UpdateCleanUndoRedoSaveRevert()
|
|||||||
fCanRedo = false;
|
fCanRedo = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
StyledEditWindow::_ShowAlert(const BString& text, const BString& label,
|
||||||
|
const BString& label2, const BString& label3, alert_type type) const
|
||||||
|
{
|
||||||
|
const char* button2 = NULL;
|
||||||
|
if (label2.Length() > 0)
|
||||||
|
button2 = label2.String();
|
||||||
|
|
||||||
|
const char* button3 = NULL;
|
||||||
|
button_spacing spacing = B_EVEN_SPACING;
|
||||||
|
if (label3.Length() > 0) {
|
||||||
|
button3 = label3.String();
|
||||||
|
spacing = B_OFFSET_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
BAlert* alert = new BAlert("Alert", text.String(), label.String(), button2,
|
||||||
|
button3, B_WIDTH_AS_USUAL, spacing, type);
|
||||||
|
alert->SetShortcut(0, B_ESCAPE);
|
||||||
|
|
||||||
|
return alert->Go();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2002-2008, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#define STYLED_EDIT_WINDOW_H
|
#define STYLED_EDIT_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
@@ -57,6 +58,9 @@ class StyledEditWindow : public BWindow {
|
|||||||
status_t _LoadFile(entry_ref* ref);
|
status_t _LoadFile(entry_ref* ref);
|
||||||
void RevertToSaved();
|
void RevertToSaved();
|
||||||
void _UpdateCleanUndoRedoSaveRevert();
|
void _UpdateCleanUndoRedoSaveRevert();
|
||||||
|
int32 _ShowAlert(const BString& text, const BString& label,
|
||||||
|
const BString& label2, const BString& label3,
|
||||||
|
alert_type type) const;
|
||||||
|
|
||||||
BMenuBar *fMenuBar;
|
BMenuBar *fMenuBar;
|
||||||
BMessage *fPrintSettings;
|
BMessage *fPrintSettings;
|
||||||
|
|||||||
Reference in New Issue
Block a user