Skip to content

Commit

Permalink
Implemented Status Window
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrily committed May 26, 2018
1 parent 5225d24 commit 4faa45c
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 5 deletions.
15 changes: 11 additions & 4 deletions GitCommand/Status.cpp
Expand Up @@ -6,6 +6,7 @@
*/

#include "Status.h"
#include "../UI/StatusWindow.h"

#include <InterfaceKit.h>

Expand Down Expand Up @@ -299,10 +300,16 @@ Status::Status(char* dirPath)
void
Status::Execute()
{
StatusWindow* statusWindow = new StatusWindow();
BString* statusText = GetStatusText();
if (statusText) {
BAlert* alert = new BAlert("", statusText->String(), "OK",
0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go();

if (!statusWindow) {
statusWindow->Quit();
return;
}

statusWindow->SetText(statusText);
thread_id thread = statusWindow->Thread();
status_t win_status = B_OK;
wait_for_thread(thread, &win_status);
}
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -29,10 +29,11 @@ APP_MIME_SIG =
# same name (source.c or source.cpp) are included from different directories.
# Also note that spaces in folder names do not work well with this Makefile.
SRCS = ThirdParty/PathBox.cpp \
UI/CloneWindow.cpp \
UI/StatusWindow.cpp \
GitCommand/Clone.cpp \
GitCommand/Init.cpp \
GitCommand/Status.cpp \
UI/CloneWindow.cpp \
TrackGit.cpp

# Specify the resource definition files to use. Full or relative paths can be
Expand Down
4 changes: 4 additions & 0 deletions UI/CloneWindow.cpp
Expand Up @@ -87,6 +87,8 @@ CloneWindow::DoClone(const char* url, const char* path)
{
printf("Cloning %s into %s\n", url, path);

git_libgit2_init();

git_repository* repo = NULL;
int ret = git_clone(&repo, url, path, NULL);

Expand All @@ -102,5 +104,7 @@ CloneWindow::DoClone(const char* url, const char* path)
}

git_repository_free(repo);
git_libgit2_shutdown();

return ret;
}
80 changes: 80 additions & 0 deletions UI/StatusWindow.cpp
@@ -0,0 +1,80 @@
/**
* @file StatusWindow.cpp
* @brief Implementation file of Status window.
*
* @author Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
*/

#include "StatusWindow.h"

#include <stdio.h>

#include <Catalog.h>
#include <LayoutBuilder.h>

#define B_TRANSLATION_CONTEXT "TrackGit"


enum {
kOK
};

/**
* StatusWindow Constructor
* @param statusText The status text to be displayed.
*/
StatusWindow::StatusWindow()
:
BWindow(BRect(0, 0, 300, 300), "TrackGit - Status", B_DOCUMENT_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{
fStatusTextView = new BTextView("statusText");
fStatusTextView->SetText("Loading...");
fStatusTextView->MakeEditable(false);

BScrollView* fScrollView = new BScrollView("statusScrollView",
fStatusTextView, B_WILL_DRAW | B_FRAME_EVENTS, false, true,
B_PLAIN_BORDER);

BButton* fOK = new BButton("ok", B_TRANSLATE("OK"),
new BMessage(kOK));

BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(10)
.Add(fScrollView)
.Add(fOK);

Show();
CenterOnScreen();

This comment has been minimized.

Copy link
@stippi

stippi Jun 4, 2018

Collaborator

This should probably be reversed, no? First CenterOnScreen(), then Show().

}


/**
* Sets Text of the View in Window.
* @param text The text to be set.
*/
void
StatusWindow::SetText(BString* text)
{
if (LockLooper()) {

This comment has been minimized.

Copy link
@stippi

stippi Jun 4, 2018

Collaborator

If I'm not mistaken, LockLooper() returns a status_t, not a boolean. So that should be if (LockLooper() == B_OK).

This comment has been minimized.

This comment has been minimized.

Copy link
@stippi

stippi Jun 7, 2018

Collaborator

Ah yes, sorry. I mixed it up with LockWithTimeout().

fStatusTextView->SetText(text->String());
UnlockLooper();
}
}


/**
* Handler to received messages.
* @param msg The received message.
*/
void
StatusWindow::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case kOK:
Quit();

This comment has been minimized.

Copy link
@stippi

stippi Jun 4, 2018

Collaborator

I think you are not supposed to call Quit() directly like that. Instead, call "PostMessage(B_QUIT_REQUESTED)". But even more easy is to setup the OK-Button with a "new BMessage(B_QUIT_REQUESTED)" instead of "new BMessage(kOK)" :-) You can then remove the MessageReceived() implementation alltogether.

break;
default:
BWindow::MessageReceived(msg);
}
}
25 changes: 25 additions & 0 deletions UI/StatusWindow.h
@@ -0,0 +1,25 @@
/**
* @file StatusWindow.h
* @brief Header file of Status window.
*
* @author Hrishikesh Hiraskar <hrishihiraskar@gmail.com>
*/

#ifndef _STATUS_WINDOW_H_
#define _STATUS_WINDOW_H_

#include <InterfaceKit.h>
#include <SupportKit.h>

class StatusWindow : public BWindow {
/**
* The Status Text View.
*/
BTextView* fStatusTextView;
public:
StatusWindow();
void SetText(BString*);
virtual void MessageReceived(BMessage*);
};

#endif

0 comments on commit 4faa45c

Please sign in to comment.