Ticket #5626: screenshotEnhancement-5626.patch

File screenshotEnhancement-5626.patch, 3.3 KB (added by Shisui, 14 years ago)

Automatic filename basename selection and "save" as default button for Screenshot

  • src/apps/screenshot/ScreenshotWindow.cpp

     
    159159            BCardLayout* layout = dynamic_cast<BCardLayout*> (GetLayout());
    160160            if (layout)
    161161                layout->SetVisibleItem(1L);
     162
     163            fSaveScreenshot->MakeDefault(true);
     164
    162165            SetTitle(TR("Save screenshot"));
    163166            break;
    164167        }
     
    168171            _TakeScreenshot();
    169172            _UpdatePreviewPanel();
    170173            Show();
     174            _UpdateFilenameSelection();
    171175            break;
    172176       
    173177        case kImageOutputFormat:
    174178            message->FindInt32("be:type", &fImageFileType);
    175179            message->FindInt32("be:translator", &fTranslator);
    176180            fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
     181            _UpdateFilenameSelection();
    177182            break;
    178183       
    179184        case kLocationChanged:
     
    183188                fLastSelectedPath = static_cast<BMenuItem*> (source);
    184189
    185190            fNameControl->SetText(_FindValidFileName(fNameControl->Text()).String());
     191            _UpdateFilenameSelection();
    186192            break;
    187193        }
    188194       
     
    235241           
    236242            if (layout)
    237243                layout->SetVisibleItem(0L);
     244            SetDefaultButton(NULL);
    238245           
    239246            SetTitle(TR("Take Screenshot"));
    240247            fBackToSave->SetEnabled(true);
     
    280287        _TakeScreenshot();
    281288        _UpdatePreviewPanel();
    282289        layout->SetVisibleItem(1L);
    283     } else
     290        fSaveScreenshot->MakeDefault(true);
     291    } else {
    284292        layout->SetVisibleItem(0L);
     293        SetDefaultButton(NULL);
     294    }
    285295}
    286296
    287297
     
    392402    BBox* divider = new BBox(B_FANCY_BORDER, NULL);
    393403    divider->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
    394404
     405    fSaveScreenshot  = new BButton("",
     406        TR("Save"), new BMessage(kFinishScreenshot));
     407
    395408    BGridLayout* gridLayout = BGridLayoutBuilder(0.0, 5.0)
    396409        .Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
    397410        .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0)
     
    416429            .Add(new BButton("", TR("Options"), new BMessage(kShowOptions)))
    417430            .AddGlue()
    418431            .Add(new BButton("", TR("Cancel"), new BMessage(B_QUIT_REQUESTED)))
    419             .Add(new BButton("", TR("Save"), new BMessage(kFinishScreenshot)))
     432            .Add(fSaveScreenshot)
    420433            .End()
    421434        .SetInsets(10.0, 10.0, 10.0, 10.0)
    422435    );
     
    561574    if (layout)
    562575        layout->SetVisibleItem(1L);
    563576
     577    _UpdateFilenameSelection();
     578
    564579    SetTitle(TR("Save screenshot"));
    565580}
    566581
    567582
     583void
     584ScreenshotWindow::_UpdateFilenameSelection()
     585{
     586    fNameControl->MakeFocus(true);
     587    fNameControl->TextView()->Select(0,
     588        fNameControl->TextView()->TextLength() -
     589        fExtension.Length());
     590    fNameControl->TextView()->ScrollToSelection();
     591}
     592
     593
    568594BString
    569595ScreenshotWindow::_FindValidFileName(const char* name)
    570596{
  • src/apps/screenshot/ScreenshotWindow.h

     
    5656                                BString& label, int32 index, bool markItem);
    5757
    5858            void            _UpdatePreviewPanel();
     59            void            _UpdateFilenameSelection();
    5960            BString         _FindValidFileName(const char* name);
    6061            int32           _PathIndexInMenu(const BString& path) const;
    6162
     
    7677            BCheckBox*      fShowMouse;
    7778            BButton*        fBackToSave;
    7879            BButton*        fTakeScreenshot;
     80            BButton*        fSaveScreenshot;
    7981            BTextControl*   fNameControl;
    8082            BMenu*          fTranslatorMenu;
    8183            BMenu*          fOutputPathMenu;