Ask confirmation in case the application would try to overwrite an existing file.
This is fixing ticket #3815. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "PNGDump.h"
|
#include "PNGDump.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
@@ -192,7 +193,8 @@ ScreenshotWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case kFinishScreenshot:
|
case kFinishScreenshot:
|
||||||
_WriteSettings();
|
_WriteSettings();
|
||||||
_SaveScreenshot();
|
if (_SaveScreenshot() != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
// fall through
|
// fall through
|
||||||
case B_QUIT_REQUESTED:
|
case B_QUIT_REQUESTED:
|
||||||
@@ -682,23 +684,41 @@ ScreenshotWindow::_GetActiveWindowFrame(BRect* frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
status_t
|
||||||
ScreenshotWindow::_SaveScreenshot()
|
ScreenshotWindow::_SaveScreenshot()
|
||||||
{
|
{
|
||||||
if (!fScreenshot || !fLastSelectedPath)
|
if (!fScreenshot || !fLastSelectedPath)
|
||||||
return;
|
return B_ERROR;
|
||||||
|
|
||||||
const char* path;
|
const char* _path;
|
||||||
BMessage* message = fLastSelectedPath->Message();
|
BMessage* message = fLastSelectedPath->Message();
|
||||||
if (!message || message->FindString("path", &path) != B_OK)
|
if (!message || message->FindString("path", &_path) != B_OK)
|
||||||
return;
|
return B_ERROR;
|
||||||
|
|
||||||
BDirectory dir(path);
|
BEntry entry;
|
||||||
BFile file(&dir, fNameControl->Text(), B_CREATE_FILE |
|
BPath path;
|
||||||
B_ERASE_FILE | B_WRITE_ONLY);
|
|
||||||
if (file.InitCheck() != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
path = _path;
|
||||||
|
path.Append(fNameControl->Text());
|
||||||
|
entry.SetTo(path.Path());
|
||||||
|
|
||||||
|
if (entry.Exists()) {
|
||||||
|
BAlert *myAlert = new BAlert("overwrite", "This file already exists.\n"
|
||||||
|
"Are you sure would you like to overwrite it?",
|
||||||
|
"Cancel", "Overwrite", NULL,
|
||||||
|
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT);
|
||||||
|
|
||||||
|
myAlert->SetShortcut(0, B_ESCAPE);
|
||||||
|
int32 button_index = myAlert->Go();
|
||||||
|
if (button_index == 0) {
|
||||||
|
return B_CANCELED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BFile file(&entry, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
|
||||||
|
if (file.InitCheck() != B_OK) {
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
BBitmapStream bitmapStream(fScreenshot);
|
BBitmapStream bitmapStream(fScreenshot);
|
||||||
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
roster->Translate(&bitmapStream, NULL, NULL, &file, fImageFileType,
|
roster->Translate(&bitmapStream, NULL, NULL, &file, fImageFileType,
|
||||||
@@ -707,12 +727,12 @@ ScreenshotWindow::_SaveScreenshot()
|
|||||||
|
|
||||||
BNodeInfo nodeInfo(&file);
|
BNodeInfo nodeInfo(&file);
|
||||||
if (nodeInfo.InitCheck() != B_OK)
|
if (nodeInfo.InitCheck() != B_OK)
|
||||||
return;
|
return B_ERROR;
|
||||||
|
|
||||||
int32 numFormats;
|
int32 numFormats;
|
||||||
const translation_format* formats = NULL;
|
const translation_format* formats = NULL;
|
||||||
if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) != B_OK)
|
if (roster->GetOutputFormats(fTranslator, &formats, &numFormats) != B_OK)
|
||||||
return;
|
return B_OK;
|
||||||
|
|
||||||
for (int32 i = 0; i < numFormats; ++i) {
|
for (int32 i = 0; i < numFormats; ++i) {
|
||||||
if (formats[i].type == uint32(fImageFileType)) {
|
if (formats[i].type == uint32(fImageFileType)) {
|
||||||
@@ -720,6 +740,7 @@ ScreenshotWindow::_SaveScreenshot()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ private:
|
|||||||
void _TakeScreenshot();
|
void _TakeScreenshot();
|
||||||
status_t _GetActiveWindowFrame(BRect* frame);
|
status_t _GetActiveWindowFrame(BRect* frame);
|
||||||
|
|
||||||
void _SaveScreenshot();
|
status_t _SaveScreenshot();
|
||||||
void _SaveScreenshotSilent() const;
|
void _SaveScreenshotSilent() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user