diff --git a/sources/AutoFiler.cpp b/sources/AutoFiler.cpp index e861628..72147f3 100644 --- a/sources/AutoFiler.cpp +++ b/sources/AutoFiler.cpp @@ -3,14 +3,18 @@ Written by DarkWyrm , Copyright 2008 Released under the MIT license. */ -#include "AutoFiler.h" + #include #include #include + +#include "AutoFiler.h" +#include "FilerDefs.h" #include "RefStorage.h" -App::App(void) - : BApplication("application/x-vnd.dw-AutoFiler") +App::App() + : + BApplication(kAutoFilerSignature) { LoadFolders(); StartWatching(); @@ -18,11 +22,11 @@ App::App(void) void -App::MessageReceived(BMessage *msg) +App::MessageReceived(BMessage* msg) { switch(msg->what) { - case M_REFRESH_FOLDERS: + case MSG_REFRESH_FOLDERS: { StopWatching(); ReloadFolders(); @@ -42,14 +46,14 @@ App::MessageReceived(BMessage *msg) void -App::StartWatching(void) +App::StartWatching() { gRefLock.Lock(); for (int32 i = 0; i < gRefStructList.CountItems(); i++) { - RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i); - watch_node(&refholder->nref,B_WATCH_ALL,this); + RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i); + watch_node(&refholder->nref, B_WATCH_ALL, this); } gRefLock.Unlock(); @@ -57,10 +61,10 @@ App::StartWatching(void) void -App::HandleNodeMonitoring(BMessage *msg) +App::HandleNodeMonitoring(BMessage* msg) { int32 op; - msg->FindInt32("opcode",&op); + msg->FindInt32("opcode", &op); switch (op) { @@ -69,14 +73,14 @@ App::HandleNodeMonitoring(BMessage *msg) BString name; entry_ref ref; - msg->FindInt32("device",&ref.device); - msg->FindInt64("directory",&ref.directory); - msg->FindString("name",&name); + msg->FindInt32("device", &ref.device); + msg->FindInt64("directory", &ref.directory); + msg->FindString("name", &name); ref.set_name(name.String()); BMessage args(B_REFS_RECEIVED); - args.AddRef("refs",&ref); - be_roster->Launch("application/x-vnd.dw-Filer",&args); + args.AddRef("refs", &ref); + be_roster->Launch(kFilerSignature, &args); break; } case B_ENTRY_MOVED: @@ -84,15 +88,15 @@ App::HandleNodeMonitoring(BMessage *msg) // We only care if we're monitoring the "to" directory because // the Filer doesn't care about files that aren't there anymore node_ref nref; - msg->FindInt32("device",&nref.device); - msg->FindInt64("to directory",&nref.node); + msg->FindInt32("device", &nref.device); + msg->FindInt64("to directory", &nref.node); gRefLock.Lock(); bool match = false; for (int32 i = 0; i < gRefStructList.CountItems(); i++) { - RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i); + RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i); if (nref == refholder->nref) { match = true; @@ -106,14 +110,14 @@ App::HandleNodeMonitoring(BMessage *msg) { BString name; entry_ref ref; - msg->FindString("name",&name); + msg->FindString("name", &name); ref.device = nref.device; ref.directory = nref.node; ref.set_name(name.String()); BMessage args(B_REFS_RECEIVED); - args.AddRef("refs",&ref); - be_roster->Launch("application/x-vnd.dw-Filer",&args); + args.AddRef("refs", &ref); + be_roster->Launch(kFilerSignature, &args); } break; } @@ -121,8 +125,8 @@ App::HandleNodeMonitoring(BMessage *msg) case B_ATTR_CHANGED: { node_ref nref; - msg->FindInt32("device",&nref.device); - msg->FindInt64("node",&nref.node); + msg->FindInt32("device", &nref.device); + msg->FindInt64("node", &nref.node); gRefLock.Lock(); @@ -130,7 +134,7 @@ App::HandleNodeMonitoring(BMessage *msg) entry_ref ref; for (int32 i = 0; i < gRefStructList.CountItems(); i++) { - RefStorage *refholder = (RefStorage*)gRefStructList.ItemAt(i); + RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i); if (nref == refholder->nref) { ref = refholder->ref; @@ -144,8 +148,8 @@ App::HandleNodeMonitoring(BMessage *msg) if (match) { BMessage args(B_REFS_RECEIVED); - args.AddRef("refs",&ref); - be_roster->Launch("application/x-vnd.dw-Filer",&args); + args.AddRef("refs", &ref); + be_roster->Launch(kFilerSignature, &args); } break; } @@ -156,16 +160,16 @@ App::HandleNodeMonitoring(BMessage *msg) void -App::StopWatching(void) +App::StopWatching() { stop_watching(this); } int -main(int argc, char **argv) +main(int argc, char** argv) { - App *app = new App; + App* app = new App; app->Run(); delete app; diff --git a/sources/AutoFiler.h b/sources/AutoFiler.h index 493dca8..0fc6bdf 100644 --- a/sources/AutoFiler.h +++ b/sources/AutoFiler.h @@ -3,8 +3,9 @@ Written by DarkWyrm , Copyright 2008 Released under the MIT license. */ -#ifndef MAIN_H -#define MAIN_H + +#ifndef AUTOFILER_H +#define AUTOFILER_H #include #include @@ -12,13 +13,13 @@ class App : public BApplication { public: - App(void); - void MessageReceived(BMessage *msg); + App(); + void MessageReceived(BMessage* msg); private: - void HandleNodeMonitoring(BMessage *msg); - void StartWatching(void); - void StopWatching(void); + void HandleNodeMonitoring(BMessage* msg); + void StartWatching(); + void StopWatching(); }; -#endif +#endif // AUTOFILER_H diff --git a/sources/AutoFilerTab.cpp b/sources/AutoFilerTab.cpp index 9c3a52c..dfa2c43 100644 --- a/sources/AutoFilerTab.cpp +++ b/sources/AutoFilerTab.cpp @@ -28,7 +28,8 @@ AutoFilerTab::AutoFilerTab() : - BView("AutoFiler", B_SUPPORTS_LAYOUT) + BView("AutoFiler", B_SUPPORTS_LAYOUT), + fDirtySettings(false) { LoadFolders(); _BuildLayout(); @@ -75,7 +76,8 @@ AutoFilerTab::_BuildLayout() fFolderList->SetInvocationMessage(new BMessage(MSG_SHOW_EDIT_PANEL)); fAutorunBox = new BCheckBox("autorunbox", - "Run AutoFiler on system startup", new BMessage); + "Run AutoFiler on system startup", + new BMessage(MSG_AUTOFILER_AUTORUN)); fStartStop = new BButton("startstop", "Start AutoFiler", new BMessage(MSG_STARTSTOP_AUTOFILER)); @@ -132,8 +134,7 @@ AutoFilerTab::_BuildLayout() void AutoFilerTab::AttachedToWindow() { -// SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE); - + fAutorunBox->SetTarget(this); fStartStop->SetTarget(this); fAddButton->SetTarget(this); fEditButton->SetTarget(this); @@ -157,6 +158,9 @@ AutoFilerTab::AttachedToWindow() void AutoFilerTab::DetachedFromWindow() { + if (!fDirtySettings) + return; + SaveFolders(); // save autorun value @@ -171,18 +175,7 @@ AutoFilerTab::DetachedFromWindow() node.WriteAttr("autorun", B_BOOL_TYPE, 0, (void*)&autorun, sizeof(bool)); } - if (autorun) - EnableAutorun(); - else - DisableAutorun(); - - // if AutoFiler is running, tell it to refresh its folders - if (be_roster->IsRunning("application/x-vnd.dw-AutoFiler")) - { - BMessage msg(MSG_REFRESH_FOLDERS); - BMessenger msgr("application/x-vnd.dw-AutoFiler"); - msgr.SendMessage(&msg); - } + ToggleAutorun(autorun); } @@ -191,6 +184,11 @@ AutoFilerTab::MessageReceived(BMessage* msg) { switch (msg->what) { + case MSG_AUTOFILER_AUTORUN: + { + ToggleAutorun(fAutorunBox->Value() == B_CONTROL_ON); + break; + } case MSG_STARTSTOP_AUTOFILER: { ToggleAutoFiler(); @@ -234,6 +232,8 @@ AutoFilerTab::MessageReceived(BMessage* msg) RefStorage* refholder = (RefStorage*)gRefStructList.RemoveItem(selection); delete refholder; gRefLock.Unlock(); + + UpdateAutoFilerFolders(); break; } case MSG_FOLDER_SELECTED: @@ -272,6 +272,8 @@ AutoFilerTab::MessageReceived(BMessage* msg) item->SetText(BPath(&ref).Path()); fFolderList->Invalidate(); + + UpdateAutoFilerFolders(); break; } default: @@ -305,6 +307,30 @@ AutoFilerTab::UpdateAutoFilerLabel() } +void +AutoFilerTab::UpdateAutoFilerFolders() +{ + fDirtySettings = true; + // if AutoFiler is running, tell it to refresh its folders + if (be_roster->IsRunning(kAutoFilerSignature)) { + BMessage msg(MSG_REFRESH_FOLDERS); + BMessenger msgr(kAutoFilerSignature); + msgr.SendMessage(&msg); + } +} + + +void +AutoFilerTab::ToggleAutorun(bool autorun) +{ + fDirtySettings = true; + if (autorun) + EnableAutorun(); + else + DisableAutorun(); +} + + void AutoFilerTab::EnableAutorun() { diff --git a/sources/AutoFilerTab.h b/sources/AutoFilerTab.h index a0bd171..7ba2fbb 100644 --- a/sources/AutoFilerTab.h +++ b/sources/AutoFilerTab.h @@ -32,6 +32,8 @@ class AutoFilerTab : public BView private: void _BuildLayout(); + void UpdateAutoFilerFolders(); + void ToggleAutorun(bool autorun); void EnableAutorun(); void DisableAutorun(); @@ -51,6 +53,8 @@ class AutoFilerTab : public BView BFilePanel* fFilePanel; TypedRefFilter* fRefFilter; BMessageRunner* fRunner; + + bool fDirtySettings; }; #endif // AUTOFILERTAB_H diff --git a/sources/DropZoneTab.cpp b/sources/DropZoneTab.cpp index 558ed52..379248f 100644 --- a/sources/DropZoneTab.cpp +++ b/sources/DropZoneTab.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -19,9 +21,6 @@ #include "main.h" #include "ReplicantWindow.h" - -#define REPLICATE 'repl' - void DropZone::_Init() { @@ -157,6 +156,11 @@ DropZone::MessageReceived(BMessage* msg) } switch (msg->what) { + case MSG_OPEN_FILER: + { + be_roster->Launch(kFilerSignature); + break; + } case B_ABOUT_REQUESTED: { BAboutWindow* about = new BAboutWindow("Filer", kFilerSignature); @@ -178,6 +182,37 @@ DropZone::MessageReceived(BMessage* msg) } +void +DropZone::MouseDown(BPoint position) +{ + uint32 buttons = 0; + if (Window() != NULL && Window()->CurrentMessage() != NULL) + buttons = Window()->CurrentMessage()->FindInt32("buttons"); + + if (buttons == B_SECONDARY_MOUSE_BUTTON) + ShowPopUpMenu(ConvertToScreen(position)); + + BView::MouseDown(position); +} + + +void +DropZone::ShowPopUpMenu(BPoint screen) +{ + if (!fReplicated) + return; + + BPopUpMenu* menu = new BPopUpMenu("PopUpMenu", this); + + BMenuItem* item = new BMenuItem("Open Filer" B_UTF8_ELLIPSIS, + new BMessage(MSG_OPEN_FILER)); + menu->AddItem(item); + + menu->SetTargetForItems(this); + menu->Go(screen, true, true, true); +} + + DropZoneTab::DropZoneTab() : BView("Dropzone", B_SUPPORTS_LAYOUT) @@ -188,7 +223,7 @@ DropZoneTab::DropZoneTab() fDropzone = new DropZone(false); fRepliButton = new BButton("replibutton", - "Replicate dropzone" B_UTF8_ELLIPSIS, new BMessage(REPLICATE)); + "Replicate dropzone" B_UTF8_ELLIPSIS, new BMessage(MSG_REPLICATE)); static const float spacing = be_control_look->DefaultItemSpacing(); BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING) @@ -218,9 +253,10 @@ DropZoneTab::MessageReceived(BMessage* msg) { switch (msg->what) { - case REPLICATE: + case MSG_REPLICATE: { - ReplicantWindow* replicantWindow = new ReplicantWindow(Window()->Frame()); + ReplicantWindow* replicantWindow + = new ReplicantWindow(Window()->Frame()); replicantWindow->Show(); break; } diff --git a/sources/DropZoneTab.h b/sources/DropZoneTab.h index 8cadcb1..cab6c83 100644 --- a/sources/DropZoneTab.h +++ b/sources/DropZoneTab.h @@ -27,10 +27,13 @@ class DropZone : public BView virtual void Draw(BRect rect); void MessageReceived(BMessage* msg); + void MouseDown(BPoint position); void _Init(); private: + void ShowPopUpMenu(BPoint screen); + bool fReplicated; BStringView* fLabel1; BStringView* fLabel2; diff --git a/sources/FilerDefs.h b/sources/FilerDefs.h index b3bdd63..f35167d 100644 --- a/sources/FilerDefs.h +++ b/sources/FilerDefs.h @@ -21,6 +21,9 @@ static const char kSettingsFile[] = "Filer_settings"; #define MSG_OK 'okay' #define MSG_CANCEL 'cncl' +#define MSG_REPLICATE 'repl' +#define MSG_OPEN_FILER 'opfi' + #define MSG_ADD_TEST 'adts' #define MSG_REMOVE_TEST 'rmts' #define MSG_ADD_ACTION 'adac' @@ -38,6 +41,7 @@ static const char kSettingsFile[] = "Filer_settings"; #define MSG_MOVE_RULE_DOWN 'mvdn' #define MSG_STARTSTOP_AUTOFILER 'ssaf' +#define MSG_AUTOFILER_AUTORUN 'afas' #define MSG_UPDATE_LABEL 'upla' #define MSG_SHOW_ADD_PANEL 'shap' #define MSG_SHOW_EDIT_PANEL 'shep' diff --git a/sources/RefStorage.cpp b/sources/RefStorage.cpp index 3067da5..86a36df 100644 --- a/sources/RefStorage.cpp +++ b/sources/RefStorage.cpp @@ -61,7 +61,7 @@ LoadFolders() entry_ref tempRef; int32 i = 0; - while (msg.FindRef("refs",i,&tempRef) == B_OK) + while (msg.FindRef("refs", i, &tempRef) == B_OK) { i++; RefStorage* refholder = new RefStorage(tempRef); diff --git a/sources/RefStorage.h b/sources/RefStorage.h index 16a1237..8b7b1fd 100644 --- a/sources/RefStorage.h +++ b/sources/RefStorage.h @@ -11,10 +11,6 @@ extern BList gRefStructList; extern BLocker gRefLock; extern const char gPrefsPath[]; -enum -{ - M_REFRESH_FOLDERS = 'rffl' -}; class RefStorage {