From a8745d98e92b2e25d6a9024cecc951e9a8ed8de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 25 May 2007 07:53:54 +0000 Subject: [PATCH] * added "NativeSaver" which combines the MessageExporter and AttributeSaver to save the document also as icon attribute to a native Icon-O-Matic document file * added cmd-Y short cut to main window (on a German keyboard, Y and Z are swapped, but the Undo/Redo shortcuts are still "Z" while Z is much harder to reach than Y) * fixed warning in SetColorCommand.cpp * FlatIconExporter needs to save the attribute using B_VECTOR_ICON_TYPE (of course) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21235 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/icon-o-matic/IconEditorApp.cpp | 5 +-- src/apps/icon-o-matic/Jamfile | 1 + src/apps/icon-o-matic/MainWindow.cpp | 3 ++ .../document/savers/NativeSaver.cpp | 35 +++++++++++++++++++ .../document/savers/NativeSaver.h | 27 ++++++++++++++ .../flat_icon/FlatIconExporter.cpp | 2 +- .../icon-o-matic/style/SetColorCommand.cpp | 3 +- 7 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/apps/icon-o-matic/document/savers/NativeSaver.cpp create mode 100644 src/apps/icon-o-matic/document/savers/NativeSaver.h diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp index cf7323aa43..76c6cf0920 100644 --- a/src/apps/icon-o-matic/IconEditorApp.cpp +++ b/src/apps/icon-o-matic/IconEditorApp.cpp @@ -35,6 +35,7 @@ #include "MessageExporter.h" #include "MessageImporter.h" #include "MessengerSaver.h" +#include "NativeSaver.h" #include "PathContainer.h" #include "RDefExporter.h" #include "SavePanel.h" @@ -354,7 +355,7 @@ IconEditorApp::_Open(const entry_ref& ref, bool append) switch (refMode) { case REF_MESSAGE: fDocument->SetNativeSaver( - new SimpleFileSaver(new MessageExporter(), ref)); + new NativeSaver(ref)); break; case REF_FLAT: fDocument->SetExportSaver( @@ -475,7 +476,7 @@ IconEditorApp::_CreateSaver(const entry_ref& ref, uint32 exportMode) case EXPORT_MODE_MESSAGE: default: - saver = new SimpleFileSaver(new MessageExporter(), ref); + saver = new NativeSaver(ref); break; } diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index 69e9803876..de402bdd05 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -116,6 +116,7 @@ Application Icon-O-Matic : DocumentSaver.cpp FileSaver.cpp MessengerSaver.cpp + NativeSaver.cpp SimpleFileSaver.cpp # generic/command diff --git a/src/apps/icon-o-matic/MainWindow.cpp b/src/apps/icon-o-matic/MainWindow.cpp index 5ecf1e4451..32ac55c159 100644 --- a/src/apps/icon-o-matic/MainWindow.cpp +++ b/src/apps/icon-o-matic/MainWindow.cpp @@ -480,6 +480,9 @@ MainWindow::_Init() fSwatchGroup->SetCurrentColor(CurrentColor::Default()); SetIcon(fDocument->Icon()); + + AddShortcut('Y', 0, new BMessage(MSG_UNDO)); + AddShortcut('Y', B_SHIFT_KEY, new BMessage(MSG_REDO)); } // _CreateGUI diff --git a/src/apps/icon-o-matic/document/savers/NativeSaver.cpp b/src/apps/icon-o-matic/document/savers/NativeSaver.cpp new file mode 100644 index 0000000000..28062ec0b0 --- /dev/null +++ b/src/apps/icon-o-matic/document/savers/NativeSaver.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#include "NativeSaver.h" + +#include "FlatIconFormat.h" +#include "MessageExporter.h" + +// constructor +NativeSaver::NativeSaver(const entry_ref& ref) + : fAttrSaver(ref, kVectorAttrNodeName), + fFileSaver(new MessageExporter(), ref) +{ +} + +// destructor +NativeSaver::~NativeSaver() +{ +} + +// Save +status_t +NativeSaver::Save(Document* document) +{ + status_t ret = fFileSaver.Save(document); + if (ret < B_OK) + return ret; + return fAttrSaver.Save(document); +} + diff --git a/src/apps/icon-o-matic/document/savers/NativeSaver.h b/src/apps/icon-o-matic/document/savers/NativeSaver.h new file mode 100644 index 0000000000..16ee8ce8a7 --- /dev/null +++ b/src/apps/icon-o-matic/document/savers/NativeSaver.h @@ -0,0 +1,27 @@ +/* + * Copyright 2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#ifndef NATIVE_SAVER_H +#define NATIVE_SAVER_H + +#include "AttributeSaver.h" +#include "SimpleFileSaver.h" + +class NativeSaver : public DocumentSaver { + public: + NativeSaver(const entry_ref& ref); + virtual ~NativeSaver(); + + virtual status_t Save(Document* document); + + protected: + AttributeSaver fAttrSaver; + SimpleFileSaver fFileSaver; +}; + +#endif // NATIVE_SAVER_H diff --git a/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp b/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp index 6259b65b11..7cbc8ed2ea 100644 --- a/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp +++ b/src/apps/icon-o-matic/import_export/flat_icon/FlatIconExporter.cpp @@ -109,7 +109,7 @@ FlatIconExporter::Export(const Icon* icon, BNode* node, return ret; // write buffer to attribute - ssize_t written = node->WriteAttr(attrName, B_RAW_TYPE, 0, + ssize_t written = node->WriteAttr(attrName, B_VECTOR_ICON_TYPE, 0, buffer.Buffer(), buffer.SizeUsed()); if (written != (ssize_t)buffer.SizeUsed()) { if (written < 0) diff --git a/src/apps/icon-o-matic/style/SetColorCommand.cpp b/src/apps/icon-o-matic/style/SetColorCommand.cpp index c7ed4619a7..8b5b7d4e40 100644 --- a/src/apps/icon-o-matic/style/SetColorCommand.cpp +++ b/src/apps/icon-o-matic/style/SetColorCommand.cpp @@ -37,7 +37,8 @@ SetColorCommand::InitCheck() #ifdef __HAIKU__ return fStyle && fStyle->Color() != fColor ? B_OK : B_NO_INIT; #else - return fStyle && *(uint32*)&fStyle->Color() != *(uint32*)&fColor ? + rgb_color color = fStyle->Color(); + return fStyle && *(uint32*)&color != *(uint32*)&fColor ? B_OK : B_NO_INIT; #endif }