Skip to content

Commit

Permalink
Add drop support to AutoFiler folder list
Browse files Browse the repository at this point in the history
One or more drag&dropped folders are now added to AutoFiler's folder list.
If files are dropped, their parent folder is added instead.
Make sure no duplicate folders are added.
  • Loading branch information
Humdinger committed May 5, 2016
1 parent fcc10f9 commit 1959dc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
52 changes: 48 additions & 4 deletions sources/AutoFilerTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ AutoFilerTab::AutoFilerTab()
B_DIRECTORY_NODE, false, NULL, fRefFilter);
BMessage panelMsg(MSG_FOLDER_CHOSEN);
fFilePanel->SetMessage(&panelMsg);

gRefLock.Lock();
for (int32 i = 0; i < gRefStructList.CountItems(); i++)
{
RefStorage* refholder = (RefStorage*)gRefStructList.ItemAt(i);
fFolderList->AddItem(new BStringItem(BPath(&refholder->ref).Path()));
}
gRefLock.Unlock();

fFolderList->MakeFocus();
if (fFolderList->CountItems() > 0)
fFolderList->Select(0L);
Expand Down Expand Up @@ -181,6 +181,22 @@ AutoFilerTab::DetachedFromWindow()
void
AutoFilerTab::MessageReceived(BMessage* msg)
{
if (msg->WasDropped()) {
BMessenger msgr(this);
entry_ref tempRef;
int32 i = 0;
while (msg->FindRef("refs", i, &tempRef) == B_OK)
{
BEntry entry(&tempRef);
if (entry.Exists()) {
BMessage newMsg(MSG_FOLDER_CHOSEN);
newMsg.AddRef("refs", &tempRef);
msgr.SendMessage(&newMsg);
} else
printf("Couldn't find file %s\n",tempRef.name);
i++;
}
}
switch (msg->what)
{
case MSG_AUTOFILER_AUTORUN:
Expand Down Expand Up @@ -252,11 +268,23 @@ AutoFilerTab::MessageReceived(BMessage* msg)
int32 index;
if (msg->FindInt32("index", &index) != B_OK)
index = -1;

entry_ref ref;
if (msg->FindRef("refs", &ref) != B_OK)
break;


BEntry entry(&ref);
BPath path;
entry.GetPath(&path);
if (!entry.IsDirectory()) {
path.GetParent(&path);
get_ref_for_path(path.Path(), &ref);
}

BString newpath(path.Path());
if (!IsFolderUnique(newpath))
return;

BStringItem* item = (BStringItem*)fFolderList->ItemAt(index);
if (item) {
gRefLock.Lock();
Expand Down Expand Up @@ -284,6 +312,22 @@ AutoFilerTab::MessageReceived(BMessage* msg)
}


bool
AutoFilerTab::IsFolderUnique(BString newpath)
{
if (fFolderList->IsEmpty())
return true;

bool unique = true;
for (int i = 0; i < fFolderList->CountItems(); i++) {
BStringItem* sItem = (BStringItem*)fFolderList->ItemAt(i);
if (newpath.Compare(sItem->Text()) == 0)
unique = false;
}
return unique;
}


void
AutoFilerTab::ToggleAutoFiler()
{
Expand Down
1 change: 1 addition & 0 deletions sources/AutoFilerTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AutoFilerTab : public BView
void EnableAutorun();
void DisableAutorun();

bool IsFolderUnique(BString newpath);
void ToggleAutoFiler();
void UpdateAutoFilerLabel();

Expand Down

0 comments on commit 1959dc3

Please sign in to comment.