TrackGit
CommitWindow.cpp
Go to the documentation of this file.
1 
8 #include "CommitWindow.h"
9 #include "../GitCommand/Commit.h"
10 
11 #include <stdio.h>
12 #include <git2.h>
13 
14 #include <LayoutBuilder.h>
15 
16 
22  :
23  TrackGitWindow(repo, BRect(0, 0, 300, 200), "TrackGit - Commit",
24  B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
25 {
26  BStringView* fCommitString = new BStringView("commitString",
27  "Commit Message:");
28  fCommitTextView = new BTextView("commitText");
29  fCommitTextView->MakeFocus();
30 
31  BScrollView* fScrollView = new BScrollView("statusScrollView",
32  fCommitTextView, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
33  B_PLAIN_BORDER);
34 
35  BButton* fCommit = new BButton("commit", "Commit",
36  new BMessage(kDoCommit));
37  BButton* fCancel = new BButton("cancel", "Cancel",
38  new BMessage(kCancelCommit));
39 
40  BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
41  .SetInsets(10)
42  .Add(fCommitString)
43  .Add(fScrollView)
44  .AddGroup(B_HORIZONTAL, 0)
45  .AddGlue()
46  .Add(fCancel)
47  .Add(fCommit)
48  .End();
49 
50  CenterOnScreen();
51  Show();
52 }
53 
54 
59 void
61 {
62  BAlert* alert = NULL;
63  switch (msg->what) {
64  case kDoCommit:
65  if (Commit::DoCommit(fRepo, BString(fCommitTextView->Text()))) {
66  const git_error* err = giterr_last();
67  printf("Error %d : %s\n", err->klass, err->message);
68 
69  BString buffer("Error : %s");
70  buffer.ReplaceFirst("%s", err->message);
71  alert = new BAlert("", buffer.String(), "Cancel",
72  0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
73  } else {
74  BString buffer("Change commited successfully.");
75  alert = new BAlert("", buffer.String(), "OK",
76  0, 0, B_WIDTH_AS_USUAL);
77  }
78  alert->Go();
79  Quit();
80  break;
81  case kCancelCommit:
82  Quit();
83  break;
84  default:
85  BWindow::MessageReceived(msg);
86  }
87 }
virtual void MessageReceived(BMessage *)
Handler to received messages.
virtual void Quit()
The function to Quit the window.
CommitWindow(BString)
CommitWindow Constructor.
static int DoCommit(BString, BString)
This function commits to given repo with given message.
Definition: Commit.cpp:57
Header file of Commit window.
BTextView * fCommitTextView
The Commit Text View.
Definition: CommitWindow.h:30
The TrackGit Window class.
BString fRepo
The repo/directory where the command is called.