Fixed a whole lot of font sensitivity (and some other minor, like the "Show Contents"

menu label update) issues of the main window (didn't touch the rest yet) - shame on
you, Korli ;-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16971 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-02 18:31:30 +00:00
parent 3647d70ded
commit 0e6b056fdc
3 changed files with 249 additions and 176 deletions
+20 -14
View File
@@ -2,36 +2,32 @@
* Copyright 2004-2006, Jérôme DUVAL. All rights reserved. * Copyright 2004-2006, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <Alert.h>
#include "ExpanderApp.h" #include "ExpanderApp.h"
#include "ExpanderWindow.h" #include "ExpanderWindow.h"
const char *APP_SIG = "application/x-vnd.haiku-Expander"; #include <Alert.h>
#include <TextView.h>
int main(int, char **)
{
ExpanderApp theApp;
theApp.Run();
return 0;
}
ExpanderApp::ExpanderApp() ExpanderApp::ExpanderApp()
: BApplication(APP_SIG) : BApplication("application/x-vnd.haiku-Expander")
{ {
BPoint windowPosition = fSettings.Message().FindPoint("window_position"); BPoint windowPosition = fSettings.Message().FindPoint("window_position");
BRect windowFrame(0,0,450,120); BRect windowFrame(0, 0, 450, 120);
windowFrame.OffsetBy(windowPosition); windowFrame.OffsetBy(windowPosition);
BMessage settings(fSettings.Message()); BMessage settings(fSettings.Message());
fWindow = new ExpanderWindow(windowFrame, NULL, &settings); fWindow = new ExpanderWindow(windowFrame, NULL, &settings);
} }
void void
ExpanderApp::AboutRequested() ExpanderApp::AboutRequested()
{ {
BAlert *alert = new BAlert("about", "Expand-O-Matic\n" BAlert *alert = new BAlert("about", "Expand-O-Matic\n"
"\twritten by Jérôme Duval\n" "\twritten by Jérôme Duval\n"
"\tCopyright 2004, OpenBeOS.\n\n" "\tCopyright 2004-2006, Haiku Inc.\n\n"
"original Be version by \n" "original Be version by \n"
"Dominic, Hiroshi, Peter, Pavel and Robert\n", "Ok"); "Dominic, Hiroshi, Peter, Pavel and Robert\n", "Ok");
BTextView *view = alert->TextView(); BTextView *view = alert->TextView();
@@ -45,14 +41,12 @@ ExpanderApp::AboutRequested()
view->SetFontAndColor(0, 14, &font); view->SetFontAndColor(0, 14, &font);
alert->Go(); alert->Go();
} }
void void
ExpanderApp::ReadyToRun() ExpanderApp::ReadyToRun()
{ {
} }
@@ -90,3 +84,15 @@ ExpanderApp::UpdateSettingsFrom(BMessage *message)
{ {
fSettings.UpdateFrom(message); fSettings.UpdateFrom(message);
} }
// #pragma mark -
int
main(int, char **)
{
ExpanderApp theApp;
theApp.Run();
return 0;
}
+219 -156
View File
@@ -2,38 +2,41 @@
* Copyright 2004-2006, Jérôme DUVAL. All rights reserved. * Copyright 2004-2006, Jérôme DUVAL. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <Entry.h>
#include <File.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Path.h>
#include <Screen.h>
#include <Alert.h>
#include <SupportDefs.h>
#include "ExpanderApp.h" #include "ExpanderApp.h"
#include "ExpanderWindow.h" #include "ExpanderWindow.h"
#include "ExpanderThread.h" #include "ExpanderThread.h"
#include "ExpanderPreferences.h" #include "ExpanderPreferences.h"
#include <Alert.h>
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <CheckBox.h>
#include <Entry.h>
#include <File.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Path.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextView.h>
const uint32 MSG_SOURCE = 'mSOU'; const uint32 MSG_SOURCE = 'mSOU';
const uint32 MSG_DEST = 'mDES'; const uint32 MSG_DEST = 'mDES';
const uint32 MSG_EXPAND = 'mEXP'; const uint32 MSG_EXPAND = 'mEXP';
const uint32 MSG_SHOW = 'mSHO'; const uint32 MSG_SHOW = 'mSHO';
const uint32 MSG_STOP = 'mSTO'; const uint32 MSG_STOP = 'mSTO';
const uint32 MSG_CLOSE = 'mCLO';
const uint32 MSG_PREFERENCES = 'mPRE'; const uint32 MSG_PREFERENCES = 'mPRE';
const uint32 MSG_SOURCETEXT = 'mSTX'; const uint32 MSG_SOURCETEXT = 'mSTX';
const uint32 MSG_DESTTEXT = 'mDTX'; const uint32 MSG_DESTTEXT = 'mDTX';
const uint32 MSG_SHOWCONTENTS = 'mSCT'; const uint32 MSG_SHOWCONTENTS = 'mSCT';
ExpanderWindow::ExpanderWindow(BRect frame_rect, const entry_ref *ref, BMessage *settings)
: BWindow(frame_rect, "Expand-O-Matic", B_TITLED_WINDOW, B_NOT_ZOOMABLE), ExpanderWindow::ExpanderWindow(BRect frame, const entry_ref *ref, BMessage *settings)
: BWindow(frame, "Expand-O-Matic", B_TITLED_WINDOW, B_NOT_ZOOMABLE),
fSourceChanged(true), fSourceChanged(true),
fListingThread(NULL), fListingThread(NULL),
fListingStarted(false), fListingStarted(false),
@@ -44,7 +47,7 @@ ExpanderWindow::ExpanderWindow(BRect frame_rect, const entry_ref *ref, BMessage
{ {
fSourcePanel = NULL; fSourcePanel = NULL;
fDestPanel = NULL; fDestPanel = NULL;
// create menu bar // create menu bar
fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar"); fBar = new BMenuBar(BRect(0, 0, Bounds().right, 20), "menu_bar");
BMenu *menu = new BMenu("File"); BMenu *menu = new BMenu("File");
@@ -63,94 +66,112 @@ ExpanderWindow::ExpanderWindow(BRect frame_rect, const entry_ref *ref, BMessage
menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K')); menu->AddItem(fStopItem = new BMenuItem("Stop", new BMessage(MSG_STOP), 'K'));
fStopItem->SetEnabled(false); fStopItem->SetEnabled(false);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Close", new BMessage(MSG_CLOSE), 'W')); menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
fBar->AddItem(menu); fBar->AddItem(menu);
menu = new BMenu("Edit"); menu = new BMenu("Edit");
menu->AddItem(fPreferencesItem = new BMenuItem("Preferences...", new BMessage(MSG_PREFERENCES), 'P')); menu->AddItem(fPreferencesItem = new BMenuItem("Preferences...",
new BMessage(MSG_PREFERENCES), 'P'));
fBar->AddItem(menu); fBar->AddItem(menu);
AddChild(fBar); AddChild(fBar);
BRect rect = Bounds(); BRect rect = Bounds();
rect.top += fBar->Bounds().Height() + 1; rect.top += fBar->Bounds().Height() + 1;
BBox *box = new BBox(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); BView *topView = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW);
AddChild(box); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
float size = 8 + be_plain_font->StringWidth("Destination")/2; // Buttons
rect = BRect(42 - size, 10, 42 + size, 25);
fSourceButton = new BButton(rect, "sourceButton", "Source", rect = topView->Bounds().InsetByCopy(8, 8);
new BMessage(MSG_SOURCE), B_FOLLOW_LEFT | B_FOLLOW_TOP);
box->AddChild(fSourceButton);
rect.OffsetBy(0, 28);
fDestButton = new BButton(rect, "destButton", "Destination", fDestButton = new BButton(rect, "destButton", "Destination",
new BMessage(MSG_DEST), B_FOLLOW_LEFT | B_FOLLOW_TOP); new BMessage(MSG_DEST), B_FOLLOW_LEFT | B_FOLLOW_TOP);
box->AddChild(fDestButton); fDestButton->ResizeToPreferred();
rect.OffsetBy(0, 28); topView->AddChild(fDestButton);
rect = fDestButton->Frame();
fDestButton->MoveBy(0, rect.Height() + 4);
fSourceButton = new BButton(rect, "sourceButton", "Source",
new BMessage(MSG_SOURCE), B_FOLLOW_LEFT | B_FOLLOW_TOP);
topView->AddChild(fSourceButton);
rect = fDestButton->Frame();
rect.OffsetBy(0, rect.Height() + 4);
fExpandButton = new BButton(rect, "expandButton", "Expand", fExpandButton = new BButton(rect, "expandButton", "Expand",
new BMessage(MSG_EXPAND), B_FOLLOW_LEFT | B_FOLLOW_TOP); new BMessage(MSG_EXPAND), B_FOLLOW_LEFT | B_FOLLOW_TOP);
box->AddChild(fExpandButton); topView->AddChild(fExpandButton);
fExpandButton->SetEnabled(false); fExpandButton->SetEnabled(false);
rect = BRect(rect.right+5, 12, Bounds().right - 10, 25); // TextControls
rect = fSourceButton->Frame();
rect.left = rect.right + 5;
rect.right = frame.Width() - 8;
fSourceText = new BTextControl(rect, "sourceText", "", NULL, fSourceText = new BTextControl(rect, "sourceText", "", NULL,
new BMessage(MSG_SOURCETEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); new BMessage(MSG_SOURCETEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
fSourceText->SetDivider(0); fSourceText->SetDivider(0);
box->AddChild(fSourceText); float width, height;
fSourceText->GetPreferredSize(&width, &height);
rect.OffsetBy(0, 28); fSourceText->ResizeTo(rect.Width(), height);
float offset = (rect.Height() - fSourceText->Bounds().Height()) / 2;
fSourceText->MoveBy(0, offset);
topView->AddChild(fSourceText);
rect = fSourceText->Frame();
rect.OffsetBy(0, fSourceButton->Bounds().Height() + 4);
fDestText = new BTextControl(rect, "destText", "", NULL, fDestText = new BTextControl(rect, "destText", "", NULL,
new BMessage(MSG_DESTTEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); new BMessage(MSG_DESTTEXT), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
fDestText->SetDivider(0); fDestText->SetDivider(0);
box->AddChild(fDestText); topView->AddChild(fDestText);
BRect frameRect = rect.OffsetByCopy(0, 27); rect.OffsetBy(0, fSourceButton->Bounds().Height() + 4 + offset);
frameRect.left += 4;
frameRect.right = frameRect.left + 250;
BRect textRect(frameRect);
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(1,1);
fExpandedText = new BTextView(frameRect, "expandedText", textRect,
be_plain_font, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
fExpandedText->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fExpandedText->MakeEditable(false);
fExpandedText->MakeSelectable(false);
box->AddChild(fExpandedText);
fExpandedText->SetText("");
rect = BRect(Bounds().right - 38 - be_plain_font->StringWidth("Show Contents"), rect.bottom + 13, Bounds().right - 10, rect.bottom + 28);
fShowContents = new BCheckBox(rect, "showContents", "Show Contents", fShowContents = new BCheckBox(rect, "showContents", "Show Contents",
new BMessage(MSG_SHOWCONTENTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP); new BMessage(MSG_SHOWCONTENTS), B_FOLLOW_RIGHT | B_FOLLOW_TOP);
box->AddChild(fShowContents); fShowContents->ResizeToPreferred();
fShowContents->MoveTo(Bounds().right - 8 - fShowContents->Bounds().Width(),
rect.top);
topView->AddChild(fShowContents);
fShowContents->SetEnabled(false); fShowContents->SetEnabled(false);
frameRect = Bounds(); rect.left = fExpandButton->Frame().right + 5;
frameRect.InsetBy(10, 0); rect.right = fShowContents->Frame().left - 4;
frameRect.top += frameRect.Height() - 21; fStatusView = new BStringView(rect, "statusView", "",
frameRect.bottom = frameRect.top + 100; B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS);
frameRect.right -= B_V_SCROLL_BAR_WIDTH; topView->AddChild(fStatusView);
textRect = frameRect; ResizeTo(frame.Width(), topView->Frame().top + fExpandButton->Frame().bottom + 8);
SetSizeLimits(fExpandButton->Bounds().Width() * 3 + fShowContents->Bounds().Width() + 24,
32767.0f, Frame().Height(), Frame().Height());
rect = topView->Bounds();
rect.InsetBy(10, 0);
rect.top = rect.bottom + 2;
rect.bottom -= 10;
rect.right -= B_V_SCROLL_BAR_WIDTH;
BRect textRect = rect;
textRect.OffsetTo(B_ORIGIN); textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(1,1); textRect.InsetBy(1, 1);
fListingText = new BTextView(frameRect, "listingText", textRect, fListingText = new BTextView(rect, "listingText", textRect,
be_fixed_font, NULL, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS); be_fixed_font, NULL, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS);
fListingText->SetText(""); fListingText->SetText("");
fListingText->MakeEditable(false); fListingText->MakeEditable(false);
fListingScroll = new BScrollView("listingScroll", fListingText, fListingScroll = new BScrollView("listingScroll", fListingText,
B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true); B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, false, true);
box->AddChild(fListingScroll); topView->AddChild(fListingScroll);
fListingScroll->Hide(); fListingScroll->Hide();
SetSizeLimits(450, BScreen(this).Frame().Width(), 120, 120);
// finish creating window // finish creating window
Show(); Show();
} }
ExpanderWindow::~ExpanderWindow() ExpanderWindow::~ExpanderWindow()
{ {
} }
void void
ExpanderWindow::FrameResized(float width, float height) ExpanderWindow::FrameResized(float width, float height)
{ {
@@ -158,52 +179,55 @@ ExpanderWindow::FrameResized(float width, float height)
BRect textRect; BRect textRect;
textRect = fListingText->Bounds(); textRect = fListingText->Bounds();
textRect.OffsetTo(B_ORIGIN); textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(1,1); textRect.InsetBy(1, 1);
fListingText->SetTextRect(textRect); fListingText->SetTextRect(textRect);
} }
} }
void void
ExpanderWindow::MessageReceived(BMessage *msg) ExpanderWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what) { switch (msg->what) {
case MSG_SOURCE: case MSG_SOURCE:
if (!fSourcePanel) if (!fSourcePanel) {
fSourcePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, fSourcePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL,
B_FILE_NODE, false, NULL, new RuleRefFilter(fRules), true); B_FILE_NODE, false, NULL, new RuleRefFilter(fRules), true);
}
fSourcePanel->Show(); fSourcePanel->Show();
break; break;
case MSG_DEST: case MSG_DEST:
if (!fDestPanel) if (!fDestPanel) {
fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, fDestPanel = new DirectoryFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL,
B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true); B_DIRECTORY_NODE, false, NULL, new DirectoryRefFilter(), true);
}
fDestPanel->Show(); fDestPanel->Show();
break; break;
case MSG_DIRECTORY: case MSG_DIRECTORY:
{
entry_ref ref;
fDestPanel->GetPanelDirectory(&ref);
fDestRef = ref;
BEntry entry(&ref);
BPath path(&entry);
fDestText->SetText(path.Path());
fDestPanel->Hide();
}
break;
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
{ {
RefsReceived(msg); entry_ref ref;
fDestPanel->GetPanelDirectory(&ref);
fDestRef = ref;
BEntry entry(&ref);
BPath path(&entry);
fDestText->SetText(path.Path());
fDestPanel->Hide();
break; break;
} }
case MSG_CLOSE:
PostMessage(B_QUIT_REQUESTED); case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
RefsReceived(msg);
break; break;
case MSG_EXPAND: case MSG_EXPAND:
if (!fExpandingStarted) { if (!fExpandingStarted) {
StartExpanding(); StartExpanding();
break; break;
} }
// supposed to fall through
case MSG_STOP: case MSG_STOP:
if (fExpandingStarted) { if (fExpandingStarted) {
fExpandingThread->SuspendExternalExpander(); fExpandingThread->SuspendExternalExpander();
@@ -217,19 +241,25 @@ ExpanderWindow::MessageReceived(BMessage *msg)
fExpandingThread->ResumeExternalExpander(); fExpandingThread->ResumeExternalExpander();
} }
break; break;
case MSG_SHOW: case MSG_SHOW:
fShowContents->SetValue(fShowContents->Value() == B_CONTROL_OFF ? B_CONTROL_ON : B_CONTROL_OFF); fShowContents->SetValue(fShowContents->Value() == B_CONTROL_OFF
fShowItem->SetLabel(fShowContents->Value() == B_CONTROL_OFF ? "Show Contents" : "Hide Contents"); ? B_CONTROL_ON : B_CONTROL_OFF);
// supposed to fall through
case MSG_SHOWCONTENTS: case MSG_SHOWCONTENTS:
// change menu item label
fShowItem->SetLabel(fShowContents->Value() == B_CONTROL_OFF
? "Show Contents" : "Hide Contents");
if (fShowContents->Value() == B_CONTROL_OFF) { if (fShowContents->Value() == B_CONTROL_OFF) {
if (fListingStarted) if (fListingStarted)
StopListing(); StopListing();
SetSizeLimits(450, BScreen().Frame().Width(), 120, 120);
ResizeTo(Frame().Width(), 120); _UpdateWindowSize(false);
fShowItem->SetLabel("Show Contents");
} else } else
StartListing(); StartListing();
break; break;
case MSG_SOURCETEXT: case MSG_SOURCETEXT:
{ {
BEntry entry(fSourceText->Text(), true); BEntry entry(fSourceText->Text(), true);
@@ -299,7 +329,7 @@ ExpanderWindow::MessageReceived(BMessage *msg)
case 'exit': // thread has finished (finished, quit, killed, we don't know) case 'exit': // thread has finished (finished, quit, killed, we don't know)
// reset window state // reset window state
if (fExpandingStarted) { if (fExpandingStarted) {
fExpandedText->SetText("File expanded"); fStatusView->SetText("File expanded");
StopExpanding(); StopExpanding();
OpenDestFolder(); OpenDestFolder();
CloseWindowOrKeepOpen(); CloseWindowOrKeepOpen();
@@ -307,12 +337,12 @@ ExpanderWindow::MessageReceived(BMessage *msg)
fSourceChanged = false; fSourceChanged = false;
StopListing(); StopListing();
} else } else
fExpandedText->SetText(""); fStatusView->SetText("");
break; break;
case 'exrr': // thread has finished case 'exrr': // thread has finished
// reset window state // reset window state
fExpandedText->SetText("Error when expanding archive"); fStatusView->SetText("Error when expanding archive");
CloseWindowOrKeepOpen(); CloseWindowOrKeepOpen();
break; break;
default: default:
@@ -321,13 +351,14 @@ ExpanderWindow::MessageReceived(BMessage *msg)
} }
} }
bool bool
ExpanderWindow::CanQuit() ExpanderWindow::CanQuit()
{ {
if ((fSourcePanel && fSourcePanel->IsShowing()) if ((fSourcePanel && fSourcePanel->IsShowing())
|| (fDestPanel && fDestPanel->IsShowing())) || (fDestPanel && fDestPanel->IsShowing()))
return false; return false;
if (fExpandingStarted) { if (fExpandingStarted) {
fExpandingThread->SuspendExternalExpander(); fExpandingThread->SuspendExternalExpander();
BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n" BAlert *alert = new BAlert("stopAlert", "Are you sure you want to stop expanding this\n"
@@ -344,36 +375,36 @@ ExpanderWindow::CanQuit()
return true; return true;
} }
bool bool
ExpanderWindow::QuitRequested() ExpanderWindow::QuitRequested()
{ {
if (!CanQuit()) if (!CanQuit())
return false; return false;
if (fListingStarted) { if (fListingStarted)
StopListing(); StopListing();
}
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
fSettings.ReplacePoint("window_position", Frame().LeftTop()); fSettings.ReplacePoint("window_position", Frame().LeftTop());
((ExpanderApp*)(be_app))->UpdateSettingsFrom(&fSettings); ((ExpanderApp*)(be_app))->UpdateSettingsFrom(&fSettings);
return true; return true;
} }
void
void
ExpanderWindow::RefsReceived(BMessage *msg) ExpanderWindow::RefsReceived(BMessage *msg)
{ {
entry_ref ref; entry_ref ref;
int32 i = 0; int32 i = 0;
int8 destination_folder = 0x63; int8 destination_folder = 0x63;
fSettings.FindInt8("destination_folder", &destination_folder); fSettings.FindInt8("destination_folder", &destination_folder);
while (msg->FindRef("refs", i++, &ref) == B_OK) { while (msg->FindRef("refs", i++, &ref) == B_OK) {
BEntry entry(&ref, true); BEntry entry(&ref, true);
BPath path(&entry); BPath path(&entry);
BNode node(&entry); BNode node(&entry);
if (node.IsFile()) { if (node.IsFile()) {
fSourceChanged = true; fSourceChanged = true;
fSourceRef = ref; fSourceRef = ref;
@@ -389,13 +420,13 @@ ExpanderWindow::RefsReceived(BMessage *msg)
BPath dPath(&dEntry); BPath dPath(&dEntry);
fDestText->SetText(dPath.Path()); fDestText->SetText(dPath.Path());
} }
BEntry dEntry(&fDestRef, true); BEntry dEntry(&fDestRef, true);
if (dEntry.Exists()) { if (dEntry.Exists()) {
fExpandButton->SetEnabled(true); fExpandButton->SetEnabled(true);
fExpandItem->SetEnabled(true); fExpandItem->SetEnabled(true);
} }
if (fShowContents->Value() == B_CONTROL_ON) { if (fShowContents->Value() == B_CONTROL_ON) {
StopListing(); StopListing();
StartListing(); StartListing();
@@ -405,7 +436,7 @@ ExpanderWindow::RefsReceived(BMessage *msg)
} }
bool fromApp; bool fromApp;
if (msg->FindBool("fromApp", &fromApp)==B_OK) { if (msg->FindBool("fromApp", &fromApp) == B_OK) {
AutoExpand(); AutoExpand();
} else } else
AutoListing(); AutoListing();
@@ -416,16 +447,14 @@ ExpanderWindow::RefsReceived(BMessage *msg)
} }
} }
void void
ExpanderWindow::StartExpanding() ExpanderWindow::StartExpanding()
{ {
BMessage message;
ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); ExpanderRule *rule = fRules.MatchingRule(&fSourceRef);
if (!rule) { if (!rule)
return; return;
}
BEntry destEntry(fDestText->Text(), true); BEntry destEntry(fDestText->Text(), true);
if (!destEntry.Exists()) { if (!destEntry.Exists()) {
BAlert *alert = new BAlert("destAlert", "The directory was either moved, renamed or not\n" BAlert *alert = new BAlert("destAlert", "The directory was either moved, renamed or not\n"
@@ -435,11 +464,12 @@ ExpanderWindow::StartExpanding()
alert->Go(); alert->Go();
return; return;
} }
BMessage message;
message.AddString("cmd", rule->ExpandCmd()); message.AddString("cmd", rule->ExpandCmd());
message.AddRef("srcRef", &fSourceRef); message.AddRef("srcRef", &fSourceRef);
message.AddRef("destRef", &fDestRef); message.AddRef("destRef", &fDestRef);
fExpandButton->SetLabel("Stop"); fExpandButton->SetLabel("Stop");
fSourceButton->SetEnabled(false); fSourceButton->SetEnabled(false);
fDestButton->SetEnabled(false); fDestButton->SetEnabled(false);
@@ -450,19 +480,20 @@ ExpanderWindow::StartExpanding()
fShowItem->SetEnabled(false); fShowItem->SetEnabled(false);
fStopItem->SetEnabled(true); fStopItem->SetEnabled(true);
fPreferencesItem->SetEnabled(false); fPreferencesItem->SetEnabled(false);
BEntry entry(&fSourceRef); BEntry entry(&fSourceRef);
BPath path(&entry); BPath path(&entry);
BString text("Expanding file "); BString text("Expanding file ");
text.Append(path.Leaf()); text.Append(path.Leaf());
fExpandedText->SetText(text.String()); fStatusView->SetText(text.String());
fExpandingThread = new ExpanderThread(&message, new BMessenger(this)); fExpandingThread = new ExpanderThread(&message, new BMessenger(this));
fExpandingThread->Start(); fExpandingThread->Start();
fExpandingStarted = true; fExpandingStarted = true;
} }
void void
ExpanderWindow::StopExpanding(void) ExpanderWindow::StopExpanding(void)
{ {
@@ -472,7 +503,7 @@ ExpanderWindow::StopExpanding(void)
} }
fExpandingStarted = false; fExpandingStarted = false;
fExpandButton->SetLabel("Expand"); fExpandButton->SetLabel("Expand");
fSourceButton->SetEnabled(true); fSourceButton->SetEnabled(true);
fDestButton->SetEnabled(true); fDestButton->SetEnabled(true);
@@ -485,27 +516,52 @@ ExpanderWindow::StopExpanding(void)
fPreferencesItem->SetEnabled(true); fPreferencesItem->SetEnabled(true);
} }
void
ExpanderWindow::_UpdateWindowSize(bool showContents)
{
float minWidth, maxWidth, minHeight, maxHeight;
GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
float bottom = fExpandButton->Parent()->Frame().top + fExpandButton->Frame().bottom + 8;
if (showContents) {
font_height fontHeight;
be_plain_font->GetHeight(&fontHeight);
float lineHeight = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading);
minHeight = bottom + 14 + 4 * lineHeight;
maxHeight = 32767.0;
bottom = minHeight + 10 * lineHeight;
} else {
minHeight = bottom;
maxHeight = bottom;
}
SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);
ResizeTo(Frame().Width(), bottom);
}
void void
ExpanderWindow::StartListing() ExpanderWindow::StartListing()
{ {
SetSizeLimits(450, BScreen().Frame().Width(), 335, BScreen().Frame().Height()); _UpdateWindowSize(true);
ResizeTo(Frame().Width(), 335);
fListingScroll->ResizeTo(fListingScroll->Bounds().Width(), 210);
if (fListingScroll->IsHidden()) if (fListingScroll->IsHidden())
fListingScroll->Show(); fListingScroll->Show();
if (!fSourceChanged) if (!fSourceChanged)
return; return;
BMessage message;
ExpanderRule *rule = fRules.MatchingRule(&fSourceRef); ExpanderRule *rule = fRules.MatchingRule(&fSourceRef);
if (!rule) { if (!rule)
return; return;
}
BMessage message;
message.AddString("cmd", rule->ListingCmd()); message.AddString("cmd", rule->ListingCmd());
message.AddRef("srcRef", &fSourceRef); message.AddRef("srcRef", &fSourceRef);
fShowContents->SetEnabled(true); fShowContents->SetEnabled(true);
fSourceItem->SetEnabled(false); fSourceItem->SetEnabled(false);
fDestItem->SetEnabled(false); fDestItem->SetEnabled(false);
@@ -514,24 +570,25 @@ ExpanderWindow::StartListing()
fShowItem->SetLabel("Hide Contents"); fShowItem->SetLabel("Hide Contents");
fStopItem->SetEnabled(false); fStopItem->SetEnabled(false);
fPreferencesItem->SetEnabled(false); fPreferencesItem->SetEnabled(false);
fSourceButton->SetEnabled(false); fSourceButton->SetEnabled(false);
fDestButton->SetEnabled(false); fDestButton->SetEnabled(false);
fExpandButton->SetEnabled(false); fExpandButton->SetEnabled(false);
BEntry entry(&fSourceRef); BEntry entry(&fSourceRef);
BPath path(&entry); BPath path(&entry);
BString text("Creating listing for "); BString text("Creating listing for ");
text.Append(path.Leaf()); text.Append(path.Leaf());
fExpandedText->SetText(text.String()); fStatusView->SetText(text.String());
fListingText->SetText(""); fListingText->SetText("");
fListingThread = new ExpanderThread(&message, new BMessenger(this)); fListingThread = new ExpanderThread(&message, new BMessenger(this));
fListingThread->Start(); fListingThread->Start();
fListingStarted = true; fListingStarted = true;
} }
void void
ExpanderWindow::StopListing(void) ExpanderWindow::StopListing(void)
{ {
@@ -541,7 +598,7 @@ ExpanderWindow::StopListing(void)
} }
fListingStarted = false; fListingStarted = false;
fShowContents->SetEnabled(true); fShowContents->SetEnabled(true);
fSourceItem->SetEnabled(true); fSourceItem->SetEnabled(true);
fDestItem->SetEnabled(true); fDestItem->SetEnabled(true);
@@ -553,59 +610,65 @@ ExpanderWindow::StopListing(void)
fSourceButton->SetEnabled(true); fSourceButton->SetEnabled(true);
fDestButton->SetEnabled(true); fDestButton->SetEnabled(true);
fExpandButton->SetEnabled(true); fExpandButton->SetEnabled(true);
fExpandedText->SetText(""); fStatusView->SetText("");
} }
void void
ExpanderWindow::CloseWindowOrKeepOpen() ExpanderWindow::CloseWindowOrKeepOpen()
{ {
bool automatically_expand_files = false; bool expandFiles = false;
fSettings.FindBool("automatically_expand_files", &automatically_expand_files); fSettings.FindBool("automatically_expand_files", &expandFiles);
bool close_when_done = false;
fSettings.FindBool("close_when_done", &close_when_done); bool closeWhenDone = false;
if (automatically_expand_files || close_when_done) fSettings.FindBool("close_when_done", &closeWhenDone);
if (expandFiles || closeWhenDone)
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
} }
void void
ExpanderWindow::OpenDestFolder() ExpanderWindow::OpenDestFolder()
{ {
bool open_destination_folder = true; bool openFolder = true;
fSettings.FindBool("open_destination_folder", &open_destination_folder); fSettings.FindBool("open_destination_folder", &openFolder);
if (!open_destination_folder) if (!openFolder)
return; return;
BMessage * message = new BMessage(B_REFS_RECEIVED); BMessage * message = new BMessage(B_REFS_RECEIVED);
message->AddRef("refs", &fDestRef); message->AddRef("refs", &fDestRef);
BPath path(&fDestRef); BPath path(&fDestRef);
BMessenger tracker( "application/x-vnd.Be-TRAK" ); BMessenger tracker("application/x-vnd.Be-TRAK");
tracker.SendMessage( message ); tracker.SendMessage(message);
} }
void void
ExpanderWindow::AutoListing() ExpanderWindow::AutoListing()
{ {
bool show_contents_listing = false; bool showContents = false;
fSettings.FindBool("show_contents_listing", &show_contents_listing); fSettings.FindBool("show_contents_listing", &showContents);
if (!show_contents_listing) if (!showContents)
return; return;
fShowContents->SetValue(B_CONTROL_ON); fShowContents->SetValue(B_CONTROL_ON);
fShowContents->Invoke(); fShowContents->Invoke();
} }
void void
ExpanderWindow::AutoExpand() ExpanderWindow::AutoExpand()
{ {
bool automatically_expand_files = false; bool expandFiles = false;
fSettings.FindBool("automatically_expand_files", &automatically_expand_files); fSettings.FindBool("automatically_expand_files", &expandFiles);
if (!automatically_expand_files) { if (!expandFiles) {
AutoListing(); AutoListing();
return; return;
} }
fExpandButton->Invoke(); fExpandButton->Invoke();
} }
+10 -6
View File
@@ -9,15 +9,17 @@
#define EXPANDER_WINDOW_H #define EXPANDER_WINDOW_H
#include <CheckBox.h>
#include <Window.h>
#include <FilePanel.h>
#include <TextControl.h>
#include <ScrollView.h>
#include "DirectoryFilePanel.h" #include "DirectoryFilePanel.h"
#include "ExpanderRules.h" #include "ExpanderRules.h"
#include <Window.h>
class BCheckBox;
class BMenu; class BMenu;
class BScrollView;
class BStringView;
class BTextControl;
class BTextView;
class ExpanderThread; class ExpanderThread;
class ExpanderPreferences; class ExpanderPreferences;
@@ -44,6 +46,7 @@ class ExpanderWindow : public BWindow {
void AutoExpand(); void AutoExpand();
void StartExpanding(); void StartExpanding();
void StopExpanding(); void StopExpanding();
void _UpdateWindowSize(bool showContents);
void StartListing(); void StartListing();
void StopListing(); void StopListing();
@@ -60,7 +63,8 @@ class ExpanderWindow : public BWindow {
*fSourceItem, *fDestItem, *fPreferencesItem; *fSourceItem, *fDestItem, *fPreferencesItem;
BCheckBox *fShowContents; BCheckBox *fShowContents;
BTextControl *fSourceText, *fDestText; BTextControl *fSourceText, *fDestText;
BTextView *fExpandedText, *fListingText; BStringView* fStatusView;
BTextView *fListingText;
BScrollView *fListingScroll; BScrollView *fListingScroll;
ExpanderThread *fListingThread; ExpanderThread *fListingThread;