From 1adde169ec8c4790ecc8bbc05a804bd73255a984 Mon Sep 17 00:00:00 2001 From: Tim Warren Date: Mon, 13 Apr 2015 16:48:41 -0400 Subject: [PATCH] Some framework for configuration storage in JSON --- Makefile | 4 +- config/scintilla.json | 8 + include/UTF8Strings/Exception.cpp | 50 -- include/UTF8Strings/Exception.h | 64 --- include/UTF8Strings/String.cpp | 899 ------------------------------ include/UTF8Strings/String.h | 325 ----------- nbproject/configurations.xml | 8 + src/definitions.h | 4 +- src/network/SFTP.h | 2 +- src/settings/Settings.cpp | 15 + src/settings/Settings.h | 23 + src/widgets/EditPane.cpp | 40 +- src/widgets/EditPane.h | 4 +- src/widgets/MainFrame.cpp | 69 ++- src/widgets/MainFrame.h | 2 + 15 files changed, 134 insertions(+), 1383 deletions(-) delete mode 100644 include/UTF8Strings/Exception.cpp delete mode 100644 include/UTF8Strings/Exception.h delete mode 100644 include/UTF8Strings/String.cpp delete mode 100644 include/UTF8Strings/String.h create mode 100644 src/settings/Settings.cpp create mode 100644 src/settings/Settings.h diff --git a/Makefile b/Makefile index 7eff014..49201ba 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXX = $(shell wx-config --cxx) -SOURCES = $(wildcard src/network/*.cpp include/**/*.cpp include/*.cpp) +SOURCES = $(wildcard include/**/*.cpp include/*.cpp) OBJECTS = $(patsubst %.cpp,%.o, $(SOURCES)) TARGET = build/Tyro.a @@ -10,7 +10,7 @@ PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC)) BASE_FLAGS = -DSCI_LEXER -std=c++11 -LDLIBS = $(TARGET) $(shell wx-config --libs base core aui stc adv) -lssh2 +LDLIBS = $(TARGET) $(shell wx-config --libs base core aui stc adv) WX_CXXFLAGS = $(shell wx-config --cxxflags) $(BASE_FLAGS) DEV_CXXFLAGS = -g -Wall -Wextra CXXFLAGS = -Os diff --git a/config/scintilla.json b/config/scintilla.json index dee2d0c..8c73859 100644 --- a/config/scintilla.json +++ b/config/scintilla.json @@ -1,5 +1,13 @@ { "default_style": { + }, + "languages": { + "c": { + + }, + "cpp": { + + } } } diff --git a/include/UTF8Strings/Exception.cpp b/include/UTF8Strings/Exception.cpp deleted file mode 100644 index 90dad36..0000000 --- a/include/UTF8Strings/Exception.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/** - * UTF8 string library. - * - * Allows to use native UTF8 sequences as a string class. Has many overloaded - * operators that provides such features as concatenation, types converting and - * much more. - * - * Distributed under GPL v3 - * - * Author: - * Grigory Gorelov (gorelov@grigory.info) - * See more information on grigory.info - */ - -#include "Exception.h" - - -const int UTF8::Exception::UnspecifiedException; -const int UTF8::Exception::StringToIntConversionError; -const int UTF8::Exception::StringToDoubleConversionError; -const int UTF8::Exception::FileNotFound; -const int UTF8::Exception::StringIsNotACharacter; - -UTF8::Exception::Exception(const std::string &error, const int &StatusCode) { - this->error = error; - this->StatusCode = StatusCode; -} - -UTF8::Exception::Exception(std::string error) { - this->error = error; - this->StatusCode = UnspecifiedException; -} - -UTF8::Exception::Exception(const UTF8::Exception &e) { - error = e.error; - StatusCode = e.StatusCode; -} - -std::string UTF8::Exception::GetErrorString() const { - return error; -} - -int UTF8::Exception::GetErrorCode() const { - return StatusCode; -} - -UTF8::Exception & UTF8::Exception::operator =(const UTF8::Exception & e) { - error = e.error; - error = e.StatusCode; -} \ No newline at end of file diff --git a/include/UTF8Strings/Exception.h b/include/UTF8Strings/Exception.h deleted file mode 100644 index a22fb74..0000000 --- a/include/UTF8Strings/Exception.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * UTF8 string library. - * - * Allows to use native UTF8 sequences as a string class. Has many overloaded - * operators that provides such features as concatenation, types converting and - * much more. - * - * Distributed under GPL v3 - * - * Author: - * Grigory Gorelov (gorelov@grigory.info) - * See more information on grigory.info - */ - -#ifndef _UTF8_Exception_H -#define _UTF8_Exception_H - -#include - -namespace UTF8 { - - /** - * Exception class. When something bad happens it is thowed by UTF8::String. - */ - class Exception { - public: - static const int UnspecifiedException = 1; - static const int StringToIntConversionError = 2; - static const int StringToDoubleConversionError = 3; - static const int FileNotFound = 4; - static const int StringIsNotACharacter = 5; - - /** - * Just a constructor - */ - Exception(std::string error); - - /// Just a constructor - Exception(const std::string &error, const int &StatusCode); - - /// Copying constructor - Exception(const Exception &e); - - /// Returns error string - std::string GetErrorString() const; - - /// Returns error code - int GetErrorCode() const; - - /// Assing operator - Exception & operator =(const Exception &); - - private: - std::string error; - int StatusCode; - - }; - -} - - - -#endif /* _EXCEPTION_H */ - diff --git a/include/UTF8Strings/String.cpp b/include/UTF8Strings/String.cpp deleted file mode 100644 index c3bfb46..0000000 --- a/include/UTF8Strings/String.cpp +++ /dev/null @@ -1,899 +0,0 @@ -/** - * UTF8 string library. - * - * Allows to use native UTF8 sequences as a string class. Has many overloaded - * operators that provides such features as concatenation, types converting and - * much more. - * - * Distributed under GPL v3 - * - * Author: - * Grigory Gorelov (gorelov@grigory.info) - * See more information on grigory.info - */ - -#include "String.h" -#include -#include -#include -#include -#include -#include -#include -#include "Exception.h" - -void UTF8::String::ConvertFromDouble(const long double d, const UTF8::String &ThousandSeparator, const UTF8::String &FractionSeparator, const int IntegerPartLength, const int FractionPartLength) { - - std::ostringstream os; - os.precision(15); - os << d; - - - UTF8::String Number(os.str()); - UTF8::String Integer, Fraction; - - // Extracting integer and fraction - std::vector Extracted = Number.Explode("."); - - unsigned int IntegerLength; - if (IntegerPartLength) { - IntegerLength = IntegerPartLength; - } else { - IntegerLength = Extracted[0].Length(); - } - - unsigned int FractionLength; - if (FractionPartLength) { - FractionLength = FractionPartLength; - } else { - if (Extracted.size() > 1) { - FractionLength = Extracted[1].Length(); - } else { - FractionLength = 0; - } - } - - // Parsing integer - for (unsigned int i = 0; i < IntegerLength; i++) { - if ((i > 0) && (i % 3 == 0)) { - Integer = ThousandSeparator + Integer; - } - - if (Extracted[0].Length() < i + 1) { - Integer = "0" + Integer; - } else { - Integer = Extracted[0][Extracted[0].Length() - 1 - i] + Integer; - } - } - - - // Parsing fraction - if (FractionLength) { - Fraction = FractionSeparator; - for (unsigned int i = 0; i < FractionLength; i++) { - if ((Extracted.size() > 1) && (Extracted[1].Length() > i)) { - Fraction += Extracted[1][i]; - } else { - Fraction += "0"; - } - } - } - - - - * this = Integer + Fraction; - - -} - -bool UTF8::String::HasThisString(const UTF8::String &Str) const { - - return GetSubstringPosition(Str) != -1; -} - -bool UTF8::String::CharacterIsOneOfThese(const UTF8::String &Characters) const { - if (Length() == 1) { - for (unsigned int i = 0; i < Characters.Length(); i++) { - if (Characters[i] == *this) { - return true; - } - } - - return false; - } else { - - throw Exception("[CharacterIsOneOfThese] String is more then one character length: \"" + ToString() + "\"", UTF8::Exception::StringIsNotACharacter); - } -} - -UTF8::String UTF8::String::FromFile(const UTF8::String &Path) { - UTF8::String s; - - std::ifstream File; - File.open(Path.ToConstCharPtr()); - - - if (File.is_open()) { - - File.seekg(0, std::ios::end); - unsigned int Length = File.tellg(); - File.seekg(0, std::ios::beg); - - char *buf = new char[Length + 1]; - memset(buf, 0, Length + 1); - - File.read(buf, Length); - s.AppendString(buf); - - delete buf; - } else { - throw Exception("Cannot open file \"" + Path.ToString() + "\"", UTF8::Exception::FileNotFound); - } - - File.close(); - - return s; -} - -long UTF8::String::Search(const UTF8::String &SubString, unsigned int StartPosition, int Direction) const { - - unsigned int SubstringLength = SubString.Length(); - unsigned int n = StartPosition; - - if (n > Length() - SubstringLength) { - if (Direction == SearchDirectionFromLeftToRight) { - return -1; - } else { - n = Length() - SubstringLength; - } - } - - if (n < 0) { - if (Direction == SearchDirectionFromRightToLeft) { - return -1; - } else { - n = 0; - } - } - - while (((Direction == SearchDirectionFromLeftToRight) && (n < Length() - SubstringLength + 1)) || ((Direction == SearchDirectionFromRightToLeft) && (n >= 0))) { - - if (this->Substring(n, SubstringLength) == SubString) { - - return n; - } - - n += Direction == SearchDirectionFromLeftToRight ? 1 : -1; - } - - return -1; - -} - -std::ostream & operator<<(std::ostream &os, const UTF8::String &s) { - os << s.ToString(); - - return os; -} - -bool operator==(const char *str, const UTF8::String &StringObj) { - - return StringObj == str; -} - -bool operator==(const std::string &str, const UTF8::String &StringObj) { - - return StringObj == str; -} - -bool operator!=(const char *str, const UTF8::String &StringObj) { - - return StringObj != str; -} - -bool operator!=(const std::string &str, const UTF8::String &StringObj) { - - return StringObj != str; -} - -UTF8::String UTF8::String::Quote() const { - return "«"+(*this)+"»"; -} - -UTF8::String UTF8::String::Trim() const { - UTF8::String result = *this; - long i = 0; - - while ((result[i] == " ") || (result[i] == "\n") || (result[i] == "\r") || (result[i] == "\t")) { - i++; - } - - if (i == result.Length()) { - return UTF8::String(); - } - - - long j = result.Length(); - while ((result[j - 1] == " ") || (result[j - 1] == "\n") || (result[j - 1] == "\r") || (result[j - 1] == "\t")) { - j--; - } - - - result = result.Substring(i, j - i); - - return result; -} - -UTF8::String UTF8::String::Replace(const UTF8::String &Search, const UTF8::String &Replace) const { - UTF8::String result = *this; - - // Long to cover unsigned int and -1 - long pos = 0; - while ((pos = result.Search(Search, pos)) != -1) { - - result = result.SubstringReplace(pos, Search.Length(), Replace); - - // Next time we search after replacement - pos += Replace.Length(); - } - - return result; - -} - -UTF8::String UTF8::String::SubstringReplace(unsigned int Start, unsigned int Count, const UTF8::String &Replace) const { - if (Start < Length()) { - return (Start ? Substring(0, Start) : UTF8::String())+Replace + Substring(Start + Count); - } else { - - return *this; - } -} - -UTF8::String UTF8::String::Implode(const std::vector &Strings, const UTF8::String &Separator) { - if (Strings.size()) { - UTF8::String Result; - - for (unsigned int i = 0; i < Strings.size(); i++) { - if (Result.Length()) { - Result += Separator; - } - - Result += Strings[i]; - } - - return Result; - } else { - - return UTF8::String(); - } -} - -std::vector UTF8::String::Explode(const String &Separator) const { - std::vector v; - - unsigned int prev = 0; - - int i = 0; - - while (i < Length() - Separator.Length() + 1) { - if (Substring(i, Separator.Length()) == Separator) { - if (i - prev > 0) { - v.push_back(Substring(prev, i - prev)); - } - i += Separator.Length(); - prev = i; - } else { - i++; - } - } - - if (prev < Length()) { - - v.push_back(Substring(prev, Length() - prev)); - } - - return v; -} - -UTF8::String operator+(const char *CharPtr, const UTF8::String &StringObj) { - UTF8::String s(CharPtr); - s += StringObj; - - return s; - -} - -UTF8::String operator+(const std::string & str, const UTF8::String &StringObj) { - UTF8::String s(str); - s += StringObj; - - return s; - -} - -UTF8::String operator+(const long l, const UTF8::String &StringObj) { - UTF8::String s(l); - s += StringObj; - - return s; -} - -UTF8::String UTF8::String::operator+(const UTF8::String &s) const { - UTF8::String res(*this); - res.AppendString(s.Data); - - return res; -} - -UTF8::String & UTF8::String::operator+=(const UTF8::String &s) { - AppendString(s.Data); - - return *this; -} - -void UTF8::String::AppendString(const char *str) { - // The functions that can fill buffer directly: - // - // SetString AppendString - // - // Make shure all preparations are done there - - if (str && strlen(str)) { - if (DataArrayLength) { - CheckIfStringIsCorrect(str); - - unsigned int StrLength = strlen(str); - - Data = (char *) realloc(Data, DataArrayLength + StrLength + 1); - - if (Data != NULL) { - - memcpy(Data + DataArrayLength, str, StrLength); - DataArrayLength += StrLength; - Data[DataArrayLength] = 0; - - CalculateStringLength(); - } else { - throw Exception("[AppendString] Cannot realloc any more memory"); - } - } else { - - SetString(str); - } - } -} - -void UTF8::String::SetString(const char *str) { - // The functions that can fill buffer directly: - // - // SetString AppendString - // - // Make shure all preparations are done there - - if (str && strlen(str)) { - CheckIfStringIsCorrect(str); - - Empty(); - - DataArrayLength = strlen(str); - Data = new char[DataArrayLength + 1]; - Data[DataArrayLength] = 0; - - memcpy(Data, str, DataArrayLength); - - CalculateStringLength(); - } else { - - Empty(); - } -} - -void UTF8::String::ConvertFromInt64(int64_t n) { - Empty(); - - if (n) { - bool minus; - if (n < 0) { - n = -n; - minus = true; - } else { - minus = false; - } - - char tmp[32] = "0"; - const char *num = "0123456789"; - memset(tmp, 0, 32); - - unsigned int i = 30; - - while (n) { - tmp[i] = num[n % 10]; - n /= 10; - i--; - - if ((i < 0) || ((i < 1) && minus)) { - throw Exception("[ConvertFromInt] Cycle terminated, buffer overflow."); - } - } - - if (minus) { - tmp[i] = '-'; - i--; - } - - SetString(tmp + i + 1); - } else { - - SetString("0"); - - } - - CalculateStringLength(); -} - -UTF8::String::String(const long double d, const UTF8::String &ThousandSeparator, const UTF8::String &DecimalSeparator, const int IntegerPartCount, const int FractionPartCount) { - - InitString(); - ConvertFromDouble(d, ThousandSeparator, DecimalSeparator, IntegerPartCount, FractionPartCount); -} - -void UTF8::String::InitString() { - - Data = NULL; - DataArrayLength = 0; - StringLength = 0; -} - -UTF8::String::String() { - - InitString(); -} - -UTF8::String::String(const std::string & s) { - - InitString(); - CheckIfStringIsCorrect(s.c_str()); - AppendString(s.c_str()); - CalculateStringLength(); -} - -int UTF8::String::GetSymbolIndexInDataArray(unsigned int Position) const { - if (Position >= StringLength) { - throw Exception((UTF8::String("[GetSymbolIndexInDataArray] trying to get position beyond the end of string. StringLength: ") + StringLength + " Position: " + Position + " String: [" + Data + "]").ToString()); - } - - unsigned int n = 0; - for (unsigned int i = 0; i < Position; i++) { - - n += GetSequenceLength(Data + n); - } - - return n; - -} - -long UTF8::String::GetSubstringPosition(const UTF8::String &SubString, unsigned int Start) const { - if (SubString.Length() > StringLength) { - return -1; - } - - unsigned int ScansCount = StringLength - SubString.StringLength + 1 - Start; - for (unsigned int i = 0; i < ScansCount; i++) { - if (this->Substring(i + Start, SubString.StringLength) == SubString) { - - return i + Start; - } - } - - return -1; -} - -UTF8::String UTF8::String::Substring(unsigned int Start, unsigned int Count) const { - if (Start >= StringLength) { - return UTF8::String(); - } - - if ((Start + Count > StringLength) || (Count == 0)) { - Count = StringLength - Start; - } - - - unsigned int StartIndex = GetSymbolIndexInDataArray(Start); - unsigned int CopyAmount = 0; - - - for (unsigned int i = 0; i < Count; i++) { - CopyAmount += GetSequenceLength(Data + StartIndex + CopyAmount); - } - - char *tmp = new char[CopyAmount + 1]; - memcpy(tmp, Data + StartIndex, CopyAmount); - tmp[CopyAmount] = 0; - - UTF8::String r(tmp); - delete tmp; - - return r; -} - -UTF8::String::String(const char * str) { - - InitString(); - SetString(str); -} - -UTF8::String::String(const uint32_t * str) { - - InitString(); - ConvertFromUTF32(str); -} - -void UTF8::String::ConvertFromUTF32(const uint32_t *s) { - if (s) { - unsigned int WideStringLength = 0; - do { - WideStringLength++; - if (WideStringLength == 4294967295UL) { - throw Exception("[ConvertFromUTF32] Cannot find termination symbol in incoming string."); - } - } while (s[WideStringLength]); - - char *tmp = new char[WideStringLength * 4 + 1]; - memset(tmp, 0, WideStringLength * 4 + 1); - unsigned int pos = 0; - - for (int i = 0; i < WideStringLength; i++) { - uint32_t wc = s[i]; - - if (wc < 0x80) { - tmp[pos++] = wc; - } else if (wc < 0x800) { - tmp[pos++] = (wc >> 6) | 0b11000000; - tmp[pos++] = (wc & 0b111111) | 0b10000000; - } else if (wc < 0x10000) { - tmp[pos++] = (wc >> 12) | 0b11100000; - tmp[pos++] = ((wc >> 6) & 0b111111) | 0b10000000; - tmp[pos++] = (wc & 0b111111) | 0b10000000; - } else { - - tmp[pos++] = (wc >> 18) | 0b11110000; - tmp[pos++] = ((wc >> 12) & 0b111111) | 0b10000000; - tmp[pos++] = ((wc >> 6) & 0b111111) | 0b10000000; - tmp[pos++] = (wc & 0b111111) | 0b10000000; - } - - } - - SetString(tmp); - - delete tmp; - } -} - -void UTF8::String::CalculateStringLength() { - // We are not writing anything to memory so limits are not needed - if (Data) { - unsigned int n = 0, count = 0; - do { - // We do not need to check line end here, it is checked when string is changed - n += GetSequenceLength(Data + n); - count++; - } while (Data[n]); - - StringLength = count; - } else { - - StringLength = 0; - } -} - -void UTF8::String::CheckIfStringIsCorrect(const char *str) const { - if (str) { - // We are not writing anything to memory so limits are not needed - unsigned int n = 0, i; - unsigned int SequenceLength; - while (str[n]) { - SequenceLength = GetSequenceLength(str + n); - for (i = 1; i < SequenceLength; i++) { - if ((((unsigned char) str[n + i]) >> 6) != 0b10) { - std::string s(str); - throw Exception("[CheckIfStringIsCorrect] Incorrect byte in UTF8 sequence: \"" + s + "\""); - } - } - n += SequenceLength; - if (n >= 0xFFFFFFFF - 4) { - - std::string s(str); - throw Exception("[CheckIfStringIsCorrect] termination char was not found in string: \"" + s + "\""); - } - } - } -} - -bool UTF8::String::operator>(const UTF8::String &s) const { - if (*this == s) { - return false; - } - - if (*this= 0; i--) { - c = Data[i]; - if ((c >= '0') && (c <= '9')) { - int_part += (c - '0') * mul; - mul *= 10; - } else { - if (c == '.') { - prec_part = (double) int_part / (double) mul; - int_part = 0; - mul = 1; - } else { - if ((c == '-') && (i == 0)) { - int_part = -int_part; - prec_part = -prec_part; - } else { - - UTF8::String err = "Cannot convert \"" + * this+"\" to double."; - throw UTF8::Exception(err.ToConstCharPtr(), UTF8::Exception::StringToDoubleConversionError); - } - } - } - } - return int_part + prec_part; -} - -int64_t UTF8::String::ToLong() const { - int64_t mul = 1; - char c; - int64_t number = 0; - - for (int i = DataArrayLength - 1; i >= 0; i--) { - c = Data[i]; - if ((c >= '0') && (c <= '9')) { - number += (c - '0') * mul; - mul *= 10; - } else { - if (c == '.') { - number = 0; - mul = 1; - } else { - if ((c == '-') && (i == 0)) { - number = -number; - } else { - - UTF8::String err = "Cannot convert \"" + * this+"\" to number."; - throw UTF8::Exception(err.ToConstCharPtr(), UTF8::Exception::StringToIntConversionError); - } - } - } - } - - return number; - -} - -UTF8::String UTF8::String::operator+(const char *s) const { - UTF8::String res(*this); - res.AppendString(s); - - return res; -} - -bool UTF8::String::operator==(const UTF8::String &s) const { - if (DataArrayLength != s.DataArrayLength) { - return false; - } else { - for (int i = 0; i < DataArrayLength; i++) { - if (Data[i] != s.Data[i]) { - - return false; - } - } - - return true; - } -} - -bool UTF8::String::operator!=(const UTF8::String &s) const { - - return !(*this == s); -} - -bool UTF8::String::operator==(const char *str) const { - if (str && strlen(str)) { - if (DataArrayLength != strlen(str)) { - return false; - } else { - for (int i = 0; i < DataArrayLength; i++) { - if (Data[i] != str[i]) { - return false; - } - } - - return true; - } - } else { - - return StringLength == 0; - } -} - -bool UTF8::String::operator!=(const char *str) const { - - return !(*this == str); -} - -const char * UTF8::String::ToConstCharPtr() const { - - return Data; -} - -unsigned int UTF8::String::Length() const { - - return StringLength; -} - -unsigned int UTF8::String::DataLength() const { - - return DataArrayLength; -} - -UTF8::String::~String() { - - Empty(); -} - -UTF8::String::String(const String& orig) { - InitString(); - SetString(orig.Data); -} - diff --git a/include/UTF8Strings/String.h b/include/UTF8Strings/String.h deleted file mode 100644 index 4a71f27..0000000 --- a/include/UTF8Strings/String.h +++ /dev/null @@ -1,325 +0,0 @@ -/** - * UTF8 string library. - * - * Allows to use native UTF8 sequences as a string class. Has many overloaded - * operators that provides such features as concatenation, types converting and - * much more. - * - * Distributed under GPL v3 - * - * Author: - * Grigory Gorelov (gorelov@grigory.info) - * See more information on grigory.info - */ - -#ifndef _UTF8_String_H -#define _UTF8_String_H - -#include "Exception.h" -#include -#include -#include -#include - -namespace UTF8 { - - /** - * The only string class containing everything to work with UTF8 strings - */ - class String { - public: - static const int SearchDirectionFromLeftToRight = 1; - static const int SearchDirectionFromRightToLeft = 2; - - /** - * Search substring in string - * @param StartPosition Position to start search - * @param Direction Search forward or backward, uses SearchDirectionFromLeftToRight and SearchDirectionFromRightToLeft - * @return Returns position of substring if found. Otherwise returns -1 - */ - long Search(const UTF8::String &SubString, unsigned int StartPosition = 0, int Direction = SearchDirectionFromLeftToRight) const; - - /// Simple constructor only initiates buffers - String(); - - /** - * Create string object from UTF8 char * string - */ - String(const char *str); - - /** - * Create string object from UTF-32 string - */ - String(const uint32_t *); - - /** - * Create string object from UTF8 std::string - */ - String(const std::string &); - - /** - * Copying constructor. Feel free to such things UTF8::String s2=s1; - */ - String(const String& orig); - - /** - * Converting from long constructor. Automatically generates string from number. - */ - String(const long double d,const UTF8::String &ThousandSeparator = "", const UTF8::String &FractionSeparator = ".", const int IntegerPartLength = 0, const int FractionPartLength = 0); - - ~String(); - - /** - * Converts UTF8::String to std::string - */ - std::string ToString() const; - - /** - * Reads content from a file and returns as UTF8::String - */ - static String FromFile(const UTF8::String &Path); - - /** - * Converts UTF8::String to long - */ - int64_t ToLong() const; - - /** - * Converts UTF8::String to double - */ - double ToDouble() const; - - /** - * Converts UTF8::String to const char * - */ - const char * ToConstCharPtr() const; - - /** - * Separates string using given separator and returns vector - */ - std::vector Explode(const String &Separator) const; - - /** - * Creating String from array of String adding separator between them. - */ - static String Implode(const std::vector &Strings, const String &Separator); - - /** - * Sum operator. Provides String1+String2 exression. - */ - String operator+(const String &) const; - - /** - * Sum operator. Provides String1+"Str" exression. - */ - String operator+(const char *) const; - - /** - * Unary sum operator. Provides String1+=String2 expression. - */ - String & operator+=(const String &); - - /** - * Assign operator. Provides String1=String2 expression. - */ - String & operator=(const String &); - - /** - * Assign operator. Provides String1="New value" expression. - */ - String & operator=(const char *); - - /** - * Assign operator. Provides String1=(uint32_t*) UTF32_StringPointer expression. - * Automatically converts UNICODE to UTF-8 ans stores in itself - */ - String & operator=(const uint32_t*); - - /** - * Assign operator. Provides String1=(long double) expression. - */ - String & operator=(long double); - - /** - * Returns substring of current string. - * @param Start Start position of substring - * @param Count Number of sybmols after start position. If number==0 string from Start till end is returned. - */ - String Substring(unsigned int Start, unsigned int Count = 0) const; - - /** - * Replaces one text peace by another and returns result - * @param Search Search string - * @param Replace Replace string - * @return Returns result of replacement - */ - String Replace(const String &Search, const String &Replace) const; - - /** - * Returns trimmed string. Removes whitespaces from left and right - */ - String Trim() const; - - /** - * Returns string with nice quotes like this « ». - */ - String Quote() const; - - /** - * Replaces region of string by text peace and returns result. - * @param Search Search string - * @param Replace Replace string - * @return Returns result of replacement - */ - String SubstringReplace(unsigned int Start, unsigned int Count, const String &Replace) const; - - - /** - * Returns position of substring in current string. - * @param Start Position to start search. Default is 0. - * @return If substring not found returns -1. - */ - long GetSubstringPosition(const UTF8::String &SubString, unsigned int Start = 0) const; - - /** - * Get one char operator. Provides UTF8::String c=String1[1]; - */ - String operator[](unsigned int const) const; - - /** - * Test operator. Provides String1==String2 expression. - */ - bool operator==(const UTF8::String &) const; - - /** - * Test operator. Provides String1!=String2 expression. - */ - bool operator!=(const UTF8::String &) const; - - /** - * Test operator. Provides String1=="Test" expression. - */ - bool operator==(const char *) const; - - /** - * Test operator. Provides String1!="Test" expression. - */ - bool operator!=(const char *) const; - - /** Test operator. Provides String1String2 expression. - * Operator compares left characters of two strings. - * If String1[0] value is greater then the String2[0] returns true. - * If they are equal then goes to second character and so on. - * Can be used to sort strings alphabetical. - */ - bool operator>(const UTF8::String &) const; - - /** - * Returns current string length. Also see DataLength to get buffer - * size - */ - unsigned int Length() const; - - /** - * Returns current char data array length, containig UTF8 string. - * As one character in UTF8 can be stored by more then one byte use - * this function to know how much memory allocated for the string. - */ - unsigned int DataLength() const; - - /** - * Clears current string as if it is just created - */ - void Empty(); - - /** - * If string is a one character check if it is one of given - */ - bool CharacterIsOneOfThese(const UTF8::String &Characters) const; - - /** - * Checks if this string contains given another string - */ - bool HasThisString(const UTF8::String &Str) const; - - - /** - * Special function to convert from very big integers - * Normally it is ok to assing UTF8::String to number. Or construct from it. - * This function exists only for very very big integers conversion. - */ - void ConvertFromInt64(int64_t n); - - - private: - char *Data; - unsigned int DataArrayLength; - unsigned int StringLength; - - unsigned int GetSequenceLength(const char * StartByte) const; - void CheckIfStringIsCorrect(const char *str) const; - void CalculateStringLength(); - - void InitString(); - void AppendString(const char *str); - void SetString(const char *str); - int GetSymbolIndexInDataArray(unsigned int Position) const; - - void ConvertFromUTF32(const uint32_t *); - void ConvertFromDouble(const long double d, const UTF8::String &ThousandSeparator = "", const UTF8::String &DecimalSeparator = ".", const int IntegerPartCount = 0, const int FractionPartCount = 0); - - }; - -} - -/** - * Not in class overloaded operator +. Provides "Sample"+String1 expression. - */ -UTF8::String operator+(const char *, const UTF8::String &); - -/** - * Not in class overloaded operator +. Provides std::string("123")+String1 expression. - */ -UTF8::String operator+(const std::string &, const UTF8::String &); - -/** - * Not in class overloaded operator +. Provides 123+String1 expression. - */ -UTF8::String operator+(long, const UTF8::String &); - -/** - * Not in class overloaded operator ==. Provides "Test"==String1 expression. - */ -bool operator==(const char *, const UTF8::String &); - -/** - * Not in class overloaded operator ==. Provides std::string==String1 expression. - */ -bool operator==(const std::string &, const UTF8::String &); - -/** - * Not in class overloaded operator !=. Provides "Test"!=String1 expression. - */ -bool operator!=(const char *, const UTF8::String &); - -/** - * Not in class overloaded operator !=. Provides std::string!=String1 expression. - */ -bool operator!=(const std::string &, const UTF8::String &); - -/** - * Overloading for cout. Provides std::cout << (UTF8::String) operation; - */ -std::ostream & operator<<(std::ostream &os, const UTF8::String &s); - -#endif /* _UTF8STRING_H */ - - diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 584ed4f..d1303be 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -16,6 +16,10 @@ SFTP.cpp + + Settings.cpp + Settings.h + EditPane.cpp MainFrame.cpp @@ -112,6 +116,10 @@ + + + + diff --git a/src/definitions.h b/src/definitions.h index f4d1da9..f5f84db 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -10,6 +10,7 @@ typedef pair StringConstMapData; typedef map StringConstMap; const wxString TYRO_FILE_OPEN_WILDCARDS = + _T("All files (*.*)|*.*|") _T("Bash (*.sh, *.bsh) |*.sh;*.bsh|") _T("Batch (*.bat, *.cmd, *.nt)|*.bat;*.cmd,*.nt|") _T("C/C++ (*.c,*.cpp,*.h)| *.c;*.cc;*.cpp;*.cxx;*.cs;*.h;*.hh;*.hpp;*.hxx;*.sma;*.cp |") @@ -25,8 +26,7 @@ const wxString TYRO_FILE_OPEN_WILDCARDS = _T("Ruby (*.rb)|*.rb|") _T("SQL (*.sql)|*.sql|") _T("TCL (*.tcl)|*.tcl|") - _T("Text (*.txt)|*.txt") - _T("All files (*.*)|*.*|"); + _T("Text (*.txt)|*.txt"); const wxString TYRO_FILE_SAVE_WILDCARDS = _T("HTML/XHTML (*.html)|*.html|") diff --git a/src/network/SFTP.h b/src/network/SFTP.h index 6690bd1..0926164 100644 --- a/src/network/SFTP.h +++ b/src/network/SFTP.h @@ -1,4 +1,4 @@ -/* +/** * File: SFTP.h * Author: twarren * diff --git a/src/settings/Settings.cpp b/src/settings/Settings.cpp new file mode 100644 index 0000000..93ed570 --- /dev/null +++ b/src/settings/Settings.cpp @@ -0,0 +1,15 @@ +/** + * Object to control settings reading/writing + */ + +#include "Settings.h" + +TyroSettings::TyroSettings() +{ + +} + +TyroSettings::~TyroSettings() +{ + +} \ No newline at end of file diff --git a/src/settings/Settings.h b/src/settings/Settings.h new file mode 100644 index 0000000..99483d5 --- /dev/null +++ b/src/settings/Settings.h @@ -0,0 +1,23 @@ +/* + * File: Settings.h + * Author: twarren + * + * Created on April 13, 2015, 4:18 PM + */ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "../common.h" +#include "../../include/json/json.h" + +class TyroSettings { +public: + TyroSettings(); + ~TyroSettings(); +private: +}; + + +#endif /* SETTINGS_H */ + diff --git a/src/widgets/EditPane.cpp b/src/widgets/EditPane.cpp index 331ba4e..b9a43e6 100644 --- a/src/widgets/EditPane.cpp +++ b/src/widgets/EditPane.cpp @@ -4,15 +4,15 @@ EditPane::EditPane( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style ) : wxStyledTextCtrl (parent, id, pos, size, style) -{ +{ StringConstMapData map_data[] = { {"c", wxSTC_LEX_CPP}, {"h", wxSTC_LEX_CPP}, {"cpp", wxSTC_LEX_CPP}, {"cxx", wxSTC_LEX_CPP}, {"py", wxSTC_LEX_PYTHON}, - {"php", wxSTC_LEX_PHPSCRIPT}, - {"js", wxSTC_LEX_ESCRIPT}, + {"php", wxSTC_LEX_PHPSCRIPT}, + {"js", wxSTC_LEX_ESCRIPT}, {"json", wxSTC_LEX_ESCRIPT} }; @@ -24,10 +24,10 @@ EditPane::EditPane( EditPane::~EditPane() {} -void EditPane::OnSize(wxSizeEvent &event) +/*void EditPane::OnSize(wxSizeEvent &event) { -} +}*/ /** * Encapsulate lexer selection when opening a file @@ -37,6 +37,7 @@ void EditPane::OnSize(wxSizeEvent &event) */ bool EditPane::LoadAndHighlight(wxString filePath) { + fileName = filePath; wxFileName file(filePath); wxString ext = file.GetExt(); @@ -53,34 +54,33 @@ bool EditPane::LoadAndHighlight(wxString filePath) this->SetProperty (wxT("fold.comment"), wxT("1") ); this->SetProperty (wxT("fold.compact"), wxT("1") ); - - this->StyleSetForeground (wxSTC_C_STRING, wxColour(150,0,0)); + this->StyleSetForeground (wxSTC_C_STRING, wxColour(150,0,0)); this->StyleSetBackground (wxSTC_C_STRING, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_PREPROCESSOR, wxColour(165,105,0)); + this->StyleSetForeground (wxSTC_C_PREPROCESSOR, wxColour(165,105,0)); this->StyleSetBackground (wxSTC_C_PREPROCESSOR, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_IDENTIFIER, wxColour(40,0,60)); + this->StyleSetForeground (wxSTC_C_IDENTIFIER, wxColour(40,0,60)); this->StyleSetBackground (wxSTC_C_IDENTIFIER, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_NUMBER, wxColour(0,150,0)); + this->StyleSetForeground (wxSTC_C_NUMBER, wxColour(0,150,0)); this->StyleSetBackground (wxSTC_C_NUMBER, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_CHARACTER, wxColour(150,0,0)); + this->StyleSetForeground (wxSTC_C_CHARACTER, wxColour(150,0,0)); this->StyleSetBackground (wxSTC_C_CHARACTER, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_WORD, wxColour(0,0,150)); + this->StyleSetForeground (wxSTC_C_WORD, wxColour(0,0,150)); this->StyleSetBackground (wxSTC_C_WORD, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_WORD2, wxColour(0,150,0)); + this->StyleSetForeground (wxSTC_C_WORD2, wxColour(0,150,0)); this->StyleSetBackground (wxSTC_C_WORD2, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_COMMENT, wxColor(147, 161, 161)); + this->StyleSetForeground (wxSTC_C_COMMENT, wxColor(147, 161, 161)); this->StyleSetBackground (wxSTC_C_COMMENT, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_COMMENTLINE, wxColor(147, 161, 161)); + this->StyleSetForeground (wxSTC_C_COMMENTLINE, wxColor(147, 161, 161)); this->StyleSetBackground (wxSTC_C_COMMENTLINE, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_COMMENTDOC, wxColor(147, 161, 161)); + this->StyleSetForeground (wxSTC_C_COMMENTDOC, wxColor(147, 161, 161)); this->StyleSetBackground (wxSTC_C_COMMENTDOC, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORD, wxColour(0,0,200)); + this->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORD, wxColour(0,0,200)); this->StyleSetBackground (wxSTC_C_COMMENTDOCKEYWORD, wxColor(253, 246, 227)); - this->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORDERROR, wxColour(0,0,200)); + this->StyleSetForeground (wxSTC_C_COMMENTDOCKEYWORDERROR, wxColour(0,0,200)); this->StyleSetBackground (wxSTC_C_COMMENTDOCKEYWORDERROR, wxColor(253, 246, 227)); - /*this->StyleSetBold(wxSTC_C_WORD, true); + this->StyleSetBold(wxSTC_C_WORD, true); this->StyleSetBold(wxSTC_C_WORD2, true); - this->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true);*/ + this->StyleSetBold(wxSTC_C_COMMENTDOCKEYWORD, true); lexer_map_it = lexer_map.find((string) ext); this->SetLexer(lexer_map_it->second); diff --git a/src/widgets/EditPane.h b/src/widgets/EditPane.h index c9f212e..26bea4f 100644 --- a/src/widgets/EditPane.h +++ b/src/widgets/EditPane.h @@ -2,11 +2,10 @@ #define TYROEDIT_PANE_H #include "../wx_common.h" +#include "../settings/Settings.h" #include -#include "../../include/json/json.h" - class EditPane: public wxStyledTextCtrl { public: @@ -22,6 +21,7 @@ public: wxVSCROLL ); ~EditPane(); + wxString fileName; void OnSize(wxSizeEvent &event); bool LoadAndHighlight(wxString filePath); private: diff --git a/src/widgets/MainFrame.cpp b/src/widgets/MainFrame.cpp index 3deec7c..3e29a22 100644 --- a/src/widgets/MainFrame.cpp +++ b/src/widgets/MainFrame.cpp @@ -29,6 +29,8 @@ MainFrame::MainFrame(wxFrame *frame, const wxString& title) SetSizerAndFit(base_sizer); + this->DisableEditControls(); + // Finally, bind events this->BindEvents(); } @@ -79,8 +81,6 @@ void MainFrame::SetupToolbar() //toolBar->AddSeparator(); //toolBar->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings"); - toolBar->EnableTool(wxID_SAVE, false); - toolBar->Realize(); } @@ -105,11 +105,6 @@ void MainFrame::SetupMenu() fileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl+W"), _T("Close the current document")); fileMenu->Append(wxID_EXIT, _T("&Quit\tCtrl+Q"), _T("Quit the application")); - fileMenu->Enable(wxID_SAVE, false); - fileMenu->Enable(wxID_SAVEAS, false); - fileMenu->Enable(wxID_CLOSE, false); - - editMenu->Append(wxID_UNDO, _T("&Undo\tCtrl+Z"), _T("Undo last action")); editMenu->Append(wxID_REDO, _T("&Redo\tCtrl+Y"), _T("Redo last action")); editMenu->AppendSeparator(); @@ -120,16 +115,7 @@ void MainFrame::SetupMenu() editMenu->AppendSeparator(); editMenu->Append (wxID_FIND, _("&Find\tCtrl+F")); editMenu->AppendSeparator(); - editMenu->Append(wxID_SELECTALL, _T("Select All\tCtrl+A"), _T("Select all the text in the current document")); - - editMenu->Enable(wxID_UNDO, false); - editMenu->Enable(wxID_REDO, false); - editMenu->Enable(wxID_CUT, false); - editMenu->Enable(wxID_COPY, false); - editMenu->Enable(wxID_PASTE, false); - editMenu->Enable(wxID_CLEAR, false); - editMenu->Enable(wxID_FIND, false); - editMenu->Enable(wxID_SELECTALL, false); + editMenu->Append(wxID_SELECTALL, _T("Select All\tCtrl+A"), _T("Select all the text in the current document")); helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show info about this application")); @@ -149,6 +135,8 @@ void MainFrame::BindEvents() { Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnNew, this, wxID_NEW); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnOpen, this, wxID_OPEN); + Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSave, this, wxID_SAVE); + Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnSaveAs, this, wxID_SAVEAS); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnFileClose, this, wxID_CLOSE); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAbout, this, wxID_ABOUT); Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT); @@ -162,6 +150,7 @@ void MainFrame::BindEvents() void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event)) { + this->EnableEditControls(); notebook->AddTab(); } @@ -176,6 +165,8 @@ void MainFrame::OnOpen(wxCommandEvent &WXUNUSED(event)) filename = dlg.GetPath(); + this->EnableEditControls(); + notebook->AddTab(filename); } @@ -186,7 +177,8 @@ void MainFrame::OnFileClose(wxCommandEvent &WXUNUSED(event)) void MainFrame::OnSave(wxCommandEvent &WXUNUSED(event)) { - // @TODO Implement OnSave + wxString file = notebook->GetCurrentEditor()->fileName; + notebook->GetCurrentEditor()->SaveFile(file); } void MainFrame::OnSaveAs(wxCommandEvent &WXUNUSED(event)) @@ -252,3 +244,44 @@ void MainFrame::OnAbout(wxCommandEvent &WXUNUSED(event)) wxAboutBox(info); } + +/** + * Enable file-specific controls + */ +void MainFrame::EnableEditControls() +{ + fileMenu->Enable(wxID_SAVE, true); + fileMenu->Enable(wxID_SAVEAS, true); + fileMenu->Enable(wxID_CLOSE, true); + //editMenu->Enable(wxID_UNDO, false); + //editMenu->Enable(wxID_REDO, false); + editMenu->Enable(wxID_CUT, true); + editMenu->Enable(wxID_COPY, true); + editMenu->Enable(wxID_PASTE, true); + editMenu->Enable(wxID_CLEAR, true); + editMenu->Enable(wxID_FIND, true); + editMenu->Enable(wxID_SELECTALL, true); + + toolBar->EnableTool(wxID_SAVE, true); +} + +/** + * Disables file-specific controls + */ +void MainFrame::DisableEditControls() +{ + fileMenu->Enable(wxID_SAVE, false); + fileMenu->Enable(wxID_SAVEAS, false); + fileMenu->Enable(wxID_CLOSE, false); + + editMenu->Enable(wxID_UNDO, false); + editMenu->Enable(wxID_REDO, false); + editMenu->Enable(wxID_CUT, false); + editMenu->Enable(wxID_COPY, false); + editMenu->Enable(wxID_PASTE, false); + editMenu->Enable(wxID_CLEAR, false); + editMenu->Enable(wxID_FIND, false); + editMenu->Enable(wxID_SELECTALL, false); + + toolBar->EnableTool(wxID_SAVE, false); +} diff --git a/src/widgets/MainFrame.h b/src/widgets/MainFrame.h index 77b2ee7..ac6c40e 100644 --- a/src/widgets/MainFrame.h +++ b/src/widgets/MainFrame.h @@ -35,6 +35,8 @@ class MainFrame: public wxFrame void SetupToolbar(); void SetupStatusBar(); void BindEvents(); + void EnableEditControls(); + void DisableEditControls(); void OnNew(wxCommandEvent &event); void OnOpen(wxCommandEvent &event); void OnFileClose(wxCommandEvent &event);