Author: stippi Date: 2011-04-17 21:21:09 +0200 (Sun, 17 Apr 2011) New Revision: 41262 Changeset: https://dev.haiku-os.org/changeset/41262 Modified: haiku/trunk/src/apps/icon-o-matic/IconEditorApp.cpp haiku/trunk/src/apps/icon-o-matic/MainWindow.cpp Log: Implemented loading a new icon into the same window when that window is empty. Modified: haiku/trunk/src/apps/icon-o-matic/IconEditorApp.cpp =================================================================== --- haiku/trunk/src/apps/icon-o-matic/IconEditorApp.cpp 2011-04-17 19:20:25 UTC (rev 41261) +++ haiku/trunk/src/apps/icon-o-matic/IconEditorApp.cpp 2011-04-17 19:21:09 UTC (rev 41262) @@ -34,7 +34,9 @@ static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic"; +static const float kWindowOffset = 20; + IconEditorApp::IconEditorApp() : BApplication(kAppSig), @@ -113,13 +115,18 @@ case MSG_NEW: _NewWindow()->Show(); break; - case MSG_OPEN: { + case MSG_OPEN: + { BMessage openMessage(B_REFS_RECEIVED); + MainWindow* window; + if (message->FindPointer("window", (void**)&window) == B_OK) + openMessage.AddPointer("window", window); fOpenPanel->SetMessage(&openMessage); fOpenPanel->Show(); break; } - case MSG_APPEND: { + case MSG_APPEND: + { MainWindow* window; if (message->FindPointer("window", (void**)&window) != B_OK) break; @@ -178,7 +185,7 @@ BRect frame; if (message->FindRect("window frame", &frame) == B_OK) { fLastWindowFrame = frame; - fLastWindowFrame.OffsetBy(-10, -10); + fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset); } break; } @@ -205,13 +212,16 @@ IconEditorApp::RefsReceived(BMessage* message) { bool append; - if (message->FindBool("append", &append) < B_OK) + if (message->FindBool("append", &append) != B_OK) 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; if (append) { - MainWindow* window; - if (message->FindPointer("window", (void**)&window) != B_OK) - return; if (!window->Lock()) return; for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) @@ -219,9 +229,15 @@ window->Unlock(); } else { for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { - MainWindow* window = _NewWindow(); - window->Open(ref, false); - window->Show(); + if (window != NULL && i == 0) { + window->Lock(); + window->Open(ref, false); + window->Unlock(); + } else { + window = _NewWindow(); + window->Open(ref, false); + window->Show(); + } } } @@ -254,7 +270,7 @@ MainWindow* IconEditorApp::_NewWindow() { - fLastWindowFrame.OffsetBy(10, 10); + fLastWindowFrame.OffsetBy(kWindowOffset, kWindowOffset); MainWindow* window = new MainWindow(fLastWindowFrame, this, &fLastWindowSettings); fWindowCount++; @@ -346,7 +362,7 @@ if (settings.FindRect("window frame", &frame) == B_OK) { fLastWindowFrame = frame; // Compensate offset for next window... - fLastWindowFrame.OffsetBy(-10, -10); + fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset); } settings.FindMessage("window settings", &fLastWindowSettings); Modified: haiku/trunk/src/apps/icon-o-matic/MainWindow.cpp =================================================================== --- haiku/trunk/src/apps/icon-o-matic/MainWindow.cpp 2011-04-17 19:20:25 UTC (rev 41261) +++ haiku/trunk/src/apps/icon-o-matic/MainWindow.cpp 2011-04-17 19:21:09 UTC (rev 41262) @@ -204,8 +204,20 @@ case B_REFS_RECEIVED: 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; + 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) { + // We want the icon appended to this window. message->AddBool("append", true); message->AddPointer("window", this); } @@ -256,6 +268,17 @@ 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_EXPORT: { @@ -1142,7 +1165,6 @@ item = new BMenuItem(B_TRANSLATE("Open"B_UTF8_ELLIPSIS), new BMessage(MSG_OPEN), 'O'); fileMenu->AddItem(item); - item->SetTarget(be_app); BMessage* appendMessage = new BMessage(MSG_APPEND); appendMessage->AddPointer("window", this); item = new BMenuItem(B_TRANSLATE("Append"B_UTF8_ELLIPSIS),