void FileTypes::MessageReceived(BMessage *message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { fTypesWindow = new FileTypesWindow(fSettings.Message()); fTypesWindow->Show(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }
/*! Opens a window containing the file pointed to by the entry_ref. This function will fail if that file doesn't exist or could not be opened. It will check if there already is a window that probes the file in question and will activate it in that case. This function must be called with the application looper locked. */ status_t DiskProbe::Probe(BEntry& entry, const char* attribute) { entry_ref ref; status_t status = entry.GetRef(&ref); if (status < B_OK) return status; ProbeWindow* lastWindow(NULL); // Do we already have that window open? for (int32 i = CountWindows(); i-- > 0; ) { ProbeWindow* window = dynamic_cast<ProbeWindow*>(WindowAt(i)); if (window == NULL) continue; if (window->Contains(ref, attribute)) { window->Activate(true); return B_OK; } if (lastWindow == NULL) lastWindow = window; } // Does the file really exist? if (!entry.Exists()) return B_ENTRY_NOT_FOUND; entry.GetRef(&ref); // cascade window BRect rect; if (lastWindow != NULL) rect = lastWindow->Frame(); else rect = fWindowFrame; rect.OffsetBy(kCascadeOffset, kCascadeOffset); BWindow* window; if (attribute != NULL) { window = new AttributeWindow(rect, &ref, attribute, &fSettings.Message()); } else window = new FileWindow(rect, &ref, &fSettings.Message()); window->Show(); // Adjust the cascading... we can only do this after the window was created // to adjust to the real size. rect.right = window->Frame().right; rect.bottom = window->Frame().bottom; BScreen screen; BRect screenBorder = screen.Frame(); float left = rect.left; if (left + rect.Width() > screenBorder.right) left = 7; float top = rect.top; if (top + rect.Height() > screenBorder.bottom) top = 26; rect.OffsetTo(BPoint(left, top)); window->MoveTo(BPoint(left, top)); fWindowCount++; return B_OK; }
void DiskProbe::MessageReceived(BMessage* message) { switch (message->what) { case kMsgOpenOpenWindow: if (fOpenWindow == NULL) { fOpenWindow = new OpenWindow(); fOpenWindow->Show(); fWindowCount++; } else fOpenWindow->Activate(true); break; case kMsgOpenWindowClosed: fOpenWindow = NULL; // supposed to fall through case kMsgWindowClosed: if (--fWindowCount == 0 && !fFilePanel->IsShowing()) PostMessage(B_QUIT_REQUESTED); break; case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgFindWindowClosed: fFindWindow = NULL; break; case kMsgFindTarget: { BMessenger target; if (message->FindMessenger("target", &target) != B_OK) break; if (fFindWindow != NULL && fFindWindow->Lock()) { fFindWindow->SetTarget(target); fFindWindow->Unlock(); } break; } case kMsgOpenFindWindow: { BMessenger target; if (message->FindMessenger("target", &target) != B_OK) break; if (fFindWindow == NULL) { // open it! fFindWindow = new FindWindow(fWindowFrame.OffsetByCopy(80, 80), *message, target, &fSettings.Message()); fFindWindow->Show(); } else fFindWindow->Activate(); break; } case kMsgOpenFilePanel: fFilePanel->Show(); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; default: BApplication::MessageReceived(message); break; } }
void FileTypes::MessageReceived(BMessage* message) { switch (message->what) { case kMsgSettingsChanged: fSettings.UpdateFrom(message); break; case kMsgOpenTypesWindow: if (fTypesWindow == NULL) { 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(); fWindowCount++; } else fTypesWindow->Activate(true); break; case kMsgTypesWindowClosed: fTypesWindow = NULL; _WindowClosed(); break; case kMsgOpenApplicationTypesWindow: if (fApplicationTypesWindow == NULL) { fApplicationTypesWindow = new ApplicationTypesWindow( fSettings.Message()); fApplicationTypesWindow->Show(); fWindowCount++; } else fApplicationTypesWindow->Activate(true); break; case kMsgApplicationTypesWindowClosed: fApplicationTypesWindow = NULL; _WindowClosed(); break; case kMsgTypeWindowClosed: fTypeWindowCount--; // supposed to fall through case kMsgWindowClosed: _WindowClosed(); break; case kMsgOpenFilePanel: { // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) subTitle = B_TRANSLATE("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) what = B_REFS_RECEIVED; BMessenger target; if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; BString title = B_TRANSLATE("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); } uint32 flavors = B_FILE_NODE; if (message->FindBool("allowDirs")) flavors |= B_DIRECTORY_NODE; fFilePanel->SetNodeFlavors(flavors); fFilePanel->SetMessage(new BMessage(what)); fFilePanel->Window()->SetTitle(title.String()); fFilePanel->SetTarget(target); if (!fFilePanel->IsShowing()) fFilePanel->Show(); break; } case B_SILENT_RELAUNCH: // In case we were launched via the add-on, there is no types // window yet. if (fTypesWindow == NULL) PostMessage(kMsgOpenTypesWindow); break; case B_CANCEL: if (fWindowCount == 0) PostMessage(B_QUIT_REQUESTED); break; case B_SIMPLE_DATA: RefsReceived(message); break; default: BApplication::MessageReceived(message); break; } }