Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
agateau committed Jan 12, 2019
2 parents 7c2e2f3 + 6e4d10b commit 3570f50
Show file tree
Hide file tree
Showing 24 changed files with 246 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/build
/dist
CMakeLists.txt.user
CMakeLists.txt.user*
.*.swp
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "singleapplication"]
path = singleapplication/src
path = 3rdparty/singleapplication/src
url = https://github.com/itay-grudev/SingleApplication
[submodule "qpropgen"]
path = qpropgen
path = 3rdparty/qpropgen
url = https://github.com/agateau/qpropgen
[submodule "3rdparty/catch2"]
path = 3rdparty/catch2
url = https://github.com/catchorg/Catch2
1 change: 1 addition & 0 deletions 3rdparty/catch2
Submodule catch2 added at 6ccd46
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
project(singleapplication)

# Dependencies
find_package(Qt5 CONFIG REQUIRED Core Widgets Network)

# Sources
set(CMAKE_AUTOMOC ON)

set(singleapplication_SRCS
src/singleapplication.cpp)

# Building
add_library(singleapplication STATIC ${singleapplication_SRCS})

target_compile_definitions(singleapplication
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 1.0.1 - 2019-01-12

### Fixed
- Fixed indentation and make it respect indentation columns.
- Made it possible to indent/unindent selected lines with Tab/Shift+Tab.
- Update welcome text to reflect current shortcuts.

### Added
- Added unit-tests.
- Added Travis integration.
- Added rpm and deb packages generated using CPack.

## 1.0.0 - 2018-12-30

First release
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ project(nanonote
)

# Dependencies
find_package(Qt5 CONFIG REQUIRED Core Widgets)
include(qpropgen/cmake/qpropgen.cmake)
find_package(Qt5 CONFIG REQUIRED Core Widgets Test)
include(3rdparty/qpropgen/cmake/qpropgen.cmake)
add_subdirectory(3rdparty/singleapplication)
add_subdirectory(3rdparty/catch2)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual")
set(CMAKE_CXX_STANDARD 17)
enable_testing()

add_subdirectory(singleapplication)
add_subdirectory(src)
add_subdirectory(tests)

# Packaging
set(PROJECT_URL "https://github.com/agateau/nanonote")
Expand Down
41 changes: 41 additions & 0 deletions RELEASE_CHECK_LIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Check working tree is up to date and clean:

git checkout dev
git pull
git status

Update CHANGELOG.md:

r!git log --pretty=format:'- \%s (\%an)' x.y.z-1..HEAD

Bump version number in CMakeLists.txt

Commit and push

Build packages:

docker run -v $PWD:/root/nanonote nanonote:1 /root/nanonote/ci/build-packages

Smoke test binary packages

- Test welcome text is OK
- Test screenshot matches

Merge dev in master:

git checkout master
git pull
git merge --no-ff origin/dev

Create "x.y.z" tag:

git tag -a x.y.z

Push:

git push
git push --tags

Publish packages on GitHub

Write blog post
16 changes: 13 additions & 3 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ FROM ubuntu:18.04

RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
qtbase5-dev qt5-default g++ make cmake ninja-build \
python3 python3-pip python3-setuptools \
file rpm
cmake \
dpkg-dev \
file \
g++ \
make \
ninja-build \
python3 \
python3-pip \
python3-setuptools \
qt5-default \
qtbase5-dev \
rpm \
xvfb

COPY requirements.txt /tmp

Expand Down
31 changes: 20 additions & 11 deletions ci/build-packages
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,49 @@ cd $(dirname $0)/..
SRC_DIR=$PWD
DIST_DIR=$PWD/dist

setup_work_dir() {
setup_work_dirs() {
cd /tmp
cd $(mktemp -d cibuild.XXXXXX)
WORK_DIR=$PWD
WORK_SRC_PKG_DIR=$PWD/srcpkg
WORK_BIN_PKG_DIR=$PWD/binpkg
mkdir $WORK_SRC_PKG_DIR $WORK_BIN_PKG_DIR
}

create_source_package() {
cd $WORK_DIR
mkdir srcpkg
cd srcpkg
cd $WORK_SRC_PKG_DIR

cmake -G Ninja $SRC_DIR
ninja package_source
SOURCE_PACKAGE=$(ls *.tar.bz2)
mv $SOURCE_PACKAGE $DIST_DIR
}

create_binary_packages() {
cd $WORK_DIR
mkdir binpkg
cd binpkg
tar xf $DIST_DIR/$SOURCE_PACKAGE
cd $(echo $SOURCE_PACKAGE | sed s/.tar.bz2$//)
unpack_source_package() {
cd $WORK_BIN_PKG_DIR
tar -xf $DIST_DIR/$SOURCE_PACKAGE --strip-components 1
}

build_and_test() {
cd $WORK_BIN_PKG_DIR
mkdir build
cd build
cmake -G Ninja ..
ninja
xvfb-run ninja test
}

create_binary_packages() {
cd $WORK_BIN_PKG_DIR/build
ninja package
mv *.deb *.rpm $DIST_DIR
}

rm -rf $DIST_DIR
mkdir $DIST_DIR
setup_work_dir
setup_work_dirs
create_source_package
unpack_source_package
build_and_test
create_binary_packages
rm -rf $WORK_DIR
2 changes: 1 addition & 1 deletion ci/docker-build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -ev
cd $(dirname $0)
cp ../qpropgen/requirements.txt .
cp ../3rdparty/qpropgen/requirements.txt .
docker build -t nanonote:1 .
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 14 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/Config.h)

set(nanonote_SRCS
main.cpp
IndentExtension.cpp
LinkSyntaxHighlighter.cpp
LinkExtension.cpp
Expand All @@ -22,19 +21,26 @@ qpropgen(QPROPGEN_SRCS
)

# Building
include_directories(
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)

# Lib
add_library(nanonotelib STATIC ${nanonote_SRCS} ${nanonote_RESOURCES} ${QPROPGEN_SRCS})
target_include_directories(nanonotelib PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(nanonotelib
Qt5::Core
Qt5::Widgets
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual")
set(CMAKE_CXX_STANDARD 17)
add_executable(nanonote ${nanonote_SRCS} ${nanonote_RESOURCES} ${QPROPGEN_SRCS})

# Main
add_executable(nanonote main.cpp)
target_link_libraries(nanonote
nanonotelib
singleapplication
Qt5::Core
Qt5::Widgets
)

# Install
Expand Down
19 changes: 17 additions & 2 deletions src/IndentExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ void IndentExtension::aboutToShowContextMenu(QMenu *menu, const QPoint &/*pos*/)
bool IndentExtension::keyPress(QKeyEvent *event)
{
if (event->key() == Qt::Key_Tab && event->modifiers() == 0) {
insertIndentation();
onTabPressed();
return true;
}
if (event->key() == Qt::Key_Backtab) {
processSelection(unindentLine);
return true;
}
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
Expand Down Expand Up @@ -106,7 +110,8 @@ bool IndentExtension::canRemoveIndentation() const
void IndentExtension::insertIndentation()
{
auto cursor = mTextEdit->textCursor();
indentLine(cursor);
int count = INDENT_SIZE - (cursor.columnNumber() % INDENT_SIZE);
cursor.insertText(QString(count, ' '));
}

void IndentExtension::processSelection(ProcessSelectionCallback callback)
Expand Down Expand Up @@ -136,6 +141,16 @@ void IndentExtension::processSelection(ProcessSelectionCallback callback)
editCursor.endEditBlock();
}

void IndentExtension::onTabPressed()
{
auto cursor = mTextEdit->textCursor();
if (cursor.selectedText().contains(QChar::ParagraphSeparator)) {
processSelection(indentLine);
} else {
insertIndentation();
}
}

void IndentExtension::removeIndentation()
{
auto cursor = mTextEdit->textCursor();
Expand Down
1 change: 1 addition & 0 deletions src/IndentExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IndentExtension : public TextEditExtension
void removeIndentation();
void insertIndentedLine();
void processSelection(ProcessSelectionCallback callback);
void onTabPressed();

QAction *mIndentAction;
QAction *mUnindentAction;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
int main(int argc, char *argv[])
{
SingleApplication app(argc, argv);
Q_INIT_RESOURCE(nanonote);
app.setOrganizationName("agateau.com");
app.setApplicationName("nanonote");
app.setApplicationVersion(NANONOTE_VERSION);
Expand Down
4 changes: 2 additions & 2 deletions src/welcome.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ It also has a few handy editing features, like auto-bullet lists:

You can also open urls using Control + click. You can try clicking on this one for example: https://github.com/agateau/nanonote.

Finally, you can indent selected lines with Ctrl+I and unindent with Ctrl+U.
Finally, you can indent selected lines with Tab or Ctrl+I and unindent them with Shift+Tab or Ctrl+U.

That's all there is to say, now you can erase this text and start taking notes!
That's all there is to say, now you can erase this text and start taking notes!
14 changes: 14 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_executable(tests
tests.cpp
IndentExtensionTest.cpp
LinkSyntaxHighlighterTest.cpp
TestUtils.cpp
)

target_link_libraries(tests
nanonotelib
Qt5::Test
Catch2::Catch2
)

add_test(NAME tests COMMAND tests)
46 changes: 46 additions & 0 deletions tests/IndentExtensionTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "IndentExtension.h"

#include <QMainWindow>
#include <QTest>
#include <QTextCursor>

#include <catch2/catch.hpp>

#include "TestUtils.h"

TEST_CASE("textedit") {
QMainWindow window;
TextEdit *edit = new TextEdit;
window.setCentralWidget(edit);
edit->addExtension(new IndentExtension(edit));
SECTION("indent insert spaces") {
edit->setPlainText("Hello");

SECTION("indent from beginning of line") {
QTest::keyClick(edit, Qt::Key_Tab);
REQUIRE(edit->toPlainText() == QString(" Hello"));
}

SECTION("indent from middle of word") {
QTest::keyClick(edit, Qt::Key_Right);
QTest::keyClick(edit, Qt::Key_Tab);
REQUIRE(edit->toPlainText() == QString("H ello"));
}
}

SECTION("indent whole lines") {
edit->setPlainText("1\n2\n3\n");
edit->moveCursor(QTextCursor::Down, QTextCursor::KeepAnchor);
edit->moveCursor(QTextCursor::Down, QTextCursor::KeepAnchor);
QTest::keyClick(edit, Qt::Key_Tab);
REQUIRE(edit->toPlainText() == QString(" 1\n 2\n3\n"));
}

SECTION("unindent whole lines") {
edit->setPlainText(" 1\n 2\n3\n");
edit->moveCursor(QTextCursor::Down, QTextCursor::KeepAnchor);
edit->moveCursor(QTextCursor::Down, QTextCursor::KeepAnchor);
QTest::keyClick(edit, Qt::Key_Backtab);
REQUIRE(edit->toPlainText() == QString("1\n2\n3\n"));
}
}
17 changes: 17 additions & 0 deletions tests/LinkSyntaxHighlighterTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "LinkSyntaxHighlighter.h"

#include <catch2/catch.hpp>

TEST_CASE("getLinkAt") {
QString text = "link to http://google.fr. The end.";
QUrl expected("http://google.fr");
SECTION("before link") {
REQUIRE(LinkSyntaxHighlighter::getLinkAt(text, 0) == QUrl());
}
SECTION("at link") {
REQUIRE(LinkSyntaxHighlighter::getLinkAt(text, 10) == expected);
}
SECTION("after link") {
REQUIRE(LinkSyntaxHighlighter::getLinkAt(text, 25) == QUrl());
}
}
Loading

0 comments on commit 3570f50

Please sign in to comment.