Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now shows warning before closing unsaved note #25

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions source/NoteWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void NoteWindow :: InitWindow(){
yellow = {254,254,92},
color;
rgb_color colors[] = {black, red, green, blue, yellow};
fQuitAfterSave = false;

//Initialize the fSaveMessage
fSaveMessage = NULL;
Expand Down Expand Up @@ -520,6 +521,10 @@ status_t NoteWindow :: Save(BMessage *message) {
delete fSaveMessage;
fSaveMessage = new BMessage(*message);
}

fIsDirty = false;
if (fQuitAfterSave)
QuitRequested();

return err;
}
Expand Down Expand Up @@ -749,10 +754,10 @@ void NoteWindow :: MessageReceived(BMessage* message) {
}
break;

// Close the application
//Close the application
case QUIT_APPL: {

Quit();
QuitRequested();

}
break;
Expand Down Expand Up @@ -819,6 +824,8 @@ void NoteWindow :: MessageReceived(BMessage* message) {
fUndoItem -> SetEnabled(true);
fRedoFlag = false;
}

fIsDirty = true;
}
break;

Expand All @@ -829,6 +836,7 @@ void NoteWindow :: MessageReceived(BMessage* message) {
fNoteText -> GetFontAndColor(&font, &sameProperties, &sameColor);
font.SetSize(fontSize);
fNoteText -> SetFontAndColor (&font, B_FONT_SIZE);
fIsDirty = true;
}

}
Expand All @@ -847,6 +855,7 @@ void NoteWindow :: MessageReceived(BMessage* message) {
// Setting a different color for the font
fNoteText -> GetFontAndColor(&font, &sameProperties);
fNoteText -> SetFontAndColor(&font,0,&colore);
fIsDirty = true;

}
break;
Expand All @@ -862,6 +871,7 @@ void NoteWindow :: MessageReceived(BMessage* message) {
fCurrentFont = static_cast <BMenuItem*>(ptr);
fontFamily = fCurrentFont -> Label();
SetFontStyle (fontFamily, fontStyle);
fIsDirty = true;

}
break;
Expand All @@ -884,6 +894,7 @@ void NoteWindow :: MessageReceived(BMessage* message) {
fontFamily = fCurrentFont -> Label();
}
SetFontStyle (fontFamily, fontStyle);
fIsDirty = true;

}
break;
Expand Down Expand Up @@ -1035,6 +1046,7 @@ void NoteWindow :: MessageReceived(BMessage* message) {
message->FindInt8("blue", &c);
colore.blue = (uint8)c;
fNoteView -> SetBackgroundColor(colore);
fIsDirty = true;

}
break;
Expand Down Expand Up @@ -1245,9 +1257,31 @@ void NoteWindow :: MessageReceived(BMessage* message) {

// Closing the window
bool NoteWindow :: QuitRequested(){

Quit();
return(true);

//Show an alert if the note has not been saved
if (fIsDirty) {
BAlert* saveAlert = new BAlert("Close and save dialog",
"Save changes before closing?","Cancel",
"Don't save", "Save",
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
saveAlert->SetShortcut(0, B_ESCAPE);
int32 button_index = saveAlert->Go();
switch (button_index) {
case 0:
break;
case 1:
Quit();
break;
case 2:
fQuitAfterSave = true;
if (!fSaveMessage)
fSavePanel -> Show();
else
Save(fSaveMessage);
break;
}
} else
Quit();
}

// Function that quits the window
Expand Down
6 changes: 6 additions & 0 deletions source/NoteWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class NoteWindow : public BWindow {
bool fCanUndo;
bool fCanRedo;
bool fRedoFlag;

// Saved flag
bool fIsDirty;

// Quit after successful save flag
bool fQuitAfterSave;

// Data structure
AlarmData fData;
Expand Down