This source file includes following definitions.
- SetValues
- Draw
- OnKeyDown
- ShowHistory
- MessageReceived
- Enable
- Action_Enter
1 #include <stdio.h>
2 #include "BF_GUI_CmdLine.h"
3 #include "BF_Dict.h"
4 #include "BF_Roster.h"
5 #include "BF_GUI_Func.h"
6 #include "BF_GUI_WinMain.h"
7
8 BF_GUI_CmdLine *poCmdLine = NULL;
9
10 BF_GUI_CmdLine::BF_GUI_CmdLine(const BRect & o_Rect)
11 :BView(o_Rect,"cmd_line",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM,B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_FRAME_EVENTS)
12 {
13 iDisableCount = 0;
14
15 SetViewColor(B_TRANSPARENT_COLOR);
16 SetFont(&poSysSetup->oFontCMDLine.oFont);
17
18 poEdit = new BF_GUI_ViewEdit(Bounds(),"cmd_edit","",B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM,B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_FRAME_EVENTS);
19 poEdit->bParentCall = false;
20 poEdit->oColBack = SYS_COLOR(BF_COLOR_CMDLINE_BACK);
21 poEdit->oColSel = SYS_COLOR(BF_COLOR_CMDLINE_TEXT);
22 poEdit->Enable(false);
23 poEdit->bAlwaysCursor = true;
24 poEdit->bCursorActive = true;
25 poEdit->bSelected = false;
26 poEdit->bSysKeysHandle = false;
27 poEdit->SetSetupFont(&poSysSetup->oFontCMDLine);
28 AddChild(poEdit);
29
30 poCmdLine = this;
31 SetValues("","");
32
33 }
34
35 void
36 BF_GUI_CmdLine::SetValues(const char *pc_Path,const char *pc_Cmd,bool b_Redraw)
37 {
38 if(pc_Path){
39 sPath = pc_Path;
40 if(poSysSetup->MainStyle() & BF_SETUP_CMDLINE_SHOWPATH) sVisPath = sPath; else sVisPath="";
41 sVisPath<<">";
42 if(pc_Cmd) sCmd = pc_Cmd;
43
44
45 fWidth = poSysSetup->oFontCMDLine.oFont.StringWidth(sVisPath.String())+2;
46 BRect oRect(Bounds());
47 oRect.left = fWidth;
48 poEdit->ResizeTo(oRect.Width(),oRect.Height());
49 poEdit->MoveTo(oRect.left,0);
50
51 if(b_Redraw) Invalidate(Bounds());
52 }
53 if(pc_Cmd){
54 poEdit->SetText(pc_Cmd,true);
55 }
56 }
57 void
58 BF_GUI_CmdLine::Draw(BRect o_Rect)
59 {
60 BRect oRect;
61
62
63
64 oRect = Bounds();
65 oRect.right = fWidth-1;
66 SetHighColor(SYS_COLOR(BF_COLOR_CMDLINE_BACK));
67 FillRect(oRect);
68
69 SetHighColor(SYS_COLOR(BF_COLOR_CMDLINE_TEXT));
70 SetLowColor(SYS_COLOR(BF_COLOR_CMDLINE_BACK));
71 MovePenTo(0,oRect.Height()-poSysSetup->oFontCMDLine.fDescent);
72 DrawString(sVisPath.String());
73
74 }
75
76
77 bool
78 BF_GUI_CmdLine::OnKeyDown(const char *bytes, int32 numBytes)
79 {
80 if(numBytes==1 && bytes[0]==B_ENTER){
81 if(poEdit->sValue=="") return false;
82 Action_Enter();
83 return true;
84 }else
85 if(numBytes==1 && bytes[0]==B_ESCAPE){
86 if(poEdit->sValue=="") return false;
87 poEdit->SetText("");
88 return true;
89 }else
90 if(numBytes==1 && bytes[0]==B_UP_ARROW){
91 uint32 iKeysModifiers = modifiers();
92 if(iKeysModifiers & B_OPTION_KEY){
93 if(lsCommand.CountItems()==0) return true;
94 BL_String *ps = (BL_String*)lsCommand.ItemAt(lsCommand.CountItems()-1);
95 if(!ps) return true;
96 poEdit->SetText(ps->String(),true);
97 return true;
98 }
99 }else
100 if(numBytes==1 && bytes[0]==B_DOWN_ARROW){
101 uint32 iKeysModifiers = modifiers();
102 if(iKeysModifiers & B_OPTION_KEY){
103 ShowHistory();
104 return true;
105 }
106 }else
107 {}
108
109 return poEdit->OnKeyDown(bytes,numBytes);
110 }
111
112 #define DLG_TITLE "Commands"
113
114 void
115 BF_GUI_CmdLine::ShowHistory()
116 {
117 if(lsCommand.CountItems()==0){
118 BF_Dialog_Alert_Sep(BF_DictAt(BF_DICT_WARNING),BF_DictAt(BF_DICT_PATH_EMPTY),NULL,poWin->CurrentFocus());
119 return;
120 }
121
122 BL_List *ploMenu = new BL_List();
123 BF_GUI_ViewMenu_Item *po=NULL;
124
125
126 BF_GUI_Func_PanelsEnable(false);
127
128
129 BL_String *ps=NULL;
130 for(int iItem=0;iItem<lsCommand.CountItems();iItem++){
131 ps = (BL_String*)lsCommand.ItemAt(iItem);
132 po = new BF_GUI_ViewMenu_Item(ps->String(),ps->String());
133 ploMenu->AddItem(po);
134 }
135
136
137 BMessage oMessage(BF_MSG_CMDLINE_HISTORY_SELECTED);
138 oMessage.AddPointer("bf_focus",(void*)this);
139 oMessage.AddPointer("bf_panel_focus",(void*)poWin->CurrentFocus());
140
141
142
143 float fMaxWidth=0;
144 {
145 BF_GUI_ViewMenu_Item *po;
146 float f;
147 for(int i=0;i<ploMenu->CountItems();i++){
148 po = (BF_GUI_ViewMenu_Item*)ploMenu->ItemAt(i);
149 ASSERT(po);
150 f = poSysSetup->oFontToolView.oFont.StringWidth(po->sTitle.String());
151 if(f>fMaxWidth) fMaxWidth = f;
152 }
153 }
154
155 {
156 float fTitleWidth = poSysSetup->oFontToolView.oFont.StringWidth(DLG_TITLE)+40;
157 if(fTitleWidth>fMaxWidth) fMaxWidth = fTitleWidth;
158 }
159
160 BRect oDlgRect(0,0,300,0);
161
162 BF_GUI_Dialog *poDialog = new BF_GUI_Dialog(oDlgRect,DLG_TITLE,"dialog",oMessage,
163 BG_GUI_DIALOG_WINRESIZE_RESIZE_ALL,true);
164
165 float fHeight = poSysSetup->oFontToolView.fHeight;
166
167 BRect oMenuRect(0,0,0,0);
168 poDialog->LocalBounds(oMenuRect);
169 oMenuRect.right = oMenuRect.left + fMaxWidth;
170 oMenuRect.bottom = oMenuRect.top + 5 + fHeight*ploMenu->CountItems();
171
172
173 BView* poMenu = new BF_GUI_DlgView_VMenu(oMenuRect,"menu", B_FOLLOW_ALL,ploMenu,0);
174
175 poDialog->AddChild(poMenu);
176 poDialog->SetSizeBy(oMenuRect.Width(),oMenuRect.Height());
177 poDialog->MoveToCenter(poWinView);
178 BF_GUI_Func_AddChildToMainView(poDialog);
179
180 return;
181 }
182
183 #undef DLG_TITLE
184
185 void
186 BF_GUI_CmdLine::MessageReceived(BMessage* po_Message)
187 {
188 switch(po_Message->what){
189 case BF_MSG_CMDLINE_HISTORY_SELECTED:{
190 BView *poView=NULL;
191 ASSERT(B_OK==po_Message->FindPointer("bf_panel_focus",(void**)&poView) && poView);
192
193 BF_GUI_Func_PanelsEnable(true);
194 poView->MakeFocus();
195
196 const char *pcCommand=NULL;
197 if(B_OK!=po_Message->FindString("menu_code",&pcCommand) || !pcCommand) return;
198
199 poEdit->SetText(pcCommand,true);
200
201
202 break;}
203 case BF_MSG_SETUP_UPDATED:
204
205 if(!(poSysSetup->MainStyle() & BF_SETUP_CMDLINE_SHOWPATH)) sVisPath = ">";
206
207 poEdit->oColBack = SYS_COLOR(BF_COLOR_CMDLINE_BACK);
208 poEdit->oColSel = SYS_COLOR(BF_COLOR_CMDLINE_TEXT);
209 poEdit->Draw(poEdit->Bounds());
210 Draw(Bounds());
211 break;
212 default:
213 BView::MessageReceived(po_Message);
214 }
215 }
216
217 void
218 BF_GUI_CmdLine::Enable(bool b_Enable)
219 {
220 iDisableCount += !b_Enable?+1:-1;
221
222 if(iDisableCount==0) poEdit->bCursorActive = true;
223 if(iDisableCount==1) poEdit->bCursorActive = false;
224 }
225
226 void
227 BF_GUI_CmdLine::Action_Enter()
228 {
229 printf("BF_GUI_CmdLine::Action_Enter()\n");
230
231
232 if(lsCommand.CountItems()==poSysSetup->iCmdLineHistorySize) lsCommand.DeleteItemAt(0);
233 lsCommand.AddItem(new BL_String(poEdit->sValue));
234
235
236 BL_String sCommand(sPath);
237 sCommand<<"/";
238 sCommand<<poEdit->sValue;
239 if(BF_Roster_RunCommand(sCommand)==0){
240 }else
241 if(BF_Roster_RunCommand(poEdit->sValue)==0){
242 }else
243 if(B_OK==BF_Roster_RunEntry(BEntry(sCommand.String()))){
244 }else
245 {
246 BF_Dialog_Alert_Sep(BF_DictAt(BF_DICT_ERROR),BF_DictAt(BF_DICT_PATH_CANNOTRUN),NULL,poWin->CurrentFocus());
247 SetValues(NULL,"");
248 }
249
250
251 sCmd = "";
252 poEdit->SetText("",true);