Skip to content

Commit

Permalink
Reconstruct filesystem model and GUI model. #3 and #4 fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
marbocub committed Sep 6, 2014
1 parent ae03a98 commit 88b72f8
Show file tree
Hide file tree
Showing 25 changed files with 4,604 additions and 2,697 deletions.
216 changes: 216 additions & 0 deletions BafxApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
* Copyright 2012-2014 @marbocub <marbocub@gmail.com>
* All rights reserved.
* Distributed under the terms of the MIT license.
*/


#include "BafxApp.h"
#include "BafxMessage.h"

#include <Alert.h>
#include <MenuBar.h>
#include <Menu.h>
#include <MenuItem.h>

#include "FilerView.h"
#include "EntryModel.h"
#include "TextFileView.h"

const char kAboutMsg[] =
"BAfx file manager\n"
"\n"
"Version 0.2.3\n"
"\n"
"Copyright " B_UTF8_COPYRIGHT " 2012-2014 @marbocub.\n"
"Distributed under the terms of the MIT license.";


#undef DEBUG

#ifdef DEBUG
# include <cstdio>
# define DEBUG_PRINT(x) {printf("%s:%s:", Name(),__FUNCTION__); printf x;}
#else
# define DEBUG_PRINT(x) do {} while (0)
#endif


BafxApp::BafxApp()
: BApplication("application/x-vnd.marbocub-BafxApp"),
mainWindow_(NULL),
filerView_(NULL),
textViewerView_(NULL)
{
}


BafxApp::~BafxApp()
{
bafx_free_keymap();
}


void
BafxApp::ReadyToRun()
{
mainWindow_ = new BafxWindow(
BRect(100,100,100+640,100+480),
"BAfx App",
B_DOCUMENT_WINDOW,
0
);

filerView_ = new FilerView(
BRect(0,0,0,0),
"double_filer_view",
B_FOLLOW_ALL_SIDES,
B_WILL_DRAW
);

textViewerView_ = new TextFileView(
BRect(0,0,0,0),
"text_file_view",
B_FOLLOW_ALL_SIDES,
B_WILL_DRAW
);

BMenuBar* menuBar = MakeMenuBar();
mainWindow_->InitContent(
menuBar,
filerView_,
/*
new BView(
BRect(0,0,0,0),
"status_view",
B_FOLLOW_BOTTOM|B_FOLLOW_LEFT_RIGHT,
B_WILL_DRAW
)
*/
new BStringView(
BRect(0,0,0,0),
"status_string",
"",
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT
)
);

filerView_->OpenDirectory1("/boot/home/");
filerView_->OpenDirectory2("/boot");

mainWindow_->Show();
}


BMenuBar*
BafxApp::MakeMenuBar()
{
BMenuBar* theMenuBar;
BMenu* theFileMenu;
BMenu* theEditMenu;
BMenu* theDevelMenu;

theMenuBar = new BMenuBar(BRect(0,0,0,0), B_EMPTY_STRING);

theFileMenu = new BMenu("BAfx");
theMenuBar->AddItem(theFileMenu);
(void)theFileMenu->AddItem(
new BMenuItem(
"About...",
new BMessage(B_ABOUT_REQUESTED)
)
);
(void)theFileMenu->AddSeparatorItem();
(void)theFileMenu->AddItem(
new BMenuItem(
"Quit",
new BMessage(B_QUIT_REQUESTED),
'Q'
)
);
theFileMenu->SetTargetForItems(this);

theEditMenu = new BMenu("Edit");
theMenuBar->AddItem(theEditMenu);
(void)theEditMenu->AddItem(
new BMenuItem(
"Copy marked items",
new BMessage(M_COPY_FILE),
'C'
)
);
(void)theEditMenu->AddItem(
new BMenuItem(
"Remove marked items",
new BMessage(M_DELETE_FILE),
'D'
)
);
theEditMenu->SetTargetForItems(this);

theDevelMenu = new BMenu("Develop");
#ifdef DEBUG
theMenuBar->AddItem(theDevelMenu);
#endif
(void)theDevelMenu->AddItem(
new BMenuItem(
"Text Viewer",
new BMessage(M_VIEW_FILE),
'V'
)
);
(void)theDevelMenu->AddItem(
new BMenuItem(
"Return to Filer",
new BMessage(M_RETURN_TO_FILER),
'F'
)
);
theDevelMenu->SetTargetForItems(this);

return theMenuBar;
}


void
BafxApp::AboutRequested()
{
BAlert* alertPanel;

alertPanel = new BAlert("about BAfx", kAboutMsg, "OK");
(void)alertPanel->Go(NULL);

return;
}


void
BafxApp::MessageReceived(BMessage* message)
{
DEBUG_PRINT(("%s:message:%c%c%c%c\n",
__FUNCTION__,
message->what>>24,
message->what>>16,
message->what>>8,
message->what));
DEBUG_PRINT(("CountNames: %d\n", message->CountNames(B_ANY_TYPE)));

switch(message->what)
{
case M_COPY_FILE:
DEBUG_PRINT(("Copy"));
break;
case M_DELETE_FILE:
DEBUG_PRINT(("Delete"));
break;
case M_VIEW_FILE:
mainWindow_->ReplaceContent(textViewerView_);
break;
case M_RETURN_TO_FILER:
mainWindow_->ReplaceContent(filerView_);
break;
default:
BApplication::MessageReceived(message);
break;
}
}
40 changes: 40 additions & 0 deletions BafxApp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2012-2014 @marbocub <marbocub@gmail.com>
* All rights reserved.
* Distributed under the terms of the MIT license.
*/


#ifndef BAFX_APP_H
#define BAFX_APP_H

#include <SupportDefs.h>
#include <app/Application.h>
#include <MenuBar.h>

#include "BafxWindow.h"
#include "FilerView.h"
#include "TextFileView.h"
//#include "EntryModel.h"


class BafxApp : public BApplication
{
private:
BafxWindow* mainWindow_;
FilerView* filerView_;
TextFileView* textViewerView_;

public:
BafxApp();
~BafxApp();
void MessageReceived(BMessage* message);

private:
void ReadyToRun();
BMenuBar* MakeMenuBar();
void AboutRequested();
};


#endif // BAFX_APP_H
14 changes: 12 additions & 2 deletions BafxMessage.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/*
* Copyright 2012-2013 @marbocub <marbocub @ gmail com>
* All rights reserved. Distributed under the terms of the MIT license.
* Copyright 2012-2014 @marbocub <marbocub@gmail.com>
* All rights reserved.
* Distributed under the terms of the MIT license.
*/


#include "BafxMessage.h"
#include <InterfaceDefs.h>

#include <malloc.h>
#include <string.h>


BafxKeymap *keymap = NULL;


const BafxKeymap default_keymap[] = {
// key modifiers message

Expand Down Expand Up @@ -59,6 +64,7 @@ const BafxKeymap default_keymap[] = {
{0, 0, 0}
};


extern "C" void bafx_setup_keymap(void)
{
if (keymap == NULL) {
Expand All @@ -68,10 +74,13 @@ extern "C" void bafx_setup_keymap(void)

}


extern "C" uint32 bafx_key_to_message(char key, int32 modifiers)
{
bafx_setup_keymap();

modifiers &= ~(B_CAPS_LOCK | B_SCROLL_LOCK | B_NUM_LOCK);

for (int32 i=0; keymap[i].key!=0; i++) {
if ((key == keymap[i].key) && (modifiers == keymap[i].modifiers))
return keymap[i].message;
Expand All @@ -80,6 +89,7 @@ extern "C" uint32 bafx_key_to_message(char key, int32 modifiers)
return 0;
}


extern "C" void bafx_free_keymap(void)
{
if (keymap != NULL) free(keymap);
Expand Down
9 changes: 7 additions & 2 deletions BafxMessage.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Copyright 2012-2013 @marbocub <marbocub @ gmail com>
* All rights reserved. Distributed under the terms of the MIT license.
* Copyright 2012-2014 @marbocub <marbocub@gmail.com>
* All rights reserved.
* Distributed under the terms of the MIT license.
*/


#ifndef BAFX_MESSAGE_H
#define BAFX_MESSAGE_H

#include <SupportDefs.h>


enum {
M_COPY_FILE = 'cp__',
M_MOVE_FILE = 'mv__',
Expand All @@ -17,6 +21,7 @@ enum {

M_OPEN_FILE = 'open',
M_VIEW_FILE = 'view',
M_RETURN_TO_FILER = 'filr',
M_EDIT_FILE = 'edit',
M_EXEC_FILE = 'exec',
M_MARK_FILE = 'mark',
Expand Down
Loading

0 comments on commit 88b72f8

Please sign in to comment.