Prevent the 'Settings...' button from opening multiple windows

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37585 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Wim van der Meer
2010-07-19 11:18:25 +00:00
parent 51b6847f5f
commit 7235f8680c
2 changed files with 66 additions and 21 deletions
+64 -20
View File
@@ -31,6 +31,7 @@
#include <Menu.h> #include <Menu.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <MessageFilter.h>
#include <Path.h> #include <Path.h>
#include <Roster.h> #include <Roster.h>
#include <String.h> #include <String.h>
@@ -43,6 +44,10 @@
#include "Utility.h" #include "Utility.h"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ScreenshotWindow"
enum { enum {
kActiveWindow, kActiveWindow,
kIncludeBorder, kIncludeBorder,
@@ -56,22 +61,47 @@ enum {
}; };
// #pragma mark - QuitMessageFilter
class QuitMessageFilter : public BMessageFilter {
public:
QuitMessageFilter(BWindow** window)
:
BMessageFilter((uint32)B_QUIT_REQUESTED),
fWindow(window)
{
}
virtual filter_result Filter(BMessage* message, BHandler** target)
{
*fWindow = NULL;
return B_DISPATCH_MESSAGE;
}
private:
BWindow** fWindow;
};
// #pragma mark - DirectoryRefFilter
class DirectoryRefFilter : public BRefFilter { class DirectoryRefFilter : public BRefFilter {
public: public:
virtual ~DirectoryRefFilter() virtual ~DirectoryRefFilter()
{ {
} }
virtual bool Filter(const entry_ref* ref, BNode* node, virtual bool Filter(const entry_ref* ref, BNode* node,
struct stat_beos* stat, const char* filetype) struct stat_beos* stat, const char* filetype)
{ {
return node->IsDirectory(); return node->IsDirectory();
} }
}; };
#undef B_TRANSLATE_CONTEXT // #pragma mark - ScreenshotWindow
#define B_TRANSLATE_CONTEXT "ScreenshotWindow"
ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent, ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent,
@@ -86,6 +116,7 @@ ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent,
fScreenshot(NULL), fScreenshot(NULL),
fOutputPathPanel(NULL), fOutputPathPanel(NULL),
fLastSelectedPath(NULL), fLastSelectedPath(NULL),
fSettingsWindow(NULL),
fDelay(0), fDelay(0),
fIncludeBorder(false), fIncludeBorder(false),
fIncludeCursor(false), fIncludeCursor(false),
@@ -262,6 +293,7 @@ ScreenshotWindow::MessageReceived(BMessage* message)
fNameControl->SetText(_FindValidFileName( fNameControl->SetText(_FindValidFileName(
fNameControl->Text()).String()); fNameControl->Text()).String());
_UpdateFilenameSelection(); _UpdateFilenameSelection();
_ShowSettings(false);
break; break;
case kLocationChanged: case kLocationChanged:
@@ -308,7 +340,7 @@ ScreenshotWindow::MessageReceived(BMessage* message)
break; break;
case kSettings: case kSettings:
_ShowSettings(); _ShowSettings(true);
break; break;
default: default:
@@ -327,9 +359,6 @@ ScreenshotWindow::Quit()
} }
// #pragma - private
void void
ScreenshotWindow::_NewScreenshot(bool silent, bool clipboard) ScreenshotWindow::_NewScreenshot(bool silent, bool clipboard)
{ {
@@ -555,8 +584,11 @@ ScreenshotWindow::_SaveScreenshot()
void void
ScreenshotWindow::_ShowSettings() ScreenshotWindow::_ShowSettings(bool activate)
{ {
if (!fSettingsWindow && !activate)
return;
// Find a translator // Find a translator
translator_id translator = 0; translator_id translator = 0;
BTranslatorRoster *roster = BTranslatorRoster::Default(); BTranslatorRoster *roster = BTranslatorRoster::Default();
@@ -568,7 +600,8 @@ ScreenshotWindow::_ShowSettings()
for (int32 x = 0; x < numTranslators; x++) { for (int32 x = 0; x < numTranslators; x++) {
const translation_format* formats = NULL; const translation_format* formats = NULL;
int32 numFormats; int32 numFormats;
if (roster->GetOutputFormats(translators[x], &formats, &numFormats) == B_OK) { if (roster->GetOutputFormats(translators[x], &formats,
&numFormats) == B_OK) {
for (int32 i = 0; i < numFormats; ++i) { for (int32 i = 0; i < numFormats; ++i) {
if (formats[i].type == static_cast<uint32>(fImageFileType)) { if (formats[i].type == static_cast<uint32>(fImageFileType)) {
translator = translators[x]; translator = translators[x];
@@ -584,7 +617,7 @@ ScreenshotWindow::_ShowSettings()
if (!foundTranslator) if (!foundTranslator)
return; return;
// Create a window with a configuration view // Create a window with a configuration view
BView *view; BView *view;
BRect rect(0, 0, 239, 239); BRect rect(0, 0, 239, 239);
@@ -594,12 +627,23 @@ ScreenshotWindow::_ShowSettings()
BAlert *alert = new BAlert(NULL, strerror(err), "OK"); BAlert *alert = new BAlert(NULL, strerror(err), "OK");
alert->Go(); alert->Go();
} else { } else {
BWindow* window = new BWindow(rect, "Translator Settings", if (fSettingsWindow) {
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, fSettingsWindow->RemoveChild(fSettingsWindow->ChildAt(0));
B_NOT_ZOOMABLE | B_NOT_RESIZABLE); float width, height;
window->AddChild(view); view->GetPreferredSize(&width, &height);
window->CenterOnScreen(); fSettingsWindow->ResizeTo(width, height);
window->Show(); fSettingsWindow->AddChild(view);
if (activate)
fSettingsWindow->Activate();
} else {
fSettingsWindow = new BWindow(rect, "Translator Settings",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_NOT_RESIZABLE);
fSettingsWindow->AddFilter(new QuitMessageFilter(&fSettingsWindow));
fSettingsWindow->AddChild(view);
fSettingsWindow->CenterOnScreen();
fSettingsWindow->Show();
}
} }
} }
+2 -1
View File
@@ -50,7 +50,7 @@ private:
void _UpdateFilenameSelection(); void _UpdateFilenameSelection();
void _SetupTranslatorMenu(); void _SetupTranslatorMenu();
status_t _SaveScreenshot(); status_t _SaveScreenshot();
void _ShowSettings(); void _ShowSettings(bool activate);
BString _FindValidFileName(const char* name); BString _FindValidFileName(const char* name);
BPath _GetDirectory(); BPath _GetDirectory();
void _ReadSettings(); void _ReadSettings();
@@ -69,6 +69,7 @@ private:
BBitmap* fScreenshot; BBitmap* fScreenshot;
BFilePanel* fOutputPathPanel; BFilePanel* fOutputPathPanel;
BMenuItem* fLastSelectedPath; BMenuItem* fLastSelectedPath;
BWindow* fSettingsWindow;
bigtime_t fDelay; bigtime_t fDelay;
bool fIncludeBorder; bool fIncludeBorder;