Patch by Shisui: Automatic filename basename selection and "Save" as default

button for Screenshot. Fixes #5626. Thanks a lot!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36208 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-04-13 11:25:15 +00:00
parent 5dcec7802a
commit 0d84b31334
2 changed files with 30 additions and 2 deletions
+28 -2
View File
@@ -159,6 +159,9 @@ ScreenshotWindow::MessageReceived(BMessage* message)
BCardLayout* layout = dynamic_cast<BCardLayout*> (GetLayout()); BCardLayout* layout = dynamic_cast<BCardLayout*> (GetLayout());
if (layout) if (layout)
layout->SetVisibleItem(1L); layout->SetVisibleItem(1L);
fSaveScreenshot->MakeDefault(true);
SetTitle(TR("Save screenshot")); SetTitle(TR("Save screenshot"));
break; break;
} }
@@ -168,12 +171,14 @@ ScreenshotWindow::MessageReceived(BMessage* message)
_TakeScreenshot(); _TakeScreenshot();
_UpdatePreviewPanel(); _UpdatePreviewPanel();
Show(); Show();
_UpdateFilenameSelection();
break; break;
case kImageOutputFormat: case kImageOutputFormat:
message->FindInt32("be:type", &fImageFileType); message->FindInt32("be:type", &fImageFileType);
message->FindInt32("be:translator", &fTranslator); message->FindInt32("be:translator", &fTranslator);
fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
_UpdateFilenameSelection();
break; break;
case kLocationChanged: case kLocationChanged:
@@ -183,6 +188,7 @@ ScreenshotWindow::MessageReceived(BMessage* message)
fLastSelectedPath = static_cast<BMenuItem*> (source); fLastSelectedPath = static_cast<BMenuItem*> (source);
fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String()); fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
_UpdateFilenameSelection();
break; break;
} }
@@ -235,6 +241,7 @@ ScreenshotWindow::MessageReceived(BMessage* message)
if (layout) if (layout)
layout->SetVisibleItem(0L); layout->SetVisibleItem(0L);
SetDefaultButton(NULL);
SetTitle(TR("Take Screenshot")); SetTitle(TR("Take Screenshot"));
fBackToSave->SetEnabled(true); fBackToSave->SetEnabled(true);
@@ -280,8 +287,11 @@ ScreenshotWindow::_InitWindow()
_TakeScreenshot(); _TakeScreenshot();
_UpdatePreviewPanel(); _UpdatePreviewPanel();
layout->SetVisibleItem(1L); layout->SetVisibleItem(1L);
} else fSaveScreenshot->MakeDefault(true);
} else {
layout->SetVisibleItem(0L); layout->SetVisibleItem(0L);
SetDefaultButton(NULL);
}
} }
@@ -392,6 +402,9 @@ ScreenshotWindow::_SetupSecondLayoutItem(BCardLayout* layout)
BBox* divider = new BBox(B_FANCY_BORDER, NULL); BBox* divider = new BBox(B_FANCY_BORDER, NULL);
divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
fSaveScreenshot = new BButton("",
TR("Save"), new BMessage(kFinishScreenshot));
BGridLayout* gridLayout = BGridLayoutBuilder(0.0, 5.0) BGridLayout* gridLayout = BGridLayoutBuilder(0.0, 5.0)
.Add(fNameControl->CreateLabelLayoutItem(), 0, 0) .Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
.Add(fNameControl->CreateTextViewLayoutItem(), 1, 0) .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0)
@@ -416,7 +429,7 @@ ScreenshotWindow::_SetupSecondLayoutItem(BCardLayout* layout)
.Add(new BButton("", TR("Options"), new BMessage(kShowOptions))) .Add(new BButton("", TR("Options"), new BMessage(kShowOptions)))
.AddGlue() .AddGlue()
.Add(new BButton("", TR("Cancel"), new BMessage(B_QUIT_REQUESTED))) .Add(new BButton("", TR("Cancel"), new BMessage(B_QUIT_REQUESTED)))
.Add(new BButton("", TR("Save"), new BMessage(kFinishScreenshot))) .Add(fSaveScreenshot)
.End() .End()
.SetInsets(10.0, 10.0, 10.0, 10.0) .SetInsets(10.0, 10.0, 10.0, 10.0)
); );
@@ -561,10 +574,23 @@ ScreenshotWindow::_UpdatePreviewPanel()
if (layout) if (layout)
layout->SetVisibleItem(1L); layout->SetVisibleItem(1L);
_UpdateFilenameSelection();
SetTitle(TR("Save screenshot")); SetTitle(TR("Save screenshot"));
} }
void
ScreenshotWindow::_UpdateFilenameSelection()
{
fNameControl->MakeFocus(true);
fNameControl->TextView()->Select(0,
fNameControl->TextView()->TextLength() -
fExtension.Length());
fNameControl->TextView()->ScrollToSelection();
}
BString BString
ScreenshotWindow::_FindValidFileName(const char* name) ScreenshotWindow::_FindValidFileName(const char* name)
{ {
+2
View File
@@ -56,6 +56,7 @@ private:
BString& label, int32 index, bool markItem); BString& label, int32 index, bool markItem);
void _UpdatePreviewPanel(); void _UpdatePreviewPanel();
void _UpdateFilenameSelection();
BString _FindValidFileName(const char* name); BString _FindValidFileName(const char* name);
int32 _PathIndexInMenu(const BString& path) const; int32 _PathIndexInMenu(const BString& path) const;
@@ -76,6 +77,7 @@ private:
BCheckBox* fShowMouse; BCheckBox* fShowMouse;
BButton* fBackToSave; BButton* fBackToSave;
BButton* fTakeScreenshot; BButton* fTakeScreenshot;
BButton* fSaveScreenshot;
BTextControl* fNameControl; BTextControl* fNameControl;
BMenu* fTranslatorMenu; BMenu* fTranslatorMenu;
BMenu* fOutputPathMenu; BMenu* fOutputPathMenu;