Skip to content

Commit 498945d

Browse files
committed
use wxString instead of std::string
1 parent 66f6fa8 commit 498945d

File tree

4 files changed

+261
-272
lines changed

4 files changed

+261
-272
lines changed

CMakeLists.txt

+31-20
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ if (UNIX)
88
set(CMAKE_CXX_STANDARD 11)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11-
# set build type and flags
11+
# set(CMAKE_CXX_COMPILER clang++)
12+
# string(CONCAT CMAKE_CXX_FLAGS
13+
# "-stdlib=libstdc++ " # Do not use libc++ as wxWidgets libraries are precompiled
14+
# )
15+
16+
# Set build type and flags
1217
string(CONCAT CMAKE_CXX_FLAGS_DEBUG
13-
"-Wall " # display all warnings
14-
"-g " # with debug information
15-
"-O0 " # no optimize
16-
"-Wno-parentheses" # disable parentheses warning
18+
"-Wall " # Display all warnings
19+
"-g " # With debug information
20+
"-O0 " # No optimize
1721
)
1822
string(CONCAT CMAKE_CXX_FLAGS_RELEASE
19-
"-O3" # enable optimize
23+
"-O3 " # Enable optimize
2024
)
2125
if (CMAKE_BUILD_TYPE STREQUAL "")
2226
set(CMAKE_BUILD_TYPE "Release")
@@ -44,31 +48,38 @@ if (UNIX)
4448
"${PROJECT_SOURCE_DIR}/static/mynotepad.desktop.in"
4549
"${PROJECT_SOURCE_DIR}/static/mynotepad.desktop"
4650
)
51+
52+
# find_package(PkgConfig REQUIRED)
53+
# pkg_check_modules(GTK gtk+-3.0 REQUIRED)
54+
# include_directories(${GTK_INCLUDE_DIRS})
55+
# message(STATUS "GTK headers: ${GTK_INCLUDE_DIRS}")
56+
# message(STATUS "GTK libraries: ${GTK_LIBRARIES}")
57+
# set(EXTRA_LIBS ${EXTRA_LIBS} ${GTK_LIBRARIES})
4758
endif()
4859

49-
# specify the path manually
60+
# Specify the path manually
5061
if (WIN32)
5162
#set(wxWidgets_ROOT_DIR "D:/wxWidgets-3.1.3/")
5263
#set(wxWidgets_LIB_DIR "D:/wxWidgets-3.1.3/lib/vc14x_dll")
5364
endif()
5465
set(wxWidgets_CONFIGURATION mswu) # or mswud
5566

56-
# find wxWidgets
67+
# Find wxWidgets
5768
find_package(wxWidgets COMPONENTS core base stc REQUIRED)
5869
message(STATUS "wxWidgets version: ${wxWidgets_VERSION_MAJOR}."
5970
"${wxWidgets_VERSION_MINOR}.${wxWidgets_VERSION_PATCH}")
6071

6172
include(${wxWidgets_USE_FILE})
6273
set(EXTRA_LIBS ${EXTRA_LIBS} ${wxWidgets_LIBRARIES})
6374

64-
# define header directory
75+
# Define header directory
6576
include_directories(
6677
"${PROJECT_BINARY_DIR}/inc"
6778
"${PROJECT_SOURCE_DIR}/inc"
6879
"${PROJECT_SOURCE_DIR}/static"
6980
"${PROJECT_SOURCE_DIR}/md2html/inc"
7081
)
71-
# define source directory
82+
# Define source directory
7283
aux_source_directory(src SOURCES)
7384

7485
if (WIN32)
@@ -77,7 +88,7 @@ if (WIN32)
7788
list(APPEND SOURCES "static/mynotepad.manifest")
7889
endif()
7990

80-
# target executable file
91+
# Target executable file
8192
set(TARGET mynotepad)
8293
add_executable(${TARGET} WIN32 ${SOURCES})
8394

@@ -101,12 +112,12 @@ else()
101112
set(EXTRA_LIBS ${EXTRA_LIBS} md2html)
102113
endif()
103114

104-
# link libraries
115+
# Link libraries
105116
target_link_libraries(${TARGET} ${EXTRA_LIBS})
106117

107118
if (WIN32)
108119
set(WXVER "${wxWidgets_VERSION_MAJOR}${wxWidgets_VERSION_MINOR}${wxWidgets_VERSION_PATCH}")
109-
# required DLLs on Windows
120+
# Required DLLs on Windows
110121
set(ALL_DLLS_DEBUG
111122
"${wxWidgets_LIB_DIR}/wxbase${WXVER}ud_vc14x_x64.dll"
112123
"${wxWidgets_LIB_DIR}/wxbase${WXVER}ud_net_vc14x_x64.dll"
@@ -130,7 +141,7 @@ if (WIN32)
130141
"${PROJECT_SOURCE_DIR}/static/logo.png"
131142
"${PROJECT_SOURCE_DIR}/static/mynotepad.visualelementsmanifest.xml"
132143
)
133-
# destination directory
144+
# Destination directory
134145
set(COPY_DLLS_TO ${PROJECT_BINARY_DIR}/)
135146
#message(STATUS ${COPY_DLLS_TO})
136147
add_custom_command(TARGET ${TARGET} POST_BUILD
@@ -141,21 +152,21 @@ if (WIN32)
141152
)
142153

143154
elseif (UNIX)
144-
# default path is /usr/local/
155+
# Default path is /usr/local/
145156
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
146157

147-
# install the program after build, /usr/local/bin/
158+
# Install the program after build, /usr/local/bin/
148159
install(TARGETS ${TARGET} RUNTIME DESTINATION bin)
149-
150-
# copy dependent files while installing, default path is /usr/local/share
160+
161+
# Copy dependent files while installing, default path is /usr/local/share
151162
install(DIRECTORY "${PROJECT_SOURCE_DIR}/static/"
152163
DESTINATION "share/${PROJECT_NAME}"
153164
# make the files writable
154165
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
155166
FILES_MATCHING PATTERN "*.css" PATTERN "*.js" PATTERN "*.png"
156167
)
157-
158-
# create desktop icon
168+
169+
# Create desktop icon
159170
install(FILES "${PROJECT_SOURCE_DIR}/static/mynotepad.desktop"
160171
DESTINATION /usr/share/applications
161172
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ

README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A markdown editor that supports exporting HTML.
88

9-
This program is initially written in pure win32 APIs just like [this](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646268(v=vs.85).aspx). Later it's rewritten using wxWidgets, you can build it in Windows and Linux.
9+
This program is initially written in pure win32 APIs just like [this](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646268(v=vs.85).aspx). Later it's rewritten using wxWidgets, you can build it in Windows and Linux.
1010

1111
Download binaries: [Release](../../releases)
1212

@@ -18,10 +18,15 @@ Try this markdown file: [test.md](test.md)
1818

1919
```bash
2020
sudo apt update
21-
sudo apt install build-essential cmake libwxgtk3.0-dev
21+
sudo apt install build-essential cmake git
22+
# Debian 9
23+
sudo apt install libwxgtk3.0-dev
24+
# Debian 10
25+
sudo apt install libwxgtk3.0-gtk3-dev
2226
git clone https://github.com/mooction/mynotepad
23-
cd mynotepad
24-
cmake .
27+
mkdir mynotepad/build
28+
cd mynotepad/build
29+
cmake .. -DCMAKE_BUILD_TYPE=Release
2530
make
2631
sudo make install
2732
```
@@ -64,7 +69,7 @@ See [CMakeLists.txt](CMakeLists.txt) for more detail.
6469

6570
5. Set `wxWidgets_ROOT_DIR` and `wxWidgets_LIB_DIR` to the wxWidgets library folder. For the instance above, set `wxWidgets_ROOT_DIR` to `D:\wxWidgets-3.1.3\` and set `wxWidgets_LIB_DIR` to `D:\wxWidgets-3.1.3\lib\vc14x_x64_dll`.
6671

67-
6. Click `Configure` again, then click `Generate`, finally we get a Visual Studio solution.
72+
6. Click `Configure` again, then click `Generate`, finally we get a Visual Studio solution.
6873

6974
### Options
7075

@@ -74,15 +79,14 @@ Use `cmake -D<VAR>=<VALUE>` to change any option.
7479
| - | - | - |
7580
| `CMAKE_BUILD_TYPE` | Debug | Build Type for Unix (Release / Debug) |
7681

77-
## Known bugs
82+
## Known issue
7883

79-
1. (Linux)Texts copied to clipboard will disappear after the window closed
80-
2. (Linux)Fail to open/save file in non-ascii path
84+
1. (Linux) Copied text will disappear after the window closed
8185

8286
## TODO
8387

84-
- search & replace
85-
- encode conversion(only support utf-8 currently)
88+
- Search & replace
89+
- Encode conversion (only support utf-8 currently)
8690

8791
## Programming Guide
8892

inc/main.h

+37-39
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
#ifndef __MAIN_H__
22
#define __MAIN_H__
33

4-
const char* MNP_APPNAME = "MyNotePad";
5-
const char* MNP_DOC_TITLE = " - MyNotePad";
6-
const char* MNP_DOC_NOTITLE = "Untitled";
7-
const char* MNP_COPYRIGHT = "\nCopyright(c) moooc.cc";
4+
const wxChar* MNP_APPNAME = wxS("MyNotePad");
5+
const wxChar* MNP_DOC_TITLE = wxS(" - MyNotePad");
6+
const wxChar* MNP_DOC_NOTITLE = wxS("Untitled");
7+
const wxChar* MNP_COPYRIGHT = wxS("\nCopyright(c) moooc.cc");
88

9-
int MNP_PADDING_LEFT = 16; // space for line number
10-
const int MNP_LINENUM_MARGIN_LEFT = 4;
11-
const int MNP_LINENUM_MARGIN_TOP = 4;
12-
const char* MNP_LINENUM_FONTFACE = "Arial";
13-
const int MNP_SCROLLBAR_WIDTH = 14;
9+
int MNP_PADDING_LEFT = 16; // space for line number
10+
const int MNP_LINENUM_MARGIN_LEFT = 4;
11+
const int MNP_LINENUM_MARGIN_TOP = 4;
12+
const int MNP_SCROLLBAR_WIDTH = 14;
13+
const wxChar* MNP_LINENUM_FONTFACE = wxS("Arial");
1414

15-
const char* MNP_CONFIG_FILE = "MyNotePad.conf";
16-
const char* MNP_CONFIG_THEME = "theme";
17-
const char* MNP_CONFIG_WORDWRAP = "word-wrap";
18-
const char* MNP_CONFIG_LINENUMBER = "line-number";
19-
const char* MNP_CONFIG_FONTNAME = "font-name";
15+
const wxChar* MNP_CONFIG_FILE = wxS("MyNotePad.conf");
16+
const wxChar* MNP_CONFIG_THEME = wxS("theme");
17+
const wxChar* MNP_CONFIG_WORDWRAP = wxS("word-wrap");
18+
const wxChar* MNP_CONFIG_LINENUMBER = wxS("line-number");
19+
const wxChar* MNP_CONFIG_FONTNAME = wxS("font-name");
2020

21-
const char* INFO_SAVE = "Save changes?";
22-
const char* ERR_OPEN_FAIL = "Failed to save HTML file, \n"\
23-
"make sure you have permissions to write that file.";
24-
const char* ERR_FAULT_ENCODING = "Can only open UTF-8 files!";
25-
const char* ERR_UNKNOWN = "Unknown error";
21+
const wxChar* INFO_SAVE = wxS("Save changes?");
22+
const wxChar* ERR_OPEN_FAIL = wxS("Failed to save HTML file, \n"\
23+
"make sure you have permissions to write that file.");
24+
const wxChar* ERR_FAULT_ENCODING = wxS("Can only open UTF-8 files!");
25+
const wxChar* ERR_UNKNOWN = wxS("Unknown error");
2626

2727
#ifdef _WIN32
28-
const char* FONT_1 = "Microsoft Yahei";
29-
const char* FONT_2 = "Lucida Console";
30-
const char* FONT_3 = "Courier New";
31-
const char* FONT_4 = "Consolas";
28+
const wxChar* FONT_1 = wxS("Microsoft Yahei");
29+
const wxChar* FONT_2 = wxS("Lucida Console");
30+
const wxChar* FONT_3 = wxS("Courier New");
31+
const wxChar* FONT_4 = wxS("Consolas");
3232
#else
33-
const char* FONT_1 = "Noto Sans Mono";
34-
const char* FONT_2 = "Liberation Mono";
35-
const char* FONT_3 = "Courier 10 Pitch";
36-
const char* FONT_4 = "DejaVu Sans Mono";
33+
const wxChar* FONT_1 = wxS("Noto Sans Mono");
34+
const wxChar* FONT_2 = wxS("Liberation Mono");
35+
const wxChar* FONT_3 = wxS("Courier 10 Pitch");
36+
const wxChar* FONT_4 = wxS("DejaVu Sans Mono");
3737
#endif
3838

3939
struct CharStyle
@@ -49,18 +49,17 @@ const CharStyle default_style = { 0 };
4949
class MyFrame : public wxFrame {
5050
public:
5151
MyFrame(const wxString& title);
52-
52+
5353
void themeLight();
5454
void themeDark();
5555
void loadSettings();
5656
void saveSettings();
5757
void updateSaveState(bool saved);
58-
void loadFile(const std::string path);
58+
void loadFile(wxString path);
5959
bool sureToQuit(wxCommandEvent& event);
60-
void saveHTML(const std::string pathname);
61-
std::string all_to_string();
60+
void saveHTML(const wxString& pathname);
6261
void ApplyTheme();
63-
void md2html(std::string& str);
62+
void md2html(wxString& str);
6463
int widthOfLineNumber() const;
6564
#ifndef _WIN32
6665
// this function is not exists on Linux
@@ -76,14 +75,14 @@ class MyFrame : public wxFrame {
7675
void OnRightButtonUp(wxMouseEvent& event);
7776
void OnKeyDown(wxKeyEvent& event);
7877
void OnChar(wxKeyEvent& event);
79-
78+
8079
void OnNew(wxCommandEvent& event);
8180
void OnOpen(wxCommandEvent& event);
8281
void OnSave(wxCommandEvent& event);
8382
void OnSaveAs(wxCommandEvent& event);
8483
void OnCopyHtml(wxCommandEvent& event);
8584
void OnExportHTML(wxCommandEvent& event);
86-
void OnQuit(wxCommandEvent& event);
85+
void OnMenuClose(wxCommandEvent& event);
8786
void OnUndo(wxCommandEvent& event);
8887
void OnRedo(wxCommandEvent& event);
8988
void OnCut(wxCommandEvent& event);
@@ -116,10 +115,9 @@ class MyFrame : public wxFrame {
116115
};
117116
notepadCtrl *article;
118117
bool bShowLineNumber; // display line number (initial true)
119-
bool bResized; // flag indicates the app window is resized
120118
bool bSaved; // set false after file is modified
121119
bool bWordWrap; // break word (initial false)
122-
120+
123121
enum THEME {
124122
THEME_LIGHT,
125123
THEME_DARK
@@ -135,12 +133,12 @@ class MyFrame : public wxFrame {
135133
wxColour lineNumFontColor;
136134
wxColour scrollBarBgColor;
137135
wxColour scrollBarColor;
138-
const char* fontFace;
139136
int fontSize;
140137
int lineNumFontSize;
138+
const wxChar* fontFace;
141139
// configure file Path
142-
std::string confFilePath;
143-
std::string openedFile;
140+
wxString confFilePath;
141+
wxString openedFile;
144142
DECLARE_EVENT_TABLE()
145143
};
146144

0 commit comments

Comments
 (0)