Now checks if there are any outstanding changes in the editor when the

window is closed.
Also, it now reports errors from the save operation if there were any.
Enabled the "Print" and "Page Setup" menu items.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6767 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-02-26 19:15:37 +00:00
parent 79681755a6
commit 0adaff854a
6 changed files with 92 additions and 14 deletions

View File

@ -258,6 +258,17 @@ AttributeWindow::MessageReceived(BMessage *message)
}
bool
AttributeWindow::QuitRequested()
{
bool quit = fProbeView->QuitRequested();
if (!quit)
return false;
return ProbeWindow::QuitRequested();
}
bool
AttributeWindow::Contains(const entry_ref &ref, const char *attribute)
{

View File

@ -18,6 +18,7 @@ class AttributeWindow : public ProbeWindow {
virtual ~AttributeWindow();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
virtual bool Contains(const entry_ref &ref, const char *attribute);
private:

View File

@ -65,13 +65,24 @@ FileWindow::FileWindow(BRect rect, entry_ref *ref, const BMessage *settings)
BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1;
ProbeView *probeView = new ProbeView(rect, ref, NULL, settings);
AddChild(probeView);
fProbeView = new ProbeView(rect, ref, NULL, settings);
AddChild(fProbeView);
probeView->AddSaveMenuItems(menu, 4);
probeView->AddPrintMenuItems(menu, menu->CountItems() - 4);
fProbeView->AddSaveMenuItems(menu, 4);
fProbeView->AddPrintMenuItems(menu, menu->CountItems() - 4);
probeView->UpdateSizeLimits();
fProbeView->UpdateSizeLimits();
}
bool
FileWindow::QuitRequested()
{
bool quit = fProbeView->QuitRequested();
if (!quit)
return false;
return ProbeWindow::QuitRequested();
}

View File

@ -8,12 +8,18 @@
#include "ProbeWindow.h"
class ProbeView;
class FileWindow : public ProbeWindow {
public:
FileWindow(BRect rect, entry_ref *ref, const BMessage *settings = NULL);
virtual bool QuitRequested();
virtual bool Contains(const entry_ref &ref, const char *attribute);
private:
ProbeView *fProbeView;
};
#endif /* FILE_WINDOW_H */

View File

@ -24,6 +24,7 @@
#include <MenuBar.h>
#include <MenuItem.h>
#include <ScrollView.h>
#include <Alert.h>
#include <String.h>
#include <Entry.h>
#include <Path.h>
@ -46,6 +47,8 @@ static const uint32 kMsgSliderUpdate = 'slup';
static const uint32 kMsgPositionUpdate = 'poup';
static const uint32 kMsgLastPosition = 'lpos';
static const uint32 kMsgFontSize = 'fnts';
static const uint32 kMsgPrint = 'prnt';
static const uint32 kMsgPageSetup = 'pgsp';
class IconView : public BView {
@ -989,12 +992,12 @@ void
ProbeView::AddPrintMenuItems(BMenu *menu, int32 index)
{
BMenuItem *item;
menu->AddItem(item = new BMenuItem("Page Setup" B_UTF8_ELLIPSIS, NULL), index++);
menu->AddItem(item = new BMenuItem("Page Setup" B_UTF8_ELLIPSIS,
new BMessage(kMsgPageSetup)), index++);
item->SetTarget(this);
item->SetEnabled(false);
menu->AddItem(item = new BMenuItem("Print" B_UTF8_ELLIPSIS, NULL, 'P', B_COMMAND_KEY), index++);
menu->AddItem(item = new BMenuItem("Print" B_UTF8_ELLIPSIS,
new BMessage(kMsgPrint), 'P', B_COMMAND_KEY), index++);
item->SetTarget(this);
item->SetEnabled(false);
}
@ -1237,16 +1240,52 @@ ProbeView::CheckClipboard()
}
void
status_t
ProbeView::Save()
{
status_t status = fEditor.Save();
char buffer[1024];
snprintf(buffer, sizeof(buffer),
"Writing to the file failed:\n"
"%s\n\n"
"All changes will be lost when you quit.",
strerror(status));
(new BAlert("DiskProbe request",
buffer, "Ok", NULL, NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
return status;
}
bool
ProbeView::QuitRequested()
{
if (!fEditor.IsModified())
return true;
int32 chosen = (new BAlert("DiskProbe request",
"Save changes before closing?", "Don't Save", "Cancel", "Save",
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
if (chosen == 0)
return true;
if (chosen == 1)
return false;
return Save() == B_OK;
}
void
ProbeView::MessageReceived(BMessage *message)
{
switch (message->what) {
case B_SAVE_REQUESTED:
{
status_t status = fEditor.Save();
printf("save returned: %s\n", strerror(status));
Save();
break;
}
case B_OBSERVER_NOTICE_CHANGE: {
int32 what;
@ -1302,6 +1341,14 @@ ProbeView::MessageReceived(BMessage *message)
break;
}
case kMsgPrint:
puts("print...");
break;
case kMsgPageSetup:
puts("page setup...");
break;
case B_NODE_MONITOR:
{
switch (message->FindInt32("opcode")) {

View File

@ -37,6 +37,7 @@ class ProbeView : public BView {
void AddPrintMenuItems(BMenu *menu, int32 index);
void UpdateSizeLimits();
bool QuitRequested();
DataEditor &Editor() { return fEditor; }
@ -44,6 +45,7 @@ class ProbeView : public BView {
void UpdateAttributesMenu(BMenu *menu);
void UpdateSelectionMenuItems(int64 start, int64 end);
void CheckClipboard();
status_t Save();
DataEditor fEditor;
UpdateLooper *fUpdateLooper;