diff --git a/src/apps/Jamfile b/src/apps/Jamfile index d4478897e7..b643ddd705 100644 --- a/src/apps/Jamfile +++ b/src/apps/Jamfile @@ -49,7 +49,6 @@ HaikuSubInclude processcontroller ; HaikuSubInclude pulse ; HaikuSubInclude remotedesktop ; HaikuSubInclude resedit ; -HaikuSubInclude resourceedit ; HaikuSubInclude screenshot ; HaikuSubInclude serialconnect ; HaikuSubInclude showimage ; diff --git a/src/apps/resourceedit/Constants.h b/src/apps/resourceedit/Constants.h deleted file mode 100644 index 1bb2e97590..0000000000 --- a/src/apps/resourceedit/Constants.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef CONSTANTS_H -#define CONSTANTS_H - - -#define MSG_NEW 'm000' -#define MSG_OPEN 'm001' -#define MSG_OPEN_DONE 'm002' -#define MSG_CLOSE 'm003' -#define MSG_SAVE 'm004' -#define MSG_SAVEAS 'm005' -#define MSG_SAVEAS_DONE 'm006' -#define MSG_SAVEALL 'm007' -#define MSG_MERGEWITH 'm008' -#define MSG_QUIT 'm009' - -#define MSG_UNDO 'm010' -#define MSG_REDO 'm011' -#define MSG_CUT 'm012' -#define MSG_COPY 'm013' -#define MSG_PASTE 'm014' -#define MSG_CLEAR 'm015' -#define MSG_SELECTALL 'm016' - -#define MSG_ADDAPPRES 'm020' -#define MSG_SETTINGS 'm021' - -#define MSG_ADD 'm030' -#define MSG_REMOVE 'm031' -#define MSG_MOVEUP 'm032' -#define MSG_MOVEDOWN 'm033' - -#define MSG_SELECTION 'm040' -#define MSG_INVOCATION 'm041' - -#define MSG_ACCEPT 'm050' -#define MSG_CANCEL 'm051' -#define MSG_IGNORE 'm052' - -#define MSG_SETTINGS_APPLY 'm022' -#define MSG_SETTINGS_REVERT 'm023' -#define MSG_SETTINGS_CLOSED 'm024' - -// TODO: Remove prior to release. -#define DEBUG 1 -#include -// --- --- - - -#endif diff --git a/src/apps/resourceedit/DefaultTypes.cpp b/src/apps/resourceedit/DefaultTypes.cpp deleted file mode 100644 index 3fed852f9c..0000000000 --- a/src/apps/resourceedit/DefaultTypes.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "DefaultTypes.h" - -#include - - -int32 -ResourceType::FindIndex(type_code code) -{ - for (int32 i = 0; kDefaultTypes[i].type != NULL; i++) - if (StringToCode(kDefaultTypes[i].code) == code) - return i; - - return -1; -} - - -int32 -ResourceType::FindIndex(const char* type) -{ - for (int32 i = 0; kDefaultTypes[i].type != NULL; i++) - if (strcmp(kDefaultTypes[i].type, type) == 0) - return i; - - return -1; -} - - -void -ResourceType::CodeToString(type_code code, char* str) -{ - *(type_code*)str = B_HOST_TO_BENDIAN_INT32(code); - str[4] = '\0'; -} - - -type_code -ResourceType::StringToCode(const char* code) -{ - // TODO: Code may be in other formats, too! Ex.: 0x4C4F4E47 - return B_BENDIAN_TO_HOST_INT32(*(int32*)code); -} diff --git a/src/apps/resourceedit/DefaultTypes.h b/src/apps/resourceedit/DefaultTypes.h deleted file mode 100644 index ef51b66aa1..0000000000 --- a/src/apps/resourceedit/DefaultTypes.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef DEFAULT_TYPES_H -#define DEFAULT_TYPES_H - - -#include "AppFlagsEdit.h" -#include "BooleanEdit.h" -#include "EditView.h" -#include "NormalEdit.h" -#include "ResourceRow.h" - -#include - - -struct ResourceType { - const char* type; - const char* code; - const char* data; - uint32 size; - EditView* edit; - - static int32 FindIndex(const char* type); - static int32 FindIndex(type_code code); - - static void CodeToString(type_code code, char* str); - static type_code StringToCode(const char* code); -}; - - -#define LINE "", "", "", ~0, NULL -#define END NULL, NULL, NULL, 0, NULL - -const ResourceType kDefaultTypes[] = { - { "app_signature", "", "application/MyApp", 18, new NormalEdit() }, - { "app_name_catalog_entry", "", "MyApp:System name:MyApp", 24, new NormalEdit() }, - //{ "app_flags", "", "None", 4, NULL }, - { LINE }, - { "bool", "BOOL", "false", 1, new BooleanEdit() }, - { LINE }, - { "int8", "BYTE", "0", 1, new NormalEdit() }, - { "int16", "SHRT", "0", 2, new NormalEdit() }, - { "int32", "LONG", "0", 4, new NormalEdit() }, - { "int64", "LLNG", "0", 8, new NormalEdit() }, - { LINE }, - { "uint8", "UBYT", "0", 1, new NormalEdit() }, - { "uint16", "USHT", "0", 2, new NormalEdit() }, - { "uint32", "ULNG", "0", 4, new NormalEdit() }, - { "uint64", "ULLG", "0", 8, new NormalEdit() }, - { LINE }, - { "string", "CSTR", "\"\"", 0, NULL }, - { "raw", "RAWT", "", 0, NULL }, - { LINE }, - { "array", "", "", 0, NULL }, - { "message", "", "", 0, NULL }, - { "import", "", "", 0, NULL }, - { END } -}; - -const int32 kDefaultTypeSelected = 8; - // int32 - -#undef LINE -#undef END - - -#endif diff --git a/src/apps/resourceedit/EditWindow.cpp b/src/apps/resourceedit/EditWindow.cpp deleted file mode 100644 index 73b03644ae..0000000000 --- a/src/apps/resourceedit/EditWindow.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "EditWindow.h" - -#include "Constants.h" -#include "DefaultTypes.h" -#include "EditView.h" -#include "ResourceRow.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -EditWindow::EditWindow(BRect frame, ResourceRow* row) - : - BWindow(frame, "Edit Resource", - B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 0) -{ - int32 ix = ResourceType::FindIndex(row->ResourceType()); - - fRow = row; - - fView = new BView(Bounds(), "fView", B_FOLLOW_ALL, 0); - fView->SetLayout(new BGroupLayout(B_VERTICAL)); - - fIDText = new BTextControl(BRect(0, 0, 0, 0), - "fIDText", "ID:", row->ResourceStringID(), NULL); - fIDText->SetDivider(50); - - fNameText = new BTextControl(BRect(0, 0, 0, 0), - "fNameText", "Name:", row->ResourceName(), NULL); - fNameText->SetDivider(50); - - fTypePopUp = new BPopUpMenu("(Type)"); - - // TODO: (Not so) evil redundancy. - for (int32 i = 0; kDefaultTypes[i].type != NULL; i++) { - if (kDefaultTypes[i].size == ~(uint32)0) - fTypePopUp->AddSeparatorItem(); - else - fTypePopUp->AddItem(new BMenuItem(kDefaultTypes[i].type, - new BMessage(MSG_SELECTION))); - } - // --- - - fTypePopUp->ItemAt(ix)->SetMarked(true); - - fTypeMenu = new BMenuField(BRect(0, 0, 0, 0), - "fTypeMenu", "Type:", fTypePopUp); - fTypeMenu->SetDivider(50); - - fCodeText = new BTextControl(BRect(0, 0, 0, 0), - "fCodeText", "Code:", row->ResourceStringCode(), NULL); - fCodeText->SetDivider(50); - - fEditViewBox = new BBox(BRect(0, 0, 0, 0), "fEditViewBox"); - fEditViewBox->SetLayout(new BGroupLayout(B_VERTICAL)); - - fEditView = kDefaultTypes[ix].edit; - fEditView->AttachTo(fEditViewBox); - fEditView->Edit(fRow); - - fErrorString = new BStringView(BRect(0, 0, 0, 0), - "fErrorString", ""); - - fErrorString->SetHighColor(ui_color(B_FAILURE_COLOR)); - - fCancelButton = new BButton(BRect(0, 0, 0, 0), - "fCancelButton", "Cancel", new BMessage(MSG_CANCEL)); - fOKButton = new BButton(BRect(0, 0, 0, 0), - "fOKButton", "OK", new BMessage(MSG_ACCEPT)); - - fView->AddChild(BGroupLayoutBuilder(B_VERTICAL, 8) - .Add(fIDText) - .Add(fNameText) - .Add(fTypeMenu) - .Add(fCodeText) - .Add(fEditViewBox) - .Add(fErrorString) - .Add(BGroupLayoutBuilder(B_HORIZONTAL, 8) - .AddGlue() - .Add(fCancelButton) - .Add(fOKButton) - .SetInsets(8, 8, 8, 8) - ) - .SetInsets(8, 8, 8, 8) - ); - - AddChild(fView); - ResizeTo(250, 350); - - Show(); -} - - -EditWindow::~EditWindow() -{ - fEditView->RemoveSelf(); -} - - -void -EditWindow::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case MSG_SELECTION: - { - int32 ix = fTypePopUp->FindMarkedIndex(); - - fCodeText->SetText(kDefaultTypes[ix].code); - - fEditView->RemoveSelf(); - - fEditView = kDefaultTypes[ix].edit; - fEditView->AttachTo(fEditViewBox); - fEditView->Edit(fRow); - - break; - } - case MSG_CANCEL: - PostMessage(B_QUIT_REQUESTED); - break; - - case MSG_ACCEPT: - { - if (_Validate()) { - int32 ix = fTypePopUp->FindMarkedIndex(); - - fRow->SetResourceStringID(fIDText->Text()); - fRow->SetResourceName(fNameText->Text()); - fRow->SetResourceType(kDefaultTypes[ix].type); - fRow->SetResourceStringCode(fCodeText->Text()); - fRow->SetResourceSize(kDefaultTypes[ix].size); - - fEditView->Commit(); - - PostMessage(B_QUIT_REQUESTED); - } - - break; - } - } -} - - -bool -EditWindow::_Validate() -{ - // TODO: Implement validation of entered data. - fErrorString->SetText(""); - return true; -} diff --git a/src/apps/resourceedit/EditWindow.h b/src/apps/resourceedit/EditWindow.h deleted file mode 100644 index d104af98fb..0000000000 --- a/src/apps/resourceedit/EditWindow.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef EDIT_WINDOW_H -#define EDIT_WINDOW_H - - -#include - - -class EditView; -class ResourceRow; - -class BBox; -class BButton; -class BMenuField; -class BPopUpMenu; -class BStringView; -class BTextControl; - - -class EditWindow : public BWindow { -public: - EditWindow(BRect frame, ResourceRow* row); - ~EditWindow(); - - void MessageReceived(BMessage* msg); - -private: - ResourceRow* fRow; - - BView* fView; - - BTextControl* fIDText; - BTextControl* fNameText; - BPopUpMenu* fTypePopUp; - BMenuField* fTypeMenu; - BTextControl* fCodeText; - - EditView* fEditView; - BBox* fEditViewBox; - - BStringView* fErrorString; - - BButton* fCancelButton; - BButton* fOKButton; - - bool _Validate(); -}; - - -#endif diff --git a/src/apps/resourceedit/Jamfile b/src/apps/resourceedit/Jamfile deleted file mode 100644 index 8167113914..0000000000 --- a/src/apps/resourceedit/Jamfile +++ /dev/null @@ -1,54 +0,0 @@ -SubDir HAIKU_TOP src apps resourceedit ; - -UsePrivateHeaders interface shared ; - -local sourceDirs = - edits - interface - settings - support -; - -local sourceDir ; - -for sourceDir in $(sourceDirs) { - SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps resourceedit $(sourceDir) ] ; -} - -Application ResourceEdit - : - # edits - AppFlagsEdit.cpp - BooleanEdit.cpp - EditView.cpp - NormalEdit.cpp - - # interface - ImageButton.cpp - - # settings - GenericSettingsView.cpp - - # support - UndoContext.cpp - - # . - DefaultTypes.cpp - EditWindow.cpp - MainWindow.cpp - ResourceEdit.cpp - ResourceListView.cpp - ResourceRow.cpp - SettingsFile.cpp - SettingsWindow.cpp - - main.cpp - : - be - tracker - translation - libcolumnlistview.a - [ TargetLibstdc++ ] - : - ResourceEdit.rdef -; diff --git a/src/apps/resourceedit/MainWindow.cpp b/src/apps/resourceedit/MainWindow.cpp deleted file mode 100644 index ae04c01af8..0000000000 --- a/src/apps/resourceedit/MainWindow.cpp +++ /dev/null @@ -1,1212 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "MainWindow.h" - -#include "Constants.h" -#include "EditWindow.h" -#include "ImageButton.h" -#include "ResourceListView.h" -#include "ResourceRow.h" -#include "SettingsFile.h" -#include "SettingsWindow.h" -#include "UndoContext.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -using namespace std; - - -MainWindow::MainWindow(BRect frame, BEntry* assocEntry, SettingsFile* settings) - : - BWindow(frame, NULL, B_DOCUMENT_WINDOW, B_OUTLINE_RESIZE) -{ - fAssocEntry = assocEntry; - fSettings = settings; - - fUndoContext = new UndoContext(); - - AdaptSettings(); - - fSavePanel = NULL; - fUnsavedChanges = false; - - fMenuBar = new BMenuBar(BRect(0, 0, 600, 1), "fMenuBar"); - - fFileMenu = new BMenu("File", B_ITEMS_IN_COLUMN); - fNewItem = new BMenuItem("New", new BMessage(MSG_NEW), 'N'); - fOpenItem = new BMenuItem("Open", new BMessage(MSG_OPEN), 'O'); - fCloseItem = new BMenuItem("Close", new BMessage(MSG_CLOSE), 'W'); - fSaveItem = new BMenuItem("Save", new BMessage(MSG_SAVE), 'S'); - fSaveAsItem = new BMenuItem("Save As" B_UTF8_ELLIPSIS, new - BMessage(MSG_SAVEAS)); - fSaveAllItem = new BMenuItem("Save All", new BMessage(MSG_SAVEALL), 'S', - B_SHIFT_KEY); - fMergeWithItem = new BMenuItem("Merge With" B_UTF8_ELLIPSIS, - new BMessage(MSG_MERGEWITH), 'M'); - fQuitItem = new BMenuItem("Quit", new BMessage(MSG_QUIT), 'Q'); - - fEditMenu = new BMenu("Edit", B_ITEMS_IN_COLUMN); - fUndoItem = new BMenuItem("Undo", new BMessage(MSG_UNDO), 'Z'); - fUndoItem->SetEnabled(false); - fRedoItem = new BMenuItem("Redo", new BMessage(MSG_REDO), 'Y'); - fRedoItem->SetEnabled(false); - fCutItem = new BMenuItem("Cut", new BMessage(MSG_CUT), 'X'); - fCutItem->SetEnabled(false); - fCopyItem = new BMenuItem("Copy", new BMessage(MSG_COPY), 'C'); - fCopyItem->SetEnabled(false); - fPasteItem = new BMenuItem("Paste", new BMessage(MSG_PASTE), 'V'); - fPasteItem->SetEnabled(false); - fClearItem = new BMenuItem("Clear", new BMessage(MSG_CLEAR)); - fSelectAllItem = new BMenuItem("Select All", - new BMessage(MSG_SELECTALL), 'A'); - - fToolsMenu = new BMenu("Tools", B_ITEMS_IN_COLUMN); - fAddAppResourcesItem = new BMenuItem("Add app resources", - new BMessage(MSG_ADDAPPRES)); - fSettingsItem = new BMenuItem("Settings", new BMessage(MSG_SETTINGS)); - - fHelpMenu = new BMenu("Help", B_ITEMS_IN_COLUMN); - - fResourceIDText = new BTextControl(BRect(0, 0, 47, 23).OffsetBySelf(8, 24), - "fResourceIDText", NULL, "0", NULL); - fResourceTypePopUp = new BPopUpMenu("(Type)"); - fResourceTypeMenu = new BMenuField(BRect(0, 0, 1, 1).OffsetBySelf(60, 24), - "fResourceTypeMenu", NULL, fResourceTypePopUp); - - for (int32 i = 0; kDefaultTypes[i].type != NULL; i++) { - if (kDefaultTypes[i].size == ~(uint32)0) - fResourceTypePopUp->AddSeparatorItem(); - else - fResourceTypePopUp->AddItem( - new BMenuItem(kDefaultTypes[i].type, NULL)); - } - - fResourceTypePopUp->ItemAt(kDefaultTypeSelected)->SetMarked(true); - - fToolbarView = new BView(BRect(0, 0, 600, 51), "fToolbarView", - B_FOLLOW_LEFT_RIGHT, 0); - - fToolbarView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - BRect toolRect = BRect(0, 0, 23, 23).OffsetBySelf(8, 24); - - fAddButton = new ImageButton(toolRect.OffsetBySelf(200, 0), - "fAddButton", BTranslationUtils::GetBitmap('PNG ', "add.png"), - new BMessage(MSG_ADD), B_FOLLOW_NONE); - fAddButton->ResizeTo(23, 23); - - fRemoveButton = new ImageButton(toolRect.OffsetBySelf(30, 0), - "fRemoveButton", BTranslationUtils::GetBitmap('PNG ', "remove.png"), - new BMessage(MSG_REMOVE), B_FOLLOW_NONE); - fRemoveButton->ResizeTo(23, 23); - fRemoveButton->SetEnabled(false); - - fMoveUpButton = new ImageButton(toolRect.OffsetBySelf(30, 0), - "fMoveUpButton", BTranslationUtils::GetBitmap('PNG ', "moveup.png"), - new BMessage(MSG_MOVEUP), B_FOLLOW_NONE); - fMoveUpButton->ResizeTo(23, 23); - fMoveUpButton->SetEnabled(false); - - fMoveDownButton = new ImageButton(toolRect.OffsetBySelf(30, 0), - "fMoveDownButton", BTranslationUtils::GetBitmap('PNG ', "movedown.png"), - new BMessage(MSG_MOVEDOWN), B_FOLLOW_NONE); - fMoveDownButton->ResizeTo(23, 23); - fMoveDownButton->SetEnabled(false); - - BRect listRect = Bounds(); - listRect.SetLeftTop(BPoint(0, 52)); - listRect.InsetBy(-1, -1); - - fResourceList = new ResourceListView(listRect, "fResourceList", - B_FOLLOW_ALL, 0); - - fResourceList->AddColumn(new BStringColumn("ID", 48, 1, 999, - B_ALIGN_LEFT), 0); - fResourceList->AddColumn(new BStringColumn("Name", 156, 1, 999, - B_TRUNCATE_END, B_ALIGN_LEFT), 1); - fResourceList->AddColumn(new BStringColumn("Type", 56, 1, 999, - B_TRUNCATE_END, B_ALIGN_CENTER), 2); - fResourceList->AddColumn(new BStringColumn("Code", 56, 1, 999, - B_TRUNCATE_END, B_ALIGN_CENTER), 3); - fResourceList->AddColumn(new BStringColumn("Data", 156, 1, 999, - B_TRUNCATE_END, B_ALIGN_LEFT), 4); - fResourceList->AddColumn(new BSizeColumn("Size", 74, 1, 999, - B_ALIGN_RIGHT), 5); - - //fResourceList->SetLatchWidth(0); - - fResourceList->SetTarget(this); - fResourceList->SetSelectionMessage(new BMessage(MSG_SELECTION)); - fResourceList->SetInvocationMessage(new BMessage(MSG_INVOCATION)); - - fStatsString = new BStringView(BRect(3, 2, 150, 13), "fStatsString", ""); - fStatsString->SetFontSize(11.0f); - - fStatsBox = new BBox(BRect(0, 0, 150, 16), "fStatsBox"); - fStatsBox->SetBorder(B_PLAIN_BORDER); - - AddChild(fMenuBar); - - fMenuBar->AddItem(fFileMenu); - fFileMenu->AddItem(fNewItem); - fFileMenu->AddItem(fOpenItem); - fFileMenu->AddItem(fCloseItem); - fFileMenu->AddSeparatorItem(); - fFileMenu->AddItem(fSaveItem); - fFileMenu->AddItem(fSaveAsItem); - fFileMenu->AddItem(fSaveAllItem); - fFileMenu->AddItem(fMergeWithItem); - fFileMenu->AddSeparatorItem(); - fFileMenu->AddItem(fQuitItem); - - fMenuBar->AddItem(fEditMenu); - fEditMenu->AddItem(fUndoItem); - fEditMenu->AddItem(fRedoItem); - fEditMenu->AddSeparatorItem(); - fEditMenu->AddItem(fCutItem); - fEditMenu->AddItem(fCopyItem); - fEditMenu->AddItem(fPasteItem); - fEditMenu->AddItem(fClearItem); - fEditMenu->AddSeparatorItem(); - fEditMenu->AddItem(fSelectAllItem); - - fMenuBar->AddItem(fToolsMenu); - fToolsMenu->AddItem(fAddAppResourcesItem); - fToolsMenu->AddSeparatorItem(); - fToolsMenu->AddItem(fSettingsItem); - - fMenuBar->AddItem(fHelpMenu); - - fToolbarView->AddChild(fResourceIDText); - fToolbarView->AddChild(fResourceTypeMenu); - - fToolbarView->AddChild(fAddButton); - fToolbarView->AddChild(fRemoveButton); - fToolbarView->AddChild(fMoveUpButton); - fToolbarView->AddChild(fMoveDownButton); - - AddChild(fToolbarView); - - AddChild(fResourceList); - fResourceList->AddStatusView(fStatsBox); - fStatsBox->AddChild(fStatsString); - - if (assocEntry != NULL) { - _SetTitleFromEntry(); - _Load(); - } else { - SetTitle("ResourceEdit | " B_UTF8_ELLIPSIS); - } -} - - -MainWindow::~MainWindow() -{ - delete fUndoContext; -} - - -bool -MainWindow::QuitRequested() -{ - // CAUTION: Do not read the body of this function if you - // are known to suffer from gotophobia. - - if (fUnsavedChanges) { - Activate(); - - char nameBuffer[B_FILE_NAME_LENGTH]; - - if (fAssocEntry != NULL) - fAssocEntry->GetName(nameBuffer); - else - strcpy(nameBuffer, "Untitled"); - - BString warning = ""; - warning << "Save changse to'"; - warning << nameBuffer; - warning << "' before closing?"; - - BAlert* alert = new BAlert("Save", warning.String(), - "Cancel", "Don't save", "Save", - B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT); - - alert->SetShortcut(0, B_ESCAPE); - - int32 result = alert->Go(); - - switch (result) { - case 0: - return false; - case 1: - goto quit; - case 2: - { - _Save(); - - if (fUnsavedChanges) - return false; - else - goto quit; - } - } - } - - quit: - BMessage* msg = new BMessage(MSG_CLOSE); - msg->AddPointer("window", (void*)this); - be_app->PostMessage(msg); - return true; -} - - -void -MainWindow::SelectionChanged() -{ - if (fResourceList->CurrentSelection(NULL) == NULL) { - fMoveUpButton->SetEnabled(false); - fMoveDownButton->SetEnabled(false); - fRemoveButton->SetEnabled(false); - - fCutItem->SetEnabled(false); - fCopyItem->SetEnabled(false); - } else { - fRemoveButton->SetEnabled(true); - fMoveUpButton->SetEnabled(!fResourceList->RowAt(0)->IsSelected()); - fMoveDownButton->SetEnabled(!fResourceList->RowAt( - fResourceList->CountRows() - 1)->IsSelected()); - - fCutItem->SetEnabled(true); - fCopyItem->SetEnabled(true); - } -} - - -void -MainWindow::MouseDown(BPoint point) -{ - -} - - -void -MainWindow::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case MSG_NEW: - be_app->PostMessage(MSG_NEW); - break; - - case MSG_OPEN: - be_app->PostMessage(MSG_OPEN); - break; - - case MSG_CLOSE: - PostMessage(B_QUIT_REQUESTED); - break; - - case MSG_SAVE: - _Save(); - break; - - case MSG_SAVEAS: - _SaveAs(); - break; - - case MSG_SAVEAS_DONE: - { - entry_ref ref; - const char* leaf; - - if (msg->FindRef("directory", &ref) != B_OK) - break; - - if (msg->FindString("name", &leaf) != B_OK) - break; - - BDirectory dir(&ref); - _Save(new BEntry(&dir, leaf)); - - break; - } - case MSG_SAVEALL: - be_app->PostMessage(MSG_SAVEALL); - break; - - case MSG_MERGEWITH: - PRINT(("[MSG_MERGEWITH]: Not yet implemented.")); - // TODO: Implement. - // "Merge from..." might be a better idea actually. - break; - - case MSG_QUIT: - be_app->PostMessage(B_QUIT_REQUESTED); - break; - - case MSG_UNDO: - fUndoContext->Undo(); - _RefreshUndoRedo(); - break; - - case MSG_REDO: - fUndoContext->Redo(); - _RefreshUndoRedo(); - break; - - case MSG_CUT: - // TODO: Implement. - PRINT(("[MSG_CUT]: Not yet implemented.")); - break; - - case MSG_COPY: - // TODO: Implement. - PRINT(("[MSG_COPY]: Not yet implemented.")); - break; - - case MSG_PASTE: - // TODO: Implement. - PRINT(("[MSG_PASTE]: Not yet implemented.")); - break; - - case MSG_CLEAR: - { - BList* rows = new BList(); - - for (int32 i = 0; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - row->ActionIndex = i; - rows->AddItem(row); - } - - _Do(new RemoveAction("Clear", fResourceList, rows)); - - SelectionChanged(); - break; - } - case MSG_SELECTALL: - { - for (int32 i = 0; i < fResourceList->CountRows(); i++) - fResourceList->AddToSelection(fResourceList->RowAt(i)); - - SelectionChanged(); - break; - } - case MSG_SETTINGS: - be_app->PostMessage(MSG_SETTINGS); - break; - - case MSG_ADD: - { - // Thank you, François Claus :D Merry Christmas! - - int32 ix = fResourceTypePopUp->FindMarkedIndex(); - - if (ix != -1) { - BList* rows = new BList(); - - ResourceRow* row = new ResourceRow(); - row->SetResourceID(_NextResourceID()); - row->SetResourceType(kDefaultTypes[ix].type); - row->SetResourceStringCode(kDefaultTypes[ix].code); - row->SetResourceData(kDefaultTypes[ix].data); - row->SetResourceSize(kDefaultTypes[ix].size); - row->ActionIndex = fResourceList->CountRows(NULL); - - rows->AddItem(row); - - _Do(new AddAction("Add", fResourceList, rows)); - } - - break; - } - case MSG_REMOVE: - { - BList* rows = new BList(); - - for (int i = 0; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - - if (row->IsSelected()) { - row->ActionIndex = i; - rows->AddItem(row); - } - } - - if (!rows->IsEmpty()) - _Do(new RemoveAction("Remove", fResourceList, rows)); - else - delete rows; - - break; - } - case MSG_MOVEUP: - { - BList* rows = new BList(); - - for (int i = 1; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - - if (row->IsSelected()) { - row->ActionIndex = i; - rows->AddItem(row); - } - } - - _Do(new MoveUpAction("Move Up", fResourceList, rows)); - - break; - } - case MSG_MOVEDOWN: - { - BList* rows = new BList(); - - for (int i = 0; i < fResourceList->CountRows() - 1; i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - - if (row->IsSelected()) { - row->ActionIndex = i; - rows->AddItem(row); - } - } - - _Do(new MoveDownAction("Move Down", fResourceList, rows)); - - break; - } - case MSG_SELECTION: - SelectionChanged(); - break; - - case MSG_INVOCATION: - { - BRect frame = Frame(); - - new EditWindow(BRect(frame.left + 50, frame.top + 50, - frame.left + 300, frame.top + 350), - (ResourceRow*)fResourceList->CurrentSelection()); - - break; - } - case MSG_SETTINGS_APPLY: - AdaptSettings(); - break; - - default: - BWindow::MessageReceived(msg); - } -} - - -void -MainWindow::AdaptSettings() -{ - fUndoContext->SetLimit(fSettings->UndoLimit); -} - - -void -MainWindow::_SetTitleFromEntry() -{ - char nameBuffer[B_FILE_NAME_LENGTH]; - - fAssocEntry->GetName(nameBuffer); - - BString title; - title << "ResourceEdit | "; - title << nameBuffer; - SetTitle(title); -} - - -void -MainWindow::_SaveAs() -{ - if (fSavePanel == NULL) - fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, - B_FILE_NODE, false, new BMessage(MSG_SAVEAS_DONE)); - - fSavePanel->Rewind(); - fSavePanel->Show(); -} - - -void -MainWindow::_Save(BEntry* entry) -{ - if (entry == NULL) { - if (fAssocEntry == NULL) { - _SaveAs(); - return; - } else - entry = fAssocEntry; - } else { - if (fAssocEntry == NULL) { - fAssocEntry = entry; - _SetTitleFromEntry(); - } - } - - BPath path; - entry->GetPath(&path); - - // I wouldn't use std:: if BFile had cooler stuff. - // Not very comfortable here. - - fstream out(path.Path(), ios::out); - - time_t timeNow = time(0); - - - out << "/*" << endl; - out << " * This file is auto-generated by Haiku ResourceEdit." << endl; - out << " * Time: " << ctime((const time_t*)&timeNow); - out << " */" << endl; - - for (int32 i = 0; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - - out << endl; - out << "resource"; - - if (row->ResourceStringID()[0] != '\0') { - out << "(" << row->ResourceID(); - - if (row->ResourceName()[0] != '\0') - out << ", \"" << row->ResourceName() << "\""; - - out << ")"; - } else { - if (row->ResourceName()[0] != '\0') - out << "(\"" << row->ResourceName() << "\")"; - } - - out << " "; - - if (row->ResourceStringCode()[0] != '\0') - out << "#\'" << row->ResourceStringCode() << "\' "; - - if (strcmp(row->ResourceType(), "raw") != 0) - out << row->ResourceType() << ' ' << row->ResourceData(); - else { - // TODO: Implement hexdump and import. - out << "array {" << endl; - out << "\t\"Not yet implemented.\"" << endl; - out << "}"; - } - - out << ";" << endl; - } - - out.close(); - - // Killed code: Export to .rsrc - - /*BFile* file = new BFile(entry, B_READ_WRITE | B_CREATE_FILE); - BResources output(file, true); - delete file; - - for (int32 i = 0; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - - output.AddResource(row->ResourceCode(), row->ResourceID(), - row->ResourceRawData(), row->ResourceSize(), row->ResourceName()); - } - - output.Sync();*/ - - fUnsavedChanges = false; -} - - -void -MainWindow::_Load() -{ - // CAUTION: Here be dragons. - - // [Initialization phase] - - BPath path; - struct stat st; - - fAssocEntry->GetPath(&path); - fAssocEntry->GetStat(&st); - - int fd = open(path.Path(), 0); - - const char* in = (const char*)mmap(NULL, st.st_size, PROT_READ, - MAP_SHARED, fd, 0); - - // [Setup phase] - - enum { - T_STATE_NORMAL, - T_STATE_COMMENT, - T_STATE_MULTILINE_COMMENT, - T_STATE_STRING, - } t_state = T_STATE_NORMAL; - - char quoteType = '\0'; - - char escChars[256]; - - for (int32 i = 0; i < 256; i++) - escChars[i] = ~(char)0; - - escChars['n'] = '\n'; - escChars['t'] = '\t'; - escChars['r'] = '\r'; - escChars['0'] = '\0'; - escChars['"'] = '\"'; - escChars['\'']= '\''; - - // TODO: Add other escape sequences? - // Multichar escape sequences cannot be resolved with this. - - BString buffer = ""; - BList* tokens = new BList(); - - BList* errors = new BList(); - // Multiple errors are allowed, but currently unused. - - BList* rows = new BList(); - - // [Tokenization phase] - - for (int32 i = 0; i < st.st_size - 1; i++) { - if (t_state == T_STATE_NORMAL) { - if (in[i] == ' ' || in[i] == '\t' || in[i] == '\n' - || in[i] == '\r') { - - if (buffer != "") { - tokens->AddItem(new BString(buffer)); - buffer = ""; - } - - continue; - } - - if (in[i] == ',' || in[i] == ';' || in[i] == '{' || in[i] == '}' - || in[i] == '(' || in[i] == ')') { - if (buffer != "") { - tokens->AddItem(new BString(buffer)); - buffer = in[i]; - tokens->AddItem(new BString(buffer)); - buffer = ""; - } - - continue; - } - - if (in[i] == '"' || in[i] == '\'') { - t_state = T_STATE_STRING; - quoteType = in[i]; - buffer += in[i]; - continue; - } - - if (in[i] == '/') { - if (in[i + 1] == '/') { - t_state = T_STATE_COMMENT; - continue; - } - - if (in[i + 1] == '*') { - t_state = T_STATE_MULTILINE_COMMENT; - continue; - } - } - - buffer += in[i]; - - } else if (t_state == T_STATE_COMMENT) { - if (in[i] == '\n') { - t_state = T_STATE_NORMAL; - continue; - } - } else if (t_state == T_STATE_MULTILINE_COMMENT) { - if (in[i] == '*' && in[i + 1] == '/') { - t_state = T_STATE_NORMAL; - i++; - continue; - } - } else if (t_state == T_STATE_STRING) { - if (in[i] == '\\' && escChars[(int)in[i]] != ~(char)0) { - buffer += escChars[(int)in[i]]; - i++; - continue; - } - - if (in[i] == quoteType) { - buffer += in[i]; - tokens->AddItem(new BString(buffer)); - buffer = ""; - t_state = T_STATE_NORMAL; - continue; - } - - buffer += in[i]; - } else { - // This can't even happen. - } - } - - if (t_state == T_STATE_MULTILINE_COMMENT) - errors->AddItem(new BString( - "Multi-line comment not closed by end of file.")); - else if (t_state == T_STATE_STRING) - errors->AddItem(new BString("String not closed by end of file.")); - else { - // [Parsing phase] - - for (int32 i = 0; i < tokens->CountItems(); i++) { - BString& token = *(BString*)tokens->ItemAt(i); - - if (token == "resource") { - ResourceRow* row = new ResourceRow(); - - token = *(BString*)tokens->ItemAt(++i); - - if (token[0] == '(') { - BList args; - bool wantComma = false; - - while (true) { - token = *(BString*)tokens->ItemAt(++i); - - if (token[0] == ')') - break; - - if (wantComma) { - if (token[0] != ',') { - errors->AddItem(new BString("Expected ','.")); - break; - } - - wantComma = false; - } else { - args.AddItem(tokens->ItemAt(i)); - wantComma = true; - } - } - - if (errors->CountItems() > 0) - break; - - token = *(BString*)tokens->ItemAt(++i); - - if (args.CountItems() > 2) { - errors->AddItem(new BString( - "Too many arguments for resource identifier.")); - break; - } - - if (args.CountItems() >= 1) { - BString& arg = *(BString*)args.ItemAt(0); - - if (arg[0] == '"') { - errors->AddItem(new BString( - "Resource ID cannot be a string.")); - break; - } - - row->SetResourceStringID(arg); - } - - if (args.CountItems() == 2) { - BString& arg = *(BString*)args.ItemAt(1); - - if (arg[0] != '"') { - errors->AddItem(new BString( - "Resource name must be a string.")); - break; - } - - row->SetResourceName(arg); - } - } - - if (token[0] == '#') { - if (token.Length() != 7 - || token[1] != '\'' || token[6] != '\'') { - errors->AddItem(new BString( - "Invalid syntax for resource type-code.")); - break; - } - - BString code; - token.CopyInto(code, 2, 4); - row->SetResourceStringCode(code); - - token = *(BString*)tokens->ItemAt(++i); - } - - if (token[0] == '(') { - BString& type = *(BString*)tokens->ItemAt(++i); - token = *(BString*)tokens->ItemAt(++i); - - if (token[0] != ')') { - errors->AddItem(new BString( - "Expected ')'.")); - break; - } - - row->SetResourceType(type); - } - - } else if (token == "type") { - // TODO: Implement. - } else if (token == "enum") { - // TODO: Implement. - } - } - } - - // [Result phase] - - if (errors->CountItems() > 0) { - for (int32 i = 0; i < errors->CountItems(); i++) { - BString& error = *(BString*)errors->ItemAt(i); - PRINT(("ERROR: %s\n", error.String())); - delete (BString*)tokens->ItemAt(i); - } - - delete errors; - } else { - for (int32 i = 0; i < rows->CountItems(); i++) { - ResourceRow* row = (ResourceRow*)rows->ItemAt(i); - PRINT(("[Resource]\n")); - PRINT(("id = %s\n", row->ResourceStringID())); - PRINT(("name = %s\n", row->ResourceName())); - // ... - PRINT(("\n")); - } - } - - // [Cleanup phase] - - for (int32 i = 0; i < tokens->CountItems(); i++) - delete (BString*)tokens->ItemAt(i); - - delete tokens; - - munmap((void*)in, st.st_size); - - // Killed code: Import from .rsrc - - /*BFile* file = new BFile(fAssocEntry, B_READ_ONLY); - BResources input(file); - delete file; - - type_code code; - int32 id; - const char* name; - size_t size; - - for (int32 i = 0; input.GetResourceInfo(i, &code, &id, &name, &size); i++) { - ResourceRow* row = new ResourceRow(); - row->SetResourceID(id); - row->SetResourceName(name); - row->SetResourceSize(size); - row->SetResourceCode(code); - row->SetResourceRawData(input.LoadResource(code, id, &size)); - fResourceList->AddRow(row); - }*/ -} - - -int32 -MainWindow::_NextResourceID() -{ - int32 currentID = atoi(fResourceIDText->Text()); - int32 nextID = currentID + 1; - BString text; - - // Should I check if the ID is already present in the list? - // Hmmm... - - text << nextID; - fResourceIDText->SetText(text); - - return currentID; -} - - -void -MainWindow::_RefreshStats() -{ - const size_t kB = 1024; - const size_t MB = 1024 * 1024; - const size_t GB = 1024 * 1024 * 1024; - - size_t size = 0; - - BString text = ""; - - text << fResourceList->CountRows(); - text << " resources, "; - - for (int32 i = 0; i < fResourceList->CountRows(); i++) { - ResourceRow* row = (ResourceRow*)fResourceList->RowAt(i); - size += row->ResourceSize(); - } - - if (size >= GB) { - text << (double)size / GB; - text << " GB"; - } else if (size >= MB) { - text << (double)size / MB; - text << " MB"; - } else if (size >= kB) { - text << (double)size / kB; - text << " kB"; - } else { - text << size; - text << " bytes"; - } - - fStatsString->SetText(text); -} - - -void -MainWindow::_RefreshUndoRedo() -{ - if (fUndoContext->CanUndo()) { - fUndoItem->SetEnabled(true); - fUndoItem->SetLabel(fUndoContext->UndoLabel().Prepend("Undo ")); - } else { - fUndoItem->SetEnabled(false); - fUndoItem->SetLabel("Undo"); - } - - if (fUndoContext->CanRedo()) { - fRedoItem->SetEnabled(true); - fRedoItem->SetLabel(fUndoContext->RedoLabel().Prepend("Redo ")); - } else { - fRedoItem->SetEnabled(false); - fRedoItem->SetLabel("Redo"); - } -} - - -void -MainWindow::_Do(UndoContext::Action* action) -{ - fUnsavedChanges = true; - fUndoContext->Do(action); - _RefreshStats(); - _RefreshUndoRedo(); -} - - -MainWindow::AddAction::AddAction(const BString& label, - ResourceListView* list, BList* rows) - : - UndoContext::Action(label) -{ - fList = list; - fRows = rows; - fAdded = false; -} - - -MainWindow::AddAction::~AddAction() -{ - if (!fAdded) - for (int32 i = 0; i < fRows->CountItems(); i++) - delete (ResourceRow*)fRows->ItemAt(i); - - delete fRows; -} - - -void -MainWindow::AddAction::Do() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - fList->AddRow(row, row->ActionIndex, row->Parent); - } - - fAdded = true; -} - - -void -MainWindow::AddAction::Undo() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) - fList->RemoveRow((ResourceRow*)fRows->ItemAt(i)); - - fAdded = false; -} - - -MainWindow::RemoveAction::RemoveAction(const BString& label, - ResourceListView* list, BList* rows) - : - UndoContext::Action(label) -{ - fList = list; - fRows = rows; - fRemoved = false; -} - - -MainWindow::RemoveAction::~RemoveAction() -{ - if (fRemoved) - for (int32 i = 0; i < fRows->CountItems(); i++) - delete (ResourceRow*)fRows->ItemAt(i); - - delete fRows; -} - - -void -MainWindow::RemoveAction::Do() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) - fList->RemoveRow((ResourceRow*)fRows->ItemAt(i)); - - fRemoved = true; -} - - -void -MainWindow::RemoveAction::Undo() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - - fList->AddRow(row, row->ActionIndex, row->Parent); - } - - fRemoved = false; -} - -// TODO: Implement EditAction - -MainWindow::MoveUpAction::MoveUpAction(const BString& label, - ResourceListView* list, BList* rows) - : - UndoContext::Action(label) -{ - fList = list; - fRows = rows; -} - - -MainWindow::MoveUpAction::~MoveUpAction() -{ - delete fRows; -} - - -void -MainWindow::MoveUpAction::Do() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - - fList->SwapRows(row->ActionIndex, row->ActionIndex - 1, - row->Parent, row->Parent); - - row->ActionIndex--; - } - - fList->SelectionChanged(); -} - - -void -MainWindow::MoveUpAction::Undo() -{ - for (int32 i = fRows->CountItems() - 1; i >= 0; i--) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - - fList->SwapRows(row->ActionIndex, row->ActionIndex + 1, - row->Parent, row->Parent); - - row->ActionIndex++; - } - - fList->SelectionChanged(); -} - -MainWindow::MoveDownAction::MoveDownAction(const BString& label, - ResourceListView* list, BList* rows) - : - UndoContext::Action(label) -{ - fList = list; - fRows = rows; -} - - -MainWindow::MoveDownAction::~MoveDownAction() -{ - delete fRows; -} - - -void -MainWindow::MoveDownAction::Do() -{ - for (int32 i = fRows->CountItems() - 1; i >= 0; i--) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - - fList->SwapRows(row->ActionIndex, row->ActionIndex + 1, - row->Parent, row->Parent); - - row->ActionIndex++; - } - - fList->SelectionChanged(); -} - - -void -MainWindow::MoveDownAction::Undo() -{ - for (int32 i = 0; i < fRows->CountItems(); i++) { - ResourceRow* row = (ResourceRow*)fRows->ItemAt(i); - - fList->SwapRows(row->ActionIndex, row->ActionIndex - 1, - row->Parent, row->Parent); - - row->ActionIndex--; - } - - fList->SelectionChanged(); -} - diff --git a/src/apps/resourceedit/MainWindow.h b/src/apps/resourceedit/MainWindow.h deleted file mode 100644 index b903e1ef7a..0000000000 --- a/src/apps/resourceedit/MainWindow.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef MAIN_WINDOW_H -#define MAIN_WINDOW_H - - -#include "UndoContext.h" - -#include - - -class ImageButton; -class ResourceListView; -class ResourceRow; -class SettingsFile; - -class BBox; -class BEntry; -class BFilePanel; -class BMenu; -class BMenuBar; -class BMenuField; -class BMenuItem; -class BMessage; -class BPopUpMenu; -class BStringView; -class BTextControl; - - -class MainWindow : public BWindow { -public: - MainWindow(BRect frame, BEntry* entry, SettingsFile* settings); - ~MainWindow(); - - bool QuitRequested(); - void MouseDown(BPoint point); - void MessageReceived(BMessage* msg); - void SelectionChanged(); - - void AdaptSettings(); - -private: - BEntry* fAssocEntry; - SettingsFile* fSettings; - - BFilePanel* fSavePanel; - bool fUnsavedChanges; - - UndoContext* fUndoContext; - - BMenuBar* fMenuBar; - - BMenu* fFileMenu; - BMenuItem* fNewItem; - BMenuItem* fOpenItem; - BMenuItem* fCloseItem; - BMenuItem* fSaveItem; - BMenuItem* fSaveAsItem; - BMenuItem* fSaveAllItem; - BMenuItem* fMergeWithItem; - BMenuItem* fQuitItem; - - BMenu* fEditMenu; - BMenuItem* fUndoItem; - BMenuItem* fRedoItem; - BMenuItem* fCutItem; - BMenuItem* fCopyItem; - BMenuItem* fPasteItem; - BMenuItem* fClearItem; - BMenuItem* fSelectAllItem; - - BMenu* fToolsMenu; - BMenuItem* fAddAppResourcesItem; - BMenuItem* fSettingsItem; - - BMenu* fHelpMenu; - - BTextControl* fResourceIDText; - BPopUpMenu* fResourceTypePopUp; - BMenuField* fResourceTypeMenu; - - BView* fToolbarView; - ImageButton* fAddButton; - ImageButton* fRemoveButton; - ImageButton* fMoveUpButton; - ImageButton* fMoveDownButton; - - ResourceListView* fResourceList; - BBox* fStatsBox; - BStringView* fStatsString; - - void _SetTitleFromEntry(); - void _SaveAs(); - void _Save(BEntry* entry = NULL); - void _Load(); - - int32 _NextResourceID(); - - void _RefreshStats(); - void _RefreshUndoRedo(); - void _Do(UndoContext::Action* action); - - class AddAction : public UndoContext::Action { - public: - AddAction(const BString& label, - ResourceListView* list, BList* rows); - ~AddAction(); - - void Do(); - void Undo(); - - private: - ResourceListView* fList; - BList* fRows; - bool fAdded; - - }; - - class RemoveAction : public UndoContext::Action { - public: - RemoveAction(const BString& label, - ResourceListView* list, BList* rows); - ~RemoveAction(); - - void Do(); - void Undo(); - - private: - ResourceListView* fList; - BList* fRows; - bool fRemoved; - - }; - - class EditAction : public UndoContext::Action { - public: - EditAction(const BString& label, - ResourceListView* list, - ResourceRow* rowold, ResourceRow* rownew); - ~EditAction(); - - void Do(); - void Undo(); - - private: - ResourceListView* fList; - ResourceRow* fRowOld; - ResourceRow* fRowNew; - - }; - - class MoveUpAction : public UndoContext::Action { - public: - MoveUpAction(const BString& label, - ResourceListView* list, BList* rows); - ~MoveUpAction(); - - void Do(); - void Undo(); - - private: - ResourceListView* fList; - BList* fRows; - - }; - - class MoveDownAction : public UndoContext::Action { - public: - MoveDownAction(const BString& label, - ResourceListView* list, BList* rows); - ~MoveDownAction(); - - void Do(); - void Undo(); - - private: - ResourceListView* fList; - BList* fRows; - - }; -}; - - -#endif diff --git a/src/apps/resourceedit/ResourceEdit.cpp b/src/apps/resourceedit/ResourceEdit.cpp deleted file mode 100644 index 977e463797..0000000000 --- a/src/apps/resourceedit/ResourceEdit.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "ResourceEdit.h" - -#include "AboutWindow.h" -#include "Constants.h" -#include "MainWindow.h" -#include "SettingsFile.h" -#include "SettingsWindow.h" - -#include -#include - - -ResourceEdit::ResourceEdit() - : - BApplication("application/x-vnd.Haiku-ResourceEdit") -{ - fCascade = BRect(100, 100, 700, 400); - fCascadeCount = 0; - - fOpenPanel = new BFilePanel(B_OPEN_PANEL, &be_app_messenger, NULL, 0, true, - new BMessage(MSG_OPEN_DONE)); - - fSettings = new SettingsFile("resourceedit_settings"); - fSettings->Load(); - - fSettingsWindow = NULL; -} - - -ResourceEdit::~ResourceEdit() -{ - -} - - -void -ResourceEdit::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case MSG_NEW: - _CreateWindow(NULL); - break; - - case MSG_OPEN: - fOpenPanel->Show(); - break; - - case MSG_OPEN_DONE: - { - entry_ref ref; - - while (fOpenPanel->GetNextSelectedRef(&ref) == B_OK) - _CreateWindow(new BEntry(&ref)); - - fOpenPanel->Rewind(); - - break; - } - case MSG_CLOSE: - { - MainWindow* window; - msg->FindPointer("window", (void**)&window); - fWindowList.RemoveItem(window); - - if (fWindowList.CountItems() == 0) - Quit(); - - break; - } - case MSG_SAVEALL: - { - for (int32 i = 0; i < fWindowList.CountItems(); i++) { - MainWindow* window = ((MainWindow*)fWindowList.ItemAt(i)); - window->PostMessage(MSG_SAVE); - } - - break; - } - case MSG_SETTINGS: - { - if (fSettingsWindow != NULL) - fSettingsWindow->Activate(); - else - fSettingsWindow = new SettingsWindow(fSettings); - - break; - } - case MSG_SETTINGS_APPLY: - { - for (int32 i = 0; i < fWindowList.CountItems(); i++) { - MainWindow* window = ((MainWindow*)fWindowList.ItemAt(i)); - window->PostMessage(MSG_SETTINGS_APPLY); - } - - break; - } - case MSG_SETTINGS_CLOSED: - fSettingsWindow = NULL; - break; - - default: - BApplication::MessageReceived(msg); - } -} - - -void -ResourceEdit::ArgvReceived(int32 argc, char* argv[]) -{ - for (int32 i = 1; i < argc; i++) - _CreateWindow(new BEntry(argv[i])); -} - - -void -ResourceEdit::ReadyToRun() -{ - if (fWindowList.CountItems() <= 0) - _CreateWindow(NULL); -} - - -void -ResourceEdit::_CreateWindow(BEntry* assocEntry) -{ - MainWindow* window = new MainWindow(_Cascade(), assocEntry, fSettings); - - fWindowList.AddItem(window); - - window->Show(); -} - - -BRect -ResourceEdit::_Cascade() -{ - if (fCascadeCount == 8) { - fCascade.OffsetBy(-20 * 8, -20 * 8); - fCascadeCount = 0; - } else { - fCascade.OffsetBy(20, 20); - fCascadeCount++; - } - - return fCascade; -} diff --git a/src/apps/resourceedit/ResourceEdit.h b/src/apps/resourceedit/ResourceEdit.h deleted file mode 100644 index 6168fcfc2c..0000000000 --- a/src/apps/resourceedit/ResourceEdit.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef RESOURCE_EDIT_H -#define RESOURCE_EDIT_H - - -#include - - -class MainWindow; -class SettingsFile; -class SettingsWindow; - -class BEntry; -class BFilePanel; -class BMessage; - - -class ResourceEdit : public BApplication { -public: - ResourceEdit(); - ~ResourceEdit(); - - void MessageReceived(BMessage* msg); - -private: - BRect fCascade; - uint32 fCascadeCount; - BList fWindowList; - - BFilePanel* fOpenPanel; - - SettingsFile* fSettings; - SettingsWindow* fSettingsWindow; - - void ArgvReceived(int32 argc, char* argv[]); - void ReadyToRun(); - - void _CreateWindow(BEntry* assocEntry); - BRect _Cascade(); - -}; - - -#endif diff --git a/src/apps/resourceedit/ResourceEdit.rdef b/src/apps/resourceedit/ResourceEdit.rdef deleted file mode 100644 index c225980220..0000000000 --- a/src/apps/resourceedit/ResourceEdit.rdef +++ /dev/null @@ -1,136 +0,0 @@ -resource app_signature "application/x-vnd.Haiku-ResourceEdit"; - -resource app_name_catalog_entry "x-vnd.Haiku-ResourceEdit:System name:ResourceEdit"; - -resource app_version { - major = 0, - middle = 1, - minor = 0, - - variety = B_APPV_ALPHA, - internal = 0, - - short_info = "ResourceEdit", - long_info = "ResourceEdit © 2012-2013 Haiku, Inc." -}; - -resource app_flags B_SINGLE_LAUNCH; - -resource file_types message { - "types" = "text/x-vnd.Be.ResourceDef" -}; - -resource vector_icon { - $"6E6369660E050102000603399E0F3D9C0ABF82B23B84A94B88504870C900A5FF" - $"F5BCEAFFF2FFB3FFE3020106023E49240000000000003CAAAA4940004A3000FF" - $"C0FFDD7C6DFFBC040192020006023A4BAE3411A9B629883C6629495368484715" - $"00FFF9BAFFFFC104020006023A6A0E3670BCB6D8C13AD0F64A21BC4A0DF300BA" - $"DCFFFF2A20F10200060239AAD5343BA5B6E7993C629D4ABB354803A500E99797" - $"FFCE323202000602AAB1FB3A081FBE8A26AF5E794C4014448D43FFFDDCAB00DB" - $"AB5F02000602B507E13A82E2BAD599B56BB44A7652479FE400116201FE69A403" - $"020006023C08200000000000004000004A4000000000FD6AD839004AB9270200" - $"06023D4D340000000000004000004A5000000000009CFA80FFF8FAFF02000603" - $"B2F679BA14D43A7FB6B38E9E460F5547105A00FFEED58DDBAB5FCFFFEED50401" - $"95020012023B8E380000000000004000004A5400C100000001FFFF0199120606" - $"AE0BB40BBF4D33C3AFB75DC173BDEFC607C13EC804CA28BD82C118B920C51BBB" - $"40BF07B8083AB6BC0605AE02B57D3EB9B9C3EFB7BB44BBB751BD75C936CA8EC1" - $"B1402F0A093B593D5BBFCDC93E455BC516C5F160465B435D4544510A045A425E" - $"3F5A3D57400A063236323D3A41403E403739330A063A433A4A404D464A464341" - $"400A064237423E48424E3F4E3948350604EE532755295528552A532B5229522A" - $"52280604EE532456295625562D532E5029502D50250A04B969B771332E502E4E" - $"2B0A04B969B5BAB969B7714E2B4E270A043324B969B5BA4E2750240A063124B8" - $"BAB5B2B8BAB779312EB677B6ECB67CB63C0606B20831245356295625562D532E" - $"3126290804BA28B4D33027302BBA28B8580003C6E8B4D3C6E8B4D3C690B51750" - $"2950B59E50B78DC6E8B858C690B814C6E8B8580A04C6F0C5C24E4F514BC9BBC4" - $"280A06C4E04F41C507374B394A45C33CC6D1C36F120A030202032020250A0001" - $"0130202501178400040A0201012020250A00010030202501178400040A010100" - $"2020250A000304050630202501178400040A0401042020250A0501052020250A" - $"0601062020250A0C0110000A0D0111000A00030D0E0F123ED413BED4133ED413" - $"3ED41347F4A24A588901178400040A0B010C023ED413BED4133ED4133ED41347" - $"F4A24A58890A0A010B023ED413BED4133ED4133ED41347F4A24A58890A09010A" - $"023ED413BED4133ED4133ED41347F4A24A58890A080109023ED413BED4133ED4" - $"133ED41347F4A24A58890A070108023ED413BED4133ED4133ED41347F4A24A58" - $"890A0001070A3ED413BED4133ED4133ED41347F4A24A588915FF" -}; - -resource(1, "add.png") #'PNG ' array { - $"89504E470D0A1A0A0000000D4948445200000018000000180806000000E0773D" - $"F80000017B494441544889ED95B14EC25014863F6AAB4864C40768D84C184908" - $"3E002B899B71742171C7677024716572C207707124260C0E460709A94C86844D" - $"144BEF6D716841CA2D5083C6857FBB7FFE73BF7B4F7B5AD8E8BF9588952A5231" - $"0B660D1D0D008967DD59559A5CAC2AD56301D2E473A739CDD8330010EF42B31E" - $"AD32D000BAEB03005BDA48210190524EEC9D5575B1011FCE07C676700347C42D" - $"8B0F1042E0391E00AE70D70014A990261FF2521C0EE5105DF8712925A4C852A2" - $"0EB4A7B9012D9A5CCE96AA6FD119AE79646AF3B6B16B7CA7C7203ED53659D796" - $"478D1CF0B4F8060934477714DB11735E54731368C0FE72C018466214511D4363" - $"D5520112AFFFD6575A4492508BB02300126F35E0812A2F94435E8A2CC7644806" - $"6B1BB8A2CF904E2837A00B61880AF0C7BFC1EC1095A8E3929996BAC0900E379C" - $"03BDB91D5E97037C75E7D66DA01091EB01CF0BF60040EDF52FEBCF01F13E1503" - $"5ADC72C2567020172F78A02B15EF7FE0EB007F8826F2807B60F0833D3652F505" - $"AA6A764F51A11AA20000000049454E44AE426082" -}; - -resource(2, "remove.png") #'PNG ' array { - $"89504E470D0A1A0A0000000D4948445200000018000000180806000000E0773D" - $"F800000275494441544889ED94C14B93611CC73F7B7D6DF80EDA72BEAFCE2D82" - $"57F022099AE065902884791C41052BD7FE804DA48378AF4E49978E199845273D" - $"CC90C0759B78085C66186387053A9C4B3417CB4DD6D3C136F5F5DDC04E1DFCC2" - $"0F5E9EDFFB7EBEBFEFFB3CEF0BE7FA6FA5C3C551557D1780A78064728B148027" - $"A3AAFA5E07C799E1E31ECFC7642824627EBF08C282C1440AC2B398DF2F92A190" - $"18F778523A38CD587566F03BAAFA617868E85A8BA2D06CB3E172B974CBDA9A77" - $"19A6014B10261EF87CE14EB71B9B24D1E6763B4AEBEBB737F2F9573BF0ABA6C1" - $"B0AACE04FBFBAF373734208A4544B188A628B8344D9792496F17740D0F0E86AF" - $"B6B454FA3649A2ADB5D5F1736BEBE6523EFF02289579B2D160379BFDBA99C90C" - $"A986F50EBB9D7B7D7D03C04087DD4E696FEF447F339361379BDD00BA81A5AA09" - $"E2B050974A793545D1554942140A9552651955964FAC894281CFE934D38B8BD1" - $"97F01A5804F6AB1A006219A6E574DAAB59AD7A932C230E0EAAD66A26C39B783C" - $"3A09534004D8A9B907C74DEAB359AF2ACB7A9310A7A61685025FB6B7799B4854" - $"8583C91E18B42A72B9815295A6C8E5CA977366F05A09A4204CDC8270BBCD5639" - $"2DC67202CDF9BC6E859EBF47581841966A701F84DB6BA7AB2801CC4074126E00" - $"BF6B2608C0631F3C348327806D4E7FB24E4003DD0ABDF1C3937434AD11E280EE" - $"C62AF05988CE423461D26F3C7CD60D74D64CB00573F570F7323814037C12A696" - $"E15103F468A097937C0722F06D069EEFC027E087C90C47D2C13906A918880894" - $"7F76F7814BE5E44158888088811883940E21A0AD26D86832022B019837C0CB92" - $"02303F022B67861FD305A0D7045E9685C3777EE55FE0E702E00F037E0BAE5DFC" - $"3C830000000049454E44AE426082" -}; - -resource(3, "moveup.png") #'PNG ' array { - $"89504E470D0A1A0A0000000D4948445200000018000000180806000000E0773D" - $"F8000001C8494441544889ED933B485B6118861F93D8788F510E27DAE00D259D" - $"0485823108723843296E22850E0EBA140AA543C4A18A9442A920EA62068582E2" - $"E0AA83E2050415A18B882028ED927AE8693C31510721A8F93B5841E9C9498A2E" - $"822FBCC3CFF7F3BCDFF75FE0510F465EC81E57F93AAE32ED85EC7B854B609F50" - $"98D4D755A1AFAB6242615302C77DC16D2185316D392044AC4D88589BD0960222" - $"A4B02A81FDCEF0D116BE84E7EA8530945B0ECFD58B911616D2312C3B1808F0A1" - $"FD9DAFBFB2D90DE2F2965D4F9DC8725E6D997ED4B072C0CC7F077C6AE27DC79B" - $"9AC19AD6221017A676573CC1539CFB4CFA1DAF5CD598CD38A0EF39DDAFBBA550" - $"9D5A00E2DCD22555763C85B686E2C8996BED178B6903828DBCEAEC94A67C2F9C" - $"64610DBF7669B5038FD3E9CF3B3C4B6EEAACDDE4FDF3D4FCE5F4D8EC063F96AE" - $"D6451512B2CFFC1823FB70FAD3B8EAD401FE72BAD8620A08A70CF8F80DD5BB4D" - $"179053E6C2DDFBD608CAB5E601A761181C63483F210EA02530807CCB09760C8E" - $"776018E025549324C8A5790049D04F88CF6B7C4EB12383DF28FE3A552D8D6CE9" - $"B7DC4D0F3FC0F20EB404D1EF1B44627BC866F5A328112D41D48A919541138540" - $"23A9A73D047633E03CCA5C7F00288AC08FE23A7EB30000000049454E44AE4260" - $"82" -}; - -resource(4, "movedown.png") #'PNG ' array { - $"89504E470D0A1A0A0000000D4948445200000018000000180806000000E0773D" - $"F8000001E6494441544889ED92DD4B53611CC73F6ED5BC680D978F6B792AC45C" - $"E164577A9710E7A6B0BAEAAE0B41F09F08BAEAC66E4421F042AF6A228A2F28BA" - $"A42226859B48DD0C247A811C8E1DE2D0081793A9674F174B523BCF966F78515F" - $"F8C173CEF7F7FB7E785EE0BF8E5B15A5CC90C0DD7543BC3DEB7707ECFC6F46D6" - $"B8FFDC6C4A98645419274A013417D50D37EB030D772ED8FA9FA657FCDA9CD991" - $"80EE7D010028AC83B5A6F6C0556AFC2F0079B0726AAF8CCA03E426588A20B979" - $"08006B437D44D6C6DE0121C169CD8500F07BD09059B04EDA4FCB2C7E0F556D50" - $"0790CA63264C7E6C6FF9E3998EDF6631D8265A1CCEE2F7994BE0BB627F8F5F3F" - $"E4594D16D7050B969E99CB7767080159E50EE2691E5FCD9B4F03B704158E5F3F" - $"1577E0BB5C2C5980F71193789A97401058D8EA71EE1E8A1924BC192A6BDDB96B" - $"D5753990E5EBE38B1C4383841FBD631A7803584A00C0EB34AF6A329CABF5D0EC" - $"BD0848757D9E83E130230F17990422C08EEDDA0200A22922DA771ACF0B82559A" - $"7DCF9705187BC2D48338A3C00CA0786E0A0970F4B6329B0C23E5D2CE4A86913D" - $"ADCC02F700F79E827743FA74A2A991DFE1A96164DF75A202DA01CFBEC3B7419C" - $"033A316302698C23077462023A00EF81C3B7A4C1A97E9DF97E9D790D3A8BDCC3" - $"970368067C4711FE8FEA273678C1FAFB9AC8FD0000000049454E44AE426082" -}; diff --git a/src/apps/resourceedit/ResourceListView.cpp b/src/apps/resourceedit/ResourceListView.cpp deleted file mode 100644 index 654de4420b..0000000000 --- a/src/apps/resourceedit/ResourceListView.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "ResourceListView.h" - -#include "Constants.h" - -#include -#include - - -ResourceListView::ResourceListView(BRect rect, const char* name, - uint32 resizingMode, uint32 drawFlags, border_style border, - bool showHorizontalScrollbar) - : - BColumnListView(rect, name, resizingMode, drawFlags, border, - showHorizontalScrollbar) -{ - //SetMouseTrackingEnabled(true); -} - - -ResourceListView::~ResourceListView() -{ - -} - - -void -ResourceListView::MouseDown(BPoint point) -{ - PRINT(("MouseDown()")); -} - - -void -ResourceListView::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case B_SIMPLE_DATA: - { - entry_ref ref; - int32 n = 0; - - // TODO: Implement D&D adding of files. - - while (msg->FindRef("refs", n++, &ref) == B_OK) { - PRINT(("%s\n", ref.name)); - // ... - } - - break; - } - default: - BColumnListView::MessageReceived(msg); - } -} diff --git a/src/apps/resourceedit/ResourceListView.h b/src/apps/resourceedit/ResourceListView.h deleted file mode 100644 index 88657f9376..0000000000 --- a/src/apps/resourceedit/ResourceListView.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef RESOURCE_LIST_VIEW_H -#define RESOURCE_LIST_VIEW_H - - -#include - - -class ResourceListView : public BColumnListView { -public: - ResourceListView(BRect rect, const char* name, uint32 resizingMode, - uint32 drawFlags, border_style border = B_NO_BORDER, - bool showHorizontalScrollbar = true); - ~ResourceListView(); - - void MouseDown(BPoint point); - void MessageReceived(BMessage* msg); - -private: - -}; - - -#endif diff --git a/src/apps/resourceedit/ResourceRow.cpp b/src/apps/resourceedit/ResourceRow.cpp deleted file mode 100644 index ecf94f709c..0000000000 --- a/src/apps/resourceedit/ResourceRow.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "ResourceRow.h" - -#include -#include - -#include - - -ResourceRow::ResourceRow() - : - BRow() -{ - Parent = NULL; - ActionIndex = -1; - - SetField(new BStringField(""), 0); - SetField(new BStringField(""), 1); - SetField(new BStringField(""), 2); - SetField(new BStringField(""), 3); - SetField(new BStringField(""), 4); - SetField(new BSizeField(0), 5); -} - - -ResourceRow::~ResourceRow() -{ - // ... -} - - -void -ResourceRow::SetResourceID(int32 id) -{ - ((BStringField*)GetField(0))->SetString((BString() << id).String()); -} - - -void -ResourceRow::SetResourceStringID(const char* id) -{ - ((BStringField*)GetField(0))->SetString(id); -} - - -void -ResourceRow::SetResourceName(const char* name) -{ - ((BStringField*)GetField(1))->SetString(name); -} - - -void -ResourceRow::SetResourceType(const char* type) -{ - ((BStringField*)GetField(2))->SetString(type); -} - - -void -ResourceRow::SetResourceCode(type_code code) -{ - fCode = code; - ResourceType::CodeToString(code, fTypeString); - ((BStringField*)GetField(3))->SetString(fTypeString); -} - - -void -ResourceRow::SetResourceStringCode(const char* code) -{ - fCode = ResourceType::StringToCode(code); - ((BStringField*)GetField(3))->SetString(code); -} - - -void -ResourceRow::SetResourceData(const char* data) -{ - ((BStringField*)GetField(4))->SetString(data); -} - - -void -ResourceRow::SetResourceSize(off_t size) -{ - ((BSizeField*)GetField(5))->SetSize(size); -} - - -int32 -ResourceRow::ResourceID() -{ - const char* strID = ResourceStringID(); - - // TODO: Check whether is numeric and resolve if not. - - return atoi(strID); -} - - -const char* -ResourceRow::ResourceStringID() -{ - return ((BStringField*)GetField(0))->String(); -} - - -const char* -ResourceRow::ResourceName() -{ - return ((BStringField*)GetField(1))->String(); -} - - -const char* -ResourceRow::ResourceType() -{ - return ((BStringField*)GetField(2))->String(); -} - - -type_code -ResourceRow::ResourceCode() -{ - return fCode; -} - - -const char* -ResourceRow::ResourceStringCode() -{ - return ((BStringField*)GetField(3))->String(); -} - - -const char* -ResourceRow::ResourceData() -{ - return ((BStringField*)GetField(4))->String(); -} - - -off_t -ResourceRow::ResourceSize() -{ - return ((BSizeField*)GetField(5))->Size(); -} diff --git a/src/apps/resourceedit/ResourceRow.h b/src/apps/resourceedit/ResourceRow.h deleted file mode 100644 index 26d3660ff9..0000000000 --- a/src/apps/resourceedit/ResourceRow.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef RESOURCE_ROW_H -#define RESOURCE_ROW_H - - -#include "DefaultTypes.h" - -#include - - -class ResourceRow : public BRow { -public: - ResourceRow(); - ~ResourceRow(); - - void SetResourceID(int32 id); - void SetResourceStringID(const char* id); - void SetResourceName(const char* name); - void SetResourceType(const char* type); - void SetResourceCode(type_code code); - void SetResourceStringCode(const char* code); - void SetResourceData(const char* data); - void SetResourceSize(off_t size); - - int32 ResourceID(); - const char* ResourceStringID(); - const char* ResourceName(); - const char* ResourceType(); - type_code ResourceCode(); - const char* ResourceStringCode(); - const char* ResourceData(); - off_t ResourceSize(); - - ResourceRow* Parent; - int32 ActionIndex; -private: - type_code fCode; - char fTypeString[8]; - -}; - - -#endif diff --git a/src/apps/resourceedit/SettingsFile.cpp b/src/apps/resourceedit/SettingsFile.cpp deleted file mode 100644 index 63e84b5d9d..0000000000 --- a/src/apps/resourceedit/SettingsFile.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "SettingsFile.h" - - -SettingsFile::SettingsFile(const char* name) -{ - find_directory(B_USER_SETTINGS_DIRECTORY, &fPath); - fPath.Append(name, true); -} - - -SettingsFile::~SettingsFile() -{ - -} - - -void -SettingsFile::Defaults() -{ - UndoLimit = 100; -} - - -void -SettingsFile::Load() -{ - fFile = new BFile(fPath.Path(), B_READ_ONLY); - - if (fFile->InitCheck() == B_OK) { - fFile->Read(&UndoLimit, sizeof(UndoLimit)); - // TODO: Add more settings here (2/3). - } else - Defaults(); - - delete fFile; -} - - -void -SettingsFile::Save() -{ - fFile = new BFile(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE); - - if (fFile->InitCheck() == B_OK) { - fFile->Write(&UndoLimit, sizeof(UndoLimit)); - // TODO: Add more settings here (3/3). - } - - delete fFile; -} diff --git a/src/apps/resourceedit/SettingsFile.h b/src/apps/resourceedit/SettingsFile.h deleted file mode 100644 index 2c52232b4b..0000000000 --- a/src/apps/resourceedit/SettingsFile.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef SETTINGS_FILE_H -#define SETTINGS_FILE_H - - -#include -#include -#include - - -class SettingsFile -{ -public: - int32 UndoLimit; - // TODO: Add more settings here (1/3). - - SettingsFile(const char* name); - ~SettingsFile(); - - void Defaults(); - void Load(); - void Save(); - -private: - BPath fPath; - BFile* fFile; -}; - - -#endif diff --git a/src/apps/resourceedit/SettingsWindow.cpp b/src/apps/resourceedit/SettingsWindow.cpp deleted file mode 100644 index 9817659cb9..0000000000 --- a/src/apps/resourceedit/SettingsWindow.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "SettingsWindow.h" - -#include "Constants.h" -#include "GenericSettingsView.h" -#include "SettingsFile.h" - -#include -#include -#include -#include -#include -#include -#include - - -SettingsWindow::SettingsWindow(SettingsFile* settings) - : - BWindow(BRect(200, 150, 600, 450), "Settings", B_TITLED_WINDOW, B_NOT_RESIZABLE) -{ - fSettings = settings; - - BRect bounds = Bounds(); - - fBackView = new BView(bounds, "fBackView", B_FOLLOW_ALL, 0); - fBackView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - fListView = new BListView(BRect(8, 8, 100 + 8, bounds.bottom - 8), - "fListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL); - - // TODO: Implement selecting different categories of settings. - // fListView->SetSelectionMessage(new BMessage(...)); - - fListView->AddItem(new BStringItem("Generic")); - fListView->Select(0); - - fScrollView = new BScrollView("fScrollView", fListView, B_FOLLOW_TOP_BOTTOM, - B_WILL_DRAW | B_FRAME_EVENTS, false, true); - - fGenericSettingsView = new GenericSettingsView( - BRect(132, 8, bounds.right - 8, bounds.bottom - 8 - 40), - "fGenericSettingsView", fSettings); - // TODO: Add more settings views (2/4). - - fRevertButton = new BButton(BRect(bounds.right - 152, bounds.bottom - 32, - bounds.right - 88, bounds.bottom - 8), - "fRevertButton", "Revert", - new BMessage(MSG_SETTINGS_REVERT)); - - fApplyButton = new BButton(BRect(bounds.right - 72, bounds.bottom - 32, - bounds.right - 8, bounds.bottom - 8), "fApplyButton", "Apply", - new BMessage(MSG_SETTINGS_APPLY)); - - AdaptSettings(); - - fBackView->AddChild(fScrollView); - fBackView->AddChild(fGenericSettingsView); - fBackView->AddChild(fRevertButton); - fBackView->AddChild(fApplyButton); - AddChild(fBackView); - - Show(); -} - - -SettingsWindow::~SettingsWindow() -{ - -} - - -bool -SettingsWindow::QuitRequested() -{ - be_app->PostMessage(MSG_SETTINGS_CLOSED); - return true; -} - -void -SettingsWindow::MessageReceived(BMessage* msg) -{ - switch (msg->what) - { - case MSG_SETTINGS_APPLY: - { - ApplySettings(); - fSettings->Save(); - be_app->PostMessage(MSG_SETTINGS_APPLY); - break; - } - case MSG_SETTINGS_REVERT: - { - AdaptSettings(); - fSettings->Save(); - be_app->PostMessage(MSG_SETTINGS_APPLY); - break; - } - default: - BWindow::MessageReceived(msg); - } -} - -void -SettingsWindow::ApplySettings() -{ - fGenericSettingsView->ApplySettings(); - // TODO: Add more settings views (3/4). -} - -void -SettingsWindow::AdaptSettings() -{ - fGenericSettingsView->AdaptSettings(); - // TODO: Add more settings views (4/4). -} diff --git a/src/apps/resourceedit/SettingsWindow.h b/src/apps/resourceedit/SettingsWindow.h deleted file mode 100644 index da015de5bf..0000000000 --- a/src/apps/resourceedit/SettingsWindow.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef SETTINGS_WINDOW_H -#define SETTINGS_WINDOW_H - - -#include - - -class GenericSettingsView; -class SettingsFile; - -class BButton; -class BListView; -class BScrollView; -class BView; - - -class SettingsWindow : public BWindow { -public: - SettingsWindow(SettingsFile* settings); - ~SettingsWindow(); - - bool QuitRequested(); - void MessageReceived(BMessage* msg); - - void ApplySettings(); - void AdaptSettings(); - -private: - SettingsFile* fSettings; - - BView* fBackView; - BListView* fListView; - BScrollView* fScrollView; - - GenericSettingsView* fGenericSettingsView; - // TODO: Add more settings (1/4). - - BButton* fRevertButton; - BButton* fApplyButton; - -}; - - -#endif diff --git a/src/apps/resourceedit/edits/AppFlagsEdit.cpp b/src/apps/resourceedit/edits/AppFlagsEdit.cpp deleted file mode 100644 index 5a1482533a..0000000000 --- a/src/apps/resourceedit/edits/AppFlagsEdit.cpp +++ /dev/null @@ -1,4 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ diff --git a/src/apps/resourceedit/edits/AppFlagsEdit.h b/src/apps/resourceedit/edits/AppFlagsEdit.h deleted file mode 100644 index 5a1482533a..0000000000 --- a/src/apps/resourceedit/edits/AppFlagsEdit.h +++ /dev/null @@ -1,4 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ diff --git a/src/apps/resourceedit/edits/BooleanEdit.cpp b/src/apps/resourceedit/edits/BooleanEdit.cpp deleted file mode 100644 index bf65a9335e..0000000000 --- a/src/apps/resourceedit/edits/BooleanEdit.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "NormalEdit.h" -#include "ResourceRow.h" - -#include -#include -#include - - -BooleanEdit::BooleanEdit() - : - EditView("BooleanEdit") -{ - -} - - -BooleanEdit::~BooleanEdit() -{ - -} - - -void -BooleanEdit::AttachTo(BView* view) -{ - EditView::AttachTo(view); - - SetLayout(new BGroupLayout(B_VERTICAL)); - - fValueCheck = new BCheckBox(BRect(0, 0, 0, 0), "fValueText", - "", NULL); - - AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) - .Add(fValueCheck) - .AddGlue() - ); - - view->AddChild(this); -} - - -void -BooleanEdit::Edit(ResourceRow* row) -{ - EditView::Edit(row); - - BString data = fRow->ResourceData(); - - if (data == "" || data == "0" || data == "false") - fValueCheck->SetValue(B_CONTROL_OFF); - else - fValueCheck->SetValue(B_CONTROL_ON); -} - - -void -BooleanEdit::Commit() -{ - EditView::Commit(); - - if (fValueCheck->Value() == B_CONTROL_ON) - fRow->SetResourceData("true"); - else - fRow->SetResourceData("false"); -} diff --git a/src/apps/resourceedit/edits/BooleanEdit.h b/src/apps/resourceedit/edits/BooleanEdit.h deleted file mode 100644 index 53889992bb..0000000000 --- a/src/apps/resourceedit/edits/BooleanEdit.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef BOOLEAN_EDIT_H -#define BOOLEAN_EDIT_H - - -#include "EditView.h" - - -class BCheckBox; - - -class BooleanEdit : public EditView { -public: - BooleanEdit(); - ~BooleanEdit(); - - void AttachTo(BView* view); - void Edit(ResourceRow* row); - void Commit(); - -private: - BCheckBox* fValueCheck; - -}; - - -#endif diff --git a/src/apps/resourceedit/edits/EditView.cpp b/src/apps/resourceedit/edits/EditView.cpp deleted file mode 100644 index dc9861aeb4..0000000000 --- a/src/apps/resourceedit/edits/EditView.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "EditView.h" - - -EditView::EditView(const char* name) - : - BView(BRect(0, 0, 0, 0), name, 0, 0) -{ - // Implemented by subclasses. -} - - -EditView::~EditView() -{ - // Implemented by subclasses. -} - - -void -EditView::AttachTo(BView* view) -{ - while (true) { - BView* child = ChildAt(0); - - if (child == NULL) - break; - - child->RemoveSelf(); - } - - // Implemented by subclasses. -} - - -void -EditView::Edit(ResourceRow* row) -{ - fRow = row; - // Implemented by subclasses. -} - - -void -EditView::Commit() -{ - // Implemented by subclasses. -} diff --git a/src/apps/resourceedit/edits/EditView.h b/src/apps/resourceedit/edits/EditView.h deleted file mode 100644 index 23aca74036..0000000000 --- a/src/apps/resourceedit/edits/EditView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef EDIT_VIEW_H -#define EDIT_VIEW_H - - -#include - - -class ResourceRow; - - -class EditView : public BView { -public: - EditView(const char* name); - virtual ~EditView(); - - virtual void AttachTo(BView* view); - virtual void Edit(ResourceRow* row); - virtual void Commit(); - -protected: - ResourceRow* fRow; - -}; - - -#endif - diff --git a/src/apps/resourceedit/edits/NormalEdit.cpp b/src/apps/resourceedit/edits/NormalEdit.cpp deleted file mode 100644 index fa822515bf..0000000000 --- a/src/apps/resourceedit/edits/NormalEdit.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "NormalEdit.h" -#include "ResourceRow.h" - -#include -#include -#include - - -NormalEdit::NormalEdit() - : - EditView("NormalEdit") -{ - -} - - -NormalEdit::~NormalEdit() -{ - -} - - -void -NormalEdit::AttachTo(BView* view) -{ - EditView::AttachTo(view); - - SetLayout(new BGroupLayout(B_VERTICAL)); - - fValueText = new BTextControl(BRect(0, 0, 0, 0), "fValueText", - "Value:", "", NULL); - fValueText->SetDivider(50); - - AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) - .Add(fValueText) - .AddGlue() - ); - - view->AddChild(this); -} - - -void -NormalEdit::Edit(ResourceRow* row) -{ - EditView::Edit(row); - - fValueText->SetText(fRow->ResourceData()); -} - - -void -NormalEdit::Commit() -{ - EditView::Commit(); - - fRow->SetResourceData(fValueText->Text()); -} diff --git a/src/apps/resourceedit/edits/NormalEdit.h b/src/apps/resourceedit/edits/NormalEdit.h deleted file mode 100644 index ea5fe78e09..0000000000 --- a/src/apps/resourceedit/edits/NormalEdit.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef NORMAL_EDIT_H -#define NORMAL_EDIT_H - - -#include "EditView.h" - - -class BTextControl; - -// TODO: Templatize this class and rename to NumericEdit. -//template -class NormalEdit : public EditView { -public: - NormalEdit(); - ~NormalEdit(); - - void AttachTo(BView* view); - void Edit(ResourceRow* row); - void Commit(); - -private: - BTextControl* fValueText; - -}; - - -#endif diff --git a/src/apps/resourceedit/interface/ImageButton.cpp b/src/apps/resourceedit/interface/ImageButton.cpp deleted file mode 100644 index 7b0b8dd995..0000000000 --- a/src/apps/resourceedit/interface/ImageButton.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "ImageButton.h" - -#include - - -ImageButton::ImageButton(BRect frame, const char* name, BBitmap* image, - BMessage* message, uint32 resizingMode = B_FOLLOW_NONE) - : - BButton(frame, name, "", message, resizingMode) -{ - fImage = image; - - fDrawPoint.x = ((frame.RightTop().x - frame.LeftTop().x) - - (image->Bounds().RightBottom().x + 1)) / 2; - - fDrawPoint.y = ((frame.LeftBottom().y - frame.LeftTop().y) - - (image->Bounds().RightBottom().y + 1)) / 2; - - fInnerBounds = Bounds(); - fInnerBounds.InsetBy(3, 3); - - SetDrawingMode(B_OP_ALPHA); -} - - -ImageButton::~ImageButton() -{ - -} - - -void -ImageButton::Draw(BRect updateRect) -{ - BButton::Draw(updateRect); - DrawBitmap(fImage, fDrawPoint); - - if (!IsEnabled()) { - rgb_color tempColor = HighColor(); - SetHighColor(255, 255, 255, 155); - FillRect(fInnerBounds, B_SOLID_HIGH); - SetHighColor(tempColor); - } -} - - -void -ImageButton::ResizeTo(float width, float height) -{ - BButton::ResizeTo(width, height); - fInnerBounds = Bounds(); - fInnerBounds.InsetBy(3, 3); -} - - -void -ImageButton::SetBitmap(BBitmap* image) -{ - fImage = image; - Invalidate(); -} diff --git a/src/apps/resourceedit/interface/ImageButton.h b/src/apps/resourceedit/interface/ImageButton.h deleted file mode 100644 index e0c3de8c89..0000000000 --- a/src/apps/resourceedit/interface/ImageButton.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef IMAGE_BUTTON_H -#define IMAGE_BUTTON_H - - -#include - - -class ImageButton : public BButton -{ -public: - ImageButton(BRect frame, const char* name, BBitmap* image, - BMessage* message, uint32 resizingMode); - ~ImageButton(); - - void Draw(BRect updateRect); - void ResizeTo(float width, float height); - - void SetBitmap(BBitmap* image); - -private: - BBitmap* fImage; - BPoint fDrawPoint; - BRect fInnerBounds; - -}; - - -#endif diff --git a/src/apps/resourceedit/main.cpp b/src/apps/resourceedit/main.cpp deleted file mode 100644 index b370361660..0000000000 --- a/src/apps/resourceedit/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "ResourceEdit.h" - - -int -main() -{ - ResourceEdit* app = new ResourceEdit(); - app->Run(); - delete app; - return 0; -} diff --git a/src/apps/resourceedit/settings/GenericSettingsView.cpp b/src/apps/resourceedit/settings/GenericSettingsView.cpp deleted file mode 100644 index 65d3377b6c..0000000000 --- a/src/apps/resourceedit/settings/GenericSettingsView.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "GenericSettingsView.h" - -#include "SettingsFile.h" - -#include -#include -#include -#include - -#include - - -GenericSettingsView::GenericSettingsView(BRect frame, const char* name, - SettingsFile* settings, uint32 resizingMode, uint32 flags) - : - BView(frame, name, resizingMode, flags) -{ - fSettings = settings; - - SetLayout(new BGroupLayout(B_VERTICAL)); - - fUndoLimitText = new BTextControl(BRect(0, 0, 0, 0), "fUndoLimitText", - "Undo Limit:", NULL, NULL); - fUndoLimitText->SetDivider(100); - - // TODO: Add more controls for generic settings (2/4). - - AddChild(BGroupLayoutBuilder(B_VERTICAL, 8) - .Add(fUndoLimitText) - .AddGlue() - ); -} - - -GenericSettingsView::~GenericSettingsView() -{ - -} - - -void -GenericSettingsView::ApplySettings() -{ - fSettings->UndoLimit = atoi(fUndoLimitText->Text()); - // TODO: Add more controls for generic settings (3/4). -} - - -void -GenericSettingsView::AdaptSettings() -{ - fUndoLimitText->SetText(BString() << fSettings->UndoLimit); - // TODO: Add more controls for generic settings (4/4). -} diff --git a/src/apps/resourceedit/settings/GenericSettingsView.h b/src/apps/resourceedit/settings/GenericSettingsView.h deleted file mode 100644 index 47d141127a..0000000000 --- a/src/apps/resourceedit/settings/GenericSettingsView.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef GENERIC_SETTINGS_VIEW_H -#define GENERIC_SETTINGS_VIEW_H - - -#include - - -class SettingsFile; - -class BTextControl; - - -class GenericSettingsView : public BView { -public: - GenericSettingsView(BRect frame, const char* name, - SettingsFile* settings, - uint32 resizingMode = B_FOLLOW_ALL, - uint32 flags = 0); - ~GenericSettingsView(); - - void ApplySettings(); - void AdaptSettings(); - -private: - SettingsFile* fSettings; - - BTextControl* fUndoLimitText; - // TODO: Add more controls for generic settings (1/4). - -}; - - -#endif diff --git a/src/apps/resourceedit/support/UndoContext.cpp b/src/apps/resourceedit/support/UndoContext.cpp deleted file mode 100644 index c4f6775b2d..0000000000 --- a/src/apps/resourceedit/support/UndoContext.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ - - -#include "UndoContext.h" - -#include "Constants.h" - -#include -#include - - -UndoContext::Action::Action(const BString& label) -{ - fLabel = label; -} - - -UndoContext::Action::~Action() -{ - -} - - -void -UndoContext::Action::Do() -{ - -} - - -void -UndoContext::Action::Undo() -{ - -} - - -void -UndoContext::Action::SetLabel(const BString& label) -{ - fLabel = label; -} - - -BString -UndoContext::Action::Label() const -{ - return fLabel; -} - - -UndoContext::UndoContext() -{ - fAt = 0; - fLimit = 3; - fHistory = new BList(); -} - - -UndoContext::~UndoContext() -{ - for (int32 i = 0; i < fHistory->CountItems(); i++) - delete (Action*)fHistory->ItemAt(i); - - delete fHistory; -} - - -void -UndoContext::SetLimit(int32 limit) -{ - int32 delta = fLimit - limit; - - if (limit > 1) - fLimit = limit; - else - limit = 1; - - if (delta > 0) { - for (int32 i = 0; i < delta; i++) - delete (Action*)fHistory->ItemAt(i); - - fHistory->RemoveItems(0, delta); - - if (fAt > fLimit) - fAt = fLimit; - } -} - - -int32 -UndoContext::Limit() const -{ - return fLimit; -} - - -void -UndoContext::Do(UndoContext::Action* action) -{ - int32 count = fHistory->CountItems(); - - if (fAt >= fLimit) - delete (Action*)fHistory->RemoveItem((int32)0); - else { - for (int32 i = fAt; i < count; i++) - delete (Action*)fHistory->ItemAt(i); - - fHistory->RemoveItems(fAt, count - fAt); - - fAt++; - } - - fHistory->AddItem(action); - - action->Do(); -} - - -void -UndoContext::Undo() -{ - if (!CanUndo()) - return; - - fAt--; - ((Action*)fHistory->ItemAt(fAt))->Undo(); -} - - -void -UndoContext::Redo() -{ - if (!CanRedo()) - return; - - ((Action*)fHistory->ItemAt(fAt))->Do(); - fAt++; -} - - -bool -UndoContext::CanUndo() const -{ - return fAt > 0; -} - - -bool -UndoContext::CanRedo() const -{ - return fAt < fHistory->CountItems(); -} - - -BString -UndoContext::UndoLabel() const -{ - if (CanUndo()) - return ((Action*)fHistory->ItemAt(fAt - 1))->Label(); - else - return ""; -} - -BString -UndoContext::RedoLabel() const -{ - if (CanRedo()) - return ((Action*)fHistory->ItemAt(fAt))->Label(); - else - return ""; -} diff --git a/src/apps/resourceedit/support/UndoContext.h b/src/apps/resourceedit/support/UndoContext.h deleted file mode 100644 index 0146e1be48..0000000000 --- a/src/apps/resourceedit/support/UndoContext.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2013 Tri-Edge AI - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef UNDO_CONTEXT_H -#define UNDO_CONTEXT_H - - -#include -#include - - -class UndoContext { -public: - class Action { - public: - Action(const BString& label); - virtual ~Action(); - - virtual void Do(); - virtual void Undo(); - - void SetLabel(const BString& label); - BString Label() const; - - private: - BString fLabel; - }; - - UndoContext(); - ~UndoContext(); - - void SetLimit(int32 limit); - int32 Limit() const; - - void Do(Action* action); - - void Undo(); - void Redo(); - - bool CanUndo() const; - bool CanRedo() const; - - BString UndoLabel() const; - BString RedoLabel() const; - -private: - int32 fAt; - int32 fLimit; - BList* fHistory; - -}; - - -#endif