Ticket #199: 199-1.patch

File 199-1.patch, 8.6 KB (added by Niels.Reedijk@…, 18 years ago)

GUI portion of the patch

  • src/apps/terminal/TermWindow.cpp

     
    2727#include "CodeConv.h"
    2828#include "ColorWindow.h"
    2929#include "MenuUtil.h"
     30#include "FindDlg.h"
    3031#include "PrefDlg.h"
    3132#include "PrefView.h"
    3233#include "PrefHandler.h"
     
    219220    fEditmenu->AddSeparatorItem ();
    220221    fEditmenu->AddItem (new BMenuItem ("Select All", new BMessage (B_SELECT_ALL), 'A'));
    221222    fEditmenu->AddItem (new BMenuItem ("Clear All", new BMessage (MENU_CLEAR_ALL), 'L'));
     223    fEditmenu->AddSeparatorItem ();
     224    fEditmenu->AddItem (new BMenuItem ("Find", new BMessage (MENU_FIND_STRING),'F'));
     225    fEditmenu->AddItem (new BMenuItem ("Find Again", new BMessage (MENU_FIND_AGAIN), ']'));
    222226
    223 /*
    224   // TODO: Implement Finding
    225   fEditmenu->AddSeparatorItem ();
    226   fEditmenu->AddItem (new BMenuItem ("Find", new BMessage (MENU_FIND_STRING),'F'));
    227   fEditmenu->AddItem (new BMenuItem ("Find Again", new BMessage (MENU_FIND_AGAIN), ']'));
    228 */
    229227    fMenubar->AddItem (fEditmenu);
    230228 
    231229    // Make Help Menu.
     
    303301            fPrefWindow = NULL;
    304302            break;
    305303        }
     304        case MENU_FIND_STRING: {
     305            if (!fFindPanel) {
     306                BRect r = Frame();
     307                r.left += 20;
     308                r.top += 20;
     309                r.right = r.left + 260;
     310                r.bottom = r.top + 220;
     311                fFindPanel = new FindDlg(r, this);
     312            }
     313            else
     314                fFindPanel->Activate();
     315            break;
     316        }
     317        case MSG_FIND_CLOSED: {
     318            fFindPanel = NULL;
     319            break;
     320        }
    306321        case MENU_FILE_QUIT: {
    307322            be_app->PostMessage(B_QUIT_REQUESTED);
    308323            break;
     
    523538    delete fTermParse;
    524539    delete fCodeConv;
    525540    if(fPrefWindow) fPrefWindow->PostMessage (B_QUIT_REQUESTED);
    526         be_app->PostMessage (B_QUIT_REQUESTED, be_app);
     541    if(fFindPanel) fFindPanel->PostMessage(B_QUIT_REQUESTED);
     542   
     543    be_app->PostMessage (B_QUIT_REQUESTED, be_app);
    527544    BWindow::Quit ();
    528545}
    529546
  • src/apps/terminal/Changelog

     
    1313Terminal window supports scrolling
    1414
    1515TODO:
    16 Make a Jamfile
    1716Make Find work
    1817Fix titling (-t works already, its the Terminal 1, 2, 3, etc...)
    1918Fix the Colour menu
    2019Move Fonts and font sizes to the "Right Place"
    2120Kill the Preferences Panel
    22 Move to .rdef source resources
  • src/apps/terminal/FindDlg.h

     
    3636#include "CurPos.h"
    3737
    3838const ulong MSG_FIND_START = 'msac';
     39const ulong MSG_FIND_CLOSED = 'mfcl';
    3940
    4041class BRect;
    4142class BBitmap;
    4243class BMessage;
    4344class TermWindow;
     45class BTextControl;
     46class BRadioButton;
     47class BCheckBox;
    4448
    4549class FindDlg : public BWindow
    4650{
    4751public:
    48   FindDlg(BRect frame, TermWindow *win);
    49   ~FindDlg ();
     52    FindDlg(BRect frame, TermWindow *win);
     53    ~FindDlg ();
    5054
    51   void      Find (CurPos *start, CurPos *end);
     55    void        Find (CurPos *start, CurPos *end);
    5256
    53  private:
    54   virtual void  Quit (void);
    55  
    56   BString   *fFindString;
    57   TermWindow    *fWindow;
     57private:
     58    virtual void    Quit (void);
    5859
     60    BView           *fFindView;
     61    BTextControl    *fFindLabel;
     62    BRadioButton    *fTextRadio;
     63    BRadioButton    *fSelectionRadio;
     64    BBox            *fSeparator;
     65    BCheckBox       *fForwardSearchBox;
     66    BCheckBox       *fMatchCaseBox;
     67    BCheckBox       *fMatchWordBox;
     68    BCheckBox       *fRegexpBox;
     69    BButton         *fFindButton;
     70
     71    BString *fFindString;
     72    TermWindow  *fWindow;
    5973};
    6074
    6175
  • src/apps/terminal/Jamfile

     
    77    AppearPrefView.cpp
    88    CodeConv.cpp
    99    CurPos.cpp
     10    FindDlg.cpp
    1011    MenuUtil.cpp
    1112    Terminal.cpp
    1213    PrefDlg.cpp
  • src/apps/terminal/FindDlg.cpp

     
    3131#include <Window.h>
    3232#include <Rect.h>
    3333#include <TextControl.h>
     34#include <Box.h>
     35#include <CheckBox.h>
    3436#include <Button.h>
     37#include <RadioButton.h>
    3538#include <Message.h>
    3639#include <stdio.h>
    3740#include <File.h>
    3841#include <String.h>
    3942
     43#include "TermWindow.h"
    4044#include "FindDlg.h"
    4145#include "TermApp.h"
    4246#include "MenuUtil.h"
     
    5155//  Constructer
    5256//////////////////////////////////////////////////////////////////////////////
    5357FindDlg::FindDlg (BRect frame, TermWindow *win)
    54   : BWindow(frame, "Find",
    55         B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
     58    : BWindow(frame, "Find",
     59        B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
    5660{
    57   PrefHandler title;
    58   LoadLocaleFile (&title);
     61    fWindow = win;
     62    SetTitle("Find");
    5963
    60   fWindow = win;
    61   this->SetTitle (title.getString ("Find"));
     64    AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
     65    AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
    6266
    63   AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
    64   AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
     67    //Build up view
     68    fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
     69    fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     70    AddChild(fFindView);
    6571
    66   BRect r (10, 10, 120, 20);
    67  
    68   BTextControl *text_ctl = new BTextControl (r, "text", NULL, NULL, NULL);
    69   AddChild (text_ctl);
     72    font_height height;
     73    fFindView->GetFontHeight(&height);
     74    float lineHeight = height.ascent + height.descent + height.leading;
    7075
    71   r.Set (100, 40, 130, 60);
    72   BButton *button = new BButton (r, NULL, "Find", new BMessage (MSG_FIND_START));
    73   AddChild (button);
    74  
     76    //These labels are from the bottom up
     77    float buttonsTop = frame.Height() - 19 - lineHeight;
     78    float regexpBottom = buttonsTop - 4;
     79    float regexpTop = regexpBottom - lineHeight - 8;
     80    float matchwordBottom = regexpTop - 4;
     81    float matchwordTop = matchwordBottom - lineHeight - 8;
     82    float matchcaseBottom = matchwordTop - 4;
     83    float matchcaseTop = matchcaseBottom - lineHeight - 8;
     84    float forwardsearchBottom = matchcaseTop - 4;
     85    float forwardsearchTop = forwardsearchBottom - lineHeight - 10;
     86
     87    //These things are calculated from the top
     88    float textRadioTop = 12;
     89    float textRadioBottom = textRadioTop + 2 + lineHeight + 2 + 1;
     90    float textRadioRight = fFindView->StringWidth("Use Text: ") + 30;
     91    float selectionRadioTop = textRadioBottom + 4;
     92    float selectionRadioBottom = selectionRadioTop + lineHeight + 8;
     93
     94    //Divider
     95    float dividerHeight = (selectionRadioBottom + forwardsearchTop) / 2;
     96   
     97    //Button Coordinates
     98    float searchbuttonLeft = (frame.Width() - fFindView->StringWidth("Find") - 60) / 2;
     99    float searchbuttonRight = searchbuttonLeft + fFindView->StringWidth("Find") + 60;
     100   
     101    //Build the Views
     102    fTextRadio = new BRadioButton(BRect(14, textRadioTop, textRadioRight, textRadioBottom),
     103        "fTextRadio", "Use Text: ", NULL);
     104    fFindView->AddChild(fTextRadio);
     105   
     106    fFindLabel = new BTextControl(BRect(textRadioRight + 4, textRadioTop, frame.Width() - 14, textRadioBottom),
     107        "fFindLabel", "", "", NULL);
     108    fFindLabel->SetDivider(0);
     109    fFindView->AddChild(fFindLabel);
     110
     111    fTextRadio->SetValue(1);    //enable first option
     112   
     113    fSelectionRadio = new BRadioButton(BRect(14, selectionRadioTop, frame.Width() - 14, selectionRadioBottom),
     114        "fSelectionRadio", "Use Selection", NULL);
     115    fFindView->AddChild(fSelectionRadio);
     116
     117    fSeparator = new BBox(BRect(6, dividerHeight, frame.Width() - 6, dividerHeight + 1));
     118    fFindView->AddChild(fSeparator);
     119   
     120    fForwardSearchBox = new BCheckBox(BRect(14, forwardsearchTop, frame.Width() - 14, forwardsearchBottom),
     121        "fForwardSearchBox", "Search Forward", NULL);
     122    fFindView->AddChild(fForwardSearchBox);
     123   
     124    fMatchCaseBox = new BCheckBox(BRect(14, matchcaseTop, frame.Width() - 14, matchcaseBottom),
     125        "fMatchCaseBox", "Match Case", NULL);
     126    fFindView->AddChild(fMatchCaseBox);
     127   
     128    fMatchWordBox = new BCheckBox(BRect(14, matchwordTop, frame.Width() - 14, matchwordBottom),
     129        "fMatchWordBox", "Match Word", NULL);
     130    fFindView->AddChild(fMatchWordBox);
     131   
     132    fRegexpBox = new BCheckBox(BRect(14, regexpTop, frame.Width() - 14, regexpBottom),
     133        "fRegexpBox", "Use Regular Expression", NULL);
     134    fFindView->AddChild(fRegexpBox);
     135   
     136    fFindButton = new BButton(BRect(searchbuttonLeft, buttonsTop, searchbuttonRight, frame.Height() - 14),
     137        "fFindButton", "Find", NULL);
     138    fFindButton->MakeDefault(true);
     139    fFindView->AddChild(fFindButton);
     140   
     141    Show();
    75142}
    76143
    77144FindDlg::~FindDlg (void)
     
    82149void
    83150FindDlg::Quit (void)
    84151{
    85   BWindow::Quit ();
     152    fWindow->PostMessage(MSG_FIND_CLOSED);
     153    BWindow::Quit ();
    86154}
    87155