TrackGit
CreateBranchWindow.cpp
Go to the documentation of this file.
1 
8 #include "CreateBranchWindow.h"
9 #include "../GitCommand/CreateBranch.h"
10 #include "../GitCommand/SwitchBranch.h"
11 
12 #include <stdio.h>
13 #include <git2.h>
14 
15 #include <LayoutBuilder.h>
16 
17 
23  :
24  TrackGitWindow(repo, BRect(0, 0, 300, 100), "TrackGit - Create Branch",
25  B_DOCUMENT_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
26 {
27  fBranchText = new BTextControl("Name: ", "", NULL);
28  fSwitchBranch = new BCheckBox("Switch to this branch");
29 
30  BButton* fCreate = new BButton("create", "Create",
31  new BMessage(kDoCreateBranch));
32  BButton* fCancel = new BButton("cancel", "Cancel",
33  new BMessage(kCancelCreateBranch));
34 
35  BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
36  .SetInsets(10)
37  .Add(fBranchText)
38  .Add(fSwitchBranch)
39  .AddGroup(B_HORIZONTAL, 0)
40  .AddGlue()
41  .Add(fCancel)
42  .Add(fCreate)
43  .End();
44 
45  CenterOnScreen();
46  Show();
47 }
48 
49 
54 void
56 {
57  BAlert* alert = NULL;
58  switch (msg->what) {
59  case kDoCreateBranch:
61  BString(fBranchText->Text())) < 0) {
62  const git_error* err = giterr_last();
63 
64  BString buffer("Error : %s");
65  if (err)
66  buffer.ReplaceFirst("%s", err->message);
67  else
68  buffer.ReplaceFirst("%s", "Invalid branch name. Does the "
69  "branch already exists?");
70  alert = new BAlert("", buffer.String(), "Cancel",
71  0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
72  } else {
73  BString buffer("Branch %b created successfully.");
74  buffer.ReplaceFirst("%b", fBranchText->Text());
75  alert = new BAlert("", buffer.String(), "OK",
76  0, 0, B_WIDTH_AS_USUAL);
77  }
78  alert->Go();
79  if (fSwitchBranch->Value() == B_CONTROL_ON) {
81  BString(fBranchText->Text())) < 0) {
82  const git_error* err = giterr_last();
83 
84  BString buffer("Error : %s");
85  buffer.ReplaceFirst("%s", err->message);
86  alert = new BAlert("", buffer.String(), "Cancel",
87  0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
88  } else {
89  BString buffer("Switched to branch %b.");
90  buffer.ReplaceFirst("%b", fBranchText->Text());
91  alert = new BAlert("", buffer.String(), "OK",
92  0, 0, B_WIDTH_AS_USUAL);
93  }
94  alert->Go();
95  }
96  Quit();
97  break;
99  Quit();
100  break;
101  default:
102  BWindow::MessageReceived(msg);
103  }
104 }
Header file of Create Branch window.
virtual void Quit()
The function to Quit the window.
static int DoCreateBranch(BString, BString)
This function creates a new branch in repo with given name.
BCheckBox * fSwitchBranch
Switch Branch check box.
BTextControl * fBranchText
The Create Branch Text View.
static int DoSwitchBranch(BString, BString)
This function creates a new branch in repo with given name.
The TrackGit Window class.
virtual void MessageReceived(BMessage *)
Handler to received messages.
BString fRepo
The repo/directory where the command is called.
CreateBranchWindow(BString)
CreateBranchWindow Constructor.