Skip to content

Commit

Permalink
Change std::string uses to wxString for better consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kosude committed Apr 21, 2024
1 parent 8ba556f commit ac15f6b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion texedit/gui/main_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace te {
}
}

void MainFrame::ShowURL(const std::string &url) {
void MainFrame::ShowURL(const wxString &url) {
if (!wxLaunchDefaultBrowser(url)) {
util::log::Error("Failed to open URL \"" + url + "\"");
}
Expand Down
2 changes: 1 addition & 1 deletion texedit/gui/main_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace te {

void OnIdle(wxIdleEvent &ev);

void ShowURL(const std::string &url);
void ShowURL(const wxString &url);

void OnMenuAbout(wxCommandEvent &event);
void OnMenuQuit(wxCommandEvent &event);
Expand Down
4 changes: 2 additions & 2 deletions texedit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace te {
what = "Unknown runtime error";
}

util::log::Fatal(what.ToStdString());
util::log::Fatal(what);

if (wxMessageBox("An unexpected exception has occurred:\n"
"\"" + what + "\"\n\n"
Expand All @@ -47,7 +47,7 @@ namespace te {
what = "Unknown runtime error";
}

util::log::Fatal("(unhandled) " + what.ToStdString());
util::log::Fatal("(unhandled) " + what);

wxMessageBox("An unexpected exception has occurred:\n"
"\"" + what + "\"\n\n"
Expand Down
2 changes: 1 addition & 1 deletion texedit/process/compiler/tecomp_proc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace te {
TECompProcess::TECompProcess(ProcessManager &mgr) : _mgr{mgr}, _id{1} {
_cmd = util::res::RelToExec("tecomp");
if (!util::res::ValidateExecutable(_cmd.ToStdString())) {
if (!util::res::ValidateExecutable(_cmd)) {
throw util::except::MissingComponentException("tecomp");
}
}
Expand Down
8 changes: 4 additions & 4 deletions texedit/process/process_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace te {
wxString cmdstr;
for (int i = 0; argv[i] != 0; i++)
cmdstr << argv[i] << " ";
util::log::Info("Executing command: " + cmdstr.ToStdString());
util::log::Info("Executing command: " + cmdstr);

wxExecute(argv, wxEXEC_ASYNC, proc);

Expand All @@ -43,7 +43,7 @@ namespace te {
wxString cmdstr;
for (int i = 0; argv[i] != 0; i++)
cmdstr << argv[i] << " ";
util::log::Info("Executing command: " + cmdstr.ToStdString());
util::log::Info("Executing command: " + cmdstr);

wxExecute(argv, wxEXEC_ASYNC, piproc);

Expand Down Expand Up @@ -72,13 +72,13 @@ namespace te {
}

void ProcessManager::HandleProcessTerminated(Process *p, int pid, int status) {
util::log::Info("Process " + std::to_string(pid) + " (" + p->GetCmd().ToStdString() + ") terminated with code " + std::to_string(status));
util::log::Info("Process " + std::to_string(pid) + " (" + p->GetCmd() + ") terminated with code " + std::to_string(status));

RemoveProcess(p);
}

void ProcessManager::HandlePipedProcessTerminated(PipedProcess *p, int pid, int status) {
util::log::Info("Process " + std::to_string(pid) + " (" + p->GetCmd().ToStdString() + ") terminated with code " + std::to_string(status));
util::log::Info("Process " + std::to_string(pid) + " (" + p->GetCmd() + ") terminated with code " + std::to_string(status));

RemovePipedProcess(p);
}
Expand Down
2 changes: 1 addition & 1 deletion texedit/util/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace te::util::except {
class MissingComponentException : public std::runtime_error {
public:
inline MissingComponentException(const std::string &name)
inline MissingComponentException(const wxString &name)
: std::runtime_error{"Missing " + name} {}
};
}
Expand Down
16 changes: 8 additions & 8 deletions texedit/util/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <ctime>
#include <wx/wx.h>

static std::string GetCurrentDateTime(
static wxString GetCurrentDateTime(
const bool with_time
);

Expand All @@ -22,23 +22,23 @@ namespace te::util::log {
ciocolstatedef(stderr);
}

void Log(const std::string &msg) {
void Log(const wxString &msg) {
# if !defined(NDEBUG)
std::cerr << "[" << GetCurrentDateTime(true) << "] DEBUG: " << msg << std::endl;
# endif
}

void Info(const std::string &msg) {
void Info(const wxString &msg) {
std::cerr << "[" << GetCurrentDateTime(true) << "] " << msg << std::endl;
}

void Warn(const std::string &msg) {
void Warn(const wxString &msg) {
ciocolstateset(CIOCOL_YELLOW, 0xff, stderr);
std::cerr << "[" << GetCurrentDateTime(true) << "] WARN: " << msg << std::endl;
ResetLogColour();
}

void Error(const std::string &msg, bool show) {
void Error(const wxString &msg, bool show) {
ciocolstateset(CIOCOL_RED, 0xff, stderr);
std::cerr << "[" << GetCurrentDateTime(true) << "] ERROR: " << msg << std::endl;
ResetLogColour();
Expand All @@ -48,14 +48,14 @@ namespace te::util::log {
}
}

void Fatal(const std::string &msg) {
void Fatal(const wxString &msg) {
ciocolstateset(CIOCOL_RED, 0xff, stderr);
std::cerr << "[" << GetCurrentDateTime(true) << "] FATAL: " << msg << std::endl;
ResetLogColour();
}
}

std::string GetCurrentDateTime(const bool with_time) {
wxString GetCurrentDateTime(const bool with_time) {
std::time_t t = std::time(nullptr);
std::tm *tm = std::localtime(&t);

Expand All @@ -68,7 +68,7 @@ std::string GetCurrentDateTime(const bool with_time) {
std::strftime(buf, 64, "%Y-%m-%d", tm);
}

return std::string { buf };
return wxString{buf};
}

throw std::runtime_error("Date/time get failed");
Expand Down
12 changes: 6 additions & 6 deletions texedit/util/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#ifndef __texedit__log_hpp__
#define __texedit__log_hpp__

#include <string>
#include <wx/string.h>

namespace te::util::log {
void ResetLogColour();

void Log(const std::string &msg);
void Info(const std::string &msg);
void Warn(const std::string &msg);
void Error(const std::string &msg, bool show = true);
void Fatal(const std::string &msg);
void Log(const wxString &msg);
void Info(const wxString &msg);
void Warn(const wxString &msg);
void Error(const wxString &msg, bool show = true);
void Fatal(const wxString &msg);
}

#endif
12 changes: 6 additions & 6 deletions texedit/util/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
#include "util/log.hpp"

namespace te::util::res {
std::string GetTexeditDir() {
wxString GetTexeditDir() {
wxFileName f = wxStandardPaths::Get().GetExecutablePath();
return f.GetPath().ToStdString();
return f.GetPath();
}

std::string RelToExec(std::vector<std::string> dirs, std::string filename) {
wxString RelToExec(std::vector<wxString> dirs, wxString filename) {
wxFileName f = wxFileName::DirName(GetTexeditDir());
for (auto d : dirs) {
f.AppendDir(d);
}

return f.GetPath().ToStdString() + wxString{wxFileName::GetPathSeparator()}.ToStdString() + filename;
return f.GetPath() + wxString{wxFileName::GetPathSeparator()} + filename;
}

std::string RelToExec(std::string filename) {
wxString RelToExec(wxString filename) {
return RelToExec({}, filename);
}

bool ValidateExecutable(std::string path) {
bool ValidateExecutable(wxString path) {
wxFileName f{path};
return f.FileExists() && f.IsFileExecutable();
}
Expand Down
10 changes: 5 additions & 5 deletions texedit/util/resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
#ifndef __texedit__resources_hpp__
#define __texedit__resources_hpp__

#include <string>
#include <wx/string.h>
#include <vector>

namespace te::util::res {
std::string GetTexeditDir();
wxString GetTexeditDir();

std::string RelToExec(std::vector<std::string> dirs, std::string filename);
std::string RelToExec(std::string filename);
wxString RelToExec(std::vector<wxString> dirs, wxString filename);
wxString RelToExec(wxString filename);

bool ValidateExecutable(std::string path);
bool ValidateExecutable(wxString path);
}

#endif

0 comments on commit ac15f6b

Please sign in to comment.