TrackGit
StatusWindow.cpp
Go to the documentation of this file.
1 
8 #include "StatusWindow.h"
9 
10 #include <stdio.h>
11 
12 #include <Catalog.h>
13 #include <LayoutBuilder.h>
14 
15 #define B_TRANSLATION_CONTEXT "TrackGit"
16 
17 
18 enum {
21 };
22 
23 
29 StatusItem::StatusItem(BString text, BString path)
30  :
31  BStringItem(text)
32 {
33  fText = text;
34  fPath = path;
35 }
36 
37 
42 BString
44 {
45  return fPath;
46 }
47 
48 
54  :
55  TrackGitWindow(repo, BRect(0, 0, 300, 300), "TrackGit - Status",
56  B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
57 {
58  fStatusListView = new BListView(B_SINGLE_SELECTION_LIST);
59  //fStatusListView->SetSelectionMessage(new BMessage(kStatusSelected));
60  fStatusListView->SetInvocationMessage(new BMessage(kStatusSelected));
61 
62  BScrollView* fScrollView = new BScrollView("statusScrollView",
63  fStatusListView, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
64  B_PLAIN_BORDER);
65 
66  BButton* fOK = new BButton("ok", B_TRANSLATE("OK"),
67  new BMessage(kStatusOK));
68 
69  BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
70  .SetInsets(10)
71  .Add(fScrollView)
72  .Add(fOK);
73 
74  CenterOnScreen();
75  Show();
76 }
77 
78 
84 void
85 StatusWindow::AddItem(BString text, BString path)
86 {
87  if (LockLooper()) {
88  fStatusListView->AddItem(new StatusItem(text, path));
89  UnlockLooper();
90  }
91 }
92 
93 
98 void
100 {
101  int selection;
102  StatusItem* item;
103  BString path;
104  BEntry entry;
105  entry_ref ref;
106  BMessenger msgr;
107  BMessage rmsg;
108  switch (msg->what) {
109  case kStatusSelected:
110  selection = fStatusListView->CurrentSelection();
111  item = (StatusItem*)fStatusListView->ItemAt(selection);
112  if (item->GetPath().Length() > 0) {
113  path = fRepo;
114  path.ReplaceFirst(".git/", "");
115  path.Append(item->GetPath());
116  printf("Selected %s\n", path.String());
117  entry = BEntry(path.String());
118  entry.GetRef(&ref);
119  msgr = BMessenger("application/x-vnd.Be-TRAK");
120  rmsg = BMessage(B_REFS_RECEIVED);
121  rmsg.AddRef("refs", &ref);
122  msgr.SendMessage(&rmsg);
123  }
124  break;
125  case kStatusOK:
126  Quit();
127  break;
128  default:
129  BWindow::MessageReceived(msg);
130  }
131 }
Header file of Status window.
The Status List Item class.
Definition: StatusWindow.h:20
virtual void MessageReceived(BMessage *)
Handler to received messages.
BString GetPath()
Getter for path.
BString fText
The text to be displayed.
Definition: StatusWindow.h:24
virtual void Quit()
The function to Quit the window.
BListView * fStatusListView
The Status List View.
Definition: StatusWindow.h:42
StatusItem(BString, BString)
StatusItem Constructor.
BString fPath
The file path of item.
Definition: StatusWindow.h:28
void AddItem(BString, BString)
Adds item to the Status list.
StatusWindow(BString)
StatusWindow Constructor.
The TrackGit Window class.
BString fRepo
The repo/directory where the command is called.