* Some reordering of methods to match declaration order.
* Some updating to new header indentation style * Improved consistency of asterix style in FileTypes.cpp. * Implemented passing -type some/type on the command line and having that type initially selected in the FileTypesWindow. (Unfortunately BOutlineListView::ScrollToSelection() is broken.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40472 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,52 +31,53 @@
|
|||||||
#define B_TRANSLATE_CONTEXT "FileTypes"
|
#define B_TRANSLATE_CONTEXT "FileTypes"
|
||||||
|
|
||||||
|
|
||||||
const char *kSignature = "application/x-vnd.Haiku-FileTypes";
|
const char* kSignature = "application/x-vnd.Haiku-FileTypes";
|
||||||
|
|
||||||
static const uint32 kMsgFileTypesSettings = 'FTst';
|
static const uint32 kMsgFileTypesSettings = 'FTst';
|
||||||
static const uint32 kCascadeOffset = 20;
|
static const uint32 kCascadeOffset = 20;
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings();
|
||||||
~Settings();
|
~Settings();
|
||||||
|
|
||||||
const BMessage &Message() const { return fMessage; }
|
const BMessage& Message() const { return fMessage; }
|
||||||
void UpdateFrom(BMessage *message);
|
void UpdateFrom(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _SetDefaults();
|
void _SetDefaults();
|
||||||
status_t _Open(BFile *file, int32 mode);
|
status_t _Open(BFile* file, int32 mode);
|
||||||
|
|
||||||
BMessage fMessage;
|
BMessage fMessage;
|
||||||
bool fUpdated;
|
bool fUpdated;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileTypes : public BApplication {
|
class FileTypes : public BApplication {
|
||||||
public:
|
public:
|
||||||
FileTypes();
|
FileTypes();
|
||||||
virtual ~FileTypes();
|
virtual ~FileTypes();
|
||||||
|
|
||||||
virtual void ReadyToRun();
|
virtual void ReadyToRun();
|
||||||
|
|
||||||
virtual void RefsReceived(BMessage* message);
|
virtual void RefsReceived(BMessage* message);
|
||||||
virtual void ArgvReceived(int32 argc, char** argv);
|
virtual void ArgvReceived(int32 argc, char** argv);
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
virtual void AboutRequested();
|
virtual void AboutRequested();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _WindowClosed();
|
void _WindowClosed();
|
||||||
|
|
||||||
Settings fSettings;
|
Settings fSettings;
|
||||||
BFilePanel *fFilePanel;
|
BFilePanel* fFilePanel;
|
||||||
BMessenger fFilePanelTarget;
|
BMessenger fFilePanelTarget;
|
||||||
BWindow *fTypesWindow;
|
FileTypesWindow* fTypesWindow;
|
||||||
BWindow *fApplicationTypesWindow;
|
BWindow* fApplicationTypesWindow;
|
||||||
uint32 fWindowCount;
|
uint32 fWindowCount;
|
||||||
uint32 fTypeWindowCount;
|
uint32 fTypeWindowCount;
|
||||||
|
BString fArgvType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -116,32 +117,7 @@ Settings::~Settings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::_SetDefaults()
|
Settings::UpdateFrom(BMessage* message)
|
||||||
{
|
|
||||||
fMessage.AddRect("file_types_frame", BRect(80.0f, 80.0f, 600.0f, 480.0f));
|
|
||||||
fMessage.AddRect("app_types_frame", BRect(100.0f, 100.0f, 540.0f, 480.0f));
|
|
||||||
fMessage.AddBool("show_icons", true);
|
|
||||||
fMessage.AddBool("show_rule", false);
|
|
||||||
fMessage.AddFloat("left_split_weight", 0.2);
|
|
||||||
fMessage.AddFloat("right_split_weight", 0.8);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
Settings::_Open(BFile *file, int32 mode)
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append("FileTypes settings");
|
|
||||||
|
|
||||||
return file->SetTo(path.Path(), mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Settings::UpdateFrom(BMessage *message)
|
|
||||||
{
|
{
|
||||||
BRect frame;
|
BRect frame;
|
||||||
if (message->FindRect("file_types_frame", &frame) == B_OK)
|
if (message->FindRect("file_types_frame", &frame) == B_OK)
|
||||||
@@ -168,11 +144,37 @@ Settings::UpdateFrom(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Settings::_SetDefaults()
|
||||||
|
{
|
||||||
|
fMessage.AddRect("file_types_frame", BRect(80.0f, 80.0f, 600.0f, 480.0f));
|
||||||
|
fMessage.AddRect("app_types_frame", BRect(100.0f, 100.0f, 540.0f, 480.0f));
|
||||||
|
fMessage.AddBool("show_icons", true);
|
||||||
|
fMessage.AddBool("show_rule", false);
|
||||||
|
fMessage.AddFloat("left_split_weight", 0.2);
|
||||||
|
fMessage.AddFloat("right_split_weight", 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Settings::_Open(BFile* file, int32 mode)
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
path.Append("FileTypes settings");
|
||||||
|
|
||||||
|
return file->SetTo(path.Path(), mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FileTypes::FileTypes()
|
FileTypes::FileTypes()
|
||||||
: BApplication(kSignature),
|
:
|
||||||
|
BApplication(kSignature),
|
||||||
fTypesWindow(NULL),
|
fTypesWindow(NULL),
|
||||||
fApplicationTypesWindow(NULL),
|
fApplicationTypesWindow(NULL),
|
||||||
fWindowCount(0),
|
fWindowCount(0),
|
||||||
@@ -202,7 +204,7 @@ FileTypes::ReadyToRun()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypes::RefsReceived(BMessage *message)
|
FileTypes::RefsReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
bool traverseLinks = (modifiers() & B_SHIFT_KEY) == 0;
|
bool traverseLinks = (modifiers() & B_SHIFT_KEY) == 0;
|
||||||
|
|
||||||
@@ -270,12 +272,17 @@ FileTypes::RefsReceived(BMessage *message)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypes::ArgvReceived(int32 argc, char **argv)
|
FileTypes::ArgvReceived(int32 argc, char** argv)
|
||||||
{
|
{
|
||||||
BMessage *message = CurrentMessage();
|
if (argc == 3 && strcmp(argv[1], "-type") == 0) {
|
||||||
|
fArgvType = argv[2];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessage* message = CurrentMessage();
|
||||||
|
|
||||||
BDirectory currentDirectory;
|
BDirectory currentDirectory;
|
||||||
if (message)
|
if (message != NULL)
|
||||||
currentDirectory.SetTo(message->FindString("cwd"));
|
currentDirectory.SetTo(message->FindString("cwd"));
|
||||||
|
|
||||||
BMessage refs;
|
BMessage refs;
|
||||||
@@ -306,15 +313,7 @@ FileTypes::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypes::_WindowClosed()
|
FileTypes::MessageReceived(BMessage* message)
|
||||||
{
|
|
||||||
if (--fWindowCount == 0 && !fFilePanel->IsShowing())
|
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FileTypes::MessageReceived(BMessage *message)
|
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgSettingsChanged:
|
case kMsgSettingsChanged:
|
||||||
@@ -324,6 +323,13 @@ FileTypes::MessageReceived(BMessage *message)
|
|||||||
case kMsgOpenTypesWindow:
|
case kMsgOpenTypesWindow:
|
||||||
if (fTypesWindow == NULL) {
|
if (fTypesWindow == NULL) {
|
||||||
fTypesWindow = new FileTypesWindow(fSettings.Message());
|
fTypesWindow = new FileTypesWindow(fSettings.Message());
|
||||||
|
if (fArgvType.Length() > 0) {
|
||||||
|
// Set the window to the type that was requested on the
|
||||||
|
// command line (-type), we do this only once, if we
|
||||||
|
// ever opened more than one FileTypesWindow.
|
||||||
|
fTypesWindow->SelectType(fArgvType.String());
|
||||||
|
fArgvType = "";
|
||||||
|
}
|
||||||
fTypesWindow->Show();
|
fTypesWindow->Show();
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
} else
|
} else
|
||||||
@@ -418,8 +424,8 @@ FileTypes::AboutRequested()
|
|||||||
aboutText << "\n";
|
aboutText << "\n";
|
||||||
aboutText << B_TRANSLATE("\twritten by Axel Dörfler\n"
|
aboutText << B_TRANSLATE("\twritten by Axel Dörfler\n"
|
||||||
"\tCopyright 2006-2007, Haiku.\n");
|
"\tCopyright 2006-2007, Haiku.\n");
|
||||||
BAlert *alert = new BAlert("about", aboutText.String(), B_TRANSLATE("OK"));
|
BAlert* alert = new BAlert("about", aboutText.String(), B_TRANSLATE("OK"));
|
||||||
BTextView *view = alert->TextView();
|
BTextView* view = alert->TextView();
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
view->SetStylable(true);
|
view->SetStylable(true);
|
||||||
@@ -440,6 +446,14 @@ FileTypes::QuitRequested()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypes::_WindowClosed()
|
||||||
|
{
|
||||||
|
if (--fWindowCount == 0 && !fFilePanel->IsShowing())
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -492,10 +506,9 @@ error_alert(const char* message, status_t status, alert_type type)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
FileTypes probe;
|
FileTypes probe;
|
||||||
|
|
||||||
probe.Run();
|
probe.Run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -944,6 +944,13 @@ FileTypesWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypesWindow::SelectType(const char* type)
|
||||||
|
{
|
||||||
|
fTypeListView->SelectType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FileTypesWindow::QuitRequested()
|
FileTypesWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
|
void SelectType(const char* type);
|
||||||
|
|
||||||
void PlaceSubWindow(BWindow* window);
|
void PlaceSubWindow(BWindow* window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user