6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
36 #include <Application.h>
38 #include <FindDirectory.h>
39 #include <Directory.h>
52 #include "TemplatesMenu.h"
53 #include "IconMenuItem.h"
54 #include "MimeTypes.h"
57 #undef B_TRANSLATION_CONTEXT
58 #define B_TRANSLATION_CONTEXT "TemplatesMenu"
63 const char* kTemplatesDirectory
= "Tracker/Tracker New Templates";
65 } // namespace BPrivate
68 // #pragma mark - TemplatesMenu
71 TemplatesMenu::TemplatesMenu(const BMessenger
&target
, const char* label
)
80 TemplatesMenu::~TemplatesMenu()
86 TemplatesMenu::AttachedToWindow()
89 BMenu::AttachedToWindow();
90 SetTargetForItems(fTarget
);
95 TemplatesMenu::SetTargetForItems(BHandler
* target
)
97 status_t result
= BMenu::SetTargetForItems(target
);
99 fOpenItem
->SetTarget(be_app_messenger
);
106 TemplatesMenu::SetTargetForItems(BMessenger messenger
)
108 status_t result
= BMenu::SetTargetForItems(messenger
);
110 fOpenItem
->SetTarget(be_app_messenger
);
117 TemplatesMenu::UpdateMenuState()
124 TemplatesMenu::BuildMenu(bool addItems
)
126 // clear everything...
128 int32 count
= CountItems();
130 delete RemoveItem((int32
)0);
133 IconMenuItem
* menuItem
= new IconMenuItem(B_TRANSLATE("New folder"),
134 new BMessage(kNewFolder
), B_DIR_MIMETYPE
, B_MINI_ICON
);
136 menuItem
->SetShortcut('N', 0);
138 // the templates folder
140 find_directory (B_USER_SETTINGS_DIRECTORY
, &path
, true);
141 path
.Append(kTemplatesDirectory
);
142 mkdir(path
.Path(), 0777);
147 BDirectory
templatesDir(path
.Path());
148 while (templatesDir
.GetNextEntry(&entry
) == B_OK
) {
150 BNodeInfo
nodeInfo(&node
);
151 char fileName
[B_FILE_NAME_LENGTH
];
152 entry
.GetName(fileName
);
153 if (nodeInfo
.InitCheck() == B_OK
) {
154 char mimeType
[B_MIME_TYPE_LENGTH
];
155 nodeInfo
.GetType(mimeType
);
157 BMimeType
mime(mimeType
);
158 if (mime
.IsValid()) {
164 // If not adding items, we are just seeing if there
165 // are any to list. So if we find one, immediately
166 // bail and return the result.
173 BMessage
* message
= new BMessage(kNewEntryFromTemplate
);
174 message
->AddRef("refs_template", &ref
);
175 message
->AddString("name", fileName
);
176 AddItem(new IconMenuItem(fileName
, message
, &nodeInfo
,
184 // this is the message sent to open the templates folder
185 BMessage
* message
= new BMessage(B_REFS_RECEIVED
);
187 if (templatesDir
.GetEntry(&entry
) == B_OK
)
188 entry
.GetRef(&dirRef
);
190 message
->AddRef("refs", &dirRef
);
192 // add item to show templates folder
193 fOpenItem
= new BMenuItem(B_TRANSLATE("Edit templates" B_UTF8_ELLIPSIS
),
196 if (dirRef
== entry_ref())
197 fOpenItem
->SetEnabled(false);