#include <sys/resource.h>
#include <BeBuild.h>
#include <Debug.h>
#include <FilePanel.h>
#include <Looper.h>
#include <Screen.h>
#include <Window.h>
#include "AutoLock.h"
#include "Commands.h"
#include "FilePanelPriv.h"
#ifndef _IMPEXP_ROOT
# define _IMPEXP_ROOT
#endif
BFilePanel::BFilePanel(file_panel_mode mode, BMessenger* target,
const entry_ref* ref, uint32 nodeFlavors, bool multipleSelection,
BMessage* message, BRefFilter* filter, bool modal,
bool hideWhenDone)
{
struct rlimit rl;
rl.rlim_cur = 512;
rl.rlim_max = RLIM_SAVED_MAX;
setrlimit(RLIMIT_NOFILE, &rl);
BEntry startDir(ref);
fWindow = new TFilePanel(mode, target, &startDir, nodeFlavors,
multipleSelection, message, filter, 0, B_DOCUMENT_WINDOW_LOOK,
(modal ? B_MODAL_APP_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL),
B_CURRENT_WORKSPACE, 0, hideWhenDone);
static_cast<TFilePanel*>(fWindow)->SetClientObject(this);
fWindow->SetIsFilePanel(true);
}
BFilePanel::~BFilePanel()
{
if (fWindow->Lock())
fWindow->Quit();
}
void
BFilePanel::Show()
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
uint32 workspace = 1UL << (uint32)current_workspace();
uint32 windowWorkspaces = fWindow->Workspaces();
if (!(windowWorkspaces & workspace)) {
fWindow->SetWorkspaces(workspace);
}
BWindow* parent = dynamic_cast<BWindow*>(
BLooper::LooperForThread(find_thread(NULL)));
if (parent != NULL)
fWindow->MoveTo(fWindow->AlertPosition(parent->Frame()));
else {
if (!static_cast<TFilePanel*>(fWindow)->DefaultStateRestored())
fWindow->MoveTo(fWindow->AlertPosition(BScreen(fWindow).Frame()));
}
if (!IsShowing())
fWindow->Show();
fWindow->Activate();
#if 1
fWindow->FindView("PoseView")->ResizeBy(1, 1);
fWindow->FindView("PoseView")->ResizeBy(-1, -1);
#endif
}
void
BFilePanel::Hide()
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
if (!fWindow->IsHidden())
fWindow->QuitRequested();
}
bool
BFilePanel::IsShowing() const
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return false;
return !fWindow->IsHidden();
}
void
BFilePanel::SendMessage(const BMessenger* messenger, BMessage* message)
{
messenger->SendMessage(message);
}
file_panel_mode
BFilePanel::PanelMode() const
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return B_OPEN_PANEL;
if (static_cast<TFilePanel*>(fWindow)->IsSavePanel())
return B_SAVE_PANEL;
return B_OPEN_PANEL;
}
BMessenger
BFilePanel::Messenger() const
{
BMessenger target;
AutoLock<BWindow> lock(fWindow);
if (!lock)
return target;
return *static_cast<TFilePanel*>(fWindow)->Target();
}
void
BFilePanel::SetTarget(BMessenger target)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetTarget(target);
}
void
BFilePanel::SetMessage(BMessage* message)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetMessage(message);
}
void
BFilePanel::Refresh()
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->Refresh();
}
BRefFilter*
BFilePanel::RefFilter() const
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return 0;
return static_cast<TFilePanel*>(fWindow)->Filter();
}
void
BFilePanel::SetRefFilter(BRefFilter* filter)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetRefFilter(filter);
}
void
BFilePanel::SetButtonLabel(file_panel_button button, const char* text)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetButtonLabel(button, text);
}
void
BFilePanel::SetNodeFlavors(uint32 flavors)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetNodeFlavors(flavors);
}
void
BFilePanel::GetPanelDirectory(entry_ref* ref) const
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
*ref = *static_cast<TFilePanel*>(fWindow)->TargetModel()->EntryRef();
}
void
BFilePanel::SetSaveText(const char* text)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetSaveText(text);
}
void
BFilePanel::SetPanelDirectory(const entry_ref* ref)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SwitchDirectory(ref);
}
void
BFilePanel::SetPanelDirectory(const char* path)
{
entry_ref ref;
status_t err = get_ref_for_path(path, &ref);
if (err < B_OK)
return;
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SwitchDirectory(&ref);
}
void
BFilePanel::SetPanelDirectory(const BEntry* entry)
{
entry_ref ref;
if (entry && entry->GetRef(&ref) == B_OK)
SetPanelDirectory(&ref);
}
void
BFilePanel::SetPanelDirectory(const BDirectory* dir)
{
BEntry entry;
if (dir && (dir->GetEntry(&entry) == B_OK))
SetPanelDirectory(&entry);
}
BWindow*
BFilePanel::Window() const
{
return fWindow;
}
void
BFilePanel::Rewind()
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->Rewind();
}
status_t
BFilePanel::GetNextSelectedRef(entry_ref* ref)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return B_ERROR;
return static_cast<TFilePanel*>(fWindow)->GetNextEntryRef(ref);
}
void
BFilePanel::SetHideWhenDone(bool on)
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return;
static_cast<TFilePanel*>(fWindow)->SetHideWhenDone(on);
}
bool
BFilePanel::HidesWhenDone(void) const
{
AutoLock<BWindow> lock(fWindow);
if (!lock)
return false;
return static_cast<TFilePanel*>(fWindow)->HidesWhenDone();
}
void
BFilePanel::WasHidden()
{
}
void
BFilePanel::SelectionChanged()
{
}