forked from HaikuArchives/TrackGit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackGitApp.cpp
More file actions
126 lines (112 loc) · 2.73 KB
/
TrackGitApp.cpp
File metadata and controls
126 lines (112 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @file TrackGitApp.cpp
* @brief Implementation file of TrackGitApp.
*
* @author Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
*/
#include "TrackGitApp.h"
#include "Utils.h"
#include <InterfaceKit.h>
#include "UI/TrackGitWindow.h"
#include "GitCommand/GitCommand.h"
#include "GitCommand/Clone.h"
#include "GitCommand/Init.h"
#include "GitCommand/Status.h"
#include "GitCommand/Add.h"
#include "GitCommand/Commit.h"
#include "GitCommand/Pull.h"
#include "GitCommand/Push.h"
#include "GitCommand/ShowConflicts.h"
#include "GitCommand/CreateBranch.h"
#include "GitCommand/SwitchBranch.h"
#include "GitCommand/Log.h"
/**
* TrackGitApp Constructor.
*/
TrackGitApp::TrackGitApp()
:
BApplication(APP_SIGN)
{
}
/**
* The handler to receive messages.
* This function acitivates already existing window or launches a new ones if
* needed. This also quits the app when there are no windows left.
* @param msg The message to receive.
*/
void
TrackGitApp::MessageReceived(BMessage* msg)
{
// If message is received for quitting the window
if (msg->what == kQuitWindow) {
BString repo;
if (msg->FindString("repo", &repo) == B_OK)
fRunningCommands.erase(repo);
// If all windows are quit
if (fRunningCommands.size() == 0)
be_app->PostMessage(B_QUIT_REQUESTED);
return;
}
vector<char*> selected;
extract_selected_paths(msg, selected);
BString dirPath = extract_current_directory(msg);
int32 itemId;
if (msg->FindInt32("addon_item_id", &itemId) != B_OK)
return;
BString repo = get_root_of_repo(dirPath);
// Check if window for selected repo already exits
// If yes bring it to front
if (fRunningCommands.count(repo)) {
fRunningCommands[repo]->Activate(true);
BWindow* window = fRunningCommands[repo];
if (window->Lock()) {
window->Activate(true);
window->Unlock();
}
return;
}
GitCommand* gitCommand = NULL;
switch (itemId) {
case kClone:
gitCommand = new Clone(repo, dirPath);
break;
case kInitHere:
gitCommand = new Init(dirPath);
break;
case kStatus:
gitCommand = new Status(repo, dirPath);
break;
case kAdd:
case kAddAll:
gitCommand = new Add(dirPath, selected);
break;
case kCommit:
gitCommand = new Commit(repo);
break;
case kPull:
gitCommand = new Pull(repo);
break;
case kPush:
gitCommand = new Push(repo);
break;
case kShowConflicts:
gitCommand = new ShowConflicts(repo);
break;
case kCreateBranch:
gitCommand = new CreateBranch(repo);
break;
case kSwitchBranch:
gitCommand = new SwitchBranch(repo);
break;
case kLog:
gitCommand = new Log(repo);
break;
default:
break;
}
TrackGitWindow* window = gitCommand->GetWindow();
if (window != NULL)
fRunningCommands[repo] = window;
if (gitCommand)
gitCommand->Execute();
}