Implemented loading a new icon into the same window when that

window is empty.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41262 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2011-04-17 19:21:09 +00:00
parent 5a6d9c8288
commit 22c7e6324c
2 changed files with 51 additions and 13 deletions
+28 -12
View File
@@ -34,6 +34,8 @@ using std::nothrow;
static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic"; static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic";
static const float kWindowOffset = 20;
IconEditorApp::IconEditorApp() IconEditorApp::IconEditorApp()
: :
@@ -113,13 +115,18 @@ IconEditorApp::MessageReceived(BMessage* message)
case MSG_NEW: case MSG_NEW:
_NewWindow()->Show(); _NewWindow()->Show();
break; break;
case MSG_OPEN: { case MSG_OPEN:
{
BMessage openMessage(B_REFS_RECEIVED); BMessage openMessage(B_REFS_RECEIVED);
MainWindow* window;
if (message->FindPointer("window", (void**)&window) == B_OK)
openMessage.AddPointer("window", window);
fOpenPanel->SetMessage(&openMessage); fOpenPanel->SetMessage(&openMessage);
fOpenPanel->Show(); fOpenPanel->Show();
break; break;
} }
case MSG_APPEND: { case MSG_APPEND:
{
MainWindow* window; MainWindow* window;
if (message->FindPointer("window", (void**)&window) != B_OK) if (message->FindPointer("window", (void**)&window) != B_OK)
break; break;
@@ -178,7 +185,7 @@ IconEditorApp::MessageReceived(BMessage* message)
BRect frame; BRect frame;
if (message->FindRect("window frame", &frame) == B_OK) { if (message->FindRect("window frame", &frame) == B_OK) {
fLastWindowFrame = frame; fLastWindowFrame = frame;
fLastWindowFrame.OffsetBy(-10, -10); fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset);
} }
break; break;
} }
@@ -205,13 +212,16 @@ void
IconEditorApp::RefsReceived(BMessage* message) IconEditorApp::RefsReceived(BMessage* message)
{ {
bool append; bool append;
if (message->FindBool("append", &append) < B_OK) if (message->FindBool("append", &append) != B_OK)
append = false; append = false;
MainWindow* window;
if (message->FindPointer("window", (void**)&window) != B_OK)
window = NULL;
// When appending, we need to know a window.
if (append && window == NULL)
return;
entry_ref ref; entry_ref ref;
if (append) { if (append) {
MainWindow* window;
if (message->FindPointer("window", (void**)&window) != B_OK)
return;
if (!window->Lock()) if (!window->Lock())
return; return;
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++)
@@ -219,9 +229,15 @@ IconEditorApp::RefsReceived(BMessage* message)
window->Unlock(); window->Unlock();
} else { } else {
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
MainWindow* window = _NewWindow(); if (window != NULL && i == 0) {
window->Open(ref, false); window->Lock();
window->Show(); window->Open(ref, false);
window->Unlock();
} else {
window = _NewWindow();
window->Open(ref, false);
window->Show();
}
} }
} }
@@ -254,7 +270,7 @@ IconEditorApp::ArgvReceived(int32 argc, char** argv)
MainWindow* MainWindow*
IconEditorApp::_NewWindow() IconEditorApp::_NewWindow()
{ {
fLastWindowFrame.OffsetBy(10, 10); fLastWindowFrame.OffsetBy(kWindowOffset, kWindowOffset);
MainWindow* window = new MainWindow(fLastWindowFrame, this, MainWindow* window = new MainWindow(fLastWindowFrame, this,
&fLastWindowSettings); &fLastWindowSettings);
fWindowCount++; fWindowCount++;
@@ -346,7 +362,7 @@ IconEditorApp::_RestoreSettings()
if (settings.FindRect("window frame", &frame) == B_OK) { if (settings.FindRect("window frame", &frame) == B_OK) {
fLastWindowFrame = frame; fLastWindowFrame = frame;
// Compensate offset for next window... // Compensate offset for next window...
fLastWindowFrame.OffsetBy(-10, -10); fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset);
} }
settings.FindMessage("window settings", &fLastWindowSettings); settings.FindMessage("window settings", &fLastWindowSettings);
+23 -1
View File
@@ -204,8 +204,20 @@ MainWindow::MessageReceived(BMessage* message)
case B_REFS_RECEIVED: case B_REFS_RECEIVED:
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
// If our icon is empty, open the file in this window,
// otherwise forward to the application which will open
// it in another window, unless we append.
message->what = B_REFS_RECEIVED; message->what = B_REFS_RECEIVED;
if (fDocument->Icon()->Styles()->CountStyles() == 0
&& fDocument->Icon()->Paths()->CountPaths() == 0
&& fDocument->Icon()->Shapes()->CountShapes() == 0) {
entry_ref ref;
if (message->FindRef("refs", &ref) == B_OK)
Open(ref);
break;
}
if (modifiers() & B_SHIFT_KEY) { if (modifiers() & B_SHIFT_KEY) {
// We want the icon appended to this window.
message->AddBool("append", true); message->AddBool("append", true);
message->AddPointer("window", this); message->AddPointer("window", this);
} }
@@ -256,6 +268,17 @@ MainWindow::MessageReceived(BMessage* message)
break; break;
} }
case MSG_OPEN:
// If our icon is empty, we want the icon to open in this
// window.
if (fDocument->Icon()->Styles()->CountStyles() == 0
&& fDocument->Icon()->Paths()->CountPaths() == 0
&& fDocument->Icon()->Shapes()->CountShapes() == 0) {
message->AddPointer("window", this);
}
be_app->PostMessage(message);
break;
case MSG_SAVE: case MSG_SAVE:
case MSG_EXPORT: case MSG_EXPORT:
{ {
@@ -1142,7 +1165,6 @@ MainWindow::_CreateMenuBar()
item = new BMenuItem(B_TRANSLATE("Open"B_UTF8_ELLIPSIS), item = new BMenuItem(B_TRANSLATE("Open"B_UTF8_ELLIPSIS),
new BMessage(MSG_OPEN), 'O'); new BMessage(MSG_OPEN), 'O');
fileMenu->AddItem(item); fileMenu->AddItem(item);
item->SetTarget(be_app);
BMessage* appendMessage = new BMessage(MSG_APPEND); BMessage* appendMessage = new BMessage(MSG_APPEND);
appendMessage->AddPointer("window", this); appendMessage->AddPointer("window", this);
item = new BMenuItem(B_TRANSLATE("Append"B_UTF8_ELLIPSIS), item = new BMenuItem(B_TRANSLATE("Append"B_UTF8_ELLIPSIS),