fix command line execution - thanks BGA

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2043 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty
2002-11-20 23:29:00 +00:00
parent b7b9d38498
commit e2344ee25b
3 changed files with 75 additions and 21 deletions
+51 -3
View File
@@ -1,5 +1,6 @@
#include <Autolock.h>
#include <Path.h>
#include "Constants.h"
#include "StyledEditApp.h"
#include "StyledEditWindow.h"
@@ -25,6 +26,29 @@ StyledEditApp::StyledEditApp()
styled_edit_app = this;
} /***StyledEditApp::StyledEditApp()***/
void StyledEditApp::DispatchMessage(BMessage *msg, BHandler *handler)
{
if ( msg->what == B_ARGV_RECEIVED ) {
int32 argc;
if (msg->FindInt32("argc",&argc) != B_OK) {
argc=0;
}
const char ** argv = new (const char*)[argc];
for (int arg = 0; (arg < argc) ; arg++) {
if (msg->FindString("argv",arg,&argv[arg]) != B_OK) {
argv[arg] = "";
}
}
const char * cwd;
if (msg->FindString("cwd",&cwd) != B_OK) {
cwd = "";
}
ArgvReceived(argc, argv, cwd);
} else {
BApplication::DispatchMessage(msg,handler);
}
}
void
StyledEditApp::MessageReceived(BMessage *message)
@@ -78,15 +102,39 @@ StyledEditApp::RefsReceived(BMessage *message)
entry_ref ref;
status_t err;
refNum=0;
refNum = 0;
do {
if((err= message->FindRef("refs", refNum, &ref)) != B_OK)
err = message->FindRef("refs", refNum, &ref);
if (err != B_OK)
return;
OpenDocument(&ref);
refNum++;
} while(1);
} while (true);
} /***StyledEditApp::RefsReceived();***/
void
StyledEditApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
{
for (int i = 1 ; (i < argc) ; i++) {
BPath path;
if (argv[i][0] == '/') {
path.SetTo(argv[i]);
} else {
path.SetTo(cwd,argv[i]);
}
if (path.InitCheck() != B_OK) {
continue; // TODO: alert the user?
}
entry_ref ref;
if (get_ref_for_path(path.Path(), &ref) != B_OK) {
continue; // TODO: alert the user?
}
OpenDocument(&ref);
}
}
void
StyledEditApp::ReadyToRun()
{
+3
View File
@@ -14,9 +14,12 @@ class StyledEditApp
public:
StyledEditApp();
virtual void MessageReceived(BMessage *message);
virtual void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
int32 NumberOfWindows();
void OpenDocument();
void OpenDocument(entry_ref * ref);
+21 -18
View File
@@ -687,30 +687,33 @@ StyledEditWindow::OpenFile(entry_ref *ref)
BFile file;
status_t fileinit;
fileinit= file.SetTo(ref, B_READ_ONLY);
fileinit = file.SetTo(ref, B_READ_ONLY);
if (fileinit == B_OK){
status_t result;
result = fTextView->GetStyledText(&file); //he he he :)
if (result == B_OK) {
be_roster->AddToRecentDocuments(ref,APP_SIGNATURE);
fSaveMessage= new BMessage(B_SAVE_REQUESTED);
if(fSaveMessage){
BEntry entry(ref, true);
BEntry parent;
entry_ref parentRef;
char name[B_FILE_NAME_LENGTH];
entry.GetParent(&parent);
entry.GetName(name);
parent.GetRef(&parentRef);
fSaveMessage->AddRef("directory",&parentRef);
fSaveMessage->AddString("name", name);
SetTitle(name);
}
// TODO: notify user?
}
}
} else {
fSaveItem->SetEnabled(true); // allow saving new files
}
be_roster->AddToRecentDocuments(ref,APP_SIGNATURE);
fSaveMessage = new BMessage(B_SAVE_REQUESTED);
if(fSaveMessage){
BEntry entry(ref, true);
BEntry parent;
entry_ref parentRef;
char name[B_FILE_NAME_LENGTH];
entry.GetParent(&parent);
entry.GetName(name);
parent.GetRef(&parentRef);
fSaveMessage->AddRef("directory",&parentRef);
fSaveMessage->AddString("name", name);
SetTitle(name);
}
}/*** StyledEditWindow::OpenFile() ***/
void