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 Sep 28, 2020
2 parents 0e9907b + e0934b1 commit 7097983
Show file tree
Hide file tree
Showing 23 changed files with 667 additions and 197 deletions.
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 1.2.91 - 2020-09-28

### Added
- You can now search inside your notes with the new search bar (Pavol Oresky)
- Move selected lines up and down (Aurelien Gateau)
- macOS dmg (Aurelien Gateau)
- Windows installer (Aurelien Gateau)

## Changed
- Reorganized context menu: added "Edit" and "View" submenus (Aurelien Gateau)

## 1.2.0 - 2019-05-11

### Added
Expand All @@ -26,16 +37,16 @@

## 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.

### 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.

## 1.0.0 - 2018-12-30

First release
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.17)
project(nanonote
VERSION 1.2.0
VERSION 1.2.91
DESCRIPTION "Minimalist note taking application for short-lived notes"
HOMEPAGE_URL "https://github.com/agateau/nanonote"
)
Expand Down
60 changes: 48 additions & 12 deletions docs/release-check-list.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,57 @@
# Pre-release

Check working tree is up to date and clean:

git checkout dev
git pull
git merge origin/master
git status
rlt-updateworkbranch

Update .ts files:

ninja -C $BDIR lupdate
git add src/translations
git commit -m "Update translations"

Update version:

rlt-version --set-next $version

Update CHANGELOG.md:

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

Bump version number in CMakeLists.txt
Tag pre-release

rlt-tag

Commit and push

Build packages:
git add .
git commit
git push
git push --tags

Smoke test binary packages generated by CI

Ask translators to update their translations

ci/docker-build-app
# Release

Smoke test binary packages
Check working tree is up to date and clean:

rlt-updateworkbranch

Update CHANGELOG.md:

r!rlt-changelog

Bump version number in CMakeLists.txt

Commit and push

git add .
git commit
git push

Smoke test binary packages generated by CI

- Test welcome text is OK
- Test screenshot matches
Expand All @@ -29,15 +63,17 @@ Merge dev in master:
git pull
git merge --no-ff origin/dev

Create "x.y.z" tag:
Create tag:

git tag -a x.y.z
rlt-tag

Push:

git push
git push --tags

Publish packages on GitHub
Publish generated packages on GitHub

# Spread

Write blog post
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(APPLIB_SRCS
TextEdit.cpp
WheelZoomExtension.cpp
SearchWidget.cpp
SearchForm.ui
SearchWidget.ui
)

qt5_add_resources(APPLIB_RESOURCES_SRCS app.qrc)
Expand Down
2 changes: 1 addition & 1 deletion src/IndentExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ IndentExtension::IndentExtension(TextEdit* textEdit)
mTextEdit->addAction(mUnindentAction);
}

void IndentExtension::aboutToShowContextMenu(QMenu* menu, const QPoint& /*pos*/) {
void IndentExtension::aboutToShowEditContextMenu(QMenu* menu, const QPoint& /*pos*/) {
menu->addAction(mIndentAction);
menu->addAction(mUnindentAction);
menu->addSeparator();
Expand Down
2 changes: 1 addition & 1 deletion src/IndentExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IndentExtension : public TextEditExtension {
public:
explicit IndentExtension(TextEdit* textEdit);

void aboutToShowContextMenu(QMenu* menu, const QPoint& pos) override;
void aboutToShowEditContextMenu(QMenu* menu, const QPoint& pos) override;
bool keyPress(QKeyEvent* event) override;

private:
Expand Down
37 changes: 18 additions & 19 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ MainWindowExtension::MainWindowExtension(MainWindow* window)

void MainWindowExtension::aboutToShowContextMenu(QMenu* menu, const QPoint&) {
menu->addAction(mWindow->mSearchAction);
menu->addSeparator();
menu->addAction(mWindow->mSettingsAction);
}

void MainWindowExtension::aboutToShowViewContextMenu(QMenu* menu, const QPoint&) {
menu->addAction(mWindow->mIncreaseFontAction);
menu->addAction(mWindow->mDecreaseFontAction);
menu->addAction(mWindow->mResetFontAction);
menu->addAction(mWindow->mAlwaysOnTopAction);
menu->addSeparator();
menu->addAction(mWindow->mSettingsAction);
menu->addAction(mWindow->mAlwaysOnTopAction);
}

//- MainWindow -----------------------------------------
Expand All @@ -54,6 +58,8 @@ MainWindow::MainWindow(QWidget* parent)
, mSettings(new Settings(this))
, mTextEdit(new TextEdit(this))
, mAutoSaveTimer(new QTimer(this))
, mSearchWidget(new SearchWidget(mTextEdit, this))
, mSearchToolBar(new QToolBar(this))
, mIncreaseFontAction(new QAction(this))
, mDecreaseFontAction(new QAction(this))
, mResetFontAction(new QAction(this))
Expand All @@ -65,9 +71,8 @@ MainWindow::MainWindow(QWidget* parent)

setCentralWidget(mTextEdit);

loadSearchWidget();

setupTextEdit();
setupSearchBar();
setupAutoSaveTimer();
setupActions();
loadNotes();
Expand Down Expand Up @@ -126,17 +131,16 @@ void MainWindow::setupActions() {
connect(mAlwaysOnTopAction, &QAction::toggled, this, &MainWindow::setAlwaysOnTop);
addAction(mAlwaysOnTopAction);

mSettingsAction->setText(tr("Settings..."));
mSettingsAction->setText(tr("Settings | About..."));
connect(mSettingsAction, &QAction::triggered, this, &MainWindow::showSettingsDialog);
addAction(mSettingsAction);

// Add find shortcut
mSearchAction->setText(tr("Find in text"));
mSearchAction->setText(tr("Find"));
mSearchAction->setShortcut(QKeySequence::Find);
connect(mSearchAction, &QAction::triggered, this, &MainWindow::showSearchBar);
addAction(mSearchAction);

mCloseSearchAction->setText(tr("Close search tab"));
mCloseSearchAction->setShortcut(Qt::Key_Escape);
connect(mCloseSearchAction, &QAction::triggered, this, &MainWindow::hideSearchBar);
addAction(mCloseSearchAction);
Expand Down Expand Up @@ -278,18 +282,13 @@ void MainWindow::showSettingsDialog() {
mSettingsDialog->show();
}

void MainWindow::loadSearchWidget() {
if (!mSearchWidget) {
mSearchWidget = new SearchWidget(mTextEdit, this);
connect(mSearchWidget, &SearchWidget::closeClicked, this, &MainWindow::hideSearchBar);
}
if (!mSearchToolBar) {
mSearchToolBar = new QToolBar(this);
mSearchToolBar->addWidget(mSearchWidget);
mSearchToolBar->setVisible(false);
mSearchToolBar->setMovable(false);
addToolBar(Qt::BottomToolBarArea, mSearchToolBar);
}
void MainWindow::setupSearchBar() {
connect(mSearchWidget, &SearchWidget::closeClicked, this, &MainWindow::hideSearchBar);

mSearchToolBar->addWidget(mSearchWidget);
mSearchToolBar->setVisible(false);
mSearchToolBar->setMovable(false);
addToolBar(Qt::BottomToolBarArea, mSearchToolBar);
}

void MainWindow::showSearchBar() {
Expand Down
30 changes: 16 additions & 14 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MainWindowExtension : public TextEditExtension {
explicit MainWindowExtension(MainWindow* window);

void aboutToShowContextMenu(QMenu* menu, const QPoint& /*pos*/) override;
void aboutToShowViewContextMenu(QMenu* menu, const QPoint& /*pos*/) override;

private:
MainWindow* mWindow;
Expand All @@ -37,6 +38,7 @@ class MainWindow : public QMainWindow {

private:
void setupTextEdit();
void setupSearchBar();
void setupAutoSaveTimer();
void setupActions();
void loadNotes();
Expand All @@ -47,23 +49,23 @@ class MainWindow : public QMainWindow {
void resetFontSize();
void setAlwaysOnTop(bool onTop);
void showSettingsDialog();
void loadSearchWidget();
void showSearchBar();
void hideSearchBar();

Settings* mSettings;
TextEdit* mTextEdit;
QTimer* mAutoSaveTimer;
SearchWidget* mSearchWidget = nullptr;
QToolBar* mSearchToolBar = nullptr;

QAction* mIncreaseFontAction;
QAction* mDecreaseFontAction;
QAction* mResetFontAction;
QAction* mAlwaysOnTopAction;
QAction* mSettingsAction;
QAction* mSearchAction;
QAction* mCloseSearchAction = nullptr;
Settings* const mSettings;
TextEdit* const mTextEdit;
QTimer* const mAutoSaveTimer;
SearchWidget* const mSearchWidget;
QToolBar* const mSearchToolBar;

QAction* const mIncreaseFontAction;
QAction* const mDecreaseFontAction;
QAction* const mResetFontAction;
QAction* const mAlwaysOnTopAction;
QAction* const mSettingsAction;
QAction* const mSearchAction;
QAction* const mCloseSearchAction;

QPointer<SettingsDialog> mSettingsDialog;

friend class MainWindowExtension;
Expand Down
68 changes: 49 additions & 19 deletions src/MoveLinesExtension.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
#include "MoveLinesExtension.h"

#include <QAction>
#include <QDebug>
#include <QMenu>
#include <QTextBlock>

static constexpr Qt::KeyboardModifiers MODIFIERS = Qt::ShiftModifier | Qt::AltModifier;
MoveLinesExtension::MoveLinesExtension(TextEdit* textEdit)
: TextEditExtension(textEdit)
, mMoveUpAction(std::make_unique<QAction>())
, mMoveDownAction(std::make_unique<QAction>()) {
mMoveUpAction->setText(tr("Move selected lines up"));
mMoveUpAction->setShortcut(Qt::SHIFT | Qt::ALT | Qt::Key_Up);
connect(mMoveUpAction.get(), &QAction::triggered, this, &MoveLinesExtension::moveUp);
mTextEdit->addAction(mMoveUpAction.get());

MoveLinesExtension::MoveLinesExtension(TextEdit* textEdit) : TextEditExtension(textEdit) {
mMoveDownAction->setText(tr("Move selected lines down"));
mMoveDownAction->setShortcut(Qt::SHIFT | Qt::ALT | Qt::Key_Down);
connect(mMoveDownAction.get(), &QAction::triggered, this, &MoveLinesExtension::moveDown);
mTextEdit->addAction(mMoveDownAction.get());
}

bool MoveLinesExtension::keyPress(QKeyEvent* event) {
if (event->modifiers() == MODIFIERS) {
if (event->key() == Qt::Key_Down) {
moveSelectedLines(1);
return true;
} else if (event->key() == Qt::Key_Up) {
moveSelectedLines(-1);
return true;
}
}
return false;
MoveLinesExtension::~MoveLinesExtension() {
}

void MoveLinesExtension::aboutToShowEditContextMenu(QMenu* menu, const QPoint& /*pos*/) {
menu->addAction(mMoveUpAction.get());
menu->addAction(mMoveDownAction.get());
}

void MoveLinesExtension::moveUp() {
moveSelectedLines(-1);
}

void MoveLinesExtension::moveDown() {
moveSelectedLines(1);
}

/**
* Add a final \\n if needed. Returns true if it added one.
*/
static bool addFinalNewLine(TextEdit* textEdit) {
static bool addFinalNewLine(TextEdit* textEdit, QTextCursor* cursor) {
if (textEdit->document()->lastBlock().text().isEmpty()) {
return false;
}
// Use our own cursor to avoid altering the current one
auto cursor = textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
cursor.insertBlock();

// The `cursor` from `moveSelectedLines()` must stay at the same position. A previous version of
// this function created its own cursor using QTextEdit::textCursor(), but if the cursor is at
// the very end of the document, then `moveSelectedLines()` cursor is moved when we insert the
// \n. I assue this is because the cursor is considered to be *after* the insertion position
// of the \n, so Qt maintains its position.
// To avoid that, we save the cursor state manually before inserting the \n, and restore the
// state before leaving this function.
int oldStart = cursor->selectionStart();
int oldEnd = cursor->selectionEnd();
if (oldStart == cursor->position()) {
std::swap(oldStart, oldEnd);
}

cursor->movePosition(QTextCursor::End);
cursor->insertBlock();

cursor->setPosition(oldStart);
cursor->setPosition(oldEnd, QTextCursor::KeepAnchor);
return true;
}

Expand All @@ -48,7 +78,7 @@ void MoveLinesExtension::moveSelectedLines(int delta) {

// To avoid dealing with the special-case of the last line not ending with
// a \n, we add one if there is none and remove it at the end
bool addedFinalNewLine = addFinalNewLine(mTextEdit);
bool addedFinalNewLine = addFinalNewLine(mTextEdit, &cursor);

// Find start and end of lines to move
QTextBlock startBlock, endBlock;
Expand Down
Loading

0 comments on commit 7097983

Please sign in to comment.