TrackGit
TrackGitApp.cpp
Go to the documentation of this file.
1 
8 #include "TrackGitApp.h"
9 #include "Utils.h"
10 
11 #include <InterfaceKit.h>
12 
13 #include "UI/TrackGitWindow.h"
14 #include "GitCommand/GitCommand.h"
15 #include "GitCommand/Clone.h"
16 #include "GitCommand/Init.h"
17 #include "GitCommand/Status.h"
18 #include "GitCommand/Add.h"
19 #include "GitCommand/Commit.h"
20 #include "GitCommand/Pull.h"
21 #include "GitCommand/Push.h"
25 #include "GitCommand/Log.h"
26 
27 
32  :
33  BApplication(APP_SIGN)
34 {
35 }
36 
37 
44 void
46 {
47  // If message is received for quitting the window
48  if (msg->what == kQuitWindow) {
49  BString repo;
50  if (msg->FindString("repo", &repo) == B_OK)
51  fRunningCommands.erase(repo);
52  // If all windows are quit
53  if (fRunningCommands.size() == 0)
54  be_app->PostMessage(B_QUIT_REQUESTED);
55  return;
56  }
57 
58  vector<char*> selected;
59  extract_selected_paths(msg, selected);
60  BString dirPath = extract_current_directory(msg);
61 
62  int32 itemId;
63  if (msg->FindInt32("addon_item_id", &itemId) != B_OK)
64  return;
65 
66  BString repo = get_root_of_repo(dirPath);
67  // Check if window for selected repo already exits
68  // If yes bring it to front
69  if (fRunningCommands.count(repo)) {
70  fRunningCommands[repo]->Activate(true);
71  BWindow* window = fRunningCommands[repo];
72  if (window->Lock()) {
73  window->Activate(true);
74  window->Unlock();
75  }
76  return;
77  }
78 
79  GitCommand* gitCommand = NULL;
80 
81  switch (itemId) {
82  case kClone:
83  gitCommand = new Clone(repo, dirPath);
84  break;
85  case kInitHere:
86  gitCommand = new Init(dirPath);
87  break;
88  case kStatus:
89  gitCommand = new Status(repo, dirPath);
90  break;
91  case kAdd:
92  case kAddAll:
93  gitCommand = new Add(dirPath, selected);
94  break;
95  case kCommit:
96  gitCommand = new Commit(repo);
97  break;
98  case kPull:
99  gitCommand = new Pull(repo);
100  break;
101  case kPush:
102  gitCommand = new Push(repo);
103  break;
104  case kShowConflicts:
105  gitCommand = new ShowConflicts(repo);
106  break;
107  case kCreateBranch:
108  gitCommand = new CreateBranch(repo);
109  break;
110  case kSwitchBranch:
111  gitCommand = new SwitchBranch(repo);
112  break;
113  case kLog:
114  gitCommand = new Log(repo);
115  break;
116  default:
117  break;
118  }
119 
120  TrackGitWindow* window = gitCommand->GetWindow();
121  if (window != NULL)
122  fRunningCommands[repo] = window;
123 
124  if (gitCommand)
125  gitCommand->Execute();
126 }
#define APP_SIGN
The Application signature.
Definition: Utils.h:45
Header file of Commit command.
virtual TrackGitWindow * GetWindow()
This is used to get pointer to the window (if any).
Definition: GitCommand.h:30
Definition: Utils.h:27
Push command Class.
Definition: Push.h:32
Header file of Clone command.
Header file of Init command.
Status command Class.
Definition: Status.h:39
Header file of Push command.
Init command Class.
Definition: Init.h:18
Log command Class.
Definition: Log.h:50
void extract_selected_paths(const BMessage *msg, vector< char *> &selected)
Get selected files.
Definition: Utils.cpp:50
Create Branch command Class.
Definition: CreateBranch.h:18
Definition: Utils.h:26
GitCommand Class.
Definition: GitCommand.h:20
Header file of Log command.
Header file of Utils.
BString extract_current_directory(const BMessage *msg)
Get current directory.
Definition: Utils.cpp:28
TrackGitApp()
TrackGitApp Constructor.
Definition: TrackGitApp.cpp:31
Header file of ShowConflicts command.
Definition: Utils.h:24
Definition: Utils.h:25
Definition: Utils.h:33
Header file of Create Branch command.
map< BString, TrackGitWindow * > fRunningCommands
The map of running commands to their repo.
Definition: TrackGitApp.h:29
Commit command Class.
Definition: Commit.h:18
Header file of Switch Branch command.
Header file of TrackGit App.
Header file of Add command.
Header file of Pull command.
Clone command Class.
Definition: Clone.h:46
The TrackGit Window class.
Pull command Class.
Definition: Pull.h:40
Switch Branch command Class.
Definition: SwitchBranch.h:20
BString get_root_of_repo(BString dirPath)
Get the root of repo of current directory.
Definition: Utils.cpp:81
Header file of GitCommand.
Definition: Utils.h:29
Definition: Utils.h:28
Definition: Utils.h:22
virtual void MessageReceived(BMessage *)
The handler to receive messages.
Definition: TrackGitApp.cpp:45
Header file of TrackGit window.
virtual void Execute()=0
This is where actual calls to libgit2 will go.
Add command Class.
Definition: Add.h:23
Header file of Status command.
ShowConflicts command Class.
Definition: ShowConflicts.h:18