Skip to content

Commit

Permalink
removed SendNotification methods and some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed committed Oct 27, 2023
1 parent 472c6b8 commit bc956f0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 79 deletions.
32 changes: 16 additions & 16 deletions src/exceptions/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class BException {
public:
BException(BString const& msg, status_t type,
BException(BString const& msg, status_t type,
status_t error)
:
_message(msg),
Expand All @@ -22,91 +22,91 @@
BString Message() noexcept { return _message; }
status_t Type() noexcept { return _type; }
status_t Error() noexcept { return _error; }

private:
BString _message;
status_t _type;
status_t _type;
status_t _error;
};


class BGeneralException : BException {
public:
BGeneralException(BString const& msg, status_t error)
: BException(msg, B_GENERAL_ERROR_BASE, error)
{}
};

class BOSException : BException {
public:
BOSException(BString const& msg, status_t error)
: BException(msg, B_OS_ERROR_BASE, error)
{}
};

class BAppException : BException {
public:
BAppException(BString const& msg, status_t error)
: BException(msg, B_APP_ERROR_BASE, error)
{}
};

class BInterfaceException : BException {
public:
BInterfaceException(BString const& msg, status_t error)
: BException(msg, B_INTERFACE_ERROR_BASE, error)
{}
};

class BMediaException : BException {
public:
BMediaException(BString const& msg, status_t error)
: BException(msg, B_MEDIA_ERROR_BASE, error)
{}
};

class BTranslationException : BException {
public:
BTranslationException(BString const& msg, status_t error)
: BException(msg, B_TRANSLATION_ERROR_BASE, error)
{}
};

class BMidiException : BException {
public:
BMidiException(BString const& msg, status_t error)
: BException(msg, B_MIDI_ERROR_BASE, error)
{}
};

class BStorageException : BException {
public:
BStorageException(BString const& msg, status_t error)
: BException(msg, B_STORAGE_ERROR_BASE, error)
{}
};

class BPosixException : BException {
public:
BPosixException(BString const& msg, status_t error)
: BException(msg, B_POSIX_ERROR_BASE, error)
{}
};

class BMailException : BException {
public:
BMailException(BString const& msg, status_t error)
: BException(msg, B_MAIL_ERROR_BASE, error)
{}
};

class BPrintException : BException {
public:
BPrintException(BString const& msg, status_t error)
: BException(msg, B_PRINT_ERROR_BASE, error)
{}
};

class BDeviceException : BException {
public:
BDeviceException(BString const& msg, status_t error)
Expand Down
14 changes: 5 additions & 9 deletions src/helpers/GSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
/*
* Copyright 2022 Nexus6 (nexus6.haiku@icloud.com)
* All rights reserved. Distributed under the terms of the MIT license.
*
* Parts are taken from
*
* Parts are taken from
* TPreferences by Eric Shepard from Be Newsletter Issue 3-35, September 2, 1998
* All rights reserved. Distributed under the terms of the Be Sample Code
* license.
*/
#include "GSettings.h"

#include <memory>
#include <typeinfo>

#include <Directory.h>
#include <Message.h>
#include <Messenger.h>
#include <NodeInfo.h>
#include <String.h>

#include "exceptions/Exceptions.h"

GSettings::GSettings(const BString& folderPath, const BString& fileName, uint32 command)
:
:
BMessage(command)
{
BFile file;

fPath.SetTo(folderPath);
fPath.Append(fileName);
fPath.Append(fileName);
fStatus = file.SetTo(fPath.Path(), B_READ_ONLY);
if (fStatus == B_OK) {
fStatus = Unflatten(&file);
Expand Down
2 changes: 1 addition & 1 deletion src/project/ProjectFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ProjectFolder::~ProjectFolder()
{
if (fLSPProjectWrapper != nullptr) {
fLSPProjectWrapper->Dispose();
delete fLSPProjectWrapper; //TODO: BLooper autodeletes itself?
delete fLSPProjectWrapper;
}
delete fSettings;
}
Expand Down
69 changes: 22 additions & 47 deletions src/ui/GenioWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

#include <DirMenu.h>


#include "exceptions/Exceptions.h"
#include "ConfigManager.h"
#include "ConfigWindow.h"
#include "FSUtils.h"
Expand Down Expand Up @@ -282,14 +280,6 @@ GenioWindow::MessageReceived(BMessage* message)
}
break;
}
case 'NOTI': {
BString notification, type;
if (message->FindString("notification", &notification) == B_OK
&& message->FindString("type", &type) == B_OK) {
_SendNotification(notification, type);
}
break;
}
case B_ABOUT_REQUESTED:
be_app->PostMessage(B_ABOUT_REQUESTED);
break;
Expand Down Expand Up @@ -358,18 +348,18 @@ GenioWindow::MessageReceived(BMessage* message)
if (message->FindInt32("line", &line) == B_OK) {
BString text;
text << editor->Name() << " :" << line;
_SendNotification(text, "FIND_MARK");
LogInfo(text.String());
}
}
}
break;
}
case EDITOR_FIND_NEXT_MISS: {
_SendNotification("Find next not found", "FIND_MISS");
LogInfo("Find next not found");
break;
}
case EDITOR_FIND_PREV_MISS: {
_SendNotification("Find previous not found", "FIND_MISS");
LogInfo("Find previous not found");
break;
}
case EDITOR_FIND_COUNT: {
Expand All @@ -381,9 +371,7 @@ GenioWindow::MessageReceived(BMessage* message)
BString notification;
notification << "\"" << text << "\""
<< " occurrences found: " << count;

_ShowLog(kNotificationLog);
_SendNotification(notification, "FIND_COUNT");
LogInfo(notification.String());
}
break;
}
Expand All @@ -393,9 +381,7 @@ GenioWindow::MessageReceived(BMessage* message)
if (message->FindInt32("count", &count) == B_OK) {
BString notification;
notification << "Replacements done: " << count;

_ShowLog(kNotificationLog);
_SendNotification(notification, "REPL_COUNT");
LogInfo(notification.String());
}
break;
}
Expand All @@ -415,8 +401,7 @@ GenioWindow::MessageReceived(BMessage* message)
notification << editor->Name() << " " << line << ":" << column
<< " \"" << sel << "\" => \""<< repl<< "\"";

_ShowLog(kNotificationLog);
_SendNotification(notification, "REPL_DONE");
LogInfo(notification.String());
}
}
}
Expand Down Expand Up @@ -460,15 +445,15 @@ GenioWindow::MessageReceived(BMessage* message)
Editor* editor = fTabManager->SelectedEditor();
if (editor) {
if (!editor->BookmarkGoToNext())
_SendNotification("Next Bookmark not found", "FIND_MISS");
LogInfo("Next Bookmark not found");
}
break;
}
case MSG_BOOKMARK_GOTO_PREVIOUS: {
Editor* editor = fTabManager->SelectedEditor();
if (editor) {
if (!editor->BookmarkGoToPrevious())
_SendNotification("Previous Bookmark not found", "FIND_MISS");
LogInfo("Previous Bookmark not found");
}


Expand Down Expand Up @@ -1540,7 +1525,7 @@ GenioWindow::_FileOpen(BMessage* msg)
Editor* editor = fTabManager->EditorAt(index);
if (editor == nullptr) {
notification << ref.name << ": NULL editor pointer";
_SendNotification(notification, "FILE_ERR");
LogInfo(notification.String());
return B_ERROR;
}

Expand Down Expand Up @@ -1575,7 +1560,7 @@ GenioWindow::_FileOpen(BMessage* msg)

notification << "File open: " << editor->Name()
<< " [" << fTabManager->CountTabs() - 1 << "]";
_SendNotification(notification, "FILE_OPEN");
LogInfo(notification.String());
notification.SetTo("");
}

Expand Down Expand Up @@ -1692,7 +1677,7 @@ GenioWindow::_FileSaveAll(ProjectFolder* onlyThisProject)
BString notification;
notification << "Index " << index
<< ": " << "NULL editor pointer";
_SendNotification(notification, "FILE_ERR");
LogInfo(notification.String());
continue;
}

Expand Down Expand Up @@ -1732,7 +1717,7 @@ GenioWindow::_FileSaveAs(int32 selection, BMessage* message)
BString notification;
notification
<< "Index " << selection << ": NULL editor pointer";
_SendNotification(notification, "FILE_ERR");
LogInfo(notification.String());
return B_ERROR;
}

Expand Down Expand Up @@ -1893,7 +1878,7 @@ GenioWindow::_GetEditorIndex(entry_ref* ref, bool checkExists)
BString notification;
notification
<< "Index " << index << ": NULL editor pointer";
_SendNotification(notification, "FILE_ERR");
LogInfo(notification.String());
continue;
}

Expand All @@ -1918,7 +1903,7 @@ GenioWindow::_GetEditorIndex(node_ref* nref)
BString notification;
notification
<< "Index " << index << ": NULL editor pointer";
_SendNotification(notification, "FILE_ERR");
LogInfo(notification.String());
continue;
}

Expand Down Expand Up @@ -2028,7 +2013,7 @@ GenioWindow::_HandleExternalMoveModification(entry_ref* oldRef, entry_ref* newRe
BString notification;
notification << "File info: " << oldPath.Path()
<< " moved externally to " << newPath.Path();
_SendNotification(notification, "FILE_INFO");
LogInfo(notification.String());
}
}

Expand Down Expand Up @@ -2069,7 +2054,7 @@ GenioWindow::_HandleExternalRemoveModification(int32 index)

BString notification;
notification << "File info: " << fileName << " removed externally";
_SendNotification(notification, "FILE_INFO");
LogInfo(notification.String());
}
}

Expand Down Expand Up @@ -3246,8 +3231,7 @@ GenioWindow::_ProjectFolderClose(ProjectFolder *project)

BString notification;
notification << closed << " " << name;
_SendNotification(notification, "PROJ_CLOSE");

LogInfo(notification.String());
}

void
Expand Down Expand Up @@ -3283,7 +3267,7 @@ GenioWindow::_ProjectFolderOpen(const BString& folder, bool activate)
if (newProject->Open() != B_OK) {
BString notification;
notification << "Project open fail: " << newProject->Name();
_SendNotification( notification.String(), "PROJ_OPEN_FAIL");
LogInfo(notification.String());
delete newProject;

return;
Expand All @@ -3302,7 +3286,7 @@ GenioWindow::_ProjectFolderOpen(const BString& folder, bool activate)

BString notification;
notification << opened << newProject->Name() << " at " << newProject->Path();
_SendNotification(notification, "PROJ_OPEN");
LogInfo(notification.String());

//let's check if any open editor is related to this project
BString projectPath = newProject->Path();
Expand Down Expand Up @@ -3346,7 +3330,7 @@ GenioWindow::_OpenTerminalWorkingDirectory()
"Terminal successfully opened with working directory: ";
}
notification << itemPath;
_SendNotification(notification, "PROJ_TERM");
LogInfo(notification.String());
return returnStatus == 0 ? B_OK : errno;
}

Expand All @@ -3373,11 +3357,11 @@ GenioWindow::_ShowCurrentItemInTracker()
returnStatus = system(commandLine);
} else {
notification << "An error occurred when showing an item in Tracker: " << directoryPath.Path();
_SendNotification(notification, "PROJ_SHOW");
LogInfo(notification.String());
}
} else {
notification << "An error occurred while retrieving parent directory of " << itemPath;
_SendNotification(notification, "PROJ_TRACK");
LogInfo(notification.String());
}
return returnStatus == 0 ? B_OK : errno;
}
Expand Down Expand Up @@ -3573,15 +3557,6 @@ GenioWindow::_RunTarget()
}
}

void
GenioWindow::_SendNotification(BString message, BString type)
{
if (!gCFG["enable_notifications"])
return;

LogInfo("Notification: %s - %s", type.String(), message.String());
}

void
GenioWindow::_SetMakefileBuildMode()
{
Expand Down
Loading

0 comments on commit bc956f0

Please sign in to comment.