From 0adaff854a59d08e9d7d28d6498298b593489a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 26 Feb 2004 19:15:37 +0000 Subject: [PATCH] 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 --- src/apps/diskprobe/AttributeWindow.cpp | 11 +++++ src/apps/diskprobe/AttributeWindow.h | 1 + src/apps/diskprobe/FileWindow.cpp | 21 +++++++-- src/apps/diskprobe/FileWindow.h | 6 +++ src/apps/diskprobe/ProbeView.cpp | 65 ++++++++++++++++++++++---- src/apps/diskprobe/ProbeView.h | 2 + 6 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/apps/diskprobe/AttributeWindow.cpp b/src/apps/diskprobe/AttributeWindow.cpp index 436b8ce007..080acbef9c 100644 --- a/src/apps/diskprobe/AttributeWindow.cpp +++ b/src/apps/diskprobe/AttributeWindow.cpp @@ -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) { diff --git a/src/apps/diskprobe/AttributeWindow.h b/src/apps/diskprobe/AttributeWindow.h index 33668fb05a..c829ff4fc2 100644 --- a/src/apps/diskprobe/AttributeWindow.h +++ b/src/apps/diskprobe/AttributeWindow.h @@ -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: diff --git a/src/apps/diskprobe/FileWindow.cpp b/src/apps/diskprobe/FileWindow.cpp index 3b4dcb4296..c84783eae5 100644 --- a/src/apps/diskprobe/FileWindow.cpp +++ b/src/apps/diskprobe/FileWindow.cpp @@ -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(); } diff --git a/src/apps/diskprobe/FileWindow.h b/src/apps/diskprobe/FileWindow.h index 8d845ae365..0ff049243b 100644 --- a/src/apps/diskprobe/FileWindow.h +++ b/src/apps/diskprobe/FileWindow.h @@ -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 */ diff --git a/src/apps/diskprobe/ProbeView.cpp b/src/apps/diskprobe/ProbeView.cpp index 0e5ce63ab3..bec81a437d 100644 --- a/src/apps/diskprobe/ProbeView.cpp +++ b/src/apps/diskprobe/ProbeView.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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")) { diff --git a/src/apps/diskprobe/ProbeView.h b/src/apps/diskprobe/ProbeView.h index 3ba30f317c..4193524d8f 100644 --- a/src/apps/diskprobe/ProbeView.h +++ b/src/apps/diskprobe/ProbeView.h @@ -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;