3232
3333#include " OpenFilesDialog.h"
3434
35+ #include < Alert.h>
3536#include < Button.h>
37+ #include < MenuItem.h>
3638#include < Path.h>
39+ #include < PopUpMenu.h>
40+ #include < Roster.h>
3741#include < String.h>
3842#include < TextControl.h>
3943
@@ -53,6 +57,12 @@ static const char NAME_RIGHT_BROWSE_BUTTON[] = "RightBrowseButton";
5357static const char NAME_DIFF_THEM_BUTTON[] = " DiffThemButton" ;
5458static const char NAME_CANCEL_BUTTON[] = " CancelButton" ;
5559
60+ static const uint32 kMsgDiffToolSelected = ' dtsl' ;
61+
62+ static const char * kPeSignature = " application/x-vnd.beunited.pe" ;
63+ static const char * kTerminalSignature = " application/x-vnd.Haiku-Terminal" ;
64+
65+
5666/* *
5767 * @brief コンストラクタ
5868 * @param[in] topLeft ダイアログの左上位置
@@ -62,7 +72,8 @@ OpenFilesDialog::OpenFilesDialog(BPoint topLeft)
6272 RT(IDS_TITLE_OPEN_FILES),
6373 B_TITLED_WINDOW_LOOK,
6474 B_NORMAL_WINDOW_FEEL,
65- B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE)
75+ B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE),
76+ fDiffToolMenuField(NULL )
6677{
6778 int index;
6879 for (index = 0 ; index < FileMAX; index++)
@@ -120,7 +131,14 @@ void OpenFilesDialog::Initialize()
120131
121132 BButton* cancelButton = new BButton (BRect (282 , 84 , 362 , 108 ), NAME_CANCEL_BUTTON, RT (IDS_LABEL_CANCEL), new BMessage (ID_CANCEL));
122133 baseView->AddChild (cancelButton);
123-
134+
135+ BPopUpMenu* menu = new BPopUpMenu (" diff tool menu" );
136+ fDiffToolMenuField = new BMenuField (
137+ BRect (12 , 84 , 212 , 108 ),
138+ " diff tool menu field" , " Diff Tool:" , menu);
139+ populateDiffToolMenu ();
140+ baseView->AddChild (fDiffToolMenuField );
141+
124142 Show ();
125143}
126144
@@ -286,13 +304,82 @@ void OpenFilesDialog::doDiffThem()
286304 return ;
287305 }
288306 BPath rightPath (text);
289-
290- PonpokoDiffApp* app = static_cast <PonpokoDiffApp*>(be_app);
291- TextDiffWnd* newDiffWnd = app->NewTextDiffWnd ();
292- newDiffWnd->ExecuteDiff (leftPath, rightPath, NULL , NULL );
293- PostMessage (B_QUIT_REQUESTED);
307+
308+ int diffTool = getSelectedDiffTool ();
309+ BString cmd;
310+ switch (diffTool) {
311+ case dtInternal:
312+ {
313+ PonpokoDiffApp* app = static_cast <PonpokoDiffApp*>(be_app);
314+ TextDiffWnd* newDiffWnd = app->NewTextDiffWnd ();
315+ newDiffWnd->ExecuteDiff (leftPath, rightPath, NULL , NULL );
316+ PostMessage (B_QUIT_REQUESTED);
317+ break ;
318+ }
319+ case dtPe:
320+ {
321+ const char * argv[] = {" --diff" , leftPath.Path (), rightPath.Path (), NULL };
322+ be_roster->Launch (kPeSignature , 3 , argv);
323+ PostMessage (B_QUIT_REQUESTED);
324+ break ;
325+ }
326+ case dtKdiff3:
327+ cmd.SetToFormat (" kdiff3 %s %s" , leftPath.Path (), rightPath.Path ());
328+ system (cmd.String ());
329+ PostMessage (B_QUIT_REQUESTED);
330+ break ;
331+ case dtVimDiff:
332+ {
333+ const char * argv[] = {" -t" , " Differences" , " vimdiff" , leftPath.Path (), rightPath.Path (), NULL };
334+ be_roster->Launch (kTerminalSignature , 5 , argv);
335+ PostMessage (B_QUIT_REQUESTED);
336+ break ;
337+ }
338+ default :
339+ BAlert* alert = new BAlert (" PonpokoDiff" , " Unkown diff tool option!" , " Ok" );
340+ alert->Go ();
341+ }
294342}
295343
344+
345+ void OpenFilesDialog::populateDiffToolMenu ()
346+ {
347+ // ToDo:
348+ // - save/restore the selected menu item to/from a settings file.
349+ // - Either only add external tools if they're installed, or show an error
350+ // when trying to use them if they are not.
351+
352+ BMenuItem* internalDiffTool = new BMenuItem (" Internal" , new BMessage (kMsgDiffToolSelected ));
353+ internalDiffTool->SetMarked (true );
354+ fDiffToolMenuField ->Menu ()->AddItem (internalDiffTool);
355+
356+ BMenuItem* peDiffTool = new BMenuItem (" Pe diff" , new BMessage (kMsgDiffToolSelected ));
357+ internalDiffTool->SetMarked (false );
358+ fDiffToolMenuField ->Menu ()->AddItem (peDiffTool);
359+
360+ BMenuItem* kdiff3DiffTool = new BMenuItem (" kdiff3" , new BMessage (kMsgDiffToolSelected ));
361+ internalDiffTool->SetMarked (false );
362+ fDiffToolMenuField ->Menu ()->AddItem (kdiff3DiffTool);
363+
364+ BMenuItem* vimDiffDiffTool = new BMenuItem (" vimdiff" , new BMessage (kMsgDiffToolSelected ));
365+ internalDiffTool->SetMarked (false );
366+ fDiffToolMenuField ->Menu ()->AddItem (vimDiffDiffTool);
367+ }
368+
369+
370+ int OpenFilesDialog::getSelectedDiffTool ()
371+ {
372+ BMenuItem* item = NULL ;
373+ int32 count = fDiffToolMenuField ->Menu ()->CountItems ();
374+ for (int i = 0 ; i < count; i++) {
375+ item = (BMenuItem*)fDiffToolMenuField ->Menu ()->ItemAt (i);
376+ if (item->IsMarked ())
377+ return i;
378+ }
379+ return dtInternal;
380+ }
381+
382+
296383/* *
297384 * @brief ウィンドウが閉じるときに呼び出されます。
298385 */
0 commit comments