Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds a delete_all_highlights #953

Open
wants to merge 16 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pdf_viewer/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,20 @@ bool DatabaseManager::delete_highlight(const std::string& uuid) {
error_message);
}

bool DatabaseManager::delete_all_current_doc_highlights(const std::string& doc_checksum) {
std::wstringstream ss;
std::wstring threshold = QString::number(HIGHLIGHT_DELETE_THRESHOLD).toStdWString();
ss << "DELETE FROM highlights where document_path='" << esc(doc_checksum) << "';";

char* error_message = nullptr;

int error_code = sqlite3_exec(global_db, utf8_encode(ss.str()).c_str(), null_callback, 0, &error_message);
return handle_error(
"delete_all_current_doc_highlights",
error_code,
error_message);
}

bool DatabaseManager::update_mark(const std::string& document_path, char symbol, float offset_y, std::optional<float> offset_x, std::optional<float> zoom_level) {

std::wstringstream ss;
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DatabaseManager {
bool select_global_mark(char symbol, std::vector<std::pair<std::string, float>>& out_result);
bool delete_opened_book(const std::string& book_path);
bool delete_highlight(const std::string& uuid);
bool delete_all_current_doc_highlights(const std::string& doc_checksum);
bool select_highlight(const std::string& checksum, std::vector<Highlight>& out_result);
bool select_highlight_with_type(const std::string& checksum, char type, std::vector<Highlight>& out_result);
bool set_actual_document_name(const std::string& checksum, const std::wstring& actual_name);
Expand Down
9 changes: 8 additions & 1 deletion pdf_viewer/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ void Document::fill_highlight_rects(fz_context* ctx, fz_document* doc_) {
}
}


std::string Document::add_highlight(const std::wstring& annot, AbsoluteDocumentPos selection_begin, AbsoluteDocumentPos selection_end, char type) {
std::deque<AbsoluteRect> selected_characters;
std::vector<AbsoluteRect> merged_rects;
Expand Down Expand Up @@ -492,6 +491,14 @@ void Document::delete_highlight(Highlight hl) {
}
}

void Document::clear_all_current_document_highlights() {
if (user_confirms_to_prompt(L"This will remove all the highlights in this document. Do you wish to proceed?")) {
db_manager->delete_all_current_doc_highlights(get_checksum());
highlights.clear();
is_annotations_dirty = true;
}
}

std::optional<Portal> Document::find_closest_portal(float to_offset_y, int* index) {
int min_index = argminf<Portal>(portals, [to_offset_y](Portal l) {
return abs(l.src_offset_y - to_offset_y);
Expand Down
2 changes: 2 additions & 0 deletions pdf_viewer/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class Document {
void delete_highlight_with_index(int index);
void delete_bookmark_with_index(int index);
void delete_highlight(Highlight hl);
void delete_all_current_doc_highlights();
void clear_all_current_document_highlights();
int get_bookmark_index_at_pos(AbsoluteDocumentPos abspos);
int get_portal_index_at_pos(AbsoluteDocumentPos abspos);
bool should_render_pdf_annotations();
Expand Down
5 changes: 5 additions & 0 deletions pdf_viewer/document_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ void DocumentView::delete_highlight(Highlight hl) {
current_document->delete_highlight(hl);
}

// void DocumentView::delete_all_current_doc_highlights() {
// current_document->delete_all_current_doc_highlights();
// }


void DocumentView::delete_closest_bookmark_to_offset(float offset) {
current_document->delete_closest_bookmark(offset);
}
Expand Down
469 changes: 469 additions & 0 deletions pdf_viewer/input.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6211,6 +6211,10 @@ void MainWidget::handle_toggle_typing_mode() {
}
}

void MainWidget::handle_clear_all_current_document_highlights() {
doc()->clear_all_current_document_highlights();
}

void MainWidget::handle_delete_highlight_under_cursor() {
QPoint mouse_pos = mapFromGlobal(cursor_pos());
WindowPos window_pos = WindowPos{ mouse_pos.x(), mouse_pos.y() };
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/main_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class MainWidget : public QMainWindow {
void handle_overview_to_portal();
void handle_toggle_typing_mode();
void handle_delete_highlight_under_cursor();
void handle_clear_all_current_document_highlights();
void handle_delete_selected_highlight();
void handle_delete_selected_bookmark();
void handle_start_reading();
Expand Down
11 changes: 11 additions & 0 deletions pdf_viewer/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ void show_error_message(const std::wstring& error_message) {
msgBox.exec();
}

bool user_confirms_to_prompt(const std::wstring& prompt_message) {
QMessageBox msgBox;
int choice;
msgBox.setText(QString::fromStdWString(prompt_message));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
choice = msgBox.exec();
return (choice == QMessageBox::Ok);
}


std::wstring utf8_decode(const std::string& encoded_str) {
std::wstring res;
utf8::utf8to32(encoded_str.begin(), encoded_str.end(), std::back_inserter(res));
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void copy_to_clipboard(const std::wstring& text, bool selection = false);
void install_app(const char* argv0);
int get_f_key(std::wstring name);
void show_error_message(const std::wstring& error_message);
bool user_confirms_to_prompt(const std::wstring& prompt_message);
std::wstring utf8_decode(const std::string& encoded_str);
std::string utf8_encode(const std::wstring& decoded_str);
// is the character a right to left character
Expand Down