* Moved the query engine from TMenu into its own function add_query_menu_items().
* Removed the "Set to..." submenu from the "Close and" menu; instead, all items are now added to the same level, which makes this menu more useful and easier to use. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20068 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+68
-49
@@ -174,6 +174,53 @@ main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
|
||||||
|
const char* format, bool popup = false)
|
||||||
|
{
|
||||||
|
BVolume volume;
|
||||||
|
BVolumeRoster().GetBootVolume(&volume);
|
||||||
|
|
||||||
|
BQuery query;
|
||||||
|
query.SetVolume(&volume);
|
||||||
|
query.PushAttr(attribute);
|
||||||
|
query.PushString("*");
|
||||||
|
query.PushOp(B_EQ);
|
||||||
|
query.Fetch();
|
||||||
|
|
||||||
|
int32 index = 0;
|
||||||
|
BEntry entry;
|
||||||
|
while (query.GetNextEntry(&entry) == B_OK) {
|
||||||
|
BFile file(&entry, B_READ_ONLY);
|
||||||
|
if (file.InitCheck() == B_OK) {
|
||||||
|
BMessage* message = new BMessage(what);
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
entry.GetRef(&ref);
|
||||||
|
message->AddRef("ref", &ref);
|
||||||
|
|
||||||
|
BString value;
|
||||||
|
if (file.ReadAttrString(attribute, &value) < B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char name[256];
|
||||||
|
if (format != NULL)
|
||||||
|
snprintf(name, sizeof(name), format, value.String());
|
||||||
|
else
|
||||||
|
strlcpy(name, value.String(), sizeof(name));
|
||||||
|
|
||||||
|
if (index < 9 && !popup)
|
||||||
|
menu->AddItem(new BMenuItem(name, message, '1' + index));
|
||||||
|
else
|
||||||
|
menu->AddItem(new BMenuItem(name, message));
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
header_len(BFile *file)
|
header_len(BFile *file)
|
||||||
{
|
{
|
||||||
@@ -1260,16 +1307,13 @@ TMailWindow::TMailWindow(BRect rect, const char *title, const entry_ref *ref, co
|
|||||||
|
|
||||||
if(!resending && fIncoming) {
|
if(!resending && fIncoming) {
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
subMenu = new BMenu(MDR_DIALECT_CHOICE ("Close and ","C) 閉じる"));
|
subMenu = new BMenu(MDR_DIALECT_CHOICE ("Close and ","C) 閉じる"));
|
||||||
if (file.GetAttrInfo(B_MAIL_ATTR_STATUS, &info) == B_NO_ERROR)
|
if (file.GetAttrInfo(B_MAIL_ATTR_STATUS, &info) == B_NO_ERROR)
|
||||||
file.ReadAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, str, info.size);
|
file.ReadAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, str, info.size);
|
||||||
else
|
else
|
||||||
str[0] = 0;
|
str[0] = 0;
|
||||||
|
|
||||||
//if( (strcmp(str, "Pending")==0)||(strcmp(str, "Sent")==0) )
|
|
||||||
// canResend = true;
|
|
||||||
|
|
||||||
if (!strcmp(str, "New")) {
|
if (!strcmp(str, "New")) {
|
||||||
subMenu->AddItem(item = new BMenuItem(
|
subMenu->AddItem(item = new BMenuItem(
|
||||||
MDR_DIALECT_CHOICE ("Leave as New", "N) 新規<New>のままにする"),
|
MDR_DIALECT_CHOICE ("Leave as New", "N) 新規<New>のままにする"),
|
||||||
@@ -1289,12 +1333,24 @@ TMailWindow::TMailWindow(BRect rect, const char *title, const entry_ref *ref, co
|
|||||||
AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(M_CLOSE_SAME));
|
AddShortcut('W', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(M_CLOSE_SAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subMenu->AddSeparatorItem();
|
||||||
|
|
||||||
subMenu->AddItem(new BMenuItem(
|
subMenu->AddItem(new BMenuItem(
|
||||||
MDR_DIALECT_CHOICE ("Set to Saved", "S) 属性を<Saved>に設定"),
|
MDR_DIALECT_CHOICE ("Set to Saved", "S) 属性を<Saved>に設定"),
|
||||||
new BMessage(M_CLOSE_SAVED), 'W', B_CONTROL_KEY));
|
new BMessage(M_CLOSE_SAVED), 'W', B_CONTROL_KEY));
|
||||||
|
|
||||||
|
if (add_query_menu_items(subMenu, INDEX_STATUS, M_STATUS,
|
||||||
|
MDR_DIALECT_CHOICE("Set to %s", "属性を<%s>に設定")) > 0)
|
||||||
|
subMenu->AddSeparatorItem();
|
||||||
|
|
||||||
|
subMenu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE("Set to", "X) 他の属性に変更")
|
||||||
|
B_UTF8_ELLIPSIS, new BMessage(M_CLOSE_CUSTOM)));
|
||||||
|
|
||||||
|
#if 0
|
||||||
subMenu->AddItem(new BMenuItem(new TMenu(
|
subMenu->AddItem(new BMenuItem(new TMenu(
|
||||||
MDR_DIALECT_CHOICE ("Set to", "X) 他の属性に変更")B_UTF8_ELLIPSIS,
|
MDR_DIALECT_CHOICE ("Set to", "X) 他の属性に変更")B_UTF8_ELLIPSIS,
|
||||||
INDEX_STATUS, M_STATUS, false, false), new BMessage(M_CLOSE_CUSTOM)));
|
INDEX_STATUS, M_STATUS, false, false), new BMessage(M_CLOSE_CUSTOM)));
|
||||||
|
#endif
|
||||||
menu->AddItem(subMenu);
|
menu->AddItem(subMenu);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -3839,17 +3895,14 @@ TMailWindow::FrontmostWindow()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
TMenu::TMenu(const char *name, const char *attribute, int32 message, bool popup, bool addRandom)
|
TMenu::TMenu(const char *name, const char *attribute, int32 message, bool popup,
|
||||||
: BPopUpMenu(name, false, false),
|
bool addRandom)
|
||||||
|
: BPopUpMenu(name, false, false),
|
||||||
fPopup(popup),
|
fPopup(popup),
|
||||||
fAddRandom(addRandom),
|
fAddRandom(addRandom),
|
||||||
fMessage(message)
|
fMessage(message)
|
||||||
{
|
{
|
||||||
fAttribute = (char *)malloc(strlen(attribute) + 1);
|
fAttribute = strdup(attribute);
|
||||||
strcpy(fAttribute, attribute);
|
|
||||||
fPredicate = (char *)malloc(strlen(fAttribute) + 5);
|
|
||||||
sprintf(fPredicate, "%s = *", fAttribute);
|
|
||||||
|
|
||||||
BuildMenu();
|
BuildMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3857,7 +3910,6 @@ TMenu::TMenu(const char *name, const char *attribute, int32 message, bool popup,
|
|||||||
TMenu::~TMenu()
|
TMenu::~TMenu()
|
||||||
{
|
{
|
||||||
free(fAttribute);
|
free(fAttribute);
|
||||||
free(fPredicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3882,45 +3934,12 @@ TMenu::ScreenLocation(void)
|
|||||||
void
|
void
|
||||||
TMenu::BuildMenu()
|
TMenu::BuildMenu()
|
||||||
{
|
{
|
||||||
BMenuItem *item;
|
RemoveItems(0, CountItems(), true);
|
||||||
while ((item = RemoveItem((int32)0)) != NULL)
|
add_query_menu_items(this, fAttribute, fMessage, NULL, fPopup);
|
||||||
delete item;
|
|
||||||
|
|
||||||
BVolume volume;
|
if (fAddRandom && CountItems() > 0) {
|
||||||
BVolumeRoster().GetBootVolume(&volume);
|
|
||||||
|
|
||||||
BQuery query;
|
|
||||||
query.SetVolume(&volume);
|
|
||||||
query.SetPredicate(fPredicate);
|
|
||||||
query.Fetch();
|
|
||||||
|
|
||||||
int32 index = 0;
|
|
||||||
BEntry entry;
|
|
||||||
while (query.GetNextEntry(&entry) == B_NO_ERROR)
|
|
||||||
{
|
|
||||||
BFile file(&entry, O_RDONLY);
|
|
||||||
if (file.InitCheck() == B_NO_ERROR)
|
|
||||||
{
|
|
||||||
BMessage *msg = new BMessage(fMessage);
|
|
||||||
|
|
||||||
entry_ref ref;
|
|
||||||
entry.GetRef(&ref);
|
|
||||||
msg->AddRef("ref", &ref);
|
|
||||||
|
|
||||||
char name[B_FILE_NAME_LENGTH];
|
|
||||||
file.ReadAttr(fAttribute, B_STRING_TYPE, 0, name, sizeof(name));
|
|
||||||
|
|
||||||
if (index < 9 && !fPopup)
|
|
||||||
AddItem(new BMenuItem(name, msg, '1' + index));
|
|
||||||
else
|
|
||||||
AddItem(new BMenuItem(name, msg));
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fAddRandom && CountItems())
|
|
||||||
{
|
|
||||||
AddItem(new BSeparatorItem(), 0);
|
AddItem(new BSeparatorItem(), 0);
|
||||||
//AddSeparatorItem();
|
|
||||||
BMessage *msg = new BMessage(M_RANDOM_SIG);
|
BMessage *msg = new BMessage(M_RANDOM_SIG);
|
||||||
if (!fPopup)
|
if (!fPopup)
|
||||||
AddItem(new BMenuItem(MDR_DIALECT_CHOICE ("Random","R) 自動決定"), msg, '0'), 0);
|
AddItem(new BMenuItem(MDR_DIALECT_CHOICE ("Random","R) 自動決定"), msg, '0'), 0);
|
||||||
|
|||||||
@@ -319,22 +319,19 @@ class TMailWindow : public BWindow {
|
|||||||
BMessenger *fOriginatingWindow;
|
BMessenger *fOriginatingWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
//====================================================================
|
class TMenu: public BPopUpMenu {
|
||||||
|
|
||||||
class TMenu: public BPopUpMenu
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TMenu(const char *, const char *, int32, bool popup = false, bool addRandom = true);
|
TMenu(const char* name, const char* attribute, int32, bool popup = false,
|
||||||
|
bool addRandom = true);
|
||||||
~TMenu();
|
~TMenu();
|
||||||
|
|
||||||
virtual BPoint ScreenLocation(void);
|
virtual BPoint ScreenLocation(void);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
|
||||||
void BuildMenu();
|
void BuildMenu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *fAttribute;
|
char* fAttribute;
|
||||||
char *fPredicate;
|
|
||||||
bool fPopup, fAddRandom;
|
bool fPopup, fAddRandom;
|
||||||
int32 fMessage;
|
int32 fMessage;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user