-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTrackGitApp.cpp
156 lines (137 loc) · 3.33 KB
/
TrackGitApp.cpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright 2018, Hrishikesh Hiraskar <[email protected]>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "TrackGitApp.h"
#include <AboutWindow.h>
#include <Catalog.h>
#include <InterfaceKit.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"
#include "UI/TrackGitWindow.h"
#include "Utils.h"
#define B_TRANSLATION_CONTEXT "TrackGitApp"
/**
* 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();
}
void
TrackGitApp::AboutRequested()
{
AboutWindow();
}
void
TrackGitApp::AboutWindow()
{
const char* authors[] = {
"Adrien Destugues",
"Hrishikesh Hiraskar",
"humdinger",
"Janus",
"Stephan Aßmus",
"waddlesplash",
NULL
};
BAboutWindow* aboutW = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME(ADDON_NAME),
APP_SIGN);
aboutW->AddDescription(B_TRANSLATE("A Tracker Addon for Git Version Control System"));
aboutW->AddCopyright(2018, "Hrishikesh Hiraskar");
aboutW->AddAuthors(authors);
aboutW->Show();
}