diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index a0b56ce1..68eac6bc 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -29,5 +29,5 @@ jobs: flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics - name: Coding Style Violations run: | - flake8 novelwriter --count --max-line-length=99 --ignore E221,E226,E228,E241 --show-source --statistics - flake8 tests --count --max-line-length=99 --ignore E221,E226,E228,E241 --show-source --statistics + flake8 novelwriter --count --max-line-length=99 --ignore E133,E221,E226,E228,E241,W503 --show-source --statistics + flake8 tests --count --max-line-length=99 --ignore E133,E221,E226,E228,E241,W503 --show-source --statistics diff --git a/.github/workflows/test_linux.yml b/.github/workflows/test_linux.yml index b95dd745..5cac8e23 100644 --- a/.github/workflows/test_linux.yml +++ b/.github/workflows/test_linux.yml @@ -14,7 +14,7 @@ jobs: testLinux: strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10"] runs-on: ubuntu-latest steps: - name: Python Setup diff --git a/.github/workflows/test_mac.yml b/.github/workflows/test_mac.yml index a011b51e..ccb1c0c1 100644 --- a/.github/workflows/test_mac.yml +++ b/.github/workflows/test_mac.yml @@ -17,7 +17,7 @@ jobs: - name: Python Setup uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: "3.10" architecture: x64 - name: Install Packages run: | diff --git a/.github/workflows/test_win.yml b/.github/workflows/test_win.yml index b41ccbf5..a976026a 100644 --- a/.github/workflows/test_win.yml +++ b/.github/workflows/test_win.yml @@ -17,7 +17,7 @@ jobs: - name: Python Setup uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: "3.10" architecture: x64 - name: Checkout Source uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3bc08f..16bb1b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,94 @@ # novelWriter Changelog +## Version 1.7 Beta 1 [2022-05-17] + +### Release Notes + +This is a beta release of the next release version, and is intended for testing purposes. Please be +careful when using this version on live writing projects, and make sure you take frequent backups. + +Please check the changelog for an overview of changes. The full release notes will be added to the +final release. + +### Detailed Changelog + +**Features** + +* A simple tool to add Lorem Ipsum placeholder text has been added to the Insert menu. PR #1028. +* Status and Importance flags can now be reorganised in Project Settings. Issue #1035. PR #1040. +* It is now possible to create multiple Root Folders of the same kind. This makes it possible to + add multiple Novel root folders in a project, for instance. Issue #967. PR #1031. +* All documents can now be dragged and dropped anywhere in the project tree. The document layout + may be converted in the process. PR #1031. +* Documents in the project tree can now have other documents as child documents. Issue #1002. + PR #1047. +* Folders in the project tree that are not empty, can now be moved to trash. PR #1048. +* Empty folders are deleted on request, and not moved to trash. Issue #1052. PR #1055. + +**User Interface** + +* The tabs under the project tree and to the right of the main window have been replaced with a + toolbar on the left hand side. The toolbar has a set of buttons to change view between Project, + Novel and Outline. The three buttons that were available under the project tree have been moved + to the bottom of the new toolbar. Issue #1056. PR #1057. +* When a document changes from a project document to a note, and back again, the Status flag + setting is preserved. Previously, the Importance setting would overwrite it during the + conversion. PR #1030. +* Item labels, Status labels, and other labels on the GUI are now run through a "simplify" function + before being accepted. This functions strips out all whitespaces and consecutive whitespaces and + replace them with single plain whitespaces. This is a safer format to store in XML, and also + makes sure there aren't invisible characters floating around in the labels. PR #1038. +* Due to the changes to how drag and drop works, there are no longer any restrictions on folders + and documents. Only root folders remain restricted in terms of moving. Root folders can only be + reordered with the Move Up and Move Down commands. PR #1047. +* The label for the highlighting of redundant spaces in the Preferences dialog has been updated to + better reflect what it does. Issue #1043. PR #1046. +* The New Project Wizard will now try to check if the path selected for the new project can + actually be used before letting the user proceed to the next page. Issue #1058. PR #1062. + +**Internationalisation** + +* Dutch translations have been added by Martijn van der Kleijn (@mvdkleijn). PR #1027. + +**Functionality** + +* Documents that are missing in the project index when a project is opened are automatically + re-indexed. This also handles cases where the cached index is missing. PR #1039. + +**Installation and Packaging** + +* Python 3.6 is no longer supported. PR #1004. +* Ubuntu 18.04 packages will no longer be released, due to dropping Python 3.6. Issue #1005. + PR #1014. + +**Project File Format** + +* The item nodes in the content section of the main project XML file have been compacted. It now + consists of a main item node and meta and a name node. All settings have been made attributes of + one of these three nodes, except the item label which is the text value of the name node. The + file format version has been bumped to 1.4. Issue #995. PR #993. +* Both Importance and Status flag values are now saved to the project file. This means if a + document changes layout, the value is no longer lost. PR #1030. + +**Code Improvements** + +* The linting settings have been updated to select between mutually exclusive options in + pycodestyle. PR #1014. +* The Tokenizer class has been converted to an abstract base class. PR #1026. +* The class handling Status and Importance flags has been completely rewritten. The flags are now + handled using a unique random key as reference rather than relying on the text of the label + itself. This makes it a lot easier to rename them as there is no need to update project items. + PR #1034. +* Many of the decisions regarding where items are allowed to belong has been delegated to the + NWItem class that holds the item. Some is also handled by the NWTree class that holds the project + tree. A new maintenance function in the NWTree class will also ensure that the meta data of an + item is correct and up to date. This is especially important after an item has been moved, but is + also checked when items are initially loaded. PRs #1031 and #1054. +* Item handles are now generated using the standard library random number generator. The new + handles have the same format as the old algorithm, so they are compatible. PR #1044. + +---- + ## Version 1.6.4 [2022-09-29] ### Release Notes diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index f64bc973..28de89d7 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,75 +2,131 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment -include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission +* Publishing others' private information, such as a physical or email address, + without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project leader at issues (at) novelwriter.io. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +reported to the community leaders responsible for enforcement at issues (at) +novelwriter.io. All complaints will be reviewed and investigated promptly and +fairly. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/CREDITS.md b/CREDITS.md index 994768ac..469e4c40 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -11,11 +11,14 @@ ## Translations +The default language is English (UK) with English (US) as an option. + +* Dutch: Martijn van der Kleijn (@mvdkleijn) * French: Jan Lüdke (@jyhelle) +* Latin American Spanish: Tommy Marplatt (@tmarplatt) * Norwegian: Veronica Berglyd Olsen (@vkbo) * Portuguese: Bruno Meneguello (@bkmeneguello) * Simplified Chinese: Qianzhi Long (@longqzh) -* Latin American Spanish: Tommy Marplatt (@tmarplatt) ## Libraries @@ -31,7 +34,7 @@ The following libraries are dependencies of novelWriter: Some of the assets bundled with novelWriter were adapted from the following sources: -* Typicons icons by Stephen Hutchings (CC BY-SA 4.0) +* Typicons icons by [Stephen Hutchings](https://github.com/stephenhutchings/typicons.font) (CC BY-SA 4.0) * Tomorrow syntax themes by Chris Kempson (MIT License) * Owl syntax themes by Sarah Drasner (MIT License) * Solarized themes by Ethan Schoonover, added by @nullbasis (MIT License) diff --git a/README.md b/README.md index 36aa11d2..7b0a9965 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,13 @@ The full documentation is available at The full credits are listed in [CREDITS.md](https://github.com/vkbo/novelWriter/blob/main/CREDITS.md). +You can also follow novelWriter on Mastodon at [fosstodon.org/@novelwriter](https://fosstodon.org/@novelwriter). + ## Implementation -The application is written in Python 3 (3.6+) using Qt5 and PyQt5 (5.3+). It is developed on Linux, -but should in principle work fine on other operating systems as well as long as dependencies are -met. It is regularly tested on Debian and Ubuntu Linux, Windows, and macOS. +The application is written with Python 3 (3.7+) using Qt5 and PyQt5 (5.3+). It is developed on +Linux, but should in principle work fine on other operating systems as well as long as dependencies +are met. It is regularly tested on Debian and Ubuntu Linux, Windows, and macOS. ## Installation diff --git a/docs/source/index.rst b/docs/source/index.rst index 0191425b..20c39895 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -39,11 +39,13 @@ too. novelWriter can be run directly from the Python source, installed from the * Website: https://novelwriter.io * Documentation: https://novelwriter.readthedocs.io +* Internationalisation: https://crowdin.com/project/novelwriter * Source Code: https://github.com/vkbo/novelWriter * Source Releases: https://github.com/vkbo/novelWriter/releases * Issue Tracker: https://github.com/vkbo/novelWriter/issues * Feature Discussions: https://github.com/vkbo/novelWriter/discussions * PyPi Project: https://pypi.org/project/novelWriter +* Social Media: https://fosstodon.org/@novelwriter .. toctree:: :maxdepth: 1 diff --git a/docs/source/int_started.rst b/docs/source/int_started.rst index f398a8b6..5b5fff70 100644 --- a/docs/source/int_started.rst +++ b/docs/source/int_started.rst @@ -115,7 +115,7 @@ Windows ------- First, make sure you have Python installed on your system. If you don't, you can download it from -`python.org`_. Python 3.6 or higher is required, but it is recommended that you install the latest +`python.org`_. Python 3.7 or higher is required, but it is recommended that you install the latest version. Make sure you select the "Add Python to PATH" option during installation, otherwise the ``python`` diff --git a/docs/source/usage_projectformat.rst b/docs/source/usage_projectformat.rst index ea0b55b5..6a7c4c8b 100644 --- a/docs/source/usage_projectformat.rst +++ b/docs/source/usage_projectformat.rst @@ -11,13 +11,32 @@ changes require minor actions from the user. The key changes in the formats are listed below, as well as the user actions required where applicable. +.. caution:: + + When you update a project from one format version to the next, the project can no longer be + opened by a version of novelWriter prior to the version where the new file format was + introduced. You will get a notification about any updates to your project file format and will + have the option to decline the upgrade. + + +.. _a_prjfmt_1_4: + +Format 1.4 Changes +================== + +This project format was introduced in novelWriter version 1.7. + +This format changes the way project items (folders, documents and notes) are stored. It is a more +compact format that is simpler and faster to parse, and easier to extend. The conversion is done +automatically the first time a project is loaded. No user action is required. + .. _a_prjfmt_1_3: Format 1.3 Changes ================== -This project format vas introduces in novelWriter version 1.5. +This project format was introduced in novelWriter version 1.5. With this format, the number of document layouts was reduced from 8 to 2. The conversion of document layouts is performed automatically when the project is opened. @@ -55,7 +74,7 @@ should be used only a few places in any given project. These are as follows: Format 1.2 Changes ================== -This project format was introduces in novelWriter version 0.10. +This project format was introduced in novelWriter version 0.10. With this format, the way auto-replace entries were stored in the main project XML file changed. Opening an old project automatically converts the storage format up to and including version 1.1.1. @@ -69,7 +88,7 @@ auto-replace is not being used, can still be opened in novelWriter as of version Format 1.1 Changes ================== -This project format was introduces in novelWriter version 0.7. +This project format was introduced in novelWriter version 0.7. With this format, the ``content`` folder was introduced in the project storage. Previously, all novelWriter documents were saved in a series of folders numbered from ``data_0`` to ``data_f``. diff --git a/docs/source/usage_shortcuts.rst b/docs/source/usage_shortcuts.rst index fea65c8c..e9e7bb36 100644 --- a/docs/source/usage_shortcuts.rst +++ b/docs/source/usage_shortcuts.rst @@ -25,7 +25,7 @@ The main shorcuts are as follows: ":kbd:`Alt`:kbd:`4`", "Switch focus to outline view. On Windows, use :kbd:`Ctrl`:kbd:`Alt`:kbd:`4`." ":kbd:`Alt`:kbd:`Left`", "Move backward in the view history of the document viewer." ":kbd:`Alt`:kbd:`Right`", "Move forward in the view history of the document viewer." - ":kbd:`Ctrl`:kbd:`.`", "Open menu to correct word under cursor." + ":kbd:`Ctrl`:kbd:`.`", "Open the context menu in the project tree or the document editor." ":kbd:`Ctrl`:kbd:`,`", "Open the :guilabel:`Preferences` dialog." ":kbd:`Ctrl`:kbd:`/`", "Toggle block format as comment." ":kbd:`Ctrl`:kbd:`0`", "Remove block formatting for block under cursor." @@ -42,13 +42,12 @@ The main shorcuts are as follows: ":kbd:`Ctrl`:kbd:`B`", "Format selected text, or word under cursor, with strong emphasis (bold)." ":kbd:`Ctrl`:kbd:`C`", "Copy selected text to clipboard." ":kbd:`Ctrl`:kbd:`D`", "Strikethrough selected text, or word under cursor." - ":kbd:`Ctrl`:kbd:`E`", "If in the project tree, edit a document or folder settings." ":kbd:`Ctrl`:kbd:`F`", "Open the search bar and search for the selected word, if any is selected." ":kbd:`Ctrl`:kbd:`G`", "Find next occurrence of search word in current document." ":kbd:`Ctrl`:kbd:`H`", "Open the search and replace bar and search for the selected word, if any is selected. (On Mac, this is :kbd:`Cmd`:kbd:`=`.)" ":kbd:`Ctrl`:kbd:`I`", "Format selected text, or word under cursor, with emphasis (italic)." ":kbd:`Ctrl`:kbd:`K`", "Activate the insert commands. The commands are listed in :ref:`a_kb_ins`." - ":kbd:`Ctrl`:kbd:`N`", "Create new document." + ":kbd:`Ctrl`:kbd:`N`", "Create new project item." ":kbd:`Ctrl`:kbd:`O`", "Open selected document." ":kbd:`Ctrl`:kbd:`Q`", "Exit novelWriter." ":kbd:`Ctrl`:kbd:`R`", "If in the project tree, open a document for viewing. If the editor has focus, open current document for viewing." @@ -59,7 +58,6 @@ The main shorcuts are as follows: ":kbd:`Ctrl`:kbd:`Y`", "Redo latest undo." ":kbd:`Ctrl`:kbd:`Z`", "Undo latest changes." ":kbd:`Ctrl`:kbd:`F7`", "Toggle spell checking." - ":kbd:`Ctrl`:kbd:`F10`", "Toggle automatic updating of project outline." ":kbd:`Ctrl`:kbd:`Up`", "Move item one step up in the project tree." ":kbd:`Ctrl`:kbd:`Down`", "Move item one step down in the project tree." ":kbd:`Ctrl`:kbd:`Del`", "Delete next word in editor." @@ -73,7 +71,6 @@ The main shorcuts are as follows: ":kbd:`Ctrl`:kbd:`Shift`:kbd:`A`", "Select all text in current paragraph." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`G`", "Find previous occurrence of search word in current document." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`I`", "Import text to the current document from a text file." - ":kbd:`Ctrl`:kbd:`Shift`:kbd:`N`", "Create new folder." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`O`", "Open a project." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`R`", "Close the document viewer." ":kbd:`Ctrl`:kbd:`Shift`:kbd:`S`", "Save the current project." @@ -88,7 +85,6 @@ The main shorcuts are as follows: ":kbd:`F7`", "Re-run spell checker." ":kbd:`F8`", "Activate :guilabel:`Focus Mode`, hiding the project tree and document viewer." ":kbd:`F9`", "Re-build the project index." - ":kbd:`F10`", "Re-build the project outline." ":kbd:`F11`", "Activate full screen mode." ":kbd:`Shift`:kbd:`F1`", "Open the local user manual (PDF) if it is available." ":kbd:`Shift`:kbd:`F3`", "Find previous occurrence of search word in current document." diff --git a/i18n/README.md b/i18n/README.md index 27486cf9..b2dd8cc9 100644 --- a/i18n/README.md +++ b/i18n/README.md @@ -2,6 +2,7 @@ The maintenance of translations has been moved to the Crowdin service. The translation strings can be edited there at the [novelWriter project page](https://crowdin.com/project/novelwriter). +However, please read the Translation Guidelines section below. You can still use the manual approach listed below, and then upload the file through the website's interface. The translation strings for that language will then be updated and queued for approval. @@ -11,6 +12,22 @@ To verify a language file translated through the Crowdin tool, download and extr [Generate an Updated Translation File](#generate-an-updated-translation-file) below. +# Translation Guidelines + +When contributing translations, keep the following things in mind. + +* For descriptive labels and dialog boxes, make sure you do _not_ change the meaning of the text + when you translate it from English. The user must receive the same instructions or information + regardless of language. This is improtant, otherwise the documentation will be inconsistent with + the user interface and it will become a lot more difficult to handle user issues and questions. +* If you think a label or description is misleading or incomplete, please file an issue report. The + correct way to handle such changes is to change the text in the code first, which will then be + forwarded to _all_ translators such that the GUI is consistent across all languages. +* For very short labels, like button labels. it may be fine to replace the word with a similar + word, but only as long as the user understands what it is supposed to do. Some buttons and tabs + have limited space. If necessary, it is OK to use abbreviations. + + # Direct Approach Using Qt Linguist Here you will find instructions for translating novelWriter to a new language directly using Qt diff --git a/i18n/nw_base.ts b/i18n/nw_base.ts index 4eaa8252..8d7e2940 100644 --- a/i18n/nw_base.ts +++ b/i18n/nw_base.ts @@ -77,259 +77,259 @@ Constant - - - + + + None - + Novel - - + + Plot - - + + Characters - - + + Locations - - + + Timeline - - + + Objects - - + + Entities - - + + Custom - + Archive - + Trash - - + + Novel Document - - + + Project Note - + Root Folder - + Folder - + Novel Title Page - + Novel Chapter - + Novel Scene - + Tag - + Point of View - - + + Focus - + Title - + Level - + Document - + Line - + Chars - + Words - + Pars - + POV - + Synopsis - + Straight single quotation mark - + Straight double quotation mark - + Left single quotation mark - + Right single quotation mark - + Single low-9 quotation mark - + Single high-reversed-9 quotation mark - + Left double quotation mark - + Right double quotation mark - + Double low-9 quotation mark - + Double high-reversed-9 quotation mark - + Double low-reversed-9 quotation mark - + Single left-pointing angle quotation mark - + Single right-pointing angle quotation mark - + Double left-pointing angle quotation mark - + Double right-pointing angle quotation mark - + Left corner bracket - + Right corner bracket - + Left white corner bracket - + Right white corner bracket @@ -353,9 +353,9 @@ - - - + + + Licence @@ -411,31 +411,31 @@ - + Theme: {0} - - - - - Author - - + Author + + + + + + Credit - + Icons: {0} - + Syntax: {0} @@ -718,62 +718,62 @@ - + Open Document - + Flat Open Document - + Plain HTML - + novelWriter Markdown - + Standard Markdown - + GitHub Markdown - + JSON + novelWriter HTML - + JSON + novelWriter Markdown - + PDF - + Save Document As - + {0} file successfully written to: - + Failed to write {0} file. {1} @@ -781,17 +781,17 @@ GuiBuildNovelDocView - + This area will show the content of the document to be exported or printed. Press the "Build Preview" button to generate content. - + Unknown - + Build Time: @@ -799,32 +799,32 @@ GuiDocEditFooter - + Status - + Line: {0} ({1}) - + Words: {0} ({1}) - + Document size is {0} bytes - + Words: {0} selected - + Character count: {0} @@ -832,22 +832,22 @@ GuiDocEditHeader - + Edit document meta - + Search document - + Toggle Focus Mode - + Close the document @@ -855,58 +855,58 @@ GuiDocEditSearch - - + + Search - + Replace - + Case Sensitive - + Whole Words Only - + RegEx Mode - + Loop Search - + Search Next File - + Preserve Case - + Close Search - + Find in current document - + Find and replace in current document @@ -914,117 +914,117 @@ GuiDocEditor - + The document you are trying to open is too big. The document size is {0} MB. The maximum size allowed is {1} MB. - + Opened Document: {0} - + The text you are trying to add is too big. The text size is {0} MB. The maximum size allowed is {1} MB. - + File Changed on Disk - + This document has been changed outside of novelWriter while it was open. Overwrite the file on disk? - + Could not save document. - + Saved Document: {0} - + Spell checking requires the package PyEnchant. It does not appear to be installed. - + Spell check complete - + File Location - + The currently open file is saved in: - + The document has grown too big and you cannot add more text to it. The maximum size of a single novelWriter document is {0} MB. - + Follow Tag - + Cut - + Copy - + Paste - + Select All - + Select Word - + Select Paragraph - + Spelling Suggestion(s) - + No Suggestions - + Add Word to Dictionary - + Please select some text before calling replace quotes. @@ -1067,12 +1067,12 @@ - + Could not save document. - + Element selected in the project tree must be a folder. @@ -1080,83 +1080,78 @@ GuiDocSplit - - + + Split Document - + Document Headers - + Select the maximum level to split into files. - + Split on Header Level 1 (Title) - + Split up to Header Level 2 (Chapter) - + Split up to Header Level 3 (Scene) - + Split up to Header Level 4 (Section) - + No source document selected. Nothing to do. - + Could not parse source document. - + Failed to open document file. - + No headers found. Nothing to do. - - Cannot add new folder for the document split. Maximum folder depth has been reached. Please move the file to another level in the project tree. - - - - + The document will be split into {0} file(s) in a new folder. The original document will remain intact. - + Continue with the splitting process? - + Could not save document. - + Element selected in the project tree must be a file. @@ -1164,42 +1159,42 @@ GuiDocViewFooter - + Show/hide the references panel - + Activate to freeze the content of the references panel when changing document - + Show comments - + Show synopsis comments - + References - + Sticky - + Comments - + Synopsis @@ -1207,22 +1202,22 @@ GuiDocViewHeader - + Go backward - + Go forward - + Reload the document - + Close the document @@ -1283,17 +1278,17 @@ - + Characters - + Words - + Paragraphs @@ -1306,237 +1301,230 @@ - + Include when building project - + Label - + Status - + Layout + + GuiLipsum + + + Insert Placeholder Text + + + + + Insert Lorem Ipsum Text + + + + + Number of paragraphs + + + + + Randomise order + + + + + Insert + + + GuiMain - - Project - - - - - Novel - - - - - Project Details - - - - - Writing Statistics - - - - - Project Settings - - - - - Editor - - - - - Outline - - - - + You are running an untested development version of novelWriter. Please be careful when working on a live project and make sure you take regular backups. - + novelWriter is ready ... - + Cannot create a new project when another project is open. - + A project already exists in that location. Please choose another folder. - + New project created ... - + Close Project - + Close the current project? - - + + Changes are saved automatically. - + Backup Project - + Backup the current project? - + The project was locked by the computer '{0}' ({1} {2}), last active on {3}. - + Project Locked - + The project is already open by another instance of novelWriter, and is therefore locked. Override lock and continue anyway? - + Note: If the program or the computer previously crashed, the lock can safely be overridden. However, overriding it is not recommended if the project is open in another instance of novelWriter. Doing so may corrupt the project. - + The project index is outdated or broken. Rebuilding index. - + Text files ({0}) - + Markdown files ({0}) - + novelWriter files ({0}) - + All files ({0}) - + Import File - + Could not read file. The file must be an existing text file. - + Please open a document to import the text file into. - + Import Document - + Importing the file will overwrite the current content of the document. Do you want to proceed? - - + + Indexing: '{0}' - + Unknown item - + Indexing completed in {0} ms - + The project index has been successfully rebuilt. - + Information - + Warning - + Error - + This is a bug! - + Internal Error - + Exit - + Do you want to exit novelWriter? @@ -1544,677 +1532,682 @@ GuiMainMenu - + &Project - + New Project - + Open Project - + Save Project - + Close Project - + Project Settings - + Project Details - + Create Root Folder - + Novel Root - + Plot Root - + Character Root - + Location Root - + Timeline Root - + Object Root - + Entity Root - + Custom Root - + Archive Root - + Create Folder - + Edit Item - + Delete Item - + Move Item Up - + Move Item Down - + Undo Last Move - + Empty Trash - + Exit - + &Document - + New Document - + Open Document - + Save Document - + Close Document - + View Document - + Close Document View - + Show File Details - + Import Text from File - + Merge Folder to Document - + Split Document to Folder - + &Edit - + Undo - + Redo - + Cut - + Copy - + Paste - + Select All - + Select Paragraph - + &View - + Go to Project Tree - + Go to Document Editor - + Go to Document Viewer - + Go to Outline - + Navigate Backward - + Navigate Forward - + Focus Mode - + Full Screen Mode - + &Insert - + Dashes - + Short Dash - + Long Dash - + Horizontal Bar - + Figure Dash - + Quote Marks - + Left Single Quote - + Right Single Quote - + Left Double Quote - + Right Double Quote - + Alternative Apostrophe - + General Punctuation - + Ellipsis - + Prime - + Double Prime - + White Spaces - + Non-Breaking Space - + Thin Space - + Thin Non-Breaking Space - + Other Symbols - + List Bullet - + Hyphen Bullet - + Flower Mark - + Per Mille - + Degree Symbol - + Minus Sign - + Times Sign - + Division Sign - + Tags and References - + Page Break and Space - + Page Break - + Vertical Space (Single) - + Vertical Space (Multi) - + + Placeholder Text + + + + &Format - + Emphasis - + Strong Emphasis - + Strikethrough - + Wrap Double Quotes - + Wrap Single Quotes - + Header 1 (Partition) - + Header 2 (Chapter) - + Header 3 (Scene) - + Header 4 (Section) - + Novel Title - + Unnumbered Chapter - + Align Left - + Align Centre - + Align Right - + Indent Left - + Indent Right - + Toggle Comment - + Remove Block Format - + Convert Single Quotes - + Convert Double Quotes - + Remove In-Paragraph Breaks - + &Search - + Find - + Replace - + Find Next - + Find Previous - + Replace Next - + &Tools - + Check Spelling - + Re-Run Spell Check - + Project Word List - + Rebuild Index - + Rebuild Outline - + Auto-Update Outline - + Backup Project - + Build Novel Project - + Writing Statistics - + Preferences - + &Help - + About novelWriter - + About Qt5 - + User Manual (Online) - + User Manual (PDF) - + Report an Issue (GitHub) - + Ask a Question (GitHub) - + The novelWriter Website - + Check for New Release @@ -2294,65 +2287,65 @@ GuiOutlineDetails - - - - + + + + Title - + Chapter - + Scene - + Section - + Document - + Status - + Characters - + Words - + Paragraphs - + Synopsis - + Title Details - + Reference Tags @@ -3046,7 +3039,7 @@ - Highlight multiple spaces + Highlight multiple or trailing spaces @@ -3187,58 +3180,58 @@ GuiProjectEditMain - + Project Settings - + Working title - + Should be set only once. - + Novel title - + Change whenever you want! - + Author(s) - + One name per line. - + Default - + Spell check language - - + + Overrides main preferences. - + No backup on close @@ -3246,27 +3239,27 @@ GuiProjectEditReplace - + Text Replace List for Preview and Export - + Keyword - + Replace With - + Select item to edit - + Save @@ -3274,67 +3267,67 @@ GuiProjectEditStatus - + Novel File Status Levels - + Note File Importance Levels - + Label - + Usage - + Select item to edit - + Colour - + Save - + Select Colour - + New Item - + Cannot delete a status item that is in use. - + Not in use - + Used once - + Used by {0} items @@ -3406,27 +3399,27 @@ GuiProjectSettings - + Project Settings - + Settings - + Status - + Importance - + Auto-Replace @@ -3464,100 +3457,78 @@ - - Please select a valid location in the tree to add the document. - - - - - Please select a valid location in the tree to add the folder. - - - - - + Did not find anywhere to add the file or folder! - + Cannot add new files or folders to the Trash folder. - - New File + + New Document - - Cannot add new folder to this item. Maximum folder depth has been reached. + + New Note - + New Folder - + There is currently no Trash folder in this project. - + The Trash folder is already empty. - + Empty Trash - + Permanently delete {0} file(s) from Trash? - - - Delete File - - - - - Permanently delete file '{0}'? - - - - - Could not delete document file. - - - - - Move file '{0}' to Trash? - - - - - Cannot delete folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - - - - + Cannot delete root folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - - - The item cannot be moved to that location. + + + Delete - + + Permanently delete '{0}'? + + + + + Move '{0}' to Trash? + + + + + Could not delete document file. + + + + There is nowhere to add item with name '{0}'. @@ -3565,52 +3536,52 @@ GuiProjectTreeMenu - + Edit Project Item - + Open Document - + View Document - + Toggle Included Flag - + New File - + New Folder - + Delete Item - + Empty Trash - + Move Item Up - + Move Item Down @@ -3649,6 +3620,39 @@ + + GuiViewsBar + + + Project + + + + + Novel + + + + + Outline + + + + + Details + + + + + Stats + + + + + Settings + + + GuiWordList @@ -3816,7 +3820,7 @@ - + Failed to read session log file. @@ -3824,314 +3828,309 @@ NWProject - - Duplicate root item detected. - - - - - + + New - + Note - + Draft - + Finished - + Minor - + Major - + Main - + New Project - + By - - + + Novel - + Plot - + Characters - + World - - + + Title Page - - - + + + New Chapter - - + + New Scene - + Chapter {0} - - + + Scene {0} - + File not found: {0} - - + + Failed to parse project xml. - + Attempting to open backup project file instead. - - + + Unknown - + Project file does not appear to be a novelWriterXML file. - + Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}. - + File Version - + The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue? - + Version Conflict - + This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project? - + Opened Project: {0} - + Project path not set, cannot save project. - - + + Failed to save project. - + Saved Project: {0} - + Backing up project ... - + Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences. - + Cannot backup project because no project name is set. Please set a Working Title in Project Settings. - + Could not create backup folder. - + Cannot backup project because the backup path is within the project folder to be backed up. Please choose a different backup path in Preferences. - + Backup from {0} - + Backup archive file written to: {0} - + Could not write backup archive. - + Project backed up to '{0}' - - + + Failed to create a new example project. - + Failed to create a new example project. Could not find the necessary files. They seem to be missing from this installation. - + Could not create new project folder. - + New project folder is not empty. Each project requires a dedicated project folder. - + You must set a valid backup path in Preferences to use the automatic project backup feature. - + You must set a valid project name in Project Settings to use the automatic project backup feature. - + and - + Could not create folder. - + Found {0} orphaned file(s) in project folder. - + Recovered - + [{0}] {1} - + Recovered File {0} - + One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists. - + Not a folder: {0} - + Could not move: {0} - - + + Could not delete: {0} - + Could not make folder: {0} - + Could not move item {0} to {1}. @@ -4139,47 +4138,47 @@ ProjWizardCustomPage - + Custom Project Options - + Select which additional root folders to make, and how to populate the Novel folder. If you don't want to add chapters or scenes, set the values to 0. You can add scenes without chapters. - + Additional Root Folders - - - - - - + + + + + + {0} folder - + Populate Novel Folder - + Add chapters - + Scenes (per chapter) - + Add chapter folders @@ -4187,27 +4186,27 @@ ProjWizardFinalPage - + Finished - + All done. - + Press '{0}' to create the new project. - + Done - + Finish @@ -4215,7 +4214,7 @@ ProjWizardFolderPage - + Select Project Folder @@ -4231,10 +4230,20 @@ - + Project Path + + + Error: A project folder cannot be created using this path. + + + + + Error: The selected path already exists. + + ProjWizardIntroPage @@ -4287,27 +4296,27 @@ ProjWizardPopulatePage - + Populate Project - + Choose how to pre-fill the project. Either with a minimal set of starter items, an example project explaining and showing many of the features, or show further custom options on the next page. - + Fill the project with a minimal set of items - + Fill the project with example files - + Show detailed options for filling the project @@ -4503,17 +4512,17 @@ Tokenizer - + Synopsis - + Document '{0}' is too big ({1} MB). Skipping. - + ERROR diff --git a/i18n/nw_en_US.ts b/i18n/nw_en_US.ts index 3fb60626..75aee812 100644 --- a/i18n/nw_en_US.ts +++ b/i18n/nw_en_US.ts @@ -77,259 +77,259 @@ Constant - - - + + + None None - + Novel Novel - - + + Plot Plot - - + + Characters Characters - - + + Locations Locations - - + + Timeline Timeline - - + + Objects Objects - - + + Entities Entities - - + + Custom Custom - + Archive Archive - + Trash Trash - - + + Novel Document Novel Document - - + + Project Note Project Note - + Root Folder Root Folder - + Folder Folder - + Novel Title Page Novel Title Page - + Novel Chapter Novel Chapter - + Novel Scene Novel Scene - + Tag Tag - + Point of View Point of View - - + + Focus Focus - + Title Title - + Level Level - + Document Document - + Line Line - + Chars Chars - + Words Words - + Pars Pars - + POV POV - + Synopsis Synopsis - + Straight single quotation mark Straight single quotation mark - + Straight double quotation mark Straight double quotation mark - + Left single quotation mark Left single quotation mark - + Right single quotation mark Right single quotation mark - + Single low-9 quotation mark Single low-9 quotation mark - + Single high-reversed-9 quotation mark Single high-reversed-9 quotation mark - + Left double quotation mark Left double quotation mark - + Right double quotation mark Right double quotation mark - + Double low-9 quotation mark Double low-9 quotation mark - + Double high-reversed-9 quotation mark Double high-reversed-9 quotation mark - + Double low-reversed-9 quotation mark Double low-reversed-9 quotation mark - + Single left-pointing angle quotation mark Single left-pointing angle quotation mark - + Single right-pointing angle quotation mark Single right-pointing angle quotation mark - + Double left-pointing angle quotation mark Double left-pointing angle quotation mark - + Double right-pointing angle quotation mark Double right-pointing angle quotation mark - + Left corner bracket Left corner bracket - + Right corner bracket Right corner bracket - + Left white corner bracket Left white corner bracket - + Right white corner bracket Right white corner bracket @@ -353,9 +353,9 @@ Release - - - + + + Licence License @@ -411,31 +411,31 @@ Translations - + Theme: {0} Theme: {0} - - - - - Author - Author - + Author + Author + + + + + Credit Credit - + Icons: {0} Icons: {0} - + Syntax: {0} Syntax: {0} @@ -718,62 +718,62 @@ There were problems when building the project: - + Open Document Open Document - + Flat Open Document Flat Open Document - + Plain HTML Plain HTML - + novelWriter Markdown novelWriter Markdown - + Standard Markdown Standard Markdown - + GitHub Markdown GitHub Markdown - + JSON + novelWriter HTML JSON + novelWriter HTML - + JSON + novelWriter Markdown JSON + novelWriter Markdown - + PDF PDF - + Save Document As Save Document As - + {0} file successfully written to: {0} file successfully written to: - + Failed to write {0} file. {1} Failed to write {0} file. {1} @@ -781,17 +781,17 @@ GuiBuildNovelDocView - + This area will show the content of the document to be exported or printed. Press the "Build Preview" button to generate content. This area will show the content of the document to be exported or printed. Press the "Build Preview" button to generate content. - + Unknown Unknown - + Build Time: Build Time: @@ -799,32 +799,32 @@ GuiDocEditFooter - + Status Status - + Line: {0} ({1}) Line: {0} ({1}) - + Words: {0} ({1}) Words: {0} ({1}) - + Document size is {0} bytes Document size is {0} bytes - + Words: {0} selected Words: {0} selected - + Character count: {0} Character count: {0} @@ -832,22 +832,22 @@ GuiDocEditHeader - + Edit document meta Edit document meta - + Search document Search document - + Toggle Focus Mode Toggle Focus Mode - + Close the document Close the document @@ -855,58 +855,58 @@ GuiDocEditSearch - - + + Search Search - + Replace Replace - + Case Sensitive Case Sensitive - + Whole Words Only Whole Words Only - + RegEx Mode RegEx Mode - + Loop Search Loop Search - + Search Next File Search Next File - + Preserve Case Preserve Case - + Close Search Close Search - + Find in current document Find in current document - + Find and replace in current document Find and replace in current document @@ -914,117 +914,117 @@ GuiDocEditor - + The document you are trying to open is too big. The document size is {0} MB. The maximum size allowed is {1} MB. The document you are trying to open is too big. The document size is {0} MB. The maximum size allowed is {1} MB. - + Opened Document: {0} Opened Document: {0} - + The text you are trying to add is too big. The text size is {0} MB. The maximum size allowed is {1} MB. The text you are trying to add is too big. The text size is {0} MB. The maximum size allowed is {1} MB. - + File Changed on Disk File Changed on Disk - + This document has been changed outside of novelWriter while it was open. Overwrite the file on disk? This document has been changed outside of novelWriter while it was open. Overwrite the file on disk? - + Could not save document. Could not save document. - + Saved Document: {0} Saved Document: {0} - + Spell checking requires the package PyEnchant. It does not appear to be installed. Spell checking requires the package PyEnchant. It does not appear to be installed. - + Spell check complete Spell check complete - + File Location File Location - + The currently open file is saved in: The currently open file is saved in: - + The document has grown too big and you cannot add more text to it. The maximum size of a single novelWriter document is {0} MB. The document has grown too big and you cannot add more text to it. The maximum size of a single novelWriter document is {0} MB. - + Follow Tag Follow Tag - + Cut Cut - + Copy Copy - + Paste Paste - + Select All Select All - + Select Word Select Word - + Select Paragraph Select Paragraph - + Spelling Suggestion(s) Spelling Suggestion(s) - + No Suggestions No Suggestions - + Add Word to Dictionary Add Word to Dictionary - + Please select some text before calling replace quotes. Please select some text before calling replace quotes. @@ -1067,12 +1067,12 @@ Internal error. - + Could not save document. Could not save document. - + Element selected in the project tree must be a folder. Element selected in the project tree must be a folder. @@ -1080,83 +1080,78 @@ GuiDocSplit - - + + Split Document Split Document - + Document Headers Document Headers - + Select the maximum level to split into files. Select the maximum level to split into files. - + Split on Header Level 1 (Title) Split on Header Level 1 (Title) - + Split up to Header Level 2 (Chapter) Split up to Header Level 2 (Chapter) - + Split up to Header Level 3 (Scene) Split up to Header Level 3 (Scene) - + Split up to Header Level 4 (Section) Split up to Header Level 4 (Section) - + No source document selected. Nothing to do. No source document selected. Nothing to do. - + Could not parse source document. Could not parse source document. - + Failed to open document file. Failed to open document file. - + No headers found. Nothing to do. No headers found. Nothing to do. - - Cannot add new folder for the document split. Maximum folder depth has been reached. Please move the file to another level in the project tree. - Cannot add new folder for the document split. Maximum folder depth has been reached. Please move the file to another level in the project tree. - - - + The document will be split into {0} file(s) in a new folder. The original document will remain intact. The document will be split into {0} file(s) in a new folder. The original document will remain intact. - + Continue with the splitting process? Continue with the splitting process? - + Could not save document. Could not save document. - + Element selected in the project tree must be a file. Element selected in the project tree must be a file. @@ -1164,42 +1159,42 @@ GuiDocViewFooter - + Show/hide the references panel Show/hide the references panel - + Activate to freeze the content of the references panel when changing document Activate to freeze the content of the references panel when changing document - + Show comments Show comments - + Show synopsis comments Show synopsis comments - + References References - + Sticky Sticky - + Comments Comments - + Synopsis Synopsis @@ -1207,22 +1202,22 @@ GuiDocViewHeader - + Go backward Go backward - + Go forward Go forward - + Reload the document Reload the document - + Close the document Close the document @@ -1283,17 +1278,17 @@ Usage - + Characters Characters - + Words Words - + Paragraphs Paragraphs @@ -1306,237 +1301,230 @@ Item Settings - + Include when building project Include when building project - + Label Label - + Status Status - + Layout Layout + + GuiLipsum + + + Insert Placeholder Text + Insert Placeholder Text + + + + Insert Lorem Ipsum Text + Insert Lorem Ipsum Text + + + + Number of paragraphs + Number of paragraphs + + + + Randomise order + Randomize order + + + + Insert + Insert + + GuiMain - - Project - Project - - - - Novel - Novel - - - - Project Details - Project Details - - - - Writing Statistics - Writing Statistics - - - - Project Settings - Project Settings - - - - Editor - Editor - - - - Outline - Outline - - - + You are running an untested development version of novelWriter. Please be careful when working on a live project and make sure you take regular backups. You are running an untested development version of novelWriter. Please be careful when working on a live project and make sure you take regular backups. - + novelWriter is ready ... novelWriter is ready ... - + Cannot create a new project when another project is open. Cannot create a new project when another project is open. - + A project already exists in that location. Please choose another folder. A project already exists in that location. Please choose another folder. - + New project created ... New project created ... - + Close Project Close Project - + Close the current project? Close the current project? - - + + Changes are saved automatically. Changes are saved automatically. - + Backup Project Backup Project - + Backup the current project? Backup the current project? - + The project was locked by the computer '{0}' ({1} {2}), last active on {3}. The project was locked by the computer '{0}' ({1} {2}), last active on {3}. - + Project Locked Project Locked - + The project is already open by another instance of novelWriter, and is therefore locked. Override lock and continue anyway? The project is already open by another instance of novelWriter, and is therefore locked. Override lock and continue anyway? - + Note: If the program or the computer previously crashed, the lock can safely be overridden. However, overriding it is not recommended if the project is open in another instance of novelWriter. Doing so may corrupt the project. Note: If the program or the computer previously crashed, the lock can safely be overridden. However, overriding it is not recommended if the project is open in another instance of novelWriter. Doing so may corrupt the project. - + The project index is outdated or broken. Rebuilding index. The project index is outdated or broken. Rebuilding index. - + Text files ({0}) Text files ({0}) - + Markdown files ({0}) Markdown files ({0}) - + novelWriter files ({0}) novelWriter files ({0}) - + All files ({0}) All files ({0}) - + Import File Import File - + Could not read file. The file must be an existing text file. Could not read file. The file must be an existing text file. - + Please open a document to import the text file into. Please open a document to import the text file into. - + Import Document Import Document - + Importing the file will overwrite the current content of the document. Do you want to proceed? Importing the file will overwrite the current content of the document. Do you want to proceed? - - + + Indexing: '{0}' Indexing: '{0}' - + Unknown item Unknown item - + Indexing completed in {0} ms Indexing completed in {0} ms - + The project index has been successfully rebuilt. The project index has been successfully rebuilt. - + Information Information - + Warning Warning - + Error Error - + This is a bug! This is a bug! - + Internal Error Internal Error - + Exit Exit - + Do you want to exit novelWriter? Do you want to exit novelWriter? @@ -1544,677 +1532,682 @@ GuiMainMenu - + &Project &Project - + New Project New Project - + Open Project Open Project - + Save Project Save Project - + Close Project Close Project - + Project Settings Project Settings - + Project Details Project Details - + Create Root Folder Create Root Folder - + Novel Root Novel Root - + Plot Root Plot Root - + Character Root Character Root - + Location Root Location Root - + Timeline Root Timeline Root - + Object Root Object Root - + Entity Root Entity Root - + Custom Root Custom Root - + Archive Root Archive Root - + Create Folder Create Folder - + Edit Item Edit Item - + Delete Item Delete Item - + Move Item Up Move Item Up - + Move Item Down Move Item Down - + Undo Last Move Undo Last Move - + Empty Trash Empty Trash - + Exit Exit - + &Document &Document - + New Document New Document - + Open Document Open Document - + Save Document Save Document - + Close Document Close Document - + View Document View Document - + Close Document View Close Document View - + Show File Details Show File Details - + Import Text from File Import Text from File - + Merge Folder to Document Merge Folder to Document - + Split Document to Folder Split Document to Folder - + &Edit &Edit - + Undo Undo - + Redo Redo - + Cut Cut - + Copy Copy - + Paste Paste - + Select All Select All - + Select Paragraph Select Paragraph - + &View &View - + Go to Project Tree Go to Project Tree - + Go to Document Editor Go to Document Editor - + Go to Document Viewer Go to Document Viewer - + Go to Outline Go to Outline - + Navigate Backward Navigate Backward - + Navigate Forward Navigate Forward - + Focus Mode Focus Mode - + Full Screen Mode Full Screen Mode - + &Insert &Insert - + Dashes Dashes - + Short Dash Short Dash - + Long Dash Long Dash - + Horizontal Bar Horizontal Bar - + Figure Dash Figure Dash - + Quote Marks Quote Marks - + Left Single Quote Left Single Quote - + Right Single Quote Right Single Quote - + Left Double Quote Left Double Quote - + Right Double Quote Right Double Quote - + Alternative Apostrophe Alternative Apostrophe - + General Punctuation General Punctuation - + Ellipsis Ellipsis - + Prime Prime - + Double Prime Double Prime - + White Spaces White Spaces - + Non-Breaking Space Non-Breaking Space - + Thin Space Thin Space - + Thin Non-Breaking Space Thin Non-Breaking Space - + Other Symbols Other Symbols - + List Bullet List Bullet - + Hyphen Bullet Hyphen Bullet - + Flower Mark Flower Mark - + Per Mille Per Mille - + Degree Symbol Degree Symbol - + Minus Sign Minus Sign - + Times Sign Times Sign - + Division Sign Division Sign - + Tags and References Tags and References - + Page Break and Space Page Break and Space - + Page Break Page Break - + Vertical Space (Single) Vertical Space (Single) - + Vertical Space (Multi) Vertical Space (Multi) - + + Placeholder Text + Placeholder Text + + + &Format &Format - + Emphasis Emphasis - + Strong Emphasis Strong Emphasis - + Strikethrough Strikethrough - + Wrap Double Quotes Wrap Double Quotes - + Wrap Single Quotes Wrap Single Quotes - + Header 1 (Partition) Header 1 (Partition) - + Header 2 (Chapter) Header 2 (Chapter) - + Header 3 (Scene) Header 3 (Scene) - + Header 4 (Section) Header 4 (Section) - + Novel Title Novel Title - + Unnumbered Chapter Unnumbered Chapter - + Align Left Align Left - + Align Centre Align Center - + Align Right Align Right - + Indent Left Indent Left - + Indent Right Indent Right - + Toggle Comment Toggle Comment - + Remove Block Format Remove Block Format - + Convert Single Quotes Convert Single Quotes - + Convert Double Quotes Convert Double Quotes - + Remove In-Paragraph Breaks Remove In-Paragraph Breaks - + &Search &Search - + Find Find - + Replace Replace - + Find Next Find Next - + Find Previous Find Previous - + Replace Next Replace Next - + &Tools &Tools - + Check Spelling Check Spelling - + Re-Run Spell Check Re-Run Spell Check - + Project Word List Project Word List - + Rebuild Index Rebuild Index - + Rebuild Outline Rebuild Outline - + Auto-Update Outline Auto-Update Outline - + Backup Project Backup Project - + Build Novel Project Build Novel Project - + Writing Statistics Writing Statistics - + Preferences Preferences - + &Help &Help - + About novelWriter About novelWriter - + About Qt5 About Qt5 - + User Manual (Online) User Manual (Online) - + User Manual (PDF) User Manual (PDF) - + Report an Issue (GitHub) Report an Issue (GitHub) - + Ask a Question (GitHub) Ask a Question (GitHub) - + The novelWriter Website The novelWriter Website - + Check for New Release Check for New Release @@ -2294,65 +2287,65 @@ GuiOutlineDetails - - - - + + + + Title Title - + Chapter Chapter - + Scene Scene - + Section Section - + Document Document - + Status Status - + Characters Characters - + Words Words - + Paragraphs Paragraphs - + Synopsis Synopsis - + Title Details Title Details - + Reference Tags Reference Tags @@ -3046,8 +3039,8 @@ - Highlight multiple spaces - Highlight multiple spaces + Highlight multiple or trailing spaces + Highlight multiple or trailing spaces @@ -3187,58 +3180,58 @@ GuiProjectEditMain - + Project Settings Project Settings - + Working title Working title - + Should be set only once. Should be set only once. - + Novel title Novel title - + Change whenever you want! Change whenever you want! - + Author(s) Author(s) - + One name per line. One name per line. - + Default Default - + Spell check language Spell check language - - + + Overrides main preferences. Overrides main preferences. - + No backup on close No backup on close @@ -3246,27 +3239,27 @@ GuiProjectEditReplace - + Text Replace List for Preview and Export Text Replace List for Preview and Export - + Keyword Keyword - + Replace With Replace With - + Select item to edit Select item to edit - + Save Save @@ -3274,67 +3267,67 @@ GuiProjectEditStatus - + Novel File Status Levels Novel File Status Levels - + Note File Importance Levels Note File Importance Levels - + Label Label - + Usage Usage - + Select item to edit Select item to edit - + Colour Color - + Save Save - + Select Colour Select Color - + New Item New Item - + Cannot delete a status item that is in use. Cannot delete a status item that is in use. - + Not in use Not in use - + Used once Used once - + Used by {0} items Used by {0} items @@ -3406,27 +3399,27 @@ GuiProjectSettings - + Project Settings Project Settings - + Settings Settings - + Status Status - + Importance Importance - + Auto-Replace Auto-Replace @@ -3464,100 +3457,78 @@ Item status - - Please select a valid location in the tree to add the document. - Please select a valid location in the tree to add the document. - - - - Please select a valid location in the tree to add the folder. - Please select a valid location in the tree to add the folder. - - - - + Did not find anywhere to add the file or folder! Did not find anywhere to add the file or folder! - + Cannot add new files or folders to the Trash folder. Cannot add new files or folders to the Trash folder. - - New File - New File + + New Document + New Document - - Cannot add new folder to this item. Maximum folder depth has been reached. - Cannot add new folder to this item. Maximum folder depth has been reached. + + New Note + New Note - + New Folder New Folder - + There is currently no Trash folder in this project. There is currently no Trash folder in this project. - + The Trash folder is already empty. The Trash folder is already empty. - + Empty Trash Empty Trash - + Permanently delete {0} file(s) from Trash? Permanently delete {0} file(s) from Trash? - - - Delete File - Delete File - - - - Permanently delete file '{0}'? - Permanently delete file '{0}'? - - - - Could not delete document file. - Could not delete document file. - - - - Move file '{0}' to Trash? - Move file '{0}' to Trash? - - - - Cannot delete folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - Cannot delete folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - - - + Cannot delete root folder. It is not empty. Recursive deletion is not supported. Please delete the content first. Cannot delete root folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - - - The item cannot be moved to that location. - The item cannot be moved to that location. + + + Delete + Delete - + + Permanently delete '{0}'? + Permanently delete '{0}'? + + + + Move '{0}' to Trash? + Move '{0}' to Trash? + + + + Could not delete document file. + Could not delete document file. + + + There is nowhere to add item with name '{0}'. There is nowhere to add item with name '{0}'. @@ -3565,52 +3536,52 @@ GuiProjectTreeMenu - + Edit Project Item Edit Project Item - + Open Document Open Document - + View Document View Document - + Toggle Included Flag Toggle Included Flag - + New File New File - + New Folder New Folder - + Delete Item Delete Item - + Empty Trash Empty Trash - + Move Item Up Move Item Up - + Move Item Down Move Item Down @@ -3649,6 +3620,39 @@ Download: {0} + + GuiViewsBar + + + Project + Project + + + + Novel + Novel + + + + Outline + Outline + + + + Details + Details + + + + Stats + Stats + + + + Settings + Settings + + GuiWordList @@ -3816,7 +3820,7 @@ Failed to write {0} file. - + Failed to read session log file. Failed to read session log file. @@ -3824,314 +3828,309 @@ NWProject - - Duplicate root item detected. - Duplicate root item detected. - - - - + + New New - + Note Note - + Draft Draft - + Finished Finished - + Minor Minor - + Major Major - + Main Main - + New Project New Project - + By By - - + + Novel Novel - + Plot Plot - + Characters Characters - + World World - - + + Title Page Title Page - - - + + + New Chapter New Chapter - - + + New Scene New Scene - + Chapter {0} Chapter {0} - - + + Scene {0} Scene {0} - + File not found: {0} File not found: {0} - - + + Failed to parse project xml. Failed to parse project xml. - + Attempting to open backup project file instead. Attempting to open backup project file instead. - - + + Unknown Unknown - + Project file does not appear to be a novelWriterXML file. Project file does not appear to be a novelWriterXML file. - + Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}. Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}. - + File Version File Version - + The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue? The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue? - + Version Conflict Version Conflict - + This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project? This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project? - + Opened Project: {0} Opened Project: {0} - + Project path not set, cannot save project. Project path not set, cannot save project. - - + + Failed to save project. Failed to save project. - + Saved Project: {0} Saved Project: {0} - + Backing up project ... Backing up project ... - + Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences. Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences. - + Cannot backup project because no project name is set. Please set a Working Title in Project Settings. Cannot backup project because no project name is set. Please set a Working Title in Project Settings. - + Could not create backup folder. Could not create backup folder. - + Cannot backup project because the backup path is within the project folder to be backed up. Please choose a different backup path in Preferences. Cannot backup project because the backup path is within the project folder to be backed up. Please choose a different backup path in Preferences. - + Backup from {0} Backup from {0} - + Backup archive file written to: {0} Backup archive file written to: {0} - + Could not write backup archive. Could not write backup archive. - + Project backed up to '{0}' Project backed up to '{0}' - - + + Failed to create a new example project. Failed to create a new example project. - + Failed to create a new example project. Could not find the necessary files. They seem to be missing from this installation. Failed to create a new example project. Could not find the necessary files. They seem to be missing from this installation. - + Could not create new project folder. Could not create new project folder. - + New project folder is not empty. Each project requires a dedicated project folder. New project folder is not empty. Each project requires a dedicated project folder. - + You must set a valid backup path in Preferences to use the automatic project backup feature. You must set a valid backup path in Preferences to use the automatic project backup feature. - + You must set a valid project name in Project Settings to use the automatic project backup feature. You must set a valid project name in Project Settings to use the automatic project backup feature. - + and and - + Could not create folder. Could not create folder. - + Found {0} orphaned file(s) in project folder. Found {0} orphaned file(s) in project folder. - + Recovered Recovered - + [{0}] {1} [{0}] {1} - + Recovered File {0} Recovered File {0} - + One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists. One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists. - + Not a folder: {0} Not a folder: {0} - + Could not move: {0} Could not move: {0} - - + + Could not delete: {0} Could not delete: {0} - + Could not make folder: {0} Could not make folder: {0} - + Could not move item {0} to {1}. Could not move item {0} to {1}. @@ -4139,47 +4138,47 @@ ProjWizardCustomPage - + Custom Project Options Custom Project Options - + Select which additional root folders to make, and how to populate the Novel folder. If you don't want to add chapters or scenes, set the values to 0. You can add scenes without chapters. Select which additional root folders to make, and how to populate the Novel folder. If you don't want to add chapters or scenes, set the values to 0. You can add scenes without chapters. - + Additional Root Folders Additional Root Folders - - - - - - + + + + + + {0} folder {0} folder - + Populate Novel Folder Populate Novel Folder - + Add chapters Add chapters - + Scenes (per chapter) Scenes (per chapter) - + Add chapter folders Add chapter folders @@ -4187,27 +4186,27 @@ ProjWizardFinalPage - + Finished Finished - + All done. All done. - + Press '{0}' to create the new project. Press '{0}' to create the new project. - + Done Done - + Finish Finish @@ -4215,7 +4214,7 @@ ProjWizardFolderPage - + Select Project Folder Select Project Folder @@ -4231,10 +4230,20 @@ Required - + Project Path Project Path + + + Error: A project folder cannot be created using this path. + Error: A project folder cannot be created using this path. + + + + Error: The selected path already exists. + Error: The selected path already exists. + ProjWizardIntroPage @@ -4287,27 +4296,27 @@ ProjWizardPopulatePage - + Populate Project Populate Project - + Choose how to pre-fill the project. Either with a minimal set of starter items, an example project explaining and showing many of the features, or show further custom options on the next page. Choose how to pre-fill the project. Either with a minimal set of starter items, an example project explaining and showing many of the features, or show further custom options on the next page. - + Fill the project with a minimal set of items Fill the project with a minimal set of items - + Fill the project with example files Fill the project with example files - + Show detailed options for filling the project Show detailed options for filling the project @@ -4503,17 +4512,17 @@ Tokenizer - + Synopsis Synopsis - + Document '{0}' is too big ({1} MB). Skipping. Document '{0}' is too big ({1} MB). Skipping. - + ERROR ERROR diff --git a/i18n/nw_nb_NO.ts b/i18n/nw_nb_NO.ts index a4a6c915..17cb5ddb 100644 --- a/i18n/nw_nb_NO.ts +++ b/i18n/nw_nb_NO.ts @@ -77,259 +77,259 @@ Constant - - - + + + None Ingen - + Novel Roman - - + + Plot Plott - - + + Characters Karakterer - - + + Locations Lokasjoner - - + + Timeline Tidslinje - - + + Objects Objekter - - + + Entities Enheter - - + + Custom Annet - + Archive Arkiv - + Trash Søppel - - + + Novel Document Romandokument - - + + Project Note Prosjektnotat - + Root Folder Hovedmappe - + Folder Mappe - + Novel Title Page Tittelside - + Novel Chapter Kapittel - + Novel Scene Scene - + Tag Knagg - + Point of View Perspektiv - - + + Focus Fokus - + Title Tittel - + Level Nivå - + Document Dokument - + Line Linje - + Chars Tegn - + Words Ord - + Pars Avsnitt - + POV Persp. - + Synopsis Sammendrag - + Straight single quotation mark Rett, enkelt sitattegn - + Straight double quotation mark Rett, dobbelt sitattegn - + Left single quotation mark Venstre, enkelt sitattegn - + Right single quotation mark Høyre, enkelt sitattegn - + Single low-9 quotation mark Enkelt, lavt-9 sitattegn - + Single high-reversed-9 quotation mark Enkelt, høyt, reversert-9 sitattegn - + Left double quotation mark Venstre, dobbelt sitattegn - + Right double quotation mark Høyre, dobbelt sitattegn - + Double low-9 quotation mark Dobbelt, lavt-9 sitattegn - + Double high-reversed-9 quotation mark Dobbelt, høyt, reversert-9 sitattegn - + Double low-reversed-9 quotation mark Dobbelt, lavt, reversert-9 sitattegn - + Single left-pointing angle quotation mark Enkelt, venstre, angulært sitattegn - + Single right-pointing angle quotation mark Enkelt, høyre, angulært sitattegn - + Double left-pointing angle quotation mark Dobbelt, venstre, angulært sitattegn - + Double right-pointing angle quotation mark Dobbelt, høyre, angulært sitattegn - + Left corner bracket Venstre hjørnevinkel - + Right corner bracket Høyre hjørnevinkel - + Left white corner bracket Venstre, hvit hjørnevinkel - + Right white corner bracket Høyre, hvit hjørnevinkel @@ -353,9 +353,9 @@ Utgivelse - - - + + + Licence Lisens @@ -411,31 +411,31 @@ Oversettelser - + Theme: {0} Tema: {0} - - - - - Author - Ansvarlig - + Author + Ansvarlig + + + + + Credit Kreditert - + Icons: {0} Ikoner: {0} - + Syntax: {0} Syntaks: {0} @@ -718,62 +718,62 @@ Det har oppstått problemer under bygging av prosjektet: - + Open Document Open Document - + Flat Open Document Flat Open Document - + Plain HTML Enkel HTML - + novelWriter Markdown novelWriter Markdown - + Standard Markdown Standard Markdown - + GitHub Markdown GitHub Markdown - + JSON + novelWriter HTML JSON + novelWriter HTML - + JSON + novelWriter Markdown JSON + novelWriter Markdown - + PDF PDF - + Save Document As Lagre dokumentet som - + {0} file successfully written to: Lagring av {0} var vellykket, og filen ble skrevet til: - + Failed to write {0} file. {1} Misslykkes i å skrive {0} til. {1} @@ -781,17 +781,17 @@ GuiBuildNovelDocView - + This area will show the content of the document to be exported or printed. Press the "Build Preview" button to generate content. Dette området vil vise innholdet av dokumentet som skal eksporteres. Trykk på knappen merket med "Lag forhåndsvisning" for å oppdatere innholdet. - + Unknown Ukjent - + Build Time: Bygget: @@ -799,32 +799,32 @@ GuiDocEditFooter - + Status Status - + Line: {0} ({1}) Linje: {0} ({1}) - + Words: {0} ({1}) Ord: {0} ({1}) - + Document size is {0} bytes Dokumentet er {0} byte - + Words: {0} selected Ord: {0} valgt - + Character count: {0} Antall tegn: {0} @@ -832,22 +832,22 @@ GuiDocEditHeader - + Edit document meta Rediger dokumentinstillinger - + Search document Søk i dokumentet - + Toggle Focus Mode Slå av/på "Fokus-modus" - + Close the document Lukk dokumentet @@ -855,58 +855,58 @@ GuiDocEditSearch - - + + Search Søk - + Replace Erstatt - + Case Sensitive Skill store/små bokstaver - + Whole Words Only Kun hele ord - + RegEx Mode RegEx-modus - + Loop Search Søk rundt - + Search Next File Søk i neste file - + Preserve Case Behold store/små bokstaver - + Close Search Lukk søk - + Find in current document Søk i det åpne dokumentet - + Find and replace in current document Søk og erstatt i det åpne dokumentet @@ -914,117 +914,117 @@ GuiDocEditor - + The document you are trying to open is too big. The document size is {0} MB. The maximum size allowed is {1} MB. Dokumentet du prøver å åpne er for stort. Dokumenter er på {0} MB. Den maksimale størrelsen tillat er {1} MB. - + Opened Document: {0} Åpnet dokument: {0} - + The text you are trying to add is too big. The text size is {0} MB. The maximum size allowed is {1} MB. Teksten du forsøker å legge til er for stor. Teksten er {0} MB. Den maksimale tillatte størrelsen er {1} MB. - + File Changed on Disk Filen er endret på disk - + This document has been changed outside of novelWriter while it was open. Overwrite the file on disk? Dette dokumentet er endret utenfor novelWriter mens det var åpent. Overskrive filen på disken? - + Could not save document. Kunne ikke lagre dokumentet. - + Saved Document: {0} Lagret dokument: {0} - + Spell checking requires the package PyEnchant. It does not appear to be installed. Stavekontroll krever at pakken PyEnchant er installert. Det ser det ikke ut til at den er. - + Spell check complete Stavekontrollen er ferdig - + File Location Filens plassering - + The currently open file is saved in: Det åpne dokumentet er lagret på følgende sted: - + The document has grown too big and you cannot add more text to it. The maximum size of a single novelWriter document is {0} MB. Dokumentet har blitt for stort og du kan ikke legge til mer tekst. Den maksimale tillatte størrelsen for et novelWriter-dokument er {0} MB. - + Follow Tag Følg knagg - + Cut Klipp - + Copy Kopier - + Paste Lim inn - + Select All Velg hele teksten - + Select Word Velg hele ordet - + Select Paragraph Velg hele avsnittet - + Spelling Suggestion(s) Forslag fra stavekontrollen - + No Suggestions Ingen forslag - + Add Word to Dictionary Legg til ord i ordbok - + Please select some text before calling replace quotes. Venligst velg en del av teksten før du velger å erstatte sitattegn. @@ -1067,12 +1067,12 @@ Intern feil - + Could not save document. Kunne ikke lagre dokumentet. - + Element selected in the project tree must be a folder. Elementet som er valgt i prosjekttreet må være en mappe. @@ -1080,83 +1080,78 @@ GuiDocSplit - - + + Split Document Del opp dokument - + Document Headers Dokumentets overskrifter - + Select the maximum level to split into files. Velg hvilket nivå av overskrifter å dele opp til. - + Split on Header Level 1 (Title) Del på overskrifter på nivå 1 (titler) - + Split up to Header Level 2 (Chapter) Del på overskrifter opp til nivå 2 (kapitler) - + Split up to Header Level 3 (Scene) Del på overskrifter opp til nivå 3 (scener) - + Split up to Header Level 4 (Section) Del på overskrifter opp til nivå 4 (seksjoner) - + No source document selected. Nothing to do. Ingen kilde-dokument er valgt. Det er ingenting å gjøre. - + Could not parse source document. Klarte ikke å lese kilde-dokumentet. - + Failed to open document file. Kunne ikke åpne dokumentets fil. - + No headers found. Nothing to do. Ingen overskrifter ble funnet i dokumentet. Det er ikke noe å gjøre. - - Cannot add new folder for the document split. Maximum folder depth has been reached. Please move the file to another level in the project tree. - Kan ikke legge til ny mappe for å dele opp dokumentet. Dokumentet har allerede maksimal dybde i prosjekttreet. Flytt dokumentet til et annet nivå først. - - - + The document will be split into {0} file(s) in a new folder. The original document will remain intact. Dokumentet vil nå bli delt opp i {0} nye filer i en ny mappe. Det originale dokumentet vil ikke bli endret eller fjernet. - + Continue with the splitting process? Fortsette med oppdelingen? - + Could not save document. Kunne ikke lagre dokumentet. - + Element selected in the project tree must be a file. Elementet som er valgt i prosjekttreet må være et dokument. @@ -1164,42 +1159,42 @@ GuiDocViewFooter - + Show/hide the references panel Skjul eller vis referanse-panelet - + Activate to freeze the content of the references panel when changing document Aktiver for å fryse innholdet i referanse-panelet ved bytte av vist dokument - + Show comments Vis kommentarer - + Show synopsis comments Vis sammendrag - + References Referanser - + Sticky Hold igjen - + Comments Kommentarer - + Synopsis Sammendrag @@ -1207,22 +1202,22 @@ GuiDocViewHeader - + Go backward Gå bakover - + Go forward Gå fremover - + Reload the document Last dokumentet på nytt - + Close the document Lukk dokumentet @@ -1283,17 +1278,17 @@ Formål - + Characters Tegn - + Words Ord - + Paragraphs Avsnitt @@ -1306,237 +1301,230 @@ Enhetsinstillinger - + Include when building project Ta med ved eksport - + Label Navn - + Status Status - + Layout Format + + GuiLipsum + + + Insert Placeholder Text + Sett inn midlertidig tekst + + + + Insert Lorem Ipsum Text + Sett inn Lorem Ipsum-tekst + + + + Number of paragraphs + Antall avsnitt + + + + Randomise order + Tilfeldig rekkefølge + + + + Insert + Sett inn + + GuiMain - - Project - Prosjekt - - - - Novel - Roman - - - - Project Details - Prosjektdetaljer - - - - Writing Statistics - Statistikk - - - - Project Settings - Prosjektinnstillinger - - - - Editor - Editor - - - - Outline - Disposisjon - - - + You are running an untested development version of novelWriter. Please be careful when working on a live project and make sure you take regular backups. Du kjører nå en utestet versjon av novelWriter. Vær forsiktig om du jobber med et av dine faktiske prosjekter. Husk å ta backup! - + novelWriter is ready ... novelWriter er klar ... - + Cannot create a new project when another project is open. Kan ikke lage et nytt prosjekt mens et annet prosjekt er åpent. - + A project already exists in that location. Please choose another folder. Et prosjekt finnes allerede i den mappen. Vennligst velg et annet sted å lagre prosjektet. - + New project created ... Et nytt prosjekt har blitt opprettet ... - + Close Project Lukk prosjektet - + Close the current project? Ønsker du å lukke dette prosjektet? - - + + Changes are saved automatically. Endringer lagres automatisk. - + Backup Project Sikkerhetskopiering - + Backup the current project? Ønsker du å ta sikkerhetskopi av dette prosjektet? - + The project was locked by the computer '{0}' ({1} {2}), last active on {3}. Prosjektet er låst av datamaskinen {0} ({1} {2}), siste registrerte aktivitet var {3}. - + Project Locked Prosjektlås - + The project is already open by another instance of novelWriter, and is therefore locked. Override lock and continue anyway? Prosjektet er allerede åpent av en annen instans av novelWriter, og er derfor låst. Vil du overstyre denne låsen og fortsette likevel? - + Note: If the program or the computer previously crashed, the lock can safely be overridden. However, overriding it is not recommended if the project is open in another instance of novelWriter. Doing so may corrupt the project. Merk: Hvis programmet eller datamaskinen tidligere krasjet, kan fil-låsen trygt overstyres. Det anbefales imidlertid ikke å overstyre den hvis prosjektet er åpent i en annen instans av novelWriter. Å gjøre det kan skape konflikter i prosjektets filer. - + The project index is outdated or broken. Rebuilding index. Prosjektets indeks er utdatert eller skadet. Bygger indeksen på nytt. - + Text files ({0}) Tekstfiler ({0}) - + Markdown files ({0}) Markdown-filer ({0}) - + novelWriter files ({0}) novelWriter-filer ({0}) - + All files ({0}) Alle filer ({0}) - + Import File Importer fil - + Could not read file. The file must be an existing text file. Kunne ikke lese filen. Filen må eksistere fra før av. - + Please open a document to import the text file into. Vennligst åpne et dokument hvor teksten i filen kan importeres. - + Import Document Importer dokument - + Importing the file will overwrite the current content of the document. Do you want to proceed? Å importere filen vil overskrive all eksisterende tekst i dokumentet. Ønsker du å fortsette? - - + + Indexing: '{0}' Indekserer: '{0}' - + Unknown item Ukjent enhet - + Indexing completed in {0} ms Indekseringen tok {0} ms - + The project index has been successfully rebuilt. Prosjektets indeks har blitt bygget på nytt. - + Information Informasjon - + Warning Advarsel - + Error Feil - + This is a bug! Dette er en systemfeil! - + Internal Error Intern feil - + Exit Avslutt - + Do you want to exit novelWriter? Ønsker du å avslutte novelWriter? @@ -1544,677 +1532,682 @@ GuiMainMenu - + &Project &Prosjekt - + New Project Nytt prosjekt - + Open Project Åpne prosjekt - + Save Project Lagre prosjektet - + Close Project Lukk prosjektet - + Project Settings Prosjektinnstillinger - + Project Details Prosjektdetaljer - + Create Root Folder Lag ny hovedmappe - + Novel Root Mappe for "Roman" - + Plot Root Mappe for "Plott" - + Character Root Mappe for "Karakterer" - + Location Root Mappe for "Lokasjoner" - + Timeline Root Mappe for "Tidslinjer" - + Object Root Mappe for "Objekter" - + Entity Root Mappe for "Enheter" - + Custom Root Mappe for "Annet" - + Archive Root Mappe for Arkiv - + Create Folder Lag ny mappe - + Edit Item Endre enhet - + Delete Item Slett enhet - + Move Item Up Flytt enhet opp - + Move Item Down Flytt enhet ned - + Undo Last Move Angre siste flytting - + Empty Trash Tøm søppel - + Exit Avslutt - + &Document &Dokument - + New Document Nytt dokument - + Open Document Åpne dokument - + Save Document Lagre dokumentet - + Close Document Lukk dokumentet - + View Document Vis dokument - + Close Document View Lukk dokumentvisning - + Show File Details Vis filinformasjon - + Import Text from File Importer tekst fra fil - + Merge Folder to Document Slå sammen mappe - + Split Document to Folder Del opp dokument - + &Edit &Rediger - + Undo Angre - + Redo Gjenopprett - + Cut Klipp - + Copy Kopier - + Paste Lim inn - + Select All Velg hele teksten - + Select Paragraph Velg hele avsnittet - + &View &Vis - + Go to Project Tree Gå til prosjekt-tre - + Go to Document Editor Gå til dokument-editor - + Go to Document Viewer Gå til visningsvindu - + Go to Outline Gå til disposisjon - + Navigate Backward Navigere bakover - + Navigate Forward Navigere fremover - + Focus Mode Focus-modus - + Full Screen Mode Fullskjerm-modus - + &Insert Sett &inn - + Dashes Bindestreker - + Short Dash Kort bindestrek - + Long Dash Lang bindestrek - + Horizontal Bar Horisontal strek - + Figure Dash Tallstrek - + Quote Marks Sitattegn - + Left Single Quote Venstre, enkelt sitattegn - + Right Single Quote Høyre, enkelt sitattegn - + Left Double Quote Venstre, dobbelt sitattegn - + Right Double Quote Høyre, dobbelt sitattegn - + Alternative Apostrophe Alternativ apostrof - + General Punctuation Generell tegnsetting - + Ellipsis Ellipsis - + Prime Primtegn - + Double Prime Dobbelt primtegn - + White Spaces Mellomrom - + Non-Breaking Space Hardt mellomrom - + Thin Space Kort mellomrom - + Thin Non-Breaking Space Hardt, kort mellomrom - + Other Symbols Andre symboler - + List Bullet Kulepunkt - + Hyphen Bullet Bindestrekpunkt - + Flower Mark Blomsterpunkt - + Per Mille Promille - + Degree Symbol Gradertegn - + Minus Sign Minustegn - + Times Sign Gangetegn - + Division Sign Deletegn - + Tags and References Knagger og referanser - + Page Break and Space Sideskift og avstand - + Page Break Sideskift - + Vertical Space (Single) Vertikal avstand (enkel) - + Vertical Space (Multi) Vertikal avstand (flere) - + + Placeholder Text + Midlertidig tekst + + + &Format &Formattering - + Emphasis Kursiv - + Strong Emphasis Uthev - + Strikethrough Gjennomstrek - + Wrap Double Quotes Sett i doble sitattegn - + Wrap Single Quotes Sett i enkle sitattegn - + Header 1 (Partition) Overskrift 1 (inndeling) - + Header 2 (Chapter) Overskrift 2 (kapittel) - + Header 3 (Scene) Overskrift 3 (scene) - + Header 4 (Section) Overskrift 4 (seksjon) - + Novel Title Boktittel - + Unnumbered Chapter Unumrert kapittel - + Align Left Venstrejuster - + Align Centre Sentrer - + Align Right Høyrejuster - + Indent Left Innrykk fra venstre - + Indent Right Innrykk fra høyre - + Toggle Comment Veksle kommentar - + Remove Block Format Fjern formattering - + Convert Single Quotes Konverter enkle sitattegn - + Convert Double Quotes Konverter doble sitattegn - + Remove In-Paragraph Breaks Fjern linjeskift i avsnittet - + &Search &Søk - + Find Søk - + Replace Erstatt - + Find Next Finn neste - + Find Previous Finn forrige - + Replace Next Erstatt neste - + &Tools &Verktøy - + Check Spelling Stavekontroll - + Re-Run Spell Check Kjør stavekontroll - + Project Word List Prosjektets ordliste - + Rebuild Index Bygg indeks - + Rebuild Outline Bygg disposisjon - + Auto-Update Outline Auto-oppdater disposisjon - + Backup Project Lag sikkerhetskopi av prosjektets mappe - + Build Novel Project Bygg prosjektet - + Writing Statistics Statistikk - + Preferences Innstillinger - + &Help &Hjelp - + About novelWriter Om novelWriter - + About Qt5 Om Qt5 - + User Manual (Online) Brukermanual (på nett) - + User Manual (PDF) Brukermanual (PDF) - + Report an Issue (GitHub) Rapporter en feil (GitHub) - + Ask a Question (GitHub) Still et spørsmål (GitHub) - + The novelWriter Website novelWriters nettside - + Check for New Release Sjekk etter oppdateringer @@ -2294,65 +2287,65 @@ GuiOutlineDetails - - - - + + + + Title Tittel - + Chapter Kapittel - + Scene Scene - + Section Seksjon - + Document Dokument - + Status Status - + Characters Tegn - + Words Ord - + Paragraphs Avsnitt - + Synopsis Sammendrag - + Title Details Oversikt - + Reference Tags Referanser @@ -3046,8 +3039,8 @@ - Highlight multiple spaces - Fremheve repeterte mellomrom + Highlight multiple or trailing spaces + Fremhev flere eller etterfølgende mellomrom @@ -3187,58 +3180,58 @@ GuiProjectEditMain - + Project Settings Prosjektinnstillinger - + Working title Arbeidstittel - + Should be set only once. Bør bare settes én gang. - + Novel title Bokens tittel - + Change whenever you want! Kan endres når som helst! - + Author(s) Forfatter(e) - + One name per line. Ett navn per linje. - + Default Ingen valg - + Spell check language Språk for stavekontroll - - + + Overrides main preferences. Overstyrer valg i innstillinger. - + No backup on close Slå av sikkerhetskopi @@ -3246,27 +3239,27 @@ GuiProjectEditReplace - + Text Replace List for Preview and Export Erstatningsliste for forhåndsvisning og eksport - + Keyword Kodeord - + Replace With Erstatt med - + Select item to edit Velg enhet å redigere - + Save Lagre @@ -3274,67 +3267,67 @@ GuiProjectEditStatus - + Novel File Status Levels Statusnivåer i roman-filer - + Note File Importance Levels Viktighetsnivåer i notatfiler - + Label Navn - + Usage Bruk - + Select item to edit Velg enhet å redigere - + Colour Farge - + Save Lagre - + Select Colour Velg farge - + New Item Legg til - + Cannot delete a status item that is in use. Kan ikke slette status som er i bruk. - + Not in use Ikke i bruk - + Used once Brukt ett sted - + Used by {0} items Brukt {0} steder @@ -3406,27 +3399,27 @@ GuiProjectSettings - + Project Settings Prosjektinnstillinger - + Settings Innstillinger - + Status Status - + Importance Viktighet - + Auto-Replace Autoerstatt @@ -3464,100 +3457,78 @@ Filen eller dokumentets status - - Please select a valid location in the tree to add the document. - Du må velge et gyldig sted i prosjekttreet for å legge til dokumentet. - - - - Please select a valid location in the tree to add the folder. - Du må velge et gyldig sted i prosjekttreet for å legge til mappen. - - - - + Did not find anywhere to add the file or folder! Fant ikke noe sted å legge til filen eller mappen! - + Cannot add new files or folders to the Trash folder. Kan ikke legge til nye filer eller mapper til søppel-mappen. - - New File - Ny fil + + New Document + Nytt dokument - - Cannot add new folder to this item. Maximum folder depth has been reached. - Kan ikke legge til ny mappe på dette stedet da maksimum mappe-dypde er nådd. + + New Note + Nytt notat - + New Folder Ny mappe - + There is currently no Trash folder in this project. Det er for øyeblikket ingen søppel-mappe i dette prosjektet. - + The Trash folder is already empty. Søppel-mappen er allerede tom. - + Empty Trash Tøm søppel - + Permanently delete {0} file(s) from Trash? Vil du slette {0} filer i søppel-mappen for godt? - - - Delete File - Slett fil - - - - Permanently delete file '{0}'? - Slette filen {0} for godt'? - - - - Could not delete document file. - Kunne ikke slette dokumentets fil. - - - - Move file '{0}' to Trash? - Vil du flytte filen {0} til søpla? - - - - Cannot delete folder. It is not empty. Recursive deletion is not supported. Please delete the content first. - Kan ikke slette mappen da den ikke er tom. Rekursiv sletting er ikke støttet. Du må slette innholdet først. - - - + Cannot delete root folder. It is not empty. Recursive deletion is not supported. Please delete the content first. Kan ikke slette hovedmappen da den ikke er tom. Rekursiv sletting er ikke støttet. Du må slette innholdet først. - - - The item cannot be moved to that location. - Denne enheten kan ikke flyttes til denne lokasjonen. + + + Delete + Slett - + + Permanently delete '{0}'? + Slette filen "{0}" for godt? + + + + Move '{0}' to Trash? + Vil du flytte filen "{0}" til søpla? + + + + Could not delete document file. + Kunne ikke slette dokumentets fil. + + + There is nowhere to add item with name '{0}'. Fant ikke noe sted å legge til enheten med navn {0}'. @@ -3565,52 +3536,52 @@ GuiProjectTreeMenu - + Edit Project Item Endre enhet - + Open Document Åpne dokument - + View Document Vis dokument - + Toggle Included Flag Slå av/på inkludering - + New File Ny fil - + New Folder Ny mappe - + Delete Item Slett enhet - + Empty Trash Tøm søppel - + Move Item Up Flytt enhet opp - + Move Item Down Flytt enhet ned @@ -3649,6 +3620,39 @@ Last ned: {0} + + GuiViewsBar + + + Project + Prosjekt + + + + Novel + Roman + + + + Outline + Oversikt + + + + Details + Detaljer + + + + Stats + Statistikk + + + + Settings + Oppsett + + GuiWordList @@ -3816,7 +3820,7 @@ Kunne ikke skrive {0}-filen. - + Failed to read session log file. Kunne ikke lese loggfil med skrive-statistikk. @@ -3824,314 +3828,309 @@ NWProject - - Duplicate root item detected. - Duplikat hovedmappe. - - - - + + New Ny - + Note Notat - + Draft Utkast - + Finished Ferdig - + Minor Mindre - + Major Større - + Main Hoved - + New Project Nytt prosjekt - + By Av - - + + Novel Roman - + Plot Plott - + Characters Karakterer - + World Verden - - + + Title Page Tittelside - - - + + + New Chapter Nytt kapittel - - + + New Scene Ny scene - + Chapter {0} Kapittel {0} - - + + Scene {0} Scene {0} - + File not found: {0} Fant ikke filen: {0} - - + + Failed to parse project xml. Kunne ikke lese prosjektets xml-data. - + Attempting to open backup project file instead. Forsøker å åpne prosjektets sekundære prosjektfil istedet. - - + + Unknown Ukjent - + Project file does not appear to be a novelWriterXML file. Prosjektfilen later ikke til å være en novelWriterXML-fil. - + Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}. Prosjektfilen har et ukjent eller ikke støttet format, og kan ikke åpnes med denne versjonen av novelWriter. Prosjektet ble lagret av novelWriter versjon {0}. - + File Version Filversjon - + The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue? Filformatet til prosjektet ditt er i ferd med å bli oppdatert. Hvis du fortsetter, vil ikke eldre versjoner av novelWriter lenger kunne åpne dette prosjektet. Fortsette? - + Version Conflict Versjonskonflikt - + This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project? Dette prosjektet ble lagret av en nyere versjon av novelWriter, versjon {0}. Dette er versjon {1}. Hvis du ønsker å fortsette med å åpne prosjektet, kan noen av innstillingene bli borte, men selve prosjektet vil være i orden. Vil du fortsatt åpne prosjektet? - + Opened Project: {0} Åpnet prosjekt: {0} - + Project path not set, cannot save project. Prosjektet mangler filbane, og kan ikke lagres. - - + + Failed to save project. Kunne ikke lagre prosjektet. - + Saved Project: {0} Lagret prosjekt: {0} - + Backing up project ... Lager sikkerhetskopi ... - + Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences. Kan ikke ta sikkerhetskopi av prosjektet da ingen filbane er satt. Du må først sette en gyldig filbane i Innstillinger. - + Cannot backup project because no project name is set. Please set a Working Title in Project Settings. Kan ikke ta sikkerhetskopi av prosjektet da ingen arbeidstittel er satt. Du må først sette en arbeidstittel i Prosjektinnstillinger. - + Could not create backup folder. Kunne ikke lage mappe til sikkerhetskopi. - + Cannot backup project because the backup path is within the project folder to be backed up. Please choose a different backup path in Preferences. Kan ikke ta sikkerhetskopi av prosjektet da filbanen er inne i prosjektmappen. Du må sette en ny filbane i Innstillinger. - + Backup from {0} Sikkerhetskopi fra {0} - + Backup archive file written to: {0} Sikkerhetskopi skrevet til: {0} - + Could not write backup archive. Kunne ikke lage sikkerhetskopi. - + Project backed up to '{0}' Sikkerhetskopi skrevet til '{0}' - - + + Failed to create a new example project. Kunne ikke lage nytt eksempel-prosjekt. - + Failed to create a new example project. Could not find the necessary files. They seem to be missing from this installation. Kunne ikke lage nytt eksempel-prosjekt. Kunne ikke finne de nødvendige filene. De ser ut til å mangle i denne installasjonen. - + Could not create new project folder. Kunne ikke lage ny prosjekt-mappe. - + New project folder is not empty. Each project requires a dedicated project folder. Ny prosjektmappe er ikke tom. Hvert prosjekt trenger sin egen mappe. - + You must set a valid backup path in Preferences to use the automatic project backup feature. Du må sette en gyldig filbane i innstillingene for å kunne bruke automatisk sikkerhetskopi. - + You must set a valid project name in Project Settings to use the automatic project backup feature. Du må sette en gyldig arbeidstittel i prosjektinnstillingene for å kunne bruke automatisk sikkerhetskopi. - + and og - + Could not create folder. Kunne ikke opprette mappe. - + Found {0} orphaned file(s) in project folder. Fant {0} tapte filer i prosjektmappen. - + Recovered Gjennopprettet - + [{0}] {1} [{0}] {1} - + Recovered File {0} Gjennopprettet fil {0} - + One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists. Én eller flere gjennopprettede filer kunne ikke bli lagt til i posjektet. Pass på at "Roman"-mappen i det minste eksisterer. - + Not a folder: {0} Ikke en mappe: {0} - + Could not move: {0} Kunne ikke flytte: {0} - - + + Could not delete: {0} Kunne ikke slette: {0} - + Could not make folder: {0} Kunne ikke lage mappe: {0} - + Could not move item {0} to {1}. Kunne ikke flytte {0} til {1}. @@ -4139,47 +4138,47 @@ ProjWizardCustomPage - + Custom Project Options Flere alternativer - + Select which additional root folders to make, and how to populate the Novel folder. If you don't want to add chapters or scenes, set the values to 0. You can add scenes without chapters. Velg hvilke mapper du ønsker i prosjektet, og hvordan du ønsker å fylle hovedmappen for boken. Hvis du ikke ønsker å legge til kapitler og scener, sett verdiene til 0. Du kan også legge til scener uten å legge til kapitler. - + Additional Root Folders Hovedmapper - - - - - - + + + + + + {0} folder {0} - + Populate Novel Folder Fyll roman-mappen - + Add chapters Legg til kapitler - + Scenes (per chapter) Scener (per kapittel) - + Add chapter folders Lag kapittel-mapper @@ -4187,27 +4186,27 @@ ProjWizardFinalPage - + Finished Ferdig - + All done. Alt er klart. - + Press '{0}' to create the new project. Trykk '{0}' for å opprette det nye prosjektet. - + Done Ferdig - + Finish Fullfør @@ -4215,7 +4214,7 @@ ProjWizardFolderPage - + Select Project Folder Velg prosjektmappe @@ -4231,10 +4230,20 @@ Påkrevd - + Project Path Filbane + + + Error: A project folder cannot be created using this path. + Feil: En prosjektmappe kan ikke opprettes ved hjelp av denne banen. + + + + Error: The selected path already exists. + Feil: Den valgte banen finnes allerede. + ProjWizardIntroPage @@ -4287,27 +4296,27 @@ ProjWizardPopulatePage - + Populate Project Fyll prosjektet - + Choose how to pre-fill the project. Either with a minimal set of starter items, an example project explaining and showing many of the features, or show further custom options on the next page. Velg hvordan du vil forhåndsfylle prosjektet. Du kan velge mellom et minimalt sett med mapper og filer, et eksempel-prosjekt som forklarer og viser hvordan du bruker programmet, eller se flere valg på neste side. - + Fill the project with a minimal set of items Fyll prosjektet med et minimalt innhold - + Fill the project with example files Fyll prosjektet med eksempelfiler - + Show detailed options for filling the project Vis detaljerte valg for å fylle prosjektet @@ -4503,17 +4512,17 @@ Tokenizer - + Synopsis Sammendrag - + Document '{0}' is too big ({1} MB). Skipping. Dokumentet '{0}' er for stort ({1} MB). Hopper over. - + ERROR FEIL diff --git a/i18n/nw_nl_NL.ts b/i18n/nw_nl_NL.ts new file mode 100644 index 00000000..332ceac8 --- /dev/null +++ b/i18n/nw_nl_NL.ts @@ -0,0 +1,4521 @@ + + + + + Common + + + in the future + in de toekomst + + + + just now + zojuist + + + + a minute ago + een minuut geleden + + + + {0} minutes ago + {0} minuten geleden + + + + an hour ago + een uur geleden + + + + {0} hours ago + {0} uur geleden + + + + a day ago + een dag geleden + + + + {0} days ago + {0} dagen geleden + + + + a week ago + een week geleden + + + + {0} weeks ago + {0} weken geleden + + + + a month ago + een maand geleden + + + + {0} months ago + {0} maanden geleden + + + + a year ago + een jaar geleden + + + + {0} years ago + {0} jaren geleden + + + + Constant + + + + + None + Geen + + + + Novel + Roman + + + + + Plot + Plot + + + + + Characters + Personages + + + + + Locations + Locaties + + + + + Timeline + Tijdslijn + + + + + Objects + Objecten + + + + + Entities + Entiteiten + + + + + Custom + Custom + + + + Archive + Archief + + + + Trash + Prullenbak + + + + + Novel Document + Roman Document + + + + + Project Note + Project Notitie + + + + Root Folder + Hoofdmap + + + + Folder + Map + + + + Novel Title Page + Roman Titel Pagina + + + + Novel Chapter + Roman Hoofdstuk + + + + Novel Scene + Roman Scene + + + + Tag + Label + + + + Point of View + Perspectief + + + + + Focus + Focus + + + + Title + Titel + + + + Level + Niveau + + + + Document + Document + + + + Line + Regel + + + + Chars + Tekens + + + + Words + Woorden + + + + Pars + Par. + + + + POV + Perspectief + + + + Synopsis + Synopsis + + + + Straight single quotation mark + Recht enkel aanhalingsteken + + + + Straight double quotation mark + Recht dubbel aanhalingsteken + + + + Left single quotation mark + Linker enkel aanhalingsteken + + + + Right single quotation mark + Rechter enkel aanhalingsteken + + + + Single low-9 quotation mark + Enkel lage-9 aanhalingsteken + + + + Single high-reversed-9 quotation mark + Enkel hoog-omgekeerd-9 aanhalingsteken + + + + Left double quotation mark + Linker dubbel aanhalingsteken + + + + Right double quotation mark + Rechter dubbel aanhalingsteken + + + + Double low-9 quotation mark + Dubbel lage-9 aanhalingsteken + + + + Double high-reversed-9 quotation mark + Dubbel hoog-omgekeerd-9 aanhalingsteken + + + + Double low-reversed-9 quotation mark + Dubbel laag-omgekeerd-9 aanhalingsteken + + + + Single left-pointing angle quotation mark + Enkel links-wijzende hoek aanhalingsteken + + + + Single right-pointing angle quotation mark + Enkel rechts-wijzende hoek aanhalingsteken + + + + Double left-pointing angle quotation mark + Dubbel links-wijzende hoek aanhalingsteken + + + + Double right-pointing angle quotation mark + Dubbel rechts-wijzende hoek aanhalingsteken + + + + Left corner bracket + Linker hoekbeugel + + + + Right corner bracket + Rechter hoekbeugel + + + + Left white corner bracket + Linker holle hoekbeugel + + + + Right white corner bracket + Rechter holle hoekbeugel + + + + GuiAbout + + + + About novelWriter + Over novelWriter + + + + About + Over + + + + Release + Uitgave + + + + + + + Licence + Licentie + + + + Website: {0} + Website: {0} + + + + Credits + Bijdragen + + + + Developer + Ontwikkelaar + + + + Concept + Concept + + + + i18n + i18n + + + + novelWriter is a markdown-like text editor designed for organising and writing novels. It is written in Python 3 with a Qt5 GUI, using PyQt5. + novelWriter is een markdown-achtige tekstbewerker, ontworpen voor het organiseren en schrijven van romans. Het is geschreven in Python 3 met een Qt5 GUI met behulp van PyQt5. + + + + novelWriter is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + novelWriter is gratis software: u kunt het herdistribueren en/of aanpassen onder de voorwaarden van de GNU General Public License zoals gepubliceerd door de Free Software Foundation, óf versie 3 van de Licentie, óf (naar uw keuze) elke latere versie. + + + + novelWriter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + novelWriter wordt verspreid in de hoop dat het nuttig is, maar ZONDER ENIGE GARANTIE; zonder zelfs de geïmpliceerde garantie van VERKOOPBAARHEID of GESCHIKTHEID VOOR EEN BEPAALD DOEL. + + + + See the Licence tab for the full licence text, or visit the GNU website at {0} for more details. + Zie het tabblad Licentie voor de volledige licentietekst, of bezoek de GNU-website op {0} voor meer details. + + + + Translations + Vertalingen + + + + Theme: {0} + Thema: {0} + + + + + + Author + Auteur + + + + + + Credit + Dank aan + + + + Icons: {0} + Pictogrammen: {0} + + + + Syntax: {0} + Syntaxis: {0} + + + + GuiBuildNovel + + + Build Novel Project + Bouw Roman Project + + + + Title Formats for Novel Files + Titel Indelingen voor Roman Bestanden + + + + Formatting Codes: + Opmaak codes: + + + + {0} for the title as set in the document + {0} voor de titel zoals ingesteld in het document + + + + {0} for chapter number (1, 2, 3) + {0} voor hoofdstuk nummer (1, 2, 3) + + + + {0} for chapter number as a word (one, two) + {0} voor hoofdstuk nummer als een woord (één, twee) + + + + {0} for chapter number in upper case Roman + {0} voor hoofdstuknummer in Romeinse hoofdletters + + + + {0} for chapter number in lower case Roman + {0} voor hoofdstuknummer in Romeinse kleine letters + + + + {0} for scene number within chapter + {0} voor scène nummer binnen hoofdstuk + + + + {0} for scene number within novel + {0} voor scènenummer in de roman + + + + Leave blank to skip this heading, or set to a static text, like for instance '{0}', to make a separator. The separator will be centred automatically and only appear between sections of the same type. + Laat leeg om deze kop over te slaan, of stel een statische tekst in, zoals bijvoorbeeld '{0}', om een scheiding te maken. De scheiding wordt automatisch gecentreerd en verschijnt alleen tussen secties van hetzelfde type. + + + + Not Set + Niet ingesteld + + + + Title + Titel + + + + Chapter + Hoofdstuk + + + + Unnumbered + Ongenummerd + + + + Scene + Scène + + + + Section + Sectie + + + + Language + Taal + + + + Hide scene + Verberg scène + + + + Hide section + Verberg sectie + + + + Font Options + Lettertype Opties + + + + Font family + Lettertype familie + + + + Font size + Lettertypegrootte + + + + Line height + Regelhoogte + + + + Justify text + Tekst uitvullen + + + + Disable styling + Opmaak uitschakelen + + + + Styling Options + Opmaak Opties + + + + Include Options + Invoeg Opties + + + + Include synopsis + Inclusief synopsis + + + + Include comments + Inclusief opmerkingen + + + + Include keywords + Inclusief trefwoorden + + + + Include body text + Inclusief inhoudstekst + + + + File Filter Options + Bestand Filter Opties + + + + Include novel files + Inclusief roman bestanden + + + + Include note files + Inclusief notitie bestanden + + + + Ignore export flag + Negeer export vlag + + + + Export Options + Export Opties + + + + Replace tabs with spaces + Vervang tabs door spaties + + + + Replace Unicode in HTML + Unicode in HTML vervangen + + + + Build Preview + Bouw voorbeeld + + + + Print + Afdrukken + + + + Print Preview + Afdrukvoorbeeld + + + + Print to PDF + Afdrukken naar PDF + + + + Save As + Opslaan als + + + + Open Document (.odt) + Open Document (.odt) + + + + Flat Open Document (.fodt) + Flat Open Document (.fodt) + + + + novelWriter HTML (.htm) + novelWriter HTML (.htm) + + + + novelWriter Markdown (.nwd) + novelWriter Markdown (.nwd) + + + + Standard Markdown (.md) + Standaard Markdown (.md) + + + + GitHub Markdown (.md) + GitHub Markdown (.md) + + + + JSON + novelWriter HTML (.json) + JSON + novelWriter HTML (.json) + + + + JSON + novelWriter Markdown (.json) + JSON + novelWriter Markdown (.json) + + + + Close + Sluiten + + + + Failed to generate preview. The result is too big. + Genereren van voorbeeld mislukt. Het resultaat is te groot. + + + + There were problems when building the project: + Er waren problemen bij het bouwen van het project: + + + + Open Document + Open Document + + + + Flat Open Document + Flat Open Document + + + + Plain HTML + Plain HTML + + + + novelWriter Markdown + novelWriter Markdown + + + + Standard Markdown + Standaard Markdown + + + + GitHub Markdown + GitHub Markdown + + + + JSON + novelWriter HTML + JSON + novelWriter HTML + + + + JSON + novelWriter Markdown + JSON + novelWriter Markdown + + + + PDF + PDF + + + + Save Document As + Document opslaan als + + + + {0} file successfully written to: + {0} bestand succesvol weggeschreven naar: + + + + Failed to write {0} file. {1} + Wegschrijven van {0} bestand mislukt. {1} + + + + GuiBuildNovelDocView + + + This area will show the content of the document to be exported or printed. Press the "Build Preview" button to generate content. + In dit gebied wordt de inhoud van het document getoond die geëxporteerd of afgedrukt moet worden. Druk op de knop "Bouw voorbeeld" om inhoud te genereren. + + + + Unknown + Onbekend + + + + Build Time: + Bouw tijd: + + + + GuiDocEditFooter + + + Status + Status + + + + Line: {0} ({1}) + Regel: {0} ({1}) + + + + Words: {0} ({1}) + Woorden: {0} ({1}) + + + + Document size is {0} bytes + Document grootte is {0} bytes + + + + Words: {0} selected + Woorden: {0} geselecteerd + + + + Character count: {0} + Aantal tekens: {0} + + + + GuiDocEditHeader + + + Edit document meta + Document meta-gegevens bewerken + + + + Search document + Doorzoek document + + + + Toggle Focus Mode + Schakel focus modus in/uit + + + + Close the document + Sluit het document + + + + GuiDocEditSearch + + + + Search + Zoek + + + + Replace + Vervang + + + + Case Sensitive + Hoofdlettergevoelig + + + + Whole Words Only + Alleen Hele Woorden + + + + RegEx Mode + RegEx Modus + + + + Loop Search + Zoekopdracht Herhalen + + + + Search Next File + Doorzoek Volgend Bestand + + + + Preserve Case + Behoud Hoofd/Kleine letters + + + + Close Search + Zoekopdracht Afsluiten + + + + Find in current document + Zoeken in huidige document + + + + Find and replace in current document + Zoek en vervang in huidig document + + + + GuiDocEditor + + + The document you are trying to open is too big. The document size is {0} MB. The maximum size allowed is {1} MB. + Het document dat u probeert te openen is te groot. De documentgrootte is {0} MB. De maximaal toegestane grootte is {1} MB. + + + + Opened Document: {0} + Geopend Document: {0} + + + + The text you are trying to add is too big. The text size is {0} MB. The maximum size allowed is {1} MB. + De tekst die u probeert toe te voegen is te groot. De tekst is {0} MB. De maximaal toegestane grootte is {1} MB. + + + + File Changed on Disk + Bestand Gewijzigd op Schijf + + + + This document has been changed outside of novelWriter while it was open. Overwrite the file on disk? + Dit document is gewijzigd buiten de openstaande novelWriter. Het bestand op de schijf overschrijven? + + + + Could not save document. + Kon document niet opslaan. + + + + Saved Document: {0} + Document Opgeslagen: {0} + + + + Spell checking requires the package PyEnchant. It does not appear to be installed. + Spellingscontrole vereist het pakket PyEnchant. Het lijkt niet geïnstalleerd te zijn. + + + + Spell check complete + Spellingscontrole compleet + + + + File Location + Bestands Locatie + + + + The currently open file is saved in: + Het momenteel geopende bestand is opgeslagen in: + + + + The document has grown too big and you cannot add more text to it. The maximum size of a single novelWriter document is {0} MB. + Het document is te groot geworden en u kunt er niet meer tekst aan toevoegen. De maximale grootte van een enkel novelWriter document is {0} MB. + + + + Follow Tag + Volg Label + + + + Cut + Knippen + + + + Copy + Kopiëren + + + + Paste + Plakken + + + + Select All + Selecteer Alles + + + + Select Word + Selecteer Woord + + + + Select Paragraph + Selecteer Paragraaf + + + + Spelling Suggestion(s) + Spelling Suggestie(s) + + + + No Suggestions + Geen Suggesties + + + + Add Word to Dictionary + Woord Toevoegen aan Woordenboek + + + + Please select some text before calling replace quotes. + Selecteer a.u.b. een tekst voordat u vervang aanhalingstekens aanroept. + + + + GuiDocMerge + + + Merge Documents + Documenten Samenvoegen + + + + Documents to Merge + Documenten om samen te voegen + + + + Drag and drop items to change the order. + Versleep items om de volgorde te wijzigen. + + + + No source documents found. Nothing to do. + Geen brondocumenten gevonden. Niets te doen. + + + + Failed to open document file. + Documentbestand openen mislukt. + + + + No source folder selected. Nothing to do. + Geen bronmap geselecteerd. Niets te doen. + + + + Internal error. + Interne fout. + + + + Could not save document. + Kon document niet opslaan. + + + + Element selected in the project tree must be a folder. + Element geselecteerd in de projectboom moet een map zijn. + + + + GuiDocSplit + + + + Split Document + Splits document + + + + Document Headers + Document kopteksten + + + + Select the maximum level to split into files. + Selecteer het maximale niveau om in bestanden op te splitsen. + + + + Split on Header Level 1 (Title) + Splits op koptekst niveau 1 (Titel) + + + + Split up to Header Level 2 (Chapter) + Opsplitsen tot kop niveau 2 (Hoofdstuk) + + + + Split up to Header Level 3 (Scene) + Opsplitsen tot kop niveau 3 (Scène) + + + + Split up to Header Level 4 (Section) + Opsplitsen tot kop niveau 4 (Sectie) + + + + No source document selected. Nothing to do. + Geen brondocument geselecteerd. Niets te doen. + + + + Could not parse source document. + Brondocument kan niet ontleden worden. + + + + Failed to open document file. + Kon documentbestand niet openen. + + + + No headers found. Nothing to do. + Geen koppen gevonden. Niets te doen. + + + + Cannot add new folder for the document split. Maximum folder depth has been reached. Please move the file to another level in the project tree. + Kan geen nieuwe map toevoegen voor de splitsing van documenten. Maximale diepte van de map is bereikt. Verplaats het bestand naar een ander niveau in de projectstructuur. + + + + The document will be split into {0} file(s) in a new folder. The original document will remain intact. + Het document zal worden opgesplitst in {0} bestand(en) in een nieuwe map. Het oorspronkelijke document blijft intact. + + + + Continue with the splitting process? + Doorgaan met het splitsings-proces? + + + + Could not save document. + Kon document niet opslaan. + + + + Element selected in the project tree must be a file. + Het in de projectboom geselecteerde element moet een bestand zijn. + + + + GuiDocViewFooter + + + Show/hide the references panel + Toon/verberg het referentiespaneel + + + + Activate to freeze the content of the references panel when changing document + Activeer om de inhoud van het referentiespaneel te bevriezen bij het wijzigen van document + + + + Show comments + Opmerkingen weergeven + + + + Show synopsis comments + Synopsis opmerkingen weergeven + + + + References + Referenties + + + + Sticky + Vastpinnen + + + + Comments + Opmerkingen + + + + Synopsis + Synopsis + + + + GuiDocViewHeader + + + Go backward + Ga achterwaarts + + + + Go forward + Ga voorwaarts + + + + Reload the document + Herlaad het document + + + + Close the document + Sluit het document + + + + GuiDocViewer + + + An error occurred while generating the preview. + Er is een fout opgetreden tijdens het genereren van het voorbeeld. + + + + Could not find the reference for tag '{0}'. It either doesn't exist, or the index is out of date. The index can be updated from the Tools menu, or by pressing {1}. + Kon de verwijzing voor tag '{0}' niet vinden. Hij bestaat niet of de index is verouderd. De index kan worden bijgewerkt in het Hulpmiddelenmenu, of door op {1} te drukken. + + + + Copy + Kopiëren + + + + Select All + Selecteer alles + + + + Select Word + Selecteer woord + + + + Select Paragraph + Selecteer paragraaf + + + + GuiItemDetails + + + Label + Label + + + + Status + Status + + + + Class + Klasse + + + + Usage + Gebruik + + + + Characters + Tekens + + + + Words + Woorden + + + + Paragraphs + Paragrafen + + + + GuiItemEditor + + + Item Settings + Item Instellingen + + + + Include when building project + Opnemen bij bouwen van project + + + + Label + Label + + + + Status + Status + + + + Layout + Indeling + + + + GuiMain + + + Project + Project + + + + Novel + Roman + + + + Project Details + Project details + + + + Writing Statistics + Schrijf statistieken + + + + Project Settings + Project instellingen + + + + Editor + Tekstbewerker + + + + Outline + Contour + + + + You are running an untested development version of novelWriter. Please be careful when working on a live project and make sure you take regular backups. + Je gebruikt een ongeteste ontwikkelingsversie van novelWriter. Wees voorzichtig bij het werken aan een live project en zorg ervoor dat je regelmatige reservekopieën maakt. + + + + novelWriter is ready ... + novelWriter is klaar ... + + + + Cannot create a new project when another project is open. + Kan geen nieuw project maken als een ander project geopend is. + + + + A project already exists in that location. Please choose another folder. + Er bestaat al een project op die locatie. Kies een andere map. + + + + New project created ... + Nieuw project aangemaakt... + + + + Close Project + Sluit project + + + + Close the current project? + Sluit het huidige project? + + + + + Changes are saved automatically. + Wijzigingen worden automatisch opgeslagen. + + + + Backup Project + Project reservekopie maken + + + + Backup the current project? + Reservekopie maken van het huidige project? + + + + The project was locked by the computer '{0}' ({1} {2}), last active on {3}. + Het project is vergrendeld door de computer '{0}' ({1} {2}), voor het laatst actief op {3}. + + + + Project Locked + Project vergrendeld + + + + The project is already open by another instance of novelWriter, and is therefore locked. Override lock and continue anyway? + Het project is al geopend door een andere instantie van novelWriter, en is daarom vergrendeld. Vergrendeling negeren en toch verder gaan? + + + + Note: If the program or the computer previously crashed, the lock can safely be overridden. However, overriding it is not recommended if the project is open in another instance of novelWriter. Doing so may corrupt the project. + Opmerking: als het programma of de computer eerder is vastgelopen, kan de vergrendeling veilig worden genegeerd. Het wordt echter niet aanbevolen als het project open is in een andere instantie van novelWriter. Toch doen kan het project beschadigen. + + + + The project index is outdated or broken. Rebuilding index. + De projectindex is verouderd of gebroken. De index wordt herbouwd. + + + + Text files ({0}) + Tekst bestanden ({0}) + + + + Markdown files ({0}) + Markdown bestanden ({0}) + + + + novelWriter files ({0}) + novelWriter bestanden ({0}) + + + + All files ({0}) + Alle bestanden ({0}) + + + + Import File + Importeer bestand + + + + Could not read file. The file must be an existing text file. + Kon het bestand niet lezen. Het bestand moet een bestaand tekst bestand zijn. + + + + Please open a document to import the text file into. + Open a.u.b. een document om het tekst bestand in te importeren. + + + + Import Document + Importeer document + + + + Importing the file will overwrite the current content of the document. Do you want to proceed? + Het importeren van het bestand overschrijft de huidige inhoud van het document. Wilt u doorgaan? + + + + + Indexing: '{0}' + Indexeren: '{0}' + + + + Unknown item + Onbekend item + + + + Indexing completed in {0} ms + Indexeren voltooid in {0} ms + + + + The project index has been successfully rebuilt. + De projectindex is succesvol opnieuw opgebouwd. + + + + Information + Informatie + + + + Warning + Waarschuwing + + + + Error + Foutmelding + + + + This is a bug! + Dit is een bug! + + + + Internal Error + Interne Foutmelding + + + + Exit + Afsluiten + + + + Do you want to exit novelWriter? + Wil je novelWriter afsluiten? + + + + GuiMainMenu + + + &Project + &Project + + + + New Project + Nieuw project + + + + Open Project + Open project + + + + Save Project + Project opslaan + + + + Close Project + Sluit project + + + + Project Settings + Project instellingen + + + + Project Details + Project details + + + + Create Root Folder + Maak hoofdmap aan + + + + Novel Root + Roman hoofdmap + + + + Plot Root + Plot hoofdmap + + + + Character Root + Personage hoofdmap + + + + Location Root + Locatie hoofdmap + + + + Timeline Root + Tijdslijn hoofdmap + + + + Object Root + Object hoofdmap + + + + Entity Root + Entiteit hoofdmap + + + + Custom Root + Aangepaste hoofdmap + + + + Archive Root + Archief hoofdmap + + + + Create Folder + Map aanmaken + + + + Edit Item + Item bewerken + + + + Delete Item + Item verwijderen + + + + Move Item Up + Verplaats item omhoog + + + + Move Item Down + Verplaats item omlaag + + + + Undo Last Move + Ongedaan maken laatste verplaatsing + + + + Empty Trash + Leeg prullenbak + + + + Exit + Afsluiten + + + + &Document + &Document + + + + New Document + Nieuw document + + + + Open Document + Open document + + + + Save Document + Document opslaan + + + + Close Document + Sluit document + + + + View Document + Document weergeven + + + + Close Document View + Sluit document weergave + + + + Show File Details + Toon bestandsdetails + + + + Import Text from File + Tekst importeren uit bestand + + + + Merge Folder to Document + Samenvoegen van map naar document + + + + Split Document to Folder + Document naar map splitsen + + + + &Edit + &Bewerken + + + + Undo + Ongedaan maken + + + + Redo + Opnieuw uitvoeren + + + + Cut + Knippen + + + + Copy + Kopiëren + + + + Paste + Plakken + + + + Select All + Selecteer alles + + + + Select Paragraph + Selecteer paragraaf + + + + &View + &Weergave + + + + Go to Project Tree + Ga naar projectboom + + + + Go to Document Editor + Ga naar Documentbewerker + + + + Go to Document Viewer + Ga naar documentweergave + + + + Go to Outline + Ga naar omlijning + + + + Navigate Backward + Navigeer achteruit + + + + Navigate Forward + Navigeer vooruit + + + + Focus Mode + Focus modus + + + + Full Screen Mode + Volledig scherm modus + + + + &Insert + &Invoegen + + + + Dashes + Streepjes + + + + Short Dash + Korte streep + + + + Long Dash + Lange streep + + + + Horizontal Bar + Horizontale lijn + + + + Figure Dash + Figuur streep + + + + Quote Marks + Aanhalingstekens + + + + Left Single Quote + Enkel Aanhalingsteken Links + + + + Right Single Quote + Enkel Aanhalingsteken Rechts + + + + Left Double Quote + Dubbel Aanhalingsteken Links + + + + Right Double Quote + Dubbele Aanhalingstekens Rechts + + + + Alternative Apostrophe + Alternatieve Apostrof + + + + General Punctuation + Algemene Leestekens + + + + Ellipsis + Ellips + + + + Prime + Priem + + + + Double Prime + Dubbele priem + + + + White Spaces + Witruimtes + + + + Non-Breaking Space + Vaste spatie + + + + Thin Space + Dunne spatie + + + + Thin Non-Breaking Space + Dunne vaste spatie + + + + Other Symbols + Andere symbolen + + + + List Bullet + Lijst opsommingsteken + + + + Hyphen Bullet + Koppelteken opsommingsteken + + + + Flower Mark + Bloem markering + + + + Per Mille + Per mille + + + + Degree Symbol + Graden symbool + + + + Minus Sign + Minus teken + + + + Times Sign + Vermenigvuldigingsteken + + + + Division Sign + Deelteken + + + + Tags and References + Tags en Referenties + + + + Page Break and Space + Pagina-einde en Spatie + + + + Page Break + Nieuwe pagina + + + + Vertical Space (Single) + Verticale spatie (enkel) + + + + Vertical Space (Multi) + Verticale spatie (multi) + + + + &Format + Opmaak + + + + Emphasis + Nadruk + + + + Strong Emphasis + Sterke nadruk + + + + Strikethrough + Doorhalen + + + + Wrap Double Quotes + Dubbele aanhalingstekens omwikkelen + + + + Wrap Single Quotes + Enkel aanhalingsteken omwikkelen + + + + Header 1 (Partition) + Kop 1 (Partitie) + + + + Header 2 (Chapter) + Kop 2 (Hoofdstuk) + + + + Header 3 (Scene) + Kop 3 (Scène) + + + + Header 4 (Section) + Kop 4 (Sectie) + + + + Novel Title + Roman titel + + + + Unnumbered Chapter + Ongenummerd hoofdstuk + + + + Align Left + Links uitlijnen + + + + Align Centre + Centreren + + + + Align Right + Rechts uitlijnen + + + + Indent Left + Links inspringen + + + + Indent Right + Rechts inspringen + + + + Toggle Comment + Opmerking in-/uitschakelen + + + + Remove Block Format + Verwijder blokformaat + + + + Convert Single Quotes + Converteer enkele aanhalingstekens + + + + Convert Double Quotes + Converteer dubbele aanhalingstekens + + + + Remove In-Paragraph Breaks + Verwijder in-paragraaf onderbrekingen + + + + &Search + &Zoeken + + + + Find + Vinden + + + + Replace + Vervangen + + + + Find Next + Volgende zoeken + + + + Find Previous + Vorige zoeken + + + + Replace Next + Vervang volgende + + + + &Tools + &Hulpmiddelen + + + + Check Spelling + Spelling controleren + + + + Re-Run Spell Check + Spellingscontrole opnieuw uitvoeren + + + + Project Word List + Project woordenlijst + + + + Rebuild Index + Index opnieuw opbouwen + + + + Rebuild Outline + Herbouw omlijning + + + + Auto-Update Outline + Auto-update omlijning + + + + Backup Project + Project back-up maken + + + + Build Novel Project + Bouw Roman Project + + + + Writing Statistics + Schrijf Statistieken + + + + Preferences + Voorkeuren + + + + &Help + &Help + + + + About novelWriter + Over novelWriter + + + + About Qt5 + Over Qt5 + + + + User Manual (Online) + Gebruikershandleiding (Online) + + + + User Manual (PDF) + Gebruikershandleiding (PDF) + + + + Report an Issue (GitHub) + Meld een probleem (GitHub) + + + + Ask a Question (GitHub) + Stel een vraag (GitHub) + + + + The novelWriter Website + De novelWriter website + + + + Check for New Release + Controleer op nieuwe release + + + + GuiMainStatus + + + + None + Geen + + + + Editor + Tekstverwerker + + + + Project + Project + + + + Session Time + Sessieduur + + + + Words: {0} ({1}) + Woorden: {0} ({1}) + + + + Project word count (session change) + Aantal projectwoorden (verandering sessie) + + + + Novel word count (session change) + Roman woordtelling (sessie verandering) + + + + GuiNovelTree + + + Novel Outline + Roman omlijning + + + + Words + Woorden + + + + POV + Perspectief + + + + Section title + Sectietitel + + + + Word count + Aantal woorden + + + + Point-of-view character + Point-of-view karakter + + + + GuiOutlineDetails + + + + + + Title + Titel + + + + Chapter + Hoofdstuk + + + + Scene + Scène + + + + Section + Sectie + + + + Document + Document + + + + Status + Status + + + + Characters + Tekens + + + + Words + Woorden + + + + Paragraphs + Paragrafen + + + + Synopsis + Synopsis + + + + Title Details + Titel details + + + + Reference Tags + Referentie tags + + + + GuiOutlineHeaderMenu + + + Select Columns + Selecteer kolommen + + + + GuiPreferences + + + Preferences + Voorkeuren + + + + General + Algemeen + + + + Projects + Projecten + + + + Documents + Documenten + + + + Editor + Tekstverwerker + + + + Highlighting + Markeren + + + + Automation + Automatisering + + + + Quotes + Aanhalingstekens + + + + Some changes will not be applied until novelWriter has been restarted. + Sommige wijzigingen zullen niet worden toegepast totdat novelWriter opnieuw is gestart. + + + + GuiPreferencesAutomation + + + Automatic Features + Automatische Functies + + + + Auto-select word under cursor + Automatisch woord onder cursor selecteren + + + + Apply formatting to word under cursor if no selection is made. + Opmaak toepassen op woord onder de cursor als er geen selectie is gemaakt. + + + + Auto-replace text as you type + Automatisch tekst vervangen terwijl u typt + + + + Allow the editor to replace symbols as you type. + Sta de editor toe om symbolen te vervangen terwijl u typt. + + + + Replace as You Type + Vervang Terwijl U Typt + + + + Auto-replace single quotes + Automatisch enkele aanhalingstekens vervangen + + + + + Try to guess which is an opening or a closing quote. + Probeer te raden wat een openend of afsluitend aanhalingsteken is. + + + + Auto-replace double quotes + Automatisch dubbele aanhalingstekens vervangen + + + + Auto-replace dashes + Automatisch streepjes vervangen + + + + Double and triple hyphens become short and long dashes. + Dubbele en drievoudige koppeltekens worden korte en lange streepjes. + + + + Auto-replace dots + Automatisch stippen vervangen + + + + Three consecutive dots become ellipsis. + Drie opeenvolgende stippen worden ellips. + + + + Automatic Padding + Automatische Opvulling + + + + Insert non-breaking space before + Vaste spatie invoegen voor + + + + Automatically add space before any of these symbols. + Voeg automatisch een spatie toe voor één van deze symbolen. + + + + Insert non-breaking space after + Vaste spatie invoegen na + + + + Automatically add space after any of these symbols. + Voeg automatisch een spatie toe na één van deze symbolen. + + + + Use thin space instead + Gebruik dunne spatie in plaats van + + + + Inserts a thin space instead of a regular space. + Voegt een dunne spatie toe in plaats van een normale spatie. + + + + GuiPreferencesDocuments + + + Text Style + Tekst Stijl + + + + Font family + Lettertype familie + + + + + + + Applies to both document editor and viewer. + Van toepassing op zowel de documentbewerker als de kijker. + + + + Font size + Lettertypegrootte + + + + pt + pt + + + + Text Flow + Tekst Flow + + + + Maximum text width in "Normal Mode" + Maximale tekstbreedte in "Normale Modus" + + + + Set to 0 to disable this feature. + Stel in op 0 om deze functie uit te schakelen. + + + + + + + px + px + + + + Maximum text width in "Focus Mode" + Maximale tekstbreedte in "Focus Modus" + + + + The maximum width cannot be disabled. + De maximale breedte kan niet worden uitgeschakeld. + + + + Hide document footer in "Focus Mode" + Verberg document voettekst in "Focus Modus" + + + + Hide the information bar in the document editor. + Verberg de informatiebalk in de documentbewerker. + + + + Justify the text margins + De tekstmarges uitvullen + + + + Minimum text margin + Minimale tekstmarge + + + + Tab width + Tab breedte + + + + The width of a tab key press in the editor and viewer. + De breedte van een tab teken in de tekstbewerker en kijker. + + + + GuiPreferencesEditor + + + Spell Checking + Spellingscontrole + + + + None + Geen + + + + Not installed + Niet geïnstalleerd + + + + Spell check language + Taal voor spellingscontrole + + + + Available languages are determined by your system. + Beschikbare talen worden bepaald door uw systeem. + + + + Big document limit + Groot document limiet + + + + Full spell checking is disabled above this limit. + Volledige spellingcontrole is uitgeschakeld boven dit limiet. + + + + kB + kB + + + + Word Count + Woord Telling + + + + Word count interval + Woord tellings interval + + + + seconds + seconden + + + + Include project notes in status bar word count + Project notities opnemen in de statusbalk woord telling + + + + Writing Guides + Schrijf Hulpjes + + + + Show tabs and spaces + Tabs en spaties weergeven + + + + Show line endings + Regeleindes weergeven + + + + Scroll Behaviour + Scroll Gedrag + + + + Scroll past end of the document + Scroll voorbij het einde van het document + + + + Set to 0 to disable this feature. + Stel in op 0 om deze functie uit te schakelen. + + + + lines + regels + + + + Typewriter style scrolling when you type + Schrijfmachine stijl scrollen bij het typen + + + + Keeps the cursor at a fixed vertical position. + Houd de cursor op een vaste verticale positie. + + + + Minimum position for Typewriter scrolling + Minimumpositie voor Schrijfmachine scrollen + + + + Percentage of the editor height from the top. + Percentage van de tekstverwerker hoogte vanaf de bovenkant. + + + + GuiPreferencesGeneral + + + Look and Feel + Look and Feel + + + + Main GUI language + Hoofdtaal van GUI + + + + + + + + Requires restart. + Vereist herstart. + + + + Main GUI theme + Hoofd GUI thema + + + + Main icon theme + Hoofd pictogrammen thema + + + + Font family + Lettertype familie + + + + Font size + Lettertypegrootte + + + + pt + pt + + + + GUI Settings + GUI Instellingen + + + + Emphasise partition and chapter labels + Partitie en hoofdstuk labels benadrukken + + + + Makes them stand out in the project tree. + Laat ze opvallen in de projectboom. + + + + Show full path in document header + Volledig pad in document kop weergeven + + + + Add the parent folder names to the header. + Voeg de bovenliggende mapnamen toe aan de kop. + + + + Hide vertical scroll bars in main windows + Verticale schuifbalken in hoofdvensters verbergen + + + + + Scrolling available with mouse wheel and keys only. + Scrollen alleen beschikbaar met muiswiel en toetsen. + + + + Hide horizontal scroll bars in main windows + Verberg horizontale schuifbalken in hoofdvensters + + + + GuiPreferencesProjects + + + Automatic Save + Automatisch Opslaan + + + + Save document interval + Document opslag interval + + + + How often the document is automatically saved. + Hoe vaak het document automatisch wordt opgeslagen. + + + + + seconds + seconden + + + + Save project interval + Project opslag interval + + + + How often the project is automatically saved. + Hoe vaak het project automatisch wordt opgeslagen. + + + + Project Backup + Project Reservekopie + + + + Browse + Blader + + + + Backup storage location + Opslaglocatie voor reservekopie + + + + + Path: {0} + Pad: {0} + + + + Run backup when the project is closed + Reservekopie maken wanneer het project wordt gesloten + + + + Can be overridden for individual projects in Project Settings. + Kan voor individuele projecten overschreven worden in Projectinstellingen. + + + + Ask before running backup + Vraag voor het maken van een reservekopie + + + + If off, backups will run in the background. + Indien uit, worden reservekopieën op de achtergrond gemaakt. + + + + Session Timer + Sessie Timer + + + + Pause the session timer when not writing + De sessie timer pauzeren wanneer niet geschreven wordt + + + + Also pauses when the application window does not have focus. + Pauzeert ook wanneer het toepassingsvenster geen focus heeft. + + + + Editor inactive time before pausing timer + Inactieve tekstbewerker duur voordat timer wordt gepauzeerd + + + + User activity includes typing and changing the content. + Gebruikersactiviteit omvat typen en het wijzigen van de inhoud. + + + + minutes + minuten + + + + Backup Directory + Reservekopie map + + + + GuiPreferencesQuotes + + + Quotation Style + Citeer Stijl + + + + Single quote open style + Enkel aanhalingsteken open stijl + + + + The symbol to use for a leading single quote. + Het symbool om te gebruiken voor een leidend enkel aanhalingsteken. + + + + Single quote close style + Enkel aanhalingsteken sluit stijl + + + + The symbol to use for a trailing single quote. + Het symbool om te gebruiken voor een afsluitend enkel aanhalingsteken. + + + + Double quote open style + Dubbele aanhalingsteken open stijl + + + + The symbol to use for a leading double quote. + Het symbool om te gebruiken voor een leidend dubbel aanhalingsteken. + + + + Double quote close style + Dubbel aanhalingsteken sluit stijl + + + + The symbol to use for a trailing double quote. + Het symbool om te gebruiken voor een afsluitend dubbel aanhalingsteken. + + + + GuiPreferencesSyntax + + + Highlighting Theme + Markeer thema + + + + Highlighting theme + Markeer thema + + + + Colour theme for the editor and viewer. + Kleur thema voor de bewerker en kijker. + + + + Quotes & Dialogue + Aanhalingstekens & Dialoog + + + + Highlight text wrapped in quotes + Markeer tekst verpakt in aanhalingstekens + + + + + + Applies to the document editor only. + Alleen van toepassing op de documentbewerker. + + + + Allow open-ended single quotes + Toestaan van open einde enkele aanhalingstekens + + + + Highlight single-quoted line with no closing quote. + Markeer regel zonder afsluitend enkel aanhalingsteken. + + + + Allow open-ended double quotes + Toestaan van open einde dubbele aanhalingstekens + + + + Highlight double-quoted line with no closing quote. + Markeer regel zonder afsluitend dubbel aanhalingsteken. + + + + Text Emphasis + Tekst nadruk + + + + Add highlight colour to emphasised text + Voeg markeerkleur toe aan geaccentueerde tekst + + + + Text Errors + Tekst Foutmeldingen + + + + Highlight multiple spaces + Meerdere spaties markeren + + + + GuiProjectDetails + + + Project Details + Project Details + + + + Overview + Overzicht + + + + Contents + Inhoud + + + + GuiProjectDetailsContents + + + Title + Titel + + + + Words + Woorden + + + + Pages + Pagina's + + + + Page + Pagina + + + + Progress + Voortgang + + + + Typical word count for a 5 by 8 inch book page with 11 pt font is 350. + Typische woordtelling voor een 5 bij 8 inch boek pagina met 11 pt lettertype is 350. + + + + Start counting page numbers from this page. + Begin met het tellen van paginanummers vanaf deze pagina. + + + + Assume a new chapter or partition always start on an odd numbered page. + Neem aan dat een nieuw hoofdstuk of partitie altijd op een oneven genummerde pagina begint. + + + + Words per page + Woorden per pagina + + + + Count pages from + Pagina's tellen vanaf + + + + Clear double pages + Dubbele pagina's wissen + + + + Table of Contents + Inhoudsopgave + + + + END + EINDE + + + + Untitled + Naamloos + + + + GuiProjectDetailsMain + + + Working Title: {0} + Werktitel: {0} + + + + By {0} + Door {0} + + + + Words + Woorden + + + + Chapters + Hoofdstukken + + + + Scenes + Scènes + + + + Revisions + Revisies + + + + Editing Time + Bewerk tijd + + + + Path + Pad + + + + GuiProjectEditMain + + + Project Settings + Project Instellingen + + + + Working title + Werk titel + + + + Should be set only once. + Mag slechts één keer worden ingesteld. + + + + Novel title + Roman titel + + + + Change whenever you want! + Verander wanneer je maar wilt! + + + + Author(s) + Auteur(s) + + + + One name per line. + Eén naam per regel. + + + + Default + Standaard + + + + Spell check language + Taal voor spellingscontrole + + + + + Overrides main preferences. + Overschrijft de hoofd voorkeuren. + + + + No backup on close + Geen back-up bij sluiten + + + + GuiProjectEditReplace + + + Text Replace List for Preview and Export + Tekst Vervang Lijst voor Voorbeeld en Export + + + + Keyword + Sleutelwoord + + + + Replace With + Vervang door + + + + Select item to edit + Selecteer te bewerken item + + + + Save + Opslaan + + + + GuiProjectEditStatus + + + Novel File Status Levels + Roman Bestand Status Niveaus + + + + Note File Importance Levels + Notitie Bestand Import Niveaus + + + + Label + Label + + + + Usage + Gebruik + + + + Select item to edit + Selecteer te bewerken item + + + + Colour + Kleur + + + + Save + Opslaan + + + + Select Colour + Selecteer kleur + + + + New Item + Nieuw item + + + + Cannot delete a status item that is in use. + Kan status item dat in gebruik is niet verwijderen. + + + + Not in use + Niet in gebruik + + + + Used once + Eenmalig gebruikt + + + + Used by {0} items + Gebruikt door {0} items + + + + GuiProjectLoad + + + + Open Project + Open Project + + + + Working Title + Werk titel + + + + Words + Woorden + + + + Last Opened + Laatst geopend + + + + Recently Opened Projects + Recent Geopende Projecten + + + + Path + Pad + + + + New + Nieuw + + + + Remove + Verwijder + + + + novelWriter Project File ({0}) + novelWriter Projectbestand ({0}) + + + + All files ({0}) + Alle bestanden ({0}) + + + + Remove Entry + Vermelding verwijderen + + + + Remove '{0}' from the recent projects list? The project files will not be deleted. + '{0}' uit de lijst met recente projecten verwijderen? De project bestanden zullen niet worden verwijderd. + + + + GuiProjectSettings + + + Project Settings + Project Instellingen + + + + Settings + Instellingen + + + + Status + Status + + + + Importance + Belangrijkheid + + + + Auto-Replace + Auto-Vervang + + + + GuiProjectTree + + + Project Tree + Project Boom + + + + Words + Woorden + + + + Item label + Item label + + + + Word count + Aantal woorden + + + + Include in build + Opnemen in bouw + + + + Item status + Item status + + + + Please select a valid location in the tree to add the document. + Selecteer een geldige locatie in de boomstructuur om het document aan toe te voegen. + + + + Please select a valid location in the tree to add the folder. + Selecteer een geldige locatie in de boomstructuur om de map aan toe te voegen. + + + + + Did not find anywhere to add the file or folder! + Kon geen plek vinden om het bestand of de map aan toe te voegen! + + + + Cannot add new files or folders to the Trash folder. + Kan geen nieuwe bestanden of mappen toevoegen aan de Prullenbak map. + + + + New File + Nieuw bestand + + + + Cannot add new folder to this item. Maximum folder depth has been reached. + Kan geen nieuwe map toevoegen aan dit item. Maximum map diepte is bereikt. + + + + New Folder + Nieuwe map + + + + There is currently no Trash folder in this project. + Er is momenteel geen Prullenbak map in dit project. + + + + The Trash folder is already empty. + De Prullenbak is al leeg. + + + + Empty Trash + Prullenbak legen + + + + Permanently delete {0} file(s) from Trash? + {0} bestand(en) permanent verwijderen uit de prullenbak? + + + + + Delete File + Verwijder bestand + + + + Permanently delete file '{0}'? + Bestand '{0}' permanent verwijderen ? + + + + Could not delete document file. + Kon documentbestand niet verwijderen. + + + + Move file '{0}' to Trash? + Verplaats bestand '{0}' naar prullenbak? + + + + Cannot delete folder. It is not empty. Recursive deletion is not supported. Please delete the content first. + Kan de map niet verwijderen. Het is niet leeg. Recursief verwijderen wordt niet ondersteund. Verwijder eerst de inhoud. + + + + Cannot delete root folder. It is not empty. Recursive deletion is not supported. Please delete the content first. + Kan de hoofdmap niet verwijderen. Het is niet leeg. Recursieve verwijdering wordt niet ondersteund. Verwijder eerst de inhoud. + + + + + The item cannot be moved to that location. + Het item kan niet worden verplaatst naar die locatie. + + + + There is nowhere to add item with name '{0}'. + Er is geen plek om item toe te voegen met de naam '{0}'. + + + + GuiProjectTreeMenu + + + Edit Project Item + Bewerk projectitem + + + + Open Document + Open document + + + + View Document + Document weergeven + + + + Toggle Included Flag + Toggle inbegrepen vlag + + + + New File + Nieuw bestand + + + + New Folder + Nieuwe map + + + + Delete Item + Item verwijderen + + + + Empty Trash + Leeg prullenbak + + + + Move Item Up + Verplaats item omhoog + + + + Move Item Down + Verplaats item omlaag + + + + GuiUpdates + + + Check for Updates + Controleren op updates + + + + Current Release + Huidige versie + + + + + novelWriter {0} released on {1} + novelWriter {0} uitgebracht op {1} + + + + Latest Release + Nieuwste versie + + + + Checking ... + Wordt gecontroleerd... + + + + Download: {0} + Download: {0} + + + + GuiWordList + + + + Project Word List + Project woordenlijst + + + + Cannot add a blank word. + Kan geen blanco woord toevoegen. + + + + The word '{0}' is already in the word list. + Het woord '{0}' staat al op de woordenlijst. + + + + GuiWritingStats + + + Writing Statistics + Schrijf Statistieken + + + + Session Start + Sessie start + + + + Length + Lengte + + + + Idle + Inactief + + + + Words + Woorden + + + + Histogram + Histogram + + + + Sum Totals + Som totalen + + + + Total Time: + Totale tijd: + + + + Idle Time: + Inactief tijd: + + + + Filtered Time: + Gefilterde tijd: + + + + Novel Word Count: + Roman woord telling: + + + + Notes Word Count: + Notities woord telling: + + + + Total Word Count: + Totaal woord telling: + + + + Filters + Filters + + + + Count novel files + Roman bestanden meetellen + + + + Count note files + Notitiebestanden tellen + + + + Hide zero word count + Verberg nul woorden aantal + + + + Hide negative word count + Negatieve woordtelling verbergen + + + + Group entries by day + Vermeldingen groeperen per dag + + + + Show idle time + Inactieve tijd weergeven + + + + Word count cap for the histogram + Woorden tellingslimiet voor het histogram + + + + Save As + Opslaan als + + + + JSON Data File (.json) + JSON gegevensbestand (.json) + + + + CSV Data File (.csv) + CSV-gegevensbestand (.csv) + + + + JSON Data File + JSON gegevensbestand + + + + CSV Data File + CSV-gegevensbestand + + + + Save Data As + Gegevens opslaan als + + + + {0} file successfully written to: + {0} bestand succesvol geschreven naar: + + + + Failed to write {0} file. + Schrijven van {0} bestand mislukt. + + + + Failed to read session log file. + Kon sessie log bestand niet lezen. + + + + NWProject + + + Duplicate root item detected. + Duplicaat root item gedetecteerd. + + + + + New + Nieuw + + + + Note + Notitie + + + + Draft + Concept + + + + Finished + Voltooid + + + + Minor + Klein + + + + Major + Groot + + + + Main + Hoofd + + + + New Project + Nieuw Project + + + + By + Door + + + + + Novel + Roman + + + + Plot + Plot + + + + Characters + Personages + + + + World + Wereld + + + + + Title Page + Titel pagina + + + + + + New Chapter + Nieuw hoofdstuk + + + + + New Scene + Nieuwe scène + + + + Chapter {0} + Hoofdstuk {0} + + + + + Scene {0} + Scène {0} + + + + File not found: {0} + Bestand niet gevonden: {0} + + + + + Failed to parse project xml. + Parsen van project xml mislukt. + + + + Attempting to open backup project file instead. + Poging om in plaats daarvan het reservekopiebestand van het project te openen. + + + + + Unknown + Onbekend + + + + Project file does not appear to be a novelWriterXML file. + Projectbestand lijkt geen novelWriter XML-bestand te zijn. + + + + Unknown or unsupported novelWriter project file format. The project cannot be opened by this version of novelWriter. The file was saved with novelWriter version {0}. + Onbekend of niet ondersteund bestandsformaat van novelWriter. Het project kan niet worden geopend door deze versie van novelWriter. Het bestand was opgeslagen met versie {0} van novelWriter. + + + + File Version + Bestands versie + + + + The file format of your project is about to be updated. If you proceed, older versions of novelWriter will no longer be able to open this project. Continue? + De bestandsindeling van uw project zal worden bijgewerkt. Als u doorgaat, kunnen oudere versies van novelWriter dit project niet meer openen. Doorgaan? + + + + Version Conflict + Versie conflict + + + + This project was saved by a newer version of novelWriter, version {0}. This is version {1}. If you continue to open the project, some attributes and settings may not be preserved, but the overall project should be fine. Continue opening the project? + Dit project was aangemaakt door een nieuwere versie van novelWriter, versie {0}. Dit is versie {1}. Als je het project blijft openen, kunnen sommige kenmerken en instellingen niet worden behouden, maar over het algemeen moet het project goed zijn. Doorgaan met het openen van het project? + + + + Opened Project: {0} + Geopend project: {0} + + + + Project path not set, cannot save project. + Projectpad niet ingesteld, project kan niet worden opgeslagen. + + + + + Failed to save project. + Opslaan project mislukt. + + + + Saved Project: {0} + Project opgeslagen: {0} + + + + Backing up project ... + Project back-uppen... + + + + Cannot backup project because no valid backup path is set. Please set a valid backup location in Preferences. + Kan geen back-up maken van project omdat er geen geldig backup pad is ingesteld. Stel een geldige back-up locatie in in Voorkeuren. + + + + Cannot backup project because no project name is set. Please set a Working Title in Project Settings. + Kan geen back-up maken van een project omdat er geen projectnaam is ingesteld. Stel een werktitel in bij Projectinstellingen. + + + + Could not create backup folder. + Kan de back-up map niet maken. + + + + Cannot backup project because the backup path is within the project folder to be backed up. Please choose a different backup path in Preferences. + Kan geen back-up maken van het project omdat het back-up pad zich in de projectmap bevindt. Kies een ander backup pad in Voorkeuren. + + + + Backup from {0} + Reservekopie van {0} + + + + Backup archive file written to: {0} + Reservekopie archief bestand weggeschreven naar: {0} + + + + Could not write backup archive. + Kon reservekopie archief niet wegschrijven. + + + + Project backed up to '{0}' + Project reservekopie gemaakt naar '{0}' + + + + + Failed to create a new example project. + Aanmaken van een nieuw voorbeeldproject is mislukt. + + + + Failed to create a new example project. Could not find the necessary files. They seem to be missing from this installation. + Aanmaken van een nieuw voorbeeldproject is mislukt. Kon de benodigde bestanden niet vinden. Ze lijken te ontbreken in deze installatie. + + + + Could not create new project folder. + Kon geen nieuwe projectmap aanmaken. + + + + New project folder is not empty. Each project requires a dedicated project folder. + Nieuwe projectmap is niet leeg. Elk project vereist een eigen projectmap. + + + + You must set a valid backup path in Preferences to use the automatic project backup feature. + U moet een geldig reservekopie pad instellen in de Voorkeuren om de automatische project reservekopie functie te kunnen gebruiken. + + + + You must set a valid project name in Project Settings to use the automatic project backup feature. + U moet een geldige projectnaam instellen in Projectinstellingen om de automatische project reservekopie functie te kunnen gebruiken. + + + + and + en + + + + Could not create folder. + Kon de map niet aanmaken. + + + + Found {0} orphaned file(s) in project folder. + {0} weesbestand(en) gevonden in de projectmap. + + + + Recovered + Hersteld + + + + [{0}] {1} + [{0}] {1} + + + + Recovered File {0} + Hersteld bestand {0} + + + + One or more orphaned files could not be added back into the project. Make sure at least a Novel root folder exists. + Een of meer verweesde bestanden konden niet aan het project worden terug gevoegd. Zorg ervoor dat er tenminste een Roman hoofdmap bestaat. + + + + Not a folder: {0} + Is geen map: {0} + + + + Could not move: {0} + Kon niet verplaatsen: {0} + + + + + Could not delete: {0} + Kon niet verwijderen: {0} + + + + Could not make folder: {0} + Kon map niet maken: {0} + + + + Could not move item {0} to {1}. + Kon item {0} niet verplaatsen naar {1}. + + + + ProjWizardCustomPage + + + Custom Project Options + Aangepaste projectopties + + + + Select which additional root folders to make, and how to populate the Novel folder. If you don't want to add chapters or scenes, set the values to 0. You can add scenes without chapters. + Selecteer welke extra hoofdmappen aan te maken en hoe de Roman map gevuld moet worden. Als je geen hoofdstukken of scènes wilt toevoegen, stel de waarden in op 0. Je kunt scènes toevoegen zonder hoofdstukken. + + + + Additional Root Folders + Aanvullende hoofdmappen + + + + + + + + + {0} folder + {0} map + + + + Populate Novel Folder + Roman map vullen + + + + Add chapters + Hoofdstukken toevoegen + + + + Scenes (per chapter) + Scènes (per hoofdstuk) + + + + Add chapter folders + Hoofdstukmappen toevoegen + + + + ProjWizardFinalPage + + + Finished + Voltooid + + + + All done. + Alles is klaar. + + + + Press '{0}' to create the new project. + Druk op '{0}' om het nieuwe project aan te maken. + + + + Done + Voltooid + + + + Finish + Voltooien + + + + ProjWizardFolderPage + + + + Select Project Folder + Selecteer projectmap + + + + Select a location to store the project. A new project folder will be created in the selected location. + Selecteer een locatie om het project op te slaan. Een nieuwe projectmap zal worden gemaakt op de geselecteerde locatie. + + + + Required + Vereist + + + + Project Path + Project pad + + + + ProjWizardIntroPage + + + Create New Project + Nieuw project maken + + + + Provide at least a working title. The working title should not be change beyond this point as it is used by the application for generating file names for for instance backups. The other fields are optional and can be changed at any time in Project Settings. + Geef ten minste een werk titel op. De werktitel mag niet worden gewijzigd na dit punt, omdat het wordt gebruikt door de applicatie voor het genereren van bestandsnamen voor, bijvoorbeeld, reservekopieën. De andere velden zijn optioneel en kunnen op elk gewenst moment worden gewijzigd in Projectinstellingen. + + + + Side image by {0}, {1} + Zijbeeld door {0}, {1} + + + + Required + Vereist + + + + Optional + Optioneel + + + + Optional. One name per line. + Optioneel. Eén naam per regel. + + + + Working Title + Werk titel + + + + Novel Title + Roman titel + + + + Author(s) + Auteur(s) + + + + ProjWizardPopulatePage + + + Populate Project + Project bevolken + + + + Choose how to pre-fill the project. Either with a minimal set of starter items, an example project explaining and showing many of the features, or show further custom options on the next page. + Kies hoe het project vooraf moet worden ingevuld. Ofwel met een minimale set van starter items, een voorbeeldproject dat veel van de functies uitlegt en laat zien, of toon verdere aanpasbare opties op de volgende pagina. + + + + Fill the project with a minimal set of items + Vul het project met een minimale set items + + + + Fill the project with example files + Vul het project met voorbeeldbestanden + + + + Show detailed options for filling the project + Toon gedetailleerde opties voor het vullen van het project + + + + QDialogButtonBox + + + OK + OK + + + + QGnomeTheme + + + &OK + &OK + + + + &Save + &Opslaan + + + + &Cancel + &Annuleren + + + + &Close + &Sluiten + + + + Close without Saving + Sluiten zonder opslaan + + + + QPlatformTheme + + + OK + OK + + + + Save + Opslaan + + + + Save All + Alles opslaan + + + + Open + Openen + + + + &Yes + &Ja + + + + Yes to &All + Ja voor &alles + + + + &No + &Nee + + + + N&o to All + N&ee op alles + + + + Abort + Afbreken + + + + Retry + Opnieuw proberen + + + + Ignore + Negeren + + + + Close + Sluiten + + + + Cancel + Annuleren + + + + Discard + Weggooien + + + + Help + Help + + + + Apply + Toepassen + + + + Reset + Beginwaarden + + + + Restore Defaults + Standaardwaarden herstellen + + + + QWizard + + + Go Back + Ga terug + + + + < &Back + < &Terug + + + + Continue + Doorgaan + + + + &Next + &Volgende + + + + &Next > + &Volgende > + + + + Commit + Vastleggen + + + + Done + Gereed + + + + &Finish + Vol&tooien + + + + + Cancel + Annuleren + + + + Help + Help + + + + &Help + &Help + + + + Tokenizer + + + Synopsis + Synopsis + + + + Document '{0}' is too big ({1} MB). Skipping. + Document '{0}' is te groot ({1} MB). Overgeslagen. + + + + ERROR + FOUT + + + diff --git a/novelwriter/__init__.py b/novelwriter/__init__.py index 2ee812f4..0ae10566 100644 --- a/novelwriter/__init__.py +++ b/novelwriter/__init__.py @@ -60,9 +60,9 @@ __license__ = "GPLv3" __author__ = "Veronica Berglyd Olsen" __maintainer__ = "Veronica Berglyd Olsen" __email__ = "code@vkbo.net" -__version__ = "1.6.4" -__hexversion__ = "0x010604f0" -__date__ = "2022-09-29" +__version__ = "1.7-beta1" +__hexversion__ = "0x010700b1" +__date__ = "2022-05-17" __status__ = "Stable" __domain__ = "novelwriter.io" __url__ = "https://novelwriter.io" @@ -209,9 +209,9 @@ def main(sysArgs=None): # Check Packages and Versions errorData = [] errorCode = 0 - if sys.hexversion < 0x030600f0: + if sys.hexversion < 0x030700f0: errorData.append( - "At least Python 3.6 is required, found %s" % CONFIG.verPyString + "At least Python 3.7 is required, found %s" % CONFIG.verPyString ) errorCode |= 0x04 if CONFIG.verQtValue < 50300: diff --git a/novelwriter/assets/i18n/project_nl_NL.json b/novelwriter/assets/i18n/project_nl_NL.json index 644da56a..65f4eaca 100644 --- a/novelwriter/assets/i18n/project_nl_NL.json +++ b/novelwriter/assets/i18n/project_nl_NL.json @@ -2,104 +2,104 @@ "Synopsis": "Synopsis", "Comment": "Opmerking", "Notes": "Notities", - "0": "Nul", - "1": "Één", - "2": "Twee", - "3": "Drie", - "4": "Vier", - "5": "Vijf", - "6": "Zes", - "7": "Zeven", - "8": "Acht", - "9": "Negen", - "10": "Tien", - "11": "Elf", - "12": "Twaalf", - "13": "Dertien", - "14": "Veertien", - "15": "Vijftien", - "16": "Zestien", - "17": "Zeventien", - "18": "Achttien", - "19": "Negentien", - "20": "Twintig", - "21": "Eenentwintig", - "22": "Tweeentwintig", - "23": "Drieentwintig", - "24": "Vierentwintig", - "25": "Vijfentwintig", - "26": "Zesentwintig", - "27": "Zevenentwintig", - "28": "Achtentwintig", - "29": "Negenentwintig", - "30": "Dertig", - "31": "Eenendertig", - "32": "Tweeendertig", - "33": "Drieendertig", - "34": "Vierendertig", - "35": "Vijfendertig", - "36": "Zesendertig", - "37": "Zevenendertig", - "38": "Achtendertig", - "39": "Negenendertig", - "40": "Veertig", - "41": "Eenenveertig", - "42": "Tweeënveertig", - "43": "Drieenveertig", - "44": "Vierenveertig", - "45": "Vijfenveertig", - "46": "Zesenveertig", - "47": "Zevenenveertig", - "48": "Achtenveertig", - "49": "Negenenveertig", - "50": "Vijftig", - "51": "Eenenvijftig", - "52": "Tweeenvijftig", - "53": "Drieenvijftig", - "54": "Vierenvijftig", - "55": "Vijfenvijftig", - "56": "Zesenvijftig", - "57": "Zevenenvijftig", - "58": "Achtenvijftig", - "59": "Negenenvijftig", - "60": "Zestig", - "61": "Eenenzestig", - "62": "Tweeenzestig", - "63": "Drieenzestig", - "64": "Vierenzestig", - "65": "Vijfenzestig", - "66": "Zesenzestig", - "67": "Zevenenzestig", - "68": "Achtenzestig", - "69": "Negenenzestig", - "70": "Zeventig", - "71": "Eenenzeventig", - "72": "Tweeenzeventig", - "73": "Drieenzeventig", - "74": "Vierenzeventig", - "75": "Vijfenzeventig", - "76": "Zesenzeventig", - "77": "Zevenenzeventig", - "78": "Achtenzeventig", - "79": "Negenenzeventig", - "80": "Tachtig", - "81": "Eenentachtig", - "82": "Tweeentachtig", - "83": "Drieentachtig", - "84": "Vierentachtig", - "85": "Vijfentachtig", - "86": "Zesentachtig", - "87": "Zevenentachtig", - "88": "Achtentachtig", - "89": "Negenentachtig", - "90": "Negentig", - "91": "Eenennegentig", - "92": "Tweeennegentig", - "93": "Drieennegentig", - "94": "Vierennegentig", - "95": "Vijfennegentig", - "96": "Zesennegentig", - "97": "Zevenennegentig", - "98": "Achtennegentig", - "99": "Negenennegentig" + "0": "nul", + "1": "één", + "2": "twee", + "3": "drie", + "4": "vier", + "5": "vijf", + "6": "zes", + "7": "zeven", + "8": "acht", + "9": "negen", + "10": "tien", + "11": "elf", + "12": "twaalf", + "13": "dertien", + "14": "veertien", + "15": "vijftien", + "16": "zestien", + "17": "zeventien", + "18": "achttien", + "19": "negentien", + "20": "twintig", + "21": "eenentwintig", + "22": "tweeëntwintig", + "23": "drieëntwintig", + "24": "vierentwintig", + "25": "vijfentwintig", + "26": "zesentwintig", + "27": "zevenentwintig", + "28": "achtentwintig", + "29": "negenentwintig", + "30": "dertig", + "31": "eenendertig", + "32": "tweeëndertig", + "33": "drieëndertig", + "34": "vierendertig", + "35": "vijfendertig", + "36": "zesendertig", + "37": "zevenendertig", + "38": "achtendertig", + "39": "negenendertig", + "40": "veertig", + "41": "eenenveertig", + "42": "tweeënveertig", + "43": "drieënveertig", + "44": "vierenveertig", + "45": "vijfenveertig", + "46": "zesenveertig", + "47": "zevenenveertig", + "48": "achtenveertig", + "49": "negenenveertig", + "50": "vijftig", + "51": "eenenvijftig", + "52": "tweeënvijftig", + "53": "drieënvijftig", + "54": "vierenvijftig", + "55": "vijfenvijftig", + "56": "zesenvijftig", + "57": "zevenenvijftig", + "58": "achtenvijftig", + "59": "negenenvijftig", + "60": "zestig", + "61": "eenenzestig", + "62": "tweeënzestig", + "63": "drieënzestig", + "64": "vierenzestig", + "65": "vijfenzestig", + "66": "zesenzestig", + "67": "zevenenzestig", + "68": "achtenzestig", + "69": "negenenzestig", + "70": "zeventig", + "71": "eenenzeventig", + "72": "tweeënzeventig", + "73": "drieënzeventig", + "74": "vierenzeventig", + "75": "vijfenzeventig", + "76": "zesenzeventig", + "77": "zevenenzeventig", + "78": "achtenzeventig", + "79": "negenenzeventig", + "80": "tachtig", + "81": "eenentachtig", + "82": "tweeëntachtig", + "83": "drieëntachtig", + "84": "vierentachtig", + "85": "vijfentachtig", + "86": "zesentachtig", + "87": "zevenentachtig", + "88": "achtentachtig", + "89": "negenentachtig", + "90": "negentig", + "91": "eenennegentig", + "92": "tweeënnegentig", + "93": "drieënnegentig", + "94": "vierennegentig", + "95": "vijfennegentig", + "96": "zesennegentig", + "97": "zevenennegentig", + "98": "achtennegentig", + "99": "negenennegentig" } diff --git a/novelwriter/assets/icons/typicons_dark/icons.conf b/novelwriter/assets/icons/typicons_dark/icons.conf index e06aba68..568c5b24 100644 --- a/novelwriter/assets/icons/typicons_dark/icons.conf +++ b/novelwriter/assets/icons/typicons_dark/icons.conf @@ -42,16 +42,20 @@ doc_h2 = mixed_heading2.svg doc_h3 = mixed_heading3.svg doc_h4 = mixed_heading4.svg done = typ_input-checked.svg +down = typ_chevron-down.svg edit = typ_pencil.svg forward = typ_chevron-right.svg hash = typ_hash.svg maximise = typ_arrow-maximise.svg +menu = typ_th-menu.svg minimise = typ_arrow-minimise.svg proj_chapter = mixed_document-chapter.svg +proj_details = typ_th-list-grey.svg proj_document = typ_document-text.svg proj_folder = typ_folder.svg proj_note = mixed_document-note.svg proj_scene = mixed_document-scene.svg +proj_stats = typ_chart-bar-grey.svg proj_title = mixed_document-title.svg reference = typ_at.svg refresh = typ_refresh.svg @@ -74,3 +78,15 @@ status_stats = typ_chart-bar-grey.svg status_time = typ_stopwatch-grey.svg sticky-off = typ_pin-outline.svg sticky-on = typ_pin.svg +up = typ_chevron-up.svg +view_build = typ_export.svg +view_editor = mixed_edit.svg +view_novel = typ_book-grey.svg +view_outline = typ_puzzle-outline.svg + +deco_doc_h0 = nw_deco-h0.svg +deco_doc_h1 = nw_deco-h1.svg +deco_doc_h2 = nw_deco-h2.svg +deco_doc_h3 = nw_deco-h3.svg +deco_doc_h4 = nw_deco-h4.svg +deco_doc_more = nw_deco-noveltree-more.svg diff --git a/novelwriter/assets/icons/typicons_dark/mixed_edit.svg b/novelwriter/assets/icons/typicons_dark/mixed_edit.svg new file mode 100644 index 00000000..fac03f3e --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/mixed_edit.svg @@ -0,0 +1,52 @@ + + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg new file mode 100644 index 00000000..3c1618c9 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h0.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg new file mode 100644 index 00000000..1c0dec9b --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h1.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg new file mode 100644 index 00000000..0f86e5bb --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h2.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg new file mode 100644 index 00000000..f05e46e6 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h3.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg new file mode 100644 index 00000000..aa74e6f3 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-h4.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/nw_deco-noveltree-more.svg b/novelwriter/assets/icons/typicons_dark/nw_deco-noveltree-more.svg new file mode 100644 index 00000000..f42d3306 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/nw_deco-noveltree-more.svg @@ -0,0 +1,30 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_book-grey.svg b/novelwriter/assets/icons/typicons_dark/typ_book-grey.svg new file mode 100644 index 00000000..a0f49771 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_book-grey.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_chevron-down.svg b/novelwriter/assets/icons/typicons_dark/typ_chevron-down.svg new file mode 100644 index 00000000..53389084 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_chevron-down.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_chevron-up.svg b/novelwriter/assets/icons/typicons_dark/typ_chevron-up.svg new file mode 100644 index 00000000..9ac7e927 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_chevron-up.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_export.svg b/novelwriter/assets/icons/typicons_dark/typ_export.svg new file mode 100644 index 00000000..6e36ed53 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_export.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_puzzle-outline.svg b/novelwriter/assets/icons/typicons_dark/typ_puzzle-outline.svg new file mode 100644 index 00000000..526feec8 --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_puzzle-outline.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_dark/typ_th-menu.svg b/novelwriter/assets/icons/typicons_dark/typ_th-menu.svg new file mode 100644 index 00000000..89434cdf --- /dev/null +++ b/novelwriter/assets/icons/typicons_dark/typ_th-menu.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/novelwriter/assets/icons/typicons_light/icons.conf b/novelwriter/assets/icons/typicons_light/icons.conf index 56e18b2a..1d6a6c0c 100644 --- a/novelwriter/assets/icons/typicons_light/icons.conf +++ b/novelwriter/assets/icons/typicons_light/icons.conf @@ -42,16 +42,20 @@ doc_h2 = mixed_heading2.svg doc_h3 = mixed_heading3.svg doc_h4 = mixed_heading4.svg done = typ_input-checked.svg +down = typ_chevron-down.svg edit = typ_pencil.svg forward = typ_chevron-right.svg hash = typ_hash.svg maximise = typ_arrow-maximise.svg +menu = typ_th-menu.svg minimise = typ_arrow-minimise.svg proj_chapter = mixed_document-chapter.svg +proj_details = typ_th-list-grey.svg proj_document = typ_document-text.svg proj_folder = typ_folder.svg proj_note = mixed_document-note.svg proj_scene = mixed_document-scene.svg +proj_stats = typ_chart-bar-grey.svg proj_title = mixed_document-title.svg reference = typ_at.svg refresh = typ_refresh.svg @@ -74,3 +78,15 @@ status_stats = typ_chart-bar-grey.svg status_time = typ_stopwatch-grey.svg sticky-off = typ_pin-outline.svg sticky-on = typ_pin.svg +up = typ_chevron-up.svg +view_build = typ_export.svg +view_editor = mixed_edit.svg +view_novel = typ_book-grey.svg +view_outline = typ_puzzle-outline.svg + +deco_doc_h0 = nw_deco-h0.svg +deco_doc_h1 = nw_deco-h1.svg +deco_doc_h2 = nw_deco-h2.svg +deco_doc_h3 = nw_deco-h3.svg +deco_doc_h4 = nw_deco-h4.svg +deco_doc_more = nw_deco-noveltree-more.svg diff --git a/novelwriter/assets/icons/typicons_light/mixed_edit.svg b/novelwriter/assets/icons/typicons_light/mixed_edit.svg new file mode 100644 index 00000000..982206ed --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/mixed_edit.svg @@ -0,0 +1,52 @@ + + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg new file mode 100644 index 00000000..3c1618c9 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-h0.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg new file mode 100644 index 00000000..e6c8efdc --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-h1.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg new file mode 100644 index 00000000..7caa4203 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-h2.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg new file mode 100644 index 00000000..61feca1b --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-h3.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg b/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg new file mode 100644 index 00000000..b76fd7da --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-h4.svg @@ -0,0 +1,35 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/nw_deco-noveltree-more.svg b/novelwriter/assets/icons/typicons_light/nw_deco-noveltree-more.svg new file mode 100644 index 00000000..f42d3306 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/nw_deco-noveltree-more.svg @@ -0,0 +1,30 @@ + + + + + + image/svg+xml + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_book-grey.svg b/novelwriter/assets/icons/typicons_light/typ_book-grey.svg new file mode 100644 index 00000000..06f58ae1 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_book-grey.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_chevron-down.svg b/novelwriter/assets/icons/typicons_light/typ_chevron-down.svg new file mode 100644 index 00000000..6ba80643 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_chevron-down.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_chevron-up.svg b/novelwriter/assets/icons/typicons_light/typ_chevron-up.svg new file mode 100644 index 00000000..1b9eb901 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_chevron-up.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_export.svg b/novelwriter/assets/icons/typicons_light/typ_export.svg new file mode 100644 index 00000000..537f71f9 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_export.svg @@ -0,0 +1,38 @@ + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_puzzle-outline.svg b/novelwriter/assets/icons/typicons_light/typ_puzzle-outline.svg new file mode 100644 index 00000000..e2792d41 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_puzzle-outline.svg @@ -0,0 +1,31 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/novelwriter/assets/icons/typicons_light/typ_th-menu.svg b/novelwriter/assets/icons/typicons_light/typ_th-menu.svg new file mode 100644 index 00000000..cfc8a1d9 --- /dev/null +++ b/novelwriter/assets/icons/typicons_light/typ_th-menu.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/novelwriter/assets/text/lipsum.txt b/novelwriter/assets/text/lipsum.txt new file mode 100644 index 00000000..f9743e26 --- /dev/null +++ b/novelwriter/assets/text/lipsum.txt @@ -0,0 +1,100 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus diam nibh, tincidunt et quam at, fringilla malesuada risus. Nullam eleifend, sem nec varius tincidunt, urna mi varius dolor, sit amet gravida risus eros at purus. Etiam vehicula hendrerit elit, sit amet pulvinar dolor viverra sed. Curabitur metus ex, gravida at sodales sed, tristique eget diam. Suspendisse ultricies lorem sed ullamcorper rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis tempus magna mi, sit amet sagittis arcu viverra ut. +Fusce in pretium tellus. Donec finibus vitae arcu at consectetur. Suspendisse et ultricies nisl. Integer et nisi vel sem aliquam scelerisque. Curabitur placerat massa et mi feugiat vulputate. In ac orci vitae risus dictum porttitor quis ut dui. Vivamus egestas condimentum risus quis fermentum. Nam lorem ante, rhoncus vel porttitor in, sodales in purus. Mauris ultricies ex metus, molestie ullamcorper arcu suscipit id. +Cras dapibus porta eros, a tincidunt sapien mattis sit amet. Pellentesque ac metus in dui accumsan tristique eget eu tellus. Nam laoreet sapien vitae hendrerit ullamcorper. Mauris accumsan semper dui vitae pellentesque. Donec non velit cursus, eleifend nulla a, porttitor tellus. Donec elementum lobortis imperdiet. Etiam fermentum pretium arcu, sed consequat dui mattis nec. Mauris cursus fringilla magna, at pharetra justo. Sed tincidunt consequat urna, quis varius lacus dapibus id. Fusce sagittis lorem vitae sodales tempor. Ut vel feugiat lacus, in iaculis risus. Aliquam viverra tortor nec nibh tristique varius. Mauris interdum leo vitae massa sagittis venenatis. +Quisque cursus eu orci at viverra. Donec libero libero, sagittis a sagittis vitae, efficitur sed nibh. Donec imperdiet malesuada est. Etiam consequat quam arcu, quis egestas libero sagittis a. Donec purus urna, volutpat id ante nec, iaculis maximus velit. Vivamus malesuada lacus sed velit consequat fringilla. Pellentesque ornare accumsan aliquam. Suspendisse tempor vel nisi quis iaculis. Curabitur porta ligula ac libero molestie, nec viverra ex feugiat. Donec lacinia eget lorem eu lacinia. Maecenas vestibulum ornare dui a aliquet. +Proin id lobortis nunc, ut feugiat urna. Nam dictum odio tortor, bibendum sollicitudin erat suscipit eu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Suspendisse eu imperdiet lectus. Nullam faucibus elit leo, sit amet pulvinar diam iaculis ac. Pellentesque accumsan vulputate orci sed ornare. Fusce at tortor ac libero volutpat tempus nec a diam. Nam eu libero tristique, rutrum magna suscipit, malesuada ligula. +Praesent suscipit imperdiet arcu vitae faucibus. Phasellus massa mauris, pharetra at posuere vel, fringilla sed quam. Morbi nec congue ante, vel vulputate massa. Suspendisse imperdiet mollis dignissim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pulvinar odio tellus, non cursus turpis malesuada sit amet. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque ex lorem, hendrerit ac enim et, tempor sodales ante. Curabitur quis tristique mauris, quis imperdiet metus. Mauris tristique interdum congue. Phasellus finibus condimentum pretium. Sed et tellus vel quam molestie aliquet. +Phasellus sagittis ligula nibh, nec hendrerit libero maximus et. Morbi vestibulum, tortor non efficitur semper, velit lacus molestie augue, ac volutpat elit ante ac augue. Pellentesque ut tristique odio, vel ornare eros. Nunc at ullamcorper arcu, in ornare risus. Vivamus sed libero auctor, vulputate lectus ut, luctus lectus. Maecenas finibus at nulla vel congue. Nullam finibus mauris leo, ac volutpat sem pulvinar eget. Maecenas in posuere tellus, in placerat est. Ut at est semper, ullamcorper ligula ac, volutpat nisi. Donec tempus tellus sed lorem posuere, a rutrum odio faucibus. Donec porta sem ac tortor vulputate, sed pharetra sapien convallis. Praesent ac feugiat odio. In risus eros, pharetra sit amet porta eu, lacinia vel nunc. +Praesent consectetur tincidunt mauris ut dignissim. Aenean sagittis ornare mi at sagittis. Proin id suscipit ipsum. Mauris lacinia commodo molestie. Fusce nec pharetra purus. Nulla eget velit varius, tincidunt erat tincidunt, cursus odio. Aliquam accumsan risus non nibh hendrerit fermentum. Aliquam erat volutpat. Phasellus non tincidunt lacus. Quisque sagittis augue eu egestas maximus. Integer sed eleifend neque, nec finibus sapien. Aliquam malesuada urna nec justo sodales dignissim. Cras volutpat maximus euismod. Pellentesque consequat lorem non augue placerat dignissim. Ut dolor nisl, malesuada sed nunc quis, malesuada dignissim nibh. Nam hendrerit hendrerit sapien quis auctor. +Aenean feugiat enim eros, interdum tincidunt eros aliquam sit amet. Fusce hendrerit mi vulputate nisi vestibulum tempor. Vestibulum at dui et nisl viverra condimentum id sit amet leo. Phasellus vitae leo commodo, blandit magna ut, commodo enim. Donec ex elit, mattis non tincidunt quis, posuere ut sapien. Aliquam lacus mauris, commodo sed libero vitae, rhoncus sodales massa. Phasellus commodo, leo sit amet sollicitudin luctus, massa purus aliquet lectus, at rutrum nulla ante eget felis. Nulla facilisi. Aenean cursus ut diam non volutpat. Aliquam nec erat non ipsum ultricies hendrerit. Phasellus blandit ac lacus non laoreet. Etiam ultricies risus mauris, a volutpat nibh cursus in. Maecenas viverra odio sit amet libero feugiat tempor. Nullam eu tristique magna. Praesent sed lacus ligula. +Sed iaculis viverra mollis. Phasellus sed eros sit amet lectus vulputate ornare sed non dui. Donec pretium dui quis felis feugiat elementum. Quisque eleifend eget nunc eu cursus. Etiam finibus lectus non ipsum ornare malesuada. Integer nec eros ullamcorper, pharetra neque at, suscipit ex. Nam faucibus sapien est, vel viverra ante viverra a. +Ut quis euismod lorem. Fusce auctor quam eu velit semper, sed pretium odio semper. Fusce vehicula porta dignissim. Integer suscipit ultrices ultricies. Aenean pharetra cursus sem. Suspendisse ut porttitor neque. In luctus purus sagittis risus gravida pulvinar. Integer eu ante convallis, pharetra velit vel, sodales urna. Curabitur pretium sapien arcu, eget dignissim neque ornare in. Vivamus eget metus et diam pulvinar aliquam vel eu turpis. Donec augue metus, dapibus eu porta a, faucibus in felis. Etiam sodales arcu a ex fermentum, sit amet rutrum est auctor. Integer gravida lorem in mauris tincidunt lobortis. +Etiam lobortis dictum dapibus. Nulla tincidunt placerat aliquam. Mauris non ornare nisi. Integer hendrerit ornare nibh, non vehicula sapien maximus eu. Proin purus erat, dapibus id dui commodo, blandit sodales mauris. Sed a vulputate lectus. Curabitur vel tincidunt orci. Vivamus cursus augue non nisl dictum, eget venenatis mi eleifend. Integer in ultricies ligula. Phasellus et sodales est, eget mollis magna. Sed lacinia, ligula eget feugiat ullamcorper, eros ipsum dignissim sapien, in suscipit mauris odio at metus. Suspendisse eget felis eu nulla porttitor dignissim at eu felis. Duis pulvinar est mauris, sit amet volutpat lacus hendrerit non. Aliquam finibus rhoncus mauris. Nunc dui nunc, lacinia aliquam finibus ut, maximus quis odio. Sed tempus dui vel orci vehicula, a tristique risus consectetur. +Ut egestas velit eu urna imperdiet cursus. Aenean blandit pretium turpis, quis sollicitudin lacus dignissim eu. In eu orci posuere, volutpat velit et, varius velit. Mauris rutrum sem nunc, nec sagittis lectus accumsan at. Morbi vestibulum est ut dolor maximus, non euismod magna consequat. Morbi pharetra gravida velit ac suscipit. Fusce vitae turpis eget ante tempus bibendum. Integer sollicitudin vulputate neque eu pulvinar. Etiam consequat pulvinar lorem eu dignissim. Fusce luctus id lacus ut fermentum. Vestibulum ligula neque, finibus et aliquam vel, consequat id lacus. Quisque pretium elit a tincidunt aliquam. +Maecenas varius magna in dictum dapibus. Vestibulum eget mattis velit, ac accumsan tellus. Donec luctus lorem in nisl convallis, eget egestas erat varius. Phasellus et lacinia dui. Praesent id nunc elementum, ultricies dolor a, pulvinar tellus. In a auctor mi, in fermentum justo. Proin sit amet vulputate leo, eu ultrices sem. Integer at sagittis ex, eu scelerisque velit. +Curabitur auctor mollis nunc quis venenatis. Cras lectus ligula, auctor in tellus eget, aliquet molestie odio. Vivamus vel venenatis sem. Sed ac purus suscipit, pulvinar sapien sed, commodo arcu. Donec eget metus ipsum. Quisque posuere congue hendrerit. Phasellus eu scelerisque ipsum, ut vulputate diam. Curabitur sollicitudin tortor sapien, a finibus arcu consequat non. Suspendisse tempus magna porttitor mauris laoreet, quis tincidunt lectus iaculis. Fusce nibh magna, finibus ac enim at, volutpat dapibus metus. Duis iaculis sapien non erat vestibulum auctor. +Maecenas nec porta leo. Fusce aliquam massa sit amet blandit interdum. Donec malesuada enim in eros laoreet iaculis. Integer fermentum faucibus nunc, et congue massa mattis eu. Pellentesque sed sodales orci. Praesent pulvinar lacus eget turpis condimentum imperdiet. Nullam molestie, ipsum a molestie accumsan, lectus quam sodales eros, malesuada faucibus ex leo malesuada velit. Fusce molestie ligula at sapien dictum semper non rutrum sapien. Ut facilisis gravida ante nec faucibus. Sed aliquet luctus auctor. In tempor libero at eleifend convallis. Phasellus in tristique ligula. Vestibulum eget quam dapibus, luctus enim vel, sagittis eros. Cras laoreet sapien diam, eu posuere nisl blandit quis. +Vestibulum bibendum a massa ac faucibus. Maecenas vestibulum arcu id diam mattis, non varius orci aliquet. Vivamus sit amet ultrices velit. Donec vitae lorem vel lectus dignissim porta. Sed ac dui dui. Suspendisse lectus ante, pellentesque non euismod vel, finibus ut erat. Vestibulum accumsan facilisis velit, at posuere velit malesuada at. Mauris aliquam tortor sed pretium viverra. Ut et porttitor ex. In quis tellus vitae neque dignissim finibus nec eu dolor. Phasellus viverra nulla a vestibulum auctor. Praesent in lorem gravida, mattis enim commodo, volutpat tellus. Quisque non urna ac eros sollicitudin blandit sit amet ut risus. Integer sed diam a metus tristique consectetur vitae non velit. Aliquam justo est, pharetra vel libero in, molestie varius enim. +Fusce vestibulum auctor varius. Maecenas malesuada, purus quis congue vehicula, arcu purus congue nunc, non convallis felis magna quis nisi. Curabitur nisi diam, imperdiet et sollicitudin quis, ultricies nec enim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rutrum, lectus at condimentum condimentum, felis justo lacinia orci, non venenatis nisl ex sed enim. Aenean semper ligula a diam cursus, ac sollicitudin ligula pretium. Etiam eleifend lorem nec massa tempor sollicitudin. Phasellus dignissim velit dignissim mauris vestibulum, sit amet sagittis sem blandit. Donec lobortis varius nunc sit amet posuere. Cras eu est lobortis, aliquet nisi in, varius mauris. Curabitur vitae leo laoreet sem condimentum vestibulum et eget enim. Nullam sed turpis ac nunc ornare tristique sit amet vel arcu. Cras efficitur ullamcorper lorem, et scelerisque lectus volutpat a. Maecenas ut urna in lacus rutrum volutpat. +Pellentesque pretium, neque quis cursus sagittis, justo mauris euismod turpis, non feugiat lacus augue a magna. Nam ornare dictum erat et consequat. Vivamus fringilla odio velit, vitae convallis arcu vulputate et. Maecenas tristique purus ac velit cursus fringilla. Suspendisse id blandit dui, eu facilisis metus. Proin a erat rutrum, tempus lectus ut, consequat nisi. In dui sem, bibendum nec nibh nec, sollicitudin varius ipsum. Nulla id lectus eu eros placerat faucibus eget nec nunc. Nullam urna lectus, tempus nec libero a, egestas malesuada enim. +Curabitur vestibulum a nibh eget varius. Sed lacus ipsum, porta sit amet egestas sit amet, pellentesque a dui. Etiam auctor mollis orci, eget pulvinar magna tristique quis. Proin condimentum ornare nibh, sed interdum orci congue at. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas quis lacinia tellus. Nullam ac nibh auctor, fermentum velit ac, rutrum ipsum. Nam egestas sodales hendrerit. +Suspendisse a feugiat mauris. Nunc eget nisi augue. Suspendisse pharetra justo sit amet sollicitudin tincidunt. Duis pretium, leo quis euismod sagittis, ex ante sodales purus, vel tempor odio nisi ut diam. Praesent odio erat, ultricies et eros ac, pulvinar aliquet justo. Pellentesque non vestibulum sem, a vulputate purus. Nunc rutrum nulla vitae mattis pharetra. Integer dui diam, pulvinar sit amet velit bibendum, aliquet dictum nulla. Nam ut magna et lorem ornare dignissim eget quis mauris. Vestibulum aliquet mi ac rutrum varius. Mauris a imperdiet eros. Curabitur lobortis lectus vitae leo aliquam auctor. Ut et tincidunt dui. +Mauris luctus risus eu tempor pulvinar. Mauris et mi nec ligula imperdiet vulputate a congue ex. Proin et venenatis mauris. Vivamus viverra accumsan lorem at gravida. Aliquam non pretium ante. Morbi aliquam risus sapien, quis consequat tellus maximus vitae. Sed consequat libero in molestie faucibus. Donec vestibulum arcu a sodales volutpat. Nullam ultricies ante quis quam accumsan rutrum. Quisque eu egestas velit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu risus vestibulum enim iaculis pellentesque iaculis eu ligula. Nam rutrum, mauris sit amet efficitur eleifend, massa quam consequat metus, eget sodales leo sem eget risus. Aliquam dui libero, maximus at dui nec, consectetur maximus ligula. Sed gravida erat eget tristique lobortis. +Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean turpis velit, vestibulum a consequat vitae, efficitur id urna. Cras dapibus dui et scelerisque luctus. Sed vel malesuada justo. Suspendisse molestie iaculis lacus eu tempor. Praesent laoreet lectus quis malesuada volutpat. Fusce consectetur mollis ligula, a lobortis justo suscipit id. Integer eget tellus in arcu viverra accumsan eu et odio. Praesent ut felis risus. Pellentesque convallis felis et quam condimentum, at pellentesque nulla eleifend. Sed eget efficitur dui. Vivamus congue, leo eu lacinia condimentum, erat mi dignissim purus, sit amet convallis lorem sem sed ligula. Duis viverra leo enim, in pharetra felis consectetur viverra. Integer euismod feugiat ipsum eget vestibulum. Morbi fermentum dui vitae tincidunt dictum. +Phasellus non eros ut ipsum pretium condimentum. Vestibulum tristique convallis aliquam. Phasellus tempor leo sit amet diam tristique, a auctor urna hendrerit. Mauris at velit euismod, sollicitudin mi at, scelerisque est. Mauris pulvinar consequat quam, eget varius augue tincidunt id. Curabitur turpis lectus, eleifend a egestas id, malesuada non diam. Proin aliquet tellus urna, venenatis consequat tortor finibus et. Quisque at tempor magna. +Donec nec congue erat. Donec mauris lorem, dignissim euismod massa non, egestas pulvinar est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean aliquam venenatis eleifend. Vivamus consectetur ante et fringilla sodales. Nam vestibulum felis non sapien suscipit consectetur et interdum velit. Sed at placerat massa. Proin quis leo lectus. Integer diam velit, gravida quis rhoncus eget, tempor at ante. Aliquam pharetra dictum mi ac venenatis. Nunc volutpat id magna a pellentesque. In rutrum leo et ligula finibus, ut pretium lorem tristique. Curabitur vel orci iaculis, pellentesque justo et, ullamcorper orci. Quisque erat ante, venenatis ac lacinia ut, maximus ac odio. Aliquam varius bibendum varius. +Duis ipsum orci, semper sit amet volutpat quis, scelerisque a nunc. Donec iaculis, erat vitae malesuada rutrum, nisl leo gravida nisi, et dignissim eros eros at mi. Cras volutpat est erat. Maecenas ex felis, porttitor vitae egestas sit amet, tincidunt efficitur tortor. Curabitur ac purus massa. Etiam porta maximus tristique. Morbi placerat pulvinar lectus sed tempus. Morbi fringilla odio posuere, volutpat mi sed, congue lorem. Cras convallis volutpat eros mattis vestibulum. Ut sit amet sodales eros, ac condimentum purus. Vivamus et elit augue. Pellentesque efficitur gravida ullamcorper. Sed non faucibus tellus, et consectetur urna. Pellentesque at turpis fringilla ipsum interdum hendrerit eu in dui. Nullam dictum eget metus non sollicitudin. Proin facilisis tincidunt euismod. +Nunc et dui porta, suscipit mi vitae, pretium ante. Mauris a accumsan magna. Fusce tincidunt, nunc ut ullamcorper laoreet, nibh risus dignissim eros, a maximus arcu nunc congue arcu. Vivamus imperdiet quam lorem, vulputate consequat ante aliquet id. Sed porttitor mollis ullamcorper. Praesent dui justo, hendrerit quis vulputate sit amet, vulputate id libero. Etiam quam odio, dictum sit amet nisi in, semper placerat erat. Vivamus lacinia augue a dolor tincidunt dignissim. Curabitur ut massa sit amet elit tincidunt maximus. +Integer sed lorem ac lacus tincidunt condimentum quis vel diam. Etiam vitae justo interdum, accumsan ex vel, pretium magna. Aenean id turpis malesuada, semper nisi vel, hendrerit leo. Vestibulum feugiat neque nec lacus auctor efficitur. Ut quis lobortis lacus, sit amet tempor orci. Donec a fringilla sem, nec sollicitudin ex. Sed vel faucibus libero. Sed pharetra leo sed porta ullamcorper. In auctor semper metus, id semper nunc rutrum a. Morbi rhoncus nulla quis ex condimentum, vel congue lectus tempor. Duis a venenatis est. Etiam dolor justo, rhoncus at lobortis quis, malesuada at quam. Donec facilisis convallis mi vitae rhoncus. Integer est ipsum, sollicitudin eu nulla in, accumsan egestas nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nunc finibus sagittis nisl, et luctus ex. +In molestie est luctus magna hendrerit, non tristique felis ultricies. Curabitur non lectus placerat, tincidunt ipsum quis, mollis nunc. Nam lacinia ullamcorper hendrerit. Fusce porttitor nisi laoreet, elementum velit vitae, venenatis mi. Aliquam venenatis dui ac justo varius fermentum. Etiam nec ligula eu neque aliquam placerat mollis ac dolor. Pellentesque gravida, enim commodo tempus faucibus, lorem nibh vulputate arcu, sodales pellentesque metus ligula volutpat sem. In scelerisque nisi ac ante lacinia auctor. +Nunc at sodales libero, ut rutrum elit. Etiam vitae venenatis metus. Nullam faucibus turpis nisl. Maecenas varius sit amet lectus a ornare. Cras eget tortor mauris. Phasellus mattis nec tortor non sagittis. Integer eget placerat massa. Praesent eu porttitor leo. Vivamus sed bibendum sapien, sit amet maximus libero. Donec at lobortis lacus. +Maecenas convallis eros nibh, nec pellentesque magna lacinia vulputate. Donec posuere neque ut lacinia iaculis. Quisque varius dictum condimentum. Aliquam lacinia elit sed sem porttitor tempus a ac ipsum. Aliquam suscipit ex vel tellus mollis, nec suscipit nunc ullamcorper. Cras urna magna, feugiat a odio a, pharetra congue velit. Proin quis hendrerit odio. Proin non orci ut sem ultricies sodales. Morbi dictum orci non enim tempor, ut condimentum erat maximus. Nam sagittis ornare lacus, at sodales dolor porttitor nec. Mauris dignissim ipsum in massa rutrum blandit. Nulla sit amet ante vestibulum, pharetra tellus eu, elementum tortor. Donec nec fringilla mi. +Donec rhoncus odio a iaculis ullamcorper. Nam condimentum volutpat ante quis viverra. Vestibulum malesuada nibh tincidunt rutrum interdum. Sed dapibus et nisl vel ornare. Nunc ullamcorper nibh nec commodo eleifend. Nulla facilisi. Nullam ut est auctor ligula viverra dictum pellentesque id odio. Aenean eleifend ullamcorper mollis. Morbi quis rutrum dolor, vel dignissim purus. In vel metus scelerisque, auctor est quis, efficitur orci. Donec volutpat dui eu vulputate maximus. In hac habitasse platea dictumst. Quisque vel vulputate lorem. Phasellus lacinia tempus lectus, sed tristique magna hendrerit eu. Nullam non metus euismod dolor fringilla imperdiet et vitae purus. Sed varius ex tortor, vel rutrum turpis sagittis ac. +Sed nec tincidunt turpis, sit amet suscipit nisi. Curabitur ultrices orci ligula, nec cursus eros placerat non. Pellentesque faucibus venenatis nisi in condimentum. Morbi facilisis mauris odio, id facilisis ex dictum ut. Duis bibendum ultricies elit, sit amet dapibus risus ultricies quis. Nulla eget ullamcorper risus, ac imperdiet nulla. Proin ultrices nisi eu turpis elementum hendrerit. Maecenas euismod pretium quam accumsan finibus. Morbi augue enim, laoreet nec nunc id, lobortis hendrerit lorem. Nunc mattis cursus dui vel lacinia. Aenean massa tellus, laoreet sit amet turpis vel, pharetra facilisis dui. +Nunc sit amet tellus vel ligula vulputate dapibus. Donec non congue nisi. Mauris risus elit, vehicula a imperdiet a, tempor gravida ipsum. Sed erat magna, volutpat ac nunc sit amet, aliquam lobortis est. Mauris quis urna sem. Sed risus justo, vestibulum ac pharetra in, dignissim id nibh. Etiam nibh justo, auctor in tellus euismod, rhoncus lobortis dolor. Proin felis lectus, hendrerit nec dignissim nec, molestie a lorem. Phasellus commodo pellentesque ligula nec imperdiet. In quis sem a erat euismod elementum at sit amet sem. +Praesent tortor enim, iaculis sit amet placerat in, sodales non erat. Phasellus porttitor, massa vel posuere tincidunt, mauris magna ultrices mi, in aliquet sapien sapien ut libero. Sed accumsan odio ut mollis dignissim. Aliquam varius egestas condimentum. Etiam id massa condimentum, scelerisque velit sed, vulputate augue. Duis mollis augue eu felis venenatis dapibus. Vivamus non gravida nulla. Integer a mi mollis, pharetra ipsum eget, tincidunt sapien. +Phasellus libero arcu, aliquet rutrum commodo vel, efficitur quis libero. Morbi sed eros ante. Quisque efficitur leo eget nulla lobortis, eget imperdiet sem vehicula. Nunc commodo lorem sit amet felis aliquam, non facilisis velit tristique. Aliquam dapibus rutrum dignissim. Phasellus elementum nulla a enim venenatis, at ornare sapien feugiat. Proin ut sem eu nulla rutrum volutpat non non quam. Fusce vel pellentesque lectus, vitae pellentesque est. Praesent sit amet dolor non purus feugiat pharetra. Donec ullamcorper diam vitae sem varius, eget imperdiet nisi viverra. Fusce fermentum dui risus. Etiam sed diam ut libero sollicitudin faucibus at in sapien. Suspendisse bibendum purus at urna vehicula, sed maximus nisi pharetra. Proin posuere nisl ac consectetur sollicitudin. Nam auctor in ex scelerisque imperdiet. +Donec consequat arcu non lacus ullamcorper, a fermentum felis lobortis. Nunc tempor est quam, ut finibus odio rutrum sit amet. Proin hendrerit tincidunt nunc, sed tincidunt nisi tempor eget. Phasellus maximus a risus ut luctus. Duis libero enim, varius a tellus vitae, dignissim facilisis felis. Vestibulum iaculis tempor condimentum. Sed mollis velit justo, quis mollis lectus imperdiet sed. Quisque laoreet eget eros porta imperdiet. Curabitur pretium velit quis sapien placerat, in blandit metus suscipit. Ut pretium urna lectus, sed interdum arcu fermentum et. +Sed euismod nunc quam, nec tincidunt dui tempus at. Mauris molestie, quam vel lobortis dignissim, justo sem porta orci, nec commodo enim orci eget dolor. Pellentesque eros risus, fermentum non urna et, ultrices pharetra augue. Curabitur at tincidunt arcu. Etiam vel sollicitudin libero. Nulla dapibus orci odio, sit amet mattis quam sodales ac. Sed iaculis at eros volutpat egestas. In at fringilla massa. Proin at mattis turpis. Phasellus non metus et leo fermentum pretium non nec odio. Ut ante orci, interdum vel gravida eget, mollis in tortor. Sed rutrum ornare arcu in efficitur. Nulla facilisi. +Aenean vestibulum nisl sed eleifend ullamcorper. Suspendisse viverra imperdiet nisi, sed imperdiet tortor vulputate ut. Nunc consequat nisi eu laoreet mollis. Quisque metus ante, fringilla at rutrum id, consectetur vel enim. Pellentesque posuere tempor urna, sit amet vulputate urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; In hac habitasse platea dictumst. Nullam quis elementum purus. Cras eleifend sed justo vitae faucibus. Morbi interdum neque vitae elementum sollicitudin. Etiam eleifend, sapien at interdum consectetur, ex mauris dictum sem, in convallis dolor felis sollicitudin augue. Curabitur id tortor ex. Mauris finibus, lectus convallis euismod congue, est tortor suscipit velit, ac dictum augue risus ut lectus. Vestibulum ultricies luctus hendrerit. Integer elit nibh, condimentum id tempus nec, euismod nec nunc. +Sed porttitor hendrerit eros vitae suscipit. Vestibulum quis est elit. Sed neque leo, condimentum quis condimentum sed, posuere ut ex. Suspendisse mattis est nunc, in ullamcorper felis pellentesque sed. In hac habitasse platea dictumst. Maecenas tempus et turpis vestibulum porttitor. Quisque nulla odio, rhoncus et porta ut, hendrerit non sapien. Proin consequat, ex sed consequat iaculis, magna dolor consequat dui, eget rhoncus magna lorem in turpis. Cras urna sem, tincidunt ac aliquet id, imperdiet vitae neque. Fusce ac risus nisi. In erat urna, feugiat ac purus non, volutpat pulvinar ipsum. Morbi ultricies eros at nulla ullamcorper, nec lobortis arcu convallis. In maximus efficitur quam id maximus. +Etiam posuere urna non diam accumsan tempor. Donec facilisis blandit leo sed convallis. Nullam ut nisl vel dolor varius accumsan vitae a dui. Nunc ullamcorper nunc ac rhoncus pretium. Mauris ac lectus urna. Phasellus quis interdum nisi. Suspendisse mi ex, mollis a euismod vel, pretium et est. Mauris condimentum in ipsum quis lacinia. Mauris scelerisque molestie nibh, auctor lobortis felis convallis ac. Praesent vestibulum luctus urna non tincidunt. Quisque id nisl pretium, bibendum nisl nec, gravida quam. Curabitur eget cursus purus, non commodo felis. Vestibulum non lectus nec quam auctor dictum. Curabitur molestie elit mi, non tempor nisi aliquam in. Etiam fringilla lacinia est. +Pellentesque eleifend pulvinar eros, quis pulvinar arcu fermentum sed. Nam augue lectus, malesuada id mattis nec, ullamcorper sed nisi. Phasellus volutpat nisl eu commodo feugiat. Morbi eget sapien iaculis, consectetur est in, tempus metus. Donec hendrerit lectus aliquam ex faucibus pellentesque. Praesent lobortis libero sit amet metus commodo faucibus. Sed gravida eget mi at finibus. +Vivamus nec ligula vitae augue auctor viverra. Sed vulputate eget libero a porta. Aenean nisl turpis, tincidunt et placerat sit amet, bibendum quis libero. Nullam ultrices a ex sit amet dapibus. Suspendisse id congue lorem. In viverra convallis neque. In facilisis dui quis rhoncus semper. Ut id imperdiet libero. Fusce condimentum, sem id elementum aliquam, quam augue tincidunt felis, at suscipit lorem eros eget augue. Suspendisse eros dui, consectetur a arcu in, hendrerit dapibus risus. Proin purus erat, tincidunt eget ante sit amet, consequat convallis erat. Praesent et ornare nisl, id vehicula nulla. +Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean dignissim pellentesque mi, consectetur ornare leo egestas vitae. Suspendisse dignissim sapien orci, sed vestibulum neque maximus at. Sed lobortis urna consequat, sollicitudin lectus eget, finibus ante. Phasellus accumsan dolor non porttitor gravida. Duis eget eros ac lectus blandit posuere. Quisque sagittis nibh nunc, eu egestas nisi cursus at. Praesent accumsan fringilla neque eget iaculis. Nunc vulputate tempus tellus non porta. Sed faucibus vel dui in posuere. Sed quam arcu, accumsan id placerat sollicitudin, congue in diam. +Cras sed nunc in turpis dignissim vehicula non a libero. Sed iaculis nulla fermentum lacinia porta. Pellentesque sit amet efficitur est. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis et ultrices justo. Etiam ut blandit nibh. In tempus lorem nec ultrices sagittis. Vivamus vel nulla faucibus, bibendum sapien ut, tristique diam. Donec pulvinar nisi nec semper blandit. Duis porttitor nibh enim, iaculis efficitur est sagittis a. Maecenas at eros ac quam pellentesque tempus nec ac magna. Donec pulvinar enim non congue facilisis. Donec eros orci, finibus vel lectus molestie, interdum scelerisque libero. Proin congue arcu lorem, in lobortis libero placerat vel. Nullam cursus est id lectus laoreet tempus et sed ex. Sed erat odio, molestie mattis egestas iaculis, sollicitudin eu ex. +Donec sodales metus ut mi suscipit, quis pretium lorem ultrices. Donec placerat ante at pellentesque vulputate. Etiam id augue vel eros facilisis interdum. Mauris imperdiet, arcu sit amet tincidunt posuere, risus quam luctus diam, eget tincidunt ipsum magna a mauris. In hac habitasse platea dictumst. Fusce lacinia sem ut ullamcorper tristique. Nunc mattis massa tellus, vitae lacinia sem tincidunt ut. Phasellus sodales justo ut ligula iaculis, sit amet ultricies arcu lacinia. Nam ac dignissim orci. Nullam nec orci nec est bibendum ultrices. Nam pulvinar consequat eros, ut laoreet massa blandit nec. Proin tristique venenatis pretium. Curabitur vitae dui est. Integer fermentum, ligula in faucibus porttitor, sem nunc rhoncus turpis, a faucibus lectus risus quis eros. Pellentesque et lorem eu dolor placerat interdum. Aliquam luctus scelerisque leo eu faucibus. +Vivamus id hendrerit odio, nec pellentesque magna. Proin augue eros, egestas nec eleifend ac, varius a sapien. Pellentesque viverra orci at condimentum euismod. Nam placerat lacus et augue porttitor blandit. Fusce scelerisque metus mollis nisl sollicitudin congue. Phasellus dictum velit arcu. Duis lacinia quam mauris, rhoncus porta enim dignissim posuere. Curabitur tempor urna eget ex cursus iaculis. Sed semper nisi nec nibh tempor pellentesque. Nulla vel turpis ac ipsum maximus porttitor eu sed nisl. Aliquam accumsan elit risus, eget sollicitudin ipsum lobortis at. Nulla sagittis faucibus sodales. Curabitur viverra pharetra quam quis efficitur. Integer eget justo maximus, dignissim magna vitae, consectetur metus. Suspendisse tincidunt, nunc eu vehicula faucibus, arcu felis accumsan velit, id rhoncus dui sapien vel purus. +Nullam lacinia urna commodo vehicula fringilla. Donec tellus est, bibendum a quam in, pellentesque auctor odio. Donec vehicula velit et leo consequat, sed eleifend mauris aliquam. Vivamus nibh ligula, blandit eu leo quis, pretium malesuada augue. Pellentesque at lacinia magna. Sed nec dolor porttitor, finibus erat ut, fringilla leo. Phasellus sed ex pellentesque, semper elit auctor, fermentum turpis. Vestibulum dictum sodales augue volutpat pretium. Integer pharetra volutpat nisl at dignissim. Mauris mattis, turpis nec volutpat maximus, sapien dolor elementum urna, ac iaculis neque dui non urna. Duis scelerisque magna nec nunc mattis maximus. In lobortis massa ante, non sagittis turpis viverra nec. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer viverra velit a fringilla sodales. +Suspendisse id arcu ut nisl ultrices convallis ornare in lectus. Nunc ultrices nulla vitae libero rutrum lobortis. Nullam hendrerit consectetur augue sit amet ornare. Cras dui est, pharetra at augue rhoncus, pharetra congue enim. Suspendisse maximus magna ut neque porta, in porttitor lorem pretium. Ut a dignissim magna, non tincidunt tortor. Vestibulum posuere tempus leo vitae blandit. Cras convallis ex a mi maximus fringilla a ac metus. Nunc sodales tincidunt semper. Praesent at risus eu neque tempus consectetur vel a odio. +Fusce bibendum ex a risus feugiat tincidunt. In ac volutpat quam, vestibulum molestie nibh. Maecenas pretium ultricies augue vitae luctus. Ut congue leo ante, consequat ullamcorper mi commodo sit amet. Duis et libero leo. Nam eu dictum sem, quis commodo tellus. Sed et dolor eu nisi varius sodales sed eu quam. Aenean eget auctor mauris, vitae faucibus nunc. Nam ultrices elit eu libero porta, vitae cursus odio aliquet. Vivamus sit amet interdum tellus. Suspendisse suscipit fringilla nisi, id scelerisque nisi aliquet vitae. Aliquam est nibh, commodo nec neque et, consequat ultrices nibh. Suspendisse efficitur id massa sed bibendum. Phasellus vitae posuere est. +Ut nec aliquet ex. Integer sapien nunc, tincidunt eu dolor ut, dictum pulvinar lorem. Donec nec augue nibh. Curabitur euismod, lorem ut mattis volutpat, nunc dui pharetra mauris, sed rutrum magna lacus non lacus. Nam ac rhoncus turpis, et dignissim erat. Fusce suscipit blandit mauris vel aliquam. Aenean id orci sed augue dapibus pellentesque ac ac sem. Nulla vel purus sapien. Integer vestibulum porttitor posuere. Mauris tincidunt elit nec risus tincidunt ornare. Duis bibendum, magna eu interdum bibendum, lectus nulla dictum dui, non condimentum sapien tortor sit amet orci. Integer ligula ligula, sodales vel nulla non, commodo semper eros. Quisque cursus tempus fringilla. Sed at nisl odio. Ut malesuada turpis ac libero consequat aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Suspendisse tempus magna et massa euismod faucibus. Pellentesque sollicitudin nisl in pharetra aliquam. Vestibulum blandit massa ut turpis ornare, nec imperdiet metus interdum. Fusce molestie aliquet justo, ac condimentum justo. Praesent quis dolor vestibulum, posuere arcu eget, molestie nisi. Donec ac urna tempor, tempus lectus non, scelerisque est. Aliquam imperdiet dictum urna, non malesuada urna. Proin et tellus quis sapien dignissim vehicula. Vestibulum tortor metus, iaculis ac eros ut, laoreet vulputate nibh. Cras tempor vitae erat eget consequat. Sed ut nisl convallis, placerat quam quis, tincidunt turpis. Suspendisse sit amet rutrum augue. Duis sem justo, dictum eu dui at, eleifend commodo orci. Curabitur at erat odio. Phasellus porttitor interdum nibh, sit amet aliquet libero. Etiam convallis mattis massa, a rhoncus ligula condimentum et. +Duis ut diam ac lectus viverra volutpat et eget dolor. Nam tincidunt mauris vitae aliquet laoreet. Nam id ipsum eget ante euismod vulputate. Mauris elementum, tellus vitae rutrum vestibulum, libero orci finibus risus, in lacinia libero massa vitae elit. Nam et vestibulum justo, sed gravida orci. In ultrices mollis ultricies. Pellentesque odio leo, sagittis lacinia odio eu, accumsan auctor nibh. In non sem elementum, mollis justo sed, ornare nisi. Fusce interdum lobortis turpis ut dictum. Integer lacinia mollis nunc, nec condimentum quam hendrerit in. +Donec condimentum, dolor in aliquet facilisis, leo ex feugiat nisi, a commodo libero urna id enim. Donec faucibus urna eget pulvinar dapibus. Curabitur ultricies justo at ligula aliquam blandit. Mauris nisi urna, porttitor eu bibendum vitae, ultrices eu risus. In ac pulvinar nisl. Vestibulum viverra tellus purus, eget rutrum arcu venenatis et. Pellentesque nibh risus, sagittis eu hendrerit eget, sollicitudin sit amet enim. Quisque molestie ornare tellus sit amet placerat. +Ut finibus metus sit amet velit posuere, in egestas massa congue. Nulla sagittis, nisi eget pretium vestibulum, mauris libero elementum mauris, vel sollicitudin ligula metus vitae elit. Sed feugiat lectus sed ante maximus pharetra. Praesent felis eros, gravida sed varius in, faucibus ut metus. Nulla eget pretium nulla. Aliquam ultricies viverra magna, vel semper ligula accumsan ut. Pellentesque sollicitudin bibendum pretium. Vivamus volutpat commodo eleifend. Maecenas ornare ac nisl at tristique. Vivamus tellus lectus, euismod nec pellentesque non, lobortis ut nunc. Quisque hendrerit mi eget hendrerit ultrices. +Nunc rhoncus ligula ac libero consequat, semper commodo eros feugiat. Phasellus iaculis neque vitae luctus porttitor. Pellentesque suscipit mi ac ipsum bibendum mollis id at velit. Curabitur consectetur sollicitudin tincidunt. In a enim convallis, consequat justo nec, dignissim urna. Sed nisl ex, semper vitae lectus non, laoreet volutpat purus. Suspendisse ut mattis urna, quis hendrerit odio. Sed tincidunt libero pulvinar sem rhoncus, eu elementum enim ornare. Proin eu placerat ex. Cras euismod sem at ullamcorper scelerisque. +Nam fringilla, velit in ultrices pellentesque, nisl magna tempor felis, vel congue purus lectus sed metus. Cras consectetur quis massa id bibendum. Praesent sed purus odio. Fusce volutpat dolor ut magna congue auctor. In at magna lacinia, bibendum nisi in, pellentesque nisl. Pellentesque metus ligula, malesuada non turpis et, vulputate ultrices lectus. Sed erat leo, maximus id elementum sagittis, lacinia a metus. Proin mattis id lorem non malesuada. Aliquam sodales quam id gravida condimentum. +Phasellus quis bibendum risus, at porttitor sem. Nulla aliquet molestie eros quis sagittis. Ut lorem massa, ullamcorper vitae odio in, hendrerit vehicula urna. Quisque et viverra ex. Aliquam erat volutpat. Curabitur at interdum elit, ut tincidunt erat. Pellentesque quis augue pellentesque, finibus ante eget, feugiat quam. Cras nec efficitur ligula. Cras porta ac ipsum in ullamcorper. Nulla nunc erat, egestas egestas rhoncus viverra, mattis quis purus. Morbi convallis fringilla iaculis. Ut a sem mi. Praesent at velit ac dui euismod pulvinar. Donec mollis vehicula lorem vel tempus. Duis et scelerisque magna. +Suspendisse sollicitudin a libero ut convallis. Donec interdum faucibus dolor, id imperdiet nibh mollis eget. Sed sem augue, bibendum nec risus quis, mollis scelerisque magna. Cras molestie velit eget est pulvinar, a pharetra sapien tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla accumsan semper arcu id porttitor. Sed lacinia massa ut nibh gravida consectetur. Donec semper ante sed scelerisque varius. Vestibulum ullamcorper varius dui, sed aliquam elit aliquam nec. Sed auctor, dui sit amet mollis egestas, libero neque interdum est, efficitur elementum nibh lacus sed libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam blandit lacus in lacinia tristique. +Suspendisse scelerisque posuere nunc, non consectetur orci facilisis in. Donec aliquet fermentum mattis. Morbi fringilla id urna eget consectetur. Vivamus turpis est, efficitur a tempus ac, ornare vel lorem. Aenean bibendum metus non ante rutrum sollicitudin. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. Suspendisse dui eros, sagittis nec ante in, gravida varius ante. Mauris sapien neque, lobortis et euismod vel, venenatis at risus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Maecenas vestibulum metus arcu, sed faucibus lacus ultrices eget. Integer porta aliquam bibendum. +Etiam tempus pulvinar dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed sed nulla vehicula, iaculis nibh sit amet, blandit urna. Maecenas metus ante, posuere vitae bibendum quis, consequat sit amet magna. Cras venenatis nunc urna, vel posuere diam congue eu. Cras sit amet ipsum laoreet, tincidunt nunc ac, convallis elit. Praesent lacinia enim nibh, et efficitur leo convallis vel. Etiam varius diam arcu, sit amet convallis dui interdum vitae. In hac habitasse platea dictumst. Nullam commodo maximus turpis, quis congue mauris fermentum quis. Donec laoreet elit non lorem gravida pharetra. Ut aliquam purus a semper sodales. +Donec nec sollicitudin nisi. Proin ipsum est, rhoncus vel commodo ut, tristique eget justo. Praesent tristique massa sed odio sodales viverra. Aliquam at nisi vel turpis pulvinar volutpat. Phasellus rhoncus scelerisque mollis. Nunc et cursus nulla, in consectetur magna. Praesent et mollis nibh, non tristique dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas malesuada odio velit, eget finibus mauris congue eget. Praesent vestibulum mollis ex id ultricies. Integer sodales tempus vulputate. Phasellus blandit quam quis tortor blandit convallis. Donec tempor mi id urna venenatis fermentum. +Vestibulum ut sapien non tellus eleifend vestibulum eu vitae magna. Donec in lectus eget nisi ornare efficitur sed ut ex. Cras volutpat metus rhoncus hendrerit fringilla. Vivamus rutrum rutrum neque, eu imperdiet augue malesuada a. Aenean tristique massa vel diam vehicula pulvinar sit amet vel velit. Aenean faucibus luctus magna, non auctor nunc tempor ut. Etiam eleifend auctor metus, ac rhoncus massa. Aenean dignissim ornare tincidunt. Donec pulvinar sapien ante, vel dignissim sapien dictum sed. In eu ante in tortor fringilla viverra sit amet quis metus. Aenean in ex elementum, gravida nunc non, pretium nibh. Donec laoreet arcu sit amet dolor tempus pulvinar. Nullam at pharetra nisl. Donec sed justo sed arcu luctus ultrices. Fusce at venenatis eros. +Maecenas placerat quam ut massa suscipit lacinia. Maecenas et posuere risus. Proin interdum, libero sit amet consectetur pulvinar, dolor magna dignissim velit, sed hendrerit nulla ex sed nisi. Morbi dictum lobortis velit. Proin molestie mi at tortor finibus, quis ullamcorper enim maximus. Nullam varius, urna id volutpat volutpat, ligula lectus placerat eros, id sollicitudin dolor ligula eget sem. Curabitur quis augue vitae neque egestas tristique. Nam lacus libero, viverra faucibus risus et, placerat vestibulum neque. +In et convallis ante. Nulla hendrerit turpis eget consequat molestie. Fusce pharetra nunc ornare leo commodo, eu consequat odio dictum. Cras est diam, consequat et eleifend sed, faucibus quis neque. Morbi fermentum sem non ipsum mollis, id tempus risus blandit. Phasellus vulputate, ante finibus molestie finibus, velit enim mattis neque, et posuere felis risus a nisl. Cras a risus eu eros porttitor malesuada. Maecenas in mattis diam, sed tempor ex. In hac habitasse platea dictumst. Aliquam in magna quis arcu ultrices fringilla. Cras rhoncus tortor sed lacus blandit commodo. Nullam placerat augue vitae diam rutrum, ut eleifend ligula pellentesque. Aenean blandit lectus orci, egestas dapibus nisi finibus at. +Quisque id dapibus nisi, in placerat ante. Sed ut feugiat arcu. Etiam facilisis augue in nisi placerat facilisis. Donec vitae porttitor nibh. Nulla et nisl id purus egestas lobortis non id lorem. Nam viverra vulputate sapien, et posuere ex tincidunt a. Pellentesque venenatis turpis non purus rutrum faucibus. Nam non dapibus sem, sit amet rutrum neque. Vestibulum tempor, libero et faucibus feugiat, metus tellus condimentum nunc, sit amet pretium diam est a ipsum. +Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed nulla neque, vulputate in aliquet quis, mollis non tellus. Ut aliquet lacus tellus, sed vehicula lectus aliquet ut. Nullam mattis in felis in condimentum. Vivamus facilisis, justo ac volutpat posuere, turpis ligula hendrerit tortor, eu ullamcorper quam dui non ex. Praesent feugiat, ligula eu aliquam interdum, mauris magna sagittis enim, eget facilisis felis lectus eget velit. In accumsan pharetra tincidunt. Sed mi massa, sodales nec nisi sed, lobortis fermentum ipsum. Nulla facilisi. Sed at accumsan felis. Donec sed condimentum metus, mollis gravida velit. +Nulla at lobortis nisl. Sed eu laoreet felis. Maecenas velit erat, mattis a condimentum eu, fermentum vel elit. Aenean mattis rutrum risus, in interdum metus volutpat sed. Nulla at dignissim lorem, in convallis tellus. Suspendisse ac risus sit amet diam ullamcorper feugiat. Maecenas sed lectus id erat cursus aliquam vel eget nisi. Ut tempus, risus id mollis lobortis, sem metus suscipit nibh, ut dapibus lectus tellus quis ipsum. In nec hendrerit nibh. In vel consectetur ex, a ullamcorper sem. Donec mauris massa, dictum non luctus a, feugiat eu metus. Donec maximus ex sit amet sem vehicula finibus egestas eget ex. Etiam volutpat ut nulla quis euismod. +Nunc consequat ut augue quis cursus. Aliquam placerat, enim eget scelerisque rhoncus, massa erat placerat tortor, ut varius dui felis in neque. Suspendisse potenti. Aliquam et magna tristique, volutpat sem eget, elementum lectus. Vivamus nunc velit, sagittis sed massa vel, vestibulum molestie urna. Cras at erat pharetra, porttitor turpis mattis, tempus magna. Nulla commodo enim mi, eu porttitor sapien pellentesque id. Aenean quis ligula eu mauris scelerisque porttitor quis ut orci. Praesent tincidunt risus mi. Nunc dignissim, arcu quis dictum consectetur, est massa imperdiet felis, ut scelerisque magna mi vel nisi. Mauris imperdiet, diam sit amet ultricies porttitor, odio sapien placerat ligula, in condimentum sem augue non justo. Duis a lorem augue. +Aenean vitae venenatis dolor, at ultricies purus. Vivamus velit urna, tempus vitae ornare id, semper in metus. In sed mi et odio pulvinar ultricies ut quis enim. Duis erat dolor, aliquam sed sodales id, porttitor vitae turpis. Fusce feugiat venenatis ex quis aliquet. Nulla pretium elit vel nisi suscipit condimentum. Nunc dapibus, mi id venenatis ultrices, libero purus rhoncus erat, a eleifend metus nisl at elit. +Aenean eget porttitor risus. Donec ac lacus feugiat, faucibus ante sed, convallis neque. Donec pharetra in sem eget congue. Quisque ac neque in urna varius interdum. Donec justo nisi, volutpat nec lobortis vitae, pulvinar sit amet lorem. Maecenas porttitor magna orci. In eleifend risus ut lectus facilisis aliquam. Nullam nibh nulla, sodales quis tempus sed, condimentum quis nulla. Proin vitae hendrerit ante. Morbi tincidunt pharetra metus, quis lobortis elit viverra sit amet. Vivamus mattis eros erat, ut semper velit pretium sed. Nulla ac vulputate leo. +Praesent at ex at lacus dictum viverra vel nec nisi. Duis maximus nisi et eleifend fringilla. Cras lacinia arcu id turpis dignissim posuere. Sed faucibus nisi dignissim, sagittis orci quis, dapibus metus. Nullam ultricies libero eu auctor finibus. Vestibulum auctor odio in tortor molestie interdum. Proin nec libero mi. Donec tempor dignissim velit a molestie. Duis feugiat cursus turpis, in dignissim justo imperdiet non. Suspendisse faucibus dui non viverra interdum. Nullam dignissim interdum egestas. Phasellus vitae eros quis lectus bibendum scelerisque. Donec dui mauris, iaculis non molestie a, elementum sed felis. Donec iaculis congue tempor. Vestibulum dolor nisi, maximus quis cursus ut, vulputate non orci. Maecenas nisi ex, maximus ut aliquam commodo, interdum sed lorem. +Cras sed vehicula risus, sed suscipit eros. Suspendisse scelerisque sapien sit amet volutpat porta. Sed sagittis orci eget feugiat eleifend. Nulla viverra ex vitae mauris lacinia imperdiet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum arcu augue, euismod non elit non, feugiat aliquet ligula. Nulla ut neque vehicula, malesuada ex sit amet, finibus sem. Maecenas eleifend molestie justo a lobortis. +Aliquam at erat vitae neque porttitor ullamcorper. Integer et rutrum leo. Vivamus dui erat, luctus at purus et, auctor tincidunt felis. Proin fermentum maximus dui quis tempor. Nullam pellentesque at ex eget mollis. In hac habitasse platea dictumst. Maecenas efficitur turpis malesuada vulputate dapibus. Integer id faucibus diam. Aliquam lectus turpis, mollis vitae dolor eget, mattis faucibus est. Vestibulum id libero at est congue facilisis. Pellentesque tellus mauris, bibendum eget dui id, sagittis maximus enim. Sed condimentum ac lectus vel vulputate. Praesent lectus orci, pharetra id metus nec, fermentum congue nulla. +Nunc vel sem sem. Integer varius tincidunt lorem, id porta massa venenatis porta. Maecenas dictum mollis pharetra. In ex justo, auctor ac tempus id, lacinia et erat. Fusce dignissim purus in metus facilisis, vitae congue nunc tempor. Nam a euismod elit. Vestibulum tincidunt sed orci et porta. Vestibulum eget dui id mi efficitur fermentum. +Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut quis lorem vitae dui ullamcorper iaculis eget sed purus. Maecenas at ex lectus. Donec ut ligula eros. Nulla consectetur sed ligula quis volutpat. Integer rhoncus, justo egestas molestie scelerisque, nibh nibh finibus neque, dapibus vulputate quam lectus interdum tortor. Donec ultrices, tellus et suscipit tempor, urna lectus congue lorem, porta laoreet nibh purus id nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse malesuada hendrerit turpis vel feugiat. Suspendisse at mi cursus, dictum ipsum in, tristique mi. Cras diam nisi, aliquam vel lacinia sed, vehicula id diam. Sed consectetur tempus massa, a pellentesque dolor posuere vel. Curabitur et finibus quam. Fusce orci magna, faucibus ac tellus id, fermentum tempor neque. Ut libero augue, egestas eget fringilla eget, suscipit vitae orci. +Nunc posuere nisi purus, a bibendum elit interdum id. Donec accumsan metus non rutrum porttitor. Donec in sollicitudin lorem. Sed porta magna et lobortis consequat. Sed eget tempus nibh. Ut sed ante vel ex interdum commodo. Fusce eget nisi nec mauris tristique scelerisque. Ut eleifend nunc ultrices mattis ultricies. Vivamus id sodales lacus. Vivamus dignissim elementum ante, sit amet ornare ipsum lacinia sit amet. Proin maximus pulvinar nibh vitae luctus. Sed at gravida metus, at ultricies eros. Integer porta velit auctor, dictum elit non, dictum dolor. +Suspendisse potenti. Morbi lobortis orci nisi, ac sollicitudin libero cursus sed. Integer vestibulum sem ac ante rutrum, at pellentesque tortor bibendum. Etiam at arcu et sapien molestie sodales. Nam fringilla turpis eget mi convallis, quis iaculis metus varius. Vivamus finibus purus ut nunc sodales pulvinar. Praesent varius, odio sed luctus tempus, orci augue sodales orci, a posuere nisi ante et justo. Ut ultricies rhoncus feugiat. Ut arcu massa, scelerisque vitae metus rhoncus, aliquet ultricies urna. +Nulla facilisi. Aliquam at porttitor quam. Pellentesque eu faucibus nunc. Sed nec leo leo. Integer cursus ex a magna lacinia interdum. Vivamus luctus lacinia odio in sollicitudin. Curabitur sem felis, condimentum sed nisi at, posuere ullamcorper arcu. Vivamus convallis vel nisl id suscipit. Maecenas semper dictum nibh, nec malesuada dolor semper id. Maecenas turpis massa, vulputate ac euismod quis, viverra id lorem. Integer imperdiet tincidunt bibendum. Donec laoreet viverra volutpat. Aliquam arcu elit, euismod vitae felis quis, venenatis commodo lectus. +Fusce mattis mi est. Proin augue dui, ultricies quis facilisis tristique, vehicula quis ex. Nunc blandit aliquet aliquet. Aliquam nibh sem, tempus a justo sit amet, viverra ullamcorper sem. Suspendisse potenti. Pellentesque quis risus eget ipsum tincidunt ornare ultrices at sapien. Phasellus viverra nec urna auctor dapibus. Curabitur id porttitor justo. Vestibulum risus sapien, dignissim vel libero ac, scelerisque fringilla risus. Donec porta at ex quis volutpat. Suspendisse potenti. Phasellus leo metus, pellentesque et laoreet sed, tempus ut ligula. Sed convallis elit libero, sed ornare odio mattis et. +Ut lobortis libero vel nibh dignissim ullamcorper. Curabitur sed tortor id leo bibendum dignissim at sit amet dolor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed vitae urna justo. Quisque in fringilla velit. Nullam venenatis laoreet tellus, sagittis sodales dolor facilisis ut. Integer tincidunt at est aliquet commodo. Cras sed urna ut sapien varius rhoncus. Duis pharetra a magna ut tincidunt. +Sed mattis nunc ut pulvinar sodales. Nullam bibendum, ex vulputate volutpat porttitor, sapien mi gravida augue, at scelerisque mi ipsum sit amet risus. Phasellus non lacus molestie, faucibus nibh vitae, bibendum ex. Mauris et elit ut augue tincidunt pellentesque. Vestibulum vehicula pretium magna in faucibus. In fringilla tincidunt nisi. Integer porta vehicula risus eu commodo. Quisque iaculis laoreet vestibulum. Donec vitae aliquam metus, a gravida purus. Integer sit amet ligula vitae tortor lacinia mollis. Phasellus leo tellus, mattis ut maximus quis, ultricies in mauris. Praesent a scelerisque quam. +Nunc tempor feugiat accumsan. Aliquam erat volutpat. Cras ut mi odio. Aenean sed purus sed nunc luctus tempor sit amet id ligula. Morbi nec faucibus neque, a luctus nisl. Maecenas aliquam lorem sed blandit maximus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. +In hac habitasse platea dictumst. Cras blandit nibh lacus, nec venenatis nulla elementum nec. Nam tincidunt posuere augue rhoncus mattis. Cras interdum tincidunt massa, ac tristique libero porta in. Integer hendrerit gravida nisi, ut fringilla ligula ullamcorper nec. Fusce erat nulla, ullamcorper vel pulvinar eget, feugiat molestie velit. Integer viverra sollicitudin velit, vitae accumsan orci aliquet ac. Suspendisse aliquet augue ac mollis hendrerit. Proin euismod sagittis metus ac pretium. Nam augue nulla, posuere ac tortor nec, ornare interdum risus. Proin non massa eros. Morbi aliquet ante et purus placerat faucibus. +Quisque pharetra dolor vitae magna vehicula fermentum quis nec odio. In commodo tincidunt turpis non scelerisque. Nam tempor consequat justo suscipit convallis. Sed sit amet augue at lorem porta eleifend sit amet sit amet velit. Fusce eu eros quis risus mattis vehicula eu at quam. Nulla faucibus elementum tincidunt. Sed in diam accumsan, blandit felis a, cursus mauris. +Nunc in hendrerit augue. Phasellus vel purus ullamcorper, auctor ante sed, auctor nisi. Nunc rutrum est erat, ut consequat elit mattis ac. Suspendisse potenti. Maecenas purus libero, pharetra quis vestibulum at, egestas eget enim. Vestibulum ut condimentum tortor. Aliquam vestibulum mattis placerat. Morbi non leo eu nisl maximus lobortis eget eget sapien. Donec sollicitudin ipsum nulla, non dignissim massa pretium sed. Nulla et molestie nibh, nec aliquet arcu. +Cras euismod ligula justo, at dignissim nibh mattis vitae. Integer bibendum sit amet urna vitae dapibus. Fusce gravida ut enim eget molestie. Quisque finibus nisl ut odio mattis, ut viverra justo pretium. Nunc convallis cursus tincidunt. Integer vel hendrerit orci. Donec leo orci, elementum at cursus a, eleifend a nisl. Nunc massa nunc, blandit non ex pretium, volutpat feugiat tortor. Phasellus gravida nibh ipsum, ac consequat ante eleifend eu. Nulla venenatis auctor efficitur. Vestibulum eleifend eros id nibh interdum, id tempus tortor molestie. Nam id finibus quam. Aenean eu vulputate ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur hendrerit mi ac venenatis suscipit. +Vestibulum lobortis maximus metus, a commodo massa ultricies et. Etiam ut lectus quis lacus euismod consequat. Maecenas tincidunt, felis dapibus aliquam gravida, est sapien tempus nibh, et rutrum dolor orci in dui. Proin tellus nisl, imperdiet mollis elit ac, gravida lacinia sapien. Aenean quis lectus id ante gravida lobortis. In sollicitudin et ex et facilisis. Curabitur in velit at augue commodo placerat. Nulla facilisi. Fusce facilisis est eu dolor rhoncus, a bibendum felis tincidunt. Sed sit amet feugiat ante. Sed accumsan, ipsum nec bibendum semper, justo elit dignissim magna, eu lacinia sem lorem sed justo. Etiam posuere sollicitudin nisi ac placerat. Duis maximus nisl nec nisi accumsan posuere. +Aliquam erat volutpat. Suspendisse tincidunt ut neque eu tincidunt. Nulla porttitor eu mi sed gravida. Maecenas in cursus nisl, et fringilla quam. Nulla posuere, turpis vel vestibulum condimentum, magna dui eleifend orci, nec semper metus risus id augue. Proin pretium risus id elit consequat tristique. Phasellus eget tortor eleifend, euismod arcu at, ullamcorper nibh. Etiam id ultricies dui, non mattis purus. Morbi sit amet mi diam. Nullam dictum erat vitae tortor lobortis imperdiet. Etiam venenatis ante non laoreet gravida. +Vestibulum eget egestas mauris. Nulla facilisi. Vivamus ut dignissim turpis. Nulla quis tincidunt libero. Ut eget metus eleifend, volutpat enim ac, semper metus. Nunc vel ex nec neque maximus rhoncus vel et orci. Ut vitae congue sem, et porttitor diam. +Duis sit amet est nec nibh scelerisque pellentesque ac in quam. Donec eget erat nec diam mattis feugiat eget a ex. Morbi interdum est non tortor accumsan porta. In hendrerit libero sit amet ex blandit, ut vestibulum quam dapibus. Integer quis velit id nibh tempor volutpat. Suspendisse euismod, sapien nec tempor malesuada, augue nunc tincidunt diam, et viverra dui massa sit amet velit. Proin efficitur, nisl non vulputate maximus, sapien nulla pharetra odio, vel eleifend neque velit at est. Phasellus leo sem, pharetra placerat lorem faucibus, pellentesque euismod mi. Nam vel diam neque. Praesent mollis feugiat magna vitae pellentesque. Proin elementum rhoncus ante, eget eleifend arcu volutpat quis. Fusce id enim sed odio mollis pulvinar sed a nulla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; +Aliquam vulputate justo ut arcu lacinia accumsan. Phasellus quis convallis arcu, vel viverra urna. Curabitur tincidunt nibh id iaculis facilisis. In tellus arcu, elementum vel luctus at, tempor quis magna. Morbi maximus, elit in pharetra lacinia, ex lorem imperdiet risus, eget vehicula sapien enim sed nunc. Aliquam faucibus sodales tortor, vel fermentum quam finibus eu. Duis non dolor accumsan, lobortis neque a, pharetra purus. Donec a tincidunt urna. Cras eleifend elit ac tortor dictum rutrum. Donec ut est et diam tristique pellentesque. In mattis diam justo, sit amet rutrum ante varius nec. Sed in orci sit amet neque finibus fermentum. Aenean risus lectus, laoreet vitae finibus non, semper non sem. Donec vel porttitor mi. Duis efficitur posuere odio, in facilisis magna fringilla et. Donec quis tristique erat. +Suspendisse mattis mattis mi at tristique. Ut ultricies sagittis iaculis. Aliquam sagittis, diam in commodo sagittis, odio nisl venenatis enim, suscipit venenatis felis diam vitae enim. Morbi a molestie urna, ac lacinia nunc. Nam quis metus augue. Fusce tristique orci ut euismod cursus. Pellentesque sed elit ac nisl placerat porttitor. Quisque molestie pharetra eros sed hendrerit. In tincidunt tellus in consequat ultricies. Nam condimentum sollicitudin aliquam. Nulla non odio urna. Aliquam gravida tincidunt erat at semper. Sed quis tempor turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. +Maecenas cursus massa tincidunt tortor placerat tempor. In justo nisl, posuere eu erat eget, vestibulum ultrices nulla. Vivamus vel est a erat gravida dapibus ut ac mauris. Integer eleifend gravida odio, aliquet tincidunt justo sollicitudin et. Ut ut ex in diam feugiat varius quis sit amet lectus. Aliquam sit amet nibh condimentum, sollicitudin neque id, vulputate orci. In vestibulum hendrerit libero, ut dapibus dui efficitur a. Aenean tristique at arcu id viverra. Maecenas cursus massa vel felis laoreet pretium. Praesent viverra tincidunt risus non sodales. Nulla id dignissim est, sed pharetra purus. Aliquam commodo, eros varius sagittis faucibus, diam lorem viverra erat, vel egestas ipsum dui sed turpis. Aenean placerat rhoncus nibh vel finibus. +Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut porttitor, nulla sed pharetra laoreet, lacus orci molestie mi, sed ullamcorper felis arcu id sapien. Curabitur et commodo velit. In pharetra arcu at augue pulvinar, commodo elementum augue condimentum. Sed mattis ipsum sed tempor faucibus. Donec non dolor sed purus ultrices condimentum sit amet vel nisi. Cras dignissim tellus et sapien porta elementum. Maecenas in eros vel orci congue dignissim. Donec et luctus libero. Phasellus vitae porttitor nisi. Donec a nibh nisi. Nulla in nibh nec tellus accumsan pretium. Aenean ultrices id est blandit malesuada. Integer blandit metus sed suscipit scelerisque. In ac urna cursus, vehicula justo nec, facilisis metus. Vivamus id scelerisque diam. +In egestas nulla non tortor viverra laoreet. Fusce porttitor sem urna, sed varius justo maximus a. Duis ligula libero, elementum quis viverra mattis, vehicula nec sem. Aenean ut libero eu est auctor placerat. Nam quam dui, accumsan eget ipsum in, ornare volutpat purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc blandit, justo ut fermentum tincidunt, ex dolor suscipit eros, sed pretium lacus dolor vel tortor. Aliquam erat volutpat. +Phasellus sagittis risus nec accumsan congue. Maecenas enim elit, mattis sit amet enim tristique, vestibulum sodales leo. Curabitur vel vehicula velit. Proin elementum dui at purus pulvinar, et dictum nisl sagittis. Nulla aliquet quam ultrices dapibus rutrum. Integer ultrices dapibus mauris, a vehicula elit posuere ut. Nullam lacinia mattis nulla, dignissim aliquam massa consequat at. Mauris ut mi dictum, iaculis urna rhoncus, euismod massa. Phasellus elementum libero id turpis imperdiet dictum. Nunc ac ipsum vitae orci ullamcorper tempus. Quisque lacinia quam sed molestie sagittis. Aenean sed rutrum sapien, et scelerisque sem. +Suspendisse tincidunt, leo in vulputate rhoncus, neque augue feugiat purus, ac tempor libero nisi vitae ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aenean at augue quis ante porttitor blandit vitae non magna. Donec vel ligula hendrerit, sodales massa et, placerat libero. Etiam lectus felis, luctus et varius hendrerit, dignissim at massa. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus velit tortor, rutrum ut tristique non, feugiat at turpis. In iaculis leo metus, eu laoreet nunc viverra vel. Nam porttitor vitae diam vel pellentesque. In ullamcorper nulla id purus cursus accumsan. Etiam et mi turpis. Praesent volutpat sem odio, vitae dapibus libero posuere ac. Mauris dignissim ultricies felis, eu vestibulum turpis fringilla vitae. Sed porttitor ornare consectetur. Nulla id justo mollis, iaculis leo sit amet, bibendum eros. Donec ac interdum sapien. +Praesent dolor urna, tincidunt a neque eu, hendrerit luctus odio. Pellentesque ac odio in est maximus maximus. Donec et lectus aliquet massa egestas euismod cursus et magna. Nam id mi hendrerit, rutrum eros iaculis, sodales enim. Nullam porttitor urna ac malesuada tincidunt. Suspendisse a turpis sapien. Curabitur rhoncus vel libero ut volutpat. Nam a sapien sem. Duis ac convallis eros, ut auctor nulla. +Interdum et malesuada fames ac ante ipsum primis in faucibus. In sagittis lorem vitae est laoreet dictum. Integer posuere est ac tortor sagittis, quis mattis ligula laoreet. Curabitur urna sem, finibus id euismod at, varius ac sem. Donec tristique tristique est, a dictum lorem ornare eu. Praesent tempor diam ligula, at placerat leo placerat nec. Nam eget dui vulputate, vestibulum nisi ut, vehicula dui. Aenean elementum tincidunt lectus at vestibulum. Nam tristique mauris sit amet sapien iaculis facilisis. Nam accumsan, nibh ac aliquam venenatis, dolor lacus pretium dolor, accumsan feugiat lectus tellus facilisis sem. Nullam a dui sit amet tortor elementum rhoncus. Aliquam mattis eget quam et lobortis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Suspendisse ultricies, magna eu imperdiet efficitur, tellus sapien suscipit massa, sit amet finibus dolor libero vitae ante. Maecenas vel aliquam massa. diff --git a/novelwriter/assets/text/release_notes.htm b/novelwriter/assets/text/release_notes.htm index 1cc14d48..aeb5fbc7 100644 --- a/novelwriter/assets/text/release_notes.htm +++ b/novelwriter/assets/text/release_notes.htm @@ -2,73 +2,16 @@ -

Release Notes for 1.6

-

Released on 20 February 2022

+

Release Notes for 1.7 Beta 1

+

Released on 17 May 2022

-

This release does not introduce any major new features, but is instead a collection of minor -improvements and tweaks based on user requests. There are also a number of changes under the hood -to improve the structure and performance of novelWriter.

-

Some key improvements to the user interface are:

-

✓ The max text width setting in Preferences now also applies to the document viewer, and -the setting itself on the Preference dialog has been simplified a bit.

-

✓ When text is selected in the document editor, the number of words selected is displayed -in the editor's footer area.

-

✓ The search tool in the document editor now shows the number of results in the -document.

-

✓ The Enter and Ctrl+O keyboard shortcuts should now work the same way in all tree -views.

-

✓ It is now possible to set a blank section title format on the Build Novel Project tool -and get empty paragraphs in the output. Previously, a blank format would just remove the section -break entirely. This change allows the user to define hard and soft scene breaks using level three -and four headings. The scene and section titles can be hidden completely with two new switches -added to the user interface.

-

Other feature changes include:

-

✓ The project index is now automatically rebuilt in the event it is empty or incomplete -when the project is opened.

-

✓ The user can now add their own syntax and GUI theme files in the app folder in their -user area on the host operating system. Where the custom files must be added is described in the -documentation.

-

✓ A Windows installer is yet again provided for novelWriter. If you have novelWriter -installed using another method, make sure you uninstall it properly first as the two methods are -not compatible.

-

✓ Release versions for Ubuntu 21.04 have been dropped, and added for the upcoming Ubuntu -22.04.

-

✓ Most translations have been updated. A Dutch translation is in the works.

+

This is a beta release of the next release version, and is intended for testing purposes. Please +be careful when using this version on live writing projects, and make sure you take frequent +backups.

+

Please check the changelog for an overview of changes. The full release notes will be added to +the final release.

See also the Releases page.

-

Patch Notes

- -

Patch 1.6.1 – 16 March 2022

- -

This is a bugfix and patch release that fixes two recursion/loop issues. One would potentially -cause a crash if the window was resized rapidly, and one would cause a hang with certain search -parameters in the editor's search box. The Latin American Spanish translation has also been -updated.

- -

Patch 1.6.2 – 20 March 2022

- -

This is a bugfix release that fixes a couple of minor issues. Projects containing one or more -empty documents would trigger a rebuild of the index each time the project was opened. This has now -been fixed. Another fix resolves an error message being written to the console logging output when -a new document was created. Both errors were harmless.

- -

Patch 1.6.3 – 18 August 2022

- -

This is a bugfix release that fixes a rare problem causing novelWriter to crash if the spell -checker language setting was configured to an empty value.

-

A few other minor issues have also been fixed: The project language setting is now properly -exported to ODT documents. Spaces are no longer inserted automatically in front of colons in -certain meta data settings when the feature is enabled (it is primarily used for French). Lastly, -the slider splitting the editor and viewer panels can no longer be dragged until the viewer -disappears. It was not necessarily obvious how the viewer panel could be restored in such cases. -

- -

Patch 1.6.4 – 29 September 2022

- -

This is a bugfix release that fixes a critical bug in the insert non-breaking spaces feature. It -basically no longer worked in the 1.6.3 release. This release also fixes a minor issue where the -text cursor sometimes disappears when reaching the right-hand edge of the text editor window.

- diff --git a/novelwriter/assets/themes/default_dark.conf b/novelwriter/assets/themes/default_dark.conf index 14d0ad51..44317ac1 100644 --- a/novelwriter/assets/themes/default_dark.conf +++ b/novelwriter/assets/themes/default_dark.conf @@ -10,7 +10,7 @@ licenseurl = https://creativecommons.org/licenses/by-sa/4.0/ window = 54, 54, 54 windowtext = 174, 174, 174 base = 62, 62, 62 -alternatebase = 67, 67, 67 +alternatebase = 78, 78, 78 text = 174, 174, 174 tooltipbase = 255, 255, 192 tooltiptext = 21, 21, 13 diff --git a/novelwriter/assets/themes/solarized_dark.conf b/novelwriter/assets/themes/solarized_dark.conf index 81a85a16..812d968d 100644 --- a/novelwriter/assets/themes/solarized_dark.conf +++ b/novelwriter/assets/themes/solarized_dark.conf @@ -10,7 +10,7 @@ licenseurl = https://github.com/altercation/solarized/blob/master/LICENSE window = 0, 43, 54 windowtext = 253, 246, 227 base = 7, 54, 66 -alternatebase = 67, 67, 67 +alternatebase = 0, 43, 54 text = 253, 246, 227 tooltipbase = 133, 153, 0 tooltiptext = 0, 43, 54 diff --git a/novelwriter/common.py b/novelwriter/common.py index 8d6f9a8c..69f6bc05 100644 --- a/novelwriter/common.py +++ b/novelwriter/common.py @@ -184,6 +184,12 @@ def checkIntRange(value, first, last, default): return default +def minmax(value, minVal, maxVal): + """Make sure an integer is between min and max value (inclusive). + """ + return min(maxVal, max(minVal, value)) + + def checkIntTuple(value, valid, default): """Check that an int is an element of a tuple. If it isn't, return the default value. @@ -241,23 +247,17 @@ def formatTime(tS): return "ERROR" -def parseTimeStamp(theStamp, default, allowNone=False): - """Parses a text representation of a timestamp and converts it into - a float. Note that negative timestamps cause an OSError on Windows. - See https://bugs.python.org/issue29097 - """ - if str(theStamp).lower() == "none" and allowNone: - return None - try: - return datetime.strptime(theStamp, nwConst.FMT_TSTAMP).timestamp() - except Exception: - return default - - # =============================================================================================== # # String Functions # =============================================================================================== # +def simplified(string): + """Take a string an strip leading and trailing whitespaces, and + replace all occurences of (multiple) whitespaces with a 0x20 space. + """ + return " ".join(str(string).strip().split()) + + def splitVersionNumber(value): """Split a version string on the form aa.bb.cc into major, minor and patch, and computes an integer value aabbcc. diff --git a/novelwriter/config.py b/novelwriter/config.py index e52a7bd7..81487a16 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -96,8 +96,6 @@ class Config: # Sizes self.winGeometry = [1200, 650] self.prefGeometry = [700, 615] - self.treeColWidth = [200, 50, 30] - self.novelColWidth = [200, 50] self.projColWidth = [200, 60, 140] self.mainPanePos = [300, 800] self.docPanePos = [400, 400] @@ -117,7 +115,7 @@ class Config: # Text Editor self.textFont = None # Editor font self.textSize = 12 # Editor font size - self.textWidth = 600 # Editor text width + self.textWidth = 700 # Editor text width self.textMargin = 40 # Editor/viewer text margin self.tabWidth = 40 # Editor tabulator width @@ -460,8 +458,6 @@ class Config: cnfSec = "Sizes" self.winGeometry = theConf.rdIntList(cnfSec, "geometry", self.winGeometry) self.prefGeometry = theConf.rdIntList(cnfSec, "preferences", self.prefGeometry) - self.treeColWidth = theConf.rdIntList(cnfSec, "treecols", self.treeColWidth) - self.novelColWidth = theConf.rdIntList(cnfSec, "novelcols", self.novelColWidth) self.projColWidth = theConf.rdIntList(cnfSec, "projcols", self.projColWidth) self.mainPanePos = theConf.rdIntList(cnfSec, "mainpane", self.mainPanePos) self.docPanePos = theConf.rdIntList(cnfSec, "docpane", self.docPanePos) @@ -581,8 +577,6 @@ class Config: theConf["Sizes"] = { "geometry": self._packList(self.winGeometry), "preferences": self._packList(self.prefGeometry), - "treecols": self._packList(self.treeColWidth), - "novelcols": self._packList(self.novelColWidth), "projcols": self._packList(self.projColWidth), "mainpane": self._packList(self.mainPanePos), "docpane": self._packList(self.docPanePos), @@ -811,20 +805,6 @@ class Config: self.confChanged = True return True - def setTreeColWidths(self, colWidths): - """Set the column widths of the main project tree. - """ - self.treeColWidth = [int(x/self.guiScale) for x in colWidths] - self.confChanged = True - return True - - def setNovelColWidths(self, colWidths): - """Set the column widths of the novel tree. - """ - self.novelColWidth = [int(x/self.guiScale) for x in colWidths] - self.confChanged = True - return True - def setProjColWidths(self, colWidths): """Set the column widths of the Load Project dialog. """ @@ -910,12 +890,6 @@ class Config: def getPreferencesSize(self): return [int(x*self.guiScale) for x in self.prefGeometry] - def getTreeColWidths(self): - return [int(x*self.guiScale) for x in self.treeColWidth] - - def getNovelColWidths(self): - return [int(x*self.guiScale) for x in self.novelColWidth] - def getProjColWidths(self): return [int(x*self.guiScale) for x in self.projColWidth] @@ -978,12 +952,12 @@ class Config: """ try: import enchant # noqa: F401 - self.hasEnchant = True - logger.debug("Checking package 'pyenchant': OK") - except Exception: + except ImportError: self.hasEnchant = False logger.debug("Checking package 'pyenchant': Missing") - + else: + self.hasEnchant = True + logger.debug("Checking package 'pyenchant': OK") return # END Class Config diff --git a/novelwriter/constants.py b/novelwriter/constants.py index f71453f3..3d1b5c13 100644 --- a/novelwriter/constants.py +++ b/novelwriter/constants.py @@ -25,7 +25,7 @@ along with this program. If not, see . from PyQt5.QtCore import QCoreApplication, QT_TRANSLATE_NOOP -from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType, nwOutline +from novelwriter.enum import nwItemClass, nwItemLayout, nwOutline def trConst(tString): @@ -34,7 +34,7 @@ def trConst(tString): return QCoreApplication.translate("Constant", tString) -class nwConst(): +class nwConst: # Date and Time Formats FMT_TSTAMP = "%Y-%m-%d %H:%M:%S" # Default format @@ -42,32 +42,13 @@ class nwConst(): FMT_DSTAMP = "%Y-%m-%d" # Date only format # Various Hard Limits - MAX_DEPTH = 30 # Maximum folder depth of a project MAX_DOCSIZE = 5000000 # Maxium size of a single document MAX_BUILDSIZE = 10000000 # Maxium size of a project build # END Class nwConst -class nwLists(): - """Lists used for grouping various other constants. - """ - # Regular user-accessible item types - REG_TYPES = {nwItemType.ROOT, nwItemType.FOLDER, nwItemType.FILE} - - # Item classes where the full list of novel layouts are allowed - CLS_NOVEL = {nwItemClass.NOVEL, nwItemClass.ARCHIVE} - - # Item classes which do not require items to have same class - FREE_CLASS = {nwItemClass.ARCHIVE, nwItemClass.TRASH} - - # Deprecated nwItemLayout entries - DEP_LAYOUT = ("TITLE", "PAGE", "BOOK", "PARTITION", "UNNUMBERED", "CHAPTER", "SCENE") - -# END Class nwLists - - -class nwRegEx(): +class nwRegEx: FMT_EI = r"(?. """ from novelwriter.core.document import NWDoc -from novelwriter.core.index import NWIndex, countWords +from novelwriter.core.index import countWords from novelwriter.core.project import NWProject from novelwriter.core.spellcheck import NWSpellEnchant from novelwriter.core.tohtml import ToHtml @@ -30,7 +30,6 @@ from novelwriter.core.tomd import ToMarkdown __all__ = [ "countWords", "NWDoc", - "NWIndex", "NWProject", "NWSpellEnchant", "ToHtml", diff --git a/novelwriter/core/document.py b/novelwriter/core/document.py index 2334c77c..5420d44e 100644 --- a/novelwriter/core/document.py +++ b/novelwriter/core/document.py @@ -52,7 +52,7 @@ class NWDoc(): self._docHandle = theHandle if self._docHandle is not None: - self._theItem = self.theProject.projTree[theHandle] + self._theItem = self.theProject.tree[theHandle] return diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index b05fa952..7ea713b6 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -4,8 +4,10 @@ novelWriter – Project Index Data class for the project index of tags, headers and references File History: -Created: 2019-04-22 [0.0.1] countWords -Created: 2019-05-27 [0.1.4] NWIndex +Created: 2019-04-22 [0.0.1] countWords +Created: 2019-05-27 [0.1.4] NWIndex +Created: 2022-05-28 [1.7rc1] IndexItem, IndexHeading +Created: 2022-05-29 [1.7rc1] TagsIndex, ItemIndex This file is a part of novelWriter Copyright 2018–2022, Veronica Berglyd Olsen @@ -30,42 +32,55 @@ import logging from time import time -from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout +from novelwriter.enum import nwItemType, nwItemLayout from novelwriter.error import logException -from novelwriter.constants import nwFiles, nwKeyWords, nwUnicode +from novelwriter.constants import nwFiles, nwKeyWords, nwUnicode, nwHeaders from novelwriter.core.document import NWDoc from novelwriter.common import ( - isHandle, isTitleTag, isItemClass, isItemLayout, jsonEncode + checkInt, isHandle, isItemClass, isTitleTag, jsonEncode ) logger = logging.getLogger(__name__) -H_VALID = ("H0", "H1", "H2", "H3", "H4") -H_LEVEL = {"H0": 0, "H1": 1, "H2": 2, "H3": 3, "H4": 4} +class NWIndex: + """This class holds the entire index for a given project. The index + contains the data that isn't stored in the project items themselves. + The content of the index is updated every time a file item is saved. -class NWIndex(): + The primary index data is contained in the ItemIndex class, which + contains an IndexItem representing each NWItem. Each IndexItem holds + an IndexHeading object for each heading of the item's text. + + A reverse index of all tags is contained in the TagsIndex class. + This is duplicate information used for quicker lookups from the tags + and back to items where they are defined. + + The index data is cached in a JSON file between writing sessions. + """ def __init__(self, theProject): self.theProject = theProject - # Internal + # Storage and State + self._tagsIndex = TagsIndex() + self._itemIndex = ItemIndex(theProject) self._indexBroken = False - # Indices - self._tagIndex = {} - self._refIndex = {} - self._fileIndex = {} - self._fileMeta = {} - # TimeStamps - self._timeNovel = 0 - self._timeNotes = 0 - self._timeIndex = 0 + self._indexChange = 0 + self._rootChange = {} return + def __repr__(self): + return f"" + + ## + # Properties + ## + @property def indexBroken(self): return self._indexBroken @@ -77,27 +92,20 @@ class NWIndex(): def clearIndex(self): """Clear the index dictionaries and time stamps. """ - self._tagIndex = {} - self._refIndex = {} - self._fileIndex = {} - self._fileMeta = {} - self._timeNovel = 0 - self._timeNotes = 0 - self._timeIndex = 0 + self._tagsIndex.clear() + self._itemIndex.clear() + self._indexChange = 0 + self._rootChange = {} return def deleteHandle(self, tHandle): """Delete all entries of a given document handle. """ logger.debug("Removing item '%s' from the index", tHandle) + for tTag in self._itemIndex.allItemTags(tHandle): + del self._tagsIndex[tTag] - delTags = list(filter(lambda x: self._tagIndex[x][1] == tHandle, self._tagIndex)) - for tTag in delTags: - self._tagIndex.pop(tTag, None) - - self._refIndex.pop(tHandle, None) - self._fileIndex.pop(tHandle, None) - self._fileMeta.pop(tHandle, None) + del self._itemIndex[tHandle] return @@ -106,30 +114,25 @@ class NWIndex(): moved from the archive or trash folders back into the active project. """ - logger.debug("Re-indexing item '%s'", tHandle) - if not self.theProject.projTree.checkType(tHandle, nwItemType.FILE): + if not self.theProject.tree.checkType(tHandle, nwItemType.FILE): return False + logger.debug("Re-indexing item '%s'", tHandle) theDoc = NWDoc(self.theProject, tHandle) - theText = theDoc.readDocument() - self.scanText(tHandle, theText if theText is not None else "") + self.scanText(tHandle, theDoc.readDocument() or "") return True - def novelChangedSince(self, checkTime): - """Check if the novel index has changed since a given time. - """ - return self._timeNovel > checkTime - - def notesChangedSince(self, checkTime): - """Check if the notes index has changed since a given time. - """ - return self._timeNotes > checkTime - def indexChangedSince(self, checkTime): """Check if the index has changed since a given time. """ - return self._timeIndex > checkTime + return self._indexChange > checkTime + + def rootChangedSince(self, rootHandle, checkTime): + """Check if the index has changed since a given time for a + given root item. + """ + return self._rootChange.get(rootHandle, self._indexChange) > checkTime ## # Load and Save Index to/from File @@ -142,32 +145,39 @@ class NWIndex(): indexFile = os.path.join(self.theProject.projMeta, nwFiles.INDEX_FILE) tStart = time() + self._indexBroken = False if os.path.isfile(indexFile): logger.debug("Loading index file") try: with open(indexFile, mode="r", encoding="utf-8") as inFile: theData = json.load(inFile) - except Exception: logger.error("Failed to load index file") logException() self._indexBroken = True return False - self._tagIndex = theData.get("tagIndex", {}) - self._refIndex = theData.get("refIndex", {}) - self._fileIndex = theData.get("fileIndex", {}) - self._fileMeta = theData.get("fileMeta", {}) + try: + self._tagsIndex.unpackData(theData["tagsIndex"]) + self._itemIndex.unpackData(theData["itemIndex"]) + except Exception: + logger.error("The index content is invalid") + logException() + self._indexBroken = True + return False - nowTime = round(time()) - self._timeNovel = nowTime - self._timeNotes = nowTime - self._timeIndex = nowTime + logger.debug("Checking index") + + # Check that all files are indexed + for fHandle in self.theProject.projFiles: + if fHandle not in self._itemIndex: + logger.warning("Item '%s' is not in the index", fHandle) + self.reIndexHandle(fHandle) + + self._indexChange = round(time()) logger.verbose("Index loaded in %.3f ms", (time() - tStart)*1000) - self._checkIndex() - return True def saveIndex(self): @@ -179,12 +189,12 @@ class NWIndex(): tStart = time() try: + tagsIndex = self._tagsIndex.packData() + itemIndex = self._itemIndex.packData() with open(indexFile, mode="w+", encoding="utf-8") as outFile: outFile.write("{\n") - outFile.write(f' "tagIndex": {jsonEncode(self._tagIndex, n=1, nmax=2)},\n') - outFile.write(f' "refIndex": {jsonEncode(self._refIndex, n=1, nmax=3)},\n') - outFile.write(f' "fileIndex": {jsonEncode(self._fileIndex, n=1, nmax=3)},\n') - outFile.write(f' "fileMeta": {jsonEncode(self._fileMeta, n=1, nmax=2)}\n') + outFile.write(f' "tagsIndex": {jsonEncode(tagsIndex, n=1, nmax=2)},\n') + outFile.write(f' "itemIndex": {jsonEncode(itemIndex, n=1, nmax=4)}\n') outFile.write("}\n") except Exception: @@ -204,22 +214,26 @@ class NWIndex(): """Scan a piece of text associated with a handle. This will update the indices accordingly. This function takes the handle and text as separate inputs as we want to primarily scan the - files before we save them in which case we already have the + files before we save them, in which case we already have the text. """ - theItem = self.theProject.projTree[tHandle] - theRoot = self.theProject.projTree.getRootItem(tHandle) - + theItem = self.theProject.tree[tHandle] if theItem is None: logger.info("Not indexing unknown item '%s'", tHandle) return False - if theItem.itemType != nwItemType.FILE: + if not theItem.isFileType(): logger.info("Not indexing non-file item '%s'", tHandle) return False + # Keep a record of existing tags, and create a new item entry + itemTags = dict.fromkeys(self._itemIndex.allItemTags(tHandle), False) + self._itemIndex.add(tHandle, theItem) + # Run word counter for the whole text cC, wC, pC = countWords(theText) - self._fileMeta[tHandle] = ["H0", cC, wC, pC] + theItem.setCharCount(cC) + theItem.setWordCount(wC) + theItem.setParaCount(pC) # If the file's meta data is missing, or the file is out of the # main project, we don't index the content @@ -229,27 +243,12 @@ class NWIndex(): if theItem.itemParent is None: logger.info("Not indexing orphaned item '%s'", tHandle) return False - if self.theProject.projTree.isTrashRoot(theItem.itemParent): - logger.debug("Not indexing trash item '%s'", tHandle) + if theItem.isInactive(): + logger.debug("Not indexing inactive item '%s'", tHandle) return False - if theRoot.itemClass == nwItemClass.ARCHIVE: - logger.debug("Not indexing archived item '%s'", tHandle) - return False - - itemClass = theItem.itemClass - itemLayout = theItem.itemLayout logger.debug("Indexing item with handle '%s'", tHandle) - # Delete or reset old entries for the file - self._refIndex.pop(tHandle, None) - self._fileIndex[tHandle] = {} - - # Also clear references to the file in the tags index - clearTags = list(filter(lambda x: self._tagIndex[x][1] == tHandle, self._tagIndex)) - for aTag in clearTags: - self._tagIndex.pop(aTag) - # Scan the text content nTitle = 0 theLines = theText.splitlines() @@ -258,7 +257,7 @@ class NWIndex(): continue if aLine.startswith("#"): - isTitle = self._indexTitle(tHandle, aLine, nLine, itemLayout) + isTitle = self._indexTitle(tHandle, aLine, nLine) if isTitle and nLine > 0: if nTitle > 0: lastText = "\n".join(theLines[nTitle-1:nLine-1]) @@ -266,7 +265,7 @@ class NWIndex(): nTitle = nLine elif aLine.startswith("@"): - self._indexKeyword(tHandle, aLine, nLine, nTitle, itemClass) + self._indexKeyword(tHandle, aLine, nTitle, theItem.itemClass, itemTags) elif aLine.startswith("%"): if nTitle > 0: @@ -283,26 +282,28 @@ class NWIndex(): lastText = "\n".join(theLines[nTitle-1:]) self._indexWordCounts(tHandle, lastText, nTitle) - # Index page with no titles and references + # Also count words on a page with no titles if nTitle == 0: - self._indexPage(tHandle, itemLayout) self._indexWordCounts(tHandle, theText, nTitle) + # Prune no longer used tags + for tTag, isActive in itemTags.items(): + if not isActive: + logger.verbose("Deleting removed tag '%s'", tTag) + del self._tagsIndex[tTag] + # Update timestamps for index changes nowTime = round(time()) - self._timeIndex = nowTime - if itemLayout == nwItemLayout.NOTE: - self._timeNotes = nowTime - else: - self._timeNovel = nowTime + self._indexChange = nowTime + self._rootChange[theItem.itemRoot] = nowTime return True ## - # Internal Indexers + # Internal Indexer Helpers ## - def _indexTitle(self, tHandle, aLine, nLine, itemLayout): + def _indexTitle(self, tHandle, aLine, nTitle): """Save information about the title and its location in the file to the index. """ @@ -327,62 +328,31 @@ class NWIndex(): else: return False - sTitle = f"T{nLine:06d}" - self._fileIndex[tHandle][sTitle] = { - "level": hDepth, - "title": hText, - "layout": itemLayout.name, - "cCount": 0, - "wCount": 0, - "pCount": 0, - "synopsis": "", - } - - if self._fileMeta[tHandle][0] == "H0": - # Since this initialises to H0, this ensures that only the - # first header level is recorded in the file meta index - self._fileMeta[tHandle][0] = hDepth + sTitle = f"T{nTitle:06d}" + self._itemIndex.addItemHeading(tHandle, sTitle, hDepth, hText) return True - def _indexPage(self, tHandle, itemLayout): - """Index a page with no title. - """ - self._fileIndex[tHandle]["T000000"] = { - "level": "H0", - "title": "", - "layout": itemLayout.name, - "cCount": 0, - "wCount": 0, - "pCount": 0, - "synopsis": "", - } - return - def _indexWordCounts(self, tHandle, theText, nTitle): """Count text stats and save the counts to the index. """ - cC, wC, pC = countWords(theText) sTitle = f"T{nTitle:06d}" - if tHandle in self._fileIndex: - if sTitle in self._fileIndex[tHandle]: - self._fileIndex[tHandle][sTitle]["cCount"] = cC - self._fileIndex[tHandle][sTitle]["wCount"] = wC - self._fileIndex[tHandle][sTitle]["pCount"] = pC + cC, wC, pC = countWords(theText) + self._itemIndex.setHeadingCounts(tHandle, sTitle, cC, wC, pC) return def _indexSynopsis(self, tHandle, theText, nTitle): """Save the synopsis to the index. """ sTitle = f"T{nTitle:06d}" - if tHandle in self._fileIndex: - if sTitle in self._fileIndex[tHandle]: - self._fileIndex[tHandle][sTitle]["synopsis"] = theText + self._itemIndex.setHeadingSynopsis(tHandle, sTitle, theText) return - def _indexKeyword(self, tHandle, aLine, nLine, nTitle, itemClass): + def _indexKeyword(self, tHandle, aLine, nTitle, itemClass, itemTags): """Validate and save the information about a reference to a tag - in another file. + in another file, or the setting of a tag in the file. A record + of active tags is updated so that no longer used tags can be + pruned later. """ isValid, theBits, _ = self.scanThis(aLine) if not isValid or len(theBits) < 2: @@ -395,15 +365,12 @@ class NWIndex(): sTitle = f"T{nTitle:06d}" if theBits[0] == nwKeyWords.TAG_KEY: - self._tagIndex[theBits[1]] = [nLine, tHandle, itemClass.name, sTitle] - + tagName = theBits[1] + self._tagsIndex.add(tagName, tHandle, sTitle, itemClass) + self._itemIndex.setHeadingTag(tHandle, sTitle, tagName) + itemTags[tagName] = True else: - if tHandle not in self._refIndex: - self._refIndex[tHandle] = {} - if sTitle not in self._refIndex[tHandle]: - self._refIndex[tHandle][sTitle] = [] - for aVal in theBits[1:]: - self._refIndex[tHandle][sTitle].append([nLine, theBits[0], aVal]) + self._itemIndex.addHeadingReferences(tHandle, sTitle, theBits[1:], theBits[0]) return @@ -465,8 +432,8 @@ class NWIndex(): # For a tag, only the first value is accepted, the rest are ignored if theBits[0] == nwKeyWords.TAG_KEY and nBits > 1: - if theBits[1] in self._tagIndex: - isGood[1] = self._tagIndex[theBits[1]][1] == tItem.itemHandle + if theBits[1] in self._tagsIndex: + isGood[1] = self._tagsIndex.tagHandle(theBits[1]) == tItem.itemHandle else: isGood[1] = True return isGood @@ -474,8 +441,8 @@ class NWIndex(): # If we're still here, we check that the references exist theKey = nwKeyWords.KEY_CLASS[theBits[0]].name for n in range(1, nBits): - if theBits[n] in self._tagIndex: - isGood[n] = theKey == self._tagIndex[theBits[n]][2] + if theBits[n] in self._tagsIndex: + isGood[n] = self._tagsIndex.tagClass(theBits[n]) == theKey return isGood @@ -483,77 +450,74 @@ class NWIndex(): # Extract Data ## - def novelStructure(self, skipExcluded=True): + def novelStructure(self, rootHandle=None, skipExcl=True): """Iterate over all titles in the novel, in the correct order as they appear in the tree view and in the respective document files, but skipping all note files. """ - for tHandle in self._listNovelHandles(skipExcluded): - for sTitle in sorted(self._fileIndex[tHandle]): - tKey = f"{tHandle}:{sTitle}" - yield tKey, tHandle, sTitle, self._fileIndex[tHandle][sTitle] + novStruct = self._itemIndex.iterNovelStructure(rootHandle=rootHandle, skipExcl=skipExcl) + for tHandle, sTitle, hItem in novStruct: + yield f"{tHandle}:{sTitle}", tHandle, sTitle, hItem + return - def getNovelWordCount(self, skipExcluded=True): + def getNovelWordCount(self, skipExcl=True): """Count the number of words in the novel project. """ wCount = 0 - for tHandle in self._listNovelHandles(skipExcluded): - for sTitle in self._fileIndex[tHandle]: - wCount += self._fileIndex[tHandle][sTitle]["wCount"] - + for _, _, hItem in self._itemIndex.iterNovelStructure(skipExcl=skipExcl): + wCount += hItem.wordCount return wCount - def getNovelTitleCounts(self, skipExcluded=True): + def getNovelTitleCounts(self, skipExcl=True): """Count the number of titles in the novel project. """ hCount = [0, 0, 0, 0, 0] - for tHandle in self._listNovelHandles(skipExcluded): - for sTitle in self._fileIndex[tHandle]: - iLevel = H_LEVEL.get(self._fileIndex[tHandle][sTitle]["level"], 0) - hCount[iLevel] += 1 - + for _, _, hItem in self._itemIndex.iterNovelStructure(skipExcl=skipExcl): + iLevel = nwHeaders.H_LEVEL.get(hItem.level, 0) + hCount[iLevel] += 1 return hCount def getHandleWordCounts(self, tHandle): """Get all header word counts for a specific handle. """ - hRecord = self._fileIndex.get(tHandle, {}) - return [(f"{tHandle}:{sTitle}", sData["wCount"]) for sTitle, sData in hRecord.items()] + return [ + (f"{tHandle}:{sTitle}", hItem.wordCount) + for sTitle, hItem in self._itemIndex.iterItemHeaders(tHandle) + ] def getHandleHeaders(self, tHandle): """Get all headers for a specific handle. """ - hRecord = self._fileIndex.get(tHandle, {}) - return [(sTitle, sData["level"], sData["title"]) for sTitle, sData in hRecord.items()] + return [ + (sTitle, hItem.level, hItem.title) + for sTitle, hItem in self._itemIndex.iterItemHeaders(tHandle) + ] def getHandleHeaderLevel(self, tHandle): """Get the header level of the first header of a handle. """ - return self._fileMeta.get(tHandle, ["H0"])[0] + return self._itemIndex.mainItemHeader(tHandle) - def getTableOfContents(self, maxDepth, skipExcluded=True): + def getTableOfContents(self, maxDepth, skipExcl=True): """Generate a table of contents up to a maximum depth. """ tOrder = [] tData = {} pKey = None - for tHandle in self._listNovelHandles(skipExcluded): - for sTitle in sorted(self._fileIndex[tHandle]): - tKey = f"{tHandle}:{sTitle}" - theData = self._fileIndex[tHandle][sTitle] - iLevel = H_LEVEL.get(theData["level"], 0) - if iLevel > maxDepth: - if pKey in tData: - theData["wCount"] - tData[pKey]["words"] += theData["wCount"] - else: - pKey = tKey - tOrder.append(tKey) - tData[tKey] = { - "level": iLevel, - "title": theData["title"], - "words": theData["wCount"], - } + for tHandle, sTitle, hItem in self._itemIndex.iterNovelStructure(skipExcl=skipExcl): + tKey = f"{tHandle}:{sTitle}" + iLevel = nwHeaders.H_LEVEL.get(hItem.level, 0) + if iLevel > maxDepth: + if pKey in tData: + tData[pKey]["words"] += hItem.wordCount + else: + pKey = tKey + tOrder.append(tKey) + tData[tKey] = { + "level": iLevel, + "title": hItem.title, + "words": hItem.wordCount, + } theToC = [( tKey, @@ -568,254 +532,672 @@ class NWIndex(): """Return the counts for a file, or a section of a file, starting at title sTitle if it is provided. """ - cC = 0 - wC = 0 - pC = 0 + tItem = self._itemIndex[tHandle] + if tItem is None: + return 0, 0, 0 if sTitle is None: - if tHandle in self._fileMeta: - cC = self._fileMeta[tHandle][1] - wC = self._fileMeta[tHandle][2] - pC = self._fileMeta[tHandle][3] + cItem = tItem.item else: - if tHandle in self._fileIndex: - if sTitle in self._fileIndex[tHandle]: - cC = self._fileIndex[tHandle][sTitle]["cCount"] - wC = self._fileIndex[tHandle][sTitle]["wCount"] - pC = self._fileIndex[tHandle][sTitle]["pCount"] + cItem = tItem[sTitle] - return cC, wC, pC + if cItem is not None: + return cItem.charCount, cItem.wordCount, cItem.paraCount + + return 0, 0, 0 def getReferences(self, tHandle, sTitle=None): """Extract all references made in a file, and optionally title section. """ theRefs = {x: [] for x in nwKeyWords.KEY_CLASS} - if tHandle not in self._refIndex: - return theRefs - - for refTitle in self._refIndex[tHandle]: - for aTag in self._refIndex[tHandle][refTitle]: - if len(aTag) == 3 and (sTitle is None or sTitle == refTitle): - if aTag[1] in theRefs: - theRefs[aTag[1]].append(aTag[2]) + for rTitle, hItem in self._itemIndex.iterItemHeaders(tHandle): + if sTitle is None or sTitle == rTitle: + for aTag, refTypes in hItem.references.items(): + for refType in refTypes: + if refType in theRefs: + theRefs[refType].append(aTag) return theRefs def getNovelData(self, tHandle, sTitle): """Return the novel data of a given handle and title. """ - if tHandle in self._fileIndex: - if sTitle in self._fileIndex[tHandle]: - return self._fileIndex[tHandle][sTitle] + if tHandle in self._itemIndex: + return self._itemIndex[tHandle][sTitle] return None def getBackReferenceList(self, tHandle): """Build a list of files referring back to our file, specified by tHandle. """ - if tHandle is None: + if tHandle is None or tHandle not in self._itemIndex: return {} theRefs = {} - theTags = set(filter(lambda x: self._tagIndex[x][1] == tHandle, self._tagIndex)) - if theTags: - for tHandle in self._refIndex: - for sTitle in self._refIndex[tHandle]: - for _, _, tTag in self._refIndex[tHandle][sTitle]: - if tTag in theTags and tHandle not in theRefs: - theRefs[tHandle] = sTitle + theTags = self._itemIndex.allItemTags(tHandle) + if not theTags: + return theRefs + + for aHandle, sTitle, hItem in self._itemIndex.iterAllHeaders(): + for aTag in hItem.references: + if aTag in theTags and aHandle not in theRefs: + theRefs[aHandle] = sTitle return theRefs def getTagSource(self, theTag): """Return the source location of a given tag. """ - theRef = self._tagIndex.get(theTag, []) - if len(theRef) == 4: - return theRef[1], theRef[0], theRef[3] - return None, 0, "T000000" - - ## - # Internal Functions - ## - - def _listNovelHandles(self, skipExcluded): - """Return a list of all handles that exist in the novel index. - """ - theHandles = [] - for tItem in self.theProject.projTree: - if tItem is None: - continue - if not tItem.isExported and skipExcluded: - continue - if tItem.itemLayout == nwItemLayout.NOTE: - continue - if tItem.itemHandle in self._fileIndex: - theHandles.append(tItem.itemHandle) - - return theHandles - - ## - # Index Checkers - ## - - def _checkIndex(self): - """Check that the entries in the index are valid and contain the - elements it should. Also check that each file present in the - contents folder when the project was loaded are also present in - the fileMeta index. - """ - logger.debug("Checking index") - tStart = time() - - try: - self._checkTagIndex() - self._checkRefIndex() - self._checkFileIndex() - self._checkFileMeta() - self._indexBroken = False - - except Exception: - logger.error("Error while checking index") - logException() - self._indexBroken = True - - # Check that project files are indexed - for fHandle in self.theProject.projFiles: - if fHandle not in self._fileMeta: - self._indexBroken = True - break - - logger.verbose("Index check completed in %.3f ms", (time() - tStart)*1000) - - if self._indexBroken: - self.clearIndex() - - return - - def _checkTagIndex(self): - """Scan the tag index for errors. - Warning: This function raises exceptions. - """ - for tTag in self._tagIndex: - if not isinstance(tTag, str): - raise KeyError("tagIndex key is not a string") - - tEntry = self._tagIndex[tTag] - if len(tEntry) != 4: - raise IndexError("tagIndex[a] expected 4 values") - if not isinstance(tEntry[0], int): - raise ValueError("tagIndex[a][0] is not an integer") - if not isHandle(tEntry[1]): - raise ValueError("tagIndex[a][1] is not a handle") - if not isItemClass(tEntry[2]): - raise ValueError("tagIndex[a][2] is not an nwItemClass") - if not isTitleTag(tEntry[3]): - raise ValueError("tagIndex[a][3] is not a title tag") - - return - - def _checkRefIndex(self): - """Scan the reference index for errors. - Warning: This function raises exceptions. - """ - for tHandle in self._refIndex: - if not isHandle(tHandle): - raise KeyError("refIndex key is not a handle") - - hEntry = self._refIndex[tHandle] - for sTitle in hEntry: - if not isTitleTag(sTitle): - raise KeyError("refIndex[a] key is not a title tag") - - sEntry = hEntry[sTitle] - for tEntry in sEntry: - if len(tEntry) != 3: - raise IndexError("refIndex[a][b][i] expected 3 values") - if not isinstance(tEntry[0], int): - raise ValueError("refIndex[a][b][i][0] is not an integer") - if not tEntry[1] in nwKeyWords.VALID_KEYS: - raise ValueError("refIndex[a][b][i][1] is not a keyword") - if not isinstance(tEntry[2], str): - raise ValueError("refIndex[a][b][i][2] is not a string") - - return - - def _checkFileIndex(self): - """Scan the file index for errors. - Warning: This function raises exceptions. - """ - for tHandle in self._fileIndex: - if not isHandle(tHandle): - raise KeyError("fileIndex key is not a handle") - - hEntry = self._fileIndex[tHandle] - for sTitle in self._fileIndex[tHandle]: - if not isTitleTag(sTitle): - raise KeyError("fileIndex[a] key is not a title tag") - - sEntry = hEntry[sTitle] - if len(sEntry) != 7: - raise IndexError("fileIndex[a][b] expected 7 values") - - if "level" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'level' key") - if "title" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'title' key") - if "layout" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'layout' key") - if "cCount" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'cCount' key") - if "wCount" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'wCount' key") - if "pCount" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'pCount' key") - if "synopsis" not in sEntry: - raise KeyError("fileIndex[a][b] has no 'synopsis' key") - - if not sEntry["level"] in H_VALID: - raise ValueError("fileIndex[a][b][level] is not a header level") - if not isinstance(sEntry["title"], str): - raise ValueError("fileIndex[a][b][title] is not a string") - if not isItemLayout(sEntry["layout"]): - raise ValueError("fileIndex[a][b][layout] is not an nwItemLayout") - if not isinstance(sEntry["cCount"], int): - raise ValueError("fileIndex[a][b][cCount] is not an integer") - if not isinstance(sEntry["wCount"], int): - raise ValueError("fileIndex[a][b][wCount] is not an integer") - if not isinstance(sEntry["pCount"], int): - raise ValueError("fileIndex[a][b][pCount] is not an integer") - if not isinstance(sEntry["synopsis"], str): - raise ValueError("fileIndex[a][b][synopsis] is not a string") - - return - - def _checkFileMeta(self): - """Scan the text counts index for errors. - Warning: This function raises exceptions. - """ - for tHandle in self._fileMeta: - if not isHandle(tHandle): - raise KeyError("fileMeta key is not a handle") - - tEntry = self._fileMeta[tHandle] - if len(tEntry) != 4: - raise IndexError("fileMeta[a] expected 4 values") - if not tEntry[0] in H_VALID: - raise ValueError("fileMeta[a][0] is not a header level") - if not isinstance(tEntry[1], int): - raise ValueError("fileMeta[a][1] is not an integer") - if not isinstance(tEntry[2], int): - raise ValueError("fileMeta[a][2] is not an integer") - if not isinstance(tEntry[3], int): - raise ValueError("fileMeta[a][3] is not an integer") - - return + tHandle = self._tagsIndex.tagHandle(theTag) + sTitle = self._tagsIndex.tagHeading(theTag) + return tHandle, sTitle # END Class NWIndex +# =============================================================================================== # +# The Tags Index Object +# =============================================================================================== # + +class TagsIndex: + """A wrapper class that holds the reverse lookup tags index. This is + just a simple wrapper around a single dictionary to keep tighter + control of the keys. + """ + + def __init__(self): + self._tags = {} + return + + ## + # Methods + ## + + def clear(self): + """Clear the index. + """ + self._tags = {} + return + + def __contains__(self, tagKey): + """Check if a tag exists in the index, + """ + return tagKey in self._tags + + def __delitem__(self, tagKey): + """Delete an entry in the index. + """ + self._tags.pop(tagKey, None) + return + + def __getitem__(self, tagKey): + """Return a tag, or return None if it isn't found. + """ + return self._tags.get(tagKey, None) + + def add(self, tagKey, tHandle, sTitle, itemClass): + """Add a key to the index and set all values. + """ + self._tags[tagKey] = { + "handle": tHandle, "heading": sTitle, "class": itemClass.name + } + return + + def tagHandle(self, tagKey): + """Get the handle of a given tag. + """ + if tagKey in self._tags: + return self._tags.get(tagKey).get("handle") + return None + + def tagHeading(self, tagKey): + """Get the heading of a given tag. + """ + if tagKey in self._tags: + return self._tags.get(tagKey).get("heading") + return nwHeaders.TT_NONE + + def tagClass(self, tagKey): + """Get the class of a given tag. + """ + if tagKey in self._tags: + return self._tags.get(tagKey).get("class") + return None + + ## + # Pack/Unpack + ## + + def packData(self): + """Pack all the data of the tags into a single dictionary. + """ + return self._tags + + def unpackData(self, data): + """Iterate through the tagsIndex loaded from cache and check + that it's valid. + """ + self._tags = {} + if not isinstance(data, dict): + raise ValueError("tagsIndex is not a dict") + + for tagKey, tagData in data.items(): + if not isinstance(tagKey, str): + raise ValueError("tagsIndex keys must be a strings") + if "handle" not in tagData: + raise KeyError("A tagIndex item is missing a handle entry") + if "heading" not in tagData: + raise KeyError("A tagIndex item is missing a heading entry") + if "class" not in tagData: + raise KeyError("A tagIndex item is missing a class entry") + if not isHandle(tagData["handle"]): + raise ValueError("tagsIndex handle must be a handle") + if not isTitleTag(tagData["heading"]): + raise ValueError("tagsIndex heading must be a title tag") + if not isItemClass(tagData["class"]): + raise ValueError("tagsIndex handle must be an nwItemClass") + + self._tags = data + + return + +# END Class TagsIndex + + +# =============================================================================================== # +# The Item Index Objects +# =============================================================================================== # + +class ItemIndex: + """A wrapper object holding the indexed items. This is a warapper + class around a single storage dictionary with a set of utility + functions for setting and accessing the index data. Each indexed + item is stored in an IndexItem object, which again holds an + IndexHeading object for each header of the text. + """ + + def __init__(self, theProject): + self.theProject = theProject + self._items = {} + return + + ## + # Methods + ## + + def clear(self): + """Clear the index. + """ + self._items = {} + return + + def __contains__(self, tHandle): + """Check if an item exists in the index, + """ + return tHandle in self._items + + def __delitem__(self, tHandle): + """Delete an entry in the index. + """ + self._items.pop(tHandle, None) + return + + def __getitem__(self, tHandle): + """Return an item, or return None if it isn't found. + """ + return self._items.get(tHandle, None) + + def add(self, tHandle, tItem): + """Add a new item to the index. This will overwrite the item if + it already exists. + """ + self._items[tHandle] = IndexItem(tHandle, tItem) + return + + def mainItemHeader(self, tHandle): + """Return the primary item header for an item. + """ + if tHandle in self._items: + return self._items[tHandle].level + return "H0" + + def allItemTags(self, tHandle): + """Get all tags set for headings of an item. + """ + if tHandle in self._items: + return self._items[tHandle].allTags() + return [] + + def iterItemHeaders(self, tHandle): + """Iterate over all item headers of an item. + """ + if tHandle in self._items: + for sTitle, hItem in self._items[tHandle].items(): + yield sTitle, hItem + return + + def iterAllHeaders(self): + """Iterate through all items and headings in the index. + """ + for tHandle, tItem in self._items.items(): + for sTitle, hItem in tItem.items(): + yield tHandle, sTitle, hItem + return + + def iterNovelStructure(self, rootHandle=None, skipExcl=False): + """Iterate over all items and headers in the novel structure for + a given root handle, or for all if root handle is None. + """ + for tItem in self.theProject.tree: + if tItem is None: + continue + if tItem.isNoteLayout(): + continue + if skipExcl and not tItem.isExported: + continue + + tHandle = tItem.itemHandle + if tHandle not in self._items: + continue + + if rootHandle is None: + for sTitle in self._items[tHandle].headings(): + yield tHandle, sTitle, self._items[tHandle][sTitle] + elif tItem.itemRoot == rootHandle: + for sTitle in self._items[tHandle].headings(): + yield tHandle, sTitle, self._items[tHandle][sTitle] + else: + continue + + return + + ## + # Setters + ## + + def addItemHeading(self, tHandle, sTitle, hDepth, hText): + """Set the main heading level of an item. + """ + if tHandle in self._items: + tItem = self._items[tHandle] + tItem.updateLevel(hDepth) + tItem.addHeading(IndexHeading(sTitle, hDepth, hText)) + return + + def setHeadingCounts(self, tHandle, sTitle, cC, wC, pC): + """Set the character, word and paragraph counts of a heading + on a given item. + """ + if tHandle in self._items: + self._items[tHandle].setHeadingCounts(sTitle, cC, wC, pC) + return + + def setHeadingSynopsis(self, tHandle, sTitle, sText): + """Set the synopsis text for a heading on a given item. + """ + if tHandle in self._items: + self._items[tHandle].setHeadingSynopsis(sTitle, sText) + return + + def setHeadingTag(self, tHandle, sTitle, tagKey): + """Set the main tag for a heading on a given item. + """ + if tHandle in self._items: + self._items[tHandle].setHeadingTag(sTitle, tagKey) + return + + def addHeadingReferences(self, tHandle, sTitle, tagKeys, refType): + """Set the reference tags for a heading on a given item. + """ + if tHandle in self._items: + self._items[tHandle].addHeadingReferences(sTitle, tagKeys, refType) + return + + ## + # Pack/Unpack + ## + + def packData(self): + """Pack all the data of the index into a single dictionary. + """ + return {handle: item.packData() for handle, item in self._items.items()} + + def unpackData(self, data): + """Iterate through the itemIndex loaded from cache and check + that it's valid. This will raise errors if there is a problem. + """ + self._items = {} + if not isinstance(data, dict): + raise ValueError("itemIndex is not a dict") + + for tHandle, tData in data.items(): + if not isHandle(tHandle): + raise ValueError("itemIndex keys must be handles") + + nwItem = self.theProject.tree[tHandle] + if nwItem is not None: + tItem = IndexItem(tHandle, nwItem) + tItem.unpackData(tData) + self._items[tHandle] = tItem + + return + +# END Class ItemIndex + + +class IndexItem: + """This object represents the index data of a project item (NWItem). + It holds a record of all the headings in the text, and the meta data + associated with each heading. It also holds a pointer to the project + item. The main heading level of the item is also held here since it + must be reset each time the item is re-indexed. + """ + + def __init__(self, tHandle, tItem): + self._handle = tHandle + self._item = tItem + self._level = "H0" + self._headings = {} + self._index = 0 + + # Add a placeholder heading + self._headings[nwHeaders.TT_NONE] = IndexHeading(nwHeaders.TT_NONE) + + return + + def __repr__(self): + return f"" + + ## + # Properties + ## + + @property + def item(self): + return self._item + + @property + def level(self): + return self._level + + ## + # Setters + ## + + def updateLevel(self, level): + """Set the level only if it has not already been set. + """ + if self._level == "H0": + self._level = level + return + + def addHeading(self, tHeading): + """Add a heading to the item. Also remove the placeholder entry + if it exists. + """ + if nwHeaders.TT_NONE in self._headings: + self._headings.pop(nwHeaders.TT_NONE) + self._headings[tHeading.key] = tHeading + return + + def setHeadingCounts(self, sTitle, charCount, wordCount, paraCount): + """Set the character, word and paragraph count of a heading. + """ + if sTitle in self._headings: + self._headings[sTitle].setCounts(charCount, wordCount, paraCount) + return + + def setHeadingSynopsis(self, sTitle, synopText): + """Set the synopsis text of a heading. + """ + if sTitle in self._headings: + self._headings[sTitle].setSynopsis(synopText) + return + + def setHeadingTag(self, sTitle, tagKey): + """Set the tag of a heading. + """ + if sTitle in self._headings: + self._headings[sTitle].setTag(tagKey) + return + + def addHeadingReferences(self, sTitle, tagKeys, refType): + """Add a reference key and all its types to a heading. + """ + if sTitle in self._headings: + for tagKey in tagKeys: + self._headings[sTitle].addReference(tagKey, refType) + return + + ## + # Data Methods + ## + + def __getitem__(self, sTitle): + return self._headings.get(sTitle, None) + + def __contains__(self, sTitle): + return sTitle in self._headings + + def items(self): + return self._headings.items() + + def headings(self): + return sorted(self._headings.keys()) + + def allTags(self): + """Return a list of all tags in the current item. + """ + tags = [] + for hItem in self._headings.values(): + tag = hItem.tag + if tag: + tags.append(tag) + return tags + + ## + # Pack/Unpack + ## + + def packData(self): + """Pack the indexed item's data into a dictionary. + """ + heads = {} + refs = {} + for sTitle, hItem in self._headings.items(): + heads[sTitle] = hItem.packData() + hRefs = hItem.packReferences() + if hRefs: + refs[sTitle] = hRefs + + data = {"level": self._level} + data["headings"] = heads + if refs: + data["references"] = refs + + return data + + def unpackData(self, data): + """Unpack an item entry from the data. + """ + self._level = data.get("level", "H0") + references = data.get("references", {}) + for sTitle, hData in data.get("headings", {}).items(): + if not isTitleTag(sTitle): + raise ValueError("The itemIndex contains an invalid title key") + tHeading = IndexHeading(sTitle) + tHeading.unpackData(hData) + tHeading.unpackReferences(references.get(sTitle, {})) + self.addHeading(tHeading) + return + +# END Class IndexItem + + +class IndexHeading: + """This object represents a section of text in a project item + associated with a single (valid) heading. It holds a separate record + of all references made under each heading. + """ + + def __init__(self, key, level="H0", title=""): + self._key = key + self._level = level + self._title = title + + self._charCount = 0 + self._wordCount = 0 + self._paraCount = 0 + self._synopsis = "" + + self._tag = "" + self._refs = {} + + return + + def __repr__(self): + return f"" + + ## + # Properties + ## + + @property + def key(self): + return self._key + + @property + def level(self): + return self._level + + @property + def title(self): + return self._title + + @property + def charCount(self): + return self._charCount + + @property + def wordCount(self): + return self._wordCount + + @property + def paraCount(self): + return self._paraCount + + @property + def synopsis(self): + return self._synopsis + + @property + def tag(self): + return self._tag + + @property + def references(self): + return self._refs + + ## + # Setters + ## + + def setLevel(self, level): + """Set the level of the header if it's a valid value. + """ + if level in nwHeaders.H_VALID: + self._level = level + return + + def setCounts(self, charCount, wordCount, paraCount): + """Set the character, word and paragraph count. Make sure the + value is an integer and is not smaller than 0. + """ + self._charCount = max(0, checkInt(charCount, 0)) + self._wordCount = max(0, checkInt(wordCount, 0)) + self._paraCount = max(0, checkInt(paraCount, 0)) + return + + def setSynopsis(self, synopText): + """Set the synopsis text and make sure it is a string. + """ + self._synopsis = str(synopText) + return + + def setTag(self, tagKey): + """Set the tag for references, and make sure it is a string. + """ + self._tag = str(tagKey) + return + + def addReference(self, tagKey, refType): + """Add a record of a reference tag, and what keyword types it is + associated with. + """ + if refType in nwKeyWords.VALID_KEYS: + if tagKey not in self._refs: + self._refs[tagKey] = set() + self._refs[tagKey].add(refType) + return + + ## + # Data Methods + ## + + def packData(self): + """Pack the values into a dictionary for saving to cache. + """ + return { + "level": self._level, + "title": self._title, + "tag": self._tag, + "cCount": self._charCount, + "wCount": self._wordCount, + "pCount": self._paraCount, + "synopsis": self._synopsis, + } + + def packReferences(self): + """Pack references into a dictionary for saving to cache. + Multiple types are packed into a sorted, comma separated string. + It is sorted to prevent creating unnecessary diffs as the order + of a set is not guaranteed. + """ + return {key: ",".join(sorted(list(value))) for key, value in self._refs.items()} + + def unpackData(self, data): + """Unpack a heading entry from a dictionary. + """ + self.setLevel(data.get("level", "H0")) + self._title = str(data.get("title", "")) + self._tag = str(data.get("tag", "")) + self.setCounts( + data.get("cCount", 0), + data.get("wCount", 0), + data.get("pCount", 0), + ) + self._synopsis = str(data.get("synopsis", "")) + return + + def unpackReferences(self, data): + """Unpack a set of references from a dictionary. + """ + for tagKey, refTypes in data.items(): + if not isinstance(tagKey, str): + raise ValueError("itemIndex reference key must be a string") + if not isinstance(refTypes, str): + raise ValueError("itemIndex reference type must be a string") + for refType in refTypes.split(","): + if refType in nwKeyWords.VALID_KEYS: + self.addReference(tagKey, refType) + else: + raise ValueError("The itemIndex contains an invalid reference type") + return + +# END Class IndexHeading + + # =============================================================================================== # # Simple Word Counter # =============================================================================================== # diff --git a/novelwriter/core/item.py b/novelwriter/core/item.py index 8c7b2ef4..95418079 100644 --- a/novelwriter/core/item.py +++ b/novelwriter/core/item.py @@ -29,9 +29,9 @@ from lxml import etree from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout from novelwriter.common import ( - checkInt, isHandle, isItemClass, isItemLayout, isItemType + checkInt, isHandle, isItemClass, isItemLayout, isItemType, simplified ) -from novelwriter.constants import nwLabels, nwLists, trConst +from novelwriter.constants import nwLabels, trConst logger = logging.getLogger(__name__) @@ -45,11 +45,13 @@ class NWItem(): self._name = "" self._handle = None self._parent = None + self._root = None self._order = 0 self._type = nwItemType.NO_TYPE self._class = nwItemClass.NO_CLASS self._layout = nwItemLayout.NO_LAYOUT self._status = None + self._import = None self._expanded = False self._exported = True @@ -84,6 +86,10 @@ class NWItem(): def itemParent(self): return self._parent + @property + def itemRoot(self): + return self._root + @property def itemOrder(self): return self._order @@ -104,6 +110,10 @@ class NWItem(): def itemStatus(self): return self._status + @property + def itemImport(self): + return self._import + @property def isExpanded(self): return self._expanded @@ -139,24 +149,33 @@ class NWItem(): def packXML(self, xParent): """Pack all the data in the class instance into an XML object. """ - xPack = etree.SubElement(xParent, "item", attrib={ - "handle": str(self._handle), - "order": str(self._order), - "parent": str(self._parent), - }) - self._subPack(xPack, "name", text=str(self._name)) - self._subPack(xPack, "type", text=str(self._type.name)) - self._subPack(xPack, "class", text=str(self._class.name)) - self._subPack(xPack, "status", text=str(self._status)) + itemAttrib = {} + itemAttrib["handle"] = str(self._handle) + itemAttrib["parent"] = str(self._parent) + itemAttrib["root"] = str(self._root) + itemAttrib["order"] = str(self._order) + itemAttrib["type"] = str(self._type.name) + itemAttrib["class"] = str(self._class.name) if self._type == nwItemType.FILE: - self._subPack(xPack, "exported", text=str(self._exported)) - self._subPack(xPack, "layout", text=str(self._layout.name)) - self._subPack(xPack, "charCount", text=str(self._charCount), none=False) - self._subPack(xPack, "wordCount", text=str(self._wordCount), none=False) - self._subPack(xPack, "paraCount", text=str(self._paraCount), none=False) - self._subPack(xPack, "cursorPos", text=str(self._cursorPos), none=False) - else: - self._subPack(xPack, "expanded", text=str(self._expanded)) + itemAttrib["layout"] = str(self._layout.name) + + metaAttrib = {} + metaAttrib["expanded"] = str(self._expanded) + if self._type == nwItemType.FILE: + metaAttrib["charCount"] = str(self._charCount) + metaAttrib["wordCount"] = str(self._wordCount) + metaAttrib["paraCount"] = str(self._paraCount) + metaAttrib["cursorPos"] = str(self._cursorPos) + + nameAttrib = {} + nameAttrib["status"] = str(self._status) + nameAttrib["import"] = str(self._import) + if self._type == nwItemType.FILE: + nameAttrib["exported"] = str(self._exported) + + xPack = etree.SubElement(xParent, "item", attrib=itemAttrib) + self._subPack(xPack, "meta", attrib=metaAttrib) + self._subPack(xPack, "name", text=str(self._name), attrib=nameAttrib) return @@ -174,20 +193,34 @@ class NWItem(): return False self.setParent(xItem.attrib.get("parent", None)) + self.setRoot(xItem.attrib.get("root", None)) self.setOrder(xItem.attrib.get("order", 0)) + self.setType(xItem.attrib.get("type", nwItemType.NO_TYPE)) + self.setClass(xItem.attrib.get("class", nwItemClass.NO_CLASS)) + self.setLayout(xItem.attrib.get("layout", nwItemLayout.NO_LAYOUT)) - tmpStatus = "" for xValue in xItem: - if xValue.tag == "name": + if xValue.tag == "meta": + self.setExpanded(xValue.attrib.get("expanded", False)) + self.setCharCount(xValue.attrib.get("charCount", 0)) + self.setWordCount(xValue.attrib.get("wordCount", 0)) + self.setParaCount(xValue.attrib.get("paraCount", 0)) + self.setCursorPos(xValue.attrib.get("cursorPos", 0)) + elif xValue.tag == "name": self.setName(xValue.text) + self.setStatus(xValue.attrib.get("status", None)) + self.setImport(xValue.attrib.get("import", None)) + self.setExported(xValue.attrib.get("exported", True)) + + # Legacy Format (1.3 and earlier) + elif xValue.tag == "status": + self.setImportStatus(xValue.text) elif xValue.tag == "type": self.setType(xValue.text) elif xValue.tag == "class": self.setClass(xValue.text) elif xValue.tag == "layout": self.setLayout(xValue.text) - elif xValue.tag == "status": - tmpStatus = xValue.text elif xValue.tag == "expanded": self.setExpanded(xValue.text) elif xValue.tag == "exported": @@ -206,8 +239,16 @@ class NWItem(): # version of novelWriter that doesn't know the tag logger.error("Unknown tag '%s'", xValue.tag) - # Guarantees that is parsed after - self.setStatus(tmpStatus) + # Make some checks to ensure consistency + if self._type == nwItemType.ROOT: + self._root = self._handle # Root items are their own ancestor + self._parent = None # Root items cannot have a parent + + if self._type != nwItemType.FILE: + self._charCount = 0 # Only set for files + self._wordCount = 0 # Only set for files + self._paraCount = 0 # Only set for files + self._cursorPos = 0 # Only set for files return True @@ -225,7 +266,7 @@ class NWItem(): return ## - # Methods + # Lookup Methods ## def describeMe(self, hLevel=None): @@ -251,142 +292,245 @@ class NWItem(): return trConst(nwLabels.ITEM_DESCRIPTION.get(descKey, "")) + def getImportStatus(self): + """Return the relevant importance or status label and icon for + the current item based on its class. + """ + if self.isNovelLike(): + stName = self.theProject.statusItems.name(self._status) + stIcon = self.theProject.statusItems.icon(self._status) + else: + stName = self.theProject.importItems.name(self._import) + stIcon = self.theProject.importItems.icon(self._import) + return stName, stIcon + + ## + # Checker Methods + ## + + def isNovelLike(self): + """Returns true if the item is of a novel-like class. + """ + return self._class in (nwItemClass.NOVEL, nwItemClass.ARCHIVE) + + def documentAllowed(self): + """Returns true if the item is allowed to be of document layout. + """ + return self._class in (nwItemClass.NOVEL, nwItemClass.ARCHIVE, nwItemClass.TRASH) + + def isInactive(self): + """Returns true if the item is in an inactive class. + """ + return self._class in (nwItemClass.NO_CLASS, nwItemClass.ARCHIVE, nwItemClass.TRASH) + + def isRootType(self): + return self._type == nwItemType.ROOT + + def isFolderType(self): + return self._type == nwItemType.FOLDER + + def isFileType(self): + return self._type == nwItemType.FILE + + def isNoteLayout(self): + return self._layout == nwItemLayout.NOTE + + def isDocumentLayout(self): + return self._layout == nwItemLayout.DOCUMENT + + ## + # Special Setters + ## + + def setImportStatus(self, value): + """Update the importance or status value based on class. This is + a wrapper setter for setStatus and setImport. + """ + if self.isNovelLike(): + self.setStatus(value) + else: + self.setImport(value) + return + + def setClassDefaults(self, itemClass): + """Set the default values based on the item's class and the + project settings. + """ + if self._parent is not None: + # Only update for child items + self.setClass(itemClass) + + if self._layout == nwItemLayout.NO_LAYOUT: + # If no layout is set, pick one + if self.isNovelLike(): + self._layout = nwItemLayout.DOCUMENT + else: + self._layout = nwItemLayout.NOTE + elif not self.documentAllowed(): + # Change layout to note if it is not in an allowed folder + self._layout = nwItemLayout.NOTE + + if self._status is None: + self.setStatus("New") # This forces a default value lookup + + if self._import is None: + self.setImport("New") # This forces a default value lookup + + return + ## # Set Item Values ## - def setName(self, theName): + def setName(self, name): """Set the item name. """ - if isinstance(theName, str): - self._name = theName.strip() + if isinstance(name, str): + self._name = simplified(name) else: self._name = "" return - def setHandle(self, theHandle): + def setHandle(self, handle): """Set the item handle, and ensure it is valid. """ - if isHandle(theHandle): - self._handle = theHandle + if isHandle(handle): + self._handle = handle else: self._handle = None return - def setParent(self, theParent): + def setParent(self, handle): """Set the parent handle, and ensure it is valid. """ - if theParent is None: + if handle is None: self._parent = None - elif isHandle(theParent): - self._parent = theParent + elif isHandle(handle): + self._parent = handle else: self._parent = None return - def setOrder(self, theOrder): + def setRoot(self, handle): + """Set the root handle, and ensure it is valid. + """ + if handle is None: + self._root = None + elif isHandle(handle): + self._root = handle + else: + self._root = None + return + + def setOrder(self, order): """Set the item order, and ensure that it is valid. This value is purely a meta value, and not actually used by novelWriter at the moment. """ - self._order = checkInt(theOrder, 0) + self._order = checkInt(order, 0) return - def setType(self, theType): + def setType(self, value): """Set the item type from either a proper nwItemType, or set it from a string representing an nwItemType. """ - if isinstance(theType, nwItemType): - self._type = theType - elif isItemType(theType): - self._type = nwItemType[theType] + if isinstance(value, nwItemType): + self._type = value + elif isItemType(value): + self._type = nwItemType[value] + elif value == "TRASH": + self._type = nwItemType.ROOT else: - logger.error("Unrecognised item type '%s'", theType) + logger.error("Unrecognised item type '%s'", value) self._type = nwItemType.NO_TYPE return - def setClass(self, theClass): + def setClass(self, value): """Set the item class from either a proper nwItemClass, or set it from a string representing an nwItemClass. """ - if isinstance(theClass, nwItemClass): - self._class = theClass - elif isItemClass(theClass): - self._class = nwItemClass[theClass] + if isinstance(value, nwItemClass): + self._class = value + elif isItemClass(value): + self._class = nwItemClass[value] else: - logger.error("Unrecognised item class '%s'", theClass) + logger.error("Unrecognised item class '%s'", value) self._class = nwItemClass.NO_CLASS return - def setLayout(self, theLayout): + def setLayout(self, value): """Set the item layout from either a proper nwItemLayout, or set it from a string representing an nwItemLayout. """ - if isinstance(theLayout, nwItemLayout): - self._layout = theLayout - elif isItemLayout(theLayout): - self._layout = nwItemLayout[theLayout] - elif theLayout in nwLists.DEP_LAYOUT: + if isinstance(value, nwItemLayout): + self._layout = value + elif isItemLayout(value): + self._layout = nwItemLayout[value] + elif value in ("TITLE", "PAGE", "BOOK", "PARTITION", "UNNUMBERED", "CHAPTER", "SCENE"): self._layout = nwItemLayout.DOCUMENT else: - logger.error("Unrecognised item layout '%s'", theLayout) + logger.error("Unrecognised item layout '%s'", value) self._layout = nwItemLayout.NO_LAYOUT return - def setStatus(self, theStatus): + def setStatus(self, value): """Set the item status by looking it up in the valid status items of the current project. """ - if self._class in nwLists.CLS_NOVEL: - self._status = self.theProject.statusItems.checkEntry(theStatus) - else: - self._status = self.theProject.importItems.checkEntry(theStatus) + self._status = self.theProject.statusItems.check(value) return - def setExpanded(self, expState): + def setImport(self, value): + """Set the item importance by looking it up in the valid import + items of the current project. + """ + self._import = self.theProject.importItems.check(value) + return + + def setExpanded(self, state): """Set the expanded status of an item in the project tree. """ - if isinstance(expState, str): - self._expanded = (expState == str(True)) + if isinstance(state, str): + self._expanded = (state == str(True)) else: - self._expanded = (expState is True) + self._expanded = (state is True) return - def setExported(self, expState): + def setExported(self, state): """Set the export flag. """ - if isinstance(expState, str): - self._exported = (expState == str(True)) + if isinstance(state, str): + self._exported = (state == str(True)) else: - self._exported = (expState is True) + self._exported = (state is True) return ## # Set Document Meta Data ## - def setCharCount(self, theCount): + def setCharCount(self, count): """Set the character count, and ensure that it is an integer. """ - self._charCount = max(0, checkInt(theCount, 0)) + self._charCount = max(0, checkInt(count, 0)) return - def setWordCount(self, theCount): + def setWordCount(self, count): """Set the word count, and ensure that it is an integer. """ - self._wordCount = max(0, checkInt(theCount, 0)) + self._wordCount = max(0, checkInt(count, 0)) return - def setParaCount(self, theCount): + def setParaCount(self, count): """Set the paragraph count, and ensure that it is an integer. """ - self._paraCount = max(0, checkInt(theCount, 0)) + self._paraCount = max(0, checkInt(count, 0)) return - def setCursorPos(self, thePosition): + def setCursorPos(self, position): """Set the cursor position, and ensure that it is an integer. """ - self._cursorPos = max(0, checkInt(thePosition, 0)) + self._cursorPos = max(0, checkInt(position, 0)) return def saveInitialCount(self): diff --git a/novelwriter/core/options.py b/novelwriter/core/options.py index 144ba4ac..d64970ae 100644 --- a/novelwriter/core/options.py +++ b/novelwriter/core/options.py @@ -28,6 +28,8 @@ import os import json import logging +from enum import Enum + from novelwriter.error import logException from novelwriter.common import checkBool, checkFloat, checkInt, checkString from novelwriter.constants import nwFiles @@ -56,7 +58,8 @@ VALID_MAP = { "winWidth", "winHeight", "widthCol0", "widthCol1", "widthCol2", "widthCol3", "widthCol4", "wordsPerPage", "countFrom", "clearDouble" }, - "GuiWordList": {"winWidth", "winHeight"} + "GuiWordList": {"winWidth", "winHeight"}, + "GuiNovelView": {"lastCol"}, } @@ -137,7 +140,10 @@ class OptionState(): if group not in self._theState: self._theState[group] = {} - self._theState[group][name] = value + if isinstance(value, Enum): + self._theState[group][name] = value.name + else: + self._theState[group][name] = value return True @@ -186,4 +192,16 @@ class OptionState(): return checkBool(self._theState[group].get(name, default), default) return default + def getEnum(self, group, name, lookup, default): + """Return the value mapped to an enum. Otherwise return the + default value + """ + if issubclass(lookup, Enum): + if group in self._theState: + if name in self._theState[group]: + value = self._theState[group][name] + if value in lookup.__members__: + return lookup[value] + return default + # END Class OptionState diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 26d2c098..1dffd1aa 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -37,6 +37,7 @@ from PyQt5.QtCore import QCoreApplication from novelwriter.core.tree import NWTree from novelwriter.core.item import NWItem +from novelwriter.core.index import NWIndex from novelwriter.core.status import NWStatus from novelwriter.core.options import OptionState from novelwriter.core.document import NWDoc @@ -44,7 +45,7 @@ from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert from novelwriter.error import logException from novelwriter.common import ( checkString, checkBool, checkInt, isHandle, formatTimeStamp, - makeFileNameSafe, hexToInt + makeFileNameSafe, hexToInt, minmax, simplified ) from novelwriter.constants import trConst, nwFiles, nwLabels @@ -53,18 +54,19 @@ logger = logging.getLogger(__name__) class NWProject(): - FILE_VERSION = "1.3" + FILE_VERSION = "1.4" # The current project file format version - def __init__(self, theParent): + def __init__(self, mainGui): # Internal - self.theParent = theParent - self.mainConf = novelwriter.CONFIG + self.mainConf = novelwriter.CONFIG + self.mainGui = mainGui # Core Elements - self.optState = OptionState(self) # Project-specific GUI options - self.projTree = NWTree(self) # The project tree - self.langData = {} # Localisation data + self._optState = OptionState(self) # Project-specific GUI options + self._projTree = NWTree(self) # The project tree + self._projIndex = NWIndex(self) # The projecty index + self._langData = {} # Localisation data # Project Status self.projOpened = 0 # The time stamp of when the project file was opened @@ -87,7 +89,7 @@ class NWProject(): self.projFiles = [] # A list of all files in the content folder on load # Project Meta - self.projName = "" # Project name (working title) + self.projName = "" # Project name self.bookTitle = "" # The final title; should only be used for exports self.bookAuthors = [] # A list of book authors @@ -95,11 +97,12 @@ class NWProject(): self.autoReplace = {} # Text to auto-replace on exports self.titleFormat = {} # The formatting of titles for exports self.spellCheck = False # Controls the spellcheck-as-you-type feature - self.autoOutline = True # If true, the Project Outline is updated automatically self.statusItems = None # Novel file progress status values self.importItems = None # Note file importance values self.lastEdited = None # The handle of the last file to be edited self.lastViewed = None # The handle of the last file to be viewed + self.lastNovel = None # The handle of the last novel root viewed + self.lastOutline = None # The handle of the last outline root viewed self.lastWCount = 0 # The project word count from last session self.lastNovelWC = 0 # The novel files word count from last session self.lastNotesWC = 0 # The note files word count from last session @@ -116,63 +119,100 @@ class NWProject(): return + ## + # Properties + ## + + @property + def index(self): + return self._projIndex + + @property + def tree(self): + return self._projTree + + @property + def options(self): + return self._optState + ## # Item Methods ## - def newRoot(self, rootName, rootClass): - """Add a new root item. These items are unique, except for item class - CUSTOM, and always have parent handle set to None. + def newRoot(self, itemClass, label=None): + """Add a new root item. If label is None, use the class label. """ - if not self.projTree.checkRootUnique(rootClass): - self.theParent.makeAlert(self.tr("Duplicate root item detected."), nwAlert.ERROR) - return None - + if label is None: + label = trConst(nwLabels.CLASS_NAME[itemClass]) newItem = NWItem(self) - newItem.setName(rootName) + newItem.setName(label) newItem.setType(nwItemType.ROOT) - newItem.setClass(rootClass) - newItem.setStatus(0) - self.projTree.append(None, None, newItem) + newItem.setClass(itemClass) + self._projTree.append(None, None, newItem) + self._projTree.updateItemData(newItem.itemHandle) return newItem.itemHandle - def newFolder(self, folderName, folderClass, pHandle): - """Add a new folder with a given name and class and parent item. + def newFolder(self, label, pHandle): + """Add a new folder with a given label and parent item. """ + if pHandle not in self._projTree: + return None newItem = NWItem(self) - newItem.setName(folderName) + newItem.setName(label) newItem.setType(nwItemType.FOLDER) - newItem.setClass(folderClass) - newItem.setStatus(0) - self.projTree.append(None, pHandle, newItem) + self._projTree.append(None, pHandle, newItem) + self._projTree.updateItemData(newItem.itemHandle) return newItem.itemHandle - def newFile(self, fileName, fileClass, pHandle): - """Add a new file with a given name and class, and set a layout - based on the class. DOCUMENT for NOVEL, otherwise NOTE. + def newFile(self, label, pHandle): + """Add a new file with a given label and parent item. """ + if pHandle not in self._projTree: + return None newItem = NWItem(self) - newItem.setName(fileName) + newItem.setName(label) newItem.setType(nwItemType.FILE) - if fileClass == nwItemClass.NOVEL: - newItem.setLayout(nwItemLayout.DOCUMENT) - else: - newItem.setLayout(nwItemLayout.NOTE) - newItem.setClass(fileClass) - newItem.setStatus(0) - self.projTree.append(None, pHandle, newItem) + self._projTree.append(None, pHandle, newItem) + self._projTree.updateItemData(newItem.itemHandle) return newItem.itemHandle + def writeNewFile(self, tHandle, hLevel, isDocument): + """Write content to a new document after it is created. This + will not run if the file exists and is not empty. + """ + tItem = self._projTree[tHandle] + if tItem is None: + return False + if not tItem.isFileType(): + return False + + newDoc = NWDoc(self, tHandle) + if newDoc.readDocument().strip(): + return False + + hshText = "#"*minmax(hLevel, 1, 4) + newText = f"{hshText} {tItem.itemName}\n\n" + if tItem.isNovelLike() and isDocument: + tItem.setLayout(nwItemLayout.DOCUMENT) + else: + tItem.setLayout(nwItemLayout.NOTE) + + newDoc.writeDocument(newText) + self._projIndex.scanText(tHandle, newText) + + return True + def trashFolder(self): """Add the special trash root folder to the project. """ - trashHandle = self.projTree.trashRoot() + trashHandle = self._projTree.trashRoot() if trashHandle is None: newItem = NWItem(self) newItem.setName(trConst(nwLabels.CLASS_NAME[nwItemClass.TRASH])) - newItem.setType(nwItemType.TRASH) + newItem.setType(nwItemType.ROOT) newItem.setClass(nwItemClass.TRASH) - self.projTree.append(None, None, newItem) + self._projTree.append(None, None, newItem) + self._projTree.updateItemData(newItem.itemHandle) return newItem.itemHandle return trashHandle @@ -193,7 +233,7 @@ class NWProject(): self.autoCount = 0 # Project Tree - self.projTree.clear() + self._projTree.clear() # Project Settings self.projPath = None @@ -217,17 +257,16 @@ class NWProject(): "section": "", } self.spellCheck = False - self.autoOutline = True - self.statusItems = NWStatus() - self.statusItems.addEntry(self.tr("New"), (100, 100, 100)) - self.statusItems.addEntry(self.tr("Note"), (200, 50, 0)) - self.statusItems.addEntry(self.tr("Draft"), (200, 150, 0)) - self.statusItems.addEntry(self.tr("Finished"), (50, 200, 0)) - self.importItems = NWStatus() - self.importItems.addEntry(self.tr("New"), (100, 100, 100)) - self.importItems.addEntry(self.tr("Minor"), (200, 50, 0)) - self.importItems.addEntry(self.tr("Major"), (200, 150, 0)) - self.importItems.addEntry(self.tr("Main"), (50, 200, 0)) + self.statusItems = NWStatus(NWStatus.STATUS) + self.statusItems.write(None, self.tr("New"), (100, 100, 100)) + self.statusItems.write(None, self.tr("Note"), (200, 50, 0)) + self.statusItems.write(None, self.tr("Draft"), (200, 150, 0)) + self.statusItems.write(None, self.tr("Finished"), (50, 200, 0)) + self.importItems = NWStatus(NWStatus.IMPORT) + self.importItems.write(None, self.tr("New"), (100, 100, 100)) + self.importItems.write(None, self.tr("Minor"), (200, 50, 0)) + self.importItems.write(None, self.tr("Major"), (200, 150, 0)) + self.importItems.write(None, self.tr("Main"), (50, 200, 0)) self.lastEdited = None self.lastViewed = None self.lastWCount = 0 @@ -267,6 +306,7 @@ class NWProject(): logger.error("No project path set for the new project") return False + self.clearProject() if not self.setProjectPath(projPath, newProject=True): return False @@ -274,86 +314,88 @@ class NWProject(): self.setBookTitle(projTitle) self.setBookAuthors(projAuthors) + hNovelRoot = self.newRoot(nwItemClass.NOVEL) + hTitlePage = self.newFile(self.tr("Title Page"), hNovelRoot) + titlePage = "#! %s\n\n" % (self.bookTitle if self.bookTitle else self.projName) if self.bookAuthors: titlePage = "%s>> %s %s <<\n" % (titlePage, self.tr("By"), self.getAuthors()) + aDoc = NWDoc(self, hTitlePage) + aDoc.writeDocument(titlePage) + if popMinimal: # Creating a minimal project with a few root folders and a - # single chapter folder with a single file. - xHandle = {} - xHandle[1] = self.newRoot(self.tr("Novel"), nwItemClass.NOVEL) - xHandle[2] = self.newRoot(self.tr("Plot"), nwItemClass.PLOT) - xHandle[3] = self.newRoot(self.tr("Characters"), nwItemClass.CHARACTER) - xHandle[4] = self.newRoot(self.tr("World"), nwItemClass.WORLD) - xHandle[5] = self.newFile(self.tr("Title Page"), nwItemClass.NOVEL, xHandle[1]) - xHandle[6] = self.newFolder(self.tr("New Chapter"), nwItemClass.NOVEL, xHandle[1]) - xHandle[7] = self.newFile(self.tr("New Chapter"), nwItemClass.NOVEL, xHandle[6]) - xHandle[8] = self.newFile(self.tr("New Scene"), nwItemClass.NOVEL, xHandle[6]) - - aDoc = NWDoc(self, xHandle[5]) - aDoc.writeDocument(titlePage) - - aDoc = NWDoc(self, xHandle[7]) + # single chapter with a single scene. + hChapter = self.newFile(self.tr("New Chapter"), hNovelRoot) + aDoc = NWDoc(self, hChapter) aDoc.writeDocument("## %s\n\n" % self.tr("New Chapter")) - aDoc = NWDoc(self, xHandle[8]) + hScene = self.newFile(self.tr("New Scene"), hChapter) + aDoc = NWDoc(self, hScene) aDoc.writeDocument("### %s\n\n" % self.tr("New Scene")) + self.newRoot(nwItemClass.PLOT) + self.newRoot(nwItemClass.CHARACTER) + self.newRoot(nwItemClass.WORLD) + self.newRoot(nwItemClass.ARCHIVE) + elif popCustom: # Create a project structure based on selected root folders # and a number of chapters and scenes selected in the # wizard's custom page. - # Create root folders - nHandle = self.newRoot(self.tr("Novel"), nwItemClass.NOVEL) - for newRoot in projData.get("addRoots", []): - if newRoot in nwItemClass: - self.newRoot(trConst(nwLabels.CLASS_NAME[newRoot]), newRoot) - - # Create a title page - tHandle = self.newFile(self.tr("Title Page"), nwItemClass.NOVEL, nHandle) - self.projTree.setFileItemLayout(tHandle, nwItemLayout.DOCUMENT) - - aDoc = NWDoc(self, tHandle) - aDoc.writeDocument(titlePage) - # Create chapters and scenes numChapters = projData.get("numChapters", 0) numScenes = projData.get("numScenes", 0) - chFolders = projData.get("chFolders", False) + + chSynop = self.tr("Summary of the chapter.") + scSynop = self.tr("Summary of the scene.") # Create chapters if numChapters > 0: for ch in range(numChapters): chTitle = self.tr("Chapter {0}").format(f"{ch+1:d}") - pHandle = nHandle - if chFolders: - pHandle = self.newFolder(chTitle, nwItemClass.NOVEL, nHandle) - - cHandle = self.newFile(chTitle, nwItemClass.NOVEL, pHandle) - self.projTree.setFileItemLayout(cHandle, nwItemLayout.DOCUMENT) - + cHandle = self.newFile(chTitle, hNovelRoot) aDoc = NWDoc(self, cHandle) - aDoc.writeDocument("## %s\n\n" % chTitle) + aDoc.writeDocument(f"## {chTitle}\n\n% Synopsis: {chSynop}\n\n") # Create chapter scenes if numScenes > 0: for sc in range(numScenes): scTitle = self.tr("Scene {0}").format(f"{ch+1:d}.{sc+1:d}") - sHandle = self.newFile(scTitle, nwItemClass.NOVEL, pHandle) - + sHandle = self.newFile(scTitle, cHandle) aDoc = NWDoc(self, sHandle) - aDoc.writeDocument("### %s\n\n" % scTitle) + aDoc.writeDocument(f"### {scTitle}\n\n% Synopsis: {scSynop}\n\n") # Create scenes (no chapters) elif numScenes > 0: for sc in range(numScenes): scTitle = self.tr("Scene {0}").format(f"{sc+1:d}") - sHandle = self.newFile(scTitle, nwItemClass.NOVEL, nHandle) - + sHandle = self.newFile(scTitle, hNovelRoot) aDoc = NWDoc(self, sHandle) - aDoc.writeDocument("### %s\n\n" % scTitle) + aDoc.writeDocument(f"### {scTitle}\n\n% Synopsis: {scSynop}\n\n") + + # Create notes folders + noteTitles = { + nwItemClass.PLOT: self.tr("Main Plot"), + nwItemClass.CHARACTER: self.tr("Protagonist"), + nwItemClass.WORLD: self.tr("Main Location"), + } + + addNotes = projData.get("addNotes", False) + for newRoot in projData.get("addRoots", []): + if newRoot in nwItemClass: + rHandle = self.newRoot(newRoot) + if addNotes: + aHandle = self.newFile(noteTitles[newRoot], rHandle) + ntTag = simplified(noteTitles[newRoot]).replace(" ", "") + aDoc = NWDoc(self, aHandle) + aDoc.writeDocument(f"# {noteTitles[newRoot]}\n\n@tag: {ntTag}\n\n") + + # Also add the archive and trash folders + self.newRoot(nwItemClass.ARCHIVE) + self.trashFolder() # Finalise if popCustom or popMinimal: @@ -372,7 +414,7 @@ class NWProject(): if not os.path.isfile(fileName): fileName = os.path.join(fileName, nwFiles.PROJ_FILE) if not os.path.isfile(fileName): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "File not found: {0}" ).format(fileName), nwAlert.ERROR) return False @@ -396,7 +438,7 @@ class NWProject(): legacyList = [] # Cleanup is done later for projItem in os.listdir(self.projPath): logger.verbose("Project contains: %s", projItem) - if projItem.startswith("data_"): + if projItem.startswith("data_") and len(projItem) == 6: legacyList.append(projItem) # Project Lock @@ -423,20 +465,20 @@ class NWProject(): try: nwXML = etree.parse(fileName) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to parse project xml." ), nwAlert.ERROR, exception=exc) # Trying to open backup file instead backFile = fileName[:-3]+"bak" if os.path.isfile(backFile): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Attempting to open backup project file instead." ), nwAlert.INFO) try: nwXML = etree.parse(backFile) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to parse project xml." ), nwAlert.ERROR, exception=exc) self.clearProject() @@ -458,8 +500,8 @@ class NWProject(): # Check File Type # =============== - if not nwxRoot == "novelWriterXML": - self.theParent.makeAlert(self.tr( + if nwxRoot != "novelWriterXML": + self.mainGui.makeAlert(self.tr( "Project file does not appear to be a novelWriterXML file." ), nwAlert.ERROR) self.clearProject() @@ -479,9 +521,13 @@ class NWProject(): # 1.3 : Reduces the number of layouts to only two. One for novel # documents and one for project notes. Introduced in # version 1.5. + # 1.4 : Introduces a more compact format for storing items. All + # settings aside from name are now attributes. This format + # also changes the way satus and importance labels are + # stored and handled. Introduced in version 1.7. - if fileVersion not in ("1.0", "1.1", "1.2", "1.3"): - self.theParent.makeAlert(self.tr( + if fileVersion not in ("1.0", "1.1", "1.2", "1.3", "1.4"): + self.mainGui.makeAlert(self.tr( "Unknown or unsupported novelWriter project file format. " "The project cannot be opened by this version of novelWriter. " "The file was saved with novelWriter version {0}." @@ -490,7 +536,7 @@ class NWProject(): return False if fileVersion != self.FILE_VERSION: - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("File Version"), self.tr( "The file format of your project is about to be updated. " @@ -506,7 +552,7 @@ class NWProject(): # ========================= if hexToInt(hexVersion) > hexToInt(novelwriter.__hexversion__): - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("Version Conflict"), self.tr( "This project was saved by a newer version of " @@ -530,14 +576,16 @@ class NWProject(): if xItem.text is None: continue if xItem.tag == "name": - logger.verbose("Working Title: '%s'", xItem.text) - self.projName = xItem.text + self.projName = checkString(simplified(xItem.text), "") + logger.verbose("Working Title: '%s'", self.projName) elif xItem.tag == "title": - logger.verbose("Title is '%s'", xItem.text) - self.bookTitle = xItem.text + self.bookTitle = checkString(simplified(xItem.text), "") + logger.verbose("Title is '%s'", self.bookTitle) elif xItem.tag == "author": - logger.verbose("Author: '%s'", xItem.text) - self.bookAuthors.append(xItem.text) + author = checkString(simplified(xItem.text), "") + if author: + self.bookAuthors.append(author) + logger.verbose("Author: '%s'", author) elif xItem.tag == "saveCount": self.saveCount = checkInt(xItem.text, 0) elif xItem.tag == "autoCount": @@ -558,12 +606,14 @@ class NWProject(): self.spellCheck = checkBool(xItem.text, False) elif xItem.tag == "spellLang": self.projSpell = checkString(xItem.text, None, True) - elif xItem.tag == "autoOutline": - self.autoOutline = checkBool(xItem.text, True) elif xItem.tag == "lastEdited": self.lastEdited = checkString(xItem.text, None, True) elif xItem.tag == "lastViewed": self.lastViewed = checkString(xItem.text, None, True) + elif xItem.tag == "lastNovel": + self.lastNovel = checkString(xItem.text, None, True) + elif xItem.tag == "lastOutline": + self.lastOutline = checkString(xItem.text, None, True) elif xItem.tag == "lastWordCount": self.lastWCount = checkInt(xItem.text, 0, False) elif xItem.tag == "novelWordCount": @@ -588,17 +638,20 @@ class NWProject(): elif xChild.tag == "content": logger.debug("Found project content") - self.projTree.unpackXML(xChild) + self._projTree.unpackXML(xChild) - self.optState.loadSettings() + self._optState.loadSettings() # Sort out old file locations if legacyList: - errList = [] - for projItem in legacyList: - errList = self._legacyDataFolder(projItem, errList) - if errList: - self.theParent.makeAlert(errList, nwAlert.ERROR) + try: + for projItem in legacyList: + self._legacyDataFolder(projItem) + except Exception: + self.mainGui.makeAlert(self.tr( + "There was an error updating the project. " + "Some data may not have been preserved." + ), nwAlert.ERROR) # Clean up no longer used files self._deprecatedFiles() @@ -607,7 +660,13 @@ class NWProject(): self.mainConf.updateRecentCache(self.projPath, self.projName, self.lastWCount, time()) self.mainConf.saveRecentCache() - self.theParent.setStatus(self.tr("Opened Project: {0}").format(self.projName)) + # Check the project tree consistency + for tItem in self._projTree: + tHandle = tItem.itemHandle + logger.verbose("Checking item '%s'", tHandle) + if not self._projTree.updateItemData(tHandle): + logger.error("There was a problem item '%s', and it has been removed", tHandle) + del self._projTree[tHandle] # The file will be re-added as orphaned self._scanProjectFolder() self._loadProjectLocalisation() @@ -618,6 +677,7 @@ class NWProject(): self._writeLockFile() self.setProjectChanged(False) + self.mainGui.setStatus(self.tr("Opened Project: {0}").format(self.projName)) return True @@ -628,7 +688,7 @@ class NWProject(): file. """ if self.projPath is None: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Project path not set, cannot save project." ), nwAlert.ERROR) return False @@ -671,9 +731,10 @@ class NWProject(): self._packProjectValue(xSettings, "language", self.projLang) self._packProjectValue(xSettings, "spellCheck", self.spellCheck) self._packProjectValue(xSettings, "spellLang", self.projSpell) - self._packProjectValue(xSettings, "autoOutline", self.autoOutline) self._packProjectValue(xSettings, "lastEdited", self.lastEdited) self._packProjectValue(xSettings, "lastViewed", self.lastViewed) + self._packProjectValue(xSettings, "lastNovel", self.lastNovel) + self._packProjectValue(xSettings, "lastOutline", self.lastOutline) self._packProjectValue(xSettings, "lastWordCount", self.currWCount) self._packProjectValue(xSettings, "novelWordCount", self.currNovelWC) self._packProjectValue(xSettings, "notesWordCount", self.currNotesWC) @@ -684,6 +745,8 @@ class NWProject(): if len(aKey) > 0: self._packProjectValue(xTitleFmt, aKey, aValue) + # Save Status/Importance + self.countStatus() xStatus = etree.SubElement(xSettings, "status") self.statusItems.packXML(xStatus) xStatus = etree.SubElement(xSettings, "importance") @@ -691,7 +754,7 @@ class NWProject(): # Save Tree Content logger.debug("Writing project content") - self.projTree.packXML(nwXML) + self._projTree.packXML(nwXML) # Write the xml tree to file tempFile = os.path.join(self.projPath, self.projFile+"~") @@ -706,7 +769,7 @@ class NWProject(): xml_declaration=True )) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to save project." ), nwAlert.ERROR, exception=exc) return False @@ -718,20 +781,20 @@ class NWProject(): os.replace(saveFile, backFile) os.replace(tempFile, saveFile) except OSError as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to save project." ), nwAlert.ERROR, exception=exc) return False # Save project GUI options - self.optState.saveSettings() + self._optState.saveSettings() # Update recent projects self.mainConf.updateRecentCache(self.projPath, self.projName, self.currWCount, saveTime) self.mainConf.saveRecentCache() self._writeLockFile() - self.theParent.setStatus(self.tr("Saved Project: {0}").format(self.projName)) + self.mainGui.setStatus(self.tr("Saved Project: {0}").format(self.projName)) self.setProjectChanged(False) return True @@ -740,8 +803,8 @@ class NWProject(): """Close the current project and clear all meta data. """ logger.info("Closing project: %s", self.projPath) - self.optState.saveSettings() - self.projTree.writeToCFile() + self._optState.saveSettings() + self._projTree.writeToCFile() self._appendSessionStats(idleTime) self._clearLockFile() self.clearProject() @@ -779,22 +842,22 @@ class NWProject(): def zipIt(self, doNotify): """Create a zip file of the entire project. """ - if not self.theParent.hasProject: + if not self.mainGui.hasProject: logger.error("No project open") return False logger.info("Backing up project") - self.theParent.setStatus(self.tr("Backing up project ...")) + self.mainGui.setStatus(self.tr("Backing up project ...")) if not (self.mainConf.backupPath and os.path.isdir(self.mainConf.backupPath)): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Cannot backup project because no valid backup path is set. " "Please set a valid backup location in Preferences." ), nwAlert.ERROR) return False if not self.projName: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Cannot backup project because no project name is set. " "Please set a Working Title in Project Settings." ), nwAlert.ERROR) @@ -807,13 +870,13 @@ class NWProject(): os.mkdir(baseDir) logger.debug("Created folder: %s", baseDir) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Could not create backup folder." ), nwAlert.ERROR, exception=exc) return False if baseDir and baseDir.startswith(self.projPath): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Cannot backup project because the backup path is within the " "project folder to be backed up. Please choose a different " "backup path in Preferences." @@ -829,17 +892,17 @@ class NWProject(): self._writeLockFile() logger.info("Backup written to: %s", archName) if doNotify: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Backup archive file written to: {0}" ).format(f"{os.path.join(cleanName, archName)}.zip"), nwAlert.INFO) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Could not write backup archive." ), nwAlert.ERROR, exception=exc) return False - self.theParent.setStatus(self.tr( + self.mainGui.setStatus(self.tr( "Project backed up to '{0}'" ).format(f"{baseName}.zip")) @@ -867,7 +930,7 @@ class NWProject(): shutil.unpack_archive(pkgSample, projPath) isSuccess = True except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to create a new example project." ), nwAlert.ERROR, exception=exc) @@ -889,12 +952,12 @@ class NWProject(): isSuccess = True except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to create a new example project." ), nwAlert.ERROR, exception=exc) else: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to create a new example project. " "Could not find the necessary files. " "They seem to be missing from this installation." @@ -902,8 +965,8 @@ class NWProject(): if isSuccess: self.clearProject() - self.theParent.openProject(projPath) - self.theParent.rebuildIndex() + self.mainGui.openProject(projPath) + self.mainGui.rebuildIndex() return isSuccess @@ -928,14 +991,14 @@ class NWProject(): os.mkdir(projPath) logger.debug("Created folder: %s", projPath) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Could not create new project folder." ), nwAlert.ERROR, exception=exc) return False if os.path.isdir(projPath): if os.listdir(self.projPath): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "New project folder is not empty. " "Each project requires a dedicated project folder." ), nwAlert.ERROR) @@ -947,17 +1010,17 @@ class NWProject(): return True def setProjectName(self, projName): - """Set the project name (working title), This is the the title - used for backup files etc. + """Set the project name, This is the the name used for backup + files etc. """ - self.projName = projName.strip() + self.projName = simplified(projName) self.setProjectChanged(True) return True def setBookTitle(self, bookTitle): """Set the book title, that is, the title to include in exports. """ - self.bookTitle = bookTitle.strip() + self.bookTitle = simplified(bookTitle) self.setProjectChanged(True) return True @@ -969,7 +1032,7 @@ class NWProject(): self.bookAuthors = [] for bookAuthor in bookAuthors.splitlines(): - bookAuthor = bookAuthor.strip() + bookAuthor = simplified(bookAuthor) if bookAuthor == "": continue self.bookAuthors.append(bookAuthor) @@ -985,14 +1048,14 @@ class NWProject(): self.doBackup = doBackup if doBackup: if not os.path.isdir(self.mainConf.backupPath): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "You must set a valid backup path in Preferences to use " "the automatic project backup feature." ), nwAlert.WARN) return False if self.projName == "": - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "You must set a valid project name in Project Settings to " "use the automatic project backup feature." ), nwAlert.WARN) @@ -1015,7 +1078,8 @@ class NWProject(): if self.projSpell != theLang: self.projSpell = theLang self.setProjectChanged(True) - return True + return True + return False def setProjectLang(self, theLang): """Set the project-specific language. @@ -1027,22 +1091,14 @@ class NWProject(): self.setProjectChanged(True) return True - def setAutoOutline(self, theMode): - """Enable/disable automatic update of project outline. - """ - if self.autoOutline != theMode: - self.autoOutline = theMode - self.setProjectChanged(True) - return self.autoOutline - def setTreeOrder(self, newOrder): """A list representing the linear/flattened order of project items in the GUI project tree. The user can rearrange the order by drag-and-drop. Forwarded to the NWTree class. """ - if len(self.projTree) != len(newOrder): + if len(self._projTree) != len(newOrder): logger.warning("Sizes of new and old tree order do not match") - self.projTree.setOrder(newOrder) + self._projTree.setOrder(newOrder) self.setProjectChanged(True) return True @@ -1062,34 +1118,38 @@ class NWProject(): self.setProjectChanged(True) return True - def setStatusColours(self, newCols): - """Update the list of novel file status flags. Also iterate - through the project and replace keys that have been renamed. + def setLastNovelViewed(self, tHandle): + """Set last viewed novel root in the novel tree. """ - replaceMap = self.statusItems.setNewEntries(newCols) - for nwItem in self.projTree: - if nwItem.itemClass == nwItemClass.NOVEL: - if nwItem.itemStatus in replaceMap: - nwItem.setStatus(replaceMap[nwItem.itemStatus]) - self.setProjectChanged(True) + if self.lastNovel != tHandle: + self.lastNovel = tHandle + self.setProjectChanged(True) return True - def setImportColours(self, newCols): - """Update the list of note file importance flags. Also iterate - through the project and replace keys that have been renamed. + def setLastOutlineViewed(self, tHandle): + """Set last viewed novel root in the outline view. """ - replaceMap = self.importItems.setNewEntries(newCols) - for nwItem in self.projTree: - if nwItem.itemClass != nwItemClass.NOVEL: - if nwItem.itemStatus in replaceMap: - nwItem.setStatus(replaceMap[nwItem.itemStatus]) - self.setProjectChanged(True) + if self.lastOutline != tHandle: + self.lastOutline = tHandle + self.setProjectChanged(True) return True + def setStatusColours(self, newCols, delCols): + """Update the list of novel file status flags. + """ + return self._setStatusImport(newCols, delCols, self.statusItems) + + def setImportColours(self, newCols, delCols): + """Update the list of note file importance flags. + """ + return self._setStatusImport(newCols, delCols, self.importItems) + def setAutoReplace(self, autoReplace): """Update the auto-replace dictionary. """ - self.autoReplace = autoReplace + self.autoReplace = {} + for key, entry in autoReplace.items(): + self.autoReplace[key] = simplified(entry) self.setProjectChanged(True) return True @@ -1098,7 +1158,9 @@ class NWProject(): """ for valKey, valEntry in titleFormat.items(): if valKey in self.titleFormat: - self.titleFormat[valKey] = checkString(valEntry, self.titleFormat[valKey]) + self.titleFormat[valKey] = checkString( + simplified(valEntry), self.titleFormat[valKey] + ) return True def setProjectChanged(self, bValue): @@ -1106,7 +1168,7 @@ class NWProject(): information to the GUI statusbar. """ self.projChanged = bValue - self.theParent.statusBar.doUpdateProjectStatus(bValue) + self.mainGui.statusBar.doUpdateProjectStatus(bValue) if bValue: # If we've changed the project at all, this should be True self.projAltered = True @@ -1146,16 +1208,16 @@ class NWProject(): capable of handling it. """ sentItems = [] - iterItems = self.projTree.handles() + iterItems = self._projTree.handles() n = 0 nMax = min(len(iterItems), 10000) while n < nMax: tHandle = iterItems[n] - tItem = self.projTree[tHandle] + tItem = self._projTree[tHandle] n += 1 if tItem is None: # Technically a bug since treeOrder is built from the - # same data as projTree + # same data as _projTree continue elif tItem.itemParent is None: # Item is a root, or already been identified as an @@ -1186,7 +1248,7 @@ class NWProject(): def updateWordCounts(self): """Update the total word count values. """ - wcNovel, wcNotes = self.projTree.sumWords() + wcNovel, wcNotes = self._projTree.sumWords() wcTotal = wcNovel + wcNotes if wcTotal != self.currWCount: self.currNovelWC = wcNovel @@ -1202,11 +1264,11 @@ class NWProject(): """ self.statusItems.resetCounts() self.importItems.resetCounts() - for nwItem in self.projTree: - if nwItem.itemClass == nwItemClass.NOVEL: - self.statusItems.countEntry(nwItem.itemStatus) + for nwItem in self._projTree: + if nwItem.isNovelLike(): + self.statusItems.increment(nwItem.itemStatus) else: - self.importItems.countEntry(nwItem.itemStatus) + self.importItems.increment(nwItem.itemImport) return def localLookup(self, theWord): @@ -1214,17 +1276,39 @@ class NWProject(): return it. The variable is cast to a string before lookup. If the word does not exist, it returns itself. """ - return self.langData.get(str(theWord), str(theWord)) + return self._langData.get(str(theWord), str(theWord)) ## # Internal Functions ## + def _setStatusImport(self, new, delete, target): + """Update the list of novel file status or importance flags, and + delete those that have been requested deleted. + """ + if not (new or delete): + return False + + order = [] + for entry in new: + key = entry.get("key", None) + name = entry.get("name", "") + cols = entry.get("cols", (100, 100, 100)) + if name: + order.append(target.write(key, name, cols)) + + for key in delete: + target.remove(key) + + target.reorder(order) + + return True + def _loadProjectLocalisation(self): """Load the language data for the current project language. """ if self.projLang is None: - self.langData = {} + self._langData = {} return False langFile = os.path.join(self.mainConf.nwLangPath, "project_%s.json" % self.projLang) @@ -1233,7 +1317,7 @@ class NWProject(): try: with open(langFile, mode="r", encoding="utf-8") as inFile: - self.langData = json.load(inFile) + self._langData = json.load(inFile) logger.debug("Loaded project language file: %s", os.path.basename(langFile)) except Exception: @@ -1314,7 +1398,7 @@ class NWProject(): os.mkdir(thePath) logger.debug("Created folder: %s", thePath) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Could not create folder." ), nwAlert.ERROR, exception=exc) return False @@ -1368,7 +1452,7 @@ class NWProject(): logger.warning("Skipping file: %s", fileItem) continue - if fHandle in self.projTree: + if fHandle in self._projTree: self.projFiles.append(fHandle) logger.debug("Checking file %s, handle '%s': OK", fileItem, fHandle) else: @@ -1377,7 +1461,7 @@ class NWProject(): # Report status if len(orphanFiles) > 0: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Found {0} orphaned file(s) in project folder." ).format(len(orphanFiles)), nwAlert.WARN) else: @@ -1415,10 +1499,10 @@ class NWProject(): if oLayout is None: oLayout = nwItemLayout.NOTE - if oParent is None or oParent not in self.projTree: - oParent = self.projTree.findRoot(oClass) + if oParent is None or oParent not in self._projTree: + oParent = self._projTree.findRoot(oClass) if oParent is None: - oParent = self.projTree.findRoot(nwItemClass.NOVEL) + oParent = self._projTree.findRoot(nwItemClass.NOVEL) # If the file still has no parent item, skip it if oParent is None: @@ -1430,10 +1514,11 @@ class NWProject(): orphItem.setType(nwItemType.FILE) orphItem.setClass(oClass) orphItem.setLayout(oLayout) - self.projTree.append(oHandle, oParent, orphItem) + self._projTree.append(oHandle, oParent, orphItem) + self._projTree.updateItemData(orphItem.itemHandle) if noWhere: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "One or more orphaned files could not be added back into the project. " "Make sure at least a Novel root folder exists." ), nwAlert.WARN) @@ -1487,82 +1572,37 @@ class NWProject(): # Legacy Data Structure Handlers ## - def _legacyDataFolder(self, theFolder, errList): + def _legacyDataFolder(self, dataDir): """Clean up legacy data folders. """ - theData = os.path.join(self.projPath, theFolder) - if not os.path.isdir(theData): - errList.append(self.tr("Not a folder: {0}").format(theData)) - return errList + dataPath = os.path.join(self.projPath, dataDir) + if not os.path.isdir(dataPath): + return False - logger.info("Old data folder %s found", theFolder) + logger.info("Old data folder found: %s", dataDir) # Move Documents to Content - for dataItem in os.listdir(theData): - theFile = os.path.join(theData, dataItem) - if not os.path.isfile(theFile): - theErr = self._moveUnknownItem(theData, dataItem) - if theErr: - errList.append(theErr) + for dataItem in os.listdir(dataPath): + dataFile = os.path.join(dataPath, dataItem) + if not os.path.isfile(dataFile): continue if len(dataItem) == 21 and dataItem.endswith("_main.nwd"): - tHandle = theFolder[-1]+dataItem[:12] - newPath = os.path.join(self.projContent, tHandle+".nwd") - try: - os.rename(theFile, newPath) - logger.info("Moved file: %s", theFile) - logger.info("New location: %s", newPath) - except Exception: - errList.append(self.tr("Could not move: {0}").format(theFile)) - logger.error("Could not move: %s", theFile) - logException() + tHandle = dataDir[-1] + dataItem[:12] + newPath = os.path.join(self.projContent, f"{tHandle}.nwd") + os.rename(dataFile, newPath) + logger.info("Moved file: %s", dataFile) elif len(dataItem) == 21 and dataItem.endswith("_main.bak"): - try: - os.unlink(theFile) - logger.info("Deleted file: %s", theFile) - except Exception: - errList.append(self.tr("Could not delete: {0}").format(theFile)) - logger.error("Could not delete: %s", theFile) - logException() - - else: - theErr = self._moveUnknownItem(theData, dataItem) - if theErr: - errList.append(theErr) + os.unlink(dataFile) + logger.info("Deleted file: %s", dataFile) # Remove Data Folder - try: - os.rmdir(theData) - logger.info("Deleted folder: %s", theFolder) - except Exception: - errList.append(self.tr("Could not delete: {0}").format(theFolder)) - logger.error("Could not delete: %s", theFolder) - logException() + if not os.listdir(dataPath): + os.rmdir(dataPath) + logger.info("Deleted folder: %s", dataDir) - return errList - - def _moveUnknownItem(self, theDir, theItem): - """Move an item that doesn't belong in the project folder to - a junk folder. - """ - theJunk = os.path.join(self.projPath, "junk") - if not self._checkFolder(theJunk): - return self.tr("Could not make folder: {0}").format(theJunk) - - theSrc = os.path.join(theDir, theItem) - theDst = os.path.join(theJunk, theItem) - - try: - os.rename(theSrc, theDst) - logger.info("Moved to junk: %s", theSrc) - except Exception: - logger.error("Could not move item %s to junk", theSrc) - logException() - return self.tr("Could not move item {0} to {1}.").format(theSrc, theJunk) - - return "" + return True def _deprecatedFiles(self): """Delete files that are no longer used by novelWriter. diff --git a/novelwriter/core/status.py b/novelwriter/core/status.py index 4318344f..4bade5e7 100644 --- a/novelwriter/core/status.py +++ b/novelwriter/core/status.py @@ -4,7 +4,8 @@ novelWriter – Project Item Status Class Data class for the status/importance settings of a project item File History: -Created: 2019-05-19 [0.1.3] +Created: 2019-05-19 [0.1.3] +Rewritten: 2022-04-05 [1.7a0] This file is a part of novelWriter Copyright 2018–2022, Veronica Berglyd Olsen @@ -23,165 +24,269 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +import random import logging +import novelwriter from lxml import etree -from novelwriter.common import checkInt +from PyQt5.QtGui import QIcon, QPixmap, QColor + +from novelwriter.common import checkInt, minmax, simplified logger = logging.getLogger(__name__) class NWStatus(): - def __init__(self): + STATUS = 1 + IMPORT = 2 - self._theLabels = [] - self._theColours = [] - self._theCounts = [] - self._theMap = {} - self._theLength = 0 - self._theIndex = 0 + def __init__(self, type): + + self._type = type + self._store = {} + self._reverse = {} + self._default = None + + self._iconSize = novelwriter.CONFIG.pxInt(32) + pixmap = QPixmap(self._iconSize, self._iconSize) + pixmap.fill(QColor(100, 100, 100)) + self._defaultIcon = QIcon(pixmap) + + if self._type == self.STATUS: + self._prefix = "s" + elif self._type == self.IMPORT: + self._prefix = "i" + else: + raise Exception("This is a bug!") return - def addEntry(self, theLabel, theColours): - """Add a status entry to the status object, but ensure it isn't - a duplicate. + def write(self, key, name, cols, count=None): + """Add or update a status entry. If the key is invalid, a new + key is generated. """ - theLabel = theLabel.strip() - if self.lookupEntry(theLabel) is None: - self._theLabels.append(theLabel) - self._theColours.append(theColours) - self._theCounts.append(0) - self._theMap[theLabel] = self._theLength - self._theLength += 1 + if not self._isKey(key): + key = self._newKey() + if not isinstance(cols, tuple): + cols = (100, 100, 100) + if len(cols) != 3: + cols = (100, 100, 100) + + pixmap = QPixmap(self._iconSize, self._iconSize) + pixmap.fill(QColor(*cols)) + + name = simplified(name) + if count is None: + count = self._store[key]["count"] if key in self._store else 0 + + self._store[key] = { + "name": name, + "icon": QIcon(pixmap), + "cols": cols, + "count": count, + } + self._reverse[name] = key + + if self._default is None: + self._default = key + + return key + + def remove(self, key): + """Remove an entry in the list, but not if the count is larger + than 0. + """ + if key not in self._store: + return False + if self._store[key]["count"] > 0: + return False + + del self._reverse[self._store[key]["name"]] + del self._store[key] + + keys = list(self._store.keys()) + if key == self._default: + if len(keys) > 0: + self._default = keys[0] + else: + self._default = None + return True - def lookupEntry(self, theLabel): - """Look up a status entry in the object lists, and return it if - it exists. + def check(self, value): + """Check the key against the stored status names. """ - if theLabel is None: - return None - theLabel = theLabel.strip() - if theLabel in self._theMap.keys(): - return self._theMap[theLabel] - return None + if self._isKey(value) and value in self._store: + return value + elif value in self._reverse: + return self._reverse[value] + elif self._default is not None: + return self._default + else: + return "" - def checkEntry(self, theStatus): - """Check if a status value is valid, and returns the safe - reference to be used internally. + def name(self, key): + """Return the name associated with a given key. """ - if isinstance(theStatus, str): - theStatus = theStatus.strip() - if self.lookupEntry(theStatus) is not None: - return theStatus - theStatus = checkInt(theStatus, 0, False) - if theStatus >= 0 and theStatus < self._theLength: - return self._theLabels[theStatus] - return self._theLabels[0] + if key in self._store: + return self._store[key]["name"] + elif self._default is not None: + return self._store[self._default]["name"] + else: + return "" - def setNewEntries(self, newList): - """Update the list of entries after they have been modified by - the GUI tool. + def cols(self, key): + """Return the colours associated with a given key. """ - replaceMap = {} + if key in self._store: + return self._store[key]["cols"] + elif self._default is not None: + return self._store[self._default]["cols"] + else: + return (100, 100, 100) - if newList is not None: - self._theLabels = [] - self._theColours = [] - self._theCounts = [] - self._theMap = {} - self._theLength = 0 - self._theIndex = 0 + def count(self, key): + """Return the count associated with a given key. + """ + if key in self._store: + return self._store[key]["count"] + elif self._default is not None: + return self._store[self._default]["count"] + else: + return 0 - for nName, nR, nG, nB, oName in newList: - self.addEntry(nName, (nR, nG, nB)) - if nName != oName and oName is not None: - replaceMap[oName] = nName + def icon(self, key): + """Return the icon associated with a given key. + """ + if key in self._store: + return self._store[key]["icon"] + elif self._default is not None: + return self._store[self._default]["icon"] + else: + return self._defaultIcon - return replaceMap + def reorder(self, order): + """Reorder the items according to list. + """ + if len(order) != len(self._store): + logger.error("Length mismatch between new and old order") + return False + + if order == list(self._store.keys()): + return False + + store = {} + for key in order: + if key in self._store: + store[key] = self._store[key] + else: + logger.error("Unknown key '%s' in order", key) + return False + + self._store = store + + return True def resetCounts(self): """Clear the counts of references to the status entries. """ - self._theCounts = [0]*self._theLength + for key in self._store: + self._store[key]["count"] = 0 return - def countEntry(self, theLabel): - """Increment the counter for a given label. This should be used - together with resetCounts in a loop over project items. + def increment(self, key): + """Increment the counter for a given entry. """ - theIndex = self.lookupEntry(theLabel) - if theIndex is not None: - self._theCounts[theIndex] += 1 + if key in self._store: + self._store[key]["count"] += 1 return def packXML(self, xParent): """Pack the status entries into an XML object for saving to the main project file. """ - for n in range(self._theLength): + for key, data in self._store.items(): xSub = etree.SubElement(xParent, "entry", attrib={ - "blue": str(self._theColours[n][2]), - "green": str(self._theColours[n][1]), - "red": str(self._theColours[n][0]), + "key": key, + "count": str(data["count"]), + "red": str(data["cols"][0]), + "green": str(data["cols"][1]), + "blue": str(data["cols"][2]), }) - xSub.text = self._theLabels[n] + xSub.text = data["name"] + return True def unpackXML(self, xParent): """Unpack an XML tree and set the class values. """ - theLabels = [] - theColours = [] + self._store = {} + self._reverse = {} + self._default = None for xChild in xParent: - theLabels.append(xChild.text) - cR = checkInt(xChild.attrib.get("red", 0), 0, False) - cG = checkInt(xChild.attrib.get("green", 0), 0, False) - cB = checkInt(xChild.attrib.get("blue", 0), 0, False) - theColours.append((cR, cG, cB)) + key = xChild.attrib.get("key", None) + name = xChild.text.strip() + count = max(checkInt(xChild.attrib.get("count", 0), 0), 0) + red = minmax(checkInt(xChild.attrib.get("red", 100), 100), 0, 255) + green = minmax(checkInt(xChild.attrib.get("green", 100), 100), 0, 255) + blue = minmax(checkInt(xChild.attrib.get("blue", 100), 100), 0, 255) + self.write(key, name, (red, green, blue), count) - if len(theLabels) > 0: - self._theLabels = [] - self._theColours = [] - self._theCounts = [] - self._theMap = {} - self._theLength = 0 - self._theIndex = 0 + return True - for n in range(len(theLabels)): - self.addEntry(theLabels[n], theColours[n]) + ## + # Internal Functions + ## + def _newKey(self): + """Generate a new key for a status flag. This method is + recursive, but should only fail if there is an issue with the + random number generator or the user has added a lot of status + flags. The Python recursion limit is given the job to handle + the extreme case and will cause an app crash. + """ + key = f"{self._prefix}{random.getrandbits(24):06x}" + if key in self._store: + key = self._newKey() + return key + + def _isKey(self, value): + """Check if a value is a key or not. + """ + if not isinstance(value, str): + return False + if len(value) != 7: + return False + if value[0] != self._prefix: + return False + for c in value[1:]: + if c not in "0123456789abcdef": + return False return True ## # Iterator Bits ## - def __getitem__(self, n): - """Return an entry by its index. - """ - if n >= 0 and n < self._theLength: - return self._theLabels[n], self._theColours[n], self._theCounts[n] - return None, None, None + def __len__(self): + return len(self._store) + + def __getitem__(self, key): + return self._store[key] def __iter__(self): - """Initialise the iterator. - """ - self._theIndex = 0 - return self + return iter(self._store) - def __next__(self): - """Return the next entry for the iterator. - """ - if self._theIndex < self._theLength: - theLabel, theColour, theCount = self.__getitem__(self._theIndex) - self._theIndex += 1 - return theLabel, theColour, theCount - else: - raise StopIteration + def keys(self): + return self._store.keys() + + def items(self): + return self._store.items() + + def values(self): + return self._store.values() # END Class NWStatus diff --git a/novelwriter/core/tohtml.py b/novelwriter/core/tohtml.py index baa5165d..86a21786 100644 --- a/novelwriter/core/tohtml.py +++ b/novelwriter/core/tohtml.py @@ -451,7 +451,7 @@ class ToHtml(Tokenizer): def _formatKeywords(self, tText): """Apply HTML formatting to keywords. """ - isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText) + isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) if not isValid or not theBits: return "" diff --git a/novelwriter/core/tokenizer.py b/novelwriter/core/tokenizer.py index 6a3a9809..3a3b52f1 100644 --- a/novelwriter/core/tokenizer.py +++ b/novelwriter/core/tokenizer.py @@ -1,7 +1,7 @@ """ novelWriter – Text Tokenizer ============================ -Splits a piece of novelWriter markdown text into its elements +Split novelWriter plain text into its elements File History: Created: 2019-05-05 [0.0.1] @@ -27,6 +27,7 @@ import re import logging import novelwriter +from abc import ABC, abstractmethod from operator import itemgetter from functools import partial @@ -40,7 +41,7 @@ from novelwriter.core.document import NWDoc logger = logging.getLogger(__name__) -class Tokenizer(): +class Tokenizer(ABC): # In-Text Format FMT_B_B = 1 # Begin bold @@ -81,7 +82,6 @@ class Tokenizer(): def __init__(self, theProject): self.theProject = theProject - self.theParent = theProject.theParent self.mainConf = novelwriter.CONFIG # Data Variables @@ -267,10 +267,14 @@ class Tokenizer(): # Class Methods ## + @abstractmethod + def doConvert(self): + raise NotImplementedError + def addRootHeading(self, theHandle): """Add a heading at the start of a new root folder. """ - if not self.theProject.projTree.checkType(theHandle, nwItemType.ROOT): + if not self.theProject.tree.checkType(theHandle, nwItemType.ROOT): return False if self._isFirst: @@ -279,7 +283,7 @@ class Tokenizer(): else: textAlign = self.A_PBB | self.A_CENTRE - theItem = self.theProject.projTree[theHandle] + theItem = self.theProject.tree[theHandle] locNotes = self._localLookup("Notes") theTitle = f"{locNotes}: {theItem.itemName}" self._theTokens = [] @@ -296,7 +300,7 @@ class Tokenizer(): not set, load it from the file. """ self._theHandle = theHandle - self._theItem = self.theProject.projTree[theHandle] + self._theItem = self.theProject.tree[theHandle] if self._theItem is None: return False diff --git a/novelwriter/core/tomd.py b/novelwriter/core/tomd.py index bd468f55..48d23a35 100644 --- a/novelwriter/core/tomd.py +++ b/novelwriter/core/tomd.py @@ -193,7 +193,7 @@ class ToMarkdown(Tokenizer): def _formatKeywords(self, tText, tStyle): """Apply Markdown formatting to keywords. """ - isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText) + isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) if not isValid or not theBits: return "" diff --git a/novelwriter/core/toodt.py b/novelwriter/core/toodt.py index c68f8991..59eaf30f 100644 --- a/novelwriter/core/toodt.py +++ b/novelwriter/core/toodt.py @@ -330,7 +330,7 @@ class ToOdt(Tokenizer): # Meta Data xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "creation-date")) - xMeta.text = datetime.now().strftime(r"%Y-%m-%dT%H:%M:%S") + xMeta.text = datetime.now().isoformat(sep="T", timespec="seconds") xMeta = etree.SubElement(self._xMeta, _mkTag("meta", "generator")) xMeta.text = f"novelWriter/{novelwriter.__version__}" @@ -550,7 +550,7 @@ class ToOdt(Tokenizer): def _formatKeywords(self, tText): """Apply formatting to keywords. """ - isValid, theBits, _ = self.theParent.theIndex.scanThis("@"+tText) + isValid, theBits, _ = self.theProject.index.scanThis("@"+tText) if not isValid or not theBits: return "" diff --git a/novelwriter/core/tree.py b/novelwriter/core/tree.py index 7dbef4c6..6bb24959 100644 --- a/novelwriter/core/tree.py +++ b/novelwriter/core/tree.py @@ -24,16 +24,15 @@ along with this program. If not, see . """ import os +import random import logging -from time import time from lxml import etree -from hashlib import sha256 -from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout +from novelwriter.enum import nwItemClass, nwItemLayout from novelwriter.error import logException from novelwriter.common import checkHandle -from novelwriter.constants import nwConst, nwFiles +from novelwriter.constants import nwFiles from novelwriter.core.item import NWItem logger = logging.getLogger(__name__) @@ -41,21 +40,20 @@ logger = logging.getLogger(__name__) class NWTree(): + MAX_DEPTH = 1000 # Cap of tree traversing for loops + def __init__(self, theProject): self.theProject = theProject self._projTree = {} # Holds all the items of the project self._treeOrder = [] # The order of the tree items on the tree view - self._treeRoots = [] # The root items of the tree + self._treeRoots = {} # The root items of the tree self._trashRoot = None # The handle of the trash root folder self._archRoot = None # The handle of the archive root folder self._theIndex = 0 # The current iterator index self._treeChanged = False # True if tree structure has changed - self._handleSeed = None # Used for generating handles for testing - self._handleCount = 0 # A counter that is added to the handle generator - return ## @@ -67,7 +65,7 @@ class NWTree(): """ self._projTree = {} self._treeOrder = [] - self._treeRoots = [] + self._treeRoots = {} self._trashRoot = None self._archRoot = None self._theIndex = 0 @@ -96,20 +94,19 @@ class NWTree(): nwItem.setHandle(tHandle) nwItem.setParent(pHandle) - if nwItem.itemType == nwItemType.ROOT: + if nwItem.isRootType(): logger.verbose("Item '%s' is a root item", str(tHandle)) - self._treeRoots.append(tHandle) + self._treeRoots[tHandle] = nwItem if nwItem.itemClass == nwItemClass.ARCHIVE: logger.verbose("Item '%s' is the archive folder", str(tHandle)) self._archRoot = tHandle - - if nwItem.itemType == nwItemType.TRASH: - if self._trashRoot is None: - logger.verbose("Item '%s' is the trash folder", str(tHandle)) - self._trashRoot = tHandle - else: - logger.error("Only one trash folder allowed") - return False + elif nwItem.itemClass == nwItemClass.TRASH: + if self._trashRoot is None: + logger.verbose("Item '%s' is the trash folder", str(tHandle)) + self._trashRoot = tHandle + else: + logger.error("Only one trash folder allowed") + return False self._projTree[tHandle] = nwItem self._treeOrder.append(tHandle) @@ -207,9 +204,30 @@ class NWTree(): return novelWords, noteWords ## - # Tree Structure Methods + # Tree Item Methods ## + def updateItemData(self, tHandle): + """Update the root item handle of a given item. Returns True if + a root was found and data updated, otherwise False. + """ + tItem = self.__getitem__(tHandle) + if tItem is None: + return False + + iItem = tItem + for _ in range(self.MAX_DEPTH): + if iItem.itemParent is None: + tItem.setRoot(iItem.itemHandle) + tItem.setClassDefaults(iItem.itemClass) + return True + else: + iItem = self.__getitem__(iItem.itemParent) + if iItem is None: + return False + else: + raise RecursionError("Critical internal error") + def checkType(self, tHandle, itemType): """Return true of item exists and is of the specified item type. """ @@ -218,71 +236,6 @@ class NWTree(): return False return tItem.itemType == itemType - def trashRoot(self): - """Returns the handle of the trash folder, or None if there - isn't one. - """ - if self._trashRoot: - return self._trashRoot - return None - - def isTrashRoot(self, tHandle): - """Check if a handle is the trash folder. - """ - if self._trashRoot is None: - return False - return tHandle == self._trashRoot - - def archiveRoot(self): - """Returns the handle of the archive folder, or None if there - isn't one. - """ - if self._archRoot: - return self._archRoot - return None - - def findRoot(self, theClass): - """Find the root item for a given class. - Note: This returns the first item for class CUSTOM. - """ - for aRoot in self._treeRoots: - tItem = self.__getitem__(aRoot) - if tItem is None: - continue - if theClass == tItem.itemClass: - return tItem.itemHandle - return None - - def checkRootUnique(self, theClass): - """Checks if there already is a root entry of class 'theClass' - in the root of the project tree. CUSTOM class is skipped as it - is not required to be unique. - """ - if theClass == nwItemClass.CUSTOM: - return True - for aRoot in self._treeRoots: - tItem = self.__getitem__(aRoot) - if tItem is None: - continue - if theClass == tItem.itemClass: - return False - return True - - def getRootItem(self, tHandle): - """Iterate upwards in the tree until we find the item with - parent None, the root item. We do this with a for loop with a - maximum depth to make infinite loops impossible. - """ - tItem = self.__getitem__(tHandle) - if tItem is not None: - for i in range(nwConst.MAX_DEPTH + 1): - if tItem.itemParent is None: - return tItem - else: - tHandle = tItem.itemParent - tItem = self.__getitem__(tHandle) - return None - def getItemPath(self, tHandle): """Iterate upwards in the tree until we find the item with parent None, the root item, and return the list of handles. @@ -293,7 +246,7 @@ class NWTree(): tItem = self.__getitem__(tHandle) if tItem is not None: tTree.append(tHandle) - for _ in range(nwConst.MAX_DEPTH + 1): + for _ in range(self.MAX_DEPTH): if tItem.itemParent is None: return tTree else: @@ -303,8 +256,72 @@ class NWTree(): return tTree else: tTree.append(tHandle) + else: + raise RecursionError("Critical internal error") + return tTree + ## + # Tree Root Methods + ## + + def rootClasses(self): + """Return a set of all root classes in use by the project. + """ + rootClasses = set() + for nwItem in self._treeRoots.values(): + rootClasses.add(nwItem.itemClass) + return rootClasses + + def iterRoots(self, itemClass): + """Iterate over all items of a given class. + """ + for tHandle, nwItem in self._treeRoots.items(): + if nwItem.itemClass == itemClass: + yield tHandle, nwItem + return + + def isRoot(self, tHandle): + """Check if a handle is a root item. + """ + return tHandle in self._treeRoots + + def isTrash(self, tHandle): + """Check if an item is in or is the trash folder. + """ + tItem = self.__getitem__(tHandle) + if tItem is None: + return True + if tItem.itemClass == nwItemClass.TRASH: + return True + if self._trashRoot is not None: + if tHandle == self._trashRoot: + return True + elif tItem.itemParent == self._trashRoot: + return True + elif tItem.itemRoot == self._trashRoot: + return True + return False + + def trashRoot(self): + """Returns the handle of the trash folder, or None if there + isn't one. + """ + if self._trashRoot: + return self._trashRoot + return None + + def findRoot(self, theClass): + """Find the first root item for a given class. + """ + for aRoot in self._treeRoots: + tItem = self.__getitem__(aRoot) + if tItem is None: + continue + if theClass == tItem.itemClass: + return tItem.itemHandle + return None + ## # Setters ## @@ -334,21 +351,13 @@ class NWTree(): return - def setSeed(self, theSeed): - """Used for debugging! - Sets a seed for generating handles so that they always come out - in a predictable order. - """ - self._handleSeed = theSeed - return - def setFileItemLayout(self, tHandle, itemLayout): """Set the nwItemLayout for a specific file. """ tItem = self.__getitem__(tHandle) if tItem is None: return False - if tItem.itemType != nwItemType.FILE: + if not tItem.isFileType(): logger.error("Item '%s' is not a file", tHandle) return False if not isinstance(itemLayout, nwItemLayout): @@ -358,30 +367,6 @@ class NWTree(): return True - ## - # Getters - ## - - def countTypes(self): - """Count the number of files, folders and roots in the project. - """ - nRoot = 0 - nFolder = 0 - nFile = 0 - - for tHandle in self._treeOrder: - tItem = self.__getitem__(tHandle) - if tItem is None: - continue - elif tItem.itemType == nwItemType.ROOT: - nRoot += 1 - elif tItem.itemType == nwItemType.FOLDER: - nFolder += 1 - elif tItem.itemType == nwItemType.FILE: - nFile += 1 - - return nRoot, nFolder, nFile - ## # Meta Methods ## @@ -420,7 +405,7 @@ class NWTree(): return if tHandle in self._treeRoots: - self._treeRoots.remove(tHandle) + del self._treeRoots[tHandle] if tHandle == self._trashRoot: self._trashRoot = None if tHandle == self._archRoot: @@ -468,29 +453,16 @@ class NWTree(): self.theProject.setProjectChanged(True) return - def _makeHandle(self, addSeed=""): + def _makeHandle(self): """Generate a unique item handle. In the event that the key - already exists, salt the seed and generate a new handle. - A key collision is very unlikely to be caused by the truncation - of the sha256 hash to 13 characters. Assuming it is near-random, - it will on average happen every 4.5^15 times. However, the clock - seed is likely to occasionally generate a collision if the - handle requests come faster than the clock resolution. + already exists, generate a new one. """ - if self._handleSeed is None: - newSeed = "%s_%d_%s" % (str(time()), self._handleCount, addSeed) - self._handleCount += 1 - else: - # This is used for debugging - newSeed = str(self._handleSeed) - self._handleSeed += 1 - - logger.verbose("Generating handle with seed '%s'", newSeed) - itemHandle = sha256(newSeed.encode()).hexdigest()[0:13] - if itemHandle in self._projTree: + logger.verbose("Generating new handle") + handle = f"{random.getrandbits(52):013x}" + if handle in self._projTree: logger.warning("Duplicate handle encountered! Retrying ...") - itemHandle = self._makeHandle(addSeed+"!") + handle = self._makeHandle() - return itemHandle + return handle # END Class NWTree diff --git a/novelwriter/dialogs/__init__.py b/novelwriter/dialogs/__init__.py index 30bd5d82..03efef5c 100644 --- a/novelwriter/dialogs/__init__.py +++ b/novelwriter/dialogs/__init__.py @@ -22,7 +22,7 @@ along with this program. If not, see . from novelwriter.dialogs.about import GuiAbout from novelwriter.dialogs.docmerge import GuiDocMerge from novelwriter.dialogs.docsplit import GuiDocSplit -from novelwriter.dialogs.itemeditor import GuiItemEditor +from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.dialogs.preferences import GuiPreferences from novelwriter.dialogs.projdetails import GuiProjectDetails from novelwriter.dialogs.projload import GuiProjectLoad @@ -35,7 +35,7 @@ __all__ = [ "GuiAbout", "GuiDocMerge", "GuiDocSplit", - "GuiItemEditor", + "GuiEditLabel", "GuiPreferences", "GuiProjectDetails", "GuiProjectLoad", diff --git a/novelwriter/dialogs/about.py b/novelwriter/dialogs/about.py index c8b9c898..9cf43daf 100644 --- a/novelwriter/dialogs/about.py +++ b/novelwriter/dialogs/about.py @@ -43,15 +43,15 @@ logger = logging.getLogger(__name__) class GuiAbout(QDialog): - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiAbout ...") self.setObjectName("GuiAbout") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme self.outerBox = QVBoxLayout() self.innerBox = QHBoxLayout() @@ -63,7 +63,7 @@ class GuiAbout(QDialog): nPx = self.mainConf.pxInt(96) self.nwIcon = QLabel() - self.nwIcon.setPixmap(self.theParent.theTheme.getPixmap("novelwriter", (nPx, nPx))) + self.nwIcon.setPixmap(self.mainGui.mainTheme.getPixmap("novelwriter", (nPx, nPx))) self.lblName = QLabel("novelWriter") self.lblVers = QLabel(f"v{novelwriter.__version__}") self.lblDate = QLabel(datetime.strptime(novelwriter.__date__, "%Y-%m-%d").strftime("%x")) @@ -182,45 +182,46 @@ class GuiAbout(QDialog): self.tr("Translations"), self._wrapTable([ ("English", "Veronica Berglyd Olsen"), + ("Español Latinoamericano", "Tommy Marplatt"), ("Français", "Jan Lüdke (jyhelle)"), + ("Nederlands", "Martijn van der Kleijn"), ("Norsk Bokmål", "Veronica Berglyd Olsen"), ("Português", "Bruno Meneguello"), ("简体中文", "Qianzhi Long"), - ("Español Latinoamericano", "Tommy Marplatt"), ]) ) - theTheme = self.theParent.theTheme - theIcons = self.theParent.theTheme.theIcons - if theTheme.themeName and theTheme.themeAuthor != "N/A": - licURL = f"{theTheme.themeLicense}" + mainTheme = self.mainGui.mainTheme + iconCache = self.mainGui.mainTheme.iconCache + if mainTheme.themeName and mainTheme.themeAuthor != "N/A": + licURL = f"{mainTheme.themeLicense}" aboutMsg += "

{0}

{1}

".format( - self.tr("Theme: {0}").format(theTheme.themeName), + self.tr("Theme: {0}").format(mainTheme.themeName), self._wrapTable([ - (self.tr("Author"), theTheme.themeAuthor), - (self.tr("Credit"), theTheme.themeCredit), + (self.tr("Author"), mainTheme.themeAuthor), + (self.tr("Credit"), mainTheme.themeCredit), (self.tr("Licence"), licURL), ]) ) - if theIcons.themeName: - licURL = f"{theIcons.themeLicense}" + if iconCache.themeName: + licURL = f"{iconCache.themeLicense}" aboutMsg += "

{0}

{1}

".format( - self.tr("Icons: {0}").format(theIcons.themeName), + self.tr("Icons: {0}").format(iconCache.themeName), self._wrapTable([ - (self.tr("Author"), theIcons.themeAuthor), - (self.tr("Credit"), theIcons.themeCredit), + (self.tr("Author"), iconCache.themeAuthor), + (self.tr("Credit"), iconCache.themeCredit), (self.tr("Licence"), licURL), ]) ) - if theTheme.syntaxName: - licURL = f"{theTheme.syntaxLicense}" + if mainTheme.syntaxName: + licURL = f"{mainTheme.syntaxLicense}" aboutMsg += "

{0}

{1}

".format( - self.tr("Syntax: {0}").format(theTheme.syntaxName), + self.tr("Syntax: {0}").format(mainTheme.syntaxName), self._wrapTable([ - (self.tr("Author"), theTheme.syntaxAuthor), - (self.tr("Credit"), theTheme.syntaxCredit), + (self.tr("Author"), mainTheme.syntaxAuthor), + (self.tr("Credit"), mainTheme.syntaxCredit), (self.tr("Licence"), licURL), ]) ) @@ -278,12 +279,12 @@ class GuiAbout(QDialog): " padding-right: 0.8em;" "}}\n" ).format( - hColR=self.theParent.theTheme.colHead[0], - hColG=self.theParent.theTheme.colHead[1], - hColB=self.theParent.theTheme.colHead[2], - kColR=self.theTheme.colKey[0], - kColG=self.theTheme.colKey[1], - kColB=self.theTheme.colKey[2], + hColR=self.mainGui.mainTheme.colHead[0], + hColG=self.mainGui.mainTheme.colHead[1], + hColB=self.mainGui.mainTheme.colHead[2], + kColR=self.mainTheme.colKey[0], + kColG=self.mainTheme.colKey[1], + kColB=self.mainTheme.colKey[2], ) self.pageAbout.document().setDefaultStyleSheet(styleSheet) self.pageNotes.document().setDefaultStyleSheet(styleSheet) diff --git a/novelwriter/dialogs/docmerge.py b/novelwriter/dialogs/docmerge.py index f9ee01af..22a6eb6b 100644 --- a/novelwriter/dialogs/docmerge.py +++ b/novelwriter/dialogs/docmerge.py @@ -41,15 +41,15 @@ logger = logging.getLogger(__name__) class GuiDocMerge(QDialog): - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiDocMerge ...") self.setObjectName("GuiDocMerge") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject + self.mainGui = mainGui + self.theProject = mainGui.theProject self.sourceItem = None self.outerBox = QVBoxLayout() @@ -57,7 +57,7 @@ class GuiDocMerge(QDialog): self.headLabel = QLabel("{0}".format(self.tr("Documents to Merge"))) self.helpLabel = QHelpLabel( - self.tr("Drag and drop items to change the order."), self.theParent.theTheme.helpText + self.tr("Drag and drop items to change the order."), self.mainGui.mainTheme.helpText ) self.listBox = QListWidget() @@ -102,7 +102,7 @@ class GuiDocMerge(QDialog): finalOrder.append(self.listBox.item(i).data(Qt.UserRole)) if len(finalOrder) == 0: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "No source documents found. Nothing to do." ), nwAlert.ERROR) return False @@ -113,36 +113,37 @@ class GuiDocMerge(QDialog): docText = inDoc.readDocument() docErr = inDoc.getError() if docText is None and docErr: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Failed to open document file."), docErr ], nwAlert.ERROR) if docText: theText += docText.rstrip("\n")+"\n\n" if self.sourceItem is None: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "No source folder selected. Nothing to do." ), nwAlert.ERROR) return False - srcItem = self.theProject.projTree[self.sourceItem] + srcItem = self.theProject.tree[self.sourceItem] if srcItem is None: - self.theParent.makeAlert(self.tr("Internal error."), nwAlert.ERROR) + self.mainGui.makeAlert(self.tr("Internal error."), nwAlert.ERROR) return False - nHandle = self.theProject.newFile(srcItem.itemName, srcItem.itemClass, srcItem.itemParent) - newItem = self.theProject.projTree[nHandle] + nHandle = self.theProject.newFile(srcItem.itemName, srcItem.itemParent) + newItem = self.theProject.tree[nHandle] newItem.setStatus(srcItem.itemStatus) + newItem.setImport(srcItem.itemImport) outDoc = NWDoc(self.theProject, nHandle) if not outDoc.writeDocument(theText): - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Could not save document."), outDoc.getError() ], nwAlert.ERROR) return False - self.theParent.treeView.revealNewTreeItem(nHandle) - self.theParent.openDocument(nHandle, doScroll=True) + self.mainGui.projView.revealNewTreeItem(nHandle) + self.mainGui.openDocument(nHandle, doScroll=True) self._doClose() @@ -164,25 +165,25 @@ class GuiDocMerge(QDialog): are then added to the list view in order. The list itself can be reordered by the user. """ - tHandle = self.theParent.treeView.getSelectedHandle() + tHandle = self.mainGui.projView.getSelectedHandle() self.sourceItem = tHandle if tHandle is None: return False - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] if nwItem is None: return False if nwItem.itemType is not nwItemType.FOLDER: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Element selected in the project tree must be a folder." ), nwAlert.ERROR) return False - for sHandle in self.theParent.treeView.getTreeFromHandle(tHandle): + for sHandle in self.mainGui.projView.getTreeFromHandle(tHandle): newItem = QListWidgetItem() - nwItem = self.theProject.projTree[sHandle] - if nwItem.itemType is not nwItemType.FILE: + nwItem = self.theProject.tree[sHandle] + if not nwItem.isFileType(): continue newItem.setText(nwItem.itemName) newItem.setData(Qt.UserRole, sHandle) diff --git a/novelwriter/dialogs/docsplit.py b/novelwriter/dialogs/docsplit.py index 1138ec58..e4c9b13a 100644 --- a/novelwriter/dialogs/docsplit.py +++ b/novelwriter/dialogs/docsplit.py @@ -33,8 +33,7 @@ from PyQt5.QtWidgets import ( ) from novelwriter.core import NWDoc -from novelwriter.enum import nwAlert, nwItemType, nwItemClass, nwItemLayout -from novelwriter.constants import nwConst +from novelwriter.enum import nwAlert from novelwriter.gui.custom import QHelpLabel logger = logging.getLogger(__name__) @@ -42,16 +41,15 @@ logger = logging.getLogger(__name__) class GuiDocSplit(QDialog): - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiDocSplit ...") self.setObjectName("GuiDocSplit") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.theProject = mainGui.theProject self.sourceItem = None self.sourceText = [] @@ -62,7 +60,7 @@ class GuiDocSplit(QDialog): self.headLabel = QLabel("{0}".format(self.tr("Document Headers"))) self.helpLabel = QHelpLabel( self.tr("Select the maximum level to split into files."), - self.theParent.theTheme.helpText + self.mainGui.mainTheme.helpText ) self.listBox = QListWidget() @@ -76,7 +74,7 @@ class GuiDocSplit(QDialog): self.splitLevel.addItem(self.tr("Split up to Header Level 3 (Scene)"), 3) self.splitLevel.addItem(self.tr("Split up to Header Level 4 (Section)"), 4) spIndex = self.splitLevel.findData( - self.optState.getInt("GuiDocSplit", "spLevel", 3) + self.theProject.options.getInt("GuiDocSplit", "spLevel", 3) ) if spIndex != -1: self.splitLevel.setCurrentIndex(spIndex) @@ -117,14 +115,14 @@ class GuiDocSplit(QDialog): logger.verbose("GuiDocSplit split button clicked") if self.sourceItem is None: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "No source document selected. Nothing to do." ), nwAlert.ERROR) return False - srcItem = self.theProject.projTree[self.sourceItem] + srcItem = self.theProject.tree[self.sourceItem] if srcItem is None: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Could not parse source document." ), nwAlert.ERROR) return False @@ -134,7 +132,7 @@ class GuiDocSplit(QDialog): docErr = inDoc.getError() if theText is None and docErr: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Failed to open document file."), docErr ], nwAlert.ERROR) @@ -155,22 +153,12 @@ class GuiDocSplit(QDialog): nFiles = len(finalOrder) if nFiles == 0: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "No headers found. Nothing to do." ), nwAlert.ERROR) return False - # Check that another folder can be created - parTree = self.theProject.projTree.getItemPath(srcItem.itemParent) - if len(parTree) >= nwConst.MAX_DEPTH - 1: - self.theParent.makeAlert(self.tr( - "Cannot add new folder for the document split. " - "Maximum folder depth has been reached. " - "Please move the file to another level in the project tree." - ), nwAlert.ERROR) - return False - - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("Split Document"), "{0}

{1}".format( self.tr( @@ -186,23 +174,18 @@ class GuiDocSplit(QDialog): return False # Create the folder - fHandle = self.theProject.newFolder( - srcItem.itemName, srcItem.itemClass, srcItem.itemParent - ) - self.theParent.treeView.revealNewTreeItem(fHandle) + fHandle = self.theProject.newFolder(srcItem.itemName, srcItem.itemParent) + self.mainGui.projView.revealNewTreeItem(fHandle) logger.verbose("Creating folder '%s'", fHandle) # Loop through, and create the files for wTitle, iStart, iEnd in finalOrder: - isNovel = srcItem.itemClass == nwItemClass.NOVEL - itemLayout = nwItemLayout.DOCUMENT if isNovel else nwItemLayout.NOTE - wTitle = wTitle.lstrip("#").strip() - nHandle = self.theProject.newFile(wTitle, srcItem.itemClass, fHandle) - newItem = self.theProject.projTree[nHandle] - newItem.setLayout(itemLayout) + nHandle = self.theProject.newFile(wTitle, fHandle) + newItem = self.theProject.tree[nHandle] newItem.setStatus(srcItem.itemStatus) + newItem.setImport(srcItem.itemImport) logger.verbose( "Creating new document '%s' with text from line %d to %d", nHandle, iStart+1, iEnd @@ -213,12 +196,12 @@ class GuiDocSplit(QDialog): outDoc = NWDoc(self.theProject, nHandle) if not outDoc.writeDocument(theText): - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Could not save document."), outDoc.getError() ], nwAlert.ERROR) return False - self.theParent.treeView.revealNewTreeItem(nHandle) + self.mainGui.projView.revealNewTreeItem(nHandle) self._doClose() @@ -227,7 +210,7 @@ class GuiDocSplit(QDialog): def _doClose(self): """Close the dialog window without doing anything. """ - self.optState.saveSettings() + self.theProject.options.saveSettings() self.close() return @@ -243,17 +226,17 @@ class GuiDocSplit(QDialog): """ self.listBox.clear() if self.sourceItem is None: - self.sourceItem = self.theParent.treeView.getSelectedHandle() + self.sourceItem = self.mainGui.projView.getSelectedHandle() if self.sourceItem is None: return False - nwItem = self.theProject.projTree[self.sourceItem] + nwItem = self.theProject.tree[self.sourceItem] if nwItem is None: return False - if nwItem.itemType is not nwItemType.FILE: - self.theParent.makeAlert(self.tr( + if not nwItem.isFileType(): + self.mainGui.makeAlert(self.tr( "Element selected in the project tree must be a file." ), nwAlert.ERROR) return False @@ -265,7 +248,7 @@ class GuiDocSplit(QDialog): return False spLevel = self.splitLevel.currentData() - self.optState.setValue("GuiDocSplit", "spLevel", spLevel) + self.theProject.options.setValue("GuiDocSplit", "spLevel", spLevel) logger.debug( "Scanning document '%s' for headings level <= %d", self.sourceItem, spLevel diff --git a/novelwriter/dialogs/editlabel.py b/novelwriter/dialogs/editlabel.py new file mode 100644 index 00000000..03bf9d08 --- /dev/null +++ b/novelwriter/dialogs/editlabel.py @@ -0,0 +1,84 @@ +""" +novelWriter – Edit Label Dialog +=============================== +A simple dialog for editing a label + +File History: +Created: 2022-06-11 [1.7b1] + +This file is a part of novelWriter +Copyright 2018–2022, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +import logging +import novelwriter + +from PyQt5.QtWidgets import ( + QDialog, QVBoxLayout, QLineEdit, QLabel, QDialogButtonBox, QHBoxLayout +) + +logger = logging.getLogger(__name__) + + +class GuiEditLabel(QDialog): + + def __init__(self, parent, text=""): + QDialog.__init__(self, parent=parent) + + self.setObjectName("GuiEditLabel") + self.setWindowTitle(self.tr("Item Label")) + + mVd = novelwriter.CONFIG.pxInt(220) + mSp = novelwriter.CONFIG.pxInt(12) + + # Item Label + self.labelValue = QLineEdit() + self.labelValue.setMinimumWidth(mVd) + self.labelValue.setMaxLength(200) + self.labelValue.setText(text) + self.labelValue.selectAll() + + # Buttons + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.accepted.connect(self.accept) + self.buttonBox.rejected.connect(self.reject) + + # Assemble + self.innerBox = QHBoxLayout() + self.innerBox.addWidget(QLabel(self.tr("Label")), 0) + self.innerBox.addWidget(self.labelValue, 1) + self.innerBox.setSpacing(mSp) + + self.outerBox = QVBoxLayout() + self.outerBox.setSpacing(mSp) + self.outerBox.addLayout(self.innerBox, 1) + self.outerBox.addWidget(self.buttonBox, 0) + + self.setLayout(self.outerBox) + + return + + @property + def itemLabel(self): + return self.labelValue.text() + + @classmethod + def getLabel(cls, parent, text): + cls = GuiEditLabel(parent, text=text) + cls.exec_() + return cls.itemLabel, cls.result() == QDialog.Accepted + +# END Class GuiEditLabel diff --git a/novelwriter/dialogs/itemeditor.py b/novelwriter/dialogs/itemeditor.py deleted file mode 100644 index 9ab1e4ac..00000000 --- a/novelwriter/dialogs/itemeditor.py +++ /dev/null @@ -1,202 +0,0 @@ -""" -novelWriter – GUI Item Editor -============================= -GUI class for the item editor dialog - -File History: -Created: 2019-04-27 [0.0.1] - -This file is a part of novelWriter -Copyright 2018–2022, Veronica Berglyd Olsen - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - -import logging -import novelwriter - -from PyQt5.QtCore import pyqtSlot -from PyQt5.QtWidgets import ( - QDialog, QVBoxLayout, QGridLayout, QLineEdit, QComboBox, QLabel, - QDialogButtonBox -) - -from novelwriter.enum import nwItemLayout, nwItemType -from novelwriter.constants import trConst, nwLists, nwLabels -from novelwriter.gui.custom import QSwitch - -logger = logging.getLogger(__name__) - - -class GuiItemEditor(QDialog): - - def __init__(self, theParent, tHandle): - QDialog.__init__(self, theParent) - - logger.debug("Initialising GuiItemEditor ...") - self.setObjectName("GuiItemEditor") - - self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - - ## - # Build GUI - ## - - self.theItem = self.theProject.projTree[tHandle] - if self.theItem is None: - self.close() - return - - self.setWindowTitle(self.tr("Item Settings")) - - mVd = self.mainConf.pxInt(220) - mSp = self.mainConf.pxInt(16) - vSp = self.mainConf.pxInt(4) - - # Item Label - self.editName = QLineEdit() - self.editName.setMinimumWidth(mVd) - self.editName.setMaxLength(200) - - # Item Status - self.editStatus = QComboBox() - self.editStatus.setMinimumWidth(mVd) - if self.theItem.itemClass in nwLists.CLS_NOVEL: - for sLabel, _, _ in self.theProject.statusItems: - self.editStatus.addItem( - self.theParent.statusIcons[sLabel], sLabel, sLabel - ) - else: - for sLabel, _, _ in self.theProject.importItems: - self.editStatus.addItem( - self.theParent.importIcons[sLabel], sLabel, sLabel - ) - - # Item Layout - self.editLayout = QComboBox() - self.editLayout.setMinimumWidth(mVd) - validLayouts = [] - if self.theItem.itemType == nwItemType.FILE: - if self.theItem.itemClass in nwLists.CLS_NOVEL: - validLayouts.append(nwItemLayout.DOCUMENT) - validLayouts.append(nwItemLayout.NOTE) - else: - validLayouts.append(nwItemLayout.NO_LAYOUT) - self.editLayout.setEnabled(False) - - for itemLayout in nwItemLayout: - if itemLayout in validLayouts: - self.editLayout.addItem(trConst(nwLabels.LAYOUT_NAME[itemLayout]), itemLayout) - - # Export Switch - self.textExport = QLabel(self.tr("Include when building project")) - self.editExport = QSwitch() - if self.theItem.itemType == nwItemType.FILE: - self.editExport.setEnabled(True) - self.editExport.setChecked(self.theItem.isExported) - else: - self.editExport.setEnabled(False) - self.editExport.setChecked(False) - - # Buttons - self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) - self.buttonBox.accepted.connect(self._doSave) - self.buttonBox.rejected.connect(self._doClose) - - # Set Current Values - self.editName.setText(self.theItem.itemName) - self.editName.selectAll() - - statusIdx = self.editStatus.findData(self.theItem.itemStatus) - if statusIdx != -1: - self.editStatus.setCurrentIndex(statusIdx) - - layoutIdx = self.editLayout.findData(self.theItem.itemLayout) - if layoutIdx != -1: - self.editLayout.setCurrentIndex(layoutIdx) - - ## - # Assemble - ## - - nameLabel = QLabel(self.tr("Label")) - statusLabel = QLabel(self.tr("Status")) - layoutLabel = QLabel(self.tr("Layout")) - - self.mainForm = QGridLayout() - self.mainForm.setVerticalSpacing(vSp) - self.mainForm.setHorizontalSpacing(mSp) - self.mainForm.addWidget(nameLabel, 0, 0, 1, 1) - self.mainForm.addWidget(self.editName, 0, 1, 1, 2) - self.mainForm.addWidget(statusLabel, 1, 0, 1, 1) - self.mainForm.addWidget(self.editStatus, 1, 1, 1, 2) - self.mainForm.addWidget(layoutLabel, 2, 0, 1, 1) - self.mainForm.addWidget(self.editLayout, 2, 1, 1, 2) - self.mainForm.addWidget(self.textExport, 3, 0, 1, 2) - self.mainForm.addWidget(self.editExport, 3, 2, 1, 1) - self.mainForm.setColumnStretch(0, 0) - self.mainForm.setColumnStretch(1, 1) - self.mainForm.setColumnStretch(2, 0) - - self.outerBox = QVBoxLayout() - self.outerBox.setSpacing(mSp) - self.outerBox.addLayout(self.mainForm) - self.outerBox.addStretch(1) - self.outerBox.addWidget(self.buttonBox) - self.setLayout(self.outerBox) - - self.rejected.connect(self._doClose) - - logger.debug("GuiItemEditor initialisation complete") - - return - - ## - # Slots - ## - - @pyqtSlot() - def _doSave(self): - """Save the setting to the item. - """ - logger.verbose("ItemEditor save button clicked") - - itemName = self.editName.text() - itemStatus = self.editStatus.currentData() - itemLayout = self.editLayout.currentData() - isExported = self.editExport.isChecked() - - self.theItem.setName(itemName) - self.theItem.setStatus(itemStatus) - self.theItem.setLayout(itemLayout) - self.theItem.setExported(isExported) - - self.theProject.setProjectChanged(True) - - self.accept() - self.close() - - return - - @pyqtSlot() - def _doClose(self): - """Close the dialog without saving the settings. - """ - logger.verbose("ItemEditor cancel button clicked") - self.close() - return - -# END Class GuiItemEditor diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index 81bef52a..f807fde1 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -43,25 +43,25 @@ logger = logging.getLogger(__name__) class GuiPreferences(PagedDialog): - def __init__(self, theParent): - PagedDialog.__init__(self, theParent) + def __init__(self, mainGui): + PagedDialog.__init__(self, mainGui) logger.debug("Initialising GuiPreferences ...") self.setObjectName("GuiPreferences") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject + self.mainGui = mainGui + self.theProject = mainGui.theProject self.setWindowTitle(self.tr("Preferences")) - self.tabGeneral = GuiPreferencesGeneral(self.theParent) - self.tabProjects = GuiPreferencesProjects(self.theParent) - self.tabDocs = GuiPreferencesDocuments(self.theParent) - self.tabEditor = GuiPreferencesEditor(self.theParent) - self.tabSyntax = GuiPreferencesSyntax(self.theParent) - self.tabAuto = GuiPreferencesAutomation(self.theParent) - self.tabQuote = GuiPreferencesQuotes(self.theParent) + self.tabGeneral = GuiPreferencesGeneral(self.mainGui) + self.tabProjects = GuiPreferencesProjects(self.mainGui) + self.tabDocs = GuiPreferencesDocuments(self.mainGui) + self.tabEditor = GuiPreferencesEditor(self.mainGui) + self.tabSyntax = GuiPreferencesSyntax(self.mainGui) + self.tabAuto = GuiPreferencesAutomation(self.mainGui) + self.tabQuote = GuiPreferencesQuotes(self.mainGui) self.addTab(self.tabGeneral, self.tr("General")) self.addTab(self.tabProjects, self.tr("Projects")) @@ -102,12 +102,12 @@ class GuiPreferences(PagedDialog): self.tabQuote.saveValues() if needsRestart: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Some changes will not be applied until novelWriter has been restarted." ), nwAlert.INFO) if refreshTree: - self.theParent.treeView.buildTree() + self.mainGui.projView.populateTree() self._saveWindowSize() self.accept() @@ -138,16 +138,16 @@ class GuiPreferences(PagedDialog): class GuiPreferencesGeneral(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) # Look and Feel @@ -174,7 +174,7 @@ class GuiPreferencesGeneral(QWidget): # Select Theme self.guiTheme = QComboBox() self.guiTheme.setMinimumWidth(minWidth) - self.theThemes = self.theTheme.listThemes() + self.theThemes = self.mainTheme.listThemes() for themeDir, themeName in self.theThemes: self.guiTheme.addItem(themeName, themeDir) themeIdx = self.guiTheme.findData(self.mainConf.guiTheme) @@ -190,8 +190,8 @@ class GuiPreferencesGeneral(QWidget): # Select Icon Theme self.guiIcons = QComboBox() self.guiIcons.setMinimumWidth(minWidth) - self.theIcons = self.theTheme.theIcons.listThemes() - for iconDir, iconName in self.theIcons: + self.iconCache = self.mainTheme.iconCache.listThemes() + for iconDir, iconName in self.iconCache: self.guiIcons.addItem(iconName, iconDir) iconIdx = self.guiIcons.findData(self.mainConf.guiIcons) if iconIdx != -1: @@ -203,13 +203,29 @@ class GuiPreferencesGeneral(QWidget): self.tr("Requires restart.") ) + # Editor Theme + self.guiSyntax = QComboBox() + self.guiSyntax.setMinimumWidth(self.mainConf.pxInt(200)) + self.theSyntaxes = self.mainTheme.listSyntax() + for syntaxFile, syntaxName in self.theSyntaxes: + self.guiSyntax.addItem(syntaxName, syntaxFile) + syntaxIdx = self.guiSyntax.findData(self.mainConf.guiSyntax) + if syntaxIdx != -1: + self.guiSyntax.setCurrentIndex(syntaxIdx) + + self.mainForm.addRow( + self.tr("Editor theme"), + self.guiSyntax, + self.tr("Colour theme for the editor and viewer.") + ) + # Font Family self.guiFont = QLineEdit() self.guiFont.setReadOnly(True) self.guiFont.setFixedWidth(self.mainConf.pxInt(162)) self.guiFont.setText(self.mainConf.guiFont) self.fontButton = QPushButton("...") - self.fontButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) + self.fontButton.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.fontButton.clicked.connect(self._selectFont) self.mainForm.addRow( self.tr("Font family"), @@ -275,6 +291,7 @@ class GuiPreferencesGeneral(QWidget): guiLang = self.guiLang.currentData() guiTheme = self.guiTheme.currentData() guiIcons = self.guiIcons.currentData() + guiSyntax = self.guiSyntax.currentData() guiFont = self.guiFont.text() guiFontSize = self.guiFontSize.value() emphLabels = self.emphLabels.isChecked() @@ -294,6 +311,7 @@ class GuiPreferencesGeneral(QWidget): self.mainConf.guiLang = guiLang self.mainConf.guiTheme = guiTheme self.mainConf.guiIcons = guiIcons + self.mainConf.guiSyntax = guiSyntax self.mainConf.guiFont = guiFont self.mainConf.guiFontSize = guiFontSize self.mainConf.emphLabels = emphLabels @@ -326,16 +344,16 @@ class GuiPreferencesGeneral(QWidget): class GuiPreferencesProjects(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) # Automatic Save @@ -487,16 +505,16 @@ class GuiPreferencesProjects(QWidget): class GuiPreferencesDocuments(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) # Text Style @@ -509,7 +527,7 @@ class GuiPreferencesDocuments(QWidget): self.textFont.setFixedWidth(self.mainConf.pxInt(162)) self.textFont.setText(self.mainConf.textFont) self.fontButton = QPushButton("...") - self.fontButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) + self.fontButton.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.fontButton.clicked.connect(self._selectFont) self.mainForm.addRow( self.tr("Font family"), @@ -648,16 +666,16 @@ class GuiPreferencesDocuments(QWidget): class GuiPreferencesEditor(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) mW = self.mainConf.pxInt(250) @@ -670,7 +688,7 @@ class GuiPreferencesEditor(QWidget): self.spellLanguage = QComboBox(self) self.spellLanguage.setMaximumWidth(mW) - langAvail = self.theParent.docEditor.spEnchant.listDictionaries() + langAvail = self.mainGui.docEditor.spEnchant.listDictionaries() if self.mainConf.hasEnchant: if langAvail: for spTag, spProv in langAvail: @@ -822,37 +840,18 @@ class GuiPreferencesEditor(QWidget): class GuiPreferencesSyntax(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) - # Highlighting Theme - # ================== - self.mainForm.addGroupLabel(self.tr("Highlighting Theme")) - - self.guiSyntax = QComboBox() - self.guiSyntax.setMinimumWidth(self.mainConf.pxInt(200)) - self.theSyntaxes = self.theTheme.listSyntax() - for syntaxFile, syntaxName in self.theSyntaxes: - self.guiSyntax.addItem(syntaxName, syntaxFile) - syntaxIdx = self.guiSyntax.findData(self.mainConf.guiSyntax) - if syntaxIdx != -1: - self.guiSyntax.setCurrentIndex(syntaxIdx) - - self.mainForm.addRow( - self.tr("Highlighting theme"), - self.guiSyntax, - self.tr("Colour theme for the editor and viewer.") - ) - # Quotes & Dialogue # ================= self.mainForm.addGroupLabel(self.tr("Quotes & Dialogue")) @@ -902,7 +901,7 @@ class GuiPreferencesSyntax(QWidget): self.showMultiSpaces = QSwitch() self.showMultiSpaces.setChecked(self.mainConf.showMultiSpaces) self.mainForm.addRow( - self.tr("Highlight multiple spaces"), + self.tr("Highlight multiple or trailing spaces"), self.showMultiSpaces, self.tr("Applies to the document editor only.") ) @@ -912,9 +911,6 @@ class GuiPreferencesSyntax(QWidget): def saveValues(self): """Save the values set for this tab. """ - # Highlighting Theme - self.mainConf.guiSyntax = self.guiSyntax.currentData() - # Quotes & Dialogue self.mainConf.highlightQuotes = self.highlightQuotes.isChecked() self.mainConf.allowOpenSQuote = self.allowOpenSQuote.isChecked() @@ -947,16 +943,16 @@ class GuiPreferencesSyntax(QWidget): class GuiPreferencesAutomation(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) # Automatic Features @@ -1104,16 +1100,16 @@ class GuiPreferencesAutomation(QWidget): class GuiPreferencesQuotes(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainTheme.helpText) self.setLayout(self.mainForm) # Quotation Style @@ -1121,7 +1117,7 @@ class GuiPreferencesQuotes(QWidget): self.mainForm.addGroupLabel(self.tr("Quotation Style")) qWidth = self.mainConf.pxInt(40) - bWidth = int(2.5*self.theTheme.getTextWidth("...")) + bWidth = int(2.5*self.mainTheme.getTextWidth("...")) self.quoteSym = {} # Single Quote Style diff --git a/novelwriter/dialogs/projdetails.py b/novelwriter/dialogs/projdetails.py index 54b6c995..e83fc0a4 100644 --- a/novelwriter/dialogs/projdetails.py +++ b/novelwriter/dialogs/projdetails.py @@ -43,31 +43,31 @@ logger = logging.getLogger(__name__) class GuiProjectDetails(PagedDialog): - def __init__(self, theParent): - PagedDialog.__init__(self, theParent) + def __init__(self, mainGui): + PagedDialog.__init__(self, mainGui) logger.debug("Initialising GuiProjectDetails ...") self.setObjectName("GuiProjectDetails") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.theProject = mainGui.theProject self.setWindowTitle(self.tr("Project Details")) wW = self.mainConf.pxInt(600) wH = self.mainConf.pxInt(400) + pOptions = self.theProject.options self.setMinimumWidth(wW) self.setMinimumHeight(wH) self.resize( - self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "winWidth", wW)), - self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "winHeight", wH)) + self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "winWidth", wW)), + self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "winHeight", wH)) ) - self.tabMain = GuiProjectDetailsMain(self.theParent, self.theProject) - self.tabContents = GuiProjectDetailsContents(self.theParent, self.theProject) + self.tabMain = GuiProjectDetailsMain(self.mainGui, self.theProject) + self.tabContents = GuiProjectDetailsContents(self.mainGui, self.theProject) self.addTab(self.tabMain, self.tr("Overview")) self.addTab(self.tabContents, self.tr("Contents")) @@ -120,16 +120,17 @@ class GuiProjectDetails(PagedDialog): countFrom = self.tabContents.poValue.value() clearDouble = self.tabContents.dblValue.isChecked() - self.optState.setValue("GuiProjectDetails", "winWidth", winWidth) - self.optState.setValue("GuiProjectDetails", "winHeight", winHeight) - self.optState.setValue("GuiProjectDetails", "widthCol0", widthCol0) - self.optState.setValue("GuiProjectDetails", "widthCol1", widthCol1) - self.optState.setValue("GuiProjectDetails", "widthCol2", widthCol2) - self.optState.setValue("GuiProjectDetails", "widthCol3", widthCol3) - self.optState.setValue("GuiProjectDetails", "widthCol4", widthCol4) - self.optState.setValue("GuiProjectDetails", "wordsPerPage", wordsPerPage) - self.optState.setValue("GuiProjectDetails", "countFrom", countFrom) - self.optState.setValue("GuiProjectDetails", "clearDouble", clearDouble) + pOptions = self.theProject.options + pOptions.setValue("GuiProjectDetails", "winWidth", winWidth) + pOptions.setValue("GuiProjectDetails", "winHeight", winHeight) + pOptions.setValue("GuiProjectDetails", "widthCol0", widthCol0) + pOptions.setValue("GuiProjectDetails", "widthCol1", widthCol1) + pOptions.setValue("GuiProjectDetails", "widthCol2", widthCol2) + pOptions.setValue("GuiProjectDetails", "widthCol3", widthCol3) + pOptions.setValue("GuiProjectDetails", "widthCol4", widthCol4) + pOptions.setValue("GuiProjectDetails", "wordsPerPage", wordsPerPage) + pOptions.setValue("GuiProjectDetails", "countFrom", countFrom) + pOptions.setValue("GuiProjectDetails", "clearDouble", clearDouble) return @@ -138,17 +139,16 @@ class GuiProjectDetails(PagedDialog): class GuiProjectDetailsMain(QWidget): - def __init__(self, theParent, theProject): - QWidget.__init__(self, theParent) + def __init__(self, mainGui, theProject): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent self.theProject = theProject - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme - fPx = self.theTheme.fontPixelSize - fPt = self.theTheme.fontPointSize + fPx = self.mainTheme.fontPixelSize + fPt = self.mainTheme.fontPointSize vPx = self.mainConf.pxInt(4) hPx = self.mainConf.pxInt(12) @@ -245,8 +245,9 @@ class GuiProjectDetailsMain(QWidget): def updateValues(self): """Set all the values. """ - hCounts = self.theIndex.getNovelTitleCounts() - nwCount = self.theIndex.getNovelWordCount() + pIndex = self.theProject.index + hCounts = pIndex.getNovelTitleCounts() + nwCount = pIndex.getNovelWordCount() edTime = self.theProject.getCurrentEditTime() self.wordCountVal.setText(f"{nwCount:n}") @@ -270,22 +271,21 @@ class GuiProjectDetailsContents(QWidget): C_PAGE = 3 C_PROG = 4 - def __init__(self, theParent, theProject): - QWidget.__init__(self, theParent) + def __init__(self, mainGui, theProject): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent self.theProject = theProject - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex - self.optState = theProject.optState + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme # Internal self._theToC = [] - iPx = self.theTheme.baseIconSize + iPx = self.mainTheme.baseIconSize hPx = self.mainConf.pxInt(12) vPx = self.mainConf.pxInt(4) + pOptions = self.theProject.options # Contents Tree # ============= @@ -314,11 +314,11 @@ class GuiProjectDetailsContents(QWidget): treeHeader.setStretchLastSection(True) treeHeader.setMinimumSectionSize(hPx) - wCol0 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol0", 200)) - wCol1 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol1", 60)) - wCol2 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol2", 60)) - wCol3 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol3", 60)) - wCol4 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol4", 90)) + wCol0 = self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "widthCol0", 200)) + wCol1 = self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "widthCol1", 60)) + wCol2 = self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "widthCol2", 60)) + wCol3 = self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "widthCol3", 60)) + wCol4 = self.mainConf.pxInt(pOptions.getInt("GuiProjectDetails", "widthCol4", 90)) self.tocTree.setColumnWidth(0, wCol0) self.tocTree.setColumnWidth(1, wCol1) @@ -330,9 +330,9 @@ class GuiProjectDetailsContents(QWidget): # Options # ======= - wordsPerPage = self.optState.getInt("GuiProjectDetails", "wordsPerPage", 350) - countFrom = self.optState.getInt("GuiProjectDetails", "countFrom", 1) - clearDouble = self.optState.getInt("GuiProjectDetails", "clearDouble", True) + wordsPerPage = pOptions.getInt("GuiProjectDetails", "wordsPerPage", 350) + countFrom = pOptions.getInt("GuiProjectDetails", "countFrom", 1) + clearDouble = pOptions.getInt("GuiProjectDetails", "clearDouble", True) wordsHelp = ( self.tr("Typical word count for a 5 by 8 inch book page with 11 pt font is 350.") @@ -424,7 +424,7 @@ class GuiProjectDetailsContents(QWidget): """Extract the data for the tree. """ self._theToC = [] - self._theToC = self.theIndex.getTableOfContents(2) + self._theToC = self.theProject.index.getTableOfContents(2) self._theToC.append(("", 0, self.tr("END"), 0)) return @@ -469,7 +469,7 @@ class GuiProjectDetailsContents(QWidget): if tTitle.strip() == "": tTitle = self.tr("Untitled") - newItem.setIcon(self.C_TITLE, self.theTheme.getIcon("doc_h%d" % tLevel)) + newItem.setIcon(self.C_TITLE, self.mainTheme.getIcon("doc_h%d" % tLevel)) newItem.setText(self.C_TITLE, tTitle) newItem.setText(self.C_WORDS, f"{wCount:n}") newItem.setText(self.C_PAGES, f"{pCount:n}") diff --git a/novelwriter/dialogs/projload.py b/novelwriter/dialogs/projload.py index bbae4920..c7229f44 100644 --- a/novelwriter/dialogs/projload.py +++ b/novelwriter/dialogs/projload.py @@ -53,21 +53,21 @@ class GuiProjectLoad(QDialog): C_COUNT = 1 C_TIME = 2 - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiProjectLoad ...") self.setObjectName("GuiProjectLoad") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme self.openState = self.NONE_STATE self.openPath = None sPx = self.mainConf.pxInt(16) nPx = self.mainConf.pxInt(96) - iPx = self.theTheme.baseIconSize + iPx = self.mainTheme.baseIconSize self.outerBox = QVBoxLayout() self.innerBox = QHBoxLayout() @@ -80,7 +80,7 @@ class GuiProjectLoad(QDialog): self.setModal(True) self.nwIcon = QLabel() - self.nwIcon.setPixmap(self.theParent.theTheme.getPixmap("novelwriter", (nPx, nPx))) + self.nwIcon.setPixmap(self.mainGui.mainTheme.getPixmap("novelwriter", (nPx, nPx))) self.innerBox.addWidget(self.nwIcon, 0, Qt.AlignTop) self.projectForm = QGridLayout() @@ -110,7 +110,7 @@ class GuiProjectLoad(QDialog): self.selPath.setReadOnly(True) self.browseButton = QPushButton("...") - self.browseButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) + self.browseButton.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.browseButton.clicked.connect(self._doBrowse) self.projectForm.addWidget(self.lblRecent, 0, 0, 1, 3) @@ -225,7 +225,7 @@ class GuiProjectLoad(QDialog): selList = self.listBox.selectedItems() if selList: projName = selList[0].text(self.C_NAME) - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("Remove Entry"), self.tr( "Remove '{0}' from the recent projects list? " @@ -280,7 +280,7 @@ class GuiProjectLoad(QDialog): sortList = sorted(dataList, key=lambda x: x[1], reverse=True) for theTitle, theTime, theWords, projPath in sortList: newItem = QTreeWidgetItem([""]*4) - newItem.setIcon(self.C_NAME, self.theParent.theTheme.getIcon("proj_nwx")) + newItem.setIcon(self.C_NAME, self.mainGui.mainTheme.getIcon("proj_nwx")) newItem.setText(self.C_NAME, theTitle) newItem.setData(self.C_NAME, Qt.UserRole, projPath) newItem.setText(self.C_COUNT, formatInt(theWords)) @@ -288,7 +288,7 @@ class GuiProjectLoad(QDialog): newItem.setTextAlignment(self.C_NAME, Qt.AlignLeft | Qt.AlignVCenter) newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight | Qt.AlignVCenter) newItem.setTextAlignment(self.C_TIME, Qt.AlignRight | Qt.AlignVCenter) - newItem.setFont(self.C_TIME, self.theTheme.guiFontFixed) + newItem.setFont(self.C_TIME, self.mainTheme.guiFontFixed) self.listBox.addTopLevelItem(newItem) if self.listBox.topLevelItemCount() > 0: diff --git a/novelwriter/dialogs/projsettings.py b/novelwriter/dialogs/projsettings.py index 3989f7eb..11a640b1 100644 --- a/novelwriter/dialogs/projsettings.py +++ b/novelwriter/dialogs/projsettings.py @@ -35,6 +35,7 @@ from PyQt5.QtWidgets import ( ) from novelwriter.enum import nwAlert +from novelwriter.common import simplified from novelwriter.gui.custom import QSwitch, PagedDialog, QConfigLayout logger = logging.getLogger(__name__) @@ -42,34 +43,34 @@ logger = logging.getLogger(__name__) class GuiProjectSettings(PagedDialog): - def __init__(self, theParent): - PagedDialog.__init__(self, theParent) + def __init__(self, mainGui): + PagedDialog.__init__(self, mainGui) logger.debug("Initialising GuiProjectSettings ...") self.setObjectName("GuiProjectSettings") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.theProject = mainGui.theProject self.theProject.countStatus() self.setWindowTitle(self.tr("Project Settings")) wW = self.mainConf.pxInt(570) wH = self.mainConf.pxInt(375) + pOptions = self.theProject.options self.setMinimumWidth(wW) self.setMinimumHeight(wH) self.resize( - self.mainConf.pxInt(self.optState.getInt("GuiProjectSettings", "winWidth", wW)), - self.mainConf.pxInt(self.optState.getInt("GuiProjectSettings", "winHeight", wH)) + self.mainConf.pxInt(pOptions.getInt("GuiProjectSettings", "winWidth", wW)), + self.mainConf.pxInt(pOptions.getInt("GuiProjectSettings", "winHeight", wH)) ) - self.tabMain = GuiProjectEditMain(self.theParent, self.theProject) - self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject, True) - self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject, False) - self.tabReplace = GuiProjectEditReplace(self.theParent, self.theProject) + self.tabMain = GuiProjectEditMain(self.mainGui, self.theProject) + self.tabStatus = GuiProjectEditStatus(self.mainGui, self.theProject, True) + self.tabImport = GuiProjectEditStatus(self.mainGui, self.theProject, False) + self.tabReplace = GuiProjectEditReplace(self.mainGui, self.theProject) self.addTab(self.tabMain, self.tr("Settings")) self.addTab(self.tabStatus, self.tr("Status")) @@ -81,6 +82,9 @@ class GuiProjectSettings(PagedDialog): self.buttonBox.rejected.connect(self._doClose) self.addControls(self.buttonBox) + # Flags + self.spellChanged = False + logger.debug("GuiProjectSettings initialisation complete") return @@ -103,19 +107,21 @@ class GuiProjectSettings(PagedDialog): self.theProject.setProjectName(projName) self.theProject.setBookTitle(bookTitle) self.theProject.setBookAuthors(bookAuthors) - self.theProject.setSpellLang(spellLang) self.theProject.setProjBackup(doBackup) + # Remember this as updating spell dictionary can be expensive + self.spellChanged = self.theProject.setSpellLang(spellLang) + if self.tabStatus.colChanged: - statusCol = self.tabStatus.getNewList() - self.theProject.setStatusColours(statusCol) + newList, delList = self.tabStatus.getNewList() + self.theProject.setStatusColours(newList, delList) if self.tabImport.colChanged: - importCol = self.tabImport.getNewList() - self.theProject.setImportColours(importCol) + newList, delList = self.tabImport.getNewList() + self.theProject.setImportColours(newList, delList) if self.tabStatus.colChanged or self.tabImport.colChanged: - self.theParent.rebuildTrees() + self.mainGui.rebuildTrees() if self.tabReplace.arChanged: newList = self.tabReplace.getNewList() @@ -146,11 +152,12 @@ class GuiProjectSettings(PagedDialog): statusColW = self.mainConf.rpxInt(self.tabStatus.listBox.columnWidth(0)) importColW = self.mainConf.rpxInt(self.tabImport.listBox.columnWidth(0)) - self.optState.setValue("GuiProjectSettings", "winWidth", winWidth) - self.optState.setValue("GuiProjectSettings", "winHeight", winHeight) - self.optState.setValue("GuiProjectSettings", "replaceColW", replaceColW) - self.optState.setValue("GuiProjectSettings", "statusColW", statusColW) - self.optState.setValue("GuiProjectSettings", "importColW", importColW) + pOptions = self.theProject.options + pOptions.setValue("GuiProjectSettings", "winWidth", winWidth) + pOptions.setValue("GuiProjectSettings", "winHeight", winHeight) + pOptions.setValue("GuiProjectSettings", "replaceColW", replaceColW) + pOptions.setValue("GuiProjectSettings", "statusColW", statusColW) + pOptions.setValue("GuiProjectSettings", "importColW", importColW) return @@ -159,29 +166,29 @@ class GuiProjectSettings(PagedDialog): class GuiProjectEditMain(QWidget): - def __init__(self, theParent, theProject): - QWidget.__init__(self, theParent) + def __init__(self, mainGui, theProject): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent + self.mainGui = mainGui self.theProject = theProject # The Form self.mainForm = QConfigLayout() - self.mainForm.setHelpTextStyle(self.theParent.theTheme.helpText) + self.mainForm.setHelpTextStyle(self.mainGui.mainTheme.helpText) self.setLayout(self.mainForm) self.mainForm.addGroupLabel(self.tr("Project Settings")) xW = self.mainConf.pxInt(250) - xH = round(4.8*self.theParent.theTheme.fontPixelSize) + xH = round(4.8*self.mainGui.mainTheme.fontPixelSize) self.editName = QLineEdit() self.editName.setMaxLength(200) self.editName.setMaximumWidth(xW) self.editName.setText(self.theProject.projName) self.mainForm.addRow( - self.tr("Working title"), + self.tr("Project name"), self.editName, self.tr("Should be set only once.") ) @@ -209,7 +216,7 @@ class GuiProjectEditMain(QWidget): self.spellLang = QComboBox(self) self.spellLang.setMaximumWidth(xW) self.spellLang.addItem(self.tr("Default"), "None") - langAvail = self.theParent.docEditor.spEnchant.listDictionaries() + langAvail = self.mainGui.docEditor.spEnchant.listDictionaries() for spTag, spProv in langAvail: qLocal = QLocale(spTag) spLang = qLocal.nativeLanguageName().title() @@ -245,14 +252,17 @@ class GuiProjectEditStatus(QWidget): COL_LABEL = 0 COL_USAGE = 1 - def __init__(self, theParent, theProject, isStatus): - QWidget.__init__(self, theParent) + KEY_ROLE = Qt.UserRole + COL_ROLE = Qt.UserRole + 1 + NUM_ROLE = Qt.UserRole + 2 + + def __init__(self, mainGui, theProject, isStatus): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent + self.mainGui = mainGui self.theProject = theProject - self.optState = theProject.optState - self.theTheme = theParent.theTheme + self.mainTheme = mainGui.mainTheme if isStatus: self.theStatus = self.theProject.statusItems @@ -264,15 +274,14 @@ class GuiProjectEditStatus(QWidget): colSetting = "importColW" wCol0 = self.mainConf.pxInt( - self.optState.getInt("GuiProjectSettings", colSetting, 130) + self.theProject.options.getInt("GuiProjectSettings", colSetting, 130) ) - self.colData = [] - self.colCounts = [] + self.colDeleted = [] self.colChanged = False - self.selColour = None + self.selColour = QColor(100, 100, 100) - self.iPx = self.theTheme.baseIconSize + self.iPx = self.mainTheme.baseIconSize # The List # ======== @@ -285,18 +294,24 @@ class GuiProjectEditStatus(QWidget): self.listBox.setColumnWidth(self.COL_LABEL, wCol0) self.listBox.setIndentation(0) - for iName, iCol, nUse in self.theStatus: - self._addItem(iName, iCol, iName, nUse) + for key, entry in self.theStatus.items(): + self._addItem(key, entry["name"], entry["cols"], entry["count"]) # List Controls # ============= - self.addButton = QPushButton(self.theTheme.getIcon("add"), "") + self.addButton = QPushButton(self.mainTheme.getIcon("add"), "") self.addButton.clicked.connect(self._newItem) - self.delButton = QPushButton(self.theTheme.getIcon("remove"), "") + self.delButton = QPushButton(self.mainTheme.getIcon("remove"), "") self.delButton.clicked.connect(self._delItem) + self.upButton = QPushButton(self.mainTheme.getIcon("up"), "") + self.upButton.clicked.connect(lambda: self._moveItem(-1)) + + self.dnButton = QPushButton(self.mainTheme.getIcon("down"), "") + self.dnButton.clicked.connect(lambda: self._moveItem(1)) + # Edit Form # ========= @@ -306,7 +321,7 @@ class GuiProjectEditStatus(QWidget): self.editName.setPlaceholderText(self.tr("Select item to edit")) self.colPixmap = QPixmap(self.iPx, self.iPx) - self.colPixmap.fill(QColor(120, 120, 120)) + self.colPixmap.fill(QColor(100, 100, 100)) self.colButton = QPushButton(QIcon(self.colPixmap), self.tr("Colour")) self.colButton.setIconSize(self.colPixmap.rect().size()) self.colButton.clicked.connect(self._selectColour) @@ -320,6 +335,8 @@ class GuiProjectEditStatus(QWidget): self.listControls = QVBoxLayout() self.listControls.addWidget(self.addButton) self.listControls.addWidget(self.delButton) + self.listControls.addWidget(self.upButton) + self.listControls.addWidget(self.dnButton) self.listControls.addStretch(1) self.editBox = QHBoxLayout() @@ -349,12 +366,15 @@ class GuiProjectEditStatus(QWidget): if self.colChanged: newList = [] for n in range(self.listBox.topLevelItemCount()): - nItem = self.listBox.topLevelItem(n) - nIdx = nItem.data(self.COL_LABEL, Qt.UserRole) - newList.append(self.colData[nIdx]) - return newList + item = self.listBox.topLevelItem(n) + newList.append({ + "key": item.data(self.COL_LABEL, self.KEY_ROLE), + "name": item.text(self.COL_LABEL), + "cols": item.data(self.COL_LABEL, self.COL_ROLE), + }) + return newList, self.colDeleted - return None + return [], [] ## # User Actions @@ -369,16 +389,16 @@ class GuiProjectEditStatus(QWidget): ) if newCol.isValid(): self.selColour = newCol - colPixmap = QPixmap(self.iPx, self.iPx) - colPixmap.fill(newCol) - self.colButton.setIcon(QIcon(colPixmap)) - self.colButton.setIconSize(colPixmap.rect().size()) + pixmap = QPixmap(self.iPx, self.iPx) + pixmap.fill(newCol) + self.colButton.setIcon(QIcon(pixmap)) + self.colButton.setIconSize(pixmap.rect().size()) return def _newItem(self): """Create a new status item. """ - newItem = self._addItem(self.tr("New Item"), (0, 0, 0), None, 0) + newItem = self._addItem(None, self.tr("New Item"), (100, 100, 100), 0) newItem.setBackground(self.COL_LABEL, QBrush(QColor(0, 255, 0, 70))) newItem.setBackground(self.COL_USAGE, QBrush(QColor(0, 255, 0, 70))) self.colChanged = True @@ -390,14 +410,14 @@ class GuiProjectEditStatus(QWidget): selItem = self._getSelectedItem() if selItem is not None: iRow = self.listBox.indexOfTopLevelItem(selItem) - selIdx = selItem.data(self.COL_LABEL, Qt.UserRole) - if self.colCounts[selIdx] == 0: - self.listBox.takeTopLevelItem(iRow) - self.colChanged = True - else: - self.theParent.makeAlert(self.tr( + if selItem.data(self.COL_LABEL, self.NUM_ROLE) > 0: + self.mainGui.makeAlert(self.tr( "Cannot delete a status item that is in use." ), nwAlert.ERROR) + else: + self.listBox.takeTopLevelItem(iRow) + self.colDeleted.append(selItem.data(self.COL_LABEL, self.KEY_ROLE)) + self.colChanged = True return def _saveItem(self): @@ -405,53 +425,75 @@ class GuiProjectEditStatus(QWidget): """ selItem = self._getSelectedItem() if selItem is not None: - selIdx = selItem.data(self.COL_LABEL, Qt.UserRole) - self.colData[selIdx] = ( - self.editName.text().strip(), - self.selColour.red(), - self.selColour.green(), - self.selColour.blue(), - self.colData[selIdx][4] - ) - selItem.setText(self.COL_LABEL, self.colData[selIdx][0]) - selItem.setText(self.COL_USAGE, self._usageString(self.colCounts[selIdx])) + selItem.setText(self.COL_LABEL, simplified(self.editName.text())) selItem.setIcon(self.COL_LABEL, self.colButton.icon()) + selItem.setData(self.COL_LABEL, self.COL_ROLE, ( + self.selColour.red(), self.selColour.green(), self.selColour.blue() + )) self.editName.setEnabled(False) self.colChanged = True return - def _addItem(self, iName, iCol, oName, nUse): + def _addItem(self, key, name, cols, count): """Add a status item to the list. """ - newIcon = QPixmap(self.iPx, self.iPx) - newIcon.fill(QColor(*iCol)) - newItem = QTreeWidgetItem() - newItem.setText(self.COL_LABEL, iName) - newItem.setText(self.COL_USAGE, self._usageString(nUse)) - newItem.setIcon(self.COL_LABEL, QIcon(newIcon)) - newItem.setData(self.COL_LABEL, Qt.UserRole, len(self.colData)) - self.listBox.addTopLevelItem(newItem) - self.colData.append((iName, iCol[0], iCol[1], iCol[2], oName)) - self.colCounts.append(nUse) - return newItem + pixmap = QPixmap(self.iPx, self.iPx) + pixmap.fill(QColor(*cols)) + + item = QTreeWidgetItem() + item.setText(self.COL_LABEL, name) + item.setIcon(self.COL_LABEL, QIcon(pixmap)) + item.setData(self.COL_LABEL, self.KEY_ROLE, key) + item.setData(self.COL_LABEL, self.COL_ROLE, cols) + item.setData(self.COL_LABEL, self.NUM_ROLE, count) + item.setText(self.COL_USAGE, self._usageString(count)) + + self.listBox.addTopLevelItem(item) + + return item + + def _moveItem(self, step): + """Move and item up or down step. + """ + selItem = self._getSelectedItem() + if selItem is None: + return + + tIndex = self.listBox.indexOfTopLevelItem(selItem) + nChild = self.listBox.topLevelItemCount() + nIndex = tIndex + step + if nIndex < 0 or nIndex >= nChild: + return + + cItem = self.listBox.takeTopLevelItem(tIndex) + self.listBox.insertTopLevelItem(nIndex, cItem) + self.listBox.clearSelection() + + cItem.setSelected(True) + self.colChanged = True + + return def _selectedItem(self): """Extract the info of a selected item and populate the settings boxes and button. """ selItem = self._getSelectedItem() - if selItem is not None: - selIdx = selItem.data(self.COL_LABEL, Qt.UserRole) - selVal = self.colData[selIdx] - self.selColour = QColor(selVal[1], selVal[2], selVal[3]) - newIcon = QPixmap(self.iPx, self.iPx) - newIcon.fill(self.selColour) - self.editName.setText(selVal[0]) - self.colButton.setIcon(QIcon(newIcon)) - self.editName.setEnabled(True) - self.editName.selectAll() - self.editName.setFocus() + if selItem is None: + return + + cols = selItem.data(self.COL_LABEL, self.COL_ROLE) + name = selItem.text(self.COL_LABEL) + + pixmap = QPixmap(self.iPx, self.iPx) + pixmap.fill(QColor(*cols)) + self.selColour = QColor(*cols) + self.editName.setText(name) + self.colButton.setIcon(QIcon(pixmap)) + self.editName.setEnabled(True) + self.editName.selectAll() + self.editName.setFocus() return @@ -467,12 +509,6 @@ class GuiProjectEditStatus(QWidget): return selItem[0] return None - def _rowsMoved(self): - """A row has been moved, so set the changed flag. - """ - self.colChanged = True - return - def _usageString(self, nUse): """Generate usage string. """ @@ -491,18 +527,17 @@ class GuiProjectEditReplace(QWidget): COL_KEY = 0 COL_REPL = 1 - def __init__(self, theParent, theProject): - QWidget.__init__(self, theParent) + def __init__(self, mainGui, theProject): + QWidget.__init__(self, mainGui) self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme self.theProject = theProject - self.optState = theProject.optState self.arChanged = False wCol0 = self.mainConf.pxInt( - self.optState.getInt("GuiProjectSettings", "replaceColW", 130) + self.theProject.options.getInt("GuiProjectSettings", "replaceColW", 130) ) pageLabel = self.tr("Text Replace List for Preview and Export") @@ -528,10 +563,10 @@ class GuiProjectEditReplace(QWidget): # List Controls # ============= - self.addButton = QPushButton(self.theTheme.getIcon("add"), "") + self.addButton = QPushButton(self.mainTheme.getIcon("add"), "") self.addButton.clicked.connect(self._addEntry) - self.delButton = QPushButton(self.theTheme.getIcon("remove"), "") + self.delButton = QPushButton(self.mainTheme.getIcon("remove"), "") self.delButton.clicked.connect(self._delEntry) # Edit Form diff --git a/novelwriter/dialogs/quotes.py b/novelwriter/dialogs/quotes.py index e8426adf..299386d8 100644 --- a/novelwriter/dialogs/quotes.py +++ b/novelwriter/dialogs/quotes.py @@ -42,8 +42,8 @@ class GuiQuoteSelect(QDialog): selectedQuote = "" - def __init__(self, theParent=None, currentQuote='"'): - QDialog.__init__(self, parent=theParent) + def __init__(self, parent=None, currentQuote='"'): + QDialog.__init__(self, parent=parent) self.mainConf = novelwriter.CONFIG diff --git a/novelwriter/dialogs/updates.py b/novelwriter/dialogs/updates.py index fccc49c2..c4782e6d 100644 --- a/novelwriter/dialogs/updates.py +++ b/novelwriter/dialogs/updates.py @@ -43,14 +43,14 @@ logger = logging.getLogger(__name__) class GuiUpdates(QDialog): - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiUpdates ...") self.setObjectName("GuiUpdates") - self.mainConf = novelwriter.CONFIG - self.theParent = theParent + self.mainConf = novelwriter.CONFIG + self.mainGui = mainGui self.setWindowTitle(self.tr("Check for Updates")) @@ -61,7 +61,7 @@ class GuiUpdates(QDialog): # Left Box self.nwIcon = QLabel() - self.nwIcon.setPixmap(self.theParent.theTheme.getPixmap("novelwriter", (nPx, nPx))) + self.nwIcon.setPixmap(self.mainGui.mainTheme.getPixmap("novelwriter", (nPx, nPx))) self.leftBox = QVBoxLayout() self.leftBox.addWidget(self.nwIcon) diff --git a/novelwriter/dialogs/wordlist.py b/novelwriter/dialogs/wordlist.py index 7dadf258..9a17eed8 100644 --- a/novelwriter/dialogs/wordlist.py +++ b/novelwriter/dialogs/wordlist.py @@ -42,29 +42,29 @@ logger = logging.getLogger(__name__) class GuiWordList(QDialog): - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiWordList ...") self.setObjectName("GuiWordList") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject self.setWindowTitle(self.tr("Project Word List")) mS = self.mainConf.pxInt(250) wW = self.mainConf.pxInt(320) wH = self.mainConf.pxInt(340) + pOptions = self.theProject.options self.setMinimumWidth(mS) self.setMinimumHeight(mS) self.resize( - self.mainConf.pxInt(self.optState.getInt("GuiWordList", "winWidth", wW)), - self.mainConf.pxInt(self.optState.getInt("GuiWordList", "winHeight", wH)) + self.mainConf.pxInt(pOptions.getInt("GuiWordList", "winWidth", wW)), + self.mainConf.pxInt(pOptions.getInt("GuiWordList", "winHeight", wH)) ) # Main Widgets @@ -78,10 +78,10 @@ class GuiWordList(QDialog): self.newEntry = QLineEdit() - self.addButton = QPushButton(self.theTheme.getIcon("add"), "") + self.addButton = QPushButton(self.mainTheme.getIcon("add"), "") self.addButton.clicked.connect(self._doAdd) - self.delButton = QPushButton(self.theTheme.getIcon("remove"), "") + self.delButton = QPushButton(self.mainTheme.getIcon("remove"), "") self.delButton.clicked.connect(self._doDelete) self.editBox = QHBoxLayout() @@ -121,13 +121,13 @@ class GuiWordList(QDialog): """ newWord = self.newEntry.text().strip() if newWord == "": - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Cannot add a blank word." ), nwAlert.ERROR) return False if self.listBox.findItems(newWord, Qt.MatchExactly): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "The word '{0}' is already in the word list." ).format(newWord), nwAlert.ERROR) return False @@ -207,8 +207,9 @@ class GuiWordList(QDialog): winWidth = self.mainConf.rpxInt(self.width()) winHeight = self.mainConf.rpxInt(self.height()) - self.optState.setValue("GuiWordList", "winWidth", winWidth) - self.optState.setValue("GuiWordList", "winHeight", winHeight) + pOptions = self.theProject.options + pOptions.setValue("GuiWordList", "winWidth", winWidth) + pOptions.setValue("GuiWordList", "winHeight", winHeight) return diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 3360d8c5..48b894ba 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -32,7 +32,6 @@ class nwItemType(Enum): ROOT = 1 FOLDER = 2 FILE = 3 - TRASH = 4 # END Enum nwItemType @@ -63,6 +62,14 @@ class nwItemLayout(Enum): # END Enum nwItemLayout +class nwDocMode(Enum): + + VIEW = 0 + EDIT = 1 + +# END Enum nwDocMode + + class nwDocAction(Enum): NO_ACTION = 0 @@ -131,6 +138,16 @@ class nwState(Enum): # END Enum nwState +class nwView(Enum): + + EDITOR = 0 + PROJECT = 1 + NOVEL = 2 + OUTLINE = 3 + +# END Enum nwView + + class nwWidget(Enum): TREE = 1 diff --git a/novelwriter/error.py b/novelwriter/error.py index 0dec56e8..2ceae1e3 100644 --- a/novelwriter/error.py +++ b/novelwriter/error.py @@ -87,6 +87,8 @@ class NWErrorMessage(QDialog): self.mainBox.addWidget(self.btnBox, 2, 0, 1, 2) self.mainBox.setSpacing(16) + # Pick a random window title from a set of error messages by + # Hex, the computer, from Discworld self.setWindowTitle([ "+++ Out of Cheese Error +++", "+++ Divide by Cucumber Error +++", diff --git a/novelwriter/gui/__init__.py b/novelwriter/gui/__init__.py index 405549cb..17699942 100644 --- a/novelwriter/gui/__init__.py +++ b/novelwriter/gui/__init__.py @@ -23,12 +23,12 @@ from novelwriter.gui.doceditor import GuiDocEditor from novelwriter.gui.docviewer import GuiDocViewer, GuiDocViewDetails from novelwriter.gui.itemdetails import GuiItemDetails from novelwriter.gui.mainmenu import GuiMainMenu -from novelwriter.gui.noveltree import GuiNovelTree -from novelwriter.gui.outline import GuiOutline -from novelwriter.gui.outlinedetails import GuiOutlineDetails -from novelwriter.gui.projtree import GuiProjectTree +from novelwriter.gui.noveltree import GuiNovelView +from novelwriter.gui.outline import GuiOutlineView +from novelwriter.gui.projtree import GuiProjectView from novelwriter.gui.statusbar import GuiMainStatus from novelwriter.gui.theme import GuiTheme +from novelwriter.gui.viewsbar import GuiViewsBar __all__ = [ "GuiDocEditor", @@ -37,9 +37,9 @@ __all__ = [ "GuiItemDetails", "GuiMainMenu", "GuiMainStatus", - "GuiNovelTree", - "GuiOutline", - "GuiOutlineDetails", - "GuiProjectTree", + "GuiNovelView", + "GuiOutlineView", + "GuiProjectView", "GuiTheme", + "GuiViewsBar", ] diff --git a/novelwriter/gui/custom.py b/novelwriter/gui/custom.py index 16d26b40..e571a5a1 100644 --- a/novelwriter/gui/custom.py +++ b/novelwriter/gui/custom.py @@ -376,8 +376,8 @@ class QSwitch(QAbstractButton): class PagedDialog(QDialog): - def __init__(self, theParent=None): - QDialog.__init__(self, parent=theParent) + def __init__(self, parent=None): + QDialog.__init__(self, parent=parent) self._tabBar = VerticalTabBar(self) self._tabBar.setExpanding(False) @@ -409,10 +409,10 @@ class PagedDialog(QDialog): return - def addTab(self, tabWidget, tabLabel): + def addTab(self, widget, label): """Forwards the adding of tabs to the QTabWidget. """ - self._tabBox.addTab(tabWidget, tabLabel) + self._tabBox.addTab(widget, label) return def addControls(self, buttonBar): @@ -426,20 +426,20 @@ class PagedDialog(QDialog): class VerticalTabBar(QTabBar): - def __init__(self, theParent=None): - QTabBar.__init__(self, parent=theParent) + def __init__(self, parent=None): + QTabBar.__init__(self, parent=parent) self._mW = novelwriter.CONFIG.pxInt(150) return - def tabSizeHint(self, theIndex): + def tabSizeHint(self, index): """Returns a transposed size hint for the rotated bar. """ - tSize = QTabBar.tabSizeHint(self, theIndex) + tSize = QTabBar.tabSizeHint(self, index) tSize.transpose() tSize.setWidth(min(tSize.width(), self._mW)) return tSize - def paintEvent(self, theEvent): + def paintEvent(self, event): """Custom implementation of the label painter that rotates the label 90 degrees. """ diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index f2412242..eb77dcdf 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -33,6 +33,7 @@ import bisect import logging import novelwriter +from enum import Enum from time import time from PyQt5.QtCore import ( @@ -50,7 +51,7 @@ from PyQt5.QtWidgets import ( ) from novelwriter.core import NWDoc, NWSpellEnchant, countWords -from novelwriter.enum import nwAlert, nwDocAction, nwDocInsert, nwItemClass +from novelwriter.enum import nwAlert, nwDocAction, nwDocInsert, nwDocMode from novelwriter.common import transferCase from novelwriter.constants import nwConst, nwKeyWords, nwUnicode from novelwriter.gui.dochighlight import GuiDocHighlighter @@ -69,18 +70,18 @@ class GuiDocEditor(QTextEdit): spellDictionaryChanged = pyqtSignal(str, str) docEditedStatusChanged = pyqtSignal(bool) docCountsChanged = pyqtSignal(str, int, int, int) + loadDocumentTagRequest = pyqtSignal(str, Enum) - def __init__(self, theParent): - QTextEdit.__init__(self, theParent) + def __init__(self, mainGui): + QTextEdit.__init__(self, mainGui) logger.debug("Initialising GuiDocEditor ...") # Class Variables self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex - self.theProject = theParent.theProject + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject self._nwDocument = None self._nwItem = None @@ -124,7 +125,7 @@ class GuiDocEditor(QTextEdit): # Syntax self.spEnchant = NWSpellEnchant() - self.highLight = GuiDocHighlighter(qDoc, self.theParent, self.spEnchant) + self.highLight = GuiDocHighlighter(qDoc, self.mainGui, self.spEnchant) # Context Menu self.setContextMenuPolicy(Qt.CustomContextMenu) @@ -132,8 +133,9 @@ class GuiDocEditor(QTextEdit): # Editor Settings self.setMinimumWidth(self.mainConf.pxInt(300)) - self.setAutoFillBackground(True) self.setAcceptRichText(False) + self.setAutoFillBackground(True) + self.setFrameStyle(QFrame.NoFrame) # Custom Shortcuts QShortcut( @@ -238,10 +240,10 @@ class GuiDocEditor(QTextEdit): if self.mainConf.textFont is None: # If none is defined, set a default font theFont = QFont() - if self.mainConf.osWindows and "Arial" in self.theTheme.guiFontDB.families(): + if self.mainConf.osWindows and "Arial" in self.mainTheme.guiFontDB.families(): theFont.setFamily("Arial") theFont.setPointSize(12) - elif self.mainConf.osDarwin and "Courier" in self.theTheme.guiFontDB.families(): + elif self.mainConf.osDarwin and "Courier" in self.mainTheme.guiFontDB.families(): theFont.setFamily("Courier") theFont.setPointSize(12) else: @@ -256,19 +258,23 @@ class GuiDocEditor(QTextEdit): # Set the widget colours to match syntax theme mainPalette = self.palette() - mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - mainPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack)) - mainPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + mainPalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(mainPalette) docPalette = self.viewport().palette() - docPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack)) - docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + docPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + docPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.viewport().setPalette(docPalette) self.docHeader.matchColours() self.docFooter.matchColours() +<<<<<<< HEAD +======= + # Set default text margins +>>>>>>> main # Due to cursor visibility, a part of the margin must be # allocated to the document itself. See issue #1112. cW = self.cursorWidth() @@ -342,7 +348,7 @@ class GuiDocEditor(QTextEdit): docSize = len(theDoc) if docSize > nwConst.MAX_DOCSIZE: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "The document you are trying to open is too big. " "The document size is {0} MB. " "The maximum size allowed is {1} MB." @@ -403,7 +409,7 @@ class GuiDocEditor(QTextEdit): self.document().rootFrame().setFrameFormat(docFrame) self.docFooter.updateLineCount() - self._docHeaders = self.theIndex.getHandleHeaders(self._docHandle) + self._docHeaders = self.theProject.index.getHandleHeaders(self._docHandle) qApp.processEvents() self.document().clearUndoRedoStacks() @@ -418,7 +424,7 @@ class GuiDocEditor(QTextEdit): # Update the status bar if self._nwItem is not None: - self.theParent.setStatus( + self.mainGui.setStatus( self.tr("Opened Document: {0}").format(self._nwItem.itemName) ) @@ -443,7 +449,7 @@ class GuiDocEditor(QTextEdit): """ docSize = len(theText) if docSize > nwConst.MAX_DOCSIZE: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "The text you are trying to add is too big. " "The text size is {0} MB. " "The maximum size allowed is {1} MB." @@ -489,7 +495,7 @@ class GuiDocEditor(QTextEdit): if not self._nwDocument.writeDocument(docText): saveOk = False if self._nwDocument._currHash != self._nwDocument._prevHash: - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("File Changed on Disk"), self.tr( "This document has been changed outside of novelWriter " @@ -500,7 +506,7 @@ class GuiDocEditor(QTextEdit): saveOk = self._nwDocument.writeDocument(docText, forceWrite=True) if not saveOk: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Could not save document."), self._nwDocument.getError() ], nwAlert.ERROR) @@ -508,22 +514,24 @@ class GuiDocEditor(QTextEdit): self.setDocumentChanged(False) - oldHeader = self.theIndex.getHandleHeaderLevel(tHandle) - self.theIndex.scanText(tHandle, docText) - newHeader = self.theIndex.getHandleHeaderLevel(tHandle) + oldHeader = self.theProject.index.getHandleHeaderLevel(tHandle) + self.theProject.index.scanText(tHandle, docText) + newHeader = self.theProject.index.getHandleHeaderLevel(tHandle) + # ToDo: This should be a signal if self._updateHeaders(checkLevel=True): - self.theParent.requestNovelTreeRefresh() + self.mainGui.requestNovelTreeRefresh() else: - self.theParent.novelView.updateWordCounts(tHandle) + self.mainGui.novelView.updateWordCounts(tHandle) + # ToDo: This should be a signal if oldHeader != newHeader: - self.theParent.treeView.setTreeItemValues(tHandle) - self.theParent.treeMeta.updateViewBox(tHandle) + self.mainGui.projView.setTreeItemValues(tHandle) + self.mainGui.itemDetails.updateViewBox(tHandle) self.docFooter.updateInfo() # Update the status bar - self.theParent.setStatus( + self.mainGui.setStatus( self.tr("Saved Document: {0}").format(self._nwItem.itemName) ) @@ -544,8 +552,13 @@ class GuiDocEditor(QTextEdit): sH = hBar.height() if hBar.isVisible() else 0 tM = self._vpMargin +<<<<<<< HEAD if self.mainConf.textWidth > 0 or self.theParent.isFocusMode: tW = self.mainConf.getTextWidth(self.theParent.isFocusMode) +======= + if self.mainConf.textWidth > 0 or self.mainGui.isFocusMode: + tW = self.mainConf.getTextWidth(self.mainGui.isFocusMode) +>>>>>>> main tM = max((wW - sW - tW)//2, self._vpMargin) tB = self.frameWidth() @@ -569,16 +582,6 @@ class GuiDocEditor(QTextEdit): return - def updateDocInfo(self, tHandle): - """Called when an item label is changed to check if the document - title bar needs updating, - """ - if tHandle == self._docHandle: - self.docHeader.setTitleFromHandle(self._docHandle) - self.docFooter.updateInfo() - self.updateDocMargins() - return - ## # Properties ## @@ -714,7 +717,7 @@ class GuiDocEditor(QTextEdit): if not self.mainConf.hasEnchant: if theMode: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Spell checking requires the package PyEnchant. " "It does not appear to be installed." ), nwAlert.INFO) @@ -724,7 +727,7 @@ class GuiDocEditor(QTextEdit): theMode = False self._spellCheck = theMode - self.theParent.mainMenu.setSpellCheck(theMode) + self.mainGui.mainMenu.setSpellCheck(theMode) self.theProject.setSpellCheck(theMode) self.highLight.setSpellCheck(theMode) if not self._bigDoc: @@ -752,7 +755,7 @@ class GuiDocEditor(QTextEdit): qApp.restoreOverrideCursor() afTime = time() logger.debug("Document highlighted in %.3f ms", 1000*(afTime-bfTime)) - self.theParent.statusBar.setStatus(self.tr("Spell check complete")) + self.mainGui.statusBar.setStatus(self.tr("Spell check complete")) return True @@ -1068,7 +1071,22 @@ class GuiDocEditor(QTextEdit): return ## - # Slots + # Public Slots + ## + + @pyqtSlot(str) + def updateDocInfo(self, tHandle): + """Called when an item label is changed to check if the document + title bar needs updating, + """ + if tHandle == self._docHandle: + self.docHeader.setTitleFromHandle(self._docHandle) + self.docFooter.updateInfo() + self.updateDocMargins() + return + + ## + # Private Slots ## @pyqtSlot(int, int, int) @@ -1080,7 +1098,7 @@ class GuiDocEditor(QTextEdit): self._lastFind = None if self.document().characterCount() > nwConst.MAX_DOCSIZE: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "The document has grown too big and you cannot add more text to it. " "The maximum size of a single novelWriter document is {0} MB." ).format( @@ -1240,7 +1258,7 @@ class GuiDocEditor(QTextEdit): if time() - self._lastEdit < 5 * self.wcInterval: logger.verbose("Running word counter") - self.theParent.threadPool.start(self.wCounterDoc) + self.mainGui.threadPool.start(self.wCounterDoc) return @@ -1297,7 +1315,7 @@ class GuiDocEditor(QTextEdit): logger.verbose("Selection word counter is busy") return - self.theParent.threadPool.start(self.wCounterSel) + self.mainGui.threadPool.start(self.wCounterSel) return @@ -1376,7 +1394,7 @@ class GuiDocEditor(QTextEdit): self.docSearch.setResultCount(0, 0) self._lastFind = None if self.docSearch.doNextFile and not goBack: - self.theParent.openNextDocument( + self.mainGui.openNextDocument( self._docHandle, wrapAround=self.docSearch.doLoop ) self.beginSearch() @@ -1396,7 +1414,7 @@ class GuiDocEditor(QTextEdit): if resIdx > maxIdx: if self.docSearch.doNextFile and not goBack: - self.theParent.openNextDocument( + self.mainGui.openNextDocument( self._docHandle, wrapAround=self.docSearch.doLoop ) self.beginSearch() @@ -1640,7 +1658,7 @@ class GuiDocEditor(QTextEdit): """ theCursor = self.textCursor() if not theCursor.hasSelection(): - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Please select some text before calling replace quotes." ), nwAlert.ERROR) return False @@ -1896,7 +1914,7 @@ class GuiDocEditor(QTextEdit): if loadTag: logger.verbose("Attempting to follow tag '%s'", theWord) - self.theParent.docViewer.loadFromTag(theWord) + self.loadDocumentTagRequest.emit(theWord, nwDocMode.VIEW) else: logger.verbose("Potential tag '%s'", theWord) @@ -2003,7 +2021,7 @@ class GuiDocEditor(QTextEdit): def _allowSpaceBeforeColon(text, char): """Special checker function only used by the insert space feature for French, Spanish, etc, so it doesn't insert a - sapce before colons in meta data lines. + space before colons in meta data lines. See issue #1090. """ if char == ":" and len(text) > 1: if text[0] == "@": @@ -2020,7 +2038,7 @@ class GuiDocEditor(QTextEdit): if self._docHandle is None: return False - newHeaders = self.theIndex.getHandleHeaders(self._docHandle) + newHeaders = self.theProject.index.getHandleHeaders(self._docHandle) if checkPos: newPos = [x[0] for x in newHeaders] oldPos = [x[0] for x in self._docHeaders] @@ -2198,9 +2216,9 @@ class GuiDocEditSearch(QFrame): self.mainConf = novelwriter.CONFIG self.docEditor = docEditor - self.theParent = docEditor.theParent + self.mainGui = docEditor.mainGui self.theProject = docEditor.theProject - self.theTheme = docEditor.theTheme + self.mainTheme = docEditor.mainTheme self.repVisible = False self.isCaseSense = self.mainConf.searchCase @@ -2211,9 +2229,9 @@ class GuiDocEditSearch(QFrame): self.doMatchCap = self.mainConf.searchMatchCap mPx = self.mainConf.pxInt(6) - tPx = int(0.8*self.theTheme.fontPixelSize) - self.boxFont = self.theTheme.guiFont - self.boxFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + tPx = int(0.8*self.mainTheme.fontPixelSize) + self.boxFont = self.mainTheme.guiFont + self.boxFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) self.setContentsMargins(0, 0, 0, 0) self.setAutoFillBackground(True) @@ -2247,38 +2265,38 @@ class GuiDocEditSearch(QFrame): self.resultLabel = QLabel("?/?") self.resultLabel.setFont(self.boxFont) - self.resultLabel.setMinimumWidth(self.theTheme.getTextWidth("?/?", self.boxFont)) + self.resultLabel.setMinimumWidth(self.mainTheme.getTextWidth("?/?", self.boxFont)) self.toggleCase = QAction(self.tr("Case Sensitive"), self) - self.toggleCase.setIcon(self.theTheme.getIcon("search_case")) + self.toggleCase.setIcon(self.mainTheme.getIcon("search_case")) self.toggleCase.setCheckable(True) self.toggleCase.setChecked(self.isCaseSense) self.toggleCase.toggled.connect(self._doToggleCase) self.searchOpt.addAction(self.toggleCase) self.toggleWord = QAction(self.tr("Whole Words Only"), self) - self.toggleWord.setIcon(self.theTheme.getIcon("search_word")) + self.toggleWord.setIcon(self.mainTheme.getIcon("search_word")) self.toggleWord.setCheckable(True) self.toggleWord.setChecked(self.isWholeWord) self.toggleWord.toggled.connect(self._doToggleWord) self.searchOpt.addAction(self.toggleWord) self.toggleRegEx = QAction(self.tr("RegEx Mode"), self) - self.toggleRegEx.setIcon(self.theTheme.getIcon("search_regex")) + self.toggleRegEx.setIcon(self.mainTheme.getIcon("search_regex")) self.toggleRegEx.setCheckable(True) self.toggleRegEx.setChecked(self.isRegEx) self.toggleRegEx.toggled.connect(self._doToggleRegEx) self.searchOpt.addAction(self.toggleRegEx) self.toggleLoop = QAction(self.tr("Loop Search"), self) - self.toggleLoop.setIcon(self.theTheme.getIcon("search_loop")) + self.toggleLoop.setIcon(self.mainTheme.getIcon("search_loop")) self.toggleLoop.setCheckable(True) self.toggleLoop.setChecked(self.doLoop) self.toggleLoop.toggled.connect(self._doToggleLoop) self.searchOpt.addAction(self.toggleLoop) self.toggleProject = QAction(self.tr("Search Next File"), self) - self.toggleProject.setIcon(self.theTheme.getIcon("search_project")) + self.toggleProject.setIcon(self.mainTheme.getIcon("search_project")) self.toggleProject.setCheckable(True) self.toggleProject.setChecked(self.doNextFile) self.toggleProject.toggled.connect(self._doToggleProject) @@ -2287,7 +2305,7 @@ class GuiDocEditSearch(QFrame): self.searchOpt.addSeparator() self.toggleMatchCap = QAction(self.tr("Preserve Case"), self) - self.toggleMatchCap.setIcon(self.theTheme.getIcon("search_preserve")) + self.toggleMatchCap.setIcon(self.mainTheme.getIcon("search_preserve")) self.toggleMatchCap.setCheckable(True) self.toggleMatchCap.setChecked(self.doMatchCap) self.toggleMatchCap.toggled.connect(self._doToggleMatchCap) @@ -2296,7 +2314,7 @@ class GuiDocEditSearch(QFrame): self.searchOpt.addSeparator() self.cancelSearch = QAction(self.tr("Close Search"), self) - self.cancelSearch.setIcon(self.theTheme.getIcon("search_cancel")) + self.cancelSearch.setIcon(self.mainTheme.getIcon("search_cancel")) self.cancelSearch.triggered.connect(self._doClose) self.searchOpt.addAction(self.cancelSearch) @@ -2311,12 +2329,12 @@ class GuiDocEditSearch(QFrame): self.showReplace.setStyleSheet("QToolButton {border: none; background: transparent;}") self.showReplace.toggled.connect(self._doToggleReplace) - self.searchButton = QPushButton(self.theTheme.getIcon("search"), "") + self.searchButton = QPushButton(self.mainTheme.getIcon("search"), "") self.searchButton.setFixedSize(QSize(bPx, bPx)) self.searchButton.setToolTip(self.tr("Find in current document")) self.searchButton.clicked.connect(self._doSearch) - self.replaceButton = QPushButton(self.theTheme.getIcon("search_replace"), "") + self.replaceButton = QPushButton(self.mainTheme.getIcon("search_replace"), "") self.replaceButton.setFixedSize(QSize(bPx, bPx)) self.replaceButton.setToolTip(self.tr("Find and replace in current document")) self.replaceButton.clicked.connect(self._doReplace) @@ -2435,7 +2453,7 @@ class GuiDocEditSearch(QFrame): """ currRes = "?" if currRes is None else currRes resCount = "?" if resCount is None else "1000+" if resCount > 1000 else resCount - minWidth = self.theTheme.getTextWidth(f"{resCount}//{resCount}", self.boxFont) + minWidth = self.mainTheme.getTextWidth(f"{resCount}//{resCount}", self.boxFont) self.resultLabel.setText(f"{currRes}/{resCount}") self.resultLabel.setMinimumWidth(minWidth) self.adjustSize() @@ -2586,13 +2604,13 @@ class GuiDocEditHeader(QWidget): self.mainConf = novelwriter.CONFIG self.docEditor = docEditor - self.theParent = docEditor.theParent + self.mainGui = docEditor.mainGui self.theProject = docEditor.theProject - self.theTheme = docEditor.theTheme + self.mainTheme = docEditor.mainTheme self._docHandle = None - fPx = int(0.9*self.theTheme.fontPixelSize) + fPx = int(0.9*self.mainTheme.fontPixelSize) hSp = self.mainConf.pxInt(6) # Main Widget Settings @@ -2609,17 +2627,17 @@ class GuiDocEditHeader(QWidget): self.theTitle.setFixedHeight(fPx) lblFont = self.theTitle.font() - lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) self.theTitle.setFont(lblFont) buttonStyle = ( "QToolButton {{border: none; background: transparent;}} " "QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" - ).format(*self.theTheme.colText) + ).format(*self.mainTheme.colText) # Buttons self.editButton = QToolButton(self) - self.editButton.setIcon(self.theTheme.getIcon("edit")) + self.editButton.setIcon(self.mainTheme.getIcon("edit")) self.editButton.setContentsMargins(0, 0, 0, 0) self.editButton.setIconSize(QSize(fPx, fPx)) self.editButton.setFixedSize(fPx, fPx) @@ -2630,7 +2648,7 @@ class GuiDocEditHeader(QWidget): self.editButton.clicked.connect(self._editDocument) self.searchButton = QToolButton(self) - self.searchButton.setIcon(self.theTheme.getIcon("search")) + self.searchButton.setIcon(self.mainTheme.getIcon("search")) self.searchButton.setContentsMargins(0, 0, 0, 0) self.searchButton.setIconSize(QSize(fPx, fPx)) self.searchButton.setFixedSize(fPx, fPx) @@ -2641,7 +2659,7 @@ class GuiDocEditHeader(QWidget): self.searchButton.clicked.connect(self._searchDocument) self.minmaxButton = QToolButton(self) - self.minmaxButton.setIcon(self.theTheme.getIcon("maximise")) + self.minmaxButton.setIcon(self.mainTheme.getIcon("maximise")) self.minmaxButton.setContentsMargins(0, 0, 0, 0) self.minmaxButton.setIconSize(QSize(fPx, fPx)) self.minmaxButton.setFixedSize(fPx, fPx) @@ -2652,7 +2670,7 @@ class GuiDocEditHeader(QWidget): self.minmaxButton.clicked.connect(self._minmaxDocument) self.closeButton = QToolButton(self) - self.closeButton.setIcon(self.theTheme.getIcon("close")) + self.closeButton.setIcon(self.mainTheme.getIcon("close")) self.closeButton.setContentsMargins(0, 0, 0, 0) self.closeButton.setIconSize(QSize(fPx, fPx)) self.closeButton.setFixedSize(fPx, fPx) @@ -2695,9 +2713,9 @@ class GuiDocEditHeader(QWidget): theme rather than the main GUI. """ thePalette = QPalette() - thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText)) - thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + thePalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + thePalette.setColor(QPalette.WindowText, QColor(*self.mainTheme.colText)) + thePalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(thePalette) self.theTitle.setPalette(thePalette) @@ -2719,15 +2737,15 @@ class GuiDocEditHeader(QWidget): if self.mainConf.showFullPath: tTitle = [] - tTree = self.theProject.projTree.getItemPath(tHandle) + tTree = self.theProject.tree.getItemPath(tHandle) for aHandle in reversed(tTree): - nwItem = self.theProject.projTree[aHandle] + nwItem = self.theProject.tree[aHandle] if nwItem is not None: tTitle.append(nwItem.itemName) sSep = " %s " % nwUnicode.U_RSAQUO self.theTitle.setText(sSep.join(tTitle)) else: - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] if nwItem is None: return False self.theTitle.setText(nwItem.itemName) @@ -2744,10 +2762,10 @@ class GuiDocEditHeader(QWidget): This function is called by the GuiMain class via the toggleFocusMode function and should not be activated directly. """ - if self.theParent.isFocusMode: - self.minmaxButton.setIcon(self.theTheme.getIcon("minimise")) + if self.mainGui.isFocusMode: + self.minmaxButton.setIcon(self.mainTheme.getIcon("minimise")) else: - self.minmaxButton.setIcon(self.theTheme.getIcon("maximise")) + self.minmaxButton.setIcon(self.mainTheme.getIcon("maximise")) return ## @@ -2757,7 +2775,7 @@ class GuiDocEditHeader(QWidget): def _editDocument(self): """Open the edit item dialog from the main GUI. """ - self.theParent.editItem(self._docHandle) + self.mainGui.editItemLabel(self._docHandle) return def _searchDocument(self): @@ -2769,7 +2787,7 @@ class GuiDocEditHeader(QWidget): def _closeDocument(self): """Trigger the close editor on the main window. """ - self.theParent.closeDocEditor() + self.mainGui.closeDocEditor() self.editButton.setVisible(False) self.searchButton.setVisible(False) self.closeButton.setVisible(False) @@ -2779,7 +2797,7 @@ class GuiDocEditHeader(QWidget): def _minmaxDocument(self): """Switch on or off Focus Mode. """ - self.theParent.toggleFocusMode() + self.mainGui.toggleFocusMode() return ## @@ -2790,7 +2808,7 @@ class GuiDocEditHeader(QWidget): """Capture a click on the title and ensure that the item is selected in the project tree. """ - self.theParent.treeView.setSelectedHandle(self._docHandle, doScroll=True) + self.mainGui.projView.setSelectedHandle(self._docHandle, doScroll=True) return # END Class GuiDocEditHeader @@ -2810,23 +2828,22 @@ class GuiDocEditFooter(QWidget): self.mainConf = novelwriter.CONFIG self.docEditor = docEditor - self.theParent = docEditor.theParent + self.mainGui = docEditor.mainGui self.theProject = docEditor.theProject - self.theTheme = docEditor.theTheme - self.optState = docEditor.theProject.optState + self.mainTheme = docEditor.mainTheme self._theItem = None self._docHandle = None self._docSelection = False - self.sPx = int(round(0.9*self.theTheme.baseIconSize)) - fPx = int(0.9*self.theTheme.fontPixelSize) + self.sPx = int(round(0.9*self.mainTheme.baseIconSize)) + fPx = int(0.9*self.mainTheme.fontPixelSize) bSp = self.mainConf.pxInt(4) hSp = self.mainConf.pxInt(6) lblFont = self.font() - lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) # Main Widget Settings self.setContentsMargins(0, 0, 0, 0) @@ -2849,7 +2866,7 @@ class GuiDocEditFooter(QWidget): # Lines self.linesIcon = QLabel("") - self.linesIcon.setPixmap(self.theTheme.getPixmap("status_lines", (self.sPx, self.sPx))) + self.linesIcon.setPixmap(self.mainTheme.getPixmap("status_lines", (self.sPx, self.sPx))) self.linesIcon.setContentsMargins(0, 0, 0, 0) self.linesIcon.setFixedHeight(self.sPx) self.linesIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop) @@ -2865,7 +2882,7 @@ class GuiDocEditFooter(QWidget): # Words self.wordsIcon = QLabel("") - self.wordsIcon.setPixmap(self.theTheme.getPixmap("status_stats", (self.sPx, self.sPx))) + self.wordsIcon.setPixmap(self.mainTheme.getPixmap("status_stats", (self.sPx, self.sPx))) self.wordsIcon.setContentsMargins(0, 0, 0, 0) self.wordsIcon.setFixedHeight(self.sPx) self.wordsIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop) @@ -2917,9 +2934,9 @@ class GuiDocEditFooter(QWidget): theme rather than the main GUI. """ thePalette = QPalette() - thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText)) - thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + thePalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + thePalette.setColor(QPalette.WindowText, QColor(*self.mainTheme.colText)) + thePalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(thePalette) self.statusText.setPalette(thePalette) @@ -2936,7 +2953,7 @@ class GuiDocEditFooter(QWidget): logger.verbose("No handle set, so clearing the editor footer") self._theItem = None else: - self._theItem = self.theProject.projTree[self._docHandle] + self._theItem = self.theProject.tree[self._docHandle] self.setHasSelection(False) self.updateInfo() @@ -2958,17 +2975,10 @@ class GuiDocEditFooter(QWidget): sIcon = QPixmap() sText = "" else: - iStatus = self._theItem.itemStatus - if self._theItem.itemClass == nwItemClass.NOVEL: - iStatus = self.theProject.statusItems.checkEntry(iStatus) - theIcon = self.theParent.statusIcons[iStatus] - else: - iStatus = self.theProject.importItems.checkEntry(iStatus) - theIcon = self.theParent.importIcons[iStatus] - + theStatus, theIcon = self._theItem.getImportStatus() sIcon = theIcon.pixmap(self.sPx, self.sPx) - hLevel = self.theParent.theIndex.getHandleHeaderLevel(self._docHandle) - sText = f"{self._theItem.itemStatus} / {self._theItem.describeMe(hLevel)}" + hLevel = self.theProject.index.getHandleHeaderLevel(self._docHandle) + sText = f"{theStatus} / {self._theItem.describeMe(hLevel)}" self.statusIcon.setPixmap(sIcon) self.statusText.setText(sText) diff --git a/novelwriter/gui/dochighlight.py b/novelwriter/gui/dochighlight.py index eddc27c3..8b7ec1a5 100644 --- a/novelwriter/gui/dochighlight.py +++ b/novelwriter/gui/dochighlight.py @@ -46,16 +46,16 @@ class GuiDocHighlighter(QSyntaxHighlighter): BLOCK_META = 2 BLOCK_TITLE = 4 - def __init__(self, theDoc, theParent, spEnchant): + def __init__(self, theDoc, mainGui, spEnchant): QSyntaxHighlighter.__init__(self, theDoc) logger.debug("Initialising GuiDocHighlighter ...") self.mainConf = novelwriter.CONFIG self.theDoc = theDoc self.spEnchant = spEnchant - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject self.theHandle = None self.spellCheck = False self.spellRx = None @@ -87,24 +87,24 @@ class GuiDocHighlighter(QSyntaxHighlighter): """ logger.debug("Setting up highlighting rules") - self.colHead = QColor(*self.theTheme.colHead) - self.colHeadH = QColor(*self.theTheme.colHeadH) - self.colDialN = QColor(*self.theTheme.colDialN) - self.colDialD = QColor(*self.theTheme.colDialD) - self.colDialS = QColor(*self.theTheme.colDialS) - self.colHidden = QColor(*self.theTheme.colHidden) - self.colKey = QColor(*self.theTheme.colKey) - self.colVal = QColor(*self.theTheme.colVal) - self.colSpell = QColor(*self.theTheme.colSpell) - self.colError = QColor(*self.theTheme.colError) - self.colRepTag = QColor(*self.theTheme.colRepTag) - self.colMod = QColor(*self.theTheme.colMod) - self.colBreak = QColor(*self.theTheme.colEmph) + self.colHead = QColor(*self.mainTheme.colHead) + self.colHeadH = QColor(*self.mainTheme.colHeadH) + self.colDialN = QColor(*self.mainTheme.colDialN) + self.colDialD = QColor(*self.mainTheme.colDialD) + self.colDialS = QColor(*self.mainTheme.colDialS) + self.colHidden = QColor(*self.mainTheme.colHidden) + self.colKey = QColor(*self.mainTheme.colKey) + self.colVal = QColor(*self.mainTheme.colVal) + self.colSpell = QColor(*self.mainTheme.colSpell) + self.colError = QColor(*self.mainTheme.colError) + self.colRepTag = QColor(*self.mainTheme.colRepTag) + self.colMod = QColor(*self.mainTheme.colMod) + self.colBreak = QColor(*self.mainTheme.colEmph) self.colBreak.setAlpha(64) self.colEmph = None if self.mainConf.highlightEmph: - self.colEmph = QColor(*self.theTheme.colEmph) + self.colEmph = QColor(*self.mainTheme.colEmph) self.hStyles = { "header1": self._makeFormat(self.colHead, "bold", 1.8), @@ -287,9 +287,10 @@ class GuiDocHighlighter(QSyntaxHighlighter): if theText.startswith("@"): # Keywords and commands self.setCurrentBlockState(self.BLOCK_META) - tItem = self.theParent.theProject.projTree[self.theHandle] - isValid, theBits, thePos = self.theIndex.scanThis(theText) - isGood = self.theIndex.checkThese(theBits, tItem) + pIndex = self.theProject.index + tItem = self.mainGui.theProject.tree[self.theHandle] + isValid, theBits, thePos = pIndex.scanThis(theText) + isGood = pIndex.checkThese(theBits, tItem) if isValid: for n, theBit in enumerate(theBits): xPos = thePos[n] diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index 4ec59570..6ce275a3 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -30,17 +30,19 @@ along with this program. If not, see . import logging import novelwriter -from PyQt5.QtCore import Qt, QUrl, QSize, pyqtSlot +from enum import Enum + +from PyQt5.QtCore import Qt, QUrl, QSize, pyqtSlot, pyqtSignal from PyQt5.QtGui import ( QTextOption, QFont, QPalette, QColor, QTextCursor, QIcon, QCursor ) from PyQt5.QtWidgets import ( qApp, QTextBrowser, QWidget, QScrollArea, QLabel, QHBoxLayout, QToolButton, - QAction, QMenu + QAction, QMenu, QFrame ) from novelwriter.core import ToHtml -from novelwriter.enum import nwAlert, nwItemType, nwDocAction +from novelwriter.enum import nwItemType, nwDocAction, nwDocMode from novelwriter.error import logException from novelwriter.constants import nwUnicode @@ -49,16 +51,18 @@ logger = logging.getLogger(__name__) class GuiDocViewer(QTextBrowser): - def __init__(self, theParent): - QTextBrowser.__init__(self, theParent) + loadDocumentTagRequest = pyqtSignal(str, Enum) + + def __init__(self, mainGui): + QTextBrowser.__init__(self, mainGui) logger.debug("Initialising GuiDocViewer ...") # Class Variables self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject # Internal Variables self._docHandle = None @@ -68,6 +72,7 @@ class GuiDocViewer(QTextBrowser): self.setAutoFillBackground(True) self.setOpenExternalLinks(False) self.setFocusPolicy(Qt.StrongFocus) + self.setFrameStyle(QFrame.NoFrame) # Document Header and Footer self.docHeader = GuiDocViewHeader(self) @@ -113,14 +118,14 @@ class GuiDocViewer(QTextBrowser): # Set the widget colours to match syntax theme mainPalette = self.palette() - mainPalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - mainPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack)) - mainPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + mainPalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(mainPalette) docPalette = self.viewport().palette() - docPalette.setColor(QPalette.Base, QColor(*self.theTheme.colBack)) - docPalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + docPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + docPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.viewport().setPalette(docPalette) self.docHeader.matchColours() @@ -159,7 +164,7 @@ class GuiDocViewer(QTextBrowser): def loadText(self, tHandle, updateHistory=True): """Load text into the viewer from an item handle. """ - if not self.theProject.projTree.checkType(tHandle, nwItemType.FILE): + if not self.theProject.tree.checkType(tHandle, nwItemType.FILE): logger.warning("Item not found") return False @@ -216,7 +221,7 @@ class GuiDocViewer(QTextBrowser): self.updateDocMargins() # Make sure the main GUI knows we changed the content - self.theParent.viewMeta.refreshReferences(tHandle) + self.mainGui.viewMeta.refreshReferences(tHandle) # Since we change the content while it may still be rendering, we mark # the document dirty again to make sure it's re-rendered properly. @@ -238,30 +243,6 @@ class GuiDocViewer(QTextBrowser): self.updateDocMargins() return - def loadFromTag(self, theTag): - """Load text in the document from a reference given by a meta - tag rather than a known handle. This function depends on the - index being up to date. - """ - logger.debug("Loading document from tag '%s'", theTag) - tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag) - if tHandle is None: - self.theParent.makeAlert(self.tr( - "Could not find the reference for tag '{0}'. It either doesn't " - "exist, or the index is out of date. The index can be updated " - "from the Tools menu, or by pressing {1}." - ).format( - theTag, "F9" - ), nwAlert.ERROR) - return False - else: - # Let the parent handle the opening as it also ensures that - # the doc view panel is visible in case this request comes - # from outside this class. - logger.verbose("Tag points to '%s#%s'", tHandle, sTitle) - self.theParent.viewDocument(tHandle, "#%s" % sTitle) - return True - def docAction(self, theAction): """Wrapper function for various document actions on the current document. @@ -341,15 +322,6 @@ class GuiDocViewer(QTextBrowser): return - def updateDocInfo(self, tHandle): - """Called when an item label is changed to check if the document - title bar needs updating, - """ - if tHandle == self._docHandle: - self.docHeader.setTitleFromHandle(self._docHandle) - self.updateDocMargins() - return - ## # Properties ## @@ -408,19 +380,33 @@ class GuiDocViewer(QTextBrowser): return 0 ## - # Slots + # Public Slots + ## + + @pyqtSlot(str) + def updateDocInfo(self, tHandle): + """Called when an item label is changed to check if the document + title bar needs updating, + """ + if tHandle == self._docHandle: + self.docHeader.setTitleFromHandle(self._docHandle) + self.updateDocMargins() + return + + ## + # Private Slots ## @pyqtSlot("QUrl") def _linkClicked(self, theURL): - """Slot for a link in the document being clicked. + """Process a clicked link internally in the document. """ theLink = theURL.url() logger.verbose("Clicked link: '%s'", theLink) if len(theLink) > 0: theBits = theLink.split("=") if len(theBits) == 2: - self.loadFromTag(theBits[1]) + self.loadDocumentTagRequest.emit(theBits[1], nwDocMode.VIEW) return @pyqtSlot("QPoint") @@ -553,27 +539,27 @@ class GuiDocViewer(QTextBrowser): " text-align: center;" "}}\n" ).format( - tColR=self.theTheme.colText[0], - tColG=self.theTheme.colText[1], - tColB=self.theTheme.colText[2], - hColR=self.theTheme.colHead[0], - hColG=self.theTheme.colHead[1], - hColB=self.theTheme.colHead[2], - aColR=self.theTheme.colVal[0], - aColG=self.theTheme.colVal[1], - aColB=self.theTheme.colVal[2], - eColR=self.theTheme.colEmph[0], - eColG=self.theTheme.colEmph[1], - eColB=self.theTheme.colEmph[2], - kColR=self.theTheme.colKey[0], - kColG=self.theTheme.colKey[1], - kColB=self.theTheme.colKey[2], - cColR=self.theTheme.colHidden[0], - cColG=self.theTheme.colHidden[1], - cColB=self.theTheme.colHidden[2], - mColR=self.theTheme.colMod[0], - mColG=self.theTheme.colMod[1], - mColB=self.theTheme.colMod[2], + tColR=self.mainTheme.colText[0], + tColG=self.mainTheme.colText[1], + tColB=self.mainTheme.colText[2], + hColR=self.mainTheme.colHead[0], + hColG=self.mainTheme.colHead[1], + hColB=self.mainTheme.colHead[2], + aColR=self.mainTheme.colVal[0], + aColG=self.mainTheme.colVal[1], + aColB=self.mainTheme.colVal[2], + eColR=self.mainTheme.colEmph[0], + eColG=self.mainTheme.colEmph[1], + eColB=self.mainTheme.colEmph[2], + kColR=self.mainTheme.colKey[0], + kColG=self.mainTheme.colKey[1], + kColB=self.mainTheme.colKey[2], + cColR=self.mainTheme.colHidden[0], + cColG=self.mainTheme.colHidden[1], + cColB=self.mainTheme.colHidden[2], + mColR=self.mainTheme.colMod[0], + mColG=self.mainTheme.colMod[1], + mColB=self.mainTheme.colMod[2], ) self.document().setDefaultStyleSheet(styleSheet) @@ -728,14 +714,14 @@ class GuiDocViewHeader(QWidget): self.mainConf = novelwriter.CONFIG self.docViewer = docViewer - self.theParent = docViewer.theParent + self.mainGui = docViewer.mainGui self.theProject = docViewer.theProject - self.theTheme = docViewer.theTheme + self.mainTheme = docViewer.mainTheme # Internal Variables self._docHandle = None - fPx = int(0.9*self.theTheme.fontPixelSize) + fPx = int(0.9*self.mainTheme.fontPixelSize) hSp = self.mainConf.pxInt(6) # Main Widget Settings @@ -752,17 +738,17 @@ class GuiDocViewHeader(QWidget): self.theTitle.setFixedHeight(fPx) lblFont = self.theTitle.font() - lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) self.theTitle.setFont(lblFont) buttonStyle = ( "QToolButton {{border: none; background: transparent;}} " "QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" - ).format(*self.theTheme.colText) + ).format(*self.mainTheme.colText) # Buttons self.backButton = QToolButton(self) - self.backButton.setIcon(self.theTheme.getIcon("backward")) + self.backButton.setIcon(self.mainTheme.getIcon("backward")) self.backButton.setContentsMargins(0, 0, 0, 0) self.backButton.setIconSize(QSize(fPx, fPx)) self.backButton.setFixedSize(fPx, fPx) @@ -773,7 +759,7 @@ class GuiDocViewHeader(QWidget): self.backButton.clicked.connect(self.docViewer.navBackward) self.forwardButton = QToolButton(self) - self.forwardButton.setIcon(self.theTheme.getIcon("forward")) + self.forwardButton.setIcon(self.mainTheme.getIcon("forward")) self.forwardButton.setContentsMargins(0, 0, 0, 0) self.forwardButton.setIconSize(QSize(fPx, fPx)) self.forwardButton.setFixedSize(fPx, fPx) @@ -784,7 +770,7 @@ class GuiDocViewHeader(QWidget): self.forwardButton.clicked.connect(self.docViewer.navForward) self.refreshButton = QToolButton(self) - self.refreshButton.setIcon(self.theTheme.getIcon("refresh")) + self.refreshButton.setIcon(self.mainTheme.getIcon("refresh")) self.refreshButton.setContentsMargins(0, 0, 0, 0) self.refreshButton.setIconSize(QSize(fPx, fPx)) self.refreshButton.setFixedSize(fPx, fPx) @@ -795,7 +781,7 @@ class GuiDocViewHeader(QWidget): self.refreshButton.clicked.connect(self._refreshDocument) self.closeButton = QToolButton(self) - self.closeButton.setIcon(self.theTheme.getIcon("close")) + self.closeButton.setIcon(self.mainTheme.getIcon("close")) self.closeButton.setContentsMargins(0, 0, 0, 0) self.closeButton.setIconSize(QSize(fPx, fPx)) self.closeButton.setFixedSize(fPx, fPx) @@ -838,9 +824,9 @@ class GuiDocViewHeader(QWidget): theme rather than the main GUI. """ thePalette = QPalette() - thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText)) - thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + thePalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + thePalette.setColor(QPalette.WindowText, QColor(*self.mainTheme.colText)) + thePalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(thePalette) self.theTitle.setPalette(thePalette) @@ -862,15 +848,15 @@ class GuiDocViewHeader(QWidget): if self.mainConf.showFullPath: tTitle = [] - tTree = self.theProject.projTree.getItemPath(tHandle) + tTree = self.theProject.tree.getItemPath(tHandle) for aHandle in reversed(tTree): - nwItem = self.theProject.projTree[aHandle] + nwItem = self.theProject.tree[aHandle] if nwItem is not None: tTitle.append(nwItem.itemName) sSep = " %s " % nwUnicode.U_RSAQUO self.theTitle.setText(sSep.join(tTitle)) else: - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] if nwItem is None: return False self.theTitle.setText(nwItem.itemName) @@ -896,14 +882,14 @@ class GuiDocViewHeader(QWidget): def _closeDocument(self): """Trigger the close editor/viewer on the main window. """ - self.theParent.closeDocViewer() + self.mainGui.closeDocViewer() return def _refreshDocument(self): """Reload the content of the document. """ - if self.docViewer.docHandle() == self.theParent.docEditor.docHandle(): - self.theParent.saveDocument() + if self.docViewer.docHandle() == self.mainGui.docEditor.docHandle(): + self.mainGui.saveDocument() self.docViewer.reloadText() return @@ -915,7 +901,7 @@ class GuiDocViewHeader(QWidget): """Capture a click on the title and ensure that the item is selected in the project tree. """ - self.theParent.treeView.setSelectedHandle(self._docHandle, doScroll=True) + self.mainGui.projView.setSelectedHandle(self._docHandle, doScroll=True) return # END Class GuiDocViewHeader @@ -935,26 +921,26 @@ class GuiDocViewFooter(QWidget): self.mainConf = novelwriter.CONFIG self.docViewer = docViewer - self.theParent = docViewer.theParent - self.theTheme = docViewer.theTheme - self.viewMeta = docViewer.theParent.viewMeta + self.mainGui = docViewer.mainGui + self.mainTheme = docViewer.mainTheme + self.viewMeta = docViewer.mainGui.viewMeta # Internal Variables self._docHandle = None - fPx = int(0.9*self.theTheme.fontPixelSize) + fPx = int(0.9*self.mainTheme.fontPixelSize) bSp = self.mainConf.pxInt(2) hSp = self.mainConf.pxInt(8) # Icons - stickyOn = self.theTheme.getPixmap("sticky-on", (fPx, fPx)) - stickyOff = self.theTheme.getPixmap("sticky-off", (fPx, fPx)) + stickyOn = self.mainTheme.getPixmap("sticky-on", (fPx, fPx)) + stickyOff = self.mainTheme.getPixmap("sticky-off", (fPx, fPx)) stickyIcon = QIcon() stickyIcon.addPixmap(stickyOn, QIcon.Normal, QIcon.On) stickyIcon.addPixmap(stickyOff, QIcon.Normal, QIcon.Off) - bulletOn = self.theTheme.getPixmap("bullet-on", (fPx, fPx)) - bulletOff = self.theTheme.getPixmap("bullet-off", (fPx, fPx)) + bulletOn = self.mainTheme.getPixmap("bullet-on", (fPx, fPx)) + bulletOff = self.mainTheme.getPixmap("bullet-off", (fPx, fPx)) bulletIcon = QIcon() bulletIcon.addPixmap(bulletOn, QIcon.Normal, QIcon.On) bulletIcon.addPixmap(bulletOff, QIcon.Normal, QIcon.Off) @@ -966,13 +952,13 @@ class GuiDocViewFooter(QWidget): buttonStyle = ( "QToolButton {{border: none; background: transparent;}} " "QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" - ).format(*self.theTheme.colText) + ).format(*self.mainTheme.colText) # Show/Hide Details self.showHide = QToolButton(self) self.showHide.setToolButtonStyle(Qt.ToolButtonIconOnly) self.showHide.setStyleSheet(buttonStyle) - self.showHide.setIcon(self.theTheme.getIcon("reference")) + self.showHide.setIcon(self.mainTheme.getIcon("reference")) self.showHide.setIconSize(QSize(fPx, fPx)) self.showHide.setFixedSize(QSize(fPx, fPx)) self.showHide.clicked.connect(self._doShowHide) @@ -1053,7 +1039,7 @@ class GuiDocViewFooter(QWidget): self.lblSynopsis.setAlignment(Qt.AlignLeft | Qt.AlignTop) lblFont = self.font() - lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) self.lblRefs.setFont(lblFont) self.lblSticky.setFont(lblFont) self.lblComments.setFont(lblFont) @@ -1098,9 +1084,9 @@ class GuiDocViewFooter(QWidget): theme rather than the main GUI. """ thePalette = QPalette() - thePalette.setColor(QPalette.Window, QColor(*self.theTheme.colBack)) - thePalette.setColor(QPalette.WindowText, QColor(*self.theTheme.colText)) - thePalette.setColor(QPalette.Text, QColor(*self.theTheme.colText)) + thePalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + thePalette.setColor(QPalette.WindowText, QColor(*self.mainTheme.colText)) + thePalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) self.setPalette(thePalette) self.lblRefs.setPalette(thePalette) @@ -1154,14 +1140,14 @@ class GuiDocViewFooter(QWidget): class GuiDocViewDetails(QScrollArea): - def __init__(self, theParent): - QScrollArea.__init__(self, theParent) + def __init__(self, mainGui): + QScrollArea.__init__(self, mainGui) logger.debug("Initialising GuiDocViewDetails ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.theProject = mainGui.theProject + self.mainTheme = mainGui.mainTheme self.refList = QLabel("") self.refList.setWordWrap(True) @@ -1170,7 +1156,7 @@ class GuiDocViewDetails(QScrollArea): self.refList.linkActivated.connect(self._linkClicked) self.linkStyle = "style='color: rgb({0},{1},{2})'".format( - *self.theTheme.colLink + *self.mainTheme.colLink ) # Assemble @@ -1185,6 +1171,7 @@ class GuiDocViewDetails(QScrollArea): self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setWidgetResizable(True) self.setMinimumHeight(self.mainConf.pxInt(50)) + self.setFrameStyle(QFrame.NoFrame) logger.debug("GuiDocViewDetails initialisation complete") @@ -1194,13 +1181,13 @@ class GuiDocViewDetails(QScrollArea): """Update the current list of document references from the project index. """ - if self.theParent.docViewer.stickyRef: + if self.mainGui.docViewer.stickyRef: return - theRefs = self.theParent.theIndex.getBackReferenceList(tHandle) + theRefs = self.theProject.index.getBackReferenceList(tHandle) theList = [] for tHandle in theRefs: - tItem = self.theProject.projTree[tHandle] + tItem = self.theProject.tree[tHandle] if tItem is not None: theList.append("%s" % ( tHandle, theRefs[tHandle], self.linkStyle, tItem.itemName @@ -1222,7 +1209,7 @@ class GuiDocViewDetails(QScrollArea): if len(theLink) == 21: tHandle = theLink[:13] tAnchor = theLink[13:] - self.theParent.viewDocument(tHandle, tAnchor) + self.mainGui.viewDocument(tHandle, tAnchor) return # END Class GuiDocViewDetails diff --git a/novelwriter/gui/itemdetails.py b/novelwriter/gui/itemdetails.py index 0596f7a8..a467ed04 100644 --- a/novelwriter/gui/itemdetails.py +++ b/novelwriter/gui/itemdetails.py @@ -30,7 +30,6 @@ from PyQt5.QtCore import Qt, pyqtSlot from PyQt5.QtGui import QFont, QPixmap from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel -from novelwriter.enum import nwItemClass, nwItemType from novelwriter.constants import trConst, nwLabels logger = logging.getLogger(__name__) @@ -38,14 +37,14 @@ logger = logging.getLogger(__name__) class GuiItemDetails(QWidget): - def __init__(self, theParent): - QWidget.__init__(self, theParent) + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) logger.debug("Initialising GuiItemDetails ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.theProject = mainGui.theProject + self.mainTheme = mainGui.mainTheme # Internal Variables self._itemHandle = None @@ -54,11 +53,11 @@ class GuiItemDetails(QWidget): hSp = self.mainConf.pxInt(6) vSp = self.mainConf.pxInt(1) mPx = self.mainConf.pxInt(6) - iPx = self.theTheme.baseIconSize - fPt = self.theTheme.fontPointSize + iPx = self.mainTheme.baseIconSize + fPt = self.mainTheme.fontPointSize - self._expCheck = self.theTheme.getPixmap("check", (iPx, iPx)) - self._expCross = self.theTheme.getPixmap("cross", (iPx, iPx)) + self._expCheck = self.mainTheme.getPixmap("check", (iPx, iPx)) + self._expCross = self.mainTheme.getPixmap("cross", (iPx, iPx)) fntLabel = QFont() fntLabel.setBold(True) @@ -115,6 +114,7 @@ class GuiItemDetails(QWidget): self.usageData = QLabel("") self.usageData.setFont(fntValue) self.usageData.setAlignment(Qt.AlignLeft) + self.usageData.setWordWrap(True) # Character Count self.cCountName = QLabel(" "+self.tr("Characters")) @@ -180,8 +180,8 @@ class GuiItemDetails(QWidget): self.setLayout(self.mainBox) # Make sure the columns for flags and counts don't resize too often - flagWidth = self.theTheme.getTextWidth("Mm", fntValue) - countWidth = self.theTheme.getTextWidth("99,999", fntValue) + flagWidth = self.mainTheme.getTextWidth("Mm", fntValue) + countWidth = self.mainTheme.getTextWidth("99,999", fntValue) self.mainBox.setColumnMinimumWidth(1, flagWidth) self.mainBox.setColumnMinimumWidth(4, countWidth) @@ -214,6 +214,16 @@ class GuiItemDetails(QWidget): return + def refreshDetails(self): + """Reload the content of the details panel. + """ + self.updateViewBox(self._itemHandle) + + ## + # Public Slots + ## + + @pyqtSlot(str) def updateViewBox(self, tHandle): """Populate the details box from a given handle. """ @@ -221,13 +231,13 @@ class GuiItemDetails(QWidget): self.clearDetails() return - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] if nwItem is None: self.clearDetails() return self._itemHandle = tHandle - iPx = int(round(0.8*self.theTheme.baseIconSize)) + iPx = int(round(0.8*self.mainTheme.baseIconSize)) # Label # ===== @@ -236,7 +246,7 @@ class GuiItemDetails(QWidget): if len(theLabel) > 100: theLabel = theLabel[:96].rstrip()+" ..." - if nwItem.itemType == nwItemType.FILE: + if nwItem.isFileType(): if nwItem.isExported: self.labelIcon.setPixmap(self._expCheck) else: @@ -249,29 +259,22 @@ class GuiItemDetails(QWidget): # Status # ====== - itStatus = nwItem.itemStatus - if nwItem.itemClass == nwItemClass.NOVEL: - itStatus = self.theProject.statusItems.checkEntry(itStatus) # Make sure it's valid - flagIcon = self.theParent.statusIcons[itStatus] - else: - itStatus = self.theProject.importItems.checkEntry(itStatus) # Make sure it's valid - flagIcon = self.theParent.importIcons[itStatus] - - self.statusIcon.setPixmap(flagIcon.pixmap(iPx, iPx)) - self.statusData.setText(nwItem.itemStatus) + theStatus, theIcon = nwItem.getImportStatus() + self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx)) + self.statusData.setText(theStatus) # Class # ===== - classIcon = self.theTheme.getIcon(nwLabels.CLASS_ICON[nwItem.itemClass]) + classIcon = self.mainTheme.getIcon(nwLabels.CLASS_ICON[nwItem.itemClass]) self.classIcon.setPixmap(classIcon.pixmap(iPx, iPx)) self.classData.setText(trConst(nwLabels.CLASS_NAME[nwItem.itemClass])) # Layout # ====== - hLevel = self.theParent.theIndex.getHandleHeaderLevel(tHandle) - usageIcon = self.theTheme.getItemIcon( + hLevel = self.theProject.index.getHandleHeaderLevel(tHandle) + usageIcon = self.mainTheme.getItemIcon( nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel ) self.usageIcon.setPixmap(usageIcon.pixmap(iPx, iPx)) @@ -280,7 +283,7 @@ class GuiItemDetails(QWidget): # Counts # ====== - if nwItem.itemType == nwItemType.FILE: + if nwItem.isFileType(): self.cCountData.setText(f"{nwItem.charCount:n}") self.wCountData.setText(f"{nwItem.wordCount:n}") self.pCountData.setText(f"{nwItem.paraCount:n}") @@ -291,12 +294,8 @@ class GuiItemDetails(QWidget): return - ## - # Slots - ## - @pyqtSlot(str, int, int, int) - def doUpdateCounts(self, tHandle, cC, wC, pC): + def updateCounts(self, tHandle, cC, wC, pC): """Update the counts if the handle is the same as the one we're already showing. Otherwise, do nothing. """ diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 5f91eccc..59af7691 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -33,7 +33,7 @@ from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices from PyQt5.QtWidgets import QMenuBar, QAction -from novelwriter.enum import nwItemType, nwItemClass, nwDocAction, nwDocInsert, nwWidget +from novelwriter.enum import nwDocAction, nwDocInsert, nwWidget from novelwriter.constants import trConst, nwKeyWords, nwLabels, nwUnicode logger = logging.getLogger(__name__) @@ -41,13 +41,13 @@ logger = logging.getLogger(__name__) class GuiMainMenu(QMenuBar): - def __init__(self, theParent): - QMenuBar.__init__(self, theParent) + def __init__(self, mainGui): + QMenuBar.__init__(self, mainGui) logger.debug("Initialising GuiMainMenu ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject + self.mainGui = mainGui + self.theProject = mainGui.theProject # Build Menu self._buildProjectMenu() @@ -61,34 +61,14 @@ class GuiMainMenu(QMenuBar): self._buildHelpMenu() # Function Pointers - self._docAction = self.theParent.passDocumentAction - self._moveTreeItem = self.theParent.treeView.moveTreeItem - self._newTreeItem = self.theParent.treeView.newTreeItem - self._docInsert = self.theParent.docEditor.insertText - self._insertKeyWord = self.theParent.docEditor.insertKeyWord + self._docAction = self.mainGui.passDocumentAction + self._docInsert = self.mainGui.docEditor.insertText + self._insertKeyWord = self.mainGui.docEditor.insertKeyWord logger.debug("GuiMainMenu initialisation complete") return - ## - # Methods - ## - - def setAvailableRoot(self): - """Update the list of available root folders and set the ones - that are active. - """ - for itemClass in nwItemClass: - if itemClass == nwItemClass.NO_CLASS: - continue - if itemClass == nwItemClass.TRASH: - continue - self.rootItems[itemClass].setVisible( - self.theProject.projTree.checkRootUnique(itemClass) - ) - return - ## # Update Menu on Settings Changed ## @@ -99,12 +79,6 @@ class GuiMainMenu(QMenuBar): self.aSpellCheck.setChecked(theMode) return - def setAutoOutline(self, theMode): - """Forward auto outline check state to its action. - """ - self.aAutoOutline.setChecked(theMode) - return - def setFocusMode(self, theMode): """Forward focus mode check state to its action. """ @@ -120,13 +94,7 @@ class GuiMainMenu(QMenuBar): flag is handled by the document editor class, so we make no decision, just pass a None to the function and let it decide. """ - self.theParent.docEditor.toggleSpellCheck(None) - return True - - def _toggleAutoOutline(self, theMode): - """Toggle auto outline when the menu entry is checked. - """ - self.theProject.setAutoOutline(theMode) + self.mainGui.docEditor.toggleSpellCheck(None) return True def _openWebsite(self, theUrl): @@ -155,25 +123,25 @@ class GuiMainMenu(QMenuBar): # Project > New Project self.aNewProject = QAction(self.tr("New Project"), self) - self.aNewProject.triggered.connect(lambda: self.theParent.newProject(None)) + self.aNewProject.triggered.connect(lambda: self.mainGui.newProject(None)) self.projMenu.addAction(self.aNewProject) # Project > Open Project self.aOpenProject = QAction(self.tr("Open Project"), self) self.aOpenProject.setShortcut("Ctrl+Shift+O") - self.aOpenProject.triggered.connect(lambda: self.theParent.showProjectLoadDialog()) + self.aOpenProject.triggered.connect(lambda: self.mainGui.showProjectLoadDialog()) self.projMenu.addAction(self.aOpenProject) # Project > Save Project self.aSaveProject = QAction(self.tr("Save Project"), self) self.aSaveProject.setShortcut("Ctrl+Shift+S") - self.aSaveProject.triggered.connect(lambda: self.theParent.saveProject()) + self.aSaveProject.triggered.connect(lambda: self.mainGui.saveProject()) self.projMenu.addAction(self.aSaveProject) # Project > Close Project self.aCloseProject = QAction(self.tr("Close Project"), self) self.aCloseProject.setShortcut("Ctrl+Shift+W") - self.aCloseProject.triggered.connect(lambda: self.theParent.closeProject(False)) + self.aCloseProject.triggered.connect(lambda: self.mainGui.closeProject(False)) self.projMenu.addAction(self.aCloseProject) # Project > Separator @@ -182,78 +150,33 @@ class GuiMainMenu(QMenuBar): # Project > Project Settings self.aProjectSettings = QAction(self.tr("Project Settings"), self) self.aProjectSettings.setShortcut("Ctrl+Shift+,") - self.aProjectSettings.triggered.connect(lambda: self.theParent.showProjectSettingsDialog()) + self.aProjectSettings.triggered.connect(lambda: self.mainGui.showProjectSettingsDialog()) self.projMenu.addAction(self.aProjectSettings) # Project > Project Details self.aProjectDetails = QAction(self.tr("Project Details"), self) self.aProjectDetails.setShortcut("Shift+F6") - self.aProjectDetails.triggered.connect(lambda: self.theParent.showProjectDetailsDialog()) + self.aProjectDetails.triggered.connect(lambda: self.mainGui.showProjectDetailsDialog()) self.projMenu.addAction(self.aProjectDetails) # Project > Separator self.projMenu.addSeparator() - # Project > New Root - self.rootMenu = self.projMenu.addMenu(self.tr("Create Root Folder")) - self.rootItems = {} - self.rootItems[nwItemClass.NOVEL] = QAction(self.tr("Novel Root"), self.rootMenu) - self.rootItems[nwItemClass.PLOT] = QAction(self.tr("Plot Root"), self.rootMenu) - self.rootItems[nwItemClass.CHARACTER] = QAction(self.tr("Character Root"), self.rootMenu) - self.rootItems[nwItemClass.WORLD] = QAction(self.tr("Location Root"), self.rootMenu) - self.rootItems[nwItemClass.TIMELINE] = QAction(self.tr("Timeline Root"), self.rootMenu) - self.rootItems[nwItemClass.OBJECT] = QAction(self.tr("Object Root"), self.rootMenu) - self.rootItems[nwItemClass.ENTITY] = QAction(self.tr("Entity Root"), self.rootMenu) - self.rootItems[nwItemClass.CUSTOM] = QAction(self.tr("Custom Root"), self.rootMenu) - self.rootItems[nwItemClass.ARCHIVE] = QAction(self.tr("Archive Root"), self.rootMenu) - for n, itemClass in enumerate(self.rootItems.keys()): - self.rootItems[itemClass].triggered.connect( - lambda n, itemClass=itemClass: self._newTreeItem(nwItemType.ROOT, itemClass) - ) - self.rootMenu.addAction(self.rootItems[itemClass]) - - # Project > New Folder - self.aCreateFolder = QAction(self.tr("Create Folder"), self) - self.aCreateFolder.setShortcut("Ctrl+Shift+N") - self.aCreateFolder.triggered.connect(lambda: self._newTreeItem(nwItemType.FOLDER, None)) - self.projMenu.addAction(self.aCreateFolder) - - # Project > Separator - self.projMenu.addSeparator() - # Project > Edit - self.aEditItem = QAction(self.tr("Edit Item"), self) - self.aEditItem.setShortcuts(["Ctrl+E", "F2"]) - self.aEditItem.triggered.connect(lambda: self.theParent.editItem(None)) + self.aEditItem = QAction(self.tr("Rename Item"), self) + self.aEditItem.setShortcuts(["F2"]) + self.aEditItem.triggered.connect(lambda: self.mainGui.editItemLabel(None)) self.projMenu.addAction(self.aEditItem) # Project > Delete self.aDeleteItem = QAction(self.tr("Delete Item"), self) self.aDeleteItem.setShortcut("Ctrl+Shift+Del") - self.aDeleteItem.triggered.connect(lambda: self.theParent.treeView.deleteItem(None)) + self.aDeleteItem.triggered.connect(lambda: self.mainGui.projView.deleteItem(None)) self.projMenu.addAction(self.aDeleteItem) - # Project > Move Up - self.aMoveUp = QAction(self.tr("Move Item Up"), self) - self.aMoveUp.setShortcut("Ctrl+Up") - self.aMoveUp.triggered.connect(lambda: self._moveTreeItem(-1)) - self.projMenu.addAction(self.aMoveUp) - - # Project > Move Down - self.aMoveDown = QAction(self.tr("Move Item Down"), self) - self.aMoveDown.setShortcut("Ctrl+Down") - self.aMoveDown.triggered.connect(lambda: self._moveTreeItem(1)) - self.projMenu.addAction(self.aMoveDown) - - # Project > Undo Last Action - self.aMoveUndo = QAction(self.tr("Undo Last Move"), self) - self.aMoveUndo.setShortcut("Ctrl+Shift+Z") - self.aMoveUndo.triggered.connect(lambda: self.theParent.treeView.undoLastMove()) - self.projMenu.addAction(self.aMoveUndo) - # Project > Empty Trash self.aEmptyTrash = QAction(self.tr("Empty Trash"), self) - self.aEmptyTrash.triggered.connect(lambda: self.theParent.treeView.emptyTrash()) + self.aEmptyTrash.triggered.connect(lambda: self.mainGui.projView.emptyTrash()) self.projMenu.addAction(self.aEmptyTrash) # Project > Separator @@ -263,7 +186,7 @@ class GuiMainMenu(QMenuBar): self.aExitNW = QAction(self.tr("Exit"), self) self.aExitNW.setShortcut("Ctrl+Q") self.aExitNW.setMenuRole(QAction.QuitRole) - self.aExitNW.triggered.connect(lambda: self.theParent.closeMain()) + self.aExitNW.triggered.connect(lambda: self.mainGui.closeMain()) self.projMenu.addAction(self.aExitNW) return @@ -274,28 +197,22 @@ class GuiMainMenu(QMenuBar): # Document self.docuMenu = self.addMenu(self.tr("&Document")) - # Document > New - self.aNewDoc = QAction(self.tr("New Document"), self) - self.aNewDoc.setShortcut("Ctrl+N") - self.aNewDoc.triggered.connect(lambda: self._newTreeItem(nwItemType.FILE, None)) - self.docuMenu.addAction(self.aNewDoc) - # Document > Open self.aOpenDoc = QAction(self.tr("Open Document"), self) self.aOpenDoc.setShortcut("Ctrl+O") - self.aOpenDoc.triggered.connect(lambda: self.theParent.openSelectedItem()) + self.aOpenDoc.triggered.connect(lambda: self.mainGui.openSelectedItem()) self.docuMenu.addAction(self.aOpenDoc) # Document > Save self.aSaveDoc = QAction(self.tr("Save Document"), self) self.aSaveDoc.setShortcut("Ctrl+S") - self.aSaveDoc.triggered.connect(lambda: self.theParent.saveDocument()) + self.aSaveDoc.triggered.connect(lambda: self.mainGui.saveDocument()) self.docuMenu.addAction(self.aSaveDoc) # Document > Close self.aCloseDoc = QAction(self.tr("Close Document"), self) self.aCloseDoc.setShortcut("Ctrl+W") - self.aCloseDoc.triggered.connect(lambda: self.theParent.closeDocEditor()) + self.aCloseDoc.triggered.connect(lambda: self.mainGui.closeDocEditor()) self.docuMenu.addAction(self.aCloseDoc) # Document > Separator @@ -304,13 +221,13 @@ class GuiMainMenu(QMenuBar): # Document > Preview self.aViewDoc = QAction(self.tr("View Document"), self) self.aViewDoc.setShortcut("Ctrl+R") - self.aViewDoc.triggered.connect(lambda: self.theParent.viewDocument(None)) + self.aViewDoc.triggered.connect(lambda: self.mainGui.viewDocument(None)) self.docuMenu.addAction(self.aViewDoc) # Document > Close Preview self.aCloseView = QAction(self.tr("Close Document View"), self) self.aCloseView.setShortcut("Ctrl+Shift+R") - self.aCloseView.triggered.connect(lambda: self.theParent.closeDocViewer()) + self.aCloseView.triggered.connect(lambda: self.mainGui.closeDocViewer()) self.docuMenu.addAction(self.aCloseView) # Document > Separator @@ -318,23 +235,23 @@ class GuiMainMenu(QMenuBar): # Document > Show File Details self.aFileDetails = QAction(self.tr("Show File Details"), self) - self.aFileDetails.triggered.connect(lambda: self.theParent.docEditor.revealLocation()) + self.aFileDetails.triggered.connect(lambda: self.mainGui.docEditor.revealLocation()) self.docuMenu.addAction(self.aFileDetails) # Document > Import From File self.aImportFile = QAction(self.tr("Import Text from File"), self) self.aImportFile.setShortcut("Ctrl+Shift+I") - self.aImportFile.triggered.connect(lambda: self.theParent.importDocument()) + self.aImportFile.triggered.connect(lambda: self.mainGui.importDocument()) self.docuMenu.addAction(self.aImportFile) # Document > Merge Documents self.aMergeDocs = QAction(self.tr("Merge Folder to Document"), self) - self.aMergeDocs.triggered.connect(lambda: self.theParent.mergeDocuments()) + self.aMergeDocs.triggered.connect(lambda: self.mainGui.mergeDocuments()) self.docuMenu.addAction(self.aMergeDocs) # Document > Split Document self.aSplitDoc = QAction(self.tr("Split Document to Folder"), self) - self.aSplitDoc.triggered.connect(lambda: self.theParent.splitDocument()) + self.aSplitDoc.triggered.connect(lambda: self.mainGui.splitDocument()) self.docuMenu.addAction(self.aSplitDoc) return @@ -407,7 +324,7 @@ class GuiMainMenu(QMenuBar): self.aFocusTree.setShortcut("Ctrl+Alt+1") else: self.aFocusTree.setShortcut("Alt+1") - self.aFocusTree.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.TREE)) + self.aFocusTree.triggered.connect(lambda: self.mainGui.switchFocus(nwWidget.TREE)) self.viewMenu.addAction(self.aFocusTree) # View > Document Pane 1 @@ -416,7 +333,7 @@ class GuiMainMenu(QMenuBar): self.aFocusEditor.setShortcut("Ctrl+Alt+2") else: self.aFocusEditor.setShortcut("Alt+2") - self.aFocusEditor.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.EDITOR)) + self.aFocusEditor.triggered.connect(lambda: self.mainGui.switchFocus(nwWidget.EDITOR)) self.viewMenu.addAction(self.aFocusEditor) # View > Document Pane 2 @@ -425,7 +342,7 @@ class GuiMainMenu(QMenuBar): self.aFocusView.setShortcut("Ctrl+Alt+3") else: self.aFocusView.setShortcut("Alt+3") - self.aFocusView.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.VIEWER)) + self.aFocusView.triggered.connect(lambda: self.mainGui.switchFocus(nwWidget.VIEWER)) self.viewMenu.addAction(self.aFocusView) # View > Outline @@ -434,7 +351,7 @@ class GuiMainMenu(QMenuBar): self.aFocusOutline.setShortcut("Ctrl+Alt+4") else: self.aFocusOutline.setShortcut("Alt+4") - self.aFocusOutline.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.OUTLINE)) + self.aFocusOutline.triggered.connect(lambda: self.mainGui.switchFocus(nwWidget.OUTLINE)) self.viewMenu.addAction(self.aFocusOutline) # View > Separator @@ -443,13 +360,13 @@ class GuiMainMenu(QMenuBar): # View > Go Backward self.aViewPrev = QAction(self.tr("Navigate Backward"), self) self.aViewPrev.setShortcut("Alt+Left") - self.aViewPrev.triggered.connect(lambda: self.theParent.docViewer.navBackward()) + self.aViewPrev.triggered.connect(lambda: self.mainGui.docViewer.navBackward()) self.viewMenu.addAction(self.aViewPrev) # View > Go Forward self.aViewNext = QAction(self.tr("Navigate Forward"), self) self.aViewNext.setShortcut("Alt+Right") - self.aViewNext.triggered.connect(lambda: self.theParent.docViewer.navForward()) + self.aViewNext.triggered.connect(lambda: self.mainGui.docViewer.navForward()) self.viewMenu.addAction(self.aViewNext) # View > Separator @@ -459,14 +376,14 @@ class GuiMainMenu(QMenuBar): self.aFocusMode = QAction(self.tr("Focus Mode"), self) self.aFocusMode.setShortcut("F8") self.aFocusMode.setCheckable(True) - self.aFocusMode.setChecked(self.theParent.isFocusMode) - self.aFocusMode.triggered.connect(lambda: self.theParent.toggleFocusMode()) + self.aFocusMode.setChecked(self.mainGui.isFocusMode) + self.aFocusMode.triggered.connect(lambda: self.mainGui.toggleFocusMode()) self.viewMenu.addAction(self.aFocusMode) # View > Toggle Full Screen self.aFullScreen = QAction(self.tr("Full Screen Mode"), self) self.aFullScreen.setShortcut("F11") - self.aFullScreen.triggered.connect(lambda: self.theParent.toggleFullScreenMode()) + self.aFullScreen.triggered.connect(lambda: self.mainGui.toggleFullScreenMode()) self.viewMenu.addAction(self.aFullScreen) return @@ -669,6 +586,11 @@ class GuiMainMenu(QMenuBar): self.aInsVSpaceM.triggered.connect(lambda: self._docInsert(nwDocInsert.VSPACE_M)) self.mInsBreaks.addAction(self.aInsVSpaceM) + # Insert > Placeholder Text + self.aLipsumText = QAction(self.tr("Placeholder Text"), self) + self.aLipsumText.triggered.connect(lambda: self.mainGui.showLoremIpsumDialog()) + self.insertMenu.addAction(self.aLipsumText) + return def _buildFormatMenu(self): @@ -830,7 +752,7 @@ class GuiMainMenu(QMenuBar): # Search > Find self.aFind = QAction(self.tr("Find"), self) self.aFind.setShortcut("Ctrl+F") - self.aFind.triggered.connect(lambda: self.theParent.docEditor.beginSearch()) + self.aFind.triggered.connect(lambda: self.mainGui.docEditor.beginSearch()) self.srcMenu.addAction(self.aFind) # Search > Replace @@ -839,7 +761,7 @@ class GuiMainMenu(QMenuBar): self.aReplace.setShortcut("Ctrl+=") else: self.aReplace.setShortcut("Ctrl+H") - self.aReplace.triggered.connect(lambda: self.theParent.docEditor.beginReplace()) + self.aReplace.triggered.connect(lambda: self.mainGui.docEditor.beginReplace()) self.srcMenu.addAction(self.aReplace) # Search > Find Next @@ -848,7 +770,7 @@ class GuiMainMenu(QMenuBar): self.aFindNext.setShortcuts(["Ctrl+G", "F3"]) else: self.aFindNext.setShortcuts(["F3", "Ctrl+G"]) - self.aFindNext.triggered.connect(lambda: self.theParent.docEditor.findNext()) + self.aFindNext.triggered.connect(lambda: self.mainGui.docEditor.findNext()) self.srcMenu.addAction(self.aFindNext) # Search > Find Prev @@ -857,13 +779,13 @@ class GuiMainMenu(QMenuBar): self.aFindPrev.setShortcuts(["Ctrl+Shift+G", "Shift+F3"]) else: self.aFindPrev.setShortcuts(["Shift+F3", "Ctrl+Shift+G"]) - self.aFindPrev.triggered.connect(lambda: self.theParent.docEditor.findNext(goBack=True)) + self.aFindPrev.triggered.connect(lambda: self.mainGui.docEditor.findNext(goBack=True)) self.srcMenu.addAction(self.aFindPrev) # Search > Replace Next self.aReplaceNext = QAction(self.tr("Replace Next"), self) self.aReplaceNext.setShortcut("Ctrl+Shift+1") - self.aReplaceNext.triggered.connect(lambda: self.theParent.docEditor.replaceNext()) + self.aReplaceNext.triggered.connect(lambda: self.mainGui.docEditor.replaceNext()) self.srcMenu.addAction(self.aReplaceNext) return @@ -885,12 +807,12 @@ class GuiMainMenu(QMenuBar): # Tools > Re-Run Spell Check self.aReRunSpell = QAction(self.tr("Re-Run Spell Check"), self) self.aReRunSpell.setShortcut("F7") - self.aReRunSpell.triggered.connect(lambda: self.theParent.docEditor.spellCheckDocument()) + self.aReRunSpell.triggered.connect(lambda: self.mainGui.docEditor.spellCheckDocument()) self.toolsMenu.addAction(self.aReRunSpell) # Tools > Project Word List self.aEditWordList = QAction(self.tr("Project Word List"), self) - self.aEditWordList.triggered.connect(lambda: self.theParent.showProjectWordListDialog()) + self.aEditWordList.triggered.connect(lambda: self.mainGui.showProjectWordListDialog()) self.toolsMenu.addAction(self.aEditWordList) # Tools > Separator @@ -899,22 +821,9 @@ class GuiMainMenu(QMenuBar): # Tools > Rebuild Indices self.aRebuildIndex = QAction(self.tr("Rebuild Index"), self) self.aRebuildIndex.setShortcut("F9") - self.aRebuildIndex.triggered.connect(lambda: self.theParent.rebuildIndex()) + self.aRebuildIndex.triggered.connect(lambda: self.mainGui.rebuildIndex()) self.toolsMenu.addAction(self.aRebuildIndex) - # Tools > Rebuild Outline - self.aRebuildOutline = QAction(self.tr("Rebuild Outline"), self) - self.aRebuildOutline.setShortcut("F10") - self.aRebuildOutline.triggered.connect(lambda: self.theParent.rebuildOutline()) - self.toolsMenu.addAction(self.aRebuildOutline) - - # Tools > Toggle Auto Build Outline - self.aAutoOutline = QAction(self.tr("Auto-Update Outline"), self) - self.aAutoOutline.setCheckable(True) - self.aAutoOutline.toggled.connect(self._toggleAutoOutline) - self.aAutoOutline.setShortcut("Ctrl+F10") - self.toolsMenu.addAction(self.aAutoOutline) - # Tools > Separator self.toolsMenu.addSeparator() @@ -926,20 +835,20 @@ class GuiMainMenu(QMenuBar): # Tools > Export Project self.aBuildProject = QAction(self.tr("Build Novel Project"), self) self.aBuildProject.setShortcut("F5") - self.aBuildProject.triggered.connect(lambda: self.theParent.showBuildProjectDialog()) + self.aBuildProject.triggered.connect(lambda: self.mainGui.showBuildProjectDialog()) self.toolsMenu.addAction(self.aBuildProject) # Tools > Writing Stats self.aWritingStats = QAction(self.tr("Writing Statistics"), self) self.aWritingStats.setShortcut("F6") - self.aWritingStats.triggered.connect(lambda: self.theParent.showWritingStatsDialog()) + self.aWritingStats.triggered.connect(lambda: self.mainGui.showWritingStatsDialog()) self.toolsMenu.addAction(self.aWritingStats) # Tools > Settings self.aPreferences = QAction(self.tr("Preferences"), self) self.aPreferences.setShortcut("Ctrl+,") self.aPreferences.setMenuRole(QAction.PreferencesRole) - self.aPreferences.triggered.connect(lambda: self.theParent.showPreferencesDialog()) + self.aPreferences.triggered.connect(lambda: self.mainGui.showPreferencesDialog()) self.toolsMenu.addAction(self.aPreferences) return @@ -953,13 +862,13 @@ class GuiMainMenu(QMenuBar): # Help > About self.aAboutNW = QAction(self.tr("About novelWriter"), self) self.aAboutNW.setMenuRole(QAction.AboutRole) - self.aAboutNW.triggered.connect(lambda: self.theParent.showAboutNWDialog()) + self.aAboutNW.triggered.connect(lambda: self.mainGui.showAboutNWDialog()) self.helpMenu.addAction(self.aAboutNW) # Help > About Qt5 self.aAboutQt = QAction(self.tr("About Qt5"), self) self.aAboutQt.setMenuRole(QAction.AboutQtRole) - self.aAboutQt.triggered.connect(lambda: self.theParent.showAboutQtDialog()) + self.aAboutQt.triggered.connect(lambda: self.mainGui.showAboutQtDialog()) self.helpMenu.addAction(self.aAboutQt) # Help > Separator @@ -1006,7 +915,7 @@ class GuiMainMenu(QMenuBar): # Document > Check for Updates self.aUpdates = QAction(self.tr("Check for New Release"), self) - self.aUpdates.triggered.connect(lambda: self.theParent.showUpdatesDialog()) + self.aUpdates.triggered.connect(lambda: self.mainGui.showUpdatesDialog()) self.helpMenu.addAction(self.aUpdates) return diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index 0f7ac02f..c8d88b88 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -4,7 +4,9 @@ novelWriter – GUI Novel Tree GUI classe for the main window novel tree File History: -Created: 2020-12-20 [1.1a0] +Created: 2020-12-20 [1.1a0] GuiNovelTree +Created: 2022-06-12 [1.7b1] GuiNovelView +Created: 2022-06-12 [1.7b1] GuiNovelToolBar This file is a part of novelWriter Copyright 2018–2020, Veronica Berglyd Olsen @@ -26,82 +28,390 @@ along with this program. If not, see . import logging import novelwriter +from enum import Enum from time import time -from PyQt5.QtCore import Qt, QSize -from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView +from PyQt5.QtGui import QPalette +from PyQt5.QtCore import Qt, QSize, pyqtSlot, pyqtSignal +from PyQt5.QtWidgets import ( + QAbstractItemView, QActionGroup, QFrame, QHBoxLayout, QHeaderView, QLabel, + QMenu, QSizePolicy, QToolButton, QToolTip, QTreeWidget, QTreeWidgetItem, + QVBoxLayout, QWidget +) +from novelwriter.enum import nwDocMode, nwItemClass, nwOutline from novelwriter.common import checkInt -from novelwriter.constants import nwKeyWords +from novelwriter.constants import nwHeaders, nwKeyWords, nwLabels, trConst logger = logging.getLogger(__name__) +class NovelTreeColumn(Enum): + + HIDDEN = 0 + POV = 1 + FOCUS = 2 + PLOT = 3 + +# END Enum NovelTreeColumn + + +class GuiNovelView(QWidget): + + # Signals for user interaction with the novel tree + selectedItemChanged = pyqtSignal(str) + openDocumentRequest = pyqtSignal(str, Enum, int, str) + + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) + + self.mainGui = mainGui + self.theProject = mainGui.theProject + + # Build GUI + self.novelBar = GuiNovelToolBar(self) + self.novelTree = GuiNovelTree(self) + + # Assemble + self.outerBox = QVBoxLayout() + self.outerBox.addWidget(self.novelBar, 0) + self.outerBox.addWidget(self.novelTree, 1) + self.outerBox.setContentsMargins(0, 0, 0, 0) + self.outerBox.setSpacing(0) + + self.setLayout(self.outerBox) + + # Function Mappings + self.updateWordCounts = self.novelTree.updateWordCounts + self.getSelectedHandle = self.novelTree.getSelectedHandle + self.setActiveHandle = self.novelTree.setActiveHandle + + return + + ## + # Methods + ## + + def initSettings(self): + """Initialise GUI elements that depend on specific settings. + """ + self.novelTree.initSettings() + return + + def refreshTree(self): + """Refresh the current tree. + """ + self.novelTree.refreshTree(rootHandle=self.theProject.lastNovel) + return + + def clearProject(self): + """Clear project-related GUI content. + """ + self.novelTree.clearContent() + self.novelBar.clearContent() + return + + def openProjectTasks(self): + """Run open project tasks. + """ + lastNovel = self.theProject.lastNovel + if lastNovel not in self.theProject.tree: + lastNovel = self.theProject.tree.findRoot(nwItemClass.NOVEL) + + logger.debug("Setting novel tree to root item '%s'", lastNovel) + + lastCol = self.theProject.options.getEnum( + "GuiNovelView", "lastCol", NovelTreeColumn, NovelTreeColumn.HIDDEN + ) + + self.clearProject() + self.novelBar.buildNovelRootMenu() + self.novelBar.setLastColType(lastCol, doRefresh=False) + self.novelBar.setCurrentRoot(lastNovel) + + return + + def closeProjectTasks(self): + """Run closing project tasks. + """ + lastColType = self.novelTree.lastColType + self.theProject.options.setValue("GuiNovelView", "lastCol", lastColType) + return + + def setTreeFocus(self): + """Set the focus to the tree widget. + """ + self.novelTree.setFocus() + return + + def treeHasFocus(self): + """Check if the novel tree has focus. + """ + return self.novelTree.hasFocus() + + ## + # Public Slots + ## + + @pyqtSlot(str) + def updateRootItem(self, tHandle): + """If any root item changes, rebuild the novel root menu. + """ + self.novelBar.buildNovelRootMenu() + return + +# END Class GuiNovelView + + +class GuiNovelToolBar(QWidget): + + def __init__(self, novelView): + QTreeWidget.__init__(self, novelView) + + logger.debug("Initialising GuiNovelToolBar ...") + + self.mainConf = novelwriter.CONFIG + self.novelView = novelView + self.theProject = novelView.mainGui.theProject + self.mainTheme = novelView.mainGui.mainTheme + + iPx = self.mainTheme.baseIconSize + mPx = self.mainConf.pxInt(2) + + self.setContentsMargins(0, 0, 0, 0) + self.setAutoFillBackground(True) + + qPalette = self.palette() + qPalette.setBrush(QPalette.Window, qPalette.base()) + self.setPalette(qPalette) + + fadeCol = qPalette.text().color() + buttonStyle = ( + "QToolButton {{padding: {0}px; border: none; background: transparent;}} " + "QToolButton:hover {{border: none; background: rgba({1},{2},{3},0.2);}}" + ).format(mPx, fadeCol.red(), fadeCol.green(), fadeCol.blue()) + + # Widget Label + self.viewLabel = QLabel("%s" % self.tr("Novel Outline")) + self.viewLabel.setContentsMargins(0, 0, 0, 0) + self.viewLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + + # Refresh Button + self.tbRefresh = QToolButton(self) + self.tbRefresh.setToolTip(self.tr("Refresh")) + self.tbRefresh.setIcon(self.mainTheme.getIcon("refresh")) + self.tbRefresh.setIconSize(QSize(iPx, iPx)) + self.tbRefresh.setStyleSheet(buttonStyle) + self.tbRefresh.clicked.connect(self._refreshNovelTree) + + # Novel Root Menu + self.mRoot = QMenu() + self.gRoot = QActionGroup(self.mRoot) + self.aRoot = {} + + self.tbRoot = QToolButton(self) + self.tbRoot.setToolTip(self.tr("Novel Root")) + self.tbRoot.setIcon(self.mainTheme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL])) + self.tbRoot.setIconSize(QSize(iPx, iPx)) + self.tbRoot.setStyleSheet(buttonStyle) + self.tbRoot.setMenu(self.mRoot) + self.tbRoot.setPopupMode(QToolButton.InstantPopup) + + # More Options Menu + self.mMore = QMenu() + + self.mLastCol = self.mMore.addMenu(self.tr("Last Column")) + self.gLastCol = QActionGroup(self.mMore) + self.aLastCol = {} + self._addLastColAction(NovelTreeColumn.HIDDEN, self.tr("Hidden")) + self._addLastColAction(NovelTreeColumn.POV, self.tr("Point of View Character")) + self._addLastColAction(NovelTreeColumn.FOCUS, self.tr("Focus Character")) + self._addLastColAction(NovelTreeColumn.PLOT, self.tr("Novel Plot")) + + self.tbMore = QToolButton(self) + self.tbMore.setToolTip(self.tr("More Options")) + self.tbMore.setIcon(self.mainTheme.getIcon("menu")) + self.tbMore.setIconSize(QSize(iPx, iPx)) + self.tbMore.setStyleSheet(buttonStyle) + self.tbMore.setMenu(self.mMore) + self.tbMore.setPopupMode(QToolButton.InstantPopup) + + # Assemble + self.outerBox = QHBoxLayout() + self.outerBox.addWidget(self.viewLabel) + self.outerBox.addWidget(self.tbRefresh) + self.outerBox.addWidget(self.tbRoot) + self.outerBox.addWidget(self.tbMore) + self.outerBox.setContentsMargins(mPx, mPx, 0, mPx) + self.outerBox.setSpacing(0) + + self.setLayout(self.outerBox) + + logger.debug("GuiNovelToolBar initialisation complete") + + return + + ## + # Methods + ## + + def clearContent(self): + """Run clearing project tasks. + """ + self.mRoot.clear() + self.aRoot = {} + return + + def buildNovelRootMenu(self): + """Build the novel root menu. + """ + self.mRoot.clear() + self.aRoot = {} + for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(nwItemClass.NOVEL)): + aRoot = self.mRoot.addAction(nwItem.itemName) + aRoot.setData(tHandle) + aRoot.setCheckable(True) + aRoot.triggered.connect(lambda n, tHandle=tHandle: self.setCurrentRoot(tHandle)) + self.gRoot.addAction(aRoot) + self.aRoot[tHandle] = aRoot + + return + + def setCurrentRoot(self, rootHandle): + """Set the current active root handle. + """ + if rootHandle in self.aRoot: + self.aRoot[rootHandle].setChecked(True) + self.novelView.novelTree.refreshTree(rootHandle=rootHandle, overRide=True) + return + + def setLastColType(self, colType, doRefresh=True): + """Set the last column type. + """ + self.aLastCol[colType].setChecked(True) + self.novelView.novelTree.setLastColType(colType, doRefresh=doRefresh) + return + + ## + # Private Slots + ## + + @pyqtSlot() + def _refreshNovelTree(self): + """Rebuild the current tree. + """ + rootHandle = self.theProject.lastNovel + self.novelView.novelTree.refreshTree(rootHandle=rootHandle, overRide=True) + return + + ## + # Internal Functions + ## + + def _addLastColAction(self, colType, actionLabel): + """Add a column selection entry to the last column menu. + """ + aLast = self.mLastCol.addAction(actionLabel) + aLast.setCheckable(True) + aLast.setActionGroup(self.gLastCol) + aLast.triggered.connect(lambda: self.setLastColType(colType)) + self.aLastCol[colType] = aLast + return + +# END Class GuiNovelToolBar + + class GuiNovelTree(QTreeWidget): C_TITLE = 0 C_WORDS = 1 - C_POV = 2 + C_EXTRA = 2 + C_MORE = 3 - def __init__(self, theParent): - QTreeWidget.__init__(self, theParent) + D_HANDLE = Qt.UserRole + D_TITLE = Qt.UserRole + 1 + D_KEY = Qt.UserRole + 2 + + def __init__(self, novelView): + QTreeWidget.__init__(self, novelView) logger.debug("Initialising GuiNovelTree ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject - self.theIndex = theParent.theIndex + self.novelView = novelView + self.mainGui = novelView.mainGui + self.mainTheme = novelView.mainGui.mainTheme + self.theProject = novelView.mainGui.theProject # Internal Variables self._treeMap = {} self._lastBuild = 0 + self._lastCol = NovelTreeColumn.POV + self._actHandle = None + + # Cached Strings + self._povLabel = trConst(nwLabels.KEY_NAME[nwKeyWords.POV_KEY]) + self._focLabel = trConst(nwLabels.KEY_NAME[nwKeyWords.FOCUS_KEY]) + self._pltLabel = trConst(nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY]) # Build GUI - iPx = self.theTheme.baseIconSize + # ========= + + iPx = self.mainTheme.baseIconSize + cMg = self.mainConf.pxInt(6) + self.setIconSize(QSize(iPx, iPx)) - self.setIndentation(iPx) - self.setColumnCount(3) - self.setHeaderLabels([ - self.tr("Novel Outline"), - self.tr("Words"), - self.tr("POV") - ]) - self.itemDoubleClicked.connect(self._treeDoubleClick) - self.itemSelectionChanged.connect(self._itemSelected) + self.setFrameStyle(QFrame.NoFrame) + self.setUniformRowHeights(True) + self.setAllColumnsShowFocus(True) + self.setHeaderHidden(True) + self.setIndentation(0) + self.setColumnCount(4) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setSelectionMode(QAbstractItemView.SingleSelection) self.setExpandsOnDoubleClick(False) self.setDragEnabled(False) - treeHeadItem = self.headerItem() - treeHeadItem.setTextAlignment(self.C_WORDS, Qt.AlignRight) - treeHeadItem.setToolTip(self.C_TITLE, self.tr("Section title")) - treeHeadItem.setToolTip(self.C_WORDS, self.tr("Word count")) - treeHeadItem.setToolTip(self.C_POV, self.tr("Point-of-view character")) - + # Lock the column sizes treeHeader = self.header() - treeHeader.setStretchLastSection(True) - treeHeader.setMinimumSectionSize(iPx + 6) + treeHeader.setStretchLastSection(False) + treeHeader.setMinimumSectionSize(iPx + cMg) + treeHeader.setSectionResizeMode(self.C_TITLE, QHeaderView.Stretch) + treeHeader.setSectionResizeMode(self.C_WORDS, QHeaderView.ResizeToContents) + treeHeader.setSectionResizeMode(self.C_EXTRA, QHeaderView.ResizeToContents) + treeHeader.setSectionResizeMode(self.C_MORE, QHeaderView.ResizeToContents) - # Get user's column width preferences for NAME and COUNT - treeColWidth = self.mainConf.getNovelColWidths() - if len(treeColWidth) <= 3: - for colN, colW in enumerate(treeColWidth): - self.setColumnWidth(colN, colW) + # Pre-Generate Tree Formatting + fH1 = self.font() + fH1.setBold(True) + fH1.setUnderline(True) - # The last column should just auto-scale - self.resizeColumnToContents(self.C_POV) + fH2 = self.font() + fH2.setBold(True) + + self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()] + self._pIndent = [ + self.mainTheme.loadDecoration("deco_doc_h0", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h1", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h2", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h3", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h4", pxH=iPx), + ] + self._pMore = self.mainTheme.loadDecoration("deco_doc_more", pxH=iPx) + + # Connect signals + self.clicked.connect(self._treeItemClicked) + self.itemDoubleClicked.connect(self._treeDoubleClick) + self.itemSelectionChanged.connect(self._treeSelectionChange) # Set custom settings - self.initTree() + self.initSettings() logger.debug("GuiNovelTree initialisation complete") return - def initTree(self): + def initSettings(self): """Set or update tree widget settings. """ # Scroll bars @@ -117,11 +427,19 @@ class GuiNovelTree(QTreeWidget): return + ## + # Properties + ## + + @property + def lastColType(self): + return self._lastCol + ## # Class Methods ## - def clearTree(self): + def clearContent(self): """Clear the GUI content and the related maps. """ self.clear() @@ -129,12 +447,15 @@ class GuiNovelTree(QTreeWidget): self._lastBuild = 0 return - def refreshTree(self, overRide=False): + def refreshTree(self, rootHandle=None, overRide=False): """Called whenever the Novel tab is activated. """ logger.verbose("Requesting refresh of the novel tree") - treeChanged = self.theParent.treeView.changedSince(self._lastBuild) - indexChanged = self.theIndex.novelChangedSince(self._lastBuild) + if rootHandle is None: + rootHandle = self.theProject.tree.findRoot(nwItemClass.NOVEL) + + treeChanged = self.mainGui.projView.changedSince(self._lastBuild) + indexChanged = self.theProject.index.rootChangedSince(rootHandle, self._lastBuild) if not (treeChanged or indexChanged or overRide): logger.verbose("No changes have been made to the novel index") return @@ -142,10 +463,10 @@ class GuiNovelTree(QTreeWidget): selItem = self.selectedItems() titleKey = None if selItem: - titleKey = selItem[0].data(self.C_TITLE, Qt.UserRole)[2] + titleKey = selItem[0].data(self.C_TITLE, self.D_KEY) - self.theParent.treeView.flushTreeOrder() - self._populateTree() + self._populateTree(rootHandle) + self.theProject.setLastNovelViewed(rootHandle) if titleKey is not None and titleKey in self._treeMap: self._treeMap[titleKey].setSelected(True) @@ -155,21 +476,12 @@ class GuiNovelTree(QTreeWidget): def updateWordCounts(self, tHandle): """Update the word count for a given handle. """ - tHeaders = self.theIndex.getHandleWordCounts(tHandle) + tHeaders = self.theProject.index.getHandleWordCounts(tHandle) for titleKey, wCount in tHeaders: if titleKey in self._treeMap: self._treeMap[titleKey].setText(self.C_WORDS, f"{wCount:n}") return - def getColumnSizes(self): - """Return the column widths for the tree columns. - """ - retVals = [ - self.columnWidth(0), - self.columnWidth(1), - ] - return retVals - def getSelectedHandle(self): """Get the currently selected handle. If multiple items are selected, return the first. @@ -178,11 +490,46 @@ class GuiNovelTree(QTreeWidget): tHandle = None tLine = 0 if selItem: - tHandle = selItem[0].data(self.C_TITLE, Qt.UserRole)[0] - tLine = checkInt(selItem[0].data(self.C_TITLE, Qt.UserRole)[1], 1) - 1 + tHandle = selItem[0].data(self.C_TITLE, self.D_HANDLE) + sTitle = selItem[0].data(self.C_TITLE, self.D_TITLE) + tLine = checkInt(sTitle[1:], 1) - 1 return tHandle, tLine + def setLastColType(self, colType, doRefresh=True): + """Change the content type of the last column and rebuild. + """ + if self._lastCol != colType: + logger.debug("Changing last column to %s", colType.name) + self._lastCol = colType + self.setColumnHidden(self.C_EXTRA, colType == NovelTreeColumn.HIDDEN) + if doRefresh: + self.refreshTree(rootHandle=self.theProject.lastNovel, overRide=True) + return + + def setActiveHandle(self, tHandle): + """Highlight the rows associated with a given handle. + """ + tStart = time() + + self._actHandle = tHandle + for i in range(self.topLevelItemCount()): + tItem = self.topLevelItem(i) + if tItem.data(self.C_TITLE, self.D_HANDLE) == tHandle: + tItem.setBackground(self.C_TITLE, self.palette().alternateBase()) + tItem.setBackground(self.C_WORDS, self.palette().alternateBase()) + tItem.setBackground(self.C_EXTRA, self.palette().alternateBase()) + tItem.setBackground(self.C_MORE, self.palette().alternateBase()) + else: + tItem.setBackground(self.C_TITLE, self.palette().base()) + tItem.setBackground(self.C_WORDS, self.palette().base()) + tItem.setBackground(self.C_EXTRA, self.palette().base()) + tItem.setBackground(self.C_MORE, self.palette().base()) + + logger.verbose("Highlighted Novel Tree in %.3f ms", (time() - tStart)*1000) + + return + ## # Events ## @@ -208,113 +555,161 @@ class GuiNovelTree(QTreeWidget): if tHandle is None: return - self.theParent.viewDocument(tHandle) + self.novelView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, -1, "") return + def focusOutEvent(self, theEvent): + """Clear the selection when the tree no longer has focus. + """ + QTreeWidget.focusOutEvent(self, theEvent) + self.clearSelection() + return + ## - # Slots + # Private Slots ## - def _treeDoubleClick(self, tItem, tCol): + @pyqtSlot("QModelIndex") + def _treeItemClicked(self, mIndex): + """The user clicked on an item in the tree. + """ + if mIndex.column() == self.C_MORE: + tHandle = mIndex.siblingAtColumn(self.C_TITLE).data(self.D_HANDLE) + sTitle = mIndex.siblingAtColumn(self.C_TITLE).data(self.D_TITLE) + tipPos = self.mapToGlobal(self.visualRect(mIndex).topRight()) + self._popMetaBox(tipPos, tHandle, sTitle) + return + + @pyqtSlot() + def _treeSelectionChange(self): + """Extract the handle and line number of the currently selected + title, and send it to the tree meta panel. + """ + tHandle, _ = self.getSelectedHandle() + if tHandle is not None: + self.novelView.selectedItemChanged.emit(tHandle) + return + + @pyqtSlot("QTreeWidgetItem*", int) + def _treeDoubleClick(self, tItem, colNo): """Extract the handle and line number of the title double- clicked, and send it to the main gui class for opening in the document editor. """ tHandle, tLine = self.getSelectedHandle() - self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True) - return - - def _itemSelected(self): - """Extract the handle and line number of the currently selected - title, and send it to the tree meta panel. - """ - selItems = self.selectedItems() - if selItems: - tHandle = selItems[0].data(self.C_TITLE, Qt.UserRole)[0] - self.theParent.treeMeta.updateViewBox(tHandle) - + self.novelView.openDocumentRequest.emit(tHandle, nwDocMode.EDIT, tLine, "") return ## # Internal Functions ## - def _populateTree(self): + def _populateTree(self, rootHandle): """Build the tree based on the project index. """ - self.clearTree() + self.clearContent() + tStart = time() + logger.verbose("Building novel tree for root item '%s'", rootHandle) - currTitle = None - currChapter = None - currScene = None + novStruct = self.theProject.index.novelStructure(rootHandle=rootHandle, skipExcl=True) + for tKey, tHandle, sTitle, novIdx in novStruct: - for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True): + iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0) + if iLevel == 0: + continue - tItem = self._createTreeItem(tHandle, sTitle, tKey, novIdx) - self._treeMap[tKey] = tItem + newItem = QTreeWidgetItem() + newItem.setData(self.C_TITLE, Qt.DecorationRole, self._pIndent[iLevel]) + newItem.setText(self.C_TITLE, novIdx.title) + newItem.setData(self.C_TITLE, self.D_HANDLE, tHandle) + newItem.setData(self.C_TITLE, self.D_TITLE, sTitle) + newItem.setData(self.C_TITLE, self.D_KEY, tKey) + newItem.setFont(self.C_TITLE, self._hFonts[iLevel]) + newItem.setText(self.C_WORDS, f"{novIdx.wordCount:n}") + newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight) + newItem.setData(self.C_MORE, Qt.DecorationRole, self._pMore) - tLevel = novIdx["level"] - if tLevel == "H1": - self.addTopLevelItem(tItem) - currTitle = tItem - currChapter = None - currScene = None + # Custom column + lastText, toolTip = self._getLastColumnText(tHandle, sTitle) + newItem.setText(self.C_EXTRA, lastText) + if lastText: + newItem.setToolTip(self.C_EXTRA, toolTip) - elif tLevel == "H2": - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - currChapter = tItem - currScene = None + self._treeMap[tKey] = newItem + self.addTopLevelItem(newItem) - elif tLevel == "H3": - if currChapter is None: - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - else: - currChapter.addChild(tItem) - currScene = tItem - - elif tLevel == "H4": - if currScene is None: - if currChapter is None: - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - else: - currChapter.addChild(tItem) - else: - currScene.addChild(tItem) - - tItem.setExpanded(True) + self.setActiveHandle(self._actHandle) + logger.verbose("Novel Tree built in %.3f ms", (time() - tStart)*1000) self._lastBuild = time() return - def _createTreeItem(self, tHandle, sTitle, titleKey, novIdx): - """Populate a tree item with all the column values. + def _getLastColumnText(self, tHandle, sTitle): + """Generate the text for the last column based on user settings. """ - newItem = QTreeWidgetItem() - hIcon = "doc_%s" % novIdx["level"].lower() - theData = (tHandle, sTitle[1:].lstrip("0"), titleKey) + if self._lastCol == NovelTreeColumn.HIDDEN: + return "", "" - wC = int(novIdx["wCount"]) + theRefs = self.theProject.index.getReferences(tHandle, sTitle) + if self._lastCol == NovelTreeColumn.POV: + newText = ", ".join(theRefs[nwKeyWords.POV_KEY]) + return newText, f"{self._povLabel}: {newText}" - newItem.setText(self.C_TITLE, novIdx["title"]) - newItem.setData(self.C_TITLE, Qt.UserRole, theData) - newItem.setIcon(self.C_TITLE, self.theTheme.getIcon(hIcon)) - newItem.setText(self.C_WORDS, f"{wC:n}") - newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight) + elif self._lastCol == NovelTreeColumn.FOCUS: + newText = ", ".join(theRefs[nwKeyWords.FOCUS_KEY]) + return newText, f"{self._focLabel}: {newText}" - theRefs = self.theIndex.getReferences(tHandle, sTitle) - newItem.setText(self.C_POV, ", ".join(theRefs[nwKeyWords.POV_KEY])) + elif self._lastCol == NovelTreeColumn.PLOT: + newText = ", ".join(theRefs[nwKeyWords.PLOT_KEY]) + return newText, f"{self._pltLabel}: {newText}" - return newItem + return "", "" + + def _popMetaBox(self, qPos, tHandle, sTitle): + """Show the novel meta data box. + """ + logger.debug("Generating meta data tooltip for '%s:%s'", tHandle, sTitle) + + pIndex = self.theProject.index + novIdx = pIndex.getNovelData(tHandle, sTitle) + refTags = pIndex.getReferences(tHandle, sTitle) + + synopText = novIdx.synopsis + if synopText: + synopLabel = trConst(nwLabels.OUTLINE_COLS[nwOutline.SYNOP]) + synopText = f"

{synopLabel}: {synopText}

" + + refLines = [] + refLines = self._appendMetaTag(refTags, nwKeyWords.POV_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.FOCUS_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.CHAR_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.PLOT_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.TIME_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.WORLD_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.OBJECT_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.ENTITY_KEY, refLines) + refLines = self._appendMetaTag(refTags, nwKeyWords.CUSTOM_KEY, refLines) + + refText = "" + if refLines: + refList = "
".join(refLines) + refText = f"

{refList}

" + + ttText = refText + synopText or self.tr("No meta data") + if ttText: + QToolTip.showText(qPos, ttText) + + return + + @staticmethod + def _appendMetaTag(refs, key, lines): + """Generate a reference list for a given reference key. + """ + tags = ", ".join(refs.get(key, [])) + if tags: + lines.append(f"{trConst(nwLabels.KEY_NAME[key])}: {tags}") + return lines # END Class GuiNovelTree diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index 1ac83ff1..e8514c15 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -4,7 +4,11 @@ novelWriter – GUI Project Outline GUI class for the project outline view File History: -Created: 2019-11-16 [0.4.1] +Created: 2022-05-15 [1.7b1] GuiOutlineView +Created: 2022-05-22 [1.7b1] GuiOutlineToolBar +Created: 2019-11-16 [0.4.1] GuiOutlineTree +Created: 2019-11-16 [0.4.1] GuiOutlineHeaderMenu +Created: 2020-06-02 [0.7.0] GuiOutlineDetails This file is a part of novelWriter Copyright 2018–2022, Veronica Berglyd Olsen @@ -27,20 +31,284 @@ import logging import novelwriter from time import time +from enum import Enum -from PyQt5.QtCore import Qt, QSize, pyqtSlot +from PyQt5.QtCore import ( + Qt, pyqtSignal, pyqtSlot, QSize, QT_TRANSLATE_NOOP +) from PyQt5.QtWidgets import ( - QTreeWidget, QTreeWidgetItem, QMenu, QAction, QAbstractItemView + QAbstractItemView, QAction, QComboBox, QFrame, QGridLayout, QGroupBox, + QHBoxLayout, QLabel, QMenu, QScrollArea, QSizePolicy, QSplitter, QToolBar, + QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget ) -from novelwriter.enum import nwItemLayout, nwItemType, nwOutline +from novelwriter.enum import ( + nwDocMode, nwItemClass, nwItemLayout, nwItemType, nwOutline +) from novelwriter.common import checkInt -from novelwriter.constants import trConst, nwKeyWords, nwLabels +from novelwriter.constants import nwHeaders, trConst, nwKeyWords, nwLabels + logger = logging.getLogger(__name__) -class GuiOutline(QTreeWidget): +class GuiOutlineView(QWidget): + + loadDocumentTagRequest = pyqtSignal(str, Enum) + + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) + + self.mainConf = novelwriter.CONFIG + self.mainGui = mainGui + self.theProject = mainGui.theProject + + # Build GUI + self.outlineBar = GuiOutlineToolBar(self) + self.outlineTree = GuiOutlineTree(self) + self.outlineData = GuiOutlineDetails(self) + + self.splitOutline = QSplitter(Qt.Vertical) + self.splitOutline.addWidget(self.outlineTree) + self.splitOutline.addWidget(self.outlineData) + self.splitOutline.setSizes(self.mainConf.getOutlinePanePos()) + + # Assemble + self.outerBox = QVBoxLayout() + self.outerBox.setContentsMargins(0, 0, 0, 0) + self.outerBox.addWidget(self.outlineBar) + self.outerBox.addWidget(self.splitOutline) + + self.setLayout(self.outerBox) + + # Connect Signals + self.outlineTree.hiddenStateChanged.connect(self._updateMenuColumns) + self.outlineTree.activeItemChanged.connect(self.outlineData.showItem) + self.outlineData.itemTagClicked.connect(self._tagClicked) + self.outlineBar.loadNovelRootRequest.connect(self._rootItemChanged) + self.outlineBar.viewColumnToggled.connect(self.outlineTree.menuColumnToggled) + + # Function Mappings + self.getSelectedHandle = self.outlineTree.getSelectedHandle + + return + + ## + # Methods + ## + + def initSettings(self): + """Initialise GUI elements that depend on specific settings. + """ + self.outlineTree.initSettings() + self.outlineData.initSettings() + return + + def refreshTree(self): + """Refresh the current tree. + """ + self.outlineTree.refreshTree(rootHandle=self.theProject.lastOutline) + return + + def clearProject(self): + """Clear project-related GUI content. + """ + self.outlineData.clearDetails() + return + + def openProjectTasks(self): + """Run open project tasks. + """ + lastOutline = self.theProject.lastOutline + if not (lastOutline in self.theProject.tree or lastOutline is None): + lastOutline = self.theProject.tree.findRoot(nwItemClass.NOVEL) + + logger.debug("Setting outline tree to root item '%s'", lastOutline) + + self.clearProject() + self.outlineBar.populateNovelList() + self.outlineBar.setCurrentRoot(lastOutline) + + return + + def closeProjectTasks(self): + self.outlineTree.closeProjectTasks() + self.outlineData.updateClasses() + return + + def splitSizes(self): + return self.splitOutline.sizes() + + def setTreeFocus(self): + """Set the focus to the tree widget. + """ + return self.outlineTree.setFocus() + + def treeHasFocus(self): + """Check if the outline tree has focus. + """ + return self.outlineTree.hasFocus() + + ## + # Public Slots + ## + + @pyqtSlot(str) + def updateRootItem(self, tHandle): + """Should be called whenever a root folders changes. + """ + self.outlineBar.populateNovelList() + self.outlineData.updateClasses() + return + + ## + # Private Slots + ## + + @pyqtSlot() + def _updateMenuColumns(self): + """Trigger an update of the toggled state of the column menu + checkboxes whenever a signal is received that the hidden state + of columns has changed. + """ + self.outlineBar.setColumnHiddenState(self.outlineTree.hiddenColumns) + return + + @pyqtSlot(str) + def _tagClicked(self, link): + """Capture the click of a tag in the details panel. + """ + if link: + self.loadDocumentTagRequest.emit(link, nwDocMode.VIEW) + return + + @pyqtSlot(str) + def _rootItemChanged(self, handle): + """The root novel handle has changed or needs to be refreshed. + """ + self.outlineTree.refreshTree(rootHandle=(handle or None), overRide=True) + return + +# END Class GuiOutlineView + + +class GuiOutlineToolBar(QToolBar): + + loadNovelRootRequest = pyqtSignal(str) + viewColumnToggled = pyqtSignal(bool, Enum) + + def __init__(self, theOutline): + QTreeWidget.__init__(self, theOutline) + + logger.debug("Initialising GuiOutlineToolBar ...") + + self.mainConf = novelwriter.CONFIG + self.mainGui = theOutline.mainGui + self.theProject = theOutline.mainGui.theProject + self.mainTheme = theOutline.mainGui.mainTheme + + iPx = self.mainConf.pxInt(22) + mPx = self.mainConf.pxInt(12) + + self.setMovable(False) + self.setIconSize(QSize(iPx, iPx)) + self.setContentsMargins(0, 0, 0, 0) + self.setStyleSheet("QToolBar {border: 0px;}") + + stretch = QWidget(self) + stretch.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + + # Novel Selector + self.novelLabel = QLabel(self.tr("Outline of")) + self.novelLabel.setContentsMargins(0, 0, mPx, 0) + + self.novelValue = QComboBox(self) + self.novelValue.setMinimumWidth(self.mainConf.pxInt(200)) + self.novelValue.currentIndexChanged.connect(self._novelValueChanged) + + # Actions + self.aRefresh = QAction(self.tr("Refresh"), self) + self.aRefresh.setIcon(self.mainTheme.getIcon("refresh")) + self.aRefresh.triggered.connect(self._refreshRequested) + + # Column Menu + self.mColumns = GuiOutlineHeaderMenu(self) + self.mColumns.columnToggled.connect( + lambda isChecked, tItem: self.viewColumnToggled.emit(isChecked, tItem) + ) + + self.tbColumns = QToolButton(self) + self.tbColumns.setIcon(self.mainTheme.getIcon("menu")) + self.tbColumns.setMenu(self.mColumns) + self.tbColumns.setPopupMode(QToolButton.InstantPopup) + + # Assemble + self.addWidget(self.novelLabel) + self.addWidget(self.novelValue) + self.addSeparator() + self.addAction(self.aRefresh) + self.addWidget(self.tbColumns) + self.addWidget(stretch) + + logger.debug("GuiOutlineToolBar initialisation complete") + + return + + ## + # Methods + ## + + def populateNovelList(self): + """Fill the novel combo box with a list of all novel folders. + """ + self.novelValue.clear() + tIcon = self.mainTheme.getIcon(nwLabels.CLASS_ICON[nwItemClass.NOVEL]) + for tHandle, nwItem in self.theProject.tree.iterRoots(nwItemClass.NOVEL): + self.novelValue.addItem(tIcon, nwItem.itemName, tHandle) + self.novelValue.insertSeparator(self.novelValue.count()) + self.novelValue.addItem(tIcon, self.tr("All Novel Folders"), "") + return + + def setCurrentRoot(self, rootHandle): + """Set the current active root handle. + """ + if rootHandle is None: + rootIdx = self.novelValue.count() - 1 + else: + rootIdx = self.novelValue.findData(rootHandle) + if rootIdx >= 0: + self.novelValue.setCurrentIndex(rootIdx) + return + + def setColumnHiddenState(self, hiddenState): + """Forward the change of column hidden states to the menu. + """ + self.mColumns.setHiddenState(hiddenState) + return + + ## + # Private Slots + ## + + @pyqtSlot(int) + def _novelValueChanged(self, index): + """Emit a signal containing the handle of the selected item. + """ + if index >= 0: + self.loadNovelRootRequest.emit(self.novelValue.currentData()) + return + + @pyqtSlot() + def _refreshRequested(self): + """Emit a signal containing the handle of the selected item. + """ + self.loadNovelRootRequest.emit(self.novelValue.currentData()) + return + +# END Class GuiOutlineToolBar + + +class GuiOutlineTree(QTreeWidget): DEF_WIDTH = { nwOutline.TITLE: 200, @@ -82,19 +350,24 @@ class GuiOutline(QTreeWidget): nwOutline.SYNOP: False, } - def __init__(self, theParent): - QTreeWidget.__init__(self, theParent) + D_HANDLE = Qt.UserRole + D_TITLE = Qt.UserRole + 1 - logger.debug("Initialising GuiOutline ...") + hiddenStateChanged = pyqtSignal() + activeItemChanged = pyqtSignal(str, str) + + def __init__(self, theOutline): + QTreeWidget.__init__(self, theOutline) + + logger.debug("Initialising GuiOutlineTree ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex - self.optState = theParent.theProject.optState - self.headerMenu = GuiOutlineHeaderMenu(self) + self.mainGui = theOutline.mainGui + self.theProject = theOutline.mainGui.theProject + self.mainTheme = theOutline.mainGui.mainTheme + self.setUniformRowHeights(True) + self.setFrameStyle(QFrame.NoFrame) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setSelectionMode(QAbstractItemView.SingleSelection) self.setExpandsOnDoubleClick(False) @@ -102,15 +375,37 @@ class GuiOutline(QTreeWidget): self.itemDoubleClicked.connect(self._treeDoubleClick) self.itemSelectionChanged.connect(self._itemSelected) - iPx = self.theTheme.baseIconSize + iPx = self.mainTheme.baseIconSize self.setIconSize(QSize(iPx, iPx)) - self.setIndentation(iPx) + self.setIndentation(0) self.treeHead = self.header() - self.treeHead.setContextMenuPolicy(Qt.CustomContextMenu) - self.treeHead.customContextMenuRequested.connect(self._headerRightClick) self.treeHead.sectionMoved.connect(self._columnMoved) + # Pre-Generate Tree Formatting + fH1 = self.font() + fH1.setBold(True) + fH1.setUnderline(True) + + fH2 = self.font() + fH2.setBold(True) + + self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()] + self._pIndent = [ + self.mainTheme.loadDecoration("deco_doc_h0", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h1", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h2", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h3", pxH=iPx), + self.mainTheme.loadDecoration("deco_doc_h4", pxH=iPx), + ] + self._dIcon = { + "H0": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H0"), + "H1": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H1"), + "H2": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H2"), + "H3": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H3"), + "H4": self.mainTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, "H4"), + } + # Internals self._treeOrder = [] self._colWidth = {} @@ -120,15 +415,28 @@ class GuiOutline(QTreeWidget): self._firstView = True self._lastBuild = 0 - self.initOutline() - self.clearOutline() - self.headerMenu.setHiddenState(self._colHidden) + self.initSettings() + self.clearContent() - logger.debug("GuiOutline initialisation complete") + self.hiddenStateChanged.emit() + + logger.debug("GuiOutlineTree initialisation complete") return - def initOutline(self): + ## + # Properties + ## + + @property + def hiddenColumns(self): + return self._colHidden + + ## + # Methods + ## + + def initSettings(self): """Set or update outline settings. """ # Scroll bars @@ -144,7 +452,7 @@ class GuiOutline(QTreeWidget): return - def clearOutline(self): + def clearContent(self): """Clear the tree and header and set the default values for the columns arrays. """ @@ -167,7 +475,7 @@ class GuiOutline(QTreeWidget): return - def refreshTree(self, overRide=False, novelChanged=False): + def refreshTree(self, rootHandle=None, overRide=False, novelChanged=False): """Called whenever the Outline tab is activated and controls what data to load, and if necessary, force a rebuild of the tree. @@ -175,25 +483,27 @@ class GuiOutline(QTreeWidget): # If it's the first time, we always build if self._firstView or self._firstView and overRide: self._loadHeaderState() - self._populateTree() + self._populateTree(rootHandle) self._firstView = False return # If the novel index or novel tree has changed since the tree # was last built, we rebuild the tree from the updated index. - indexChanged = self.theIndex.novelChangedSince(self._lastBuild) - doBuild = (novelChanged or indexChanged) and self.theProject.autoOutline - if doBuild or overRide: - logger.debug("Rebuilding Project Outline") - self._populateTree() + indexChanged = self.theProject.index.rootChangedSince(rootHandle, self._lastBuild) + if not (novelChanged or indexChanged or overRide): + logger.verbose("No changes have been made to the novel index") + return + + self._populateTree(rootHandle) + self.theProject.setLastOutlineViewed(rootHandle or None) return - def closeOutline(self): + def closeProjectTasks(self): """Called before a project is closed. """ self._saveHeaderState() - self.clearOutline() + self.clearContent() self._firstView = True return @@ -205,7 +515,7 @@ class GuiOutline(QTreeWidget): tHandle = None tLine = 0 if selItem: - tHandle = selItem[0].data(self._colIdx[nwOutline.TITLE], Qt.UserRole) + tHandle = selItem[0].data(self._colIdx[nwOutline.TITLE], self.D_HANDLE) tLine = checkInt(selItem[0].text(self._colIdx[nwOutline.LINE]), 1) - 1 return tHandle, tLine @@ -221,7 +531,7 @@ class GuiOutline(QTreeWidget): document editor. """ tHandle, tLine = self.getSelectedHandle() - self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True) + self.mainGui.openDocument(tHandle, tLine=tLine - 1, doScroll=True) return @pyqtSlot() @@ -231,20 +541,12 @@ class GuiOutline(QTreeWidget): """ selItems = self.selectedItems() if selItems: - tHandle = selItems[0].data(self._colIdx[nwOutline.TITLE], Qt.UserRole) - sTitle = selItems[0].data(self._colIdx[nwOutline.LINE], Qt.UserRole) - self.theParent.projMeta.showItem(tHandle, sTitle) - self.theParent.treeView.setSelectedHandle(tHandle) + tHandle = selItems[0].data(self._colIdx[nwOutline.TITLE], self.D_HANDLE) + sTitle = selItems[0].data(self._colIdx[nwOutline.TITLE], self.D_TITLE) + self.activeItemChanged.emit(tHandle, sTitle) return - @pyqtSlot("QPoint") - def _headerRightClick(self, clickPos): - """Show the header column menu. - """ - self.headerMenu.exec_(self.mapToGlobal(clickPos)) - return - @pyqtSlot(int, int, int) def _columnMoved(self, logIdx, oldVisualIdx, newVisualIdx): """Make sure the order array is up to date with the actual order @@ -254,9 +556,10 @@ class GuiOutline(QTreeWidget): self._saveHeaderState() return - def _menuColumnToggled(self, isChecked, theItem): + @pyqtSlot(bool, Enum) + def menuColumnToggled(self, isChecked, theItem): """Receive the changes to column visibility forwarded by the - header context menu. + column selection menu. """ logger.verbose("User toggled Outline column '%s'", theItem.name) if theItem in self._colIdx: @@ -273,10 +576,12 @@ class GuiOutline(QTreeWidget): """Load the state of the main tree header, that is, column order and column width. """ + pOptions = self.theProject.options + # Load whatever we saved last time, regardless of wether it # contains the correct names or number of columns. The names # must be valid though. - tempOrder = self.optState.getValue("GuiOutline", "headerOrder", []) + tempOrder = pOptions.getValue("GuiOutline", "headerOrder", []) treeOrder = [] for hName in tempOrder: try: @@ -299,21 +604,21 @@ class GuiOutline(QTreeWidget): # We load whatever column widths and hidden states we find in # the file, and leave the rest in their default state. - tmpWidth = self.optState.getValue("GuiOutline", "columnWidth", {}) + tmpWidth = pOptions.getValue("GuiOutline", "columnWidth", {}) for hName in tmpWidth: try: self._colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName]) except Exception: logger.warning("Ignored unknown outline column '%s'", str(hName)) - tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {}) + tmpHidden = pOptions.getValue("GuiOutline", "columnHidden", {}) for hName in tmpHidden: try: self._colHidden[nwOutline[hName]] = tmpHidden[hName] except Exception: logger.warning("Ignored unknown outline column '%s'", str(hName)) - self.headerMenu.setHiddenState(self._colHidden) + self.hiddenStateChanged.emit() return @@ -347,14 +652,15 @@ class GuiOutline(QTreeWidget): if not logHidden and logWidth > 0: colWidth[hName] = logWidth - self.optState.setValue("GuiOutline", "headerOrder", treeOrder) - self.optState.setValue("GuiOutline", "columnWidth", colWidth) - self.optState.setValue("GuiOutline", "columnHidden", colHidden) - self.optState.saveSettings() + pOptions = self.theProject.options + pOptions.setValue("GuiOutline", "headerOrder", treeOrder) + pOptions.setValue("GuiOutline", "columnWidth", colWidth) + pOptions.setValue("GuiOutline", "columnHidden", colHidden) + pOptions.saveSettings() return - def _populateTree(self): + def _populateTree(self, rootHandle): """Build the tree based on the project index, and the header based on the defined constants, default values and user selected width, order and hidden state. All columns are populated, even @@ -374,8 +680,7 @@ class GuiOutline(QTreeWidget): self.setColumnWidth(self._colIdx[hItem], self._colWidth[hItem]) self.setColumnHidden(self._colIdx[hItem], self._colHidden[hItem]) - # Make sure title column is always visible, - # and handle column always hidden + # Make sure title column is always visible self.setColumnHidden(self._colIdx[nwOutline.TITLE], False) headItem = self.headerItem() @@ -383,109 +688,61 @@ class GuiOutline(QTreeWidget): headItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight) headItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight) - currTitle = None - currChapter = None - currScene = None + novStruct = self.theProject.index.novelStructure(rootHandle=rootHandle, skipExcl=True) + for _, tHandle, sTitle, novIdx in novStruct: - for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True): + iLevel = nwHeaders.H_LEVEL.get(novIdx.level, 0) + dLevel = self.theProject.index.getHandleHeaderLevel(tHandle) + if iLevel == 0: + continue - tItem = self._createTreeItem(tHandle, sTitle, novIdx) + trItem = QTreeWidgetItem() + nwItem = self.theProject.tree[tHandle] - tLevel = novIdx["level"] - if tLevel == "H1": - self.addTopLevelItem(tItem) - currTitle = tItem - currChapter = None - currScene = None + trItem.setData(self._colIdx[nwOutline.TITLE], Qt.DecorationRole, self._pIndent[iLevel]) + trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title) + trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle) + trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle) + trItem.setFont(self._colIdx[nwOutline.TITLE], self._hFonts[iLevel]) + trItem.setText(self._colIdx[nwOutline.LEVEL], novIdx.level) + trItem.setIcon(self._colIdx[nwOutline.LABEL], self._dIcon[dLevel]) + trItem.setText(self._colIdx[nwOutline.LABEL], nwItem.itemName) + trItem.setText(self._colIdx[nwOutline.LINE], sTitle[1:].lstrip("0")) + trItem.setText(self._colIdx[nwOutline.SYNOP], novIdx.synopsis) + trItem.setText(self._colIdx[nwOutline.CCOUNT], f"{novIdx.charCount:n}") + trItem.setText(self._colIdx[nwOutline.WCOUNT], f"{novIdx.wordCount:n}") + trItem.setText(self._colIdx[nwOutline.PCOUNT], f"{novIdx.paraCount:n}") + trItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight) + trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight) + trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight) - elif tLevel == "H2": - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - currChapter = tItem - currScene = None + refs = self.theProject.index.getReferences(tHandle, sTitle) + trItem.setText(self._colIdx[nwOutline.POV], ", ".join(refs[nwKeyWords.POV_KEY])) + trItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(refs[nwKeyWords.FOCUS_KEY])) + trItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(refs[nwKeyWords.CHAR_KEY])) + trItem.setText(self._colIdx[nwOutline.PLOT], ", ".join(refs[nwKeyWords.PLOT_KEY])) + trItem.setText(self._colIdx[nwOutline.TIME], ", ".join(refs[nwKeyWords.TIME_KEY])) + trItem.setText(self._colIdx[nwOutline.WORLD], ", ".join(refs[nwKeyWords.WORLD_KEY])) + trItem.setText(self._colIdx[nwOutline.OBJECT], ", ".join(refs[nwKeyWords.OBJECT_KEY])) + trItem.setText(self._colIdx[nwOutline.ENTITY], ", ".join(refs[nwKeyWords.ENTITY_KEY])) + trItem.setText(self._colIdx[nwOutline.CUSTOM], ", ".join(refs[nwKeyWords.CUSTOM_KEY])) - elif tLevel == "H3": - if currChapter is None: - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - else: - currChapter.addChild(tItem) - currScene = tItem - - elif tLevel == "H4": - if currScene is None: - if currChapter is None: - if currTitle is None: - self.addTopLevelItem(tItem) - else: - currTitle.addChild(tItem) - else: - currChapter.addChild(tItem) - else: - currScene.addChild(tItem) - - tItem.setExpanded(True) + self.addTopLevelItem(trItem) self._lastBuild = time() return - def _createTreeItem(self, tHandle, sTitle, novIdx): - """Populate a tree item with all the column values. - """ - nwItem = self.theProject.projTree[tHandle] - newItem = QTreeWidgetItem() - hIcon = "doc_%s" % novIdx["level"].lower() - - hLevel = self.theIndex.getHandleHeaderLevel(tHandle) - dIcon = self.theTheme.getItemIcon(nwItemType.FILE, None, nwItemLayout.DOCUMENT, hLevel) - - cC = int(novIdx["cCount"]) - wC = int(novIdx["wCount"]) - pC = int(novIdx["pCount"]) - - newItem.setText(self._colIdx[nwOutline.TITLE], novIdx["title"]) - newItem.setData(self._colIdx[nwOutline.TITLE], Qt.UserRole, tHandle) - newItem.setIcon(self._colIdx[nwOutline.TITLE], self.theTheme.getIcon(hIcon)) - newItem.setText(self._colIdx[nwOutline.LEVEL], novIdx["level"]) - newItem.setText(self._colIdx[nwOutline.LABEL], nwItem.itemName) - newItem.setIcon(self._colIdx[nwOutline.LABEL], dIcon) - newItem.setText(self._colIdx[nwOutline.LINE], sTitle[1:].lstrip("0")) - newItem.setData(self._colIdx[nwOutline.LINE], Qt.UserRole, sTitle) - newItem.setText(self._colIdx[nwOutline.SYNOP], novIdx["synopsis"]) - newItem.setText(self._colIdx[nwOutline.CCOUNT], f"{cC:n}") - newItem.setText(self._colIdx[nwOutline.WCOUNT], f"{wC:n}") - newItem.setText(self._colIdx[nwOutline.PCOUNT], f"{pC:n}") - newItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight) - newItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight) - newItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight) - - theRefs = self.theIndex.getReferences(tHandle, sTitle) - newItem.setText(self._colIdx[nwOutline.POV], ", ".join(theRefs[nwKeyWords.POV_KEY])) - newItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(theRefs[nwKeyWords.FOCUS_KEY])) - newItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(theRefs[nwKeyWords.CHAR_KEY])) - newItem.setText(self._colIdx[nwOutline.PLOT], ", ".join(theRefs[nwKeyWords.PLOT_KEY])) - newItem.setText(self._colIdx[nwOutline.TIME], ", ".join(theRefs[nwKeyWords.TIME_KEY])) - newItem.setText(self._colIdx[nwOutline.WORLD], ", ".join(theRefs[nwKeyWords.WORLD_KEY])) - newItem.setText(self._colIdx[nwOutline.OBJECT], ", ".join(theRefs[nwKeyWords.OBJECT_KEY])) - newItem.setText(self._colIdx[nwOutline.ENTITY], ", ".join(theRefs[nwKeyWords.ENTITY_KEY])) - newItem.setText(self._colIdx[nwOutline.CUSTOM], ", ".join(theRefs[nwKeyWords.CUSTOM_KEY])) - - return newItem - -# END Class GuiOutline +# END Class GuiOutlineTree class GuiOutlineHeaderMenu(QMenu): - def __init__(self, theParent): - QMenu.__init__(self, theParent) + columnToggled = pyqtSignal(bool, Enum) + + def __init__(self, theOutline): + QMenu.__init__(self, theOutline) - self.theParent = theParent self.acceptToggle = True mnuHead = QAction(self.tr("Select Columns"), self) @@ -499,7 +756,7 @@ class GuiOutlineHeaderMenu(QMenu): self.actionMap[hItem] = QAction(trConst(nwLabels.OUTLINE_COLS[hItem]), self) self.actionMap[hItem].setCheckable(True) self.actionMap[hItem].toggled.connect( - lambda isChecked, tItem=hItem: self._columnToggled(isChecked, tItem) + lambda isChecked, tItem=hItem: self.columnToggled.emit(isChecked, tItem) ) self.addAction(self.actionMap[hItem]) @@ -520,16 +777,338 @@ class GuiOutlineHeaderMenu(QMenu): return +# END Class GuiOutlineHeaderMenu + + +class GuiOutlineDetails(QScrollArea): + + LVL_MAP = { + "H1": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Title"), + "H2": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Chapter"), + "H3": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Scene"), + "H4": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Section"), + } + + itemTagClicked = pyqtSignal(str) + + def __init__(self, theOutline): + QScrollArea.__init__(self, theOutline) + + logger.debug("Initialising GuiOutlineDetails ...") + + self.mainConf = novelwriter.CONFIG + self.theOutline = theOutline + self.mainGui = theOutline.mainGui + self.theProject = theOutline.mainGui.theProject + self.mainTheme = theOutline.mainGui.mainTheme + + # Sizes + minTitle = 30*self.mainTheme.textNWidth + maxTitle = 40*self.mainTheme.textNWidth + wCount = self.mainTheme.getTextWidth("999,999") + hSpace = int(self.mainConf.pxInt(10)) + vSpace = int(self.mainConf.pxInt(4)) + + # Details Area + self.titleLabel = QLabel("%s" % self.tr("Title")) + self.fileLabel = QLabel("%s" % self.tr("Document")) + self.itemLabel = QLabel("%s" % self.tr("Status")) + self.titleValue = QLabel("") + self.fileValue = QLabel("") + self.itemValue = QLabel("") + + self.titleValue.setMinimumWidth(minTitle) + self.titleValue.setMaximumWidth(maxTitle) + self.fileValue.setMinimumWidth(minTitle) + self.fileValue.setMaximumWidth(maxTitle) + self.itemValue.setMinimumWidth(minTitle) + self.itemValue.setMaximumWidth(maxTitle) + + # Stats Area + self.cCLabel = QLabel("%s" % self.tr("Characters")) + self.wCLabel = QLabel("%s" % self.tr("Words")) + self.pCLabel = QLabel("%s" % self.tr("Paragraphs")) + self.cCValue = QLabel("") + self.wCValue = QLabel("") + self.pCValue = QLabel("") + + self.cCValue.setMinimumWidth(wCount) + self.wCValue.setMinimumWidth(wCount) + self.pCValue.setMinimumWidth(wCount) + self.cCValue.setAlignment(Qt.AlignRight) + self.wCValue.setAlignment(Qt.AlignRight) + self.pCValue.setAlignment(Qt.AlignRight) + + # Synopsis + self.synopLabel = QLabel("%s" % self.tr("Synopsis")) + self.synopValue = QLabel("") + self.synopLWrap = QHBoxLayout() + self.synopValue.setWordWrap(True) + self.synopValue.setAlignment(Qt.AlignTop | Qt.AlignLeft) + self.synopLWrap.addWidget(self.synopValue, 1) + + # Tags + self.povKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.POV_KEY])) + self.focKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.FOCUS_KEY])) + self.chrKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.CHAR_KEY])) + self.pltKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY])) + self.timKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.TIME_KEY])) + self.wldKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.WORLD_KEY])) + self.objKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.OBJECT_KEY])) + self.entKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.ENTITY_KEY])) + self.cstKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.CUSTOM_KEY])) + + self.povKeyLWrap = QHBoxLayout() + self.focKeyLWrap = QHBoxLayout() + self.chrKeyLWrap = QHBoxLayout() + self.pltKeyLWrap = QHBoxLayout() + self.timKeyLWrap = QHBoxLayout() + self.wldKeyLWrap = QHBoxLayout() + self.objKeyLWrap = QHBoxLayout() + self.entKeyLWrap = QHBoxLayout() + self.cstKeyLWrap = QHBoxLayout() + + self.povKeyValue = QLabel("") + self.focKeyValue = QLabel("") + self.chrKeyValue = QLabel("") + self.pltKeyValue = QLabel("") + self.timKeyValue = QLabel("") + self.wldKeyValue = QLabel("") + self.objKeyValue = QLabel("") + self.entKeyValue = QLabel("") + self.cstKeyValue = QLabel("") + + self.povKeyValue.setWordWrap(True) + self.focKeyValue.setWordWrap(True) + self.chrKeyValue.setWordWrap(True) + self.pltKeyValue.setWordWrap(True) + self.timKeyValue.setWordWrap(True) + self.wldKeyValue.setWordWrap(True) + self.objKeyValue.setWordWrap(True) + self.entKeyValue.setWordWrap(True) + self.cstKeyValue.setWordWrap(True) + + def tagClicked(link): + self.itemTagClicked.emit(link) + + self.povKeyValue.linkActivated.connect(tagClicked) + self.focKeyValue.linkActivated.connect(tagClicked) + self.chrKeyValue.linkActivated.connect(tagClicked) + self.pltKeyValue.linkActivated.connect(tagClicked) + self.timKeyValue.linkActivated.connect(tagClicked) + self.wldKeyValue.linkActivated.connect(tagClicked) + self.objKeyValue.linkActivated.connect(tagClicked) + self.entKeyValue.linkActivated.connect(tagClicked) + self.cstKeyValue.linkActivated.connect(tagClicked) + + self.povKeyLWrap.addWidget(self.povKeyValue, 1) + self.focKeyLWrap.addWidget(self.focKeyValue, 1) + self.chrKeyLWrap.addWidget(self.chrKeyValue, 1) + self.pltKeyLWrap.addWidget(self.pltKeyValue, 1) + self.timKeyLWrap.addWidget(self.timKeyValue, 1) + self.wldKeyLWrap.addWidget(self.wldKeyValue, 1) + self.objKeyLWrap.addWidget(self.objKeyValue, 1) + self.entKeyLWrap.addWidget(self.entKeyValue, 1) + self.cstKeyLWrap.addWidget(self.cstKeyValue, 1) + + # Selected Item Details + self.mainGroup = QGroupBox(self.tr("Title Details"), self) + self.mainForm = QGridLayout() + self.mainGroup.setLayout(self.mainForm) + + self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) + self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) + self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) + self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft) + self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft) + + self.mainForm.setColumnStretch(1, 1) + self.mainForm.setRowStretch(4, 1) + self.mainForm.setHorizontalSpacing(hSpace) + self.mainForm.setVerticalSpacing(vSpace) + + # Selected Item Tags + self.tagsGroup = QGroupBox(self.tr("Reference Tags"), self) + self.tagsForm = QGridLayout() + self.tagsGroup.setLayout(self.tagsForm) + + self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) + self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) + + self.tagsForm.setColumnStretch(1, 1) + self.tagsForm.setRowStretch(8, 1) + self.tagsForm.setHorizontalSpacing(hSpace) + self.tagsForm.setVerticalSpacing(vSpace) + + # Assemble + self.outerWidget = QWidget() + self.outerBox = QHBoxLayout() + self.outerBox.addWidget(self.mainGroup, 0) + self.outerBox.addWidget(self.tagsGroup, 1) + + self.outerWidget.setLayout(self.outerBox) + self.setWidget(self.outerWidget) + + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.setWidgetResizable(True) + self.setFrameStyle(QFrame.NoFrame) + + self.initSettings() + + logger.debug("GuiOutlineDetails initialisation complete") + + return + + def initSettings(self): + """Set or update outline settings. + """ + # Scroll bars + if self.mainConf.hideVScroll: + self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + else: + self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + + if self.mainConf.hideHScroll: + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) + else: + self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + + self.updateClasses() + + return + + def clearDetails(self): + """Clear all the data labels. + """ + self.titleLabel.setText("%s" % self.tr("Title")) + self.titleValue.setText("") + self.fileValue.setText("") + self.itemValue.setText("") + self.cCValue.setText("") + self.wCValue.setText("") + self.pCValue.setText("") + self.synopValue.setText("") + self.povKeyValue.setText("") + self.focKeyValue.setText("") + self.chrKeyValue.setText("") + self.pltKeyValue.setText("") + self.timKeyValue.setText("") + self.wldKeyValue.setText("") + self.objKeyValue.setText("") + self.entKeyValue.setText("") + self.cstKeyValue.setText("") + self.updateClasses() + return + ## # Slots ## - def _columnToggled(self, isChecked, theItem): - """The user has toggled the visibility of a column. Forward the - event to the parent class only if we're accepting changes. + @pyqtSlot(str, str) + def showItem(self, tHandle, sTitle): + """Update the content of the tree with the given handle and line + number pointing to a header. """ - if self.acceptToggle: - self.theParent._menuColumnToggled(isChecked, theItem) + pIndex = self.theProject.index + nwItem = self.theProject.tree[tHandle] + novIdx = pIndex.getNovelData(tHandle, sTitle) + theRefs = pIndex.getReferences(tHandle, sTitle) + if nwItem is None or novIdx is None: + return False + + if novIdx.level in self.LVL_MAP: + self.titleLabel.setText("%s" % self.tr(self.LVL_MAP[novIdx.level])) + else: + self.titleLabel.setText("%s" % self.tr("Title")) + self.titleValue.setText(novIdx.title) + + itemStatus, _ = nwItem.getImportStatus() + + self.fileValue.setText(nwItem.itemName) + self.itemValue.setText(itemStatus) + + cC = checkInt(novIdx.charCount, 0) + wC = checkInt(novIdx.wordCount, 0) + pC = checkInt(novIdx.paraCount, 0) + + self.cCValue.setText(f"{cC:n}") + self.wCValue.setText(f"{wC:n}") + self.pCValue.setText(f"{pC:n}") + + self.synopValue.setText(novIdx.synopsis) + + self.povKeyValue.setText(self._formatTags(theRefs, nwKeyWords.POV_KEY)) + self.focKeyValue.setText(self._formatTags(theRefs, nwKeyWords.FOCUS_KEY)) + self.chrKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CHAR_KEY)) + self.pltKeyValue.setText(self._formatTags(theRefs, nwKeyWords.PLOT_KEY)) + self.timKeyValue.setText(self._formatTags(theRefs, nwKeyWords.TIME_KEY)) + self.wldKeyValue.setText(self._formatTags(theRefs, nwKeyWords.WORLD_KEY)) + self.objKeyValue.setText(self._formatTags(theRefs, nwKeyWords.OBJECT_KEY)) + self.entKeyValue.setText(self._formatTags(theRefs, nwKeyWords.ENTITY_KEY)) + self.cstKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CUSTOM_KEY)) + + return True + + @pyqtSlot() + def updateClasses(self): + """Update the visibility status of class details. + """ + usedClasses = self.theProject.tree.rootClasses() + + pltVisible = nwItemClass.PLOT in usedClasses + timVisible = nwItemClass.TIMELINE in usedClasses + wldVisible = nwItemClass.WORLD in usedClasses + objVisible = nwItemClass.OBJECT in usedClasses + entVisible = nwItemClass.ENTITY in usedClasses + cstVisible = nwItemClass.CUSTOM in usedClasses + + self.pltKeyLabel.setVisible(pltVisible) + self.pltKeyValue.setVisible(pltVisible) + self.timKeyLabel.setVisible(timVisible) + self.timKeyValue.setVisible(timVisible) + self.wldKeyLabel.setVisible(wldVisible) + self.wldKeyValue.setVisible(wldVisible) + self.objKeyLabel.setVisible(objVisible) + self.objKeyValue.setVisible(objVisible) + self.entKeyLabel.setVisible(entVisible) + self.entKeyValue.setVisible(entVisible) + self.cstKeyLabel.setVisible(cstVisible) + self.cstKeyValue.setVisible(cstVisible) + return -# END Class GuiOutlineHeaderMenu + @staticmethod + def _formatTags(refs, key): + """Convert a list of tags into a list of clickable tag links. + """ + return ", ".join( + [f"{tag}" for tag in refs.get(key, [])] + ) + +# END Class GuiOutlineDetails diff --git a/novelwriter/gui/outlinedetails.py b/novelwriter/gui/outlinedetails.py deleted file mode 100644 index cc97cdf5..00000000 --- a/novelwriter/gui/outlinedetails.py +++ /dev/null @@ -1,349 +0,0 @@ -""" -novelWriter – GUI Project Outline Details -========================================= -GUI class for the project outline details panel - -File History: -Created: 2020-06-02 [0.7.0] - -This file is a part of novelWriter -Copyright 2018–2022, Veronica Berglyd Olsen - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - -import logging -import novelwriter - -from PyQt5.QtCore import Qt, QT_TRANSLATE_NOOP -from PyQt5.QtWidgets import ( - QScrollArea, QWidget, QGridLayout, QHBoxLayout, QGroupBox, QLabel -) - -from novelwriter.common import checkInt -from novelwriter.constants import trConst, nwKeyWords, nwLabels - -logger = logging.getLogger(__name__) - - -class GuiOutlineDetails(QScrollArea): - - LVL_MAP = { - "H1": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Title"), - "H2": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Chapter"), - "H3": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Scene"), - "H4": QT_TRANSLATE_NOOP("GuiOutlineDetails", "Section"), - } - - def __init__(self, theParent): - QScrollArea.__init__(self, theParent) - - logger.debug("Initialising GuiOutlineDetails ...") - - self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theProject = theParent.theProject - self.theTheme = theParent.theTheme - self.theIndex = theParent.theIndex - self.optState = theParent.theProject.optState - - # Sizes - minTitle = 30*self.theTheme.textNWidth - maxTitle = 40*self.theTheme.textNWidth - wCount = self.theTheme.getTextWidth("999,999") - hSpace = int(self.mainConf.pxInt(10)) - vSpace = int(self.mainConf.pxInt(4)) - - # Details Area - self.titleLabel = QLabel("%s" % self.tr("Title")) - self.fileLabel = QLabel("%s" % self.tr("Document")) - self.itemLabel = QLabel("%s" % self.tr("Status")) - self.titleValue = QLabel("") - self.fileValue = QLabel("") - self.itemValue = QLabel("") - - self.titleValue.setMinimumWidth(minTitle) - self.titleValue.setMaximumWidth(maxTitle) - self.fileValue.setMinimumWidth(minTitle) - self.fileValue.setMaximumWidth(maxTitle) - self.itemValue.setMinimumWidth(minTitle) - self.itemValue.setMaximumWidth(maxTitle) - - # Stats Area - self.cCLabel = QLabel("%s" % self.tr("Characters")) - self.wCLabel = QLabel("%s" % self.tr("Words")) - self.pCLabel = QLabel("%s" % self.tr("Paragraphs")) - self.cCValue = QLabel("") - self.wCValue = QLabel("") - self.pCValue = QLabel("") - - self.cCValue.setMinimumWidth(wCount) - self.wCValue.setMinimumWidth(wCount) - self.pCValue.setMinimumWidth(wCount) - self.cCValue.setAlignment(Qt.AlignRight) - self.wCValue.setAlignment(Qt.AlignRight) - self.pCValue.setAlignment(Qt.AlignRight) - - # Synopsis - self.synopLabel = QLabel("%s" % self.tr("Synopsis")) - self.synopValue = QLabel("") - self.synopLWrap = QHBoxLayout() - self.synopValue.setWordWrap(True) - self.synopValue.setAlignment(Qt.AlignTop | Qt.AlignLeft) - self.synopLWrap.addWidget(self.synopValue, 1) - - # Tags - self.povKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.POV_KEY])) - self.focKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.FOCUS_KEY])) - self.chrKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.CHAR_KEY])) - self.pltKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY])) - self.timKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.TIME_KEY])) - self.wldKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.WORLD_KEY])) - self.objKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.OBJECT_KEY])) - self.entKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.ENTITY_KEY])) - self.cstKeyLabel = QLabel("%s" % trConst(nwLabels.KEY_NAME[nwKeyWords.CUSTOM_KEY])) - - self.povKeyLWrap = QHBoxLayout() - self.focKeyLWrap = QHBoxLayout() - self.chrKeyLWrap = QHBoxLayout() - self.pltKeyLWrap = QHBoxLayout() - self.timKeyLWrap = QHBoxLayout() - self.wldKeyLWrap = QHBoxLayout() - self.objKeyLWrap = QHBoxLayout() - self.entKeyLWrap = QHBoxLayout() - self.cstKeyLWrap = QHBoxLayout() - - self.povKeyValue = QLabel("") - self.focKeyValue = QLabel("") - self.chrKeyValue = QLabel("") - self.pltKeyValue = QLabel("") - self.timKeyValue = QLabel("") - self.wldKeyValue = QLabel("") - self.objKeyValue = QLabel("") - self.entKeyValue = QLabel("") - self.cstKeyValue = QLabel("") - - self.povKeyValue.setWordWrap(True) - self.focKeyValue.setWordWrap(True) - self.chrKeyValue.setWordWrap(True) - self.pltKeyValue.setWordWrap(True) - self.timKeyValue.setWordWrap(True) - self.wldKeyValue.setWordWrap(True) - self.objKeyValue.setWordWrap(True) - self.entKeyValue.setWordWrap(True) - self.cstKeyValue.setWordWrap(True) - - self.povKeyValue.linkActivated.connect(self._tagClicked) - self.focKeyValue.linkActivated.connect(self._tagClicked) - self.chrKeyValue.linkActivated.connect(self._tagClicked) - self.pltKeyValue.linkActivated.connect(self._tagClicked) - self.timKeyValue.linkActivated.connect(self._tagClicked) - self.wldKeyValue.linkActivated.connect(self._tagClicked) - self.objKeyValue.linkActivated.connect(self._tagClicked) - self.entKeyValue.linkActivated.connect(self._tagClicked) - self.cstKeyValue.linkActivated.connect(self._tagClicked) - - self.povKeyLWrap.addWidget(self.povKeyValue, 1) - self.focKeyLWrap.addWidget(self.focKeyValue, 1) - self.chrKeyLWrap.addWidget(self.chrKeyValue, 1) - self.pltKeyLWrap.addWidget(self.pltKeyValue, 1) - self.timKeyLWrap.addWidget(self.timKeyValue, 1) - self.wldKeyLWrap.addWidget(self.wldKeyValue, 1) - self.objKeyLWrap.addWidget(self.objKeyValue, 1) - self.entKeyLWrap.addWidget(self.entKeyValue, 1) - self.cstKeyLWrap.addWidget(self.cstKeyValue, 1) - - # Selected Item Details - self.mainGroup = QGroupBox(self.tr("Title Details"), self) - self.mainForm = QGridLayout() - self.mainGroup.setLayout(self.mainForm) - - self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) - self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) - self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, Qt.AlignTop | Qt.AlignRight) - self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft) - self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, Qt.AlignTop | Qt.AlignLeft) - - self.mainForm.setColumnStretch(1, 1) - self.mainForm.setRowStretch(4, 1) - self.mainForm.setHorizontalSpacing(hSpace) - self.mainForm.setVerticalSpacing(vSpace) - - # Selected Item Tags - self.tagsGroup = QGroupBox(self.tr("Reference Tags"), self) - self.tagsForm = QGridLayout() - self.tagsGroup.setLayout(self.tagsForm) - - self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft) - self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, Qt.AlignTop | Qt.AlignLeft) - - self.tagsForm.setColumnStretch(1, 1) - self.tagsForm.setRowStretch(8, 1) - self.tagsForm.setHorizontalSpacing(hSpace) - self.tagsForm.setVerticalSpacing(vSpace) - - # Assemble - self.outerWidget = QWidget() - self.outerBox = QHBoxLayout() - self.outerBox.addWidget(self.mainGroup, 0) - self.outerBox.addWidget(self.tagsGroup, 1) - - self.outerWidget.setLayout(self.outerBox) - self.setWidget(self.outerWidget) - - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - self.setWidgetResizable(True) - - self.initDetails() - - logger.debug("GuiOutlineDetails initialisation complete") - - return - - def initDetails(self): - """Set or update outline settings. - """ - # Scroll bars - if self.mainConf.hideVScroll: - self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - else: - self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) - - if self.mainConf.hideHScroll: - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) - else: - self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) - - return - - def clearDetails(self): - """Clear all the data labels. - """ - self.titleLabel.setText("%s" % self.tr("Title")) - self.titleValue.setText("") - self.fileValue.setText("") - self.itemValue.setText("") - self.cCValue.setText("") - self.wCValue.setText("") - self.pCValue.setText("") - self.synopValue.setText("") - self.povKeyValue.setText("") - self.focKeyValue.setText("") - self.chrKeyValue.setText("") - self.pltKeyValue.setText("") - self.timKeyValue.setText("") - self.wldKeyValue.setText("") - self.objKeyValue.setText("") - self.entKeyValue.setText("") - self.cstKeyValue.setText("") - return - - def showItem(self, tHandle, sTitle): - """Update the content of the tree with the given handle and line - number pointing to a header. - """ - nwItem = self.theProject.projTree[tHandle] - novIdx = self.theIndex.getNovelData(tHandle, sTitle) - theRefs = self.theIndex.getReferences(tHandle, sTitle) - if nwItem is None or novIdx is None: - return False - - if novIdx["level"] in self.LVL_MAP: - self.titleLabel.setText("%s" % self.tr(self.LVL_MAP[novIdx["level"]])) - else: - self.titleLabel.setText("%s" % self.tr("Title")) - self.titleValue.setText(novIdx["title"]) - - self.fileValue.setText(nwItem.itemName) - self.itemValue.setText(nwItem.itemStatus) - - cC = checkInt(novIdx["cCount"], 0) - wC = checkInt(novIdx["wCount"], 0) - pC = checkInt(novIdx["pCount"], 0) - - self.cCValue.setText(f"{cC:n}") - self.wCValue.setText(f"{wC:n}") - self.pCValue.setText(f"{pC:n}") - - self.synopValue.setText(novIdx["synopsis"]) - - self.povKeyValue.setText(self._formatTags(theRefs, nwKeyWords.POV_KEY)) - self.focKeyValue.setText(self._formatTags(theRefs, nwKeyWords.FOCUS_KEY)) - self.chrKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CHAR_KEY)) - self.pltKeyValue.setText(self._formatTags(theRefs, nwKeyWords.PLOT_KEY)) - self.timKeyValue.setText(self._formatTags(theRefs, nwKeyWords.TIME_KEY)) - self.wldKeyValue.setText(self._formatTags(theRefs, nwKeyWords.WORLD_KEY)) - self.objKeyValue.setText(self._formatTags(theRefs, nwKeyWords.OBJECT_KEY)) - self.entKeyValue.setText(self._formatTags(theRefs, nwKeyWords.ENTITY_KEY)) - self.cstKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CUSTOM_KEY)) - - return True - - ## - # Slots - ## - - def _tagClicked(self, theLink): - """Capture the click of a tag in the right-most column. - """ - logger.verbose("Clicked link: '%s'", theLink) - if len(theLink) > 0: - theBits = theLink.split("=") - if len(theBits) == 2: - self.theParent.docViewer.loadFromTag(theBits[1]) - return - - ## - # Internal Functions - ## - - def _formatTags(self, theRefs, theKey): - """Format the tags as clickable links. - """ - if theKey not in theRefs: - return "" - refTags = [] - for tTag in theRefs[theKey]: - refTags.append("%s" % ( - theKey[1:], tTag, tTag - )) - return ", ".join(refTags) - -# END Class GuiOutlineDetails diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 9f55cbe4..e6acd81d 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -5,7 +5,8 @@ GUI classes for the main window project tree File History: Created: 2018-09-29 [0.0.1] GuiProjectTree -Created: 2020-06-04 [0.7] GuiProjectTreeMenu +Created: 2022-06-06 [1.7b1] GuiProjectView +Created: 2022-06-06 [1.7b1] GuiProjectToolBar This file is a part of novelWriter Copyright 2018–2022, Veronica Berglyd Olsen @@ -27,21 +28,291 @@ along with this program. If not, see . import logging import novelwriter +from enum import Enum from time import time +from PyQt5.QtGui import QPalette from PyQt5.QtCore import Qt, QSize, pyqtSignal, pyqtSlot -from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import ( - QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction + QAbstractItemView, QFrame, QHBoxLayout, QHeaderView, QLabel, + QMenu, QShortcut, QSizePolicy, QToolButton, QTreeWidget, QTreeWidgetItem, + QVBoxLayout, QWidget ) from novelwriter.core import NWDoc -from novelwriter.enum import nwItemType, nwItemClass, nwItemLayout, nwAlert -from novelwriter.constants import nwConst, trConst, nwLists, nwLabels +from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout, nwAlert +from novelwriter.constants import nwHeaders, trConst, nwLabels +from novelwriter.dialogs.editlabel import GuiEditLabel logger = logging.getLogger(__name__) +class GuiProjectView(QWidget): + """This is a wrapper class holding all the elements of the project + tree. The core object is the project tree itself. Most methods + available are mapped through to the project tree class. + """ + + # Signals triggered when the meta data values of items change + treeItemChanged = pyqtSignal(str) + rootFolderChanged = pyqtSignal(str) + wordCountsChanged = pyqtSignal() + + # Signals for user interaction with the project tree + selectedItemChanged = pyqtSignal(str) + openDocumentRequest = pyqtSignal(str, Enum, int, str) + + def __init__(self, mainGui): + QWidget.__init__(self, mainGui) + + self.mainGui = mainGui + + # Build GUI + self.projTree = GuiProjectTree(self) + self.projBar = GuiProjectToolBar(self) + + # Assemble + self.outerBox = QVBoxLayout() + self.outerBox.addWidget(self.projBar, 0) + self.outerBox.addWidget(self.projTree, 1) + self.outerBox.setContentsMargins(0, 0, 0, 0) + self.outerBox.setSpacing(0) + + self.setLayout(self.outerBox) + + # Keyboard Shortcuts + self.keyMoveUp = QShortcut(self.projTree) + self.keyMoveUp.setKey("Ctrl+Up") + self.keyMoveUp.setContext(Qt.WidgetShortcut) + self.keyMoveUp.activated.connect(lambda: self.projTree.moveTreeItem(-1)) + + self.keyMoveDn = QShortcut(self.projTree) + self.keyMoveDn.setKey("Ctrl+Down") + self.keyMoveDn.setContext(Qt.WidgetShortcut) + self.keyMoveDn.activated.connect(lambda: self.projTree.moveTreeItem(1)) + + self.keyUndoMv = QShortcut(self.projTree) + self.keyUndoMv.setKey("Ctrl+Shift+Z") + self.keyUndoMv.setContext(Qt.WidgetShortcut) + self.keyUndoMv.activated.connect(lambda: self.projTree.undoLastMove()) + + self.keyContext = QShortcut(self.projTree) + self.keyContext.setKey("Ctrl+.") + self.keyContext.setContext(Qt.WidgetShortcut) + self.keyContext.activated.connect(lambda: self.projTree.openContextOnSelected()) + + # Function Mappings + self.revealNewTreeItem = self.projTree.revealNewTreeItem + self.renameTreeItem = self.projTree.renameTreeItem + self.getTreeFromHandle = self.projTree.getTreeFromHandle + self.emptyTrash = self.projTree.emptyTrash + self.deleteItem = self.projTree.deleteItem + self.setTreeItemValues = self.projTree.setTreeItemValues + self.propagateCount = self.projTree.propagateCount + self.getSelectedHandle = self.projTree.getSelectedHandle + self.setSelectedHandle = self.projTree.setSelectedHandle + self.changedSince = self.projTree.changedSince + + return + + ## + # Methods + ## + + def initSettings(self): + self.projTree.initSettings() + return + + def clearProject(self): + self.projTree.clearTree() + return + + def saveProjectTree(self): + self.projTree.saveTreeOrder() + return + + def populateTree(self): + self.projTree.buildTree() + return + + def setFocus(self): + """Forward the set focus call to the tree widget. + """ + self.projTree.setFocus() + return + + def treeHasFocus(self): + """Check if the project tree has focus. + """ + return self.projTree.hasFocus() + + ## + # Public Slots + ## + + @pyqtSlot(str, int, int, int) + def updateCounts(self, tHandle, cCount, wCount, pCount): + """Slot for updating the word count of a specific item. + """ + self.projTree.propagateCount(tHandle, wCount, countChildren=True) + self.wordCountsChanged.emit() + return + +# END Class GuiProjectView + + +class GuiProjectToolBar(QWidget): + + def __init__(self, projView): + QTreeWidget.__init__(self, projView) + + logger.debug("Initialising GuiProjectToolBar ...") + + self.mainConf = novelwriter.CONFIG + self.projView = projView + self.projTree = projView.projTree + self.mainGui = projView.mainGui + self.theProject = projView.mainGui.theProject + self.mainTheme = projView.mainGui.mainTheme + + iPx = self.mainTheme.baseIconSize + mPx = self.mainConf.pxInt(2) + + self.setContentsMargins(0, 0, 0, 0) + self.setAutoFillBackground(True) + + qPalette = self.palette() + qPalette.setBrush(QPalette.Window, qPalette.base()) + self.setPalette(qPalette) + + fadeCol = qPalette.text().color() + buttonStyle = ( + "QToolButton {{padding: {0}px; border: none; background: transparent;}} " + "QToolButton:hover {{border: none; background: rgba({1},{2},{3},0.2);}}" + ).format(mPx, fadeCol.red(), fadeCol.green(), fadeCol.blue()) + + # Widget Label + self.viewLabel = QLabel("%s" % self.tr("Project Content")) + self.viewLabel.setContentsMargins(0, 0, 0, 0) + self.viewLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + + # Move Buttons + self.tbMoveU = QToolButton(self) + self.tbMoveU.setToolTip("%s [Ctrl+Up]" % self.tr("Move Up")) + self.tbMoveU.setIcon(self.mainTheme.getIcon("up")) + self.tbMoveU.setIconSize(QSize(iPx, iPx)) + self.tbMoveU.setStyleSheet(buttonStyle) + self.tbMoveU.clicked.connect(lambda: self.projTree.moveTreeItem(-1)) + + self.tbMoveD = QToolButton(self) + self.tbMoveD.setToolTip("%s [Ctrl+Down]" % self.tr("Move Down")) + self.tbMoveD.setIcon(self.mainTheme.getIcon("down")) + self.tbMoveD.setIconSize(QSize(iPx, iPx)) + self.tbMoveD.setStyleSheet(buttonStyle) + self.tbMoveD.clicked.connect(lambda: self.projTree.moveTreeItem(1)) + + # Add Item Menu + self.mAdd = QMenu() + + self.aAddEmpty = self.mAdd.addAction(trConst(nwLabels.ITEM_DESCRIPTION["document"])) + self.aAddEmpty.setIcon(self.mainTheme.getIcon("proj_document")) + self.aAddEmpty.triggered.connect( + lambda: self.projTree.newTreeItem(nwItemType.FILE, hLevel=0, isNote=False) + ) + + self.aAddChap = self.mAdd.addAction(trConst(nwLabels.ITEM_DESCRIPTION["doc_h2"])) + self.aAddChap.setIcon(self.mainTheme.getIcon("proj_chapter")) + self.aAddChap.triggered.connect( + lambda: self.projTree.newTreeItem(nwItemType.FILE, hLevel=2, isNote=False) + ) + + self.aAddScene = self.mAdd.addAction(trConst(nwLabels.ITEM_DESCRIPTION["doc_h3"])) + self.aAddScene.setIcon(self.mainTheme.getIcon("proj_scene")) + self.aAddScene.triggered.connect( + lambda: self.projTree.newTreeItem(nwItemType.FILE, hLevel=3, isNote=False) + ) + + self.aAddNote = self.mAdd.addAction(trConst(nwLabels.ITEM_DESCRIPTION["note"])) + self.aAddNote.setIcon(self.mainTheme.getIcon("proj_note")) + self.aAddNote.triggered.connect( + lambda: self.projTree.newTreeItem(nwItemType.FILE, hLevel=1, isNote=True) + ) + + self.aAddFolder = self.mAdd.addAction(trConst(nwLabels.ITEM_DESCRIPTION["folder"])) + self.aAddFolder.setIcon(self.mainTheme.getIcon("proj_folder")) + self.aAddFolder.triggered.connect( + lambda: self.projTree.newTreeItem(nwItemType.FOLDER) + ) + + self.mAddRoot = self.mAdd.addMenu(trConst(nwLabels.ITEM_DESCRIPTION["root"])) + self._addRootFolderEntry(nwItemClass.NOVEL) + self._addRootFolderEntry(nwItemClass.ARCHIVE) + self.mAddRoot.addSeparator() + self._addRootFolderEntry(nwItemClass.PLOT) + self._addRootFolderEntry(nwItemClass.CHARACTER) + self._addRootFolderEntry(nwItemClass.WORLD) + self._addRootFolderEntry(nwItemClass.TIMELINE) + self._addRootFolderEntry(nwItemClass.OBJECT) + self._addRootFolderEntry(nwItemClass.ENTITY) + self._addRootFolderEntry(nwItemClass.CUSTOM) + + self.tbAdd = QToolButton(self) + self.tbAdd.setToolTip("%s [Ctrl+N]" % self.tr("Add Item")) + self.tbAdd.setShortcut("Ctrl+N") + self.tbAdd.setIcon(self.mainTheme.getIcon("add")) + self.tbAdd.setIconSize(QSize(iPx, iPx)) + self.tbAdd.setStyleSheet(buttonStyle) + self.tbAdd.setMenu(self.mAdd) + self.tbAdd.setPopupMode(QToolButton.InstantPopup) + + # More Options Menu + self.mMore = QMenu() + + self.aMoreUndo = self.mMore.addAction(self.tr("Undo Move")) + self.aMoreUndo.triggered.connect(lambda: self.projTree.undoLastMove()) + + self.aEmptyTrash = self.mMore.addAction(self.tr("Empty Trash")) + self.aEmptyTrash.triggered.connect(lambda: self.projTree.emptyTrash()) + + self.tbMore = QToolButton(self) + self.tbMore.setToolTip(self.tr("More Options")) + self.tbMore.setIcon(self.mainTheme.getIcon("menu")) + self.tbMore.setIconSize(QSize(iPx, iPx)) + self.tbMore.setStyleSheet(buttonStyle) + self.tbMore.setMenu(self.mMore) + self.tbMore.setPopupMode(QToolButton.InstantPopup) + + # Assemble + self.outerBox = QHBoxLayout() + self.outerBox.addWidget(self.viewLabel) + self.outerBox.addWidget(self.tbMoveU) + self.outerBox.addWidget(self.tbMoveD) + self.outerBox.addWidget(self.tbAdd) + self.outerBox.addWidget(self.tbMore) + self.outerBox.setContentsMargins(mPx, mPx, 0, mPx) + self.outerBox.setSpacing(0) + + self.setLayout(self.outerBox) + + logger.debug("GuiProjectToolBar initialisation complete") + + return + + ## + # Internal Functions + ## + + def _addRootFolderEntry(self, itemClass): + """Add a menu entry for a root folder of a given class. + """ + aNew = self.mAddRoot.addAction(trConst(nwLabels.CLASS_NAME[itemClass])) + aNew.setIcon(self.mainTheme.getIcon(nwLabels.CLASS_ICON[itemClass])) + aNew.triggered.connect(lambda: self.projTree.newTreeItem(nwItemType.ROOT, itemClass)) + self.mAddRoot.addAction(aNew) + +# END Class GuiProjectToolBar + + class GuiProjectTree(QTreeWidget): C_NAME = 0 @@ -49,59 +320,53 @@ class GuiProjectTree(QTreeWidget): C_EXPORT = 2 C_STATUS = 3 - novelItemChanged = pyqtSignal() - noteItemChanged = pyqtSignal() - wordCountsChanged = pyqtSignal() - - def __init__(self, theParent): - QTreeWidget.__init__(self, theParent) + def __init__(self, projView): + QTreeWidget.__init__(self, projView) logger.debug("Initialising GuiProjectTree ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject - self.theIndex = theParent.theIndex + self.projView = projView + self.mainGui = projView.mainGui + self.mainTheme = projView.mainGui.mainTheme + self.theProject = projView.mainGui.theProject # Internal Variables - self._treeMap = {} - self._treeChanged = False + self._treeMap = {} + self._lastMove = {} self._timeChanged = 0 - self._lastMove = {} - ## - # Build GUI - ## + # Build GUI + # ========= # Context Menu - self.ctxMenu = GuiProjectTreeMenu(self) self.setContextMenuPolicy(Qt.CustomContextMenu) - self.customContextMenuRequested.connect(self._rightClickMenu) + self.customContextMenuRequested.connect(self._openContextMenu) # Tree Settings - iPx = self.theTheme.baseIconSize + iPx = self.mainTheme.baseIconSize + cMg = self.mainConf.pxInt(6) + self.setIconSize(QSize(iPx, iPx)) - self.setExpandsOnDoubleClick(True) + self.setFrameStyle(QFrame.NoFrame) + self.setUniformRowHeights(True) + self.setAllColumnsShowFocus(True) + self.setExpandsOnDoubleClick(False) + self.setAutoExpandDelay(1000) + self.setHeaderHidden(True) self.setIndentation(iPx) self.setColumnCount(4) - self.setHeaderLabels([ - self.tr("Project Tree"), self.tr("Words"), "", "" - ]) - treeHeadItem = self.headerItem() - treeHeadItem.setTextAlignment(self.C_COUNT, Qt.AlignRight) - treeHeadItem.setToolTip(self.C_NAME, self.tr("Item label")) - treeHeadItem.setToolTip(self.C_COUNT, self.tr("Word count")) - treeHeadItem.setToolTip(self.C_EXPORT, self.tr("Include in build")) - treeHeadItem.setToolTip(self.C_STATUS, self.tr("Item status")) - - # Let the last column stretch, and set the minimum size to the - # size of the icon as the default Qt font metrics approach fails - # for some fonts like the Ubuntu font. + # Lock the column sizes treeHeader = self.header() - treeHeader.setStretchLastSection(True) - treeHeader.setMinimumSectionSize(iPx + 6) + treeHeader.setStretchLastSection(False) + treeHeader.setMinimumSectionSize(iPx + cMg) + treeHeader.setSectionResizeMode(self.C_NAME, QHeaderView.Stretch) + treeHeader.setSectionResizeMode(self.C_COUNT, QHeaderView.ResizeToContents) + treeHeader.setSectionResizeMode(self.C_EXPORT, QHeaderView.Fixed) + treeHeader.setSectionResizeMode(self.C_STATUS, QHeaderView.Fixed) + treeHeader.resizeSection(self.C_EXPORT, iPx + cMg) + treeHeader.resizeSection(self.C_STATUS, iPx + cMg) # Allow Move by Drag & Drop self.setDragEnabled(True) @@ -116,23 +381,18 @@ class GuiProjectTree(QTreeWidget): # self.setSelectionMode(QAbstractItemView.ExtendedSelection) self.setSelectionBehavior(QAbstractItemView.SelectRows) - # Get user's column width preferences for NAME and COUNT - treeColWidth = self.mainConf.getTreeColWidths() - if len(treeColWidth) <= 4: - for colN, colW in enumerate(treeColWidth): - self.setColumnWidth(colN, colW) - - # The last column should just auto-scale - self.resizeColumnToContents(self.C_STATUS) + # Connect signals + self.itemDoubleClicked.connect(self._treeDoubleClick) + self.itemSelectionChanged.connect(self._treeSelectionChange) # Set custom settings - self.initTree() + self.initSettings() logger.debug("GuiProjectTree initialisation complete") return - def initTree(self): + def initSettings(self): """Set or update tree widget settings. """ # Scroll bars @@ -157,159 +417,118 @@ class GuiProjectTree(QTreeWidget): """ self.clear() self._treeMap = {} - self._treeChanged = False + self._lastMove = {} self._timeChanged = 0 return - def newTreeItem(self, itemType, itemClass): - """Add new item to the tree, with a given itemType and - itemClass, and attach it to the selected handle. Also make sure - the item is added in a place it can be added, and that other - meta data is set correctly to ensure a valid project tree. + def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False): + """Add new item to the tree, with a given itemType (and + itemClass if Root), and attach it to the selected handle. Also + make sure the item is added in a place it can be added, and that + other meta data is set correctly to ensure a valid project tree. """ - pHandle = self.getSelectedHandle() - nHandle = None - - if not self.theParent.hasProject: + if not self.mainGui.hasProject: logger.error("No project open") return False - if not isinstance(itemType, nwItemType): - # This would indicate an internal bug - logger.error("No itemType provided") - return False + nHandle = None + tHandle = None - # The item needs to be assigned an item class, so one must be - # provided, or it must be possible to extract it from the parent - # item of the new item. - if itemClass is None and pHandle is not None: - pItem = self.theProject.projTree[pHandle] - if pItem is not None: - itemClass = pItem.itemClass + if itemType == nwItemType.ROOT and isinstance(itemClass, nwItemClass): - # If class is still not set, alert the user and exit - if itemClass is None: - if itemType == nwItemType.FILE: - self.theParent.makeAlert(self.tr( - "Please select a valid location in the tree to add the document." - ), nwAlert.ERROR) - else: - self.theParent.makeAlert(self.tr( - "Please select a valid location in the tree to add the folder." - ), nwAlert.ERROR) - return False + tHandle = self.theProject.newRoot(itemClass) - # Everything is fine, we have what we need, so we proceed - logger.verbose( - "Adding new item of type '%s' and class '%s' to handle '%s'", - itemType.name, itemClass.name, str(pHandle) - ) + elif itemType in (nwItemType.FILE, nwItemType.FOLDER): - if itemType == nwItemType.ROOT: - tHandle = self.theProject.newRoot( - trConst(nwLabels.CLASS_NAME[itemClass]), itemClass - ) - if tHandle is None: - logger.error("No root item added") - return False - - else: - # If no parent has been selected, make the new file under - # the root NOVEL item. - if pHandle is None: - pHandle = self.theProject.projTree.findRoot(nwItemClass.NOVEL) - - # If still nothing, give up - if pHandle is None: - self.theParent.makeAlert(self.tr( + sHandle = self.getSelectedHandle() + if sHandle is None or sHandle not in self.theProject.tree: + self.mainGui.makeAlert(self.tr( "Did not find anywhere to add the file or folder!" ), nwAlert.ERROR) return False - # Now check if the selected item is a file, in which case - # the new file will be a sibling - pItem = self.theProject.projTree[pHandle] - if pItem.itemType == nwItemType.FILE: - nHandle = pHandle - pHandle = pItem.itemParent + # Collect some information about the selected item that + pItem = self.theProject.tree[sHandle] + qItem = self._getTreeItem(sHandle) + sLevel = nwHeaders.H_LEVEL.get(self.theProject.index.getHandleHeaderLevel(sHandle), 0) + sIsParent = False if qItem is None else qItem.childCount() > 0 - # If we again have no home, give up - if pHandle is None: - self.theParent.makeAlert(self.tr( - "Did not find anywhere to add the file or folder!" - ), nwAlert.ERROR) - return False - - if self.theProject.projTree.isTrashRoot(pHandle): - self.theParent.makeAlert(self.tr( + if self.theProject.tree.isTrash(sHandle): + self.mainGui.makeAlert(self.tr( "Cannot add new files or folders to the Trash folder." ), nwAlert.ERROR) return False - parTree = self.theProject.projTree.getItemPath(pHandle) - - # If we're still here, add the file or folder + # Set default label and determine if new item is to be added + # as child or sibling to the selected item if itemType == nwItemType.FILE: - tHandle = self.theProject.newFile(self.tr("New File"), itemClass, pHandle) - - elif itemType == nwItemType.FOLDER: - if len(parTree) >= nwConst.MAX_DEPTH - 1: - # Folders cannot be deeper than MAX_DEPTH - 1, leaving room - # for one more level of files. - self.theParent.makeAlert(self.tr( - "Cannot add new folder to this item. " - "Maximum folder depth has been reached." - ), nwAlert.ERROR) - return False - tHandle = self.theProject.newFolder(self.tr("New Folder"), itemClass, pHandle) - + if isNote: + newLabel = self.tr("New Note") + asChild = sIsParent + elif hLevel == 2: + newLabel = self.tr("New Chapter") + asChild = sIsParent and pItem.isDocumentLayout() and sLevel < 2 + elif hLevel == 3: + newLabel = self.tr("New Scene") + asChild = sIsParent and pItem.isDocumentLayout() and sLevel < 3 + else: + newLabel = self.tr("New Document") + asChild = sIsParent and pItem.isDocumentLayout() else: - logger.error("Failed to add new item") + newLabel = self.tr("New Folder") + asChild = False + + if not (asChild or pItem.isFolderType() or pItem.isRootType()): + # Move to the parent item so that the new item is added + # as a sibling instead + nHandle = sHandle + sHandle = pItem.itemParent + if sHandle is None: + # Bug: We have a condition that is unhandled + logger.error("Internal error") + return False + + # Ask for label + newLabel, dlgOk = GuiEditLabel.getLabel(self, text=newLabel) + if not dlgOk: + logger.info("New item creation cancelled by user") return False - # If there is no handle set, return here - if tHandle is None: - return True - - # Add the new item to the tree - self.revealNewTreeItem(tHandle, nHandle) - self.theParent.editItem(tHandle) - nwItem = self.theProject.projTree[tHandle] - - # If this is a folder, return here - if nwItem.itemType != nwItemType.FILE: - return True - - # This is a new files, so let's add some content - newDoc = NWDoc(self.theProject, tHandle) - curTxt = newDoc.readDocument() - if curTxt is None: - curTxt = "" - - if curTxt == "": - if nwItem.itemLayout == nwItemLayout.DOCUMENT: - newText = f"### {nwItem.itemName}\n\n" + # Add the file or folder + if itemType == nwItemType.FILE: + tHandle = self.theProject.newFile(newLabel, sHandle) else: - newText = f"# {nwItem.itemName}\n\n" + tHandle = self.theProject.newFolder(newLabel, sHandle) - # Save the text and index it - newDoc.writeDocument(newText) - self.theIndex.scanText(tHandle, newText) + else: + logger.error("Failed to add new item") + return False - # Get Word Counts - cC, wC, pC = self.theIndex.getCounts(tHandle) - nwItem.setCharCount(cC) - nwItem.setWordCount(wC) - nwItem.setParaCount(pC) - self.propagateCount(tHandle, wC) - self.wordCountsChanged.emit() + # If there is no handle set, return here. This is a bug. + if tHandle is None: # pragma: no cover + logger.error("Internal error") + return True + + # Handle new file creation + if itemType == nwItemType.FILE and hLevel > 0: + if self.theProject.writeNewFile(tHandle, hLevel, not isNote): + # If successful, update word count + wC = self.theProject.index.getCounts(tHandle)[1] + self.propagateCount(tHandle, wC) + self.projView.wordCountsChanged.emit() + + # Add the new item to the project tree + self.revealNewTreeItem(tHandle, nHandle) return True def revealNewTreeItem(self, tHandle, nHandle=None): """Reveal a newly added project item in the project tree. """ - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] + if nwItem is None: + return False + trItem = self._addTreeItem(nwItem, nHandle) if trItem is None: return False @@ -318,55 +537,68 @@ class GuiProjectTree(QTreeWidget): if pHandle is not None and pHandle in self._treeMap: self._treeMap[pHandle].setExpanded(True) - self._emitItemChange(tHandle) + self._alertTreeChange(tHandle=tHandle, flush=True) self.clearSelection() trItem.setSelected(True) return True def moveTreeItem(self, nStep): - """Move an item up or down in the tree, but only if the treeView - has focus. This also applies when the menu is used. + """Move an item up or down in the tree. """ - if not self.theParent.hasProject: - logger.error("No project open") - return False - - if not self.hasFocus(): - return False - tHandle = self.getSelectedHandle() - tItem = self._getTreeItem(tHandle) - if tItem is None: + trItem = self._getTreeItem(tHandle) + if trItem is None: + logger.verbose("No item selected") return False - pItem = tItem.parent() + pItem = trItem.parent() + isExp = trItem.isExpanded() if pItem is None: - tIndex = self.indexOfTopLevelItem(tItem) + tIndex = self.indexOfTopLevelItem(trItem) nChild = self.topLevelItemCount() + nIndex = tIndex + nStep if nIndex < 0 or nIndex >= nChild: return False + cItem = self.takeTopLevelItem(tIndex) self.insertTopLevelItem(nIndex, cItem) else: - tIndex = pItem.indexOfChild(tItem) + tIndex = pItem.indexOfChild(trItem) nChild = pItem.childCount() + nIndex = tIndex + nStep if nIndex < 0 or nIndex >= nChild: return False + cItem = pItem.takeChild(tIndex) pItem.insertChild(nIndex, cItem) self._recordLastMove(cItem, pItem, tIndex) + self._alertTreeChange(tHandle=tHandle, flush=True) self.clearSelection() - cItem.setSelected(True) - self._setTreeChanged(True) - self._emitItemChange(tHandle) + trItem.setSelected(True) + trItem.setExpanded(isExp) return True + def renameTreeItem(self, tHandle): + """Open a dialog to edit the label of an item. + """ + tItem = self.theProject.tree[tHandle] + if tItem is None: + return False + + newLabel, dlgOk = GuiEditLabel.getLabel(self, text=tItem.itemName) + if dlgOk: + tItem.setName(newLabel) + self.setTreeItemValues(tHandle) + self._alertTreeChange(tHandle=tHandle, flush=False) + + return + def saveTreeOrder(self): """Build a list of the items in the project tree and send them to the project class. This syncs up the two versions of the @@ -380,19 +612,9 @@ class GuiProjectTree(QTreeWidget): self.theProject.setTreeOrder(theList) return True - def flushTreeOrder(self): - """Calls saveTreeOrder if there are unsaved changes, otherwise - does nothing. - """ - if self._treeChanged: - logger.verbose("Flushing project tree to project class") - self.saveTreeOrder() - self._setTreeChanged(False) - return - def getTreeFromHandle(self, tHandle): - """Recursively return all the children items starting from a - given item handle. + """Recursively return all the child items starting from a given + item handle. """ theList = [] theItem = self._getTreeItem(tHandle) @@ -400,30 +622,20 @@ class GuiProjectTree(QTreeWidget): theList = self._scanChildren(theList, theItem, 0) return theList - def getColumnSizes(self): - """Return the column widths for the tree columns. - """ - retVals = [ - self.columnWidth(0), - self.columnWidth(1), - self.columnWidth(2), - ] - return retVals - def emptyTrash(self): """Permanently delete all documents in the Trash folder. This function only asks for confirmation once, and calls the regular deleteItem function for each document in the Trash folder. """ - if not self.theParent.hasProject: + if not self.mainGui.hasProject: logger.error("No project open") return False - trashHandle = self.theProject.projTree.trashRoot() + trashHandle = self.theProject.tree.trashRoot() logger.debug("Emptying Trash folder") if trashHandle is None: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "There is currently no Trash folder in this project." ), nwAlert.INFO) return False @@ -434,12 +646,12 @@ class GuiProjectTree(QTreeWidget): nTrash = len(theTrash) if nTrash == 0: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "The Trash folder is already empty." ), nwAlert.INFO) return False - msgYes = self.theParent.askQuestion( + msgYes = self.mainGui.askQuestion( self.tr("Empty Trash"), self.tr("Permanently delete {0} file(s) from Trash?").format(nTrash) ) @@ -447,13 +659,13 @@ class GuiProjectTree(QTreeWidget): return False logger.verbose("Deleting %d file(s) from Trash", nTrash) - for tHandle in self.getTreeFromHandle(trashHandle): + for tHandle in reversed(self.getTreeFromHandle(trashHandle)): if tHandle == trashHandle: continue self.deleteItem(tHandle, alreadyAsked=True, bulkAction=True) if nTrash > 0: - self._setTreeChanged(True) + self._alertTreeChange(tHandle=trashHandle, flush=True) return True @@ -461,10 +673,10 @@ class GuiProjectTree(QTreeWidget): """Delete an item from the project tree. As a first step, files are moved to the Trash folder. Permanent deletion is a second step. This second step also deletes the item from the project object as well as - delete the files on disk. Folders are deleted if they're empty only, - and the deletion is always permanent. + delete the files on disk. Root folders are deleted if they're empty + only, and the deletion is always permanent. """ - if not self.theParent.hasProject: + if not self.mainGui.hasProject: logger.error("No project open") return False @@ -480,30 +692,56 @@ class GuiProjectTree(QTreeWidget): return False trItemS = self._getTreeItem(tHandle) - nwItemS = self.theProject.projTree[tHandle] + nwItemS = self.theProject.tree[tHandle] if trItemS is None or nwItemS is None: logger.error("Could not find tree item for deletion") return False - wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole)) - if nwItemS.itemType == nwItemType.FILE: - logger.debug("User requested file '%s' deleted", tHandle) + wCount = self._getItemWordCount(tHandle) + autoFlush = not bulkAction + if nwItemS.isRootType(): + # Only an empty ROOT folder can be deleted + logger.debug("User requested a root folder '%s' deleted", tHandle) + tIndex = self.indexOfTopLevelItem(trItemS) + if trItemS.childCount() == 0: + self.takeTopLevelItem(tIndex) + self._deleteTreeItem(tHandle) + self._alertTreeChange(tHandle=tHandle, flush=True) + else: + self.mainGui.makeAlert(self.tr( + "Cannot delete root folder. It is not empty. " + "Recursive deletion is not supported. " + "Please delete the content first." + ), nwAlert.ERROR) + return False + + elif nwItemS.isFolderType() and trItemS.childCount() == 0: + # An empty FOLDER is just deleted without any further checks + logger.debug("User requested an empty folder '%s' deleted", tHandle) + trItemP = trItemS.parent() + tIndex = trItemP.indexOfChild(trItemS) + trItemP.takeChild(tIndex) + self._deleteTreeItem(tHandle) + self._alertTreeChange(tHandle=tHandle, flush=autoFlush) + + else: + # A populated FOLDER or a FILE requires confirmtation + logger.debug("User requested a file or folder '%s' deleted", tHandle) trItemP = trItemS.parent() trItemT = self._addTrashRoot() if trItemP is None or trItemT is None: logger.error("Could not delete item") return False - pHandle = nwItemS.itemParent - if self.theProject.projTree.isTrashRoot(pHandle): + if self.theProject.tree.isTrash(tHandle): # If the file is in the trash folder already, as the # user if they want to permanently delete the file. doPermanent = False if not alreadyAsked: - msgYes = self.theParent.askQuestion( - self.tr("Delete File"), - self.tr("Permanently delete file '{0}'?").format(nwItemS.itemName) + msgYes = self.mainGui.askQuestion( + self.tr("Delete"), + self.tr("Permanently delete '{0}'?").format(nwItemS.itemName) ) if msgYes: doPermanent = True @@ -511,85 +749,36 @@ class GuiProjectTree(QTreeWidget): doPermanent = True if doPermanent: - logger.debug("Permanently deleting file with handle '%s'", tHandle) + logger.debug("Permanently deleting item with handle '%s'", tHandle) self.propagateCount(tHandle, 0) tIndex = trItemP.indexOfChild(trItemS) trItemC = trItemP.takeChild(tIndex) + for dHandle in reversed(self.getTreeFromHandle(tHandle)): + if self.mainGui.docEditor.docHandle() == dHandle: + self.mainGui.closeDocument() + self._deleteTreeItem(dHandle) - if self.theParent.docEditor.docHandle() == tHandle: - self.theParent.closeDocument() - - delDoc = NWDoc(self.theProject, tHandle) - if not delDoc.deleteDocument(): - self.theParent.makeAlert([ - self.tr("Could not delete document file."), delDoc.getError() - ], nwAlert.ERROR) - return False - - self.theIndex.deleteHandle(tHandle) - self._deleteTreeItem(tHandle) - self._setTreeChanged(True) - self.wordCountsChanged.emit() + self._alertTreeChange(tHandle=tHandle, flush=autoFlush) + self.projView.wordCountsChanged.emit() else: - # The file is not already in the trash folder, so we + # The item is not already in the trash folder, so we # move it there. - msgYes = self.theParent.askQuestion( - self.tr("Delete File"), - self.tr("Move file '{0}' to Trash?").format(nwItemS.itemName), + msgYes = self.mainGui.askQuestion( + self.tr("Delete"), + self.tr("Move '{0}' to Trash?").format(nwItemS.itemName), ) if msgYes: - if pHandle is None: - logger.warning("File has no parent item") - - logger.debug("Moving file '%s' to trash", tHandle) + logger.debug("Moving item '%s' to trash", tHandle) self.propagateCount(tHandle, 0) - tIndex = trItemP.indexOfChild(trItemS) + tIndex = trItemP.indexOfChild(trItemS) trItemC = trItemP.takeChild(tIndex) trItemT.addChild(trItemC) - self._updateItemParent(tHandle) - self.propagateCount(tHandle, wCount) - - self.theIndex.deleteHandle(tHandle) + self._postItemMove(tHandle, wCount) self._recordLastMove(trItemS, trItemP, tIndex) - self._setTreeChanged(True) - - elif nwItemS.itemType == nwItemType.FOLDER: - logger.debug("User requested folder '%s' deleted", tHandle) - trItemP = trItemS.parent() - if trItemP is None: - logger.error("Could not delete folder") - return False - tIndex = trItemP.indexOfChild(trItemS) - if trItemS.childCount() == 0: - trItemP.takeChild(tIndex) - self._deleteTreeItem(tHandle) - self._setTreeChanged(True) - else: - self.theParent.makeAlert(self.tr( - "Cannot delete folder. It is not empty. " - "Recursive deletion is not supported. " - "Please delete the content first." - ), nwAlert.ERROR) - return False - - elif nwItemS.itemType == nwItemType.ROOT: - logger.debug("User requested root folder '%s' deleted", tHandle) - tIndex = self.indexOfTopLevelItem(trItemS) - if trItemS.childCount() == 0: - self.takeTopLevelItem(tIndex) - self._deleteTreeItem(tHandle) - self.theParent.mainMenu.setAvailableRoot() - self._setTreeChanged(True) - else: - self.theParent.makeAlert(self.tr( - "Cannot delete root folder. It is not empty. " - "Recursive deletion is not supported. " - "Please delete the content first." - ), nwAlert.ERROR) - return False + self._alertTreeChange(tHandle=tHandle, flush=autoFlush) return True @@ -599,49 +788,35 @@ class GuiProjectTree(QTreeWidget): already coming from the project tree. """ trItem = self._getTreeItem(tHandle) - nwItem = self.theProject.projTree[tHandle] + nwItem = self.theProject.tree[tHandle] if trItem is None or nwItem is None: return - expIcon = QIcon() - if nwItem.itemType == nwItemType.FILE: - if nwItem.isExported: - expIcon = self.theTheme.getIcon("check") - else: - expIcon = self.theTheme.getIcon("cross") - - iStatus = nwItem.itemStatus - if nwItem.itemClass == nwItemClass.NOVEL: - iStatus = self.theProject.statusItems.checkEntry(iStatus) # Make sure it's valid - statIcon = self.theParent.statusIcons[iStatus] - else: - iStatus = self.theProject.importItems.checkEntry(iStatus) # Make sure it's valid - statIcon = self.theParent.importIcons[iStatus] - - hLevel = self.theIndex.getHandleHeaderLevel(tHandle) - itemIcon = self.theTheme.getItemIcon( + itemStatus, statusIcon = nwItem.getImportStatus() + hLevel = self.theProject.index.getHandleHeaderLevel(tHandle) + itemIcon = self.mainTheme.getItemIcon( nwItem.itemType, nwItem.itemClass, nwItem.itemLayout, hLevel ) trItem.setIcon(self.C_NAME, itemIcon) trItem.setText(self.C_NAME, nwItem.itemName) - trItem.setIcon(self.C_EXPORT, expIcon) - trItem.setIcon(self.C_STATUS, statIcon) - trItem.setToolTip(self.C_STATUS, nwItem.itemStatus) + trItem.setIcon(self.C_STATUS, statusIcon) + trItem.setToolTip(self.C_STATUS, itemStatus) - if self.mainConf.emphLabels and nwItem.itemLayout == nwItemLayout.DOCUMENT: + if nwItem.isFileType(): + trItem.setIcon( + self.C_EXPORT, self.mainTheme.getIcon("check" if nwItem.isExported else "cross") + ) + + if self.mainConf.emphLabels and nwItem.isDocumentLayout(): trFont = trItem.font(self.C_NAME) - if hLevel in ("H1", "H2"): - trFont.setBold(True) - trFont.setUnderline(True) - else: - trFont.setBold(False) - trFont.setUnderline(False) + trFont.setBold(hLevel == "H1" or hLevel == "H2") + trFont.setUnderline(hLevel == "H1") trItem.setFont(self.C_NAME, trFont) return - def propagateCount(self, tHandle, theCount, nDepth=0): + def propagateCount(self, tHandle, newCount, countChildren=False): """Recursive function setting the word count for a given item, and propagating that count upwards in the tree until reaching a root item. This function is more efficient than recalculating @@ -653,20 +828,30 @@ class GuiProjectTree(QTreeWidget): if tItem is None: return - tItem.setText(self.C_COUNT, f"{theCount:n}") - tItem.setData(self.C_COUNT, Qt.UserRole, int(theCount)) + if countChildren: + for i in range(tItem.childCount()): + newCount += int(tItem.child(i).data(self.C_COUNT, Qt.UserRole)) + + tItem.setText(self.C_COUNT, f"{newCount:n}") + tItem.setData(self.C_COUNT, Qt.UserRole, int(newCount)) pItem = tItem.parent() if pItem is None: return pCount = 0 + pHandle = None for i in range(pItem.childCount()): pCount += int(pItem.child(i).data(self.C_COUNT, Qt.UserRole)) pHandle = pItem.data(self.C_NAME, Qt.UserRole) - if not nDepth > nwConst.MAX_DEPTH + 1 and pHandle != "": - self.propagateCount(pHandle, pCount, nDepth+1) + if pHandle: + if self.theProject.tree.checkType(pHandle, nwItemType.FILE): + # A file has an internal word count we need to account + # for, but a folder always has 0 words on its own. + pCount += self.theProject.index.getCounts(pHandle)[1] + + self.propagateCount(pHandle, pCount, countChildren=False) return @@ -694,9 +879,6 @@ class GuiProjectTree(QTreeWidget): dstItem = self._lastMove.get("parent", None) dstIndex = self._lastMove.get("index", None) - if not self.hasFocus(): - return False - if srcItem is None or dstItem is None or dstIndex is None: logger.verbose("No tree move to undo") return False @@ -710,20 +892,19 @@ class GuiProjectTree(QTreeWidget): return False dstIndex = min(max(0, dstIndex), dstItem.childCount()) - wCount = int(srcItem.data(self.C_COUNT, Qt.UserRole)) sHandle = srcItem.data(self.C_NAME, Qt.UserRole) dHandle = dstItem.data(self.C_NAME, Qt.UserRole) logger.debug("Moving item '%s' back to '%s', index %d", sHandle, dHandle, dstIndex) + wCount = self._getItemWordCount(sHandle) self.propagateCount(sHandle, 0) parItem = srcItem.parent() srcIndex = parItem.indexOfChild(srcItem) movItem = parItem.takeChild(srcIndex) dstItem.insertChild(dstIndex, movItem) - snItem = self.theProject.projTree[sHandle] - dnItem = self.theProject.projTree[dHandle] - self._postItemMove(sHandle, snItem, dnItem, wCount) + self._postItemMove(sHandle, wCount) + self._alertTreeChange(tHandle=sHandle, flush=True) self.clearSelection() movItem.setSelected(True) @@ -744,9 +925,6 @@ class GuiProjectTree(QTreeWidget): def setSelectedHandle(self, tHandle, doScroll=False): """Set a specific handle as the selected item. """ - if tHandle not in self._treeMap: - return False - tItem = self._getTreeItem(tHandle) if tItem is None: return False @@ -760,39 +938,163 @@ class GuiProjectTree(QTreeWidget): return True + def openContextOnSelected(self): + """Open the context menu on the current selected item. + """ + selItem = self.selectedItems() + if selItem: + pos = self.visualItemRect(selItem[0]).center() + return self._openContextMenu(pos) + return False + def changedSince(self, checkTime): """Check if the tree has changed since a given time. """ return self._timeChanged > checkTime ## - # Slots + # Private Slots ## + @pyqtSlot() + def _treeSelectionChange(self): + """The user changed which item is selected. + """ + tHandle = self.getSelectedHandle() + if tHandle is not None: + self.projView.selectedItemChanged.emit(tHandle) + return + + @pyqtSlot("QTreeWidgetItem*", int) + def _treeDoubleClick(self, tItem, colNo): + """Capture a double-click event and either request the document + for editing if it is a file, or expand/close the node it is not. + """ + tHandle = self.getSelectedHandle() + if tHandle is None: + return + + tItem = self.theProject.tree[tHandle] + if tItem is None: + return + + if tItem.isFileType(): + self.projView.openDocumentRequest.emit(tHandle, nwDocMode.EDIT, -1, "") + else: + trItem = self._getTreeItem(tHandle) + if trItem is not None: + trItem.setExpanded(not trItem.isExpanded()) + + return + @pyqtSlot("QPoint") - def _rightClickMenu(self, clickPos): + def _openContextMenu(self, clickPos): """The user right clicked an element in the project tree, so we open a context menu in-place. """ + tItem = None selItem = self.itemAt(clickPos) if isinstance(selItem, QTreeWidgetItem): tHandle = selItem.data(self.C_NAME, Qt.UserRole) - self.setSelectedHandle(tHandle) # Just to be safe - tItem = self.theProject.projTree[tHandle] - if tItem is not None: - if self.ctxMenu.filterActions(tItem): - # Only open menu if any actions remain after filter - self.ctxMenu.exec_(self.viewport().mapToGlobal(clickPos)) + tItem = self.theProject.tree[tHandle] - return + if tItem is None: + logger.debug("No item found") + return False - @pyqtSlot(str, int, int, int) - def doUpdateCounts(self, tHandle, cCount, wCount, pCount): - """Slot for updating the word count of a specific item. - """ - self.propagateCount(tHandle, wCount) - self.wordCountsChanged.emit() - return + ctxMenu = QMenu() + + # Trash Folder + # ============ + + trashHandle = self.theProject.tree.trashRoot() + if tItem.itemHandle == trashHandle and trashHandle is not None: + # The trash folder only has one option + ctxMenu.addAction( + self.tr("Empty Trash"), lambda: self.emptyTrash() + ) + ctxMenu.exec_(self.viewport().mapToGlobal(clickPos)) + return True + + # Document Actions + # ================ + + isRoot = tItem.isRootType() + isFolder = tItem.isFolderType() + isFile = tItem.isFileType() + isEmpty = selItem.childCount() == 0 + + if isFile: + ctxMenu.addAction( + self.tr("Open Document"), + lambda: self.projView.openDocumentRequest.emit(tHandle, nwDocMode.EDIT, -1, "") + ) + ctxMenu.addAction( + self.tr("View Document"), + lambda: self.projView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, -1, "") + ) + ctxMenu.addSeparator() + + # Edit Item Settings + # ================== + + ctxMenu.addAction( + self.tr("Change Label"), lambda: self.renameTreeItem(tHandle) + ) + + if isFile: + ctxMenu.addAction( + self.tr("Toggle Exported"), lambda: self._toggleItemExported(tHandle) + ) + + if tItem.isNovelLike(): + mStatus = ctxMenu.addMenu(self.tr("Set Status to ...")) + for n, (key, entry) in enumerate(self.theProject.statusItems.items()): + aStatus = mStatus.addAction(entry["icon"], entry["name"]) + aStatus.triggered.connect( + lambda n, key=key: self._changeItemStatus(tHandle, key) + ) + else: + mImport = ctxMenu.addMenu(self.tr("Set Importance to ...")) + for n, (key, entry) in enumerate(self.theProject.importItems.items()): + aImport = mImport.addAction(entry["icon"], entry["name"]) + aImport.triggered.connect( + lambda n, key=key: self._changeItemImport(tHandle, key) + ) + + if isFile and tItem.documentAllowed(): + if tItem.isNoteLayout(): + ctxMenu.addAction( + self.tr("Convert to {0}").format( + trConst(nwLabels.LAYOUT_NAME[nwItemLayout.DOCUMENT]) + ), + lambda: self._changeItemLayout(tHandle, nwItemLayout.DOCUMENT) + ) + else: + ctxMenu.addAction( + self.tr("Convert to {0}").format( + trConst(nwLabels.LAYOUT_NAME[nwItemLayout.NOTE]) + ), + lambda: self._changeItemLayout(tHandle, nwItemLayout.NOTE) + ) + + ctxMenu.addSeparator() + + # Delete Item + # =========== + + if tItem.itemClass == nwItemClass.TRASH or isRoot or (isFolder and isEmpty): + ctxMenu.addAction( + self.tr("Delete Permanently"), lambda: self.deleteItem(tHandle) + ) + else: + ctxMenu.addAction( + self.tr("Move to Trash"), lambda: self.deleteItem(tHandle) + ) + + ctxMenu.exec_(self.viewport().mapToGlobal(clickPos)) + + return True ## # Events @@ -816,71 +1118,44 @@ class GuiProjectTree(QTreeWidget): return tHandle = selItem.data(self.C_NAME, Qt.UserRole) - tItem = self.theProject.projTree[tHandle] + tItem = self.theProject.tree[tHandle] if tItem is None: return - if tItem.itemType == nwItemType.FILE: - self.theParent.viewDocument(tHandle) + if tItem.isFileType(): + self.projView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, -1, "") return def dropEvent(self, theEvent): - """Overload the drop of dragged item event to check whether the - drop is allowed or not. Disallowed drops are cancelled. + """Overload the drop item event to ensure relevant data has been + updated. """ sHandle = self.getSelectedHandle() if sHandle is None: - logger.error("No handle selected") + logger.error("Invalid drag and drop event") return - dIndex = self.indexAt(theEvent.pos()) - if not dIndex.isValid(): - logger.error("Invalid drop index") - return + logger.debug("Drag'n'drop of item '%s' accepted", sHandle) sItem = self._getTreeItem(sHandle) - dItem = self.itemFromIndex(dIndex) - dHandle = dItem.data(self.C_NAME, Qt.UserRole) - snItem = self.theProject.projTree[sHandle] - dnItem = self.theProject.projTree[dHandle] - if dnItem is None: - self.theParent.makeAlert(self.tr( - "The item cannot be moved to that location." - ), nwAlert.ERROR) - return + isExpanded = False + if sItem is not None: + isExpanded = sItem.isExpanded() pItem = sItem.parent() pIndex = 0 if pItem is not None: pIndex = pItem.indexOfChild(sItem) - wCount = int(sItem.data(self.C_COUNT, Qt.UserRole)) - isFile = snItem.itemType == nwItemType.FILE - isRoot = snItem.itemType == nwItemType.ROOT - onFile = dnItem.itemType == nwItemType.FILE + wCount = self._getItemWordCount(sHandle) + self.propagateCount(sHandle, 0) - isSame = snItem.itemClass == dnItem.itemClass - isNone = snItem.itemClass == nwItemClass.NO_CLASS - isNote = snItem.itemLayout == nwItemLayout.NOTE - onFree = dnItem.itemClass in nwLists.FREE_CLASS and isFile - - allowDrop = isSame or isNone or isNote or onFree - allowDrop &= not (self.dropIndicatorPosition() == QAbstractItemView.OnItem and onFile) - - if allowDrop and not isRoot: - logger.debug("Drag'n'drop of item '%s' accepted", sHandle) - self.propagateCount(sHandle, 0) - QTreeWidget.dropEvent(self, theEvent) - self._postItemMove(sHandle, snItem, dnItem, wCount) - self._recordLastMove(sItem, pItem, pIndex) - - else: - theEvent.ignore() - logger.debug("Drag'n'drop of item '%s' not accepted", sHandle) - self.theParent.makeAlert(self.tr( - "The item cannot be moved to that location." - ), nwAlert.ERROR) + QTreeWidget.dropEvent(self, theEvent) + self._postItemMove(sHandle, wCount) + self._recordLastMove(sItem, pItem, pIndex) + self._alertTreeChange(tHandle=sHandle, flush=True) + sItem.setExpanded(isExpanded) return @@ -888,51 +1163,110 @@ class GuiProjectTree(QTreeWidget): # Internal Functions ## - def _postItemMove(self, sHandle, snItem, dnItem, wCount): + def _postItemMove(self, tHandle, wCount): """Run various maintenance tasks for a moved item. """ - isFile = snItem.itemType == nwItemType.FILE - isSame = snItem.itemClass == dnItem.itemClass - onFree = dnItem.itemClass in nwLists.FREE_CLASS and isFile + trItemS = self._getTreeItem(tHandle) + nwItemS = self.theProject.tree[tHandle] + trItemP = trItemS.parent() + if trItemP is None: + logger.error("Failed to find new parent item of '%s'", tHandle) + return False - self._updateItemParent(sHandle) + # Update item parent handle in the project, make sure meta data + # is updated accordingly, and update word count + pHandle = trItemP.data(self.C_NAME, Qt.UserRole) + nwItemS.setParent(pHandle) + trItemP.setExpanded(True) + logger.debug("The parent of item '%s' has been changed to '%s'", tHandle, pHandle) - # If the item does not have the same class as the target, - # and the target is not a free root folder, update its class - if not (isSame or onFree): - logger.debug( - "Item '%s' class has been changed from '%s' to '%s'", - sHandle, snItem.itemClass.name, dnItem.itemClass.name - ) - snItem.setClass(dnItem.itemClass) - self.setTreeItemValues(sHandle) + mHandles = self.getTreeFromHandle(tHandle) + logger.debug("A total of %d item(s) were moved", len(mHandles)) + for mHandle in mHandles: + logger.debug("Updating item '%s'", mHandle) + self.theProject.tree.updateItemData(mHandle) - self.propagateCount(sHandle, wCount) + # Update the index + if nwItemS.isInactive(): + self.theProject.index.deleteHandle(mHandle) + else: + self.theProject.index.reIndexHandle(mHandle) - # The items dropped into archive or trash should be removed - # from the project index, for all other items, we rescan the - # file to ensure the index is up to date. - if onFree: - self.theIndex.deleteHandle(sHandle) - else: - self.theIndex.reIndexHandle(sHandle) + self.setTreeItemValues(mHandle) # Trigger dependent updates - self._setTreeChanged(True) - self._emitItemChange(sHandle) + self.propagateCount(tHandle, wCount) - return + return True + + def _getItemWordCount(self, tHandle): + """Retrun the word count of a given item handle. + """ + tItem = self._getTreeItem(tHandle) + if tItem is None: + return 0 + return int(tItem.data(self.C_COUNT, Qt.UserRole)) def _getTreeItem(self, tHandle): - """Returns the QTreeWidgetItem of a given item handle. + """Return the QTreeWidgetItem of a given item handle. """ return self._treeMap.get(tHandle, None) def _deleteTreeItem(self, tHandle): - """Delete a tree item from the project and the map. + """Permanently delete a tree item from the project and the map. """ - del self.theProject.projTree[tHandle] + if self.theProject.tree.checkType(tHandle, nwItemType.FILE): + delDoc = NWDoc(self.theProject, tHandle) + if not delDoc.deleteDocument(): + self.mainGui.makeAlert([ + self.tr("Could not delete document file."), delDoc.getError() + ], nwAlert.ERROR) + return False + + self.theProject.index.deleteHandle(tHandle) + del self.theProject.tree[tHandle] self._treeMap.pop(tHandle, None) + + return True + + def _toggleItemExported(self, tHandle): + """Toggle the exported status of an item. + """ + tItem = self.theProject.tree[tHandle] + if tItem is not None: + tItem.setExported(not tItem.isExported) + self.setTreeItemValues(tItem.itemHandle) + return + + def _changeItemStatus(self, tHandle, tStatus): + """Set a new status value of an item. + """ + tItem = self.theProject.tree[tHandle] + if tItem is not None: + tItem.setStatus(tStatus) + self.setTreeItemValues(tItem.itemHandle) + return + + def _changeItemImport(self, tHandle, tImport): + """Set a new importance value of an item. + """ + tItem = self.theProject.tree[tHandle] + if tItem is not None: + tItem.setImport(tImport) + self.setTreeItemValues(tItem.itemHandle) + return + + def _changeItemLayout(self, tHandle, itemLayout): + """Set a new item layout value of an item. + """ + tItem = self.theProject.tree[tHandle] + if tItem is not None: + if itemLayout == nwItemLayout.DOCUMENT and tItem.documentAllowed(): + tItem.setLayout(nwItemLayout.DOCUMENT) + self.setTreeItemValues(tItem.itemHandle) + elif itemLayout == nwItemLayout.NOTE: + tItem.setLayout(nwItemLayout.NOTE) + self.setTreeItemValues(tItem.itemHandle) return def _scanChildren(self, theList, tItem, tIndex): @@ -940,12 +1274,17 @@ class GuiProjectTree(QTreeWidget): starting at a given QTreeWidgetItem. """ tHandle = tItem.data(self.C_NAME, Qt.UserRole) - nwItem = self.theProject.projTree[tHandle] - nwItem.setExpanded(tItem.isExpanded()) + cCount = tItem.childCount() + + # Update tree-related meta data + nwItem = self.theProject.tree[tHandle] + nwItem.setExpanded(tItem.isExpanded() and cCount > 0) nwItem.setOrder(tIndex) + theList.append(tHandle) - for i in range(tItem.childCount()): + for i in range(cCount): self._scanChildren(theList, tItem.child(i), i) + return theList def _addTreeItem(self, nwItem, nHandle=None): @@ -971,13 +1310,11 @@ class GuiProjectTree(QTreeWidget): self._treeMap[tHandle] = newItem if pHandle is None: - if nwItem.itemType == nwItemType.ROOT: - self.addTopLevelItem(newItem) - self.theParent.mainMenu.setAvailableRoot() - elif nwItem.itemType == nwItemType.TRASH: + if nwItem.isRootType(): + newItem.setFlags(newItem.flags() ^ Qt.ItemIsDragEnabled) self.addTopLevelItem(newItem) else: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "There is nowhere to add item with name '{0}'." ).format(nwItem.itemName), nwAlert.ERROR) del self._treeMap[tHandle] @@ -991,16 +1328,14 @@ class GuiProjectTree(QTreeWidget): except Exception: logger.error("Failed to get index of item with handle '%s'", nHandle) if byIndex >= 0: - self._treeMap[pHandle].insertChild(byIndex+1, newItem) + self._treeMap[pHandle].insertChild(byIndex + 1, newItem) else: self._treeMap[pHandle].addChild(newItem) - self.propagateCount(tHandle, nwItem.wordCount) + self.propagateCount(tHandle, nwItem.wordCount, countChildren=True) self.setTreeItemValues(tHandle) newItem.setExpanded(nwItem.isExpanded) - self._setTreeChanged(True) - return newItem def _addTrashRoot(self): @@ -1013,52 +1348,32 @@ class GuiProjectTree(QTreeWidget): trItem = self._getTreeItem(trashHandle) if trItem is None: - trItem = self._addTreeItem( - self.theProject.projTree[trashHandle] - ) + trItem = self._addTreeItem(self.theProject.tree[trashHandle]) if trItem is not None: trItem.setExpanded(True) - self._setTreeChanged(True) + self._alertTreeChange(tHandle=trashHandle, flush=True) return trItem - def _updateItemParent(self, tHandle): - """Update the parent handle of an item so that the information - in the project is consistent with the treeView. + def _alertTreeChange(self, tHandle=None, flush=True): + """Update information on tree change state, and emit necessary + signals. """ - trItemS = self._getTreeItem(tHandle) - nwItemS = self.theProject.projTree[tHandle] - trItemP = trItemS.parent() - if trItemP is None: - logger.error("Failed to find new parent item of '%s'", tHandle) - return False + self._timeChanged = time() + self.theProject.setProjectChanged(True) + if flush: + self.saveTreeOrder() - pHandle = trItemP.data(self.C_NAME, Qt.UserRole) - nwItemS.setParent(pHandle) - self.setTreeItemValues(tHandle) + tItem = self.theProject.tree[tHandle] + if tItem is None: + return - logger.debug("The parent of item '%s' has been changed to '%s'", tHandle, pHandle) + itemType = tItem.itemType + if itemType == nwItemType.ROOT: + self.projView.rootFolderChanged.emit(tHandle) - return True + self.projView.treeItemChanged.emit(tHandle) - def _setTreeChanged(self, theState): - """Set the tree change flag, and propagate to the project. - """ - self._treeChanged = theState - if theState: - self._timeChanged = time() - self.theProject.setProjectChanged(True) - return - - def _emitItemChange(self, tHandle): - """Emit an item change signal for a given handle. - """ - if self.theProject.projTree.checkType(tHandle, nwItemType.FILE): - nwItem = self.theProject.projTree[tHandle] - if nwItem.itemClass == nwItemClass.NOVEL: - self.novelItemChanged.emit() - else: - self.noteItemChanged.emit() return def _recordLastMove(self, srcItem, parItem, parIndex): @@ -1075,167 +1390,3 @@ class GuiProjectTree(QTreeWidget): return # END Class GuiProjectTree - - -class GuiProjectTreeMenu(QMenu): - - def __init__(self, theTree): - QMenu.__init__(self, theTree) - - self.theTree = theTree - self.theItem = None - - self.editItem = QAction(self.tr("Edit Project Item"), self) - self.editItem.triggered.connect(self._doEditItem) - self.addAction(self.editItem) - - self.openItem = QAction(self.tr("Open Document"), self) - self.openItem.triggered.connect(self._doOpenItem) - self.addAction(self.openItem) - - self.viewItem = QAction(self.tr("View Document"), self) - self.viewItem.triggered.connect(self._doViewItem) - self.addAction(self.viewItem) - - self.toggleExp = QAction(self.tr("Toggle Included Flag"), self) - self.toggleExp.triggered.connect(self._doToggleExported) - self.addAction(self.toggleExp) - - self.newFile = QAction(self.tr("New File"), self) - self.newFile.triggered.connect(self._doMakeFile) - self.addAction(self.newFile) - - self.newFolder = QAction(self.tr("New Folder"), self) - self.newFolder.triggered.connect(self._doMakeFolder) - self.addAction(self.newFolder) - - self.deleteItem = QAction(self.tr("Delete Item"), self) - self.deleteItem.triggered.connect(self._doDeleteItem) - self.addAction(self.deleteItem) - - self.emptyTrash = QAction(self.tr("Empty Trash"), self) - self.emptyTrash.triggered.connect(self._doEmptyTrash) - self.addAction(self.emptyTrash) - - self.moveUp = QAction(self.tr("Move Item Up"), self) - self.moveUp.triggered.connect(self._doMoveUp) - self.addAction(self.moveUp) - - self.moveDown = QAction(self.tr("Move Item Down"), self) - self.moveDown.triggered.connect(self._doMoveDown) - self.addAction(self.moveDown) - - return - - def filterActions(self, theItem): - """Filter the menu entries available based on the properties of - the item the menu was activated on. - """ - self.theItem = theItem - - if theItem is None: - logger.error("Failed to extract information to build tree context menu") - return False - - trashHandle = self.theTree.theProject.projTree.trashRoot() - - inTrash = theItem.itemParent == trashHandle and trashHandle is not None - isTrash = theItem.itemHandle == trashHandle and trashHandle is not None - isFile = theItem.itemType == nwItemType.FILE - - allowNew = not (isTrash or inTrash) - - self.editItem.setVisible(not isTrash) - self.openItem.setVisible(isFile) - self.viewItem.setVisible(isFile) - self.toggleExp.setVisible(isFile) - self.newFile.setVisible(allowNew) - self.newFolder.setVisible(allowNew) - self.deleteItem.setVisible(not isTrash) - self.emptyTrash.setVisible(isTrash) - - return True - - ## - # Slots - ## - - @pyqtSlot() - def _doOpenItem(self): - """Forward the open document call to the main GUI window. - """ - if self.theItem is not None: - self.theTree.theParent.openDocument(self.theItem.itemHandle, doScroll=False) - return - - @pyqtSlot() - def _doViewItem(self): - """Forward the view document call to the main GUI window. - """ - if self.theItem is not None: - self.theTree.theParent.viewDocument(self.theItem.itemHandle) - return - - @pyqtSlot() - def _doEditItem(self): - """Forward the edit item call to the main GUI window. - """ - if self.theItem is not None: - self.theTree.theParent.editItem() - return - - @pyqtSlot() - def _doMakeFile(self): - """Forward the new file call to the project tree. - """ - if self.theItem is not None: - self.theTree.newTreeItem(nwItemType.FILE, None) - return - - @pyqtSlot() - def _doMakeFolder(self): - """Forward the new folder call to the project tree. - """ - if self.theItem is not None: - self.theTree.newTreeItem(nwItemType.FOLDER, None) - return - - @pyqtSlot() - def _doToggleExported(self): - """Flip the isExported flag of the current item. - """ - if self.theItem is not None: - self.theItem.setExported(not self.theItem.isExported) - self.theTree.setTreeItemValues(self.theItem.itemHandle) - return - - @pyqtSlot() - def _doDeleteItem(self): - """Forward the delete item call to the project tree. - """ - if self.theItem is not None: - self.theTree.deleteItem() - return - - @pyqtSlot() - def _doEmptyTrash(self): - """Forward the empty trash call to the project tree. - """ - self.theTree.emptyTrash() - return - - @pyqtSlot() - def _doMoveUp(self): - """Forward the move item call to the project tree. - """ - self.theTree.moveTreeItem(-1) - return - - @pyqtSlot() - def _doMoveDown(self): - """Forward the move item call to the project tree. - """ - self.theTree.moveTreeItem(1) - return - -# END Class GuiProjectTreeMenu diff --git a/novelwriter/gui/statusbar.py b/novelwriter/gui/statusbar.py index e3891e7e..a0cf9416 100644 --- a/novelwriter/gui/statusbar.py +++ b/novelwriter/gui/statusbar.py @@ -41,22 +41,22 @@ logger = logging.getLogger(__name__) class GuiMainStatus(QStatusBar): - def __init__(self, theParent): - QStatusBar.__init__(self, theParent) + def __init__(self, mainGui): + QStatusBar.__init__(self, mainGui) logger.debug("Initialising GuiMainStatus ...") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme self.refTime = None self.userIdle = False - colNone = QColor(*self.theTheme.statNone) - colTrue = QColor(*self.theTheme.statUnsaved) - colFalse = QColor(*self.theTheme.statSaved) + colNone = QColor(*self.mainTheme.statNone) + colTrue = QColor(*self.mainTheme.statUnsaved) + colFalse = QColor(*self.mainTheme.statSaved) - iPx = self.theTheme.baseIconSize + iPx = self.mainTheme.baseIconSize # Permanent Widgets # ================= @@ -66,7 +66,7 @@ class GuiMainStatus(QStatusBar): # The Spell Checker Language self.langIcon = QLabel("") self.langText = QLabel(self.tr("None")) - self.langIcon.setPixmap(self.theTheme.getPixmap("status_lang", (iPx, iPx))) + self.langIcon.setPixmap(self.mainTheme.getPixmap("status_lang", (iPx, iPx))) self.langIcon.setContentsMargins(0, 0, 0, 0) self.langText.setContentsMargins(0, 0, xM, 0) self.addPermanentWidget(self.langIcon) @@ -91,7 +91,7 @@ class GuiMainStatus(QStatusBar): # The Project and Session Stats self.statsIcon = QLabel() self.statsText = QLabel("") - self.statsIcon.setPixmap(self.theTheme.getPixmap("status_stats", (iPx, iPx))) + self.statsIcon.setPixmap(self.mainTheme.getPixmap("status_stats", (iPx, iPx))) self.statsIcon.setContentsMargins(0, 0, 0, 0) self.statsText.setContentsMargins(0, 0, xM, 0) self.addPermanentWidget(self.statsIcon) @@ -99,14 +99,14 @@ class GuiMainStatus(QStatusBar): # The Session Clock # Set the mimimum width so the label doesn't rescale every second - self.timePixmap = self.theTheme.getPixmap("status_time", (iPx, iPx)) - self.idlePixmap = self.theTheme.getPixmap("status_idle", (iPx, iPx)) + self.timePixmap = self.mainTheme.getPixmap("status_time", (iPx, iPx)) + self.idlePixmap = self.mainTheme.getPixmap("status_idle", (iPx, iPx)) self.timeIcon = QLabel() self.timeText = QLabel("") self.timeIcon.setPixmap(self.timePixmap) self.timeText.setToolTip(self.tr("Session Time")) - self.timeText.setMinimumWidth(self.theTheme.getTextWidth("00:00:00:")) + self.timeText.setMinimumWidth(self.mainTheme.getTextWidth("00:00:00:")) self.timeIcon.setContentsMargins(0, 0, 0, 0) self.timeText.setContentsMargins(0, 0, 0, 0) self.addPermanentWidget(self.timeIcon) diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 6cdf72ef..e72a8c97 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -54,7 +54,7 @@ class GuiTheme: def __init__(self): self.mainConf = novelwriter.CONFIG - self.theIcons = GuiIcons(self) + self.iconCache = GuiIcons(self) # Loaded Theme Settings # ===================== @@ -127,13 +127,13 @@ class GuiTheme: self.updateFont() self.updateTheme() - self.theIcons.updateTheme() + self.iconCache.updateTheme() # Icon Functions - self.getIcon = self.theIcons.getIcon - self.getPixmap = self.theIcons.getPixmap - self.getItemIcon = self.theIcons.getItemIcon - self.loadDecoration = self.theIcons.loadDecoration + self.getIcon = self.iconCache.getIcon + self.getPixmap = self.iconCache.getPixmap + self.getItemIcon = self.iconCache.getItemIcon + self.loadDecoration = self.iconCache.loadDecoration # Extract Other Info self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() @@ -456,34 +456,35 @@ class GuiIcons: ICON_KEYS = { # Project and GUI icons - "novelwriter", "proj_nwx", - "cls_none", "cls_novel", "cls_plot", "cls_character", "cls_world", - "cls_timeline", "cls_object", "cls_entity", "cls_custom", "cls_archive", "cls_trash", - "proj_document", "proj_title", "proj_chapter", "proj_scene", "proj_note", "proj_folder", - "status_lang", "status_time", "status_idle", "status_stats", "status_lines", - "doc_h0", "doc_h1", "doc_h2", "doc_h3", "doc_h4", - "search_case", "search_regex", "search_word", "search_loop", "search_project", - "search_cancel", "search_preserve", + "novelwriter", "cls_archive", "cls_character", "cls_custom", "cls_entity", "cls_none", + "cls_novel", "cls_object", "cls_plot", "cls_timeline", "cls_trash", "cls_world", "doc_h0", + "doc_h1", "doc_h2", "doc_h3", "doc_h4", "proj_chapter", "proj_details", "proj_document", + "proj_folder", "proj_note", "proj_nwx", "proj_scene", "proj_stats", "proj_title", + "search_cancel", "search_case", "search_loop", "search_preserve", "search_project", + "search_regex", "search_word", "status_idle", "status_lang", "status_lines", + "status_stats", "status_time", "view_build", "view_editor", "view_novel", "view_outline", # General Button Icons - "delete", "close", "done", "clear", "save", "add", "remove", - "search", "search_replace", "edit", "check", "cross", "hash", - "maximise", "minimise", "refresh", "reference", "backward", - "forward", "settings", + "add", "backward", "check", "clear", "close", "cross", "delete", "done", "down", "edit", + "forward", "hash", "maximise", "menu", "minimise", "reference", "refresh", "remove", + "save", "search_replace", "search", "settings", "up", # Switches "sticky-on", "sticky-off", "bullet-on", "bullet-off", + + # Decorations + "deco_doc_h0", "deco_doc_h1", "deco_doc_h2", "deco_doc_h3", "deco_doc_h4", "deco_doc_more", } - DECO_MAP = { + IMAGE_MAP = { "wiz-back": "wizard-back.jpg", } - def __init__(self, theTheme): + def __init__(self, mainTheme): self.mainConf = novelwriter.CONFIG - self.theTheme = theTheme + self.mainTheme = mainTheme # Storage self._qIcons = {} @@ -575,19 +576,22 @@ class GuiIcons: # Access Functions ## - def loadDecoration(self, decoKey, pxW, pxH): + def loadDecoration(self, decoKey, pxW=None, pxH=None): """Load graphical decoration element based on the decoration - map. This function always returns a QSwgWidget. + map or the icon map. This function always returns a QPixmap. """ - if decoKey not in self.DECO_MAP: + if decoKey in self._themeMap: + imgPath = self._themeMap[decoKey] + elif decoKey in self.IMAGE_MAP: + imgPath = os.path.join( + self.mainConf.assetPath, "images", self.IMAGE_MAP[decoKey] + ) + else: logger.error("Decoration with name '%s' does not exist", decoKey) return QPixmap() - imgPath = os.path.join( - self.mainConf.assetPath, "images", self.DECO_MAP[decoKey] - ) if not os.path.isfile(imgPath): - logger.error("Decoration file '%s' not in assets folder", self.DECO_MAP[decoKey]) + logger.error("Asset '%s' not found", self.IMAGE_MAP[decoKey]) return QPixmap() theDeco = QPixmap(imgPath) @@ -639,9 +643,6 @@ class GuiIcons: iconName = "proj_scene" elif tLayout == nwItemLayout.NOTE: iconName = "proj_note" - elif tType == nwItemType.TRASH: - iconName = nwLabels.CLASS_ICON[tClass] - if iconName is None: return QIcon() diff --git a/novelwriter/gui/viewsbar.py b/novelwriter/gui/viewsbar.py new file mode 100644 index 00000000..031f4316 --- /dev/null +++ b/novelwriter/gui/viewsbar.py @@ -0,0 +1,139 @@ +""" +novelWriter – GUI Main Window Views ToolBar +=========================================== +GUI class for the main window "Views" toolbar + +File History: +Created: 2022-05-10 [1.7b1] + +This file is a part of novelWriter +Copyright 2018–2022, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +import logging +import novelwriter + +from PyQt5.QtCore import Qt, QSize, pyqtSignal +from PyQt5.QtWidgets import ( + QToolBar, QWidget, QSizePolicy, QAction, QMenu, QToolButton +) + +from novelwriter.enum import nwView + +logger = logging.getLogger(__name__) + + +class GuiViewsBar(QToolBar): + + viewChangeRequested = pyqtSignal(nwView) + + def __init__(self, mainGui): + QToolBar.__init__(self, mainGui) + + logger.debug("Initialising GuiViewsBar ...") + + self.mainConf = novelwriter.CONFIG + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + + # Style + iPx = self.mainConf.pxInt(22) + mPx = self.mainConf.pxInt(60) + + lblFont = self.mainTheme.guiFont + lblFont.setPointSizeF(0.65*self.mainTheme.fontPointSize) + + self.setMovable(False) + self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) + self.setIconSize(QSize(iPx, iPx)) + self.setMaximumWidth(mPx) + self.setContentsMargins(0, 0, 0, 0) + self.setStyleSheet("QToolBar {border: 0px;}") + + stretch = QWidget(self) + stretch.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + + # Actions + self.aProject = QAction(self.tr("Project")) + self.aProject.setFont(lblFont) + self.aProject.setToolTip(self.tr("Show project tree and editor")) + self.aProject.setIcon(self.mainTheme.getIcon("view_editor")) + self.aProject.triggered.connect(lambda: self.viewChangeRequested.emit(nwView.PROJECT)) + + self.aNovel = QAction(self.tr("Novel")) + self.aNovel.setFont(lblFont) + self.aNovel.setToolTip(self.tr("Show novel tree and editor")) + self.aNovel.setIcon(self.mainTheme.getIcon("view_novel")) + self.aNovel.triggered.connect(lambda: self.viewChangeRequested.emit(nwView.NOVEL)) + + self.aOutline = QAction(self.tr("Outline")) + self.aOutline.setFont(lblFont) + self.aOutline.setToolTip(self.tr("Show novel outline")) + self.aOutline.setIcon(self.mainTheme.getIcon("view_outline")) + self.aOutline.triggered.connect(lambda: self.viewChangeRequested.emit(nwView.OUTLINE)) + + self.aBuild = QAction(self.tr("Build")) + self.aBuild.setFont(lblFont) + self.aBuild.setToolTip(self.tr("Build novel project")) + self.aBuild.setIcon(self.mainTheme.getIcon("view_build")) + self.aBuild.triggered.connect(lambda: self.mainGui.showBuildProjectDialog()) + + self.aDetails = QAction(self.tr("Details")) + self.aDetails.setFont(lblFont) + self.aDetails.setToolTip(self.tr("Show project details")) + self.aDetails.setIcon(self.mainTheme.getIcon("proj_details")) + self.aDetails.triggered.connect(lambda: self.mainGui.showProjectDetailsDialog()) + + self.aStats = QAction(self.tr("Stats")) + self.aStats.setFont(lblFont) + self.aStats.setToolTip(self.tr("Show project statistics")) + self.aStats.setIcon(self.mainTheme.getIcon("proj_stats")) + self.aStats.triggered.connect(lambda: self.mainGui.showWritingStatsDialog()) + + # Settings Menu + self.mSettings = QMenu() + + self.aPrjSettings = QAction(self.tr("Project Settings")) + self.aPrjSettings.triggered.connect(lambda: self.mainGui.showProjectSettingsDialog()) + self.mSettings.addAction(self.aPrjSettings) + + self.aPreferences = QAction(self.tr("Preferences")) + self.aPreferences.triggered.connect(lambda: self.mainGui.showPreferencesDialog()) + self.mSettings.addAction(self.aPreferences) + + self.tbSettings = QToolButton(self) + self.tbSettings.setFont(lblFont) + self.tbSettings.setText(self.tr("Settings")) + self.tbSettings.setIcon(self.mainTheme.getIcon("settings")) + self.tbSettings.setMenu(self.mSettings) + self.tbSettings.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) + self.tbSettings.setPopupMode(QToolButton.InstantPopup) + + # Assemble + self.addAction(self.aProject) + self.addAction(self.aNovel) + self.addAction(self.aOutline) + self.addAction(self.aBuild) + self.addWidget(stretch) + self.addAction(self.aDetails) + self.addAction(self.aStats) + self.addWidget(self.tbSettings) + + logger.debug("GuiViewsBar initialisation complete") + + return + +# END Class GuiViewsBar diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index f0aa7899..bad8c904 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -27,33 +27,34 @@ import os import logging import novelwriter +from enum import Enum from time import time from datetime import datetime -from PyQt5.QtCore import Qt, QTimer, QSize, QThreadPool, pyqtSlot -from PyQt5.QtGui import QIcon, QPixmap, QColor, QKeySequence, QCursor +from PyQt5.QtCore import Qt, QTimer, QThreadPool, pyqtSlot +from PyQt5.QtGui import QIcon, QKeySequence, QCursor from PyQt5.QtWidgets import ( qApp, QMainWindow, QVBoxLayout, QWidget, QSplitter, QFileDialog, QShortcut, - QMessageBox, QDialog, QTabWidget, QToolBar, QAction + QMessageBox, QDialog, QStackedWidget ) from novelwriter.gui import ( GuiDocEditor, GuiDocViewDetails, GuiDocViewer, GuiItemDetails, GuiMainMenu, - GuiMainStatus, GuiNovelTree, GuiOutline, GuiOutlineDetails, GuiProjectTree, - GuiTheme + GuiMainStatus, GuiNovelView, GuiOutlineView, GuiProjectView, GuiTheme, + GuiViewsBar ) from novelwriter.dialogs import ( - GuiAbout, GuiDocMerge, GuiDocSplit, GuiItemEditor, GuiPreferences, - GuiProjectDetails, GuiProjectLoad, GuiProjectSettings, GuiUpdates, - GuiWordList + GuiAbout, GuiDocMerge, GuiDocSplit, GuiPreferences, GuiProjectDetails, + GuiProjectLoad, GuiProjectSettings, GuiUpdates, GuiWordList ) -from novelwriter.tools import GuiBuildNovel, GuiProjectWizard, GuiWritingStats -from novelwriter.core import NWProject, NWIndex +from novelwriter.tools import ( + GuiBuildNovel, GuiLipsum, GuiProjectWizard, GuiWritingStats +) +from novelwriter.core import NWProject from novelwriter.enum import ( - nwItemType, nwItemClass, nwAlert, nwWidget, nwState + nwDocMode, nwItemType, nwItemClass, nwAlert, nwWidget, nwState, nwView ) from novelwriter.common import getGuiItem, hexToInt -from novelwriter.constants import nwLists logger = logging.getLogger(__name__) @@ -83,9 +84,8 @@ class GuiMain(QMainWindow): # ============ # Core Classes and Settings - self.theTheme = GuiTheme() + self.mainTheme = GuiTheme() self.theProject = NWProject(self) - self.theIndex = NWIndex(self.theProject) self.hasProject = False self.isFocusMode = False self.idleRefTime = time() @@ -101,126 +101,75 @@ class GuiMain(QMainWindow): # Sizes mPx = self.mainConf.pxInt(4) - fPx = self.theTheme.fontPixelSize - fPt = self.theTheme.fontPointSize + hWd = self.mainConf.pxInt(4) # Main GUI Elements - self.statusBar = GuiMainStatus(self) - self.treeView = GuiProjectTree(self) - self.novelView = GuiNovelTree(self) - self.docEditor = GuiDocEditor(self) - self.viewMeta = GuiDocViewDetails(self) - self.docViewer = GuiDocViewer(self) - self.treeMeta = GuiItemDetails(self) - self.projView = GuiOutline(self) - self.projMeta = GuiOutlineDetails(self) - self.mainMenu = GuiMainMenu(self) + self.statusBar = GuiMainStatus(self) + self.projView = GuiProjectView(self) + self.novelView = GuiNovelView(self) + self.docEditor = GuiDocEditor(self) + self.viewMeta = GuiDocViewDetails(self) + self.docViewer = GuiDocViewer(self) + self.itemDetails = GuiItemDetails(self) + self.outlineView = GuiOutlineView(self) + self.mainMenu = GuiMainMenu(self) + self.viewsBar = GuiViewsBar(self) - # Connect Signals Between Main Elements - self.docEditor.spellDictionaryChanged.connect(self.statusBar.setLanguage) - self.docEditor.docEditedStatusChanged.connect(self.statusBar.doUpdateDocumentStatus) - self.docEditor.docCountsChanged.connect(self.treeMeta.doUpdateCounts) - self.docEditor.docCountsChanged.connect(self.treeView.doUpdateCounts) - - self.treeView.itemSelectionChanged.connect(self._treeSingleClick) - self.treeView.itemDoubleClicked.connect(self._treeDoubleClick) - self.treeView.novelItemChanged.connect(self._treeNovelItemChanged) - self.treeView.wordCountsChanged.connect(self._updateStatusWordCount) - - # Minor GUI Elements - self.statusIcons = [] - self.importIcons = [] - - # Project Tree Tabs - self.projTabs = QTabWidget() - self.projTabs.setTabPosition(QTabWidget.South) - self.projTabs.setStyleSheet("QTabWidget::pane {border: 0;};") - self.projTabs.addTab(self.treeView, self.tr("Project")) - self.projTabs.addTab(self.novelView, self.tr("Novel")) - self.projTabs.currentChanged.connect(self._projTabsChanged) - - tabFont = self.projTabs.tabBar().font() - tabFont.setPointSizeF(0.9*fPt) - self.projTabs.tabBar().setFont(tabFont) - - # Project Tree Action Buttons - btnSize = int(round(0.7*fPx)) - self.treeButtons = QToolBar() - self.treeButtons.setToolButtonStyle(Qt.ToolButtonIconOnly) - self.treeButtons.setIconSize(QSize(btnSize, btnSize)) - self.treeButtons.setContentsMargins(0, 0, 0, 0) - self.treeButtons.setStyleSheet("QToolBar {padding: 0;}") - self.projTabs.setCornerWidget(self.treeButtons, Qt.BottomRightCorner) - - self.projDetailsBtn = QAction(self.tr("Project Details")) - self.projDetailsBtn.setIcon(self.theTheme.getIcon("status_lines")) - self.projDetailsBtn.triggered.connect(lambda: self.showProjectDetailsDialog()) - self.treeButtons.addAction(self.projDetailsBtn) - - self.projStatsBtn = QAction(self.tr("Writing Statistics")) - self.projStatsBtn.setIcon(self.theTheme.getIcon("status_stats")) - self.projStatsBtn.triggered.connect(lambda: self.showWritingStatsDialog()) - self.treeButtons.addAction(self.projStatsBtn) - - self.projSettingsBtn = QAction(self.tr("Project Settings")) - self.projSettingsBtn.setIcon(self.theTheme.getIcon("settings")) - self.projSettingsBtn.triggered.connect(lambda: self.showProjectSettingsDialog()) - self.treeButtons.addAction(self.projSettingsBtn) + # Project Tree Stack + self.projStack = QStackedWidget() + self.projStack.addWidget(self.projView) + self.projStack.addWidget(self.novelView) + self.projStack.currentChanged.connect(self._projStackChanged) # Project Tree View self.treePane = QWidget() self.treeBox = QVBoxLayout() self.treeBox.setContentsMargins(0, 0, 0, 0) self.treeBox.setSpacing(mPx) - self.treeBox.addWidget(self.projTabs) - self.treeBox.addWidget(self.treeMeta) + self.treeBox.addWidget(self.projStack) + self.treeBox.addWidget(self.itemDetails) self.treePane.setLayout(self.treeBox) # Splitter : Document Viewer / Document Meta self.splitView = QSplitter(Qt.Vertical) self.splitView.addWidget(self.docViewer) self.splitView.addWidget(self.viewMeta) + self.splitView.setHandleWidth(hWd) self.splitView.setSizes(self.mainConf.getViewPanePos()) # Splitter : Document Editor / Document Viewer self.splitDocs = QSplitter(Qt.Horizontal) self.splitDocs.addWidget(self.docEditor) self.splitDocs.addWidget(self.splitView) - - # Splitter : Project Outlie / Outline Details - self.splitOutline = QSplitter(Qt.Vertical) - self.splitOutline.addWidget(self.projView) - self.splitOutline.addWidget(self.projMeta) - self.splitOutline.setSizes(self.mainConf.getOutlinePanePos()) - - # Main Tabs : Editor / Outline - self.mainTabs = QTabWidget() - self.mainTabs.setTabPosition(QTabWidget.East) - self.mainTabs.setStyleSheet("QTabWidget::pane {border: 0;}") - self.mainTabs.addTab(self.splitDocs, self.tr("Editor")) - self.mainTabs.addTab(self.splitOutline, self.tr("Outline")) - self.mainTabs.currentChanged.connect(self._mainTabChanged) + self.splitDocs.setHandleWidth(hWd) # Splitter : Project Tree / Main Tabs self.splitMain = QSplitter(Qt.Horizontal) - self.splitMain.setContentsMargins(mPx, mPx, mPx, mPx) + self.splitMain.setContentsMargins(0, 0, 0, 0) self.splitMain.addWidget(self.treePane) - self.splitMain.addWidget(self.mainTabs) + self.splitMain.addWidget(self.splitDocs) + self.splitMain.setHandleWidth(hWd) self.splitMain.setSizes(self.mainConf.getMainPanePos()) + # Main Stack : Editor / Outline + self.mainStack = QStackedWidget() + self.mainStack.addWidget(self.splitMain) + self.mainStack.addWidget(self.outlineView) + self.mainStack.currentChanged.connect(self._mainStackChanged) + # Indices of Splitter Widgets self.idxTree = self.splitMain.indexOf(self.treePane) - self.idxMain = self.splitMain.indexOf(self.mainTabs) + self.idxMain = self.splitMain.indexOf(self.splitDocs) self.idxEditor = self.splitDocs.indexOf(self.docEditor) self.idxViewer = self.splitDocs.indexOf(self.splitView) self.idxViewDoc = self.splitView.indexOf(self.docViewer) self.idxViewMeta = self.splitView.indexOf(self.viewMeta) # Indices of Tab Widgets - self.idxTabEdit = self.mainTabs.indexOf(self.splitDocs) - self.idxTabProj = self.mainTabs.indexOf(self.splitOutline) - self.idxTreeView = self.projTabs.indexOf(self.treeView) - self.idxNovelView = self.projTabs.indexOf(self.novelView) + self.idxEditorView = self.mainStack.indexOf(self.splitMain) + self.idxOutlineView = self.mainStack.indexOf(self.outlineView) + self.idxProjView = self.projStack.indexOf(self.projView) + self.idxNovelView = self.projStack.indexOf(self.novelView) # Splitter Behaviour self.splitMain.setCollapsible(self.idxTree, False) @@ -239,8 +188,36 @@ class GuiMain(QMainWindow): # Set Main Window Elements self.setMenuBar(self.mainMenu) - self.setCentralWidget(self.splitMain) + self.setCentralWidget(self.mainStack) self.setStatusBar(self.statusBar) + self.addToolBar(Qt.LeftToolBarArea, self.viewsBar) + + # Connect Signals + # =============== + + self.viewsBar.viewChangeRequested.connect(self._changeView) + + self.projView.selectedItemChanged.connect(self.itemDetails.updateViewBox) + self.projView.openDocumentRequest.connect(self._openDocument) + self.projView.wordCountsChanged.connect(self._updateStatusWordCount) + self.projView.treeItemChanged.connect(self.docEditor.updateDocInfo) + self.projView.treeItemChanged.connect(self.docViewer.updateDocInfo) + self.projView.treeItemChanged.connect(self.itemDetails.updateViewBox) + self.projView.rootFolderChanged.connect(self.outlineView.updateRootItem) + self.projView.rootFolderChanged.connect(self.novelView.updateRootItem) + + self.novelView.selectedItemChanged.connect(self.itemDetails.updateViewBox) + self.novelView.openDocumentRequest.connect(self._openDocument) + + self.docEditor.spellDictionaryChanged.connect(self.statusBar.setLanguage) + self.docEditor.docEditedStatusChanged.connect(self.statusBar.doUpdateDocumentStatus) + self.docEditor.docCountsChanged.connect(self.itemDetails.updateCounts) + self.docEditor.docCountsChanged.connect(self.projView.updateCounts) + self.docEditor.loadDocumentTagRequest.connect(self._followTag) + + self.docViewer.loadDocumentTagRequest.connect(self._followTag) + + self.outlineView.loadDocumentTagRequest.connect(self._followTag) # Finalise Initialisation # ======================= @@ -317,15 +294,15 @@ class GuiMain(QMainWindow): """Wrapper function to clear all sub-elements of the main GUI. """ # Project Area - self.treeView.clearTree() - self.novelView.clearTree() - self.treeMeta.clearDetails() + self.projView.clearProject() + self.novelView.clearProject() + self.itemDetails.clearDetails() # Work Area self.docEditor.clearEditor() self.docEditor.setDictionaries() self.closeDocViewer() - self.projMeta.clearDetails() + self.outlineView.clearProject() # General self.statusBar.clearStatus() @@ -387,6 +364,8 @@ class GuiMain(QMainWindow): self.rebuildTrees() self.saveProject() self.docEditor.setDictionaries() + self.novelView.openProjectTasks() + self.outlineView.openProjectTasks() self.rebuildIndex(beQuiet=True) self.statusBar.setRefTime(self.theProject.projOpened) self.statusBar.setProjectStatus(nwState.GOOD) @@ -442,16 +421,17 @@ class GuiMain(QMainWindow): if saveOK: self.closeDocument() self.docViewer.clearNavHistory() - self.projView.closeOutline() + self.outlineView.closeProjectTasks() + self.novelView.closeProjectTasks() self.theProject.closeProject(self.idleTime) self.idleRefTime = time() self.idleTime = 0.0 - self.theIndex.clearIndex() + self.theProject.index.clearIndex() self.clearGUI() self.hasProject = False - self.mainTabs.setCurrentWidget(self.splitDocs) + self._changeView(nwView.PROJECT) return saveOK @@ -467,7 +447,7 @@ class GuiMain(QMainWindow): return False # Switch main tab to editor view - self.mainTabs.setCurrentWidget(self.splitDocs) + self._changeView(nwView.PROJECT) # Try to open the project if not self.theProject.openProject(projFile): @@ -525,15 +505,16 @@ class GuiMain(QMainWindow): self.idleTime = 0.0 # Load the tag index - self.theIndex.loadIndex() + self.theProject.index.loadIndex() # Update GUI self._updateWindowTitle(self.theProject.projName) self.rebuildTrees() self.docEditor.setDictionaries() self.docEditor.toggleSpellCheck(self.theProject.spellCheck) - self.mainMenu.setAutoOutline(self.theProject.autoOutline) self.statusBar.setRefTime(self.theProject.projOpened) + self.novelView.openProjectTasks() + self.outlineView.openProjectTasks() self._updateStatusWordCount() # Restore previously open documents, if any @@ -544,10 +525,10 @@ class GuiMain(QMainWindow): self.viewDocument(self.theProject.lastViewed) # Check if we need to rebuild the index - if self.theIndex.indexBroken: + if self.theProject.index.indexBroken: self.makeAlert(self.tr( "The project index is outdated or broken. Rebuilding index." - ), nwAlert.WARN) + ), nwAlert.INFO) self.rebuildIndex() # Make sure the changed status is set to false on things opened @@ -566,9 +547,9 @@ class GuiMain(QMainWindow): logger.error("No project open") return False - self.treeView.saveTreeOrder() + self.projView.saveProjectTree() if self.theProject.saveProject(autoSave=autoSave): - self.theIndex.saveIndex() + self.theProject.index.saveIndex() return True @@ -576,7 +557,7 @@ class GuiMain(QMainWindow): # Document Actions ## - def closeDocument(self): + def closeDocument(self, beforeOpen=False): """Close the document and clear the editor and title field. """ if not self.hasProject: @@ -591,6 +572,8 @@ class GuiMain(QMainWindow): if self.docEditor.docChanged(): self.saveDocument() self.docEditor.clearEditor() + if not beforeOpen: + self.novelView.setActiveHandle(None) return True @@ -601,17 +584,18 @@ class GuiMain(QMainWindow): logger.error("No project open") return False - if not self.theProject.projTree.checkType(tHandle, nwItemType.FILE): + if not self.theProject.tree.checkType(tHandle, nwItemType.FILE): logger.debug("Requested item '%s' is not a document", tHandle) return False - self.closeDocument() - self.mainTabs.setCurrentWidget(self.splitDocs) + self.closeDocument(beforeOpen=True) + self._changeView(nwView.EDITOR) if self.docEditor.loadText(tHandle, tLine): if changeFocus: self.docEditor.setFocus() self.theProject.setLastEdited(tHandle) - self.treeView.setSelectedHandle(tHandle, doScroll=doScroll) + self.projView.setSelectedHandle(tHandle, doScroll=doScroll) + self.novelView.setActiveHandle(tHandle) else: return False @@ -625,12 +609,11 @@ class GuiMain(QMainWindow): logger.error("No project open") return False - self.treeView.flushTreeOrder() nHandle = None # The next handle after tHandle fHandle = None # The first file handle we encounter foundIt = False # We've found tHandle, pick the next we see - for tItem in self.theProject.projTree: - if not self.theProject.projTree.checkType(tItem.itemHandle, nwItemType.FILE): + for tItem in self.theProject.tree: + if not self.theProject.tree.checkType(tItem.itemHandle, nwItemType.FILE): continue if fHandle is None: fHandle = tItem.itemHandle @@ -678,7 +661,7 @@ class GuiMain(QMainWindow): self.saveDocument() else: logger.verbose("Trying selected document") - tHandle = self.treeView.getSelectedHandle() + tHandle = self.projView.getSelectedHandle() if tHandle is None: logger.verbose("Trying last viewed document") @@ -689,7 +672,7 @@ class GuiMain(QMainWindow): return False # Make sure main tab is in Editor view - self.mainTabs.setCurrentWidget(self.splitDocs) + self._changeView(nwView.EDITOR) logger.debug("Viewing document with handle '%s'", tHandle) if self.docViewer.loadText(tHandle): @@ -815,12 +798,12 @@ class GuiMain(QMainWindow): tHandle = None tLine = None - if self.treeView.hasFocus(): - tHandle = self.treeView.getSelectedHandle() - elif self.novelView.hasFocus(): + if self.projView.treeHasFocus(): + tHandle = self.projView.getSelectedHandle() + elif self.novelView.treeHasFocus(): tHandle, tLine = self.novelView.getSelectedHandle() - elif self.projView.hasFocus(): - tHandle, tLine = self.projView.getSelectedHandle() + elif self.outlineView.treeHasFocus(): + tHandle, tLine = self.outlineView.getSelectedHandle() else: logger.warning("No item selected") return False @@ -830,7 +813,7 @@ class GuiMain(QMainWindow): return True - def editItem(self, tHandle=None): + def editItemLabel(self, tHandle=None): """Open the edit item dialog. """ if not self.hasProject: @@ -841,42 +824,23 @@ class GuiMain(QMainWindow): if self.docEditor.anyFocus() or self.isFocusMode: tHandle = self.docEditor.docHandle() else: - tHandle = self.treeView.getSelectedHandle() + tHandle = self.projView.getSelectedHandle() + if tHandle: + return self.projView.renameTreeItem(tHandle) - if tHandle is None: - logger.warning("No item selected") - return False - - tItem = self.theProject.projTree[tHandle] - if tItem is None: - return False - if tItem.itemType not in nwLists.REG_TYPES: - return False - - logger.verbose("Requesting change to item '%s'", tHandle) - dlgProj = GuiItemEditor(self, tHandle) - dlgProj.exec_() - if dlgProj.result() == QDialog.Accepted: - self.treeView.setTreeItemValues(tHandle) - self.treeMeta.updateViewBox(tHandle) - self.docEditor.updateDocInfo(tHandle) - self.docViewer.updateDocInfo(tHandle) - - return True + return False def rebuildTrees(self): """Rebuild the project tree. """ - self._makeStatusIcons() - self._makeImportIcons() - self.treeView.buildTree() - self.novelView.refreshTree() + self.projView.populateTree() + # self.novelView.refreshTree() return def requestNovelTreeRefresh(self): """Update the novel tree, but only if it is visible. """ - if self.projTabs.currentIndex() == self.idxNovelView and self.hasProject: + if self.projStack.currentIndex() == self.idxNovelView and self.hasProject: self.novelView.refreshTree() return True return False @@ -892,27 +856,18 @@ class GuiMain(QMainWindow): qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) tStart = time() - self.treeView.saveTreeOrder() - self.theIndex.clearIndex() + self.projView.saveProjectTree() + self.theProject.index.clearIndex() - for tItem in self.theProject.projTree: + for tItem in self.theProject.tree: + if tItem is None: # pragma: no cover + continue # This is a bug trap - if tItem is not None: - self.setStatus(self.tr("Indexing: '{0}'").format(tItem.itemName)) - else: - self.setStatus(self.tr("Indexing: '{0}'").format(self.tr("Unknown item"))) - - if tItem is not None and tItem.itemType == nwItemType.FILE: - logger.verbose("Scanning '%s'", tItem.itemName) - self.theIndex.reIndexHandle(tItem.itemHandle) - - # Get Word Counts - cC, wC, pC = self.theIndex.getCounts(tItem.itemHandle) - tItem.setCharCount(cC) - tItem.setWordCount(wC) - tItem.setParaCount(pC) - self.treeView.propagateCount(tItem.itemHandle, wC) - self.treeView.setTreeItemValues(tItem.itemHandle) + logger.verbose("Indexing '%s'", tItem.itemName) + if self.theProject.index.reIndexHandle(tItem.itemHandle): + # Update Word Counts + self.projView.propagateCount(tItem.itemHandle, tItem.wordCount, countChildren=True) + self.projView.setTreeItemValues(tItem.itemHandle) tEnd = time() self.setStatus( @@ -929,19 +884,6 @@ class GuiMain(QMainWindow): return True - def rebuildOutline(self): - """Force a rebuild of the Outline view. - """ - if not self.hasProject: - logger.error("No project open") - return False - - logger.verbose("Forcing a rebuild of the Project Outline") - self.mainTabs.setCurrentWidget(self.splitOutline) - self.projView.refreshTree(overRide=True) - - return True - ## # Main Dialogs ## @@ -982,14 +924,13 @@ class GuiMain(QMainWindow): if dlgConf.result() == QDialog.Accepted: logger.debug("Applying new preferences") self.initMain() - self.theTheme.updateTheme() + self.mainTheme.updateTheme() self.saveDocument() self.docEditor.initEditor() self.docViewer.initViewer() - self.treeView.initTree() - self.novelView.initTree() - self.projView.initOutline() - self.projMeta.initDetails() + self.projView.initSettings() + self.novelView.initSettings() + self.outlineView.initSettings() self._updateStatusWordCount() return @@ -1006,7 +947,9 @@ class GuiMain(QMainWindow): if dlgProj.result() == QDialog.Accepted: logger.debug("Applying new project settings") - self.docEditor.setDictionaries() + if dlgProj.spellChanged: + self.docEditor.setDictionaries() + self.itemDetails.refreshDetails() self._updateWindowTitle(self.theProject.projName) return True @@ -1018,8 +961,6 @@ class GuiMain(QMainWindow): logger.error("No project open") return False - self.treeView.flushTreeOrder() - dlgDetails = getGuiItem("GuiProjectDetails") if dlgDetails is None: dlgDetails = GuiProjectDetails(self) @@ -1050,6 +991,24 @@ class GuiMain(QMainWindow): return True + def showLoremIpsumDialog(self): + """Open the insert lorem ipsum text dialog. + """ + if not self.hasProject: + logger.error("No project open") + return False + + dlgLipsum = getGuiItem("GuiLipsum") + if dlgLipsum is None: + dlgLipsum = GuiLipsum(self) + + dlgLipsum.setModal(False) + dlgLipsum.show() + dlgLipsum.raise_() + qApp.processEvents() + + return True + def showProjectWordListDialog(self): """Open the project word list dialog. """ @@ -1206,13 +1165,11 @@ class GuiMain(QMainWindow): if not self.isFocusMode: self.mainConf.setMainPanePos(self.splitMain.sizes()) self.mainConf.setDocPanePos(self.splitDocs.sizes()) - self.mainConf.setOutlinePanePos(self.splitOutline.sizes()) + self.mainConf.setOutlinePanePos(self.outlineView.splitSizes()) if self.viewMeta.isVisible(): self.mainConf.setViewPanePos(self.splitView.sizes()) self.mainConf.setShowRefPanel(self.viewMeta.isVisible()) - self.mainConf.setTreeColWidths(self.treeView.getColumnSizes()) - self.mainConf.setNovelColWidths(self.novelView.getColumnSizes()) if not self.mainConf.isFullScreen: self.mainConf.setWinSize(self.width(), self.height()) @@ -1230,20 +1187,20 @@ class GuiMain(QMainWindow): """Switch focus between main GUI views. """ if paneNo == nwWidget.TREE: - tabIdx = self.projTabs.currentIndex() - if tabIdx == self.idxTreeView: - self.treeView.setFocus() + tabIdx = self.projStack.currentIndex() + if tabIdx == self.idxProjView: + self.projView.setFocus() elif tabIdx == self.idxNovelView: - self.novelView.setFocus() + self.novelView.setTreeFocus() elif paneNo == nwWidget.EDITOR: - self.mainTabs.setCurrentWidget(self.splitDocs) + self._changeView(nwView.EDITOR) self.docEditor.setFocus() elif paneNo == nwWidget.VIEWER: - self.mainTabs.setCurrentWidget(self.splitDocs) + self._changeView(nwView.EDITOR) self.docViewer.setFocus() elif paneNo == nwWidget.OUTLINE: - self.mainTabs.setCurrentWidget(self.splitOutline) - self.projView.setFocus() + self._changeView(nwView.OUTLINE) + self.outlineView.setTreeFocus() return def closeDocEditor(self): @@ -1275,7 +1232,6 @@ class GuiMain(QMainWindow): self.mainMenu.setFocusMode(self.isFocusMode) if self.isFocusMode: logger.debug("Activating Focus Mode") - self.mainTabs.setCurrentWidget(self.splitDocs) self.switchFocus(nwWidget.EDITOR) else: logger.debug("Deactivating Focus Mode") @@ -1284,7 +1240,7 @@ class GuiMain(QMainWindow): self.treePane.setVisible(isVisible) self.statusBar.setVisible(isVisible) self.mainMenu.setVisible(isVisible) - self.mainTabs.tabBar().setVisible(isVisible) + self.viewsBar.setVisible(isVisible) hideDocFooter = self.isFocusMode and self.mainConf.hideFocusFooter self.docEditor.docFooter.setVisible(not hideDocFooter) @@ -1412,7 +1368,7 @@ class GuiMain(QMainWindow): return True def _updateWindowTitle(self, projName=None): - """Set the window title and add the project's working title. + """Set the window title and add the project's name. """ winTitle = self.mainConf.appName if projName is not None: @@ -1442,29 +1398,6 @@ class GuiMain(QMainWindow): self.saveDocument() return - def _makeStatusIcons(self): - """Generate all the item status icons based on project settings. - """ - self.statusIcons = {} - iPx = self.mainConf.pxInt(32) - for sLabel, sCol, _ in self.theProject.statusItems: - theIcon = QPixmap(iPx, iPx) - theIcon.fill(QColor(*sCol)) - self.statusIcons[sLabel] = QIcon(theIcon) - return - - def _makeImportIcons(self): - """Generate all the item importance icons based on project - settings. - """ - self.importIcons = {} - iPx = self.mainConf.pxInt(32) - for sLabel, sCol, _ in self.theProject.importItems: - theIcon = QPixmap(iPx, iPx) - theIcon.fill(QColor(*sCol)) - self.importIcons[sLabel] = QIcon(theIcon) - return - def _assembleProjectWizardData(self, newProj): """Extract the user choices from the New Project Wizard and store them in a dictionary. @@ -1478,9 +1411,9 @@ class GuiMain(QMainWindow): "popMinimal": newProj.field("popMinimal"), "popCustom": newProj.field("popCustom"), "addRoots": [], + "addNotes": False, "numChapters": 0, "numScenes": 0, - "chFolders": False, } if newProj.field("popCustom"): addRoots = [] @@ -1490,19 +1423,30 @@ class GuiMain(QMainWindow): addRoots.append(nwItemClass.CHARACTER) if newProj.field("addWorld"): addRoots.append(nwItemClass.WORLD) - if newProj.field("addTime"): - addRoots.append(nwItemClass.TIMELINE) - if newProj.field("addObject"): - addRoots.append(nwItemClass.OBJECT) - if newProj.field("addEntity"): - addRoots.append(nwItemClass.ENTITY) projData["addRoots"] = addRoots + projData["addNotes"] = newProj.field("addNotes") projData["numChapters"] = newProj.field("numChapters") projData["numScenes"] = newProj.field("numScenes") - projData["chFolders"] = newProj.field("chFolders") return projData + def _getTagSource(self, tTag): + """A wrapper function for the index lookup of a tag that will + display an alert if the tag cannot be found. + """ + tHandle, sTitle = self.theProject.index.getTagSource(tTag) + if tHandle is None: + self.makeAlert(self.tr( + "Could not find the reference for tag '{0}'. It either doesn't " + "exist, or the index is out of date. The index can be updated " + "from the Tools menu, or by pressing {1}." + ).format( + tTag, "F9" + ), nwAlert.ERROR) + return None, None + + return tHandle, sTitle + ## # Events ## @@ -1518,9 +1462,53 @@ class GuiMain(QMainWindow): return ## - # Slots + # Private Slots ## + @pyqtSlot(str, Enum) + def _followTag(self, tTag, tMode): + """Follow a tag after user interaction with a link. + """ + tHandle, sTitle = self._getTagSource(tTag) + if tHandle is not None: + if tMode == nwDocMode.EDIT: + self.openDocument(tHandle) + elif tMode == nwDocMode.VIEW: + self.viewDocument(tHandle=tHandle, tAnchor=f"#{sTitle}") + return + + @pyqtSlot(str, Enum, int, str) + def _openDocument(self, tHandle, tMode, tLine, tAnchor): + """Handle an open document request from one of the tree views. + """ + if tHandle is not None: + if tMode == nwDocMode.EDIT: + self.openDocument(tHandle, tLine=tLine, changeFocus=False) + elif tMode == nwDocMode.VIEW: + self.viewDocument(tHandle=tHandle, tAnchor=(tAnchor or None)) + return + + @pyqtSlot(nwView) + def _changeView(self, view): + """Handle the requested change of view from the GuiViewBar. + """ + if view == nwView.EDITOR: + # Only change the main stack, but not the project stack + self.mainStack.setCurrentWidget(self.splitMain) + + elif view == nwView.PROJECT: + self.mainStack.setCurrentWidget(self.splitMain) + self.projStack.setCurrentWidget(self.projView) + + elif view == nwView.NOVEL: + self.mainStack.setCurrentWidget(self.splitMain) + self.projStack.setCurrentWidget(self.novelView) + + elif view == nwView.OUTLINE: + self.mainStack.setCurrentWidget(self.outlineView) + + return + @pyqtSlot() def _timeTick(self): """Triggered on every tick of the main timer. @@ -1563,39 +1551,6 @@ class GuiMain(QMainWindow): return - @pyqtSlot() - def _treeSingleClick(self): - """Single click on a project tree item just updates the details - panel below the tree. - """ - tHandle = self.treeView.getSelectedHandle() - if tHandle is not None: - self.treeMeta.updateViewBox(tHandle) - return - - @pyqtSlot("QTreeWidgetItem*", int) - def _treeDoubleClick(self, tItem, colNo): - """The user double-clicked an item in the tree. If it is a file, - we open it. Otherwise, we do nothing. - """ - tHandle = self.treeView.getSelectedHandle() - if tHandle is not None: - self.openDocument(tHandle, changeFocus=False, doScroll=False) - return - - @pyqtSlot() - def _treeNovelItemChanged(self): - """Triggered when there is a change to a novel item in the - project tree. - """ - if self.mainTabs.currentIndex() == self.idxTabProj: - logger.verbose("Novel tree changed while Outline tab active") - if self.hasProject: - self.treeView.flushTreeOrder() - self.projView.refreshTree(novelChanged=True) - - return - @pyqtSlot() def _keyPressReturn(self): """Forward the return/enter keypress to the function that opens @@ -1617,35 +1572,35 @@ class GuiMain(QMainWindow): return @pyqtSlot(int) - def _mainTabChanged(self, tabIndex): + def _mainStackChanged(self, stIndex): """Activated when the main window tab is changed. """ - if tabIndex == self.idxTabEdit: - logger.verbose("Editor tab activated") - elif tabIndex == self.idxTabProj: - logger.verbose("Project outline tab activated") + if stIndex == self.idxEditorView: + logger.verbose("Editor View activated") + elif stIndex == self.idxOutlineView: + logger.verbose("Outline View activated") if self.hasProject: - self.projView.refreshTree() + self.outlineView.refreshTree() return @pyqtSlot(int) - def _projTabsChanged(self, tabIndex): + def _projStackChanged(self, stIndex): """Activated when the project view tab is changed. """ sHandle = None - if tabIndex == self.idxTreeView: - logger.verbose("Project tree tab activated") - sHandle = self.treeView.getSelectedHandle() + if stIndex == self.idxProjView: + logger.verbose("Project Tree View activated") + sHandle = self.projView.getSelectedHandle() - elif tabIndex == self.idxNovelView: - logger.verbose("Novel tree tab activated") + elif stIndex == self.idxNovelView: + logger.verbose("Novel Tree View activated") if self.hasProject: self.novelView.refreshTree() sHandle, _ = self.novelView.getSelectedHandle() - self.treeMeta.updateViewBox(sHandle) + self.itemDetails.updateViewBox(sHandle) return diff --git a/novelwriter/tools/__init__.py b/novelwriter/tools/__init__.py index b42ec956..024ae3fd 100644 --- a/novelwriter/tools/__init__.py +++ b/novelwriter/tools/__init__.py @@ -20,11 +20,13 @@ along with this program. If not, see . """ from novelwriter.tools.build import GuiBuildNovel +from novelwriter.tools.lipsum import GuiLipsum from novelwriter.tools.projwizard import GuiProjectWizard from novelwriter.tools.writingstats import GuiWritingStats __all__ = [ "GuiBuildNovel", + "GuiLipsum", "GuiProjectWizard", "GuiWritingStats", ] diff --git a/novelwriter/tools/build.py b/novelwriter/tools/build.py index d852a33f..7a0eba6c 100644 --- a/novelwriter/tools/build.py +++ b/novelwriter/tools/build.py @@ -65,17 +65,16 @@ class GuiBuildNovel(QDialog): FMT_JSON_H = 8 # HTML5 wrapped in JSON FMT_JSON_M = 9 # nW Markdown wrapped in JSON - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiBuildNovel ...") self.setObjectName("GuiBuildNovel") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject self.htmlText = [] # List of html documents self.htmlStyle = [] # List of html styles @@ -86,14 +85,15 @@ class GuiBuildNovel(QDialog): self.setMinimumWidth(self.mainConf.pxInt(700)) self.setMinimumHeight(self.mainConf.pxInt(600)) + pOptions = self.theProject.options self.resize( - self.mainConf.pxInt(self.optState.getInt("GuiBuildNovel", "winWidth", 900)), - self.mainConf.pxInt(self.optState.getInt("GuiBuildNovel", "winHeight", 800)) + self.mainConf.pxInt(pOptions.getInt("GuiBuildNovel", "winWidth", 900)), + self.mainConf.pxInt(pOptions.getInt("GuiBuildNovel", "winHeight", 800)) ) self.docView = GuiBuildNovelDocView(self, self.theProject) - hS = self.theTheme.fontPixelSize + hS = self.mainTheme.fontPixelSize wS = 2*hS # Title Formats @@ -174,12 +174,12 @@ class GuiBuildNovel(QDialog): self.hideScene = QSwitch(width=wS, height=hS) self.hideScene.setChecked( - self.optState.getBool("GuiBuildNovel", "hideScene", False) + pOptions.getBool("GuiBuildNovel", "hideScene", False) ) self.hideSection = QSwitch(width=wS, height=hS) self.hideSection.setChecked( - self.optState.getBool("GuiBuildNovel", "hideSection", True) + pOptions.getBool("GuiBuildNovel", "hideSection", True) ) # Wrapper boxes due to QGridView and QLineEdit expand bug @@ -235,29 +235,29 @@ class GuiBuildNovel(QDialog): self.textFont.setReadOnly(True) self.textFont.setMinimumWidth(xFmt) self.textFont.setText( - self.optState.getString("GuiBuildNovel", "textFont", self.mainConf.textFont) + pOptions.getString("GuiBuildNovel", "textFont", self.mainConf.textFont) ) self.fontButton = QPushButton("...") - self.fontButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) + self.fontButton.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.fontButton.clicked.connect(self._selectFont) self.textSize = QSpinBox(self) - self.textSize.setFixedWidth(6*self.theTheme.textNWidth) + self.textSize.setFixedWidth(6*self.mainTheme.textNWidth) self.textSize.setMinimum(6) self.textSize.setMaximum(72) self.textSize.setSingleStep(1) self.textSize.setValue( - self.optState.getInt("GuiBuildNovel", "textSize", self.mainConf.textSize) + pOptions.getInt("GuiBuildNovel", "textSize", self.mainConf.textSize) ) self.lineHeight = QDoubleSpinBox(self) - self.lineHeight.setFixedWidth(6*self.theTheme.textNWidth) + self.lineHeight.setFixedWidth(6*self.mainTheme.textNWidth) self.lineHeight.setMinimum(0.8) self.lineHeight.setMaximum(3.0) self.lineHeight.setSingleStep(0.05) self.lineHeight.setDecimals(2) self.lineHeight.setValue( - self.optState.getFloat("GuiBuildNovel", "lineHeight", 1.15) + pOptions.getFloat("GuiBuildNovel", "lineHeight", 1.15) ) # Wrapper box due to QGridView and QLineEdit expand bug @@ -291,12 +291,12 @@ class GuiBuildNovel(QDialog): self.justifyText = QSwitch(width=wS, height=hS) self.justifyText.setChecked( - self.optState.getBool("GuiBuildNovel", "justifyText", False) + pOptions.getBool("GuiBuildNovel", "justifyText", False) ) self.noStyling = QSwitch(width=wS, height=hS) self.noStyling.setChecked( - self.optState.getBool("GuiBuildNovel", "noStyling", False) + pOptions.getBool("GuiBuildNovel", "noStyling", False) ) self.styleForm.addWidget(justifyLabel, 1, 0, 1, 1, Qt.AlignLeft) @@ -316,22 +316,22 @@ class GuiBuildNovel(QDialog): self.includeSynopsis = QSwitch(width=wS, height=hS) self.includeSynopsis.setChecked( - self.optState.getBool("GuiBuildNovel", "incSynopsis", False) + pOptions.getBool("GuiBuildNovel", "incSynopsis", False) ) self.includeComments = QSwitch(width=wS, height=hS) self.includeComments.setChecked( - self.optState.getBool("GuiBuildNovel", "incComments", False) + pOptions.getBool("GuiBuildNovel", "incComments", False) ) self.includeKeywords = QSwitch(width=wS, height=hS) self.includeKeywords.setChecked( - self.optState.getBool("GuiBuildNovel", "incKeywords", False) + pOptions.getBool("GuiBuildNovel", "incKeywords", False) ) self.includeBody = QSwitch(width=wS, height=hS) self.includeBody.setChecked( - self.optState.getBool("GuiBuildNovel", "incBodyText", True) + pOptions.getBool("GuiBuildNovel", "incBodyText", True) ) synopsisLabel = QLabel(self.tr("Include synopsis")) @@ -360,17 +360,17 @@ class GuiBuildNovel(QDialog): self.novelFiles = QSwitch(width=wS, height=hS) self.novelFiles.setChecked( - self.optState.getBool("GuiBuildNovel", "addNovel", True) + pOptions.getBool("GuiBuildNovel", "addNovel", True) ) self.noteFiles = QSwitch(width=wS, height=hS) self.noteFiles.setChecked( - self.optState.getBool("GuiBuildNovel", "addNotes", False) + pOptions.getBool("GuiBuildNovel", "addNotes", False) ) self.ignoreFlag = QSwitch(width=wS, height=hS) self.ignoreFlag.setChecked( - self.optState.getBool("GuiBuildNovel", "ignoreFlag", False) + pOptions.getBool("GuiBuildNovel", "ignoreFlag", False) ) novelLabel = QLabel(self.tr("Include novel files")) @@ -396,12 +396,12 @@ class GuiBuildNovel(QDialog): self.replaceTabs = QSwitch(width=wS, height=hS) self.replaceTabs.setChecked( - self.optState.getBool("GuiBuildNovel", "replaceTabs", False) + pOptions.getBool("GuiBuildNovel", "replaceTabs", False) ) self.replaceUCode = QSwitch(width=wS, height=hS) self.replaceUCode.setChecked( - self.optState.getBool("GuiBuildNovel", "replaceUCode", False) + pOptions.getBool("GuiBuildNovel", "replaceUCode", False) ) tabsLabel = QLabel(self.tr("Replace tabs with spaces")) @@ -493,9 +493,9 @@ class GuiBuildNovel(QDialog): # Splitter Position boxWidth = self.mainConf.pxInt(350) - boxWidth = self.optState.getInt("GuiBuildNovel", "boxWidth", boxWidth) + boxWidth = pOptions.getInt("GuiBuildNovel", "boxWidth", boxWidth) docWidth = max(self.width() - boxWidth, 100) - docWidth = self.optState.getInt("GuiBuildNovel", "docWidth", docWidth) + docWidth = pOptions.getInt("GuiBuildNovel", "docWidth", docWidth) # The Tool Box self.toolsBox = QVBoxLayout() @@ -677,7 +677,7 @@ class GuiBuildNovel(QDialog): replaceUCode = self.replaceUCode.isChecked() # The language lookup dict is reloaded if needed - self.theProject.setProjectLang(self.buildLang.currentData()) + self.theProject.setProjectLang(buildLang) # Get font information fontInfo = QFontInfo(QFont(textFont, textSize)) @@ -711,13 +711,12 @@ class GuiBuildNovel(QDialog): bldObj.initDocument() # Make sure the project and document is up to date - self.theParent.treeView.flushTreeOrder() - self.theParent.saveDocument() + self.mainGui.saveDocument() - self.buildProgress.setMaximum(len(self.theProject.projTree)) + self.buildProgress.setMaximum(len(self.theProject.tree)) self.buildProgress.setValue(0) - for nItt, tItem in enumerate(self.theProject.projTree): + for nItt, tItem in enumerate(self.theProject.tree): noteRoot = noteFiles noteRoot &= tItem.itemType == nwItemType.ROOT @@ -761,7 +760,7 @@ class GuiBuildNovel(QDialog): logger.debug("Built project in %.3f ms", 1000*(tEnd - tStart)) if bldObj.errData: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("There were problems when building the project:") ] + bldObj.errData, nwAlert.ERROR) @@ -782,16 +781,14 @@ class GuiBuildNovel(QDialog): if theItem is None: return False - if not theItem.isExported and not ignoreFlag: + if not (theItem.isExported or ignoreFlag): return False - isNone = theItem.itemType != nwItemType.FILE + isNone = not theItem.isFileType() isNone |= theItem.itemLayout == nwItemLayout.NO_LAYOUT - isNone |= theItem.itemClass == nwItemClass.NO_CLASS - isNone |= theItem.itemClass == nwItemClass.TRASH - isNone |= theItem.itemParent == self.theProject.projTree.trashRoot() + isNone |= theItem.isInactive() isNone |= theItem.itemParent is None - isNote = theItem.itemLayout == nwItemLayout.NOTE + isNote = theItem.isNoteLayout() isNovel = not isNone and not isNote if isNone: @@ -801,10 +798,6 @@ class GuiBuildNovel(QDialog): if isNovel and not novelFiles: return False - rootItem = self.theProject.projTree.getRootItem(theItem.itemHandle) - if rootItem.itemClass == nwItemClass.ARCHIVE: - return False - return True def _saveDocument(self, theFmt): @@ -1010,11 +1003,11 @@ class GuiBuildNovel(QDialog): # ============== if wSuccess: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("{0} file successfully written to:").format(textFmt), savePath ], nwAlert.INFO) else: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to write {0} file. {1}" ).format(textFmt, errMsg), nwAlert.ERROR) @@ -1161,28 +1154,28 @@ class GuiBuildNovel(QDialog): self.theProject.setProjectLang(buildLang) # GUI Settings - self.optState.setValue("GuiBuildNovel", "hideScene", hideScene) - self.optState.setValue("GuiBuildNovel", "hideSection", hideSection) - self.optState.setValue("GuiBuildNovel", "winWidth", winWidth) - self.optState.setValue("GuiBuildNovel", "winHeight", winHeight) - self.optState.setValue("GuiBuildNovel", "boxWidth", boxWidth) - self.optState.setValue("GuiBuildNovel", "docWidth", docWidth) - self.optState.setValue("GuiBuildNovel", "justifyText", justifyText) - self.optState.setValue("GuiBuildNovel", "noStyling", noStyling) - self.optState.setValue("GuiBuildNovel", "textFont", textFont) - self.optState.setValue("GuiBuildNovel", "textSize", textSize) - self.optState.setValue("GuiBuildNovel", "lineHeight", lineHeight) - self.optState.setValue("GuiBuildNovel", "addNovel", novelFiles) - self.optState.setValue("GuiBuildNovel", "addNotes", noteFiles) - self.optState.setValue("GuiBuildNovel", "ignoreFlag", ignoreFlag) - self.optState.setValue("GuiBuildNovel", "incSynopsis", incSynopsis) - self.optState.setValue("GuiBuildNovel", "incComments", incComments) - self.optState.setValue("GuiBuildNovel", "incKeywords", incKeywords) - self.optState.setValue("GuiBuildNovel", "incBodyText", incBodyText) - self.optState.setValue("GuiBuildNovel", "replaceTabs", replaceTabs) - self.optState.setValue("GuiBuildNovel", "replaceUCode", replaceUCode) - - self.optState.saveSettings() + pOptions = self.theProject.options + pOptions.setValue("GuiBuildNovel", "hideScene", hideScene) + pOptions.setValue("GuiBuildNovel", "hideSection", hideSection) + pOptions.setValue("GuiBuildNovel", "winWidth", winWidth) + pOptions.setValue("GuiBuildNovel", "winHeight", winHeight) + pOptions.setValue("GuiBuildNovel", "boxWidth", boxWidth) + pOptions.setValue("GuiBuildNovel", "docWidth", docWidth) + pOptions.setValue("GuiBuildNovel", "justifyText", justifyText) + pOptions.setValue("GuiBuildNovel", "noStyling", noStyling) + pOptions.setValue("GuiBuildNovel", "textFont", textFont) + pOptions.setValue("GuiBuildNovel", "textSize", textSize) + pOptions.setValue("GuiBuildNovel", "lineHeight", lineHeight) + pOptions.setValue("GuiBuildNovel", "addNovel", novelFiles) + pOptions.setValue("GuiBuildNovel", "addNotes", noteFiles) + pOptions.setValue("GuiBuildNovel", "ignoreFlag", ignoreFlag) + pOptions.setValue("GuiBuildNovel", "incSynopsis", incSynopsis) + pOptions.setValue("GuiBuildNovel", "incComments", incComments) + pOptions.setValue("GuiBuildNovel", "incKeywords", incKeywords) + pOptions.setValue("GuiBuildNovel", "incBodyText", incBodyText) + pOptions.setValue("GuiBuildNovel", "replaceTabs", replaceTabs) + pOptions.setValue("GuiBuildNovel", "replaceUCode", replaceUCode) + pOptions.saveSettings() return @@ -1200,18 +1193,18 @@ class GuiBuildNovel(QDialog): class GuiBuildNovelDocView(QTextBrowser): - def __init__(self, theParent, theProject): - QTextBrowser.__init__(self, theParent) + def __init__(self, mainGui, theProject): + QTextBrowser.__init__(self, mainGui) logger.debug("Initialising GuiBuildNovelDocView ...") self.mainConf = novelwriter.CONFIG self.theProject = theProject - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme self.buildTime = 0 - self.setMinimumWidth(40*self.theParent.theTheme.textNWidth) + self.setMinimumWidth(40*self.mainGui.mainTheme.textNWidth) self.setOpenExternalLinks(False) self.document().setDocumentMargin(self.mainConf.getTextMargin()) @@ -1245,9 +1238,9 @@ class GuiBuildNovelDocView(QTextBrowser): lblPalette.setColor(QPalette.Foreground, lblPalette.toolTipText().color()) lblFont = self.font() - lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.9*self.mainTheme.fontPointSize) - fPx = int(1.1*self.theTheme.fontPixelSize) + fPx = int(1.1*self.mainTheme.fontPixelSize) self.theTitle = QLabel("", self) self.theTitle.setIndent(0) diff --git a/novelwriter/tools/lipsum.py b/novelwriter/tools/lipsum.py new file mode 100644 index 00000000..2086d615 --- /dev/null +++ b/novelwriter/tools/lipsum.py @@ -0,0 +1,142 @@ +""" +novelWriter – Lorem Ipsum Tool +============================== +Simple tool for inserting placeholder text in a document + +File History: +Created: 2022-04-02 [1.7a0] + +This file is a part of novelWriter +Copyright 2018–2022, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +import os +import random +import logging +import novelwriter + +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import ( + QDialog, QGridLayout, QHBoxLayout, QVBoxLayout, QLabel, QDialogButtonBox, + QSpinBox +) + +from novelwriter.gui.custom import QSwitch +from novelwriter.common import readTextFile + +logger = logging.getLogger(__name__) + + +class GuiLipsum(QDialog): + + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) + + logger.debug("Initialising GuiLipsum ...") + self.setObjectName("GuiLipsum") + + self.mainConf = novelwriter.CONFIG + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + + self.setWindowTitle(self.tr("Insert Placeholder Text")) + + self.innerBox = QHBoxLayout() + self.innerBox.setSpacing(self.mainConf.pxInt(16)) + + # Icon + nPx = self.mainConf.pxInt(64) + vSp = self.mainConf.pxInt(4) + self.docIcon = QLabel() + self.docIcon.setPixmap(self.mainTheme.getPixmap("proj_document", (nPx, nPx))) + + self.leftBox = QVBoxLayout() + self.leftBox.setSpacing(vSp) + self.leftBox.addWidget(self.docIcon) + self.leftBox.addStretch(1) + self.innerBox.addLayout(self.leftBox) + + # Form + self.headLabel = QLabel("{0}".format(self.tr("Insert Lorem Ipsum Text"))) + + self.paraLabel = QLabel(self.tr("Number of paragraphs")) + self.paraCount = QSpinBox() + self.paraCount.setMinimum(1) + self.paraCount.setMaximum(100) + self.paraCount.setValue(5) + + self.randLabel = QLabel(self.tr("Randomise order")) + self.randSwitch = QSwitch() + + self.formBox = QGridLayout() + self.formBox.addWidget(self.headLabel, 0, 0, 1, 2, Qt.AlignLeft) + self.formBox.addWidget(self.paraLabel, 1, 0, 1, 1, Qt.AlignLeft) + self.formBox.addWidget(self.paraCount, 1, 1, 1, 1, Qt.AlignRight) + self.formBox.addWidget(self.randLabel, 2, 0, 1, 1, Qt.AlignLeft) + self.formBox.addWidget(self.randSwitch, 2, 1, 1, 1, Qt.AlignRight) + self.formBox.setVerticalSpacing(vSp) + self.formBox.setRowStretch(3, 1) + self.innerBox.addLayout(self.formBox) + + # Buttons + self.buttonBox = QDialogButtonBox() + self.buttonBox.rejected.connect(self._doClose) + + self.btnClose = self.buttonBox.addButton(QDialogButtonBox.Close) + self.btnClose.setAutoDefault(False) + + self.btnSave = self.buttonBox.addButton(self.tr("Insert"), QDialogButtonBox.ActionRole) + self.btnSave.clicked.connect(self._doInsert) + self.btnSave.setAutoDefault(False) + + # Assemble + self.outerBox = QVBoxLayout() + self.outerBox.addLayout(self.innerBox) + self.outerBox.addWidget(self.buttonBox) + self.outerBox.setSpacing(self.mainConf.pxInt(16)) + self.setLayout(self.outerBox) + + logger.debug("GuiLipsum initialisation complete") + + return + + ## + # Slots + ## + + def _doInsert(self): + """Load the text and insert it in the open document. + """ + lipsumFile = os.path.join(self.mainConf.assetPath, "text", "lipsum.txt") + lipsumText = readTextFile(lipsumFile).splitlines() + + if self.randSwitch.isChecked(): + random.shuffle(lipsumText) + + pCount = self.paraCount.value() + inText = "\n\n".join(lipsumText[0:pCount]) + "\n\n" + + self.mainGui.docEditor.insertText(inText) + + return + + def _doClose(self): + """Close the dialog window without doing anything. + """ + self.close() + return + +# END Class GuiLipsum diff --git a/novelwriter/tools/projwizard.py b/novelwriter/tools/projwizard.py index 8f746ca6..5b21f69a 100644 --- a/novelwriter/tools/projwizard.py +++ b/novelwriter/tools/projwizard.py @@ -31,12 +31,10 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QWizard, QWizardPage, QLabel, QVBoxLayout, QLineEdit, QPlainTextEdit, QPushButton, QFileDialog, QHBoxLayout, QRadioButton, QFormLayout, - QGroupBox, QGridLayout, QSpinBox + QGridLayout, QSpinBox ) -from novelwriter.enum import nwItemClass from novelwriter.common import makeFileNameSafe -from novelwriter.constants import trConst, nwLabels from novelwriter.gui.custom import QSwitch logger = logging.getLogger(__name__) @@ -50,17 +48,17 @@ PAGE_FINAL = 4 class GuiProjectWizard(QWizard): - def __init__(self, theParent): - QWizard.__init__(self, theParent) + def __init__(self, mainGui): + QWizard.__init__(self, mainGui) logger.debug("Initialising GuiProjectWizard ...") self.setObjectName("GuiProjectWizard") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme - self.sideImage = self.theTheme.loadDecoration( + self.sideImage = self.mainTheme.loadDecoration( "wiz-back", None, self.mainConf.pxInt(370) ) self.setWizardStyle(QWizard.ModernStyle) @@ -94,14 +92,14 @@ class ProjWizardIntroPage(QWizardPage): self.mainConf = novelwriter.CONFIG self.theWizard = theWizard - self.theTheme = theWizard.theTheme + self.mainTheme = theWizard.mainTheme self.setTitle(self.tr("Create New Project")) self.theText = QLabel(self.tr( - "Provide at least a working title. The working title should not " - "be change beyond this point as it is used by the application for " - "generating file names for for instance backups. The other fields " - "are optional and can be changed at any time in Project Settings." + "Provide at least a project name. The project name should not " + "be changed beyond this point as it is used for generating file " + "names for for instance backups. The other fields are optional " + "and can be changed at any time in Project Settings." )) self.theText.setWordWrap(True) @@ -109,7 +107,7 @@ class ProjWizardIntroPage(QWizardPage): "Peter Mitterhofer", "CC BY-SA 4.0" )) lblFont = self.imgCredit.font() - lblFont.setPointSizeF(0.6*self.theTheme.fontPointSize) + lblFont.setPointSizeF(0.6*self.mainTheme.fontPointSize) self.imgCredit.setFont(lblFont) xW = self.mainConf.pxInt(300) @@ -134,7 +132,7 @@ class ProjWizardIntroPage(QWizardPage): self.projAuthors.setPlaceholderText(self.tr("Optional. One name per line.")) self.mainForm = QFormLayout() - self.mainForm.addRow(self.tr("Working Title"), self.projName) + self.mainForm.addRow(self.tr("Project Name"), self.projName) self.mainForm.addRow(self.tr("Novel Title"), self.projTitle) self.mainForm.addRow(self.tr("Author(s)"), self.projAuthors) self.mainForm.setVerticalSpacing(fS) @@ -164,7 +162,7 @@ class ProjWizardFolderPage(QWizardPage): self.mainConf = novelwriter.CONFIG self.theWizard = theWizard - self.theTheme = theWizard.theTheme + self.mainTheme = theWizard.mainTheme self.setTitle(self.tr("Select Project Folder")) self.theText = QLabel(self.tr( @@ -182,9 +180,12 @@ class ProjWizardFolderPage(QWizardPage): self.projPath.setPlaceholderText(self.tr("Required")) self.browseButton = QPushButton("...") - self.browseButton.setMaximumWidth(int(2.5*self.theTheme.getTextWidth("..."))) + self.browseButton.setMaximumWidth(int(2.5*self.mainTheme.getTextWidth("..."))) self.browseButton.clicked.connect(self._doBrowse) + self.errLabel = QLabel("") + self.errLabel.setWordWrap(True) + self.mainForm = QHBoxLayout() self.mainForm.addWidget(QLabel(self.tr("Project Path")), 0) self.mainForm.addWidget(self.projPath, 1) @@ -198,11 +199,36 @@ class ProjWizardFolderPage(QWizardPage): self.outerBox.setSpacing(vS) self.outerBox.addWidget(self.theText) self.outerBox.addLayout(self.mainForm) + self.outerBox.addWidget(self.errLabel) self.outerBox.addStretch(1) self.setLayout(self.outerBox) return + def isComplete(self): + """Check that the selected path isn't already being used. + """ + self.errLabel.setText("") + if not QWizardPage.isComplete(self): + return False + + setPath = os.path.abspath(os.path.expanduser(self.projPath.text())) + parPath = os.path.dirname(setPath) + logger.verbose("Path is: %s", setPath) + if parPath and not os.path.isdir(parPath): + self.errLabel.setText(self.tr( + "Error: A project folder cannot be created using this path." + )) + return False + + if os.path.exists(setPath): + self.errLabel.setText(self.tr( + "Error: The selected path already exists." + )) + return False + + return True + ## # Slots ## @@ -296,68 +322,28 @@ class ProjWizardCustomPage(QWizardPage): self.setTitle(self.tr("Custom Project Options")) self.theText = QLabel(self.tr( - "Select which additional root folders to make, and how to populate " - "the Novel folder. If you don't want to add chapters or scenes, set " - "the values to 0. You can add scenes without chapters." + "Select which additional elements to populate the project with. " + "You can skip making chapters and add only scenes by setting the " + "number of chapters to 0." )) self.theText.setWordWrap(True) - vS = self.mainConf.pxInt(12) + cM = self.mainConf.pxInt(12) + mH = self.mainConf.pxInt(26) + fS = self.mainConf.pxInt(4) # Root Folders - self.rootGroup = QGroupBox(self.tr("Additional Root Folders")) - self.rootForm = QGridLayout() - self.rootGroup.setLayout(self.rootForm) - - self.lblPlot = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.PLOT])) - ) - self.lblChar = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.CHARACTER])) - ) - self.lblWorld = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.WORLD])) - ) - self.lblTime = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.TIMELINE])) - ) - self.lblObject = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.OBJECT])) - ) - self.lblEntity = QLabel(self.tr("{0} folder").format( - trConst(nwLabels.CLASS_NAME[nwItemClass.ENTITY])) - ) - - self.addPlot = QSwitch() - self.addChar = QSwitch() - self.addWorld = QSwitch() - self.addTime = QSwitch() - self.addObject = QSwitch() - self.addEntity = QSwitch() + self.addPlot = QSwitch() + self.addChar = QSwitch() + self.addWorld = QSwitch() + self.addNotes = QSwitch() self.addPlot.setChecked(True) self.addChar.setChecked(True) - self.addWorld.setChecked(True) - - self.rootForm.addWidget(self.lblPlot, 0, 0) - self.rootForm.addWidget(self.lblChar, 1, 0) - self.rootForm.addWidget(self.lblWorld, 2, 0) - self.rootForm.addWidget(self.lblTime, 3, 0) - self.rootForm.addWidget(self.lblObject, 4, 0) - self.rootForm.addWidget(self.lblEntity, 5, 0) - self.rootForm.addWidget(self.addPlot, 0, 1, 1, 1, Qt.AlignRight) - self.rootForm.addWidget(self.addChar, 1, 1, 1, 1, Qt.AlignRight) - self.rootForm.addWidget(self.addWorld, 2, 1, 1, 1, Qt.AlignRight) - self.rootForm.addWidget(self.addTime, 3, 1, 1, 1, Qt.AlignRight) - self.rootForm.addWidget(self.addObject, 4, 1, 1, 1, Qt.AlignRight) - self.rootForm.addWidget(self.addEntity, 5, 1, 1, 1, Qt.AlignRight) - self.rootForm.setRowStretch(6, 1) - - # Novel Options - self.novelGroup = QGroupBox(self.tr("Populate Novel Folder")) - self.novelForm = QGridLayout() - self.novelGroup.setLayout(self.novelForm) + self.addWorld.setChecked(False) + self.addNotes.setChecked(False) + # Generate Content self.numChapters = QSpinBox() self.numChapters.setRange(0, 100) self.numChapters.setValue(5) @@ -366,37 +352,40 @@ class ProjWizardCustomPage(QWizardPage): self.numScenes.setRange(0, 200) self.numScenes.setValue(5) - self.chFolders = QSwitch() - self.chFolders.setChecked(True) - - self.novelForm.addWidget(QLabel(self.tr("Add chapters")), 0, 0) - self.novelForm.addWidget(QLabel(self.tr("Scenes (per chapter)")), 1, 0) - self.novelForm.addWidget(QLabel(self.tr("Add chapter folders")), 2, 0) - self.novelForm.addWidget(self.numChapters, 0, 1, 1, 1, Qt.AlignRight) - self.novelForm.addWidget(self.numScenes, 1, 1, 1, 1, Qt.AlignRight) - self.novelForm.addWidget(self.chFolders, 2, 1, 1, 1, Qt.AlignRight) - self.novelForm.setRowStretch(3, 1) + # Grid Form + self.addBox = QGridLayout() + self.addBox.addWidget(QLabel(self.tr("Add a folder for plot notes")), 0, 0) + self.addBox.addWidget(QLabel(self.tr("Add a folder for character notes")), 1, 0) + self.addBox.addWidget(QLabel(self.tr("Add a folder for location notes")), 2, 0) + self.addBox.addWidget(QLabel(self.tr("Add example notes to the above")), 3, 0) + self.addBox.addWidget(QLabel(self.tr("Add chapters to the novel folder")), 4, 0) + self.addBox.addWidget(QLabel(self.tr("Add scenes to each chapter")), 5, 0) + self.addBox.addWidget(self.addPlot, 0, 1, 1, 1, Qt.AlignRight) + self.addBox.addWidget(self.addChar, 1, 1, 1, 1, Qt.AlignRight) + self.addBox.addWidget(self.addWorld, 2, 1, 1, 1, Qt.AlignRight) + self.addBox.addWidget(self.addNotes, 3, 1, 1, 1, Qt.AlignRight) + self.addBox.addWidget(self.numChapters, 4, 1, 1, 1, Qt.AlignRight) + self.addBox.addWidget(self.numScenes, 5, 1, 1, 1, Qt.AlignRight) + self.addBox.setVerticalSpacing(fS) + self.addBox.setHorizontalSpacing(cM) + self.addBox.setContentsMargins(cM, 0, cM, 0) + self.addBox.setColumnStretch(2, 1) + for i in range(6): + self.addBox.setRowMinimumHeight(i, mH) # Wizard Fields self.registerField("addPlot", self.addPlot) self.registerField("addChar", self.addChar) self.registerField("addWorld", self.addWorld) - self.registerField("addTime", self.addTime) - self.registerField("addObject", self.addObject) - self.registerField("addEntity", self.addEntity) + self.registerField("addNotes", self.addNotes) self.registerField("numChapters", self.numChapters) self.registerField("numScenes", self.numScenes) - self.registerField("chFolders", self.chFolders) # Assemble - self.innerBox = QHBoxLayout() - self.innerBox.addWidget(self.rootGroup) - self.innerBox.addWidget(self.novelGroup) - self.outerBox = QVBoxLayout() - self.outerBox.setSpacing(vS) + self.outerBox.setSpacing(cM) self.outerBox.addWidget(self.theText) - self.outerBox.addLayout(self.innerBox) + self.outerBox.addLayout(self.addBox) self.outerBox.addStretch(1) self.setLayout(self.outerBox) @@ -413,15 +402,8 @@ class ProjWizardFinalPage(QWizardPage): self.mainConf = novelwriter.CONFIG self.theWizard = theWizard - self.setTitle(self.tr("Finished")) - self.theText = QLabel( - "

%s

%s

" % ( - self.tr("All done."), - self.tr("Press '{0}' to create the new project.").format( - self.tr("Done") if self.mainConf.osDarwin else self.tr("Finish") - ) - ) - ) + self.setTitle(self.tr("Summary")) + self.theText = QLabel("") self.theText.setWordWrap(True) # Assemble @@ -433,4 +415,51 @@ class ProjWizardFinalPage(QWizardPage): return + def initializePage(self): + """Update the summary information on the final page. + """ + QWizardPage.initializePage(self) + + sumList = [] + sumList.append(self.tr("Project Name: {0}").format(self.field("projName"))) + sumList.append(self.tr("Project Path: {0}").format(self.field("projPath"))) + + if self.field("popMinimal"): + sumList.append(self.tr("Fill the project with a minimal set of items")) + elif self.field("popSample"): + sumList.append(self.tr("Fill the project with example files")) + elif self.field("popCustom"): + if self.field("addPlot"): + sumList.append(self.tr("Add a folder for plot notes")) + if self.field("addChar"): + sumList.append(self.tr("Add a folder for character notes")) + if self.field("addWorld"): + sumList.append(self.tr("Add a folder for location notes")) + if self.field("addNotes"): + sumList.append(self.tr("Add example notes to the above")) + if self.field("numChapters") > 0: + sumList.append(self.tr("Add {0} chapters to the novel folder").format( + self.field("numChapters") + )) + if self.field("numScenes") > 0: + sumList.append(self.tr("Add {0} scenes to each chapter").format( + self.field("numScenes") + )) + else: + if self.field("numScenes") > 0: + sumList.append(self.tr("Add {0} scenes").format( + self.field("numScenes") + )) + + self.theText.setText( + "

%s

 • %s

%s

" % ( + self.tr("You have selected the following:"), + "
 • ".join(sumList), + self.tr("Press '{0}' to create the new project.").format( + self.tr("Done") if self.mainConf.osDarwin else self.tr("Finish") + ) + ) + ) + return + # END Class ProjWizardFinalPage diff --git a/novelwriter/tools/writingstats.py b/novelwriter/tools/writingstats.py index e0a338bb..add052ec 100644 --- a/novelwriter/tools/writingstats.py +++ b/novelwriter/tools/writingstats.py @@ -57,43 +57,44 @@ class GuiWritingStats(QDialog): FMT_JSON = 0 FMT_CSV = 1 - def __init__(self, theParent): - QDialog.__init__(self, theParent) + def __init__(self, mainGui): + QDialog.__init__(self, mainGui) logger.debug("Initialising GuiWritingStats ...") self.setObjectName("GuiWritingStats") self.mainConf = novelwriter.CONFIG - self.theParent = theParent - self.theTheme = theParent.theTheme - self.theProject = theParent.theProject - self.optState = theParent.theProject.optState + self.mainGui = mainGui + self.mainTheme = mainGui.mainTheme + self.theProject = mainGui.theProject self.logData = [] self.filterData = [] self.timeFilter = 0.0 self.wordOffset = 0 + pOptions = self.theProject.options + self.setWindowTitle(self.tr("Writing Statistics")) self.setMinimumWidth(self.mainConf.pxInt(420)) self.setMinimumHeight(self.mainConf.pxInt(400)) self.resize( - self.mainConf.pxInt(self.optState.getInt("GuiWritingStats", "winWidth", 550)), - self.mainConf.pxInt(self.optState.getInt("GuiWritingStats", "winHeight", 500)) + self.mainConf.pxInt(pOptions.getInt("GuiWritingStats", "winWidth", 550)), + self.mainConf.pxInt(pOptions.getInt("GuiWritingStats", "winHeight", 500)) ) # List Box wCol0 = self.mainConf.pxInt( - self.optState.getInt("GuiWritingStats", "widthCol0", 180) + pOptions.getInt("GuiWritingStats", "widthCol0", 180) ) wCol1 = self.mainConf.pxInt( - self.optState.getInt("GuiWritingStats", "widthCol1", 80) + pOptions.getInt("GuiWritingStats", "widthCol1", 80) ) wCol2 = self.mainConf.pxInt( - self.optState.getInt("GuiWritingStats", "widthCol2", 80) + pOptions.getInt("GuiWritingStats", "widthCol2", 80) ) wCol3 = self.mainConf.pxInt( - self.optState.getInt("GuiWritingStats", "widthCol3", 80) + pOptions.getInt("GuiWritingStats", "widthCol3", 80) ) self.listBox = QTreeWidget() @@ -115,16 +116,16 @@ class GuiWritingStats(QDialog): hHeader.setTextAlignment(self.C_IDLE, Qt.AlignRight) hHeader.setTextAlignment(self.C_COUNT, Qt.AlignRight) - sortCol = checkIntRange(self.optState.getInt("GuiWritingStats", "sortCol", 0), 0, 2, 0) + sortCol = checkIntRange(pOptions.getInt("GuiWritingStats", "sortCol", 0), 0, 2, 0) sortOrder = checkIntTuple( - self.optState.getInt("GuiWritingStats", "sortOrder", Qt.DescendingOrder), + pOptions.getInt("GuiWritingStats", "sortOrder", Qt.DescendingOrder), (Qt.AscendingOrder, Qt.DescendingOrder), Qt.DescendingOrder ) self.listBox.sortByColumn(sortCol, sortOrder) self.listBox.setSortingEnabled(True) # Word Bar - self.barHeight = int(round(0.5*self.theTheme.fontPixelSize)) + self.barHeight = int(round(0.5*self.mainTheme.fontPixelSize)) self.barWidth = self.mainConf.pxInt(200) self.barImage = QPixmap(self.barHeight, self.barHeight) self.barImage.fill(self.palette().highlight().color()) @@ -135,27 +136,27 @@ class GuiWritingStats(QDialog): self.infoBox.setLayout(self.infoForm) self.labelTotal = QLabel(formatTime(0)) - self.labelTotal.setFont(self.theTheme.guiFontFixed) + self.labelTotal.setFont(self.mainTheme.guiFontFixed) self.labelTotal.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.labelIdleT = QLabel(formatTime(0)) - self.labelIdleT.setFont(self.theTheme.guiFontFixed) + self.labelIdleT.setFont(self.mainTheme.guiFontFixed) self.labelIdleT.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.labelFilter = QLabel(formatTime(0)) - self.labelFilter.setFont(self.theTheme.guiFontFixed) + self.labelFilter.setFont(self.mainTheme.guiFontFixed) self.labelFilter.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.novelWords = QLabel("0") - self.novelWords.setFont(self.theTheme.guiFontFixed) + self.novelWords.setFont(self.mainTheme.guiFontFixed) self.novelWords.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.notesWords = QLabel("0") - self.notesWords.setFont(self.theTheme.guiFontFixed) + self.notesWords.setFont(self.mainTheme.guiFontFixed) self.notesWords.setAlignment(Qt.AlignVCenter | Qt.AlignRight) self.totalWords = QLabel("0") - self.totalWords.setFont(self.theTheme.guiFontFixed) + self.totalWords.setFont(self.mainTheme.guiFontFixed) self.totalWords.setAlignment(Qt.AlignVCenter | Qt.AlignRight) lblTTime = QLabel(self.tr("Total Time:")) @@ -182,7 +183,7 @@ class GuiWritingStats(QDialog): self.infoForm.setRowStretch(6, 1) # Filter Options - sPx = self.theTheme.baseIconSize + sPx = self.mainTheme.baseIconSize self.filterBox = QGroupBox(self.tr("Filters"), self) self.filterForm = QGridLayout(self) @@ -190,37 +191,37 @@ class GuiWritingStats(QDialog): self.incNovel = QSwitch(width=2*sPx, height=sPx) self.incNovel.setChecked( - self.optState.getBool("GuiWritingStats", "incNovel", True) + pOptions.getBool("GuiWritingStats", "incNovel", True) ) self.incNovel.clicked.connect(self._updateListBox) self.incNotes = QSwitch(width=2*sPx, height=sPx) self.incNotes.setChecked( - self.optState.getBool("GuiWritingStats", "incNotes", True) + pOptions.getBool("GuiWritingStats", "incNotes", True) ) self.incNotes.clicked.connect(self._updateListBox) self.hideZeros = QSwitch(width=2*sPx, height=sPx) self.hideZeros.setChecked( - self.optState.getBool("GuiWritingStats", "hideZeros", True) + pOptions.getBool("GuiWritingStats", "hideZeros", True) ) self.hideZeros.clicked.connect(self._updateListBox) self.hideNegative = QSwitch(width=2*sPx, height=sPx) self.hideNegative.setChecked( - self.optState.getBool("GuiWritingStats", "hideNegative", False) + pOptions.getBool("GuiWritingStats", "hideNegative", False) ) self.hideNegative.clicked.connect(self._updateListBox) self.groupByDay = QSwitch(width=2*sPx, height=sPx) self.groupByDay.setChecked( - self.optState.getBool("GuiWritingStats", "groupByDay", False) + pOptions.getBool("GuiWritingStats", "groupByDay", False) ) self.groupByDay.clicked.connect(self._updateListBox) self.showIdleTime = QSwitch(width=2*sPx, height=sPx) self.showIdleTime.setChecked( - self.optState.getBool("GuiWritingStats", "showIdleTime", False) + pOptions.getBool("GuiWritingStats", "showIdleTime", False) ) self.showIdleTime.clicked.connect(self._updateListBox) @@ -244,7 +245,7 @@ class GuiWritingStats(QDialog): self.histMax.setMaximum(100000) self.histMax.setSingleStep(100) self.histMax.setValue( - self.optState.getInt("GuiWritingStats", "histMax", 2000) + pOptions.getInt("GuiWritingStats", "histMax", 2000) ) self.histMax.valueChanged.connect(self._updateListBox) @@ -323,23 +324,23 @@ class GuiWritingStats(QDialog): showIdleTime = self.showIdleTime.isChecked() histMax = self.histMax.value() - self.optState.setValue("GuiWritingStats", "winWidth", winWidth) - self.optState.setValue("GuiWritingStats", "winHeight", winHeight) - self.optState.setValue("GuiWritingStats", "widthCol0", widthCol0) - self.optState.setValue("GuiWritingStats", "widthCol1", widthCol1) - self.optState.setValue("GuiWritingStats", "widthCol2", widthCol2) - self.optState.setValue("GuiWritingStats", "widthCol3", widthCol3) - self.optState.setValue("GuiWritingStats", "sortCol", sortCol) - self.optState.setValue("GuiWritingStats", "sortOrder", sortOrder) - self.optState.setValue("GuiWritingStats", "incNovel", incNovel) - self.optState.setValue("GuiWritingStats", "incNotes", incNotes) - self.optState.setValue("GuiWritingStats", "hideZeros", hideZeros) - self.optState.setValue("GuiWritingStats", "hideNegative", hideNegative) - self.optState.setValue("GuiWritingStats", "groupByDay", groupByDay) - self.optState.setValue("GuiWritingStats", "showIdleTime", showIdleTime) - self.optState.setValue("GuiWritingStats", "histMax", histMax) - - self.optState.saveSettings() + pOptions = self.theProject.options + pOptions.setValue("GuiWritingStats", "winWidth", winWidth) + pOptions.setValue("GuiWritingStats", "winHeight", winHeight) + pOptions.setValue("GuiWritingStats", "widthCol0", widthCol0) + pOptions.setValue("GuiWritingStats", "widthCol1", widthCol1) + pOptions.setValue("GuiWritingStats", "widthCol2", widthCol2) + pOptions.setValue("GuiWritingStats", "widthCol3", widthCol3) + pOptions.setValue("GuiWritingStats", "sortCol", sortCol) + pOptions.setValue("GuiWritingStats", "sortOrder", sortOrder) + pOptions.setValue("GuiWritingStats", "incNovel", incNovel) + pOptions.setValue("GuiWritingStats", "incNotes", incNotes) + pOptions.setValue("GuiWritingStats", "hideZeros", hideZeros) + pOptions.setValue("GuiWritingStats", "hideNegative", hideNegative) + pOptions.setValue("GuiWritingStats", "groupByDay", groupByDay) + pOptions.setValue("GuiWritingStats", "showIdleTime", showIdleTime) + pOptions.setValue("GuiWritingStats", "histMax", histMax) + pOptions.saveSettings() self.close() return @@ -410,11 +411,11 @@ class GuiWritingStats(QDialog): # Report to user if wSuccess: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("{0} file successfully written to:").format(textFmt), savePath ], nwAlert.INFO) else: - self.theParent.makeAlert([ + self.mainGui.makeAlert([ self.tr("Failed to write {0} file.").format(textFmt), errMsg ], nwAlert.ERROR) @@ -457,12 +458,8 @@ class GuiWritingStats(QDialog): if len(inData) < 6: continue - dStart = datetime.strptime( - "%s %s" % (inData[0], inData[1]), nwConst.FMT_TSTAMP - ) - dEnd = datetime.strptime( - "%s %s" % (inData[2], inData[3]), nwConst.FMT_TSTAMP - ) + dStart = datetime.fromisoformat(" ".join(inData[0:2])) + dEnd = datetime.fromisoformat(" ".join(inData[2:4])) sIdle = 0 if len(inData) > 6: @@ -481,7 +478,7 @@ class GuiWritingStats(QDialog): self.logData.append((dStart, sDiff, wcNovel, wcNotes, sIdle)) except Exception as exc: - self.theParent.makeAlert(self.tr( + self.mainGui.makeAlert(self.tr( "Failed to read session log file." ), nwAlert.ERROR, exception=exc) return False @@ -608,13 +605,13 @@ class GuiWritingStats(QDialog): newItem.setTextAlignment(self.C_COUNT, Qt.AlignRight) newItem.setTextAlignment(self.C_BAR, Qt.AlignLeft | Qt.AlignVCenter) - newItem.setFont(self.C_TIME, self.theTheme.guiFontFixed) - newItem.setFont(self.C_LENGTH, self.theTheme.guiFontFixed) - newItem.setFont(self.C_COUNT, self.theTheme.guiFontFixed) + newItem.setFont(self.C_TIME, self.mainTheme.guiFontFixed) + newItem.setFont(self.C_LENGTH, self.mainTheme.guiFontFixed) + newItem.setFont(self.C_COUNT, self.mainTheme.guiFontFixed) if showIdleTime: - newItem.setFont(self.C_IDLE, self.theTheme.guiFontFixed) + newItem.setFont(self.C_IDLE, self.mainTheme.guiFontFixed) else: - newItem.setFont(self.C_IDLE, self.theTheme.guiFont) + newItem.setFont(self.C_IDLE, self.mainTheme.guiFont) self.listBox.addTopLevelItem(newItem) self.timeFilter += sDiff diff --git a/sample/content/5eaea4e8cdee8.nwd b/sample/content/5eaea4e8cdee8.nwd index 1a7f3c79..0f8ecc26 100644 --- a/sample/content/5eaea4e8cdee8.nwd +++ b/sample/content/5eaea4e8cdee8.nwd @@ -4,5 +4,6 @@ # Mars @tag: Mars +@location: Space It’s red. Dusty and red. diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index 8fe96042..a334e8ce 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -1,19 +1,19 @@ %%~name: Making a Scene -%%~path: e7ded148d6e4a/636b6aa9b697b +%%~path: 6a2d6d5f4f401/636b6aa9b697b %%~kind: NOVEL/DOCUMENT ### Making a Scene @pov: Jane -@char: John +@char: John, Jane @location: Earth -A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree. +A scene is defined by a level three heading, like the one at the top of this page. The scene will be assigned to the chapter preceding it in the project tree. The scene document can be sorted after the chapter document, or as a child of the chapter. Both result in the same output in the end, so it is a matter of preference. Each paragraph in the scene is separated by a blank line. The text supports minimal formatting, like **bold**, _italic_ and **_bold italic_**. You can also ~~strike through~~ text. There is **some support for _nested_ emphasis**, but there are some known limitations. If the syntax highlighter doesn’t show it correctly, the export tool will not either. -In addition, the editor supports automatic formatting of “quotes”, both double and ‘single’. Depending on the syntax highlighter, these can be in different colours. “You can of course use **bold** and _italic_ text inside of quotes too.” +In addition, the editor supports automatic formatting of “quotes”, both double and ‘single’. Depending on the syntax highlighter settings and colour theme, these can be in different colours. “You can of course use **bold** and _italic_ text inside of quotes too.” -If you have the need for it, you can also add text that can be automatically replaced by other text when you generate a preview or export the project. Now, let’s auto-replace this A with , and this C with . While is just . Press Ctrl+R to see what this looks like in the view pane. +If you have the need for it, you can also add text that can be automatically replaced by other text when you generate a preview or export the project. Now, let’s auto-replace this A with , and this C with . While is just . Press Ctrl+R to see what this looks like in the view pane. The list of auto-replaced text is sett in Project Settings. The editor also supports non breaking spaces, and the spell checker accepts long dashes—like this—as valid word separators. Regular dashes are also supported – and can be automatically inserted when typing two hyphens. @@ -25,7 +25,7 @@ If you need to split a scene file up into further pieces, you can do so with the Both scene and section titles can be left out of the final exported document. The formatting of titles can be selected from the Build Novel Project dialog. You can also have them replaced with scene separators like “* * *”. -#### Text Alignment +#### Text Alignment and Indentation The text by default will have the left or justified alignment in the main text files in your project. You can also specify alignment for a specific paragraph by “pushing” it away from an edge with a set of ‘>>’ or ‘<<’ symbols, like so: @@ -35,8 +35,6 @@ This text is left-aligned. << >> This text is centred. << -#### Text Indent - You can indent a paragraph from both the left and right margin with ‘>’ and ‘<’ symbols. > This paragraph is indented from both the left margin and the right margin. This is useful for when you want to quote a large chunk of text for instance. < diff --git a/sample/content/6a2d6d5f4f401.nwd b/sample/content/6a2d6d5f4f401.nwd index 60d8d2a0..2a536e9f 100644 --- a/sample/content/6a2d6d5f4f401.nwd +++ b/sample/content/6a2d6d5f4f401.nwd @@ -1,11 +1,11 @@ %%~name: Chapter One -%%~path: e7ded148d6e4a/6a2d6d5f4f401 +%%~path: 7031beac91f75/6a2d6d5f4f401 %%~kind: NOVEL/DOCUMENT ## So it Begins @pov: Jane @location: Earth -% Synopsis: We can add a chapter file, but keep the scene files separate. In the chapter file we can set the meta data that applies to the whole chapter if we wish to. +% Synopsis: We can add a chapter document, but keep the scene files separate. In the chapter document we can set the meta data that applies to the whole chapter if we wish to. You can add the scenes as child documents directly under the chapter. -A chapter can also contain leading text before the first scene. +A chapter can contain leading text before the first scene, like this piece of text. diff --git a/sample/content/88706ddc78b1b.nwd b/sample/content/88706ddc78b1b.nwd index ce4d2123..ceaddd29 100644 --- a/sample/content/88706ddc78b1b.nwd +++ b/sample/content/88706ddc78b1b.nwd @@ -1,5 +1,5 @@ %%~name: Chapter Two -%%~path: e7ded148d6e4a/88706ddc78b1b +%%~path: 7031beac91f75/88706ddc78b1b %%~kind: NOVEL/DOCUMENT ## Where has John Gone? @@ -11,6 +11,7 @@ ### Jane Cannot Find John @pov: Jane +@focus: John @location: Space Jane has been looking all over for John. He’s nowhere to be found on Earth, so Jane goes to space. diff --git a/sample/content/8a5deb88c0e97.nwd b/sample/content/8a5deb88c0e97.nwd index c5b61a9f..31a99aeb 100644 --- a/sample/content/8a5deb88c0e97.nwd +++ b/sample/content/8a5deb88c0e97.nwd @@ -1,6 +1,6 @@ %%~name: Old File %%~path: ae9bf3c3ea159/8a5deb88c0e97 -%%~kind: NOVEL/DOCUMENT +%%~kind: ARCHIVE/DOCUMENT ### Discarded Scene -If you have files you no longer want in your main project, you can move them to the “Archive” folder. This is equivalent to turning off the “Include when building project” switch, just that you also put the file away, although the switch can be ignored when building the project, this folder cannot. +If you have files you no longer want in your main project, you can move them to the “Archive” folder. This is equivalent to turning off the “Include when building project” switch, just that you also put the file away. diff --git a/sample/content/96b68994dfa3d.nwd b/sample/content/96b68994dfa3d.nwd index 849cd41d..05ae7770 100644 --- a/sample/content/96b68994dfa3d.nwd +++ b/sample/content/96b68994dfa3d.nwd @@ -1,11 +1,11 @@ %%~name: A Note on Structure -%%~path: e7ded148d6e4a/96b68994dfa3d +%%~path: 7031beac91f75/96b68994dfa3d %%~kind: NOVEL/NOTE # A Note on Structure This file is just a note. You can save notes anywhere you like in the project tree. Notes can be filtered out when you export the project. -In root folders that isn’t the Novel root folder, you can _only_ add notes. In the Novel root folder, you can choose between a number of layouts. Some of them are just to let yourself know what each file is for. +In root folders that aren’t the Novel or Archive root folders, you can _only_ add notes. In the Novel and Archive folder you can also add Project Documents, which are the documents that make up your actual story. ## Headers in Notes @@ -15,8 +15,10 @@ Unlike in novel files, headers in notes have no particular meaning other than vi The folders in the tree view have no structural meaning other than they’re a way for you to organise your files into groups in whatever way suits you. They are not intended to represent chapters, but you can of course use them for that. If you do, know that you still need to define chapter headers in your structure so novelWriter knows where you want them. +If you do have separate chapter documents, you can always add scene documents as child document of the chapter instead of using folders. + ## Linking Files and Notes -You can link files and notes together by assigning tags to them, and then reference them from other files. The file class of a file determines which reference keywords apply to each file. For instance a file in the Characters root folder can be referenced using either the @char keyword or the @pov keyword. +You can link project documents and notes together by assigning tags to the notes with the @tag keyword, and then reference them from other files using one of the many reference keywords. The file class of a file determines which reference keywords apply to each file. For instance a file in the Characters root folder can be referenced using either the @char keyword or the @pov keyword. If you want to see the content of the file the reference points to, you can click Ctrl+Enter with the cursor on top of the reference, and the view pane will show you the file. In the view pane, all references are clickable, so you can navigate further. At the bottom of the view pane, a list of files referencing the one your viewing will appear. This panel updates when you navigate, unless you make it sticky by clicking the sticky checkbox. \ No newline at end of file diff --git a/sample/content/974e400180a99.nwd b/sample/content/974e400180a99.nwd index ff9b71d5..99919687 100644 --- a/sample/content/974e400180a99.nwd +++ b/sample/content/974e400180a99.nwd @@ -6,4 +6,4 @@ This is a plain page with some text on it. -If you want the text to start on a fresh page, add the [NEW PAGE] code above the text. You can also add empty paragraphs with the [VSPACE] code. +If you want the text to start on a fresh page, add the [NEW PAGE] code above the text. You can also add empty paragraphs with the [VSPACE] code. The above code adds two empty paragraphs before the text starts. diff --git a/sample/content/a520879ca0b45.nwd b/sample/content/a520879ca0b45.nwd new file mode 100644 index 00000000..75ba39c8 --- /dev/null +++ b/sample/content/a520879ca0b45.nwd @@ -0,0 +1,17 @@ +%%~name: Chapter One +%%~path: e5e47ebf63b1c/a520879ca0b45 +%%~kind: NOVEL/DOCUMENT +## Chapter One + +@pov: Jane + +% Synopsis: Remember Jane and John? + +### Scene One + +@pov: Jane +@focus: John + +A project can have multiple novel root folders for multiple novels. This is the first scene of a sequel to the first novel. + +In this way, the writer can keep the same notes for multiple novels. This can be especially useful if the writer is planning a multi-novel story in advance. diff --git a/sample/content/ae7339df26ded.nwd b/sample/content/ae7339df26ded.nwd index 9b135713..8b53f816 100644 --- a/sample/content/ae7339df26ded.nwd +++ b/sample/content/ae7339df26ded.nwd @@ -1,9 +1,10 @@ %%~name: We Found John! -%%~path: e7ded148d6e4a/ae7339df26ded +%%~path: 88706ddc78b1b/ae7339df26ded %%~kind: NOVEL/DOCUMENT ### We Found John! @pov: John +@focus: John @location: Mars Jane has been searching for a while, and she finally found John on Mars. He was indeed in space! What was he doing on Mars anyway? Well, it turns out, he was farming potatoes. diff --git a/sample/content/b3e74dbc1f584.nwd b/sample/content/b3e74dbc1f584.nwd index 6931a299..bb88600b 100644 --- a/sample/content/b3e74dbc1f584.nwd +++ b/sample/content/b3e74dbc1f584.nwd @@ -4,5 +4,6 @@ # Earth @tag: Earth +@location: Space -Third planet from the sun, fairly dense, and with lots of people on it. \ No newline at end of file +Third planet from the sun, fairly dense, and with lots of people on it. diff --git a/sample/content/b8136a5a774a0.nwd b/sample/content/b8136a5a774a0.nwd index 3c2c1854..636c7227 100644 --- a/sample/content/b8136a5a774a0.nwd +++ b/sample/content/b8136a5a774a0.nwd @@ -1,6 +1,6 @@ %%~name: Delete Me! %%~path: 98acd8c76c93a/b8136a5a774a0 -%%~kind: NOVEL/DOCUMENT +%%~kind: TRASH/DOCUMENT ### Delete Me! This scene is trash. \ No newline at end of file diff --git a/sample/content/ba8a28a246524.nwd b/sample/content/ba8a28a246524.nwd index cd684e19..c2acfb26 100644 --- a/sample/content/ba8a28a246524.nwd +++ b/sample/content/ba8a28a246524.nwd @@ -1,9 +1,9 @@ %%~name: Interlude -%%~path: e7ded148d6e4a/ba8a28a246524 +%%~path: 7031beac91f75/ba8a28a246524 %%~kind: NOVEL/DOCUMENT ##! Interlude -% Notice that this is a file with the flag ‘N.Un’. The ‘N’ means it’s a novel file, and the ‘Un’ means it’s an unnumbered chapter. Unnumbered chapters can be treated separately from numbered chapters during export. Perfect for when you want to add an interlude, or for a prologue or epilogue. +% Notice that this document has a title with a ‘!’ in it in addition to the two hash symbols. This means it is an unnumbered chapter. Unnumbered chapters can be treated separately from numbered chapters during export. Perfect for when you want to add an interlude, or for a prologue or epilogue. I am the very model of a modern Major-General I've information vegetable, animal, and mineral diff --git a/sample/content/bacb7059e3083.nwd b/sample/content/bacb7059e3083.nwd new file mode 100644 index 00000000..b6be7a07 --- /dev/null +++ b/sample/content/bacb7059e3083.nwd @@ -0,0 +1,8 @@ +%%~name: Title Page +%%~path: e5e47ebf63b1c/bacb7059e3083 +%%~kind: NOVEL/DOCUMENT +#! Sequel Novel + +>> **By Jane Doh** << + +% Synopsis: Jane and John are back in a sequel to My Novel! diff --git a/sample/content/bc0cbd2a407f3.nwd b/sample/content/bc0cbd2a407f3.nwd index 3c95e8ff..fd920d0d 100644 --- a/sample/content/bc0cbd2a407f3.nwd +++ b/sample/content/bc0cbd2a407f3.nwd @@ -1,5 +1,5 @@ %%~name: Another Scene -%%~path: e7ded148d6e4a/bc0cbd2a407f3 +%%~path: 6a2d6d5f4f401/bc0cbd2a407f3 %%~kind: NOVEL/DOCUMENT ### Another Scene @@ -7,9 +7,9 @@ @focus: Jane @location: Earth -Adding more scenes to a chapter is as easy as adding more scene files, with a level three heading, or just adding another level three heading in the same file if that works for the way you want to structure your files. +Adding more scenes to a chapter is as easy as adding more scene files with a level three heading. You can of course also just add another level three heading in the same file if that works for the way you want to structure your files. -In fact, if you wish, you can add all the scenes in the chapter file too. All novelWriter cares about is the level of the headings. +In fact, if you wish, you can add all the scenes in the chapter file too. All novelWriter cares about is the level of the headings and the order in which they appear. ### More Scenes @@ -17,4 +17,4 @@ In fact, if you wish, you can add all the scenes in the chapter file too. All no @focus: John @location: Earth -This is a second scene in the same file as the previous scene. You can always split the files up later. +This is a second scene in the same file as the previous scene. You can always split the files up later using the split tool. diff --git a/sample/content/edca4be2fcaf8.nwd b/sample/content/edca4be2fcaf8.nwd index 3028b3fd..8b3efc78 100644 --- a/sample/content/edca4be2fcaf8.nwd +++ b/sample/content/edca4be2fcaf8.nwd @@ -3,4 +3,4 @@ %%~kind: NOVEL/DOCUMENT # Part One ->> In the beginning … << \ No newline at end of file +>> In the beginning … << diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 436f8362..b5bf2647 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,25 +1,26 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1305 - 199 - 65071 + 1378 + 236 + 69273 False en_GB True None - True 636b6aa9b697b 636b6aa9b697b - 1206 - 830 - 376 + 7031beac91f75 + 7031beac91f75 + 1363 + 954 + 409 B E @@ -33,281 +34,129 @@
- New - Notes - Started - 1st Draft - 2nd Draft - 3rd Draft - Finished + New + Notes + Started + 1st Draft + 2nd Draft + 3rd Draft + Finished - None - Minor - Major - Main + None + Minor + Major + Main
- - - Novel - ROOT - NOVEL - Started - True + + + + Novel - - Title Page - FILE - NOVEL - Started - True - DOCUMENT - 93 - 19 - 2 - 2 + + + Title Page - - Page - FILE - NOVEL - New - True - DOCUMENT - 186 - 39 - 2 - 212 + + + Page - - Part One - FILE - NOVEL - New - True - DOCUMENT - 26 - 6 - 1 - 33 + + + Part One - - A Folder - FOLDER - NOVEL - 1st Draft - True + + + Chapter One - - Chapter One - FILE - NOVEL - Notes - True - DOCUMENT - 75 - 14 - 1 - 279 + + + Making a Scene - - Making a Scene - FILE - NOVEL - 1st Draft - True - DOCUMENT - 2429 - 432 - 14 - 219 + + + Another Scene - - Another Scene - FILE - NOVEL - 1st Draft - True - DOCUMENT - 476 - 93 - 3 - 577 + + + Interlude - - Interlude - FILE - NOVEL - New - True - DOCUMENT - 617 - 101 - 3 - 4 + + + A Note on Structure - - A Note on Structure - FILE - NOVEL - 2nd Draft - False - NOTE - 1692 - 313 - 6 - 1110 + + + Chapter Two - - Chapter Two - FILE - NOVEL - 1st Draft - True - DOCUMENT - 139 - 28 - 1 - 343 + + + We Found John! - - We Found John! - FILE - NOVEL - 1st Draft - True - DOCUMENT - 189 - 37 - 1 - 224 + + + Sequel - - Characters - ROOT - CHARACTER - None - True + + + Title Page - - Main Characters - FOLDER - CHARACTER - None - True + + + Chapter One - - John Smith - FILE - CHARACTER - Minor - True - NOTE - 49 - 9 - 1 - 24 + + + Characters - - Jane Smith - FILE - CHARACTER - Major - True - NOTE - 55 - 9 - 1 - 25 + + + Main Characters - - Locations - ROOT - WORLD - None - True + + + John Smith - - Earth - FILE - WORLD - Main - True - NOTE - 76 - 15 - 1 - 20 + + + Jane Smith - - Space - FILE - WORLD - Minor - True - NOTE - 115 - 24 - 1 - 133 + + + Locations - - Mars - FILE - WORLD - Major - True - NOTE - 28 - 6 - 1 - 45 + + + Earth - - Archive - ROOT - ARCHIVE - New - True + + + Space - - Scenes - FOLDER - ARCHIVE - New - True + + + Mars - - Old File - FILE - NOVEL - 1st Draft - True - DOCUMENT - 315 - 55 - 1 - 322 + + + Archive - - Trash - TRASH - TRASH - None - True + + + Scenes - - Delete Me! - FILE - NOVEL - New - True - DOCUMENT - 30 - 6 - 1 - 36 + + + Old File + + + + Trash + + + + Delete Me!
diff --git a/setup.cfg b/setup.cfg index d3bbcf41..b88b656b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,7 +11,6 @@ license_file = LICENSE.md license = GNU General Public License v3 classifiers = Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 @@ -29,7 +28,7 @@ project_urls = Source Code = https://github.com/vkbo/novelWriter [options] -python_requires = >=3.6 +python_requires = >=3.7 include_package_data = True packages = find: install_requires = @@ -50,6 +49,6 @@ gui_scripts = universal = 0 [flake8] -ignore = E221,E226,E228,E241 +ignore = E133,E221,E226,E228,E241,W503 max-line-length = 99 exclude = docs/* diff --git a/setup.py b/setup.py index 98c19ea7..a0bb9b03 100755 --- a/setup.py +++ b/setup.py @@ -197,6 +197,7 @@ def cleanBuildDirs(): removeFolder("dist") removeFolder("dist_deb") removeFolder("dist_minimal") + removeFolder("dist_appimage") removeFolder("novelWriter.egg-info") print("") @@ -848,7 +849,6 @@ def makeForLaunchpad(doSign=False, isFirst=False, isSnapshot=False): bldNum = "0" distLoop = [ - ("18.04", "bionic"), ("20.04", "focal"), ("22.04", "jammy"), ("22.10", "kinetic"), @@ -898,10 +898,231 @@ def makeForLaunchpad(doSign=False, isFirst=False, isSnapshot=False): return +## +# Make AppImage (build-appimage) +## + +def makeAppImage(sysArgs): + """Build an Appimage + """ + + import glob + import argparse + import platform + + try: + import python_appimage # noqa F401 + except ImportError: + print( + "ERROR: Package 'python-appimage' is missing on this system.\n" + " Please run 'pip install --user python-appimage' to install it.\n" + ) + sys.exit(1) + + print("") + print("Build AppImage") + print("==============") + print("") + + parser = argparse.ArgumentParser( + prog="build_appimage", + description="Build an AppImage", + epilog="see https://appimage.org/ for more details", + ) + parser.add_argument( + "--linux-tag", + nargs="?", + default=f"manylinux2010_{platform.machine()}", + help=( + "linux compatibility tag (e.g. manylinux1_x86_64) \n" + "see https://python-appimage.readthedocs.io/en/latest/#available-python-appimages \n" + "and https://github.com/pypa/manylinux for a list of valid tags" + ), + ) + parser.add_argument( + "--python-version", nargs="?", default="3.10", help="python version (e.g. 3.10)" + ) + + args, unparsedArgs = parser.parse_known_args(sysArgs) + + linuxTag = args.linux_tag + pythonVer = args.python_version + + # Version Info + # ============ + + numVers, _, relDate = extractVersion() + pkgVers = compactVersion(numVers) + relDate = datetime.datetime.strptime(relDate, "%Y-%m-%d") + print("") + + # Set Up Folder + # ============= + + bldDir = "dist_appimage" + bldPkg = f"novelwriter_{pkgVers}" + outDir = f"{bldDir}/{bldPkg}" + imageDir = f"{bldDir}/appimage" + + # Set Up Folders + # ============== + + if not os.path.isdir(bldDir): + os.mkdir(bldDir) + + if os.path.isdir(outDir): + print("Removing old build files ...") + print("") + shutil.rmtree(outDir) + + os.mkdir(outDir) + + if os.path.isdir(imageDir): + print("Removing old build metadata files ...") + print("") + shutil.rmtree(imageDir) + + os.mkdir(imageDir) + + # Remove old Appimages + outFiles = glob.glob(f"{bldDir}/*.AppImage") + + if outFiles: + print("Removing old AppImages") + print("") + for image in outFiles: + try: + os.remove(image) + except OSError: + print("Error while deleting file : ", image) + + # Build Additional Assets + # ======================= + + buildQtI18n() + buildSampleZip() + buildPdfManual() + + # Copy novelWriter Source + # ======================= + + print("Copying novelWriter source ...") + print("") + + for nPath, _, nFiles in os.walk("novelwriter"): + if nPath.endswith("__pycache__"): + print("Skipped: %s" % nPath) + continue + + pPath = f"{outDir}/{nPath}" + if not os.path.isdir(pPath): + os.mkdir(pPath) + + fCount = 0 + for fFile in nFiles: + nFile = f"{nPath}/{fFile}" + pFile = f"{pPath}/{fFile}" + + if fFile.endswith(".pyc"): + print("Skipped: %s" % nFile) + continue + + shutil.copyfile(nFile, pFile) + fCount += 1 + + print("Copied: %s/* [Files: %d]" % (nPath, fCount)) + + print("") + print("Copying or generating additional files ...") + print("") + + # Copy/Write Root Files + # ===================== + + copyFiles = ["LICENSE.md", "CREDITS.md", "CHANGELOG.md", "pyproject.toml"] + for copyFile in copyFiles: + shutil.copyfile(copyFile, f"{outDir}/{copyFile}") + print("Copied: %s" % copyFile) + + writeFile(f"{outDir}/MANIFEST.in", ( + "include LICENSE.md\n" + "include CREDITS.md\n" + "include CHANGELOG.md\n" + "include data/*\n" + "recursive-include novelwriter/assets *\n" + )) + print("Wrote: MANIFEST.in") + + writeFile(f"{outDir}/setup.py", ( + "import setuptools\n" + "setuptools.setup()\n" + )) + print("Wrote: setup.py") + + setupCfg = readFile("setup.cfg").replace( + "file: setup/description_pypi.md", "file: data/description_short.txt" + ) + writeFile(f"{outDir}/setup.cfg", setupCfg) + print("Wrote: setup.cfg") + + # Write Metadata + # ============== + + appDescription = readFile("setup/description_short.txt") + appdataXML = readFile("setup/novelwriter.appdata.xml").format(description=appDescription) + writeFile(f"{imageDir}/novelwriter.appdata.xml", appdataXML) + print("Wrote: novelwriter.appdata.xml") + + writeFile(f"{imageDir}/entrypoint.sh", ( + '#! /bin/bash \n' + '{{ python-executable }} -sE ${APPDIR}/opt/python{{ python-version }}/bin/novelwriter "$@"' + )) + print("Wrote: entrypoint.sh") + + writeFile(f"{imageDir}/requirements.txt", os.path.abspath(outDir)) + print("Wrote: requirements.txt") + + shutil.copyfile("setup/data/novelwriter.desktop", f"{imageDir}/novelwriter.desktop") + print("Copied: setup/data/novelwriter.desktop") + + shutil.copyfile("setup/icons/novelwriter.svg", f"{imageDir}/novelwriter.svg") + print("Copied: setup/icons/novelwriter.svg") + + shutil.copyfile("setup/data/hicolor/256x256/apps/novelwriter.png", + f"{imageDir}/novelwriter.png") + print("Copied: setup/data/hicolor/256x256/apps/novelwriter.png") + + # Build Appimage + # ============== + + try: + subprocess.call([ + sys.executable, "-m", "python_appimage", "build", "app", + "-l", linuxTag, "-p", pythonVer, "appimage" + ], cwd=bldDir) + except Exception as exc: + print("AppImage build: FAILED") + print("") + print(str(exc)) + print("") + print("Dependencies:") + print(" * pip install python-appimage") + print("") + sys.exit(1) + + outFile = glob.glob(f"{bldDir}/*.AppImage")[0] + shaFile = makeCheckSum(os.path.basename(outFile), cwd=bldDir) + + toUpload(outFile) + toUpload(shaFile) + + return unparsedArgs + ## # Make Windows Setup EXE (build-win-exe) ## + def makeWindowsEmbedded(sysArgs): """Set up a package with embedded Python and dependencies for Windows installation. @@ -1652,6 +1873,8 @@ if __name__ == "__main__": " Add --snapshot to make a snapshot package.", " build-win-exe Build a setup.exe file with Python embedded for Windows.", " The package must be built from a minimal windows zip file.", + " build-appimage Build an AppImage. Argument --linux-tag defaults to", + " manylinux1_x86_64 / i386, and --python-version to 3.10.", "", "System Install:", "", @@ -1754,6 +1977,14 @@ if __name__ == "__main__": makeWindowsEmbedded(sys.argv) sys.exit(0) # Don't continue execution + if "build-appimage" in sys.argv: + sys.argv.remove("build-appimage") + if hostOS == OS_LINUX: + sys.argv = makeAppImage(sys.argv) # Build appimage and prune its args + else: + print("ERROR: Command 'build-appimage' can only be used on Linux") + sys.exit(1) + # General Installers # ================== diff --git a/setup/data/novelwriter.desktop b/setup/data/novelwriter.desktop index 2666fa13..8b140ffc 100644 --- a/setup/data/novelwriter.desktop +++ b/setup/data/novelwriter.desktop @@ -1,10 +1,9 @@ [Desktop Entry] Type=Application -Encoding=UTF-8 Name=novelWriter Comment=A markdown-like text editor for planning and writing novels Exec=novelwriter %f Icon=novelwriter Categories=Qt;Office;WordProcessor; Terminal=false -MimeType=application/x-novelwriter-project +MimeType=application/x-novelwriter-project; diff --git a/setup/data/x-novelwriter-project.xml b/setup/data/x-novelwriter-project.xml index 789c08fd..db045446 100644 --- a/setup/data/x-novelwriter-project.xml +++ b/setup/data/x-novelwriter-project.xml @@ -4,5 +4,6 @@ novelWriter Project + diff --git a/setup/debian/control b/setup/debian/control index d32c56ba..e2d40f90 100644 --- a/setup/debian/control +++ b/setup/debian/control @@ -2,14 +2,14 @@ Source: novelwriter Maintainer: Veronica Berglyd Olsen Section: text Priority: optional -Build-Depends: dh-python, python3-setuptools, python3-all, debhelper (>= 9), python3 (>=3.6), python3-pyqt5 (>= 5.3), python3-lxml (>= 4.0), python3-enchant (>= 2.0) +Build-Depends: dh-python, python3-setuptools, python3-all, debhelper (>= 9), python3 (>=3.7), python3-pyqt5 (>= 5.3), python3-lxml (>= 4.0), python3-enchant (>= 2.0) Standards-Version: 4.5.1 Homepage: https://novelwriter.io -X-Python3-Version: >= 3.6 +X-Python3-Version: >= 3.7 Package: novelwriter Architecture: all -Depends: ${misc:Depends}, ${python3:Depends}, python3 (>=3.6), python3-pyqt5 (>= 5.3), python3-lxml (>= 4.0), python3-enchant (>= 2.0) +Depends: ${misc:Depends}, ${python3:Depends}, python3 (>=3.7), python3-pyqt5 (>= 5.3), python3-lxml (>= 4.0), python3-enchant (>= 2.0) Description: A markdown-like text editor for planning and writing novels novelWriter is a plain text editor designed for writing novels assembled from many smaller text documents. It uses a minimal formatting syntax inspired by diff --git a/setup/description_pypi.md b/setup/description_pypi.md index 8c15b1be..ed98ffda 100644 --- a/setup/description_pypi.md +++ b/setup/description_pypi.md @@ -10,9 +10,9 @@ synchronisation tools. All text is saved as plain text files with a meta data he project structure is stored in a single project XML file, and other meta data is primarily saved as JSON files. -The application is written in Python 3 (3.6+) using Qt5 and PyQt5 (5.3+). It is developed on Linux, -but should in principle work fine on other operating systems as well as long as dependencies are -met. It is regularly tested on Debian and Ubuntu Linux, Windows, and macOS. +The application is written with Python 3 (3.7+) using Qt5 and PyQt5 (5.3+). It is developed on +Linux, but should in principle work fine on other operating systems as well as long as dependencies +are met. It is regularly tested on Debian and Ubuntu Linux, Windows, and macOS. novelWriter is developed and maintained by [Veronica Berglyd Olsen](https://github.com/vkbo). diff --git a/setup/make_snapshot.sh b/setup/make_snapshot.sh new file mode 100755 index 00000000..371996a0 --- /dev/null +++ b/setup/make_snapshot.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +if [ ! -f setup.py ]; then + echo "Must be called from the root folder of the source" + exit 1 +fi + +echo "" +echo " Building Dependencies" +echo "================================================================================" +echo "" +python3 setup.py clean-assets +python3 setup.py qtlrelease manual sample + +echo "" +echo " Building Linux Snapshots" +echo "================================================================================" +echo "" +python3 setup.py build-ubuntu --sign --snapshot diff --git a/setup/novelwriter.appdata.xml b/setup/novelwriter.appdata.xml new file mode 100644 index 00000000..98a6e33b --- /dev/null +++ b/setup/novelwriter.appdata.xml @@ -0,0 +1,21 @@ + + + novelwriter + GPL-3.0 + GPL-3.0 + novelWriter + A markdown-like text editor for planning and writing novels + +

{description}

+
+ novelwriter.desktop + https://novelwriter.io/ + + + https://novelwriter.io/images/screenshot-multi.png + + + + novelwriter.desktop + +
\ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index cf348870..769f855c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,6 +36,13 @@ from PyQt5.QtWidgets import QMessageBox # noqa: E402 from novelwriter.config import Config # noqa: E402 +@pytest.fixture(autouse=True) +def initQt(qtbot): + """Ensures that the qt main thread is always available in all tests. + """ + return + + ## # Core Test Folders ## @@ -173,6 +180,26 @@ def nwGUI(qtbot, monkeypatch, fncDir, fncConf): return +## +# Python Objects +## + +@pytest.fixture(scope="function") +def mockRnd(monkeypatch): + """Create a mock random number generator that just counts upwards + from 0. This one will generate status/importance flags and handles + in a predictable sequence. + """ + def rnd(n): + for x in range(n): + yield x + + gen = rnd(1000) + monkeypatch.setattr("random.getrandbits", lambda *a: next(gen)) + + return + + ## # Temp Project Folders ## @@ -241,10 +268,6 @@ def nwOldProj(tmpDir): return -## -# Useful Fixtures -## - @pytest.fixture(scope="session") def ipsumText(): """Return five paragraphs of Lorem Ipsum text. diff --git a/tests/lipsum/nwProject.nwx b/tests/lipsum/nwProject.nwx index 02803bbd..4eac7bc6 100644 --- a/tests/lipsum/nwProject.nwx +++ b/tests/lipsum/nwProject.nwx @@ -1,21 +1,22 @@ - + Lorem Ipsum Lorem Ipsum lipsum.com - 17 + 26 24 - 1777 + 1863 False en_GB False None - True 7a992350f3eb6 None + None + None 3847 3109 738 @@ -31,240 +32,102 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main
- - Novel - ROOT - NOVEL - New - True + + + Novel - - Lorem Ipsum - FILE - NOVEL - Finished - True - DOCUMENT - 230 - 40 - 3 - 148 + + + Lorem Ipsum - - Front Matter - FILE - NOVEL - Finished - True - DOCUMENT - 1058 - 176 - 2 - 43 + + + Front Matter - - Prologue - FILE - NOVEL - Draft - True - DOCUMENT - 584 - 92 - 1 - 4 + + + Prologue - - Act One - FILE - NOVEL - New - True - DOCUMENT - 35 - 6 - 1 - 42 + + + Act One - - Chapter One - FOLDER - NOVEL - Draft - True + + + Chapter One - - Chapter One - FILE - NOVEL - Draft - True - DOCUMENT - 419 - 67 - 1 - 56 + + + Chapter One - - Scene One - FILE - NOVEL - Finished - True - DOCUMENT - 2758 - 404 - 4 - 1528 + + + Scene One - - Scene Two - FILE - NOVEL - Finished - True - DOCUMENT - 4043 - 600 - 6 - 2335 + + + Scene Two - - Interlude - FILE - NOVEL - New - False - DOCUMENT - 631 - 109 - 3 - 376 + + + Interlude - - Chapter Two - FOLDER - NOVEL - Draft - True + + + Chapter Two - - Chapter Two - FILE - NOVEL - Draft - True - DOCUMENT - 477 - 70 - 1 - 56 + + + Chapter Two - - Scene Three - FILE - NOVEL - Finished - True - DOCUMENT - 3006 - 439 - 4 - 57 + + + Scene Three - - Scene Four - FILE - NOVEL - Finished - True - DOCUMENT - 3839 - 563 - 6 - 56 + + + Scene Four - - Scene Five - FILE - NOVEL - Finished - True - DOCUMENT - 3644 - 543 - 5 - 351 + + + Scene Five - - Characters - ROOT - CHARACTER - New - True + + + Characters - - Mr. Nobody - FILE - CHARACTER - Major - True - NOTE - 1864 - 284 - 3 - 1883 + + + Mr. Nobody - - Plot - ROOT - PLOT - New - True + + + Plot - - Main - FILE - PLOT - Main - True - NOTE - 1369 - 195 - 2 - 1387 + + + Main - - World - ROOT - WORLD - New - True + + + World - - Ancient Europe - FILE - WORLD - Minor - True - NOTE - 1770 - 259 - 3 - 1792 + + + Ancient Europe
diff --git a/tests/minimal/nwProject.nwx b/tests/minimal/nwProject.nwx index c1f2a901..5862d48c 100644 --- a/tests/minimal/nwProject.nwx +++ b/tests/minimal/nwProject.nwx @@ -1,22 +1,23 @@ - + Test Minimal Minimal Jane Doe John Doh - 9 + 17 2 - 113 + 150 True en_GB False None - True None None + None + None 10 10 0 @@ -29,89 +30,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main
- - Novel - ROOT - NOVEL - New - True + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 28 - 6 - 1 - 33 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - True + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 16 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 15 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World
diff --git a/tests/mock.py b/tests/mock.py index 4b272a17..23938d41 100644 --- a/tests/mock.py +++ b/tests/mock.py @@ -29,7 +29,6 @@ class MockGuiMain(): def __init__(self): self.mainConf = None self.hasProject = True - self.theIndex = None self.theProject = None self.statusBar = MockStatusBar() diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index 8018b089..56b5a807 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -13,8 +13,6 @@ hidehscroll = False [Sizes] geometry = 1200, 650 preferences = 700, 615 -treecols = 200, 50, 30 -novelcols = 200, 50 projcols = 200, 60, 140 mainpane = 300, 800 docpane = 400, 400 @@ -30,7 +28,7 @@ emphlabels = True [Editor] textfont = None textsize = 12 -width = 600 +width = 700 margin = 40 tabwidth = 40 focuswidth = 800 diff --git a/tests/reference/coreIndex_LoadSave_tagsIndex.json b/tests/reference/coreIndex_LoadSave_tagsIndex.json index fb4d9acd..60c59d86 100644 --- a/tests/reference/coreIndex_LoadSave_tagsIndex.json +++ b/tests/reference/coreIndex_LoadSave_tagsIndex.json @@ -1,99 +1,125 @@ { -"tagIndex": { - "Bod": [3, "4c4f28287af27", "CHARACTER", "T000001"], - "Main": [3, "2426c6f0ca922", "PLOT", "T000001"], - "Europe": [3, "04468803b92e1", "WORLD", "T000001"] -}, -"refIndex": { - "fb609cd8319dc": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] + "tagsIndex": { + "Bod": {"handle": "4c4f28287af27", "heading": "T000001", "class": "CHARACTER"}, + "Main": {"handle": "2426c6f0ca922", "heading": "T000001", "class": "PLOT"}, + "Europe": {"handle": "04468803b92e1", "heading": "T000001", "class": "WORLD"} }, - "88243afbe5ed8": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "f96ec11c6a3da": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "441420a886d82": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "eb103bc70c90c": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "f8c0562e50f1b": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "47666c91c7ccf": { - "T000001": [[3, "@pov", "Bod"], [4, "@plot", "Main"], [5, "@location", "Europe"]] - }, - "4c4f28287af27": { - "T000001": [[4, "@plot", "Main"]] + "itemIndex": { + "7a992350f3eb6": { + "level": "H1", + "headings": { + "T000001": {"level": "H1", "title": "Lorem Ipsum", "tag": "", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""} + } + }, + "8c58a65414c23": { + "level": "H0", + "headings": { + "T000000": {"level": "H0", "title": "", "tag": "", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""} + } + }, + "88d59a277361b": { + "level": "H2", + "headings": { + "T000001": {"level": "H2", "title": "Prologue", "tag": "", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} + } + }, + "db7e733775d4d": { + "level": "H1", + "headings": { + "T000001": {"level": "H1", "title": "Act One", "tag": "", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""} + } + }, + "fb609cd8319dc": { + "level": "H2", + "headings": { + "T000001": {"level": "H2", "title": "Chapter One", "tag": "", "cCount": 419, "wCount": 67, "pCount": 1, "synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at aliquam quam."} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "88243afbe5ed8": { + "level": "H3", + "headings": { + "T000001": {"level": "H3", "title": "Scene One", "tag": "", "cCount": 1197, "wCount": 174, "pCount": 2, "synopsis": "Aenean ut placerat velit. Etiam laoreet ullamcorper risus, eget lobortis enim scelerisque non. Suspendisse id maximus nunc, et mollis sapien. Curabitur vel semper sapien, non pulvinar dolor. Etiam finibus nisi vel mi molestie consectetur."}, + "T000013": {"level": "H4", "title": "Scene One, Section Two", "tag": "", "cCount": 1561, "wCount": 230, "pCount": 2, "synopsis": ""} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "f96ec11c6a3da": { + "level": "H3", + "headings": { + "T000001": {"level": "H3", "title": "Scene Two", "tag": "", "cCount": 2034, "wCount": 299, "pCount": 3, "synopsis": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer sapien nulla, dictum at lacus a, dignissim consectetur dolor. Nunc vel eleifend lacus, eu dapibus orci."}, + "T000015": {"level": "H4", "title": "Scene Two, Section Two", "tag": "", "cCount": 2009, "wCount": 301, "pCount": 3, "synopsis": ""} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "846352075de7d": { + "level": "H2", + "headings": { + "T000001": {"level": "H2", "title": "Why do we use it?", "tag": "", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""} + } + }, + "441420a886d82": { + "level": "H2", + "headings": { + "T000001": {"level": "H2", "title": "Chapter Two", "tag": "", "cCount": 477, "wCount": 70, "pCount": 1, "synopsis": "Curabitur a elit posuere, varius ex et, convallis neque. Phasellus sagittis pharetra sem vitae dapibus. Curabitur varius lorem non pulvinar congue."} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "eb103bc70c90c": { + "level": "H3", + "headings": { + "T000001": {"level": "H3", "title": "Scene Three", "tag": "", "cCount": 3006, "wCount": 439, "pCount": 4, "synopsis": "Aenean ut libero ut lectus porttitor rhoncus vel et massa. Nam pretium, nibh et varius vehicula, urna metus blandit eros, euismod pharetra diam diam et libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos."} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "f8c0562e50f1b": { + "level": "H3", + "headings": { + "T000001": {"level": "H3", "title": "Scene Four", "tag": "", "cCount": 3839, "wCount": 563, "pCount": 6, "synopsis": "Nam tempor blandit magna laoreet aliquet. Vestibulum auctor posuere leo, ac gravida nisi rhoncus varius. Aenean posuere dolor vitae condimentum volutpat. Donec egestas volutpat risus, quis luctus justo."} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "47666c91c7ccf": { + "level": "H3", + "headings": { + "T000001": {"level": "H3", "title": "Scene Five", "tag": "", "cCount": 3644, "wCount": 543, "pCount": 5, "synopsis": "Praesent eget est porta, dictum ante in, egestas risus. Mauris risus mauris, consequat aliquam mauris et, feugiat iaculis ipsum. Aliquam arcu ipsum, fermentum ut arcu sed, lobortis euismod sem. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus."} + }, + "references": { + "T000001": {"Bod": "@pov", "Main": "@plot", "Europe": "@location"} + } + }, + "4c4f28287af27": { + "level": "H1", + "headings": { + "T000001": {"level": "H1", "title": "Nobody Owens", "tag": "Bod", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""} + }, + "references": { + "T000001": {"Main": "@plot"} + } + }, + "2426c6f0ca922": { + "level": "H1", + "headings": { + "T000001": {"level": "H1", "title": "Main Plot", "tag": "Main", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""} + } + }, + "04468803b92e1": { + "level": "H1", + "headings": { + "T000001": {"level": "H1", "title": "Ancient Europe", "tag": "Europe", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""} + } + } } -}, -"fileIndex": { - "7a992350f3eb6": { - "T000001": {"level": "H1", "title": "Lorem Ipsum", "layout": "DOCUMENT", "cCount": 230, "wCount": 40, "pCount": 3, "synopsis": ""} - }, - "8c58a65414c23": { - "T000000": {"level": "H0", "title": "", "layout": "DOCUMENT", "cCount": 1058, "wCount": 176, "pCount": 2, "synopsis": ""} - }, - "88d59a277361b": { - "T000001": {"level": "H2", "title": "Prologue", "layout": "DOCUMENT", "cCount": 584, "wCount": 92, "pCount": 1, "synopsis": "Explanation from the lipsum.com website."} - }, - "db7e733775d4d": { - "T000001": {"level": "H1", "title": "Act One", "layout": "DOCUMENT", "cCount": 35, "wCount": 6, "pCount": 1, "synopsis": ""} - }, - "fb609cd8319dc": { - "T000001": {"level": "H2", "title": "Chapter One", "layout": "DOCUMENT", "cCount": 419, "wCount": 67, "pCount": 1, "synopsis": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at aliquam quam."} - }, - "88243afbe5ed8": { - "T000001": {"level": "H3", "title": "Scene One", "layout": "DOCUMENT", "cCount": 1197, "wCount": 174, "pCount": 2, "synopsis": "Aenean ut placerat velit. Etiam laoreet ullamcorper risus, eget lobortis enim scelerisque non. Suspendisse id maximus nunc, et mollis sapien. Curabitur vel semper sapien, non pulvinar dolor. Etiam finibus nisi vel mi molestie consectetur."}, - "T000013": {"level": "H4", "title": "Scene One, Section Two", "layout": "DOCUMENT", "cCount": 1561, "wCount": 230, "pCount": 2, "synopsis": ""} - }, - "f96ec11c6a3da": { - "T000001": {"level": "H3", "title": "Scene Two", "layout": "DOCUMENT", "cCount": 2034, "wCount": 299, "pCount": 3, "synopsis": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer sapien nulla, dictum at lacus a, dignissim consectetur dolor. Nunc vel eleifend lacus, eu dapibus orci."}, - "T000015": {"level": "H4", "title": "Scene Two, Section Two", "layout": "DOCUMENT", "cCount": 2009, "wCount": 301, "pCount": 3, "synopsis": ""} - }, - "846352075de7d": { - "T000001": {"level": "H2", "title": "Why do we use it?", "layout": "DOCUMENT", "cCount": 631, "wCount": 109, "pCount": 3, "synopsis": ""} - }, - "441420a886d82": { - "T000001": {"level": "H2", "title": "Chapter Two", "layout": "DOCUMENT", "cCount": 477, "wCount": 70, "pCount": 1, "synopsis": "Curabitur a elit posuere, varius ex et, convallis neque. Phasellus sagittis pharetra sem vitae dapibus. Curabitur varius lorem non pulvinar congue."} - }, - "eb103bc70c90c": { - "T000001": {"level": "H3", "title": "Scene Three", "layout": "DOCUMENT", "cCount": 3006, "wCount": 439, "pCount": 4, "synopsis": "Aenean ut libero ut lectus porttitor rhoncus vel et massa. Nam pretium, nibh et varius vehicula, urna metus blandit eros, euismod pharetra diam diam et libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos."} - }, - "f8c0562e50f1b": { - "T000001": {"level": "H3", "title": "Scene Four", "layout": "DOCUMENT", "cCount": 3839, "wCount": 563, "pCount": 6, "synopsis": "Nam tempor blandit magna laoreet aliquet. Vestibulum auctor posuere leo, ac gravida nisi rhoncus varius. Aenean posuere dolor vitae condimentum volutpat. Donec egestas volutpat risus, quis luctus justo."} - }, - "47666c91c7ccf": { - "T000001": {"level": "H3", "title": "Scene Five", "layout": "DOCUMENT", "cCount": 3644, "wCount": 543, "pCount": 5, "synopsis": "Praesent eget est porta, dictum ante in, egestas risus. Mauris risus mauris, consequat aliquam mauris et, feugiat iaculis ipsum. Aliquam arcu ipsum, fermentum ut arcu sed, lobortis euismod sem. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus."} - }, - "4c4f28287af27": { - "T000001": {"level": "H1", "title": "Nobody Owens", "layout": "NOTE", "cCount": 1864, "wCount": 284, "pCount": 3, "synopsis": ""} - }, - "2426c6f0ca922": { - "T000001": {"level": "H1", "title": "Main Plot", "layout": "NOTE", "cCount": 1369, "wCount": 195, "pCount": 2, "synopsis": ""} - }, - "04468803b92e1": { - "T000001": {"level": "H1", "title": "Ancient Europe", "layout": "NOTE", "cCount": 1770, "wCount": 259, "pCount": 3, "synopsis": ""} - } -}, -"fileMeta": { - "7a992350f3eb6": ["H1", 230, 40, 3], - "8c58a65414c23": ["H0", 1058, 176, 2], - "88d59a277361b": ["H2", 584, 92, 1], - "db7e733775d4d": ["H1", 35, 6, 1], - "fb609cd8319dc": ["H2", 419, 67, 1], - "88243afbe5ed8": ["H3", 2758, 404, 4], - "f96ec11c6a3da": ["H3", 4043, 600, 6], - "846352075de7d": ["H2", 631, 109, 3], - "441420a886d82": ["H2", 477, 70, 1], - "eb103bc70c90c": ["H3", 3006, 439, 4], - "f8c0562e50f1b": ["H3", 3839, 563, 6], - "47666c91c7ccf": ["H3", 3644, 543, 5], - "4c4f28287af27": ["H1", 1864, 284, 3], - "2426c6f0ca922": ["H1", 1369, 195, 2], - "04468803b92e1": ["H1", 1770, 259, 3] -} } diff --git a/tests/reference/coreProject_NewCustomA_nwProject.nwx b/tests/reference/coreProject_NewCustomA_nwProject.nwx index 3ba6a538..48ae6363 100644 --- a/tests/reference/coreProject_NewCustomA_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomA_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -14,9 +14,10 @@ None False None - True None None + None + None 0 0 0 @@ -29,244 +30,106 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - - Novel - ROOT - NOVEL - New - False + + + + Novel - - Plot - ROOT - PLOT - New - False + + + Title Page - - Characters - ROOT - CHARACTER - New - False + + + Chapter 1 - - Locations - ROOT - WORLD - New - False + + + Scene 1.1 - - Timeline - ROOT - TIMELINE - New - False + + + Scene 1.2 - - Objects - ROOT - OBJECT - New - False + + + Scene 1.3 - - Entities - ROOT - ENTITY - New - False + + + Chapter 2 - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2.1 - - Chapter 1 - FOLDER - NOVEL - New - False + + + Scene 2.2 - - Chapter 1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 2.3 - - Scene 1.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Chapter 3 - - Scene 1.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3.1 - - Scene 1.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 3.2 - - Chapter 2 - FOLDER - NOVEL - New - False + + + Scene 3.3 - - Chapter 2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Plot - - Scene 2.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Main Plot - - Scene 2.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Characters - - Scene 2.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Protagonist - - Chapter 3 - FOLDER - NOVEL - New - False + + + Locations - - Chapter 3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Main Location - - Scene 3.1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Archive - - Scene 3.2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 - - - Scene 3.3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Trash
diff --git a/tests/reference/coreProject_NewCustomB_nwProject.nwx b/tests/reference/coreProject_NewCustomB_nwProject.nwx index 2afad85a..9399dd3f 100644 --- a/tests/reference/coreProject_NewCustomB_nwProject.nwx +++ b/tests/reference/coreProject_NewCustomB_nwProject.nwx @@ -1,5 +1,5 @@ - + Test Custom Test Novel @@ -14,9 +14,10 @@ None False None - True None None + None + None 0 0 0 @@ -29,151 +30,82 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - - Novel - ROOT - NOVEL - New - False + + + + Novel - - Plot - ROOT - PLOT - New - False + + + Title Page - - Characters - ROOT - CHARACTER - New - False + + + Scene 1 - - Locations - ROOT - WORLD - New - False + + + Scene 2 - - Timeline - ROOT - TIMELINE - New - False + + + Scene 3 - - Objects - ROOT - OBJECT - New - False + + + Scene 4 - - Entities - ROOT - ENTITY - New - False + + + Scene 5 - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Scene 6 - - Scene 1 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Plot - - Scene 2 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Main Plot - - Scene 3 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Characters - - Scene 4 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Protagonist - - Scene 5 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Locations - - Scene 6 - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Main Location + + + + Archive + + + + Trash
diff --git a/tests/reference/coreProject_NewFileFolder_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx new file mode 100644 index 00000000..b8df1c93 --- /dev/null +++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx @@ -0,0 +1,90 @@ + + + + New Project + New Novel + Jane Doe + 2 + 1 + 0 + + + True + None + False + None + None + None + None + None + 2 + 1 + 1 + + + %title% + %title% + %title% + * * * +
+
+ + New + Note + Draft + Finished + + + New + Minor + Major + Main + +
+ + + + Novel + + + + Plot + + + + Characters + + + + World + + + + Title Page + + + + New Chapter + + + + New Chapter + + + + New Scene + + + + Stuff + + + + Hello + + + + Jane + + +
diff --git a/tests/reference/coreProject_NewFile_nwProject.nwx b/tests/reference/coreProject_NewFile_nwProject.nwx deleted file mode 100644 index 88c9aafb..00000000 --- a/tests/reference/coreProject_NewFile_nwProject.nwx +++ /dev/null @@ -1,139 +0,0 @@ - - - - New Project - - 2 - 1 - 0 - - - True - None - False - None - True - None - None - 0 - 0 - 0 - - - %title% - %title% - %title% - * * * -
-
- - New - Note - Draft - Finished - - - New - Minor - Major - Main - -
- - - Novel - ROOT - NOVEL - New - False - - - Plot - ROOT - PLOT - New - False - - - Characters - ROOT - CHARACTER - New - False - - - World - ROOT - WORLD - New - False - - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 - - - New Chapter - FOLDER - NOVEL - New - False - - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 - - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 - - - Hello - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 - - - Jane - FILE - CHARACTER - New - True - NOTE - 0 - 0 - 0 - 0 - - -
diff --git a/tests/reference/coreProject_NewMinimal_nwProject.nwx b/tests/reference/coreProject_NewMinimal_nwProject.nwx index d3702a07..633f9f4c 100644 --- a/tests/reference/coreProject_NewMinimal_nwProject.nwx +++ b/tests/reference/coreProject_NewMinimal_nwProject.nwx @@ -1,9 +1,9 @@ - + New Project - 1 + 2 1 0 @@ -12,9 +12,10 @@ None False None - True None None + None + None 0 0 0 @@ -27,89 +28,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - Novel - ROOT - NOVEL - New - False + + + Novel - - Plot - ROOT - PLOT - New - False + + + Title Page - - Characters - ROOT - CHARACTER - New - False + + + New Chapter - - World - ROOT - WORLD - New - False + + + New Scene - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Plot - - New Chapter - FOLDER - NOVEL - New - False + + + Characters - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Locations - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Archive
diff --git a/tests/reference/coreProject_NewRoot_nwProject.nwx b/tests/reference/coreProject_NewRoot_nwProject.nwx index 58344c12..9102601d 100644 --- a/tests/reference/coreProject_NewRoot_nwProject.nwx +++ b/tests/reference/coreProject_NewRoot_nwProject.nwx @@ -1,8 +1,9 @@ - + New Project - + New Novel + Jane Doe 2 1 0 @@ -12,9 +13,10 @@ None False None - True None None + None + None 0 0 0 @@ -27,117 +29,82 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - - Novel - ROOT - NOVEL - New - False + + + + Novel - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 0 - 0 - 0 - 0 + + + New Scene - - Timeline - ROOT - TIMELINE - New - False + + + Novel - - Object - ROOT - OBJECT - New - False + + + Plot - - Custom1 - ROOT - CUSTOM - New - False + + + Characters - - Custom2 - ROOT - CUSTOM - New - False + + + Locations + + + + Timeline + + + + Objects + + + + Custom + + + + Custom
diff --git a/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd b/tests/reference/guiEditor_Main_Final_000000000000f.nwd similarity index 96% rename from tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd rename to tests/reference/guiEditor_Main_Final_000000000000f.nwd index aabfe562..1ac700fb 100644 --- a/tests/reference/guiEditor_Main_Final_0e17daca5f3e1.nwd +++ b/tests/reference/guiEditor_Main_Final_000000000000f.nwd @@ -1,5 +1,5 @@ %%~name: New Scene -%%~path: 31489056e0916/0e17daca5f3e1 +%%~path: 000000000000d/000000000000f %%~kind: NOVEL/DOCUMENT # Novel diff --git a/tests/reference/guiEditor_Main_Final_1a6562590ef19.nwd b/tests/reference/guiEditor_Main_Final_0000000000020.nwd similarity index 57% rename from tests/reference/guiEditor_Main_Final_1a6562590ef19.nwd rename to tests/reference/guiEditor_Main_Final_0000000000020.nwd index 9a3ca0a9..c0316819 100644 --- a/tests/reference/guiEditor_Main_Final_1a6562590ef19.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000020.nwd @@ -1,5 +1,5 @@ -%%~name: New File -%%~path: 71ee45a3c0db9/1a6562590ef19 +%%~name: New Note +%%~path: 000000000000a/0000000000020 %%~kind: CHARACTER/NOTE # Jane Doe diff --git a/tests/reference/guiEditor_Main_Final_031b4af5197ec.nwd b/tests/reference/guiEditor_Main_Final_0000000000021.nwd similarity index 61% rename from tests/reference/guiEditor_Main_Final_031b4af5197ec.nwd rename to tests/reference/guiEditor_Main_Final_0000000000021.nwd index acb36501..5dddd23b 100644 --- a/tests/reference/guiEditor_Main_Final_031b4af5197ec.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000021.nwd @@ -1,5 +1,5 @@ -%%~name: New File -%%~path: 44cb730c42048/031b4af5197ec +%%~name: New Note +%%~path: 0000000000009/0000000000021 %%~kind: PLOT/NOTE # Main Plot diff --git a/tests/reference/guiEditor_Main_Final_41cfc0d1f2d12.nwd b/tests/reference/guiEditor_Main_Final_0000000000022.nwd similarity index 62% rename from tests/reference/guiEditor_Main_Final_41cfc0d1f2d12.nwd rename to tests/reference/guiEditor_Main_Final_0000000000022.nwd index 8e8cb037..092f832a 100644 --- a/tests/reference/guiEditor_Main_Final_41cfc0d1f2d12.nwd +++ b/tests/reference/guiEditor_Main_Final_0000000000022.nwd @@ -1,5 +1,5 @@ -%%~name: New File -%%~path: 811786ad1ae74/41cfc0d1f2d12 +%%~name: New Note +%%~path: 000000000000b/0000000000022 %%~kind: WORLD/NOTE # Main Location diff --git a/tests/reference/guiEditor_Main_Final_nwProject.nwx b/tests/reference/guiEditor_Main_Final_nwProject.nwx index d4dbfd2e..5496b5b3 100644 --- a/tests/reference/guiEditor_Main_Final_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Final_nwProject.nwx @@ -1,9 +1,10 @@ - + New Project - - 5 + New Novel + Jane Doe + 4 2 4 @@ -12,11 +13,12 @@ None True None - True - 0e17daca5f3e1 + 000000000000f None - 142 - 115 + 0000000000008 + 0000000000008 + 145 + 118 27 @@ -27,132 +29,66 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - Novel - ROOT - NOVEL - New - True + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - True + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 693 - 111 - 12 - 917 + + + New Scene - - Plot - ROOT - PLOT - New - True + + + Plot - - New File - FILE - PLOT - New - True - NOTE - 48 - 10 - 1 - 69 + + + New Note - - Characters - ROOT - CHARACTER - New - True + + + Characters - - New File - FILE - CHARACTER - New - True - NOTE - 34 - 8 - 1 - 51 + + + New Note - - World - ROOT - WORLD - New - True + + + World - - New File - FILE - WORLD - New - True - NOTE - 51 - 9 - 1 - 68 + + + New Note - - Trash - TRASH - TRASH - None - True + + + Trash
diff --git a/tests/reference/guiEditor_Main_Initial_nwProject.nwx b/tests/reference/guiEditor_Main_Initial_nwProject.nwx index 7d2cfe5f..0563c440 100644 --- a/tests/reference/guiEditor_Main_Initial_nwProject.nwx +++ b/tests/reference/guiEditor_Main_Initial_nwProject.nwx @@ -1,9 +1,10 @@ - + New Project - - 3 + New Novel + Jane Doe + 2 1 0 @@ -12,11 +13,12 @@ None False None - True None None - 6 - 6 + None + None + 9 + 9 0 @@ -27,89 +29,50 @@
- New - Note - Draft - Finished + New + Note + Draft + Finished - New - Minor - Major - Main + New + Minor + Major + Main - - Novel - ROOT - NOVEL - New - False + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 0 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World
diff --git a/tests/reference/guiPreferences_novelwriter.conf b/tests/reference/guiPreferences_novelwriter.conf index 71c08fb1..9d21830d 100644 --- a/tests/reference/guiPreferences_novelwriter.conf +++ b/tests/reference/guiPreferences_novelwriter.conf @@ -13,8 +13,6 @@ hidehscroll = True [Sizes] geometry = 1200, 650 preferences = 670, 589 -treecols = 200, 50, 30 -novelcols = 200, 50 projcols = 200, 60, 140 mainpane = 300, 800 docpane = 400, 400 diff --git a/tests/reference/guiProjSettings_Dialog_nwProject.nwx b/tests/reference/guiProjSettings_Dialog_nwProject.nwx index 96334e16..1db9d48c 100644 --- a/tests/reference/guiProjSettings_Dialog_nwProject.nwx +++ b/tests/reference/guiProjSettings_Dialog_nwProject.nwx @@ -1,11 +1,11 @@ - + Project Name Project Title Jane Doe John Doh - 2 + 1 1 0 @@ -14,16 +14,17 @@ None False en - True None None - 6 - 6 + None + None + 9 + 9 0 B D - With This Stuff + With This Stuff %title% @@ -33,89 +34,50 @@
- New - Note - Finished - Final + New + Note + Finished + Final - New - Minor - Major - Final + New + Minor + Major + Final - - Novel - ROOT - NOVEL - New - False + + + Novel - - Title Page - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + Title Page - - New Chapter - FOLDER - NOVEL - New - False + + + New Chapter - - New Chapter - FILE - NOVEL - New - True - DOCUMENT - 11 - 2 - 0 - 0 + + + New Chapter - - New Scene - FILE - NOVEL - New - True - DOCUMENT - 9 - 2 - 0 - 0 + + + New Scene - - Plot - ROOT - PLOT - New - False + + + Plot - - Characters - ROOT - CHARACTER - New - False + + + Characters - - World - ROOT - WORLD - New - False + + + World
diff --git a/tests/test_base/test_base_common.py b/tests/test_base/test_base_common.py index 5b9b9c13..0ce153b4 100644 --- a/tests/test_base/test_base_common.py +++ b/tests/test_base/test_base_common.py @@ -24,8 +24,6 @@ import os import time import pytest -from datetime import datetime - from mock import causeOSError from tools import writeFile @@ -33,7 +31,7 @@ from novelwriter.guimain import GuiMain from novelwriter.common import ( checkString, checkInt, checkFloat, checkBool, checkHandle, isHandle, isTitleTag, isItemClass, isItemType, isItemLayout, hexToInt, checkIntRange, - checkIntTuple, formatInt, formatTimeStamp, formatTime, parseTimeStamp, + minmax, checkIntTuple, formatInt, formatTimeStamp, formatTime, simplified, splitVersionNumber, transferCase, fuzzyTime, numberToRoman, jsonEncode, readTextFile, makeFileNameSafe, sha256sum, getGuiItem, NWConfigParser ) @@ -163,6 +161,7 @@ def testBaseCommon_IsItemClass(): assert isItemClass("ARCHIVE") is True assert isItemClass("TRASH") is True + # Invalid assert isItemClass("None") is False assert isItemClass(None) is False assert isItemClass("STUFF") is False @@ -178,8 +177,11 @@ def testBaseCommon_IsItemType(): assert isItemType("ROOT") is True assert isItemType("FOLDER") is True assert isItemType("FILE") is True - assert isItemType("TRASH") is True + # Deprecated Type + assert isItemType("TRASH") is False + + # Invalid assert isItemType("None") is False assert isItemType(None) is False assert isItemType("STUFF") is False @@ -195,6 +197,16 @@ def testBaseCommon_IsItemLayout(): assert isItemLayout("DOCUMENT") is True assert isItemLayout("NOTE") is True + # Deprecated Layouts + assert isItemLayout("TITLE") is False + assert isItemLayout("PAGE") is False + assert isItemLayout("BOOK") is False + assert isItemLayout("PARTITION") is False + assert isItemLayout("UNNUMBERED") is False + assert isItemLayout("CHAPTER") is False + assert isItemLayout("SCENE") is False + + # Invalid assert isItemLayout("None") is False assert isItemLayout(None) is False assert isItemLayout("STUFF") is False @@ -228,6 +240,16 @@ def testBaseCommon_CheckIntRange(): # END Test testBaseCommon_CheckIntRange +@pytest.mark.base +def testBaseCommon_MinMax(): + """Test the minmax function. + """ + for i in range(-5, 15): + assert 0 <= minmax(i, 0, 10) <= 10 + +# END Test testBaseCommon_MinMax + + @pytest.mark.base def testBaseCommon_CheckIntTuple(): """Test the checkIntTuple function. @@ -273,18 +295,14 @@ def testBaseCommon_FormatTime(): @pytest.mark.base -def testBaseCommon_ParseTimeStamp(): - """Test the parseTimeStamp function. +def testBaseCommon_Simplified(): + """Test the simplified function. """ - localEpoch = datetime(2000, 1, 1).timestamp() - assert parseTimeStamp(None, 0.0, allowNone=True) is None - assert parseTimeStamp("None", 0.0, allowNone=True) is None - assert parseTimeStamp("None", 0.0) == 0.0 - assert parseTimeStamp("2000-01-01 00:00:00", 123.0) == localEpoch - assert parseTimeStamp("2000-13-01 00:00:00", 123.0) == 123.0 - assert parseTimeStamp("2000-01-32 00:00:00", 123.0) == 123.0 + assert simplified("Hello World") == "Hello World" + assert simplified(" Hello World ") == "Hello World" + assert simplified("\tHello\n\r\tWorld") == "Hello World" -# END Test testBaseCommon_ParseTimeStamp +# END Test testBaseCommon_Simplified @pytest.mark.base diff --git a/tests/test_base/test_base_config.py b/tests/test_base/test_base_config.py index 2e055884..83ff3160 100644 --- a/tests/test_base/test_base_config.py +++ b/tests/test_base/test_base_config.py @@ -410,32 +410,6 @@ def testBaseConfig_SettersGetters(tmpConf, tmpDir, outDir, refDir): assert tmpConf.setPreferencesSize(700, 615) - # Project Tree Columns - tmpConf.guiScale = 2.0 - assert tmpConf.setTreeColWidths([10, 20, 25]) - assert tmpConf.getTreeColWidths() == [10, 20, 24] - assert tmpConf.treeColWidth == [5, 10, 12] - - tmpConf.guiScale = 1.0 - assert tmpConf.setTreeColWidths([10, 20, 25]) - assert tmpConf.getTreeColWidths() == [10, 20, 25] - assert tmpConf.treeColWidth == [10, 20, 25] - - assert tmpConf.setTreeColWidths([200, 50, 30]) - - # Novel Tree Columns - tmpConf.guiScale = 2.0 - assert tmpConf.setNovelColWidths([10, 20]) - assert tmpConf.getNovelColWidths() == [10, 20] - assert tmpConf.novelColWidth == [5, 10] - - tmpConf.guiScale = 1.0 - assert tmpConf.setNovelColWidths([10, 20]) - assert tmpConf.getNovelColWidths() == [10, 20] - assert tmpConf.novelColWidth == [10, 20] - - assert tmpConf.setNovelColWidths([200, 50]) - # Project Settings Tree Columns tmpConf.guiScale = 2.0 assert tmpConf.setProjColWidths([10, 20, 30]) @@ -505,13 +479,13 @@ def testBaseConfig_SettersGetters(tmpConf, tmpDir, outDir, refDir): # ============ tmpConf.guiScale = 1.0 - assert tmpConf.getTextWidth(False) == 600 + assert tmpConf.getTextWidth(False) == 700 assert tmpConf.getTextWidth(True) == 800 assert tmpConf.getTextMargin() == 40 assert tmpConf.getTabWidth() == 40 tmpConf.guiScale = 2.0 - assert tmpConf.getTextWidth(False) == 1200 + assert tmpConf.getTextWidth(False) == 1400 assert tmpConf.getTextWidth(True) == 1600 assert tmpConf.getTextMargin() == 80 assert tmpConf.getTabWidth() == 80 diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index eb7794b5..2f80e45a 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -64,9 +64,9 @@ def testCoreDocument_LoadSave(monkeypatch, mockGUI, nwMinimal): assert theDoc.readDocument() == "### New Scene\n\n" # Try to open a new (non-existent) file - nHandle = theProject.projTree.findRoot(nwItemClass.NOVEL) + nHandle = theProject.tree.findRoot(nwItemClass.NOVEL) assert nHandle is not None - xHandle = theProject.newFile("New File", nwItemClass.NOVEL, nHandle) + xHandle = theProject.newFile("New File", nHandle) theDoc = NWDoc(theProject, xHandle) assert bool(theDoc) is True assert repr(theDoc) == f"" diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 9a7f7b88..8f126e56 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -19,17 +19,17 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os import json +import pytest from shutil import copyfile from mock import causeException -from tools import cmpFiles +from tools import buildTestProject, cmpFiles, writeFile from novelwriter.core.project import NWProject -from novelwriter.core.index import NWIndex, countWords +from novelwriter.core.index import NWIndex, countWords, TagsIndex from novelwriter.enum import nwItemClass, nwItemLayout @@ -43,10 +43,11 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir): compFile = os.path.join(refDir, "coreIndex_LoadSave_tagsIndex.json") theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) assert theProject.openProject(nwLipsum) theIndex = NWIndex(theProject) + assert repr(theIndex) == "" + notIndexable = { "b3643d0f92e32": False, # Novel ROOT "45e6b01ca35c1": False, # Chapter One FOLDER @@ -55,7 +56,7 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir): "6c6afb1247750": False, # Plot ROOT "60bdf227455cc": False, # World ROOT } - for tItem in theProject.projTree: + for tItem in theProject.tree: assert theIndex.reIndexHandle(tItem.itemHandle) is notIndexable.get(tItem.itemHandle, True) assert theIndex.reIndexHandle(None) is False @@ -69,66 +70,77 @@ def testCoreIndex_LoadSave(monkeypatch, nwLipsum, mockGUI, outDir, refDir): assert theIndex.saveIndex() is True # Take a copy of the index - tagIndex = str(theIndex._tagIndex) - refIndex = str(theIndex._refIndex) - fileIndex = str(theIndex._fileIndex) - textCounts = str(theIndex._fileMeta) + tagIndex = str(theIndex._tagsIndex.packData()) + itemsIndex = str(theIndex._itemIndex.packData()) # Delete a handle - assert theIndex._tagIndex.get("Bod", None) is not None - assert theIndex._refIndex.get("4c4f28287af27", None) is not None - assert theIndex._fileIndex.get("4c4f28287af27", None) is not None - assert theIndex._fileMeta.get("4c4f28287af27", None) is not None + assert theIndex._tagsIndex["Bod"] is not None + assert theIndex._itemIndex["4c4f28287af27"] is not None theIndex.deleteHandle("4c4f28287af27") - assert theIndex._tagIndex.get("Bod", None) is None - assert theIndex._refIndex.get("4c4f28287af27", None) is None - assert theIndex._fileIndex.get("4c4f28287af27", None) is None - assert theIndex._fileMeta.get("4c4f28287af27", None) is None + assert theIndex._tagsIndex["Bod"] is None + assert theIndex._itemIndex["4c4f28287af27"] is None # Clear the index theIndex.clearIndex() - assert theIndex._tagIndex == {} - assert theIndex._refIndex == {} - assert theIndex._fileIndex == {} - assert theIndex._fileMeta == {} + assert theIndex._tagsIndex._tags == {} + assert theIndex._itemIndex._items == {} # Make the load fail with monkeypatch.context() as mp: mp.setattr(json, "load", causeException) assert theIndex.loadIndex() is False + assert theIndex.indexBroken is True # Make the load pass assert theIndex.loadIndex() is True - - assert str(theIndex._tagIndex) == tagIndex - assert str(theIndex._refIndex) == refIndex - assert str(theIndex._fileIndex) == fileIndex - assert str(theIndex._fileMeta) == textCounts - - # Break the index and check that we notice assert theIndex.indexBroken is False - theIndex._tagIndex["Bod"].append("Stuff") - theIndex._checkIndex() + + assert str(theIndex._tagsIndex.packData()) == tagIndex + assert str(theIndex._itemIndex.packData()) == itemsIndex + + # Check File + copyfile(projFile, testFile) + assert cmpFiles(testFile, compFile) + + # Write an emtpy index file and load it + writeFile(projFile, "{}") + assert theIndex.loadIndex() is False assert theIndex.indexBroken is True + # Write an index file that passes loading, but is still empty + writeFile(projFile, '{"tagsIndex": {}, "itemIndex": {}}') + assert theIndex.loadIndex() is True + assert theIndex.indexBroken is False + + # Check that the index is re-populated + assert "04468803b92e1" in theIndex._itemIndex + assert "2426c6f0ca922" in theIndex._itemIndex + assert "441420a886d82" in theIndex._itemIndex + assert "47666c91c7ccf" in theIndex._itemIndex + assert "4c4f28287af27" in theIndex._itemIndex + assert "846352075de7d" in theIndex._itemIndex + assert "88243afbe5ed8" in theIndex._itemIndex + assert "88d59a277361b" in theIndex._itemIndex + assert "8c58a65414c23" in theIndex._itemIndex + assert "db7e733775d4d" in theIndex._itemIndex + assert "eb103bc70c90c" in theIndex._itemIndex + assert "f8c0562e50f1b" in theIndex._itemIndex + assert "f96ec11c6a3da" in theIndex._itemIndex + assert "fb609cd8319dc" in theIndex._itemIndex + assert "7a992350f3eb6" in theIndex._itemIndex + # Finalise assert theProject.closeProject() is True - copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile) - # END Test testCoreIndex_LoadSave @pytest.mark.core -def testCoreIndex_ScanThis(nwMinimal, mockGUI): +def testCoreIndex_ScanThis(mockGUI): """Test the tag scanner function scanThis. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) - assert theProject.openProject(nwMinimal) is True - - theIndex = NWIndex(theProject) + theIndex = theProject.index isValid, theBits, thePos = theIndex.scanThis("tag: this, and this") assert isValid is False @@ -173,21 +185,19 @@ def testCoreIndex_ScanThis(nwMinimal, mockGUI): @pytest.mark.core -def testCoreIndex_CheckThese(nwMinimal, mockGUI): +def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd): """Test the tag checker function checkThese. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) - assert theProject.openProject(nwMinimal) is True + buildTestProject(theProject, fncDir) + theIndex = theProject.index - theIndex = NWIndex(theProject) - nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") - cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") - nItem = theProject.projTree[nHandle] - cItem = theProject.projTree[cHandle] + nHandle = theProject.newFile("Hello", "0000000000010") + cHandle = theProject.newFile("Jane", "0000000000012") + nItem = theProject.tree[nHandle] + cItem = theProject.tree[cHandle] - assert theIndex.novelChangedSince(0) is False - assert theIndex.notesChangedSince(0) is False + assert theIndex.rootChangedSince("0000000000010", 0) is False assert theIndex.indexChangedSince(0) is False assert theIndex.scanText(cHandle, ( @@ -201,8 +211,10 @@ def testCoreIndex_CheckThese(nwMinimal, mockGUI): "@pov: Jane\n" "@invalid: John\n" # Checks for issue #688 )) - assert theIndex._tagIndex == {"Jane": [2, cHandle, "CHARACTER", "T000001"]} - assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!" + assert theIndex._tagsIndex.tagHandle("Jane") == cHandle + assert theIndex._tagsIndex.tagHeading("Jane") == "T000001" + assert theIndex._tagsIndex.tagClass("Jane") == "CHARACTER" + assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!" assert theIndex.getReferences(nHandle, "T000001") == { "@char": [], "@custom": [], @@ -215,8 +227,7 @@ def testCoreIndex_CheckThese(nwMinimal, mockGUI): "@time": [] } - assert theIndex.novelChangedSince(0) is True - assert theIndex.notesChangedSince(0) is True + assert theIndex.rootChangedSince("0000000000010", 0) is True assert theIndex.indexChangedSince(0) is True assert theIndex.getHandleHeaderLevel(cHandle) == "H1" @@ -250,19 +261,17 @@ def testCoreIndex_CheckThese(nwMinimal, mockGUI): @pytest.mark.core -def testCoreIndex_ScanText(nwMinimal, mockGUI): +def testCoreIndex_ScanText(mockGUI, fncDir, mockRnd): """Check the index text scanner. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) - assert theProject.openProject(nwMinimal) is True - - theIndex = NWIndex(theProject) + buildTestProject(theProject, fncDir) + theIndex = theProject.index # Some items for fail to scan tests - dHandle = theProject.newFolder("Folder", nwItemClass.NOVEL, "a508bb932959c") - xHandle = theProject.newFile("No Layout", nwItemClass.NOVEL, "a508bb932959c") - xItem = theProject.projTree[xHandle] + dHandle = theProject.newFolder("Folder", "0000000000010") + xHandle = theProject.newFile("No Layout", "0000000000010") + xItem = theProject.tree[xHandle] xItem.setLayout(nwItemLayout.NO_LAYOUT) # Check invalid data @@ -276,22 +285,26 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): # Create the trash folder tHandle = theProject.trashFolder() - assert theProject.projTree[tHandle] is not None + assert theProject.tree[tHandle] is not None xItem.setParent(tHandle) + theProject.tree.updateItemData(xItem.itemHandle) + assert xItem.itemRoot == tHandle + assert xItem.itemClass == nwItemClass.TRASH assert theIndex.scanText(xHandle, "Hello World!") is False # Create the archive root - aHandle = theProject.newRoot("Archive", nwItemClass.ARCHIVE) - assert theProject.projTree[aHandle] is not None + aHandle = theProject.newRoot(nwItemClass.ARCHIVE) + assert theProject.tree[aHandle] is not None xItem.setParent(aHandle) + theProject.tree.updateItemData(xItem.itemHandle) assert theIndex.scanText(xHandle, "Hello World!") is False # Make some usable items - tHandle = theProject.newFile("Title", nwItemClass.NOVEL, "a508bb932959c") - pHandle = theProject.newFile("Page", nwItemClass.NOVEL, "a508bb932959c") - nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") - cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") - sHandle = theProject.newFile("Scene", nwItemClass.NOVEL, "a508bb932959c") + tHandle = theProject.newFile("Title", "0000000000010") + pHandle = theProject.newFile("Page", "0000000000010") + nHandle = theProject.newFile("Hello", "0000000000010") + cHandle = theProject.newFile("Jane", "0000000000012") + sHandle = theProject.newFile("Scene", "0000000000010") # Text Indexing # ============= @@ -309,8 +322,10 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): "This is a story about Jane Smith.\n\n" "Well, not really.\n" )) - assert theIndex._tagIndex == {"Jane": [2, cHandle, "CHARACTER", "T000001"]} - assert theIndex.getNovelData(nHandle, "T000001")["title"] == "Hello World!" + assert theIndex._tagsIndex.tagHandle("Jane") == cHandle + assert theIndex._tagsIndex.tagHeading("Jane") == "T000001" + assert theIndex._tagsIndex.tagClass("Jane") == "CHARACTER" + assert theIndex.getNovelData(nHandle, "T000001").title == "Hello World!" # Title Indexing # ============== @@ -332,42 +347,40 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): "##### Title Five\n\n" # Not interpreted as a title, the hashes are counted as a word "Paragraph Five.\n\n" )) - assert nHandle not in theIndex._refIndex + assert theIndex._itemIndex[nHandle]["T000001"].references == {} + assert theIndex._itemIndex[nHandle]["T000007"].references == {} + assert theIndex._itemIndex[nHandle]["T000013"].references == {} + assert theIndex._itemIndex[nHandle]["T000019"].references == {} - assert theIndex._fileIndex[nHandle]["T000001"]["level"] == "H1" - assert theIndex._fileIndex[nHandle]["T000007"]["level"] == "H2" - assert theIndex._fileIndex[nHandle]["T000013"]["level"] == "H3" - assert theIndex._fileIndex[nHandle]["T000019"]["level"] == "H4" + assert theIndex._itemIndex[nHandle]["T000001"].level == "H1" + assert theIndex._itemIndex[nHandle]["T000007"].level == "H2" + assert theIndex._itemIndex[nHandle]["T000013"].level == "H3" + assert theIndex._itemIndex[nHandle]["T000019"].level == "H4" - assert theIndex._fileIndex[nHandle]["T000001"]["title"] == "Title One" - assert theIndex._fileIndex[nHandle]["T000007"]["title"] == "Title Two" - assert theIndex._fileIndex[nHandle]["T000013"]["title"] == "Title Three" - assert theIndex._fileIndex[nHandle]["T000019"]["title"] == "Title Four" + assert theIndex._itemIndex[nHandle]["T000001"].title == "Title One" + assert theIndex._itemIndex[nHandle]["T000007"].title == "Title Two" + assert theIndex._itemIndex[nHandle]["T000013"].title == "Title Three" + assert theIndex._itemIndex[nHandle]["T000019"].title == "Title Four" - assert theIndex._fileIndex[nHandle]["T000001"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[nHandle]["T000007"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[nHandle]["T000013"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[nHandle]["T000019"]["layout"] == "DOCUMENT" + assert theIndex._itemIndex[nHandle]["T000001"].charCount == 23 + assert theIndex._itemIndex[nHandle]["T000007"].charCount == 23 + assert theIndex._itemIndex[nHandle]["T000013"].charCount == 27 + assert theIndex._itemIndex[nHandle]["T000019"].charCount == 56 - assert theIndex._fileIndex[nHandle]["T000001"]["cCount"] == 23 - assert theIndex._fileIndex[nHandle]["T000007"]["cCount"] == 23 - assert theIndex._fileIndex[nHandle]["T000013"]["cCount"] == 27 - assert theIndex._fileIndex[nHandle]["T000019"]["cCount"] == 56 + assert theIndex._itemIndex[nHandle]["T000001"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T000007"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T000013"].wordCount == 4 + assert theIndex._itemIndex[nHandle]["T000019"].wordCount == 9 - assert theIndex._fileIndex[nHandle]["T000001"]["wCount"] == 4 - assert theIndex._fileIndex[nHandle]["T000007"]["wCount"] == 4 - assert theIndex._fileIndex[nHandle]["T000013"]["wCount"] == 4 - assert theIndex._fileIndex[nHandle]["T000019"]["wCount"] == 9 + assert theIndex._itemIndex[nHandle]["T000001"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T000007"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T000013"].paraCount == 1 + assert theIndex._itemIndex[nHandle]["T000019"].paraCount == 3 - assert theIndex._fileIndex[nHandle]["T000001"]["pCount"] == 1 - assert theIndex._fileIndex[nHandle]["T000007"]["pCount"] == 1 - assert theIndex._fileIndex[nHandle]["T000013"]["pCount"] == 1 - assert theIndex._fileIndex[nHandle]["T000019"]["pCount"] == 3 - - assert theIndex._fileIndex[nHandle]["T000001"]["synopsis"] == "Synopsis One." - assert theIndex._fileIndex[nHandle]["T000007"]["synopsis"] == "Synopsis Two." - assert theIndex._fileIndex[nHandle]["T000013"]["synopsis"] == "Synopsis Three." - assert theIndex._fileIndex[nHandle]["T000019"]["synopsis"] == "Synopsis Four." + assert theIndex._itemIndex[nHandle]["T000001"].synopsis == "Synopsis One." + assert theIndex._itemIndex[nHandle]["T000007"].synopsis == "Synopsis Two." + assert theIndex._itemIndex[nHandle]["T000013"].synopsis == "Synopsis Three." + assert theIndex._itemIndex[nHandle]["T000019"].synopsis == "Synopsis Four." # Note File assert theIndex.scanText(cHandle, ( @@ -376,15 +389,13 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): "% synopsis: Synopsis One.\n\n" "Paragraph One.\n\n" )) - assert cHandle not in theIndex._refIndex - - assert theIndex._fileIndex[cHandle]["T000001"]["level"] == "H1" - assert theIndex._fileIndex[cHandle]["T000001"]["title"] == "Title One" - assert theIndex._fileIndex[cHandle]["T000001"]["layout"] == "NOTE" - assert theIndex._fileIndex[cHandle]["T000001"]["cCount"] == 23 - assert theIndex._fileIndex[cHandle]["T000001"]["wCount"] == 4 - assert theIndex._fileIndex[cHandle]["T000001"]["pCount"] == 1 - assert theIndex._fileIndex[cHandle]["T000001"]["synopsis"] == "Synopsis One." + assert theIndex._itemIndex[cHandle]["T000001"].references == {} + assert theIndex._itemIndex[cHandle]["T000001"].level == "H1" + assert theIndex._itemIndex[cHandle]["T000001"].title == "Title One" + assert theIndex._itemIndex[cHandle]["T000001"].charCount == 23 + assert theIndex._itemIndex[cHandle]["T000001"].wordCount == 4 + assert theIndex._itemIndex[cHandle]["T000001"].paraCount == 1 + assert theIndex._itemIndex[cHandle]["T000001"].synopsis == "Synopsis One." # Valid and Invalid References assert theIndex.scanText(sHandle, ( @@ -395,9 +406,9 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): "% synopsis: Synopsis One.\n\n" "Paragraph One.\n\n" )) - assert theIndex._refIndex[sHandle]["T000001"] == ( - [[3, "@pov", "One"], [5, "@char", "Two"]] - ) + assert theIndex._itemIndex[sHandle]["T000001"].references == { + "One": {"@pov"}, "Two": {"@char"} + } # Special Titles # ============== @@ -406,58 +417,52 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): "#! My Project\n\n" ">> By Jane Doe <<\n\n" )) - assert tHandle not in theIndex._refIndex - - assert theIndex._fileIndex[tHandle]["T000001"]["level"] == "H1" - assert theIndex._fileIndex[tHandle]["T000001"]["title"] == "My Project" - assert theIndex._fileIndex[tHandle]["T000001"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[tHandle]["T000001"]["cCount"] == 21 - assert theIndex._fileIndex[tHandle]["T000001"]["wCount"] == 5 - assert theIndex._fileIndex[tHandle]["T000001"]["pCount"] == 1 - assert theIndex._fileIndex[tHandle]["T000001"]["synopsis"] == "" + assert theIndex._itemIndex[cHandle]["T000001"].references == {} + assert theIndex._itemIndex[tHandle]["T000001"].level == "H1" + assert theIndex._itemIndex[tHandle]["T000001"].title == "My Project" + assert theIndex._itemIndex[tHandle]["T000001"].charCount == 21 + assert theIndex._itemIndex[tHandle]["T000001"].wordCount == 5 + assert theIndex._itemIndex[tHandle]["T000001"].paraCount == 1 + assert theIndex._itemIndex[tHandle]["T000001"].synopsis == "" assert theIndex.scanText(tHandle, ( "##! Prologue\n\n" "In the beginning there was time ...\n\n" )) - assert tHandle not in theIndex._refIndex - - assert theIndex._fileIndex[tHandle]["T000001"]["level"] == "H2" - assert theIndex._fileIndex[tHandle]["T000001"]["title"] == "Prologue" - assert theIndex._fileIndex[tHandle]["T000001"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[tHandle]["T000001"]["cCount"] == 43 - assert theIndex._fileIndex[tHandle]["T000001"]["wCount"] == 8 - assert theIndex._fileIndex[tHandle]["T000001"]["pCount"] == 1 - assert theIndex._fileIndex[tHandle]["T000001"]["synopsis"] == "" + assert theIndex._itemIndex[cHandle]["T000001"].references == {} + assert theIndex._itemIndex[tHandle]["T000001"].level == "H2" + assert theIndex._itemIndex[tHandle]["T000001"].title == "Prologue" + assert theIndex._itemIndex[tHandle]["T000001"].charCount == 43 + assert theIndex._itemIndex[tHandle]["T000001"].wordCount == 8 + assert theIndex._itemIndex[tHandle]["T000001"].paraCount == 1 + assert theIndex._itemIndex[tHandle]["T000001"].synopsis == "" # Page wo/Title # ============= - theProject.projTree[pHandle]._layout = nwItemLayout.DOCUMENT + theProject.tree[pHandle]._layout = nwItemLayout.DOCUMENT assert theIndex.scanText(pHandle, ( "This is a page with some text on it.\n\n" )) - assert pHandle in theIndex._fileIndex - assert theIndex._fileIndex[pHandle]["T000000"]["level"] == "H0" - assert theIndex._fileIndex[pHandle]["T000000"]["title"] == "" - assert theIndex._fileIndex[pHandle]["T000000"]["layout"] == "DOCUMENT" - assert theIndex._fileIndex[pHandle]["T000000"]["cCount"] == 36 - assert theIndex._fileIndex[pHandle]["T000000"]["wCount"] == 9 - assert theIndex._fileIndex[pHandle]["T000000"]["pCount"] == 1 - assert theIndex._fileIndex[pHandle]["T000000"]["synopsis"] == "" + assert theIndex._itemIndex[pHandle]["T000000"].references == {} + assert theIndex._itemIndex[pHandle]["T000000"].level == "H0" + assert theIndex._itemIndex[pHandle]["T000000"].title == "" + assert theIndex._itemIndex[pHandle]["T000000"].charCount == 36 + assert theIndex._itemIndex[pHandle]["T000000"].wordCount == 9 + assert theIndex._itemIndex[pHandle]["T000000"].paraCount == 1 + assert theIndex._itemIndex[pHandle]["T000000"].synopsis == "" - theProject.projTree[pHandle]._layout = nwItemLayout.NOTE + theProject.tree[pHandle]._layout = nwItemLayout.NOTE assert theIndex.scanText(pHandle, ( "This is a page with some text on it.\n\n" )) - assert pHandle in theIndex._fileIndex - assert theIndex._fileIndex[pHandle]["T000000"]["level"] == "H0" - assert theIndex._fileIndex[pHandle]["T000000"]["title"] == "" - assert theIndex._fileIndex[pHandle]["T000000"]["layout"] == "NOTE" - assert theIndex._fileIndex[pHandle]["T000000"]["cCount"] == 36 - assert theIndex._fileIndex[pHandle]["T000000"]["wCount"] == 9 - assert theIndex._fileIndex[pHandle]["T000000"]["pCount"] == 1 - assert theIndex._fileIndex[pHandle]["T000000"]["synopsis"] == "" + assert theIndex._itemIndex[pHandle]["T000000"].references == {} + assert theIndex._itemIndex[pHandle]["T000000"].level == "H0" + assert theIndex._itemIndex[pHandle]["T000000"].title == "" + assert theIndex._itemIndex[pHandle]["T000000"].charCount == 36 + assert theIndex._itemIndex[pHandle]["T000000"].wordCount == 9 + assert theIndex._itemIndex[pHandle]["T000000"].paraCount == 1 + assert theIndex._itemIndex[pHandle]["T000000"].synopsis == "" assert theProject.closeProject() is True @@ -465,19 +470,27 @@ def testCoreIndex_ScanText(nwMinimal, mockGUI): @pytest.mark.core -def testCoreIndex_ExtractData(nwMinimal, mockGUI): +def testCoreIndex_ExtractData(mockGUI, fncDir, mockRnd): """Check the index data extraction functions. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) - assert theProject.openProject(nwMinimal) is True + buildTestProject(theProject, fncDir) - theIndex = NWIndex(theProject) - nHandle = theProject.newFile("Hello", nwItemClass.NOVEL, "a508bb932959c") - cHandle = theProject.newFile("Jane", nwItemClass.CHARACTER, "afb3043c7b2b3") + theIndex = theProject.index + theIndex.reIndexHandle("0000000000010") + theIndex.reIndexHandle("0000000000011") + theIndex.reIndexHandle("0000000000012") + theIndex.reIndexHandle("0000000000013") + theIndex.reIndexHandle("0000000000014") + theIndex.reIndexHandle("0000000000015") + theIndex.reIndexHandle("0000000000016") + theIndex.reIndexHandle("0000000000017") + + nHandle = theProject.newFile("Hello", "0000000000010") + cHandle = theProject.newFile("Jane", "0000000000012") assert theIndex.getNovelData("", "") is None - assert theIndex.getNovelData("a508bb932959c", "") is None + assert theIndex.getNovelData("0000000000010", "") is None assert theIndex.scanText(cHandle, ( "# Jane Smith\n" @@ -497,28 +510,36 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): for aKey, _, _, _ in theIndex.novelStructure(): theKeys.append(aKey) - assert theKeys == ["%s:T000001" % nHandle] + assert theKeys == [ + "0000000000014:T000001", + "0000000000016:T000001", + "0000000000017:T000001", + "%s:T000001" % nHandle, + ] # Check that excluded files can be skipped - theProject.projTree[nHandle].setExported(False) + theProject.tree[nHandle].setExported(False) theKeys = [] - for aKey, _, _, _ in theIndex.novelStructure(skipExcluded=False): + for aKey, _, _, _ in theIndex.novelStructure(skipExcl=False): theKeys.append(aKey) - assert theKeys == ["%s:T000001" % nHandle] + assert theKeys == [ + "0000000000014:T000001", + "0000000000016:T000001", + "0000000000017:T000001", + "%s:T000001" % nHandle, + ] theKeys = [] - for aKey, _, _, _ in theIndex.novelStructure(skipExcluded=True): + for aKey, _, _, _ in theIndex.novelStructure(skipExcl=True): theKeys.append(aKey) - assert theKeys == [] - - theKeys = [] - for aKey, _, _, _ in theIndex.novelStructure(): - theKeys.append(aKey) - - assert theKeys == [] + assert theKeys == [ + "0000000000014:T000001", + "0000000000016:T000001", + "0000000000017:T000001", + ] # The novel file should have the correct counts cC, wC, pC = theIndex.getCounts(nHandle) @@ -545,6 +566,9 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): # None handle should return an empty dict assert theIndex.getBackReferenceList(None) == {} + # The Title Page file should have no references as it has no tag + assert theIndex.getBackReferenceList("0000000000014") == {} + # The character file should have a record of the reference from the novel file theRefs = theIndex.getBackReferenceList(cHandle) assert theRefs == {nHandle: "T000001"} @@ -552,13 +576,17 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): # getTagSource # ============ - assert theIndex.getTagSource("Jane") == (cHandle, 2, "T000001") - assert theIndex.getTagSource("John") == (None, 0, "T000000") + assert theIndex.getTagSource("Jane") == (cHandle, "T000001") + assert theIndex.getTagSource("John") == (None, "T000000") # getCounts # ========= # For whole text and sections + # Invalid handle or title should return 0s + assert theIndex.getCounts("stuff") == (0, 0, 0) + assert theIndex.getCounts(nHandle, "stuff") == (0, 0, 0) + # Get section counts for a novel file assert theIndex.scanText(nHandle, ( "# Hello World!\n" @@ -628,46 +656,80 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): # Novel Stats # =========== - hHandle = theProject.newFile("Chapter", nwItemClass.NOVEL, "a508bb932959c") - sHandle = theProject.newFile("Scene One", nwItemClass.NOVEL, "a508bb932959c") - tHandle = theProject.newFile("Scene Two", nwItemClass.NOVEL, "a508bb932959c") + hHandle = theProject.newFile("Chapter", "0000000000010") + sHandle = theProject.newFile("Scene One", "0000000000010") + tHandle = theProject.newFile("Scene Two", "0000000000010") - theProject.projTree[hHandle].itemLayout == nwItemLayout.DOCUMENT - theProject.projTree[sHandle].itemLayout == nwItemLayout.DOCUMENT - theProject.projTree[tHandle].itemLayout == nwItemLayout.DOCUMENT + theProject.tree[hHandle].itemLayout == nwItemLayout.DOCUMENT + theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT + theProject.tree[tHandle].itemLayout == nwItemLayout.DOCUMENT assert theIndex.scanText(hHandle, "## Chapter One\n\n") assert theIndex.scanText(sHandle, "### Scene One\n\n") assert theIndex.scanText(tHandle, "### Scene Two\n\n") - assert theIndex._listNovelHandles(False) == [nHandle, hHandle, sHandle, tHandle] - assert theIndex._listNovelHandles(True) == [hHandle, sHandle, tHandle] + assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [ + ("0000000000014", "T000001"), + ("0000000000016", "T000001"), + ("0000000000017", "T000001"), + (nHandle, "T000001"), + (nHandle, "T000011"), + (hHandle, "T000001"), + (sHandle, "T000001"), + (tHandle, "T000001"), + ] + + assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=True)] == [ + ("0000000000014", "T000001"), + ("0000000000016", "T000001"), + ("0000000000017", "T000001"), + (hHandle, "T000001"), + (sHandle, "T000001"), + (tHandle, "T000001"), + ] # Add a fake handle to the tree and check that it's ignored - theProject.projTree._treeOrder.append("0000000000000") - assert theIndex._listNovelHandles(False) == [nHandle, hHandle, sHandle, tHandle] - theProject.projTree._treeOrder.remove("0000000000000") + theProject.tree._treeOrder.append("0000000000000") + assert [(h, t) for h, t, _ in theIndex._itemIndex.iterNovelStructure(skipExcl=False)] == [ + ("0000000000014", "T000001"), + ("0000000000016", "T000001"), + ("0000000000017", "T000001"), + (nHandle, "T000001"), + (nHandle, "T000011"), + (hHandle, "T000001"), + (sHandle, "T000001"), + (tHandle, "T000001"), + ] + theProject.tree._treeOrder.remove("0000000000000") # Extract stats - assert theIndex.getNovelWordCount(False) == 34 - assert theIndex.getNovelWordCount(True) == 6 - assert theIndex.getNovelTitleCounts(False) == [0, 2, 1, 2, 0] - assert theIndex.getNovelTitleCounts(True) == [0, 0, 1, 2, 0] + assert theIndex.getNovelWordCount(skipExcl=False) == 43 + assert theIndex.getNovelWordCount(skipExcl=True) == 15 + assert theIndex.getNovelTitleCounts(skipExcl=False) == [0, 3, 2, 3, 0] + assert theIndex.getNovelTitleCounts(skipExcl=True) == [0, 1, 2, 3, 0] # Table of Contents - assert theIndex.getTableOfContents(0, True) == [] - assert theIndex.getTableOfContents(1, True) == [] - assert theIndex.getTableOfContents(2, True) == [ + assert theIndex.getTableOfContents(0, skipExcl=True) == [] + assert theIndex.getTableOfContents(1, skipExcl=True) == [ + ("0000000000014:T000001", 1, "New Novel", 15), + ] + assert theIndex.getTableOfContents(2, skipExcl=True) == [ + ("0000000000014:T000001", 1, "New Novel", 5), + ("0000000000016:T000001", 2, "New Chapter", 4), ("%s:T000001" % hHandle, 2, "Chapter One", 6), ] - assert theIndex.getTableOfContents(3, True) == [ + assert theIndex.getTableOfContents(3, skipExcl=True) == [ + ("0000000000014:T000001", 1, "New Novel", 5), + ("0000000000016:T000001", 2, "New Chapter", 2), + ("0000000000017:T000001", 3, "New Scene", 2), ("%s:T000001" % hHandle, 2, "Chapter One", 2), ("%s:T000001" % sHandle, 3, "Scene One", 2), ("%s:T000001" % tHandle, 3, "Scene Two", 2), ] - assert theIndex.getTableOfContents(0, False) == [] - assert theIndex.getTableOfContents(1, False) == [ + assert theIndex.getTableOfContents(0, skipExcl=False) == [] + assert theIndex.getTableOfContents(1, skipExcl=False) == [ + ("0000000000014:T000001", 1, "New Novel", 9), ("%s:T000001" % nHandle, 1, "Hello World!", 12), ("%s:T000011" % nHandle, 1, "Hello World!", 22), ] @@ -682,7 +744,9 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): ("%s:T000001" % nHandle, 12), ("%s:T000011" % nHandle, 16) ] - assert theProject.closeProject() + assert theIndex.saveIndex() is True + assert theProject.saveProject() is True + assert theProject.closeProject() is True # Header Record bHandle = "0000000000000" @@ -698,535 +762,400 @@ def testCoreIndex_ExtractData(nwMinimal, mockGUI): @pytest.mark.core -def testCoreIndex_CheckTagIndex(mockGUI): - """Test the tag index checker. +def testCoreIndex_TagsIndex(): + """Check the TagsIndex class. """ - theProject = NWProject(mockGUI) - theIndex = NWIndex(theProject) + tagsIndex = TagsIndex() + assert tagsIndex._tags == {} - # Valid Index - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "T000001"], + # Expected data + content = { + "Tag1": { + "handle": "0000000000001", + "heading": "T000001", + "class": nwItemClass.NOVEL.name, + }, + "Tag2": { + "handle": "0000000000002", + "heading": "T000002", + "class": nwItemClass.CHARACTER.name, + }, + "Tag3": { + "handle": "0000000000003", + "heading": "T000003", + "class": nwItemClass.PLOT.name, + }, } - assert theIndex._checkTagIndex() is None - # Wrong Key Type - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - 123456: [3, "bb2c23b3c42cc", "CHARACTER", "T000001"], - } + # Add data + tagsIndex.add("Tag1", "0000000000001", "T000001", nwItemClass.NOVEL) + tagsIndex.add("Tag2", "0000000000002", "T000002", nwItemClass.CHARACTER) + tagsIndex.add("Tag3", "0000000000003", "T000003", nwItemClass.PLOT) + assert tagsIndex._tags == content + + # Get items + assert tagsIndex["Tag1"] == content["Tag1"] + assert tagsIndex["Tag2"] == content["Tag2"] + assert tagsIndex["Tag3"] == content["Tag3"] + assert tagsIndex["Tag4"] is None + + # Contains + assert "Tag1" in tagsIndex + assert "Tag2" in tagsIndex + assert "Tag3" in tagsIndex + assert "Tag4" not in tagsIndex + + # Read back handles + assert tagsIndex.tagHandle("Tag1") == "0000000000001" + assert tagsIndex.tagHandle("Tag2") == "0000000000002" + assert tagsIndex.tagHandle("Tag3") == "0000000000003" + assert tagsIndex.tagHandle("Tag4") is None + + # Read back headings + assert tagsIndex.tagHeading("Tag1") == "T000001" + assert tagsIndex.tagHeading("Tag2") == "T000002" + assert tagsIndex.tagHeading("Tag3") == "T000003" + assert tagsIndex.tagHeading("Tag4") == "T000000" + + # Read back classes + assert tagsIndex.tagClass("Tag1") == nwItemClass.NOVEL.name + assert tagsIndex.tagClass("Tag2") == nwItemClass.CHARACTER.name + assert tagsIndex.tagClass("Tag3") == nwItemClass.PLOT.name + assert tagsIndex.tagClass("Tag4") is None + + # Pack Data + assert tagsIndex.packData() == content + + # Delete the second key and a nomn-existant key + del tagsIndex["Tag2"] + del tagsIndex["Tag4"] + assert "Tag1" in tagsIndex + assert "Tag2" not in tagsIndex + assert "Tag3" in tagsIndex + assert "Tag4" not in tagsIndex + + # Clear and reload + tagsIndex.clear() + assert tagsIndex._tags == {} + assert tagsIndex.packData() == {} + + tagsIndex.unpackData(content) + assert tagsIndex._tags == content + assert tagsIndex.packData() == content + + # Unpack Errors + # ============= + tagsIndex.clear() + + # Invalid data type + with pytest.raises(ValueError): + tagsIndex.unpackData([]) + + # Invalid key + with pytest.raises(ValueError): + tagsIndex.unpackData({ + 1234: { + "handle": "0000000000001", + "heading": "T000001", + "class": "NOVEL", + } + }) + + # Missing handle with pytest.raises(KeyError): - theIndex._checkTagIndex() + tagsIndex.unpackData({ + "Tag1": { + "heading": "T000001", + "class": "NOVEL", + } + }) - # Wrong Length - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "T000001", "Stuff"], - } - with pytest.raises(IndexError): - theIndex._checkTagIndex() + # Missing heading + with pytest.raises(KeyError): + tagsIndex.unpackData({ + "Tag1": { + "handle": "0000000000001", + "class": "NOVEL", + } + }) - # Wrong Type of Entry 0 - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": ["3", "bb2c23b3c42cc", "CHARACTER", "T000001"], - } + # Missing class + with pytest.raises(KeyError): + tagsIndex.unpackData({ + "Tag1": { + "handle": "0000000000001", + "heading": "T000001", + } + }) + + # Invalid handle with pytest.raises(ValueError): - theIndex._checkTagIndex() + tagsIndex.unpackData({ + "Tag1": { + "handle": "blablabla", + "heading": "T000001", + "class": "NOVEL", + } + }) - # Wrong Type of Entry 1 - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": [3, 0xbb2c23b3c42cc, "CHARACTER", "T000001"], - } + # Invalid heading with pytest.raises(ValueError): - theIndex._checkTagIndex() + tagsIndex.unpackData({ + "Tag1": { + "handle": "0000000000001", + "heading": "blabla", + "class": "NOVEL", + } + }) - # Wrong Type of Entry 2 - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": [3, "bb2c23b3c42cc", "INVALID_CLASS", "T000001"], - } + # Invalid class with pytest.raises(ValueError): - theIndex._checkTagIndex() + tagsIndex.unpackData({ + "Tag1": { + "handle": "0000000000001", + "heading": "T000001", + "class": "blabla", + } + }) - # Wrong Type of Entry 3 - theIndex._tagIndex = { - "John": [3, "14298de4d9524", "CHARACTER", "T000001"], - "Jane": [3, "bb2c23b3c42cc", "CHARACTER", "INVALID"], - } - with pytest.raises(ValueError): - theIndex._checkTagIndex() - -# END Test testCoreIndex_CheckTagIndex +# END Test testCoreIndex_TagsIndex @pytest.mark.core -def testCoreIndex_CheckRefIndex(mockGUI): - """Test the reference index checker. +def testCoreIndex_ItemIndex(mockGUI, fncDir, mockRnd): + """Check the ItemIndex class. """ theProject = NWProject(mockGUI) - theIndex = NWIndex(theProject) + buildTestProject(theProject, fncDir) - # Valid Index - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth"]], - } - } - assert theIndex._checkRefIndex() is None + nHandle = "0000000000014" + cHandle = "0000000000016" + sHandle = "0000000000017" - # Invalid Handle - theIndex._refIndex = { - "Ha2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth"]], - } - } - with pytest.raises(KeyError): - theIndex._checkRefIndex() + assert theProject.index.saveIndex() is True + itemIndex = theProject.index._itemIndex - # Invalid Title - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "INVALID": [[3, "@pov", "Jane"], [4, "@location", "Earth"]], - } - } - with pytest.raises(KeyError): - theIndex._checkRefIndex() + # The index should be empty + assert nHandle not in itemIndex + assert cHandle not in itemIndex + assert sHandle not in itemIndex - # Wrong Length - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], [4, "@location", "Earth", "Stuff"]], - } - } - with pytest.raises(IndexError): - theIndex._checkRefIndex() + # Add Items + # ========= + assert cHandle not in itemIndex - # Wrong Type of Entry 0 - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], ["4", "@location", "Earth"]], - } + # Add the novel chapter file + itemIndex.add(cHandle, theProject.tree[cHandle]) + assert cHandle in itemIndex + assert itemIndex[cHandle].item == theProject.tree[cHandle] + assert itemIndex.mainItemHeader(cHandle) == "H0" + assert itemIndex.allItemTags(cHandle) == [] + assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000000" + + # Add a heading to the item, which should replace the T000000 heading + itemIndex.addItemHeading(cHandle, "T000001", "H2", "Chapter One") + assert itemIndex.mainItemHeader(cHandle) == "H2" + assert list(itemIndex.iterItemHeaders(cHandle))[0][0] == "T000001" + + # Set the remainig data values + itemIndex.setHeadingCounts(cHandle, "T000001", 60, 10, 2) + itemIndex.setHeadingSynopsis(cHandle, "T000001", "In the beginning ...") + itemIndex.setHeadingTag(cHandle, "T000001", "One") + itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane"], "@pov") + itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane"], "@focus") + itemIndex.addHeadingReferences(cHandle, "T000001", ["Jane", "John"], "@char") + idxData = itemIndex.packData() + + assert idxData[cHandle]["level"] == "H2" + assert idxData[cHandle]["headings"]["T000001"] == { + "level": "H2", "title": "Chapter One", "tag": "One", + "cCount": 60, "wCount": 10, "pCount": 2, "synopsis": "In the beginning ...", } + assert "@pov" in idxData[cHandle]["references"]["T000001"]["Jane"] + assert "@focus" in idxData[cHandle]["references"]["T000001"]["Jane"] + assert "@char" in idxData[cHandle]["references"]["T000001"]["Jane"] + assert "@char" in idxData[cHandle]["references"]["T000001"]["John"] + + # Add the other two files + itemIndex.add(nHandle, theProject.tree[nHandle]) + itemIndex.add(sHandle, theProject.tree[sHandle]) + itemIndex.addItemHeading(nHandle, "T000001", "H1", "Novel") + itemIndex.addItemHeading(sHandle, "T000001", "H3", "Scene One") + + # Check Item and Heading Direct Access + # ==================================== + + # Check repr strings + assert repr(itemIndex[nHandle]) == f"" + assert repr(itemIndex[nHandle]["T000001"]) == "" + + # Check content of a single item + assert "T000001" in itemIndex[nHandle] + assert itemIndex[cHandle].allTags() == ["One"] + + # Check the content of a single heading + assert itemIndex[cHandle]["T000001"].key == "T000001" + assert itemIndex[cHandle]["T000001"].level == "H2" + assert itemIndex[cHandle]["T000001"].title == "Chapter One" + assert itemIndex[cHandle]["T000001"].tag == "One" + assert itemIndex[cHandle]["T000001"].charCount == 60 + assert itemIndex[cHandle]["T000001"].wordCount == 10 + assert itemIndex[cHandle]["T000001"].paraCount == 2 + assert itemIndex[cHandle]["T000001"].synopsis == "In the beginning ..." + assert "Jane" in itemIndex[cHandle]["T000001"].references + assert "John" in itemIndex[cHandle]["T000001"].references + + # Check heading level setter + itemIndex[cHandle]["T000001"].setLevel("H3") # Change it + assert itemIndex[cHandle]["T000001"].level == "H3" + itemIndex[cHandle]["T000001"].setLevel("H2") # Set it back + assert itemIndex[cHandle]["T000001"].level == "H2" + itemIndex[cHandle]["T000001"].setLevel("H5") # Invalid level + assert itemIndex[cHandle]["T000001"].level == "H2" + + # Data Extraction + # =============== + + # Get headers + allHeads = list(itemIndex.iterAllHeaders()) + assert allHeads[0][0] == cHandle + assert allHeads[1][0] == nHandle + assert allHeads[2][0] == sHandle + assert allHeads[0][1] == "T000001" + assert allHeads[1][1] == "T000001" + assert allHeads[2][1] == "T000001" + + # Ask for stuff that doesn't exist + assert itemIndex.mainItemHeader("blablabla") == "H0" + assert itemIndex.allItemTags("blablabla") == [] + + # Novel Structure + # =============== + + # Add a second novel + mHandle = theProject.newRoot(nwItemClass.NOVEL) + uHandle = theProject.newFile("Title Page", mHandle) + itemIndex.add(uHandle, theProject.tree[uHandle]) + itemIndex.addItemHeading(uHandle, "T000001", "H1", "Novel 2") + assert uHandle in itemIndex + + # Structure of all novels + nStruct = list(itemIndex.iterNovelStructure()) + assert len(nStruct) == 4 + assert nStruct[0][0] == nHandle + assert nStruct[1][0] == cHandle + assert nStruct[2][0] == sHandle + assert nStruct[3][0] == uHandle + + # Novel structure with root handle set + nStruct = list(itemIndex.iterNovelStructure(rootHandle="0000000000010")) + assert len(nStruct) == 3 + assert nStruct[0][0] == nHandle + assert nStruct[1][0] == cHandle + assert nStruct[2][0] == sHandle + + nStruct = list(itemIndex.iterNovelStructure(rootHandle=mHandle)) + assert len(nStruct) == 1 + assert nStruct[0][0] == uHandle + + # Inject garbage into tree + theProject.tree._treeOrder.append("stuff") + nStruct = list(itemIndex.iterNovelStructure()) + assert len(nStruct) == 4 + assert nStruct[0][0] == nHandle + assert nStruct[1][0] == cHandle + assert nStruct[2][0] == sHandle + assert nStruct[3][0] == uHandle + + # Skip excluded + theProject.tree[sHandle].setExported(False) + nStruct = list(itemIndex.iterNovelStructure(skipExcl=True)) + assert len(nStruct) == 3 + assert nStruct[0][0] == nHandle + assert nStruct[1][0] == cHandle + assert nStruct[2][0] == uHandle + + # Delete new item + del itemIndex[uHandle] + assert uHandle not in itemIndex + + # Unpack Error Handling + # ===================== + + # Pack/unpack should restore state + content = itemIndex.packData() + itemIndex.clear() + itemIndex.unpackData(content) + assert itemIndex.packData() == content + itemIndex.clear() + + # Data must be dictionary with pytest.raises(ValueError): - theIndex._checkRefIndex() + itemIndex.unpackData("stuff") - # Wrong Type of Entry 1 - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], [4, "@stuff", "Earth"]], - } - } + # Keys must be valid handles with pytest.raises(ValueError): - theIndex._checkRefIndex() + itemIndex.unpackData({"stuff": "more stuff"}) - # Wrong Type of Entry 2 - theIndex._refIndex = { - "6a2d6d5f4f401": { - "T000000": [], - "T000001": [[3, "@pov", "Jane"], [4, "@location", 123456]], - } - } + # Unknown keys should be skipped + itemIndex.unpackData({"0000000000000": {}}) + assert itemIndex._items == {} + + # Known keys can be added, even witout data + itemIndex.unpackData({nHandle: {}}) + assert nHandle in itemIndex + + # Title tags must be valid with pytest.raises(ValueError): - theIndex._checkRefIndex() + itemIndex.unpackData({cHandle: {"headings": {"TTTTTTT": {}}}}) -# END Test testCoreIndex_CheckRefIndex - - -@pytest.mark.core -def testCoreIndex_CheckFileIndex(mockGUI): - """Test the file index checker. - """ - theProject = NWProject(mockGUI) - theIndex = NWIndex(theProject) - - # Valid Index - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } + # Reference without a heading should be rejected + itemIndex.unpackData({ + cHandle: { + "headings": {"T000001": {}}, + "references": {"T000001": {}, "T000002": {}}, } - } - theIndex._fileIndex = theIndex._fileIndex.copy() - assert theIndex._checkFileIndex() is None + }) + assert "T000001" in itemIndex[cHandle] + assert "T000002" not in itemIndex[cHandle] + itemIndex.clear() - # Invalid Handle - theIndex._fileIndex = { - "H3b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Invalid Title - theIndex._fileIndex = { - "53b69b83cdafc": { - "INVALID": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Wrong Length - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - "stuff": None - } - } - } - with pytest.raises(IndexError): - theIndex._checkFileIndex() - - # Missing Keys - # ============ - - # Missing 'level' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "stuff": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'title' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "stuff": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'layout' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "stuff": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'cCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "stuff": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'wCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "stuff": 15, - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'pCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "stuff": 2, - "synopsis": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Missing 'synopsis' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "stuff": "text", - } - } - } - with pytest.raises(KeyError): - theIndex._checkFileIndex() - - # Wrong Types - # =========== - - # Wrong Type for 'level' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "XX", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", - } - } - } + # Tag keys must be strings with pytest.raises(ValueError): - theIndex._checkFileIndex() - - # Wrong Type for 'title' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": 12345678, - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", + itemIndex.unpackData({ + cHandle: { + "headings": {"T000001": {}}, + "references": {"T000001": {1234: "@pov"}}, } - } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() + }) - # Wrong Type for 'layout' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "INVALID", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": "text", + # Type must be strings + with pytest.raises(ValueError): + itemIndex.unpackData({ + cHandle: { + "headings": {"T000001": {}}, + "references": {"T000001": {"John": []}}, } - } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() + }) - # Wrong Type for 'cCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": "72", - "wCount": 15, - "pCount": 2, - "synopsis": "text", + # Types must be valid + with pytest.raises(ValueError): + itemIndex.unpackData({ + cHandle: { + "headings": {"T000001": {}}, + "references": {"T000001": {"John": "@pov,@char,@stuff"}}, } + }) + + # This should pass + itemIndex.unpackData({ + cHandle: { + "headings": {"T000001": {}}, + "references": {"T000001": {"John": "@pov,@char"}}, } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() + }) - # Wrong Type for 'wCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": "15", - "pCount": 2, - "synopsis": "text", - } - } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() - - # Wrong Type for 'pCount' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": "2", - "synopsis": "text", - } - } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() - - # Wrong Type for 'synopsis' - theIndex._fileIndex = { - "53b69b83cdafc": { - "T000001": { - "level": "H1", - "title": "My Novel", - "layout": "DOCUMENT", - "cCount": 72, - "wCount": 15, - "pCount": 2, - "synopsis": 123456, - } - } - } - with pytest.raises(ValueError): - theIndex._checkFileIndex() - -# END Test testCoreIndex_CheckFileIndex - - -@pytest.mark.core -def testCoreIndex_CheckFileMeta(mockGUI): - """Test the file meta checker. - """ - theProject = NWProject(mockGUI) - theIndex = NWIndex(theProject) - - # Valid Index - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["H0", 210, 40, 2], - } - assert theIndex._checkFileMeta() is None - - # Invalid Handle - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "h74e400180a99": ["H0", 210, 40, 2], - } - with pytest.raises(KeyError): - theIndex._checkFileMeta() - - # Wrong Length - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["H0", 210, 40, 2, 8], - } - with pytest.raises(IndexError): - theIndex._checkFileMeta() - - # Content of Entry 0 - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["XXX", 210, 40, 2], - } - with pytest.raises(ValueError): - theIndex._checkFileMeta() - - # Type of Entry 1 - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["H0", "210", 40, 2], - } - with pytest.raises(ValueError): - theIndex._checkFileMeta() - - # Type of Entry 2 - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["H0", 210, "40", 2], - } - with pytest.raises(ValueError): - theIndex._checkFileMeta() - - # Type of Entry 3 - theIndex._fileMeta = { - "53b69b83cdafc": ["H0", 72, 15, 2], - "974e400180a99": ["H0", 210, 40, "2"], - } - with pytest.raises(ValueError): - theIndex._checkFileMeta() - -# END Test testCoreIndex_CheckTextCounts +# END Test testCoreIndex_ItemIndex @pytest.mark.core diff --git a/tests/test_core/test_core_item.py b/tests/test_core/test_core_item.py index dea2b3c7..e2fa75e0 100644 --- a/tests/test_core/test_core_item.py +++ b/tests/test_core/test_core_item.py @@ -23,23 +23,30 @@ import pytest from lxml import etree +from PyQt5.QtGui import QIcon + from novelwriter.core import NWProject from novelwriter.core.item import NWItem from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout @pytest.mark.core -def testCoreItem_Setters(mockGUI): +def testCoreItem_Setters(mockGUI, mockRnd): """Test all the simple setters for the NWItem class. """ theProject = NWProject(mockGUI) theItem = NWItem(theProject) + statusKeys = ["s000000", "s000001", "s000002", "s000003"] + importKeys = ["i000004", "i000005", "i000006", "i000007"] + # Name theItem.setName("A Name") assert theItem.itemName == "A Name" theItem.setName("\t A Name ") assert theItem.itemName == "A Name" + theItem.setName("\t A\t\u2009\u202f\u2002\u2003\u2028\u2029Name ") + assert theItem.itemName == "A Name" theItem.setName(123) assert theItem.itemName == "" @@ -65,6 +72,18 @@ def testCoreItem_Setters(mockGUI): theItem.setParent("0123456789abc") assert theItem.itemParent == "0123456789abc" + # Root + theItem.setRoot(None) + assert theItem.itemRoot is None + theItem.setRoot(123) + assert theItem.itemRoot is None + theItem.setRoot("0123456789abcdef") + assert theItem.itemRoot is None + theItem.setRoot("0123456789abg") + assert theItem.itemRoot is None + theItem.setRoot("0123456789abc") + assert theItem.itemRoot == "0123456789abc" + # Order theItem.setOrder(None) assert theItem.itemOrder == 0 @@ -74,29 +93,33 @@ def testCoreItem_Setters(mockGUI): assert theItem.itemOrder == 1 # Importance - theItem.setStatus("Nonsense") - assert theItem.itemStatus == "New" - theItem.setStatus("New") - assert theItem.itemStatus == "New" - theItem.setStatus("Minor") - assert theItem.itemStatus == "Minor" - theItem.setStatus("Major") - assert theItem.itemStatus == "Major" - theItem.setStatus("Main") - assert theItem.itemStatus == "Main" + theItem._class = nwItemClass.CHARACTER + theItem.setImport("Word") + assert theItem.itemImport == importKeys[0] # Default + for key in importKeys: + theItem.setImport(key) + assert theItem.itemImport == key # Status theItem._class = nwItemClass.NOVEL - theItem.setStatus("Nonsense") - assert theItem.itemStatus == "New" - theItem.setStatus("New") - assert theItem.itemStatus == "New" - theItem.setStatus("Note") - assert theItem.itemStatus == "Note" - theItem.setStatus("Draft") - assert theItem.itemStatus == "Draft" - theItem.setStatus("Finished") - assert theItem.itemStatus == "Finished" + theItem.setStatus("Word") + assert theItem.itemStatus == statusKeys[0] # Default + for key in statusKeys: + theItem.setStatus(key) + assert theItem.itemStatus == key + + # Status/Importance Wrapper + theItem._class = nwItemClass.CHARACTER + for key in importKeys: + theItem.setImport(key) + assert theItem.itemImport == key + assert theItem.itemStatus == statusKeys[3] # Should not change + + theItem._class = nwItemClass.NOVEL + for key in statusKeys: + theItem.setStatus(key) + assert theItem.itemImport == importKeys[3] # Should not change + assert theItem.itemStatus == key # Expanded theItem.setExpanded(8) @@ -180,12 +203,16 @@ def testCoreItem_Methods(mockGUI): theItem.setType("ROOT") assert theItem.describeMe() == "Root Folder" + assert theItem.isRootType() is True theItem.setType("FOLDER") assert theItem.describeMe() == "Folder" + assert theItem.isFolderType() is True theItem.setType("FILE") theItem.setLayout("DOCUMENT") + assert theItem.isFileType() is True + assert theItem.isDocumentLayout() is True assert theItem.describeMe() == "Novel Document" assert theItem.describeMe("H0") == "Novel Document" assert theItem.describeMe("H1") == "Novel Title Page" @@ -194,8 +221,34 @@ def testCoreItem_Methods(mockGUI): assert theItem.describeMe("H4") == "Novel Document" theItem.setLayout("NOTE") + assert theItem.isNoteLayout() is True assert theItem.describeMe() == "Project Note" + # Status + Icon + # ============= + + theItem.setType("FILE") + theItem.setStatus("Note") + theItem.setImport("Minor") + + theItem.setClass("NOVEL") + stT, stI = theItem.getImportStatus() + assert stT == "Note" + assert isinstance(stI, QIcon) + + theItem.setImportStatus("Draft") + stT, stI = theItem.getImportStatus() + assert stT == "Draft" + + theItem.setClass("CHARACTER") + stT, stI = theItem.getImportStatus() + assert stT == "Minor" + assert isinstance(stI, QIcon) + + theItem.setImportStatus("Major") + stT, stI = theItem.getImportStatus() + assert stT == "Major" + # Representation # ============== @@ -235,8 +288,8 @@ def testCoreItem_TypeSetter(mockGUI): assert theItem.itemType == nwItemType.FOLDER theItem.setType("FILE") assert theItem.itemType == nwItemType.FILE - theItem.setType("TRASH") - assert theItem.itemType == nwItemType.TRASH + + # Alternative theItem.setType(nwItemType.ROOT) assert theItem.itemType == nwItemType.ROOT @@ -256,28 +309,74 @@ def testCoreItem_ClassSetter(mockGUI): assert theItem.itemClass == nwItemClass.NO_CLASS theItem.setClass("NONSENSE") assert theItem.itemClass == nwItemClass.NO_CLASS + theItem.setClass("NO_CLASS") assert theItem.itemClass == nwItemClass.NO_CLASS + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is True + theItem.setClass("NOVEL") assert theItem.itemClass == nwItemClass.NOVEL + assert theItem.isNovelLike() is True + assert theItem.documentAllowed() is True + assert theItem.isInactive() is False + theItem.setClass("PLOT") assert theItem.itemClass == nwItemClass.PLOT + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("CHARACTER") assert theItem.itemClass == nwItemClass.CHARACTER + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("WORLD") assert theItem.itemClass == nwItemClass.WORLD + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("TIMELINE") assert theItem.itemClass == nwItemClass.TIMELINE + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("OBJECT") assert theItem.itemClass == nwItemClass.OBJECT + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("ENTITY") assert theItem.itemClass == nwItemClass.ENTITY + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("CUSTOM") assert theItem.itemClass == nwItemClass.CUSTOM + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is False + assert theItem.isInactive() is False + theItem.setClass("ARCHIVE") assert theItem.itemClass == nwItemClass.ARCHIVE + assert theItem.isNovelLike() is True + assert theItem.documentAllowed() is True + assert theItem.isInactive() is True + theItem.setClass("TRASH") assert theItem.itemClass == nwItemClass.TRASH + assert theItem.isNovelLike() is False + assert theItem.documentAllowed() is True + assert theItem.isInactive() is True + + # Alternative theItem.setClass(nwItemClass.NOVEL) assert theItem.itemClass == nwItemClass.NOVEL @@ -306,23 +405,7 @@ def testCoreItem_LayoutSetter(mockGUI): theItem.setLayout("NOTE") assert theItem.itemLayout == nwItemLayout.NOTE - # Deprecated Layouts - theItem.setLayout("TITLE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("PAGE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("BOOK") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("PARTITION") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("UNNUMBERED") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("CHAPTER") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - theItem.setLayout("SCENE") - assert theItem.itemLayout == nwItemLayout.DOCUMENT - - # Alternatives + # Alternative theItem.setLayout(nwItemLayout.NOTE) assert theItem.itemLayout == nwItemLayout.NOTE @@ -330,23 +413,83 @@ def testCoreItem_LayoutSetter(mockGUI): @pytest.mark.core -def testCoreItem_XMLPackUnpack(mockGUI, caplog): +def testCoreItem_ClassDefaults(mockGUI): + """Test the setter for the default values. + """ + theProject = NWProject(mockGUI) + theItem = NWItem(theProject) + + # Root items should not have their class updated + theItem.setParent(None) + theItem.setClass(nwItemClass.NO_CLASS) + assert theItem.itemClass == nwItemClass.NO_CLASS + + theItem.setClassDefaults(nwItemClass.NOVEL) + assert theItem.itemClass == nwItemClass.NO_CLASS + + # Non-root items should have their class updated + theItem.setParent("0123456789abc") + theItem.setClass(nwItemClass.NO_CLASS) + assert theItem.itemClass == nwItemClass.NO_CLASS + + theItem.setClassDefaults(nwItemClass.NOVEL) + assert theItem.itemClass == nwItemClass.NOVEL + + # Non-layout items should have their layout set based on class + theItem.setParent("0123456789abc") + theItem.setClass(nwItemClass.NO_CLASS) + theItem.setLayout(nwItemLayout.NO_LAYOUT) + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + + theItem.setClassDefaults(nwItemClass.NOVEL) + assert theItem.itemLayout == nwItemLayout.DOCUMENT + + theItem.setParent("0123456789abc") + theItem.setClass(nwItemClass.NO_CLASS) + theItem.setLayout(nwItemLayout.NO_LAYOUT) + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + + theItem.setClassDefaults(nwItemClass.PLOT) + assert theItem.itemLayout == nwItemLayout.NOTE + + # If documents are not allowed in that class, the layout should be changed + theItem.setParent("0123456789abc") + theItem.setClass(nwItemClass.NO_CLASS) + theItem.setLayout(nwItemLayout.DOCUMENT) + assert theItem.itemLayout == nwItemLayout.DOCUMENT + + theItem.setClassDefaults(nwItemClass.PLOT) + assert theItem.itemLayout == nwItemLayout.NOTE + + # In all cases, status and importance should no longer be None + assert theItem.itemStatus is not None + assert theItem.itemImport is not None + +# END Test testCoreItem_ClassDefaults + + +@pytest.mark.core +def testCoreItem_XMLPackUnpack(mockGUI, caplog, mockRnd): """Test packing and unpacking XML objects for the NWItem class. """ theProject = NWProject(mockGUI) nwXML = etree.Element("novelWriterXML") + statusKeys = ["s000000", "s000001", "s000002", "s000003"] + importKeys = ["i000004", "i000005", "i000006", "i000007"] + # File # ==== theItem = NWItem(theProject) theItem.setHandle("0123456789abc") theItem.setParent("0123456789abc") + theItem.setRoot("0123456789abc") theItem.setOrder(1) theItem.setName("A Name") theItem.setClass("NOVEL") theItem.setType("FILE") - theItem.setStatus("Main") + theItem.setImport(importKeys[3]) theItem.setLayout("NOTE") theItem.setExported(False) theItem.setParaCount(3) @@ -358,19 +501,20 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): xContent = etree.SubElement(nwXML, "content") theItem.packXML(xContent) assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"A NameFILENOVELNew" - b"FalseNOTE7" - b"5311" - b"" - ) + b'' + b'A Name' + b'' + ) % bytes(importKeys[3], encoding="utf8") # Unpack theItem = NWItem(theProject) assert theItem.unpackXML(xContent[0]) assert theItem.itemHandle == "0123456789abc" assert theItem.itemParent == "0123456789abc" + assert theItem.itemRoot == "0123456789abc" assert theItem.itemOrder == 1 assert theItem.isExported is False assert theItem.paraCount == 3 @@ -380,6 +524,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): assert theItem.itemClass == nwItemClass.NOVEL assert theItem.itemType == nwItemType.FILE assert theItem.itemLayout == nwItemLayout.NOTE + assert theItem.itemStatus == statusKeys[0] # Was None, should now be default + assert theItem.itemImport == importKeys[3] # Folder # ====== @@ -387,11 +533,12 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): theItem = NWItem(theProject) theItem.setHandle("0123456789abc") theItem.setParent("0123456789abc") + theItem.setRoot("0123456789abc") theItem.setOrder(1) theItem.setName("A Name") theItem.setClass("NOVEL") theItem.setType("FOLDER") - theItem.setStatus("Main") + theItem.setStatus(statusKeys[1]) theItem.setLayout("NOTE") theItem.setExpanded(True) theItem.setExported(False) @@ -404,18 +551,19 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): xContent = etree.SubElement(nwXML, "content") theItem.packXML(xContent) assert etree.tostring(xContent, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"A NameFOLDERNOVELNew" - b"True" - b"" - ) + b'' + b'A Name' + b'' + ) % bytes(statusKeys[1], encoding="utf8") # Unpack theItem = NWItem(theProject) assert theItem.unpackXML(xContent[0]) assert theItem.itemHandle == "0123456789abc" assert theItem.itemParent == "0123456789abc" + assert theItem.itemRoot == "0123456789abc" assert theItem.itemOrder == 1 assert theItem.isExpanded is True assert theItem.isExported is True @@ -426,6 +574,8 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): assert theItem.itemClass == nwItemClass.NOVEL assert theItem.itemType == nwItemType.FOLDER assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + assert theItem.itemStatus == statusKeys[1] + assert theItem.itemImport == importKeys[0] # Was None, should now be default # Errors # ====== @@ -462,3 +612,111 @@ def testCoreItem_XMLPackUnpack(mockGUI, caplog): ) # END Test testCoreItem_XMLPackUnpack + + +@pytest.mark.core +def testCoreItem_ConvertFromFmt12(mockGUI): + """Test the setter for all the nwItemLayout values for the NWItem + class using the class names that were present in file format 1.2. + """ + theProject = NWProject(mockGUI) + theItem = NWItem(theProject) + + # Deprecated Layouts + theItem.setLayout("TITLE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("PAGE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("BOOK") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("PARTITION") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("UNNUMBERED") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("CHAPTER") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("SCENE") + assert theItem.itemLayout == nwItemLayout.DOCUMENT + theItem.setLayout("MUMBOJUMBO") + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + +# END Test testCoreItem_ConvertFromFmt12 + + +@pytest.mark.core +def testCoreItem_ConvertFromFmt13(mockGUI): + """Test packing and unpacking XML objects for the NWItem class from + format version 1.3 + """ + theProject = NWProject(mockGUI) + + # Make Version 1.3 XML + nwXML = etree.Element("novelWriterXML") + xContent = etree.SubElement(nwXML, "content") + + # Folder + xPack = etree.SubElement(xContent, "item", attrib={ + "handle": "a000000000001", + "order": "1", + "parent": "b000000000001", + }) + NWItem._subPack(xPack, "name", text="Folder") + NWItem._subPack(xPack, "type", text="FOLDER") + NWItem._subPack(xPack, "class", text="NOVEL") + NWItem._subPack(xPack, "status", text="New") + NWItem._subPack(xPack, "expanded", text="True") + + # Unpack Folder + theItem = NWItem(theProject) + theItem.unpackXML(xContent[0]) + assert theItem.itemHandle == "a000000000001" + assert theItem.itemParent == "b000000000001" + assert theItem.itemOrder == 1 + assert theItem.isExpanded is True + assert theItem.isExported is True + assert theItem.charCount == 0 + assert theItem.wordCount == 0 + assert theItem.paraCount == 0 + assert theItem.cursorPos == 0 + assert theItem.itemClass == nwItemClass.NOVEL + assert theItem.itemType == nwItemType.FOLDER + assert theItem.itemLayout == nwItemLayout.NO_LAYOUT + + # File + xPack = etree.SubElement(xContent, "item", attrib={ + "handle": "c000000000001", + "order": "2", + "parent": "a000000000001", + }) + NWItem._subPack(xPack, "name", text="Scene") + NWItem._subPack(xPack, "type", text="FILE") + NWItem._subPack(xPack, "class", text="NOVEL") + NWItem._subPack(xPack, "status", text="New") + NWItem._subPack(xPack, "exported", text="True") + NWItem._subPack(xPack, "layout", text="DOCUMENT") + NWItem._subPack(xPack, "charCount", text="600") + NWItem._subPack(xPack, "wordCount", text="100") + NWItem._subPack(xPack, "paraCount", text="6") + NWItem._subPack(xPack, "cursorPos", text="50") + + # Unpack File + theItem = NWItem(theProject) + theItem.unpackXML(xContent[1]) + assert theItem.itemHandle == "c000000000001" + assert theItem.itemParent == "a000000000001" + assert theItem.itemOrder == 2 + assert theItem.isExpanded is False + assert theItem.isExported is True + assert theItem.charCount == 600 + assert theItem.wordCount == 100 + assert theItem.paraCount == 6 + assert theItem.cursorPos == 50 + assert theItem.itemClass == nwItemClass.NOVEL + assert theItem.itemType == nwItemType.FILE + assert theItem.itemLayout == nwItemLayout.DOCUMENT + + # Deprecated Type + theItem.setType("TRASH") + assert theItem.itemType == nwItemType.ROOT + +# END Test testCoreItem_ConvertFromFmt13 diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 7ae461eb..3be812e1 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -19,24 +19,28 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest from shutil import copyfile from zipfile import ZipFile from lxml import etree -from tools import cmpFiles, writeFile, readFile +from tools import cmpFiles, writeFile, readFile, buildTestProject, XML_IGNORE from mock import causeOSError -from novelwriter.core.project import NWProject from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout from novelwriter.common import formatTimeStamp from novelwriter.constants import nwFiles +from novelwriter.core.tree import NWTree +from novelwriter.core.index import NWIndex +from novelwriter.core.project import NWProject +from novelwriter.core.options import OptionState +from novelwriter.core.document import NWDoc @pytest.mark.core -def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): +def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI, mockRnd): """Create a new project from a project wizard dictionary. With default setting, creating a Minimal project. """ @@ -45,7 +49,6 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): compFile = os.path.join(refDir, "coreProject_NewMinimal_nwProject.nwx") theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) # Setting no data should fail assert theProject.newProject({}) is False @@ -61,10 +64,6 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): # Creating the project once more should fail assert theProject.newProject({"projPath": fncDir}) is False - # Check the new project - copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) - # Open again assert theProject.openProject(projFile) is True @@ -72,7 +71,7 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) assert theProject.projChanged is False # Open a second time @@ -82,13 +81,13 @@ def testCoreProject_NewMinimal(fncDir, outDir, refDir, mockGUI): assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) # END Test testCoreProject_NewMinimal @pytest.mark.core -def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI): +def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI, mockRnd): """Create a new project from a project wizard dictionary. Custom type with chapters and scenes. """ @@ -108,29 +107,25 @@ def testCoreProject_NewCustomA(fncDir, outDir, refDir, mockGUI): nwItemClass.PLOT, nwItemClass.CHARACTER, nwItemClass.WORLD, - nwItemClass.TIMELINE, - nwItemClass.OBJECT, - nwItemClass.ENTITY, ], + "addNotes": True, "numChapters": 3, "numScenes": 3, - "chFolders": True, } theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) assert theProject.newProject(projData) is True assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) # END Test testCoreProject_NewCustomA @pytest.mark.core -def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI): +def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI, mockRnd): """Create a new project from a project wizard dictionary. Custom type without chapters, but with scenes. """ @@ -150,23 +145,19 @@ def testCoreProject_NewCustomB(fncDir, outDir, refDir, mockGUI): nwItemClass.PLOT, nwItemClass.CHARACTER, nwItemClass.WORLD, - nwItemClass.TIMELINE, - nwItemClass.OBJECT, - nwItemClass.ENTITY, ], + "addNotes": True, "numChapters": 0, "numScenes": 6, - "chFolders": True, } theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) assert theProject.newProject(projData) is True assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) # END Test testCoreProject_NewCustomB @@ -186,7 +177,6 @@ def testCoreProject_NewSampleA(fncDir, tmpConf, mockGUI, tmpDir): "popCustom": False, } theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) # Sample set, but no path assert not theProject.newProject({"popSample": True}) @@ -235,7 +225,6 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir): "popCustom": False, } theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) # Make sure we do not pick up the novelwriter/assets/sample.zip file tmpConf.assetPath = tmpDir @@ -259,7 +248,7 @@ def testCoreProject_NewSampleB(monkeypatch, fncDir, tmpConf, mockGUI, tmpDir): @pytest.mark.core -def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI): +def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI, mockRnd): """Check that new root folders can be added to the project. """ projFile = os.path.join(fncDir, "nwProject.nwx") @@ -267,62 +256,84 @@ def testCoreProject_NewRoot(fncDir, outDir, refDir, mockGUI): compFile = os.path.join(refDir, "coreProject_NewRoot_nwProject.nwx") theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) + buildTestProject(theProject, fncDir) - assert theProject.newProject({"projPath": fncDir}) is True assert theProject.setProjectPath(fncDir) is True assert theProject.saveProject() is True assert theProject.closeProject() is True assert theProject.openProject(projFile) is True - assert isinstance(theProject.newRoot("Novel", nwItemClass.NOVEL), type(None)) - assert isinstance(theProject.newRoot("Plot", nwItemClass.PLOT), type(None)) - assert isinstance(theProject.newRoot("Character", nwItemClass.CHARACTER), type(None)) - assert isinstance(theProject.newRoot("World", nwItemClass.WORLD), type(None)) - assert isinstance(theProject.newRoot("Timeline", nwItemClass.TIMELINE), str) - assert isinstance(theProject.newRoot("Object", nwItemClass.OBJECT), str) - assert isinstance(theProject.newRoot("Custom1", nwItemClass.CUSTOM), str) - assert isinstance(theProject.newRoot("Custom2", nwItemClass.CUSTOM), str) + assert isinstance(theProject.newRoot(nwItemClass.NOVEL), str) + assert isinstance(theProject.newRoot(nwItemClass.PLOT), str) + assert isinstance(theProject.newRoot(nwItemClass.CHARACTER), str) + assert isinstance(theProject.newRoot(nwItemClass.WORLD), str) + assert isinstance(theProject.newRoot(nwItemClass.TIMELINE), str) + assert isinstance(theProject.newRoot(nwItemClass.OBJECT), str) + assert isinstance(theProject.newRoot(nwItemClass.CUSTOM), str) + assert isinstance(theProject.newRoot(nwItemClass.CUSTOM), str) assert theProject.projChanged is True assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) assert theProject.projChanged is False # END Test testCoreProject_NewRoot @pytest.mark.core -def testCoreProject_NewFile(fncDir, outDir, refDir, mockGUI): +def testCoreProject_NewFileFolder(fncDir, outDir, refDir, mockGUI, mockRnd): """Check that new files can be added to the project. """ projFile = os.path.join(fncDir, "nwProject.nwx") - testFile = os.path.join(outDir, "coreProject_NewFile_nwProject.nwx") - compFile = os.path.join(refDir, "coreProject_NewFile_nwProject.nwx") + testFile = os.path.join(outDir, "coreProject_NewFileFolder_nwProject.nwx") + compFile = os.path.join(refDir, "coreProject_NewFileFolder_nwProject.nwx") theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) + buildTestProject(theProject, fncDir) - assert theProject.newProject({"projPath": fncDir}) is True assert theProject.setProjectPath(fncDir) is True assert theProject.saveProject() is True assert theProject.closeProject() is True assert theProject.openProject(projFile) is True - assert isinstance(theProject.newFile("Hello", nwItemClass.NOVEL, "31489056e0916"), str) - assert isinstance(theProject.newFile("Jane", nwItemClass.CHARACTER, "71ee45a3c0db9"), str) - assert theProject.projChanged + # Invalid call + assert theProject.newFolder("New Folder", "1234567890abc") is None + assert theProject.newFile("New File", "1234567890abc") is None + + # Add files properly + assert theProject.newFolder("Stuff", "0000000000015") == "0000000000028" + assert theProject.newFile("Hello", "0000000000015") == "0000000000029" + assert theProject.newFile("Jane", "0000000000012") == "000000000002a" + + assert "0000000000028" in theProject.tree + assert "0000000000029" in theProject.tree + assert "000000000002a" in theProject.tree + + # Write to file, failed + assert theProject.writeNewFile("blabla", 1, True) is False # Not a handle + assert theProject.writeNewFile("0000000000028", 1, True) is False # Not a file + assert theProject.writeNewFile("0000000000014", 1, True) is False # Already has content + + # Write to file, success + assert theProject.writeNewFile("0000000000029", 2, True) is True + assert NWDoc(theProject, "0000000000029").readDocument() == "## Hello\n\n" + + assert theProject.writeNewFile("000000000002a", 1, False) is True + assert NWDoc(theProject, "000000000002a").readDocument() == "# Jane\n\n" + + # Save, close and check + assert theProject.projChanged is True assert theProject.saveProject() is True assert theProject.closeProject() is True copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) assert theProject.projChanged is False -# END Test testCoreProject_NewFile +# END Test testCoreProject_NewFileFolder @pytest.mark.core @@ -452,12 +463,15 @@ def testCoreProject_Open(monkeypatch, nwMinimal, mockGUI): os.rename(oName, rName) # Add some legacy stuff that cannot be removed - writeFile(os.path.join(nwMinimal, "junk"), "stuff") - os.mkdir(os.path.join(nwMinimal, "data_0")) - writeFile(os.path.join(nwMinimal, "data_0", "junk"), "stuff") - mockGUI.clear() - assert theProject.openProject(nwMinimal) is True - assert "data_0" in mockGUI.lastAlert + with monkeypatch.context() as mp: + mp.setattr(theProject, "_legacyDataFolder", causeOSError) + os.mkdir(os.path.join(nwMinimal, "data_0")) + writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.nwd"), "stuff") + writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.bak"), "stuff") + mockGUI.clear() + assert theProject.openProject(nwMinimal) is True + assert "There was an error updating the project." in mockGUI.lastAlert + assert theProject.closeProject() # END Test testCoreProject_Open @@ -500,7 +514,7 @@ def testCoreProject_Save(monkeypatch, nwMinimal, mockGUI, refDir): assert theProject.saveProject() is True assert theProject.saveCount == saveCount + 1 assert theProject.autoCount == autoCount - assert cmpFiles(testFile, compFile, [2, 6, 7, 8, 9]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) # Check that a second save creates a .bak file assert os.path.isfile(backFile) is True @@ -511,7 +525,7 @@ def testCoreProject_Save(monkeypatch, nwMinimal, mockGUI, refDir): assert theProject.saveProject(autoSave=True) is True assert theProject.saveCount == saveCount assert theProject.autoCount == autoCount + 1 - assert cmpFiles(testFile, compFile, [2, 6, 7, 8, 9]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) # Close test project assert theProject.closeProject() @@ -630,6 +644,11 @@ def testCoreProject_AccessItems(nwMinimal, mockGUI): theProject = NWProject(mockGUI) theProject.openProject(nwMinimal) + # Storage Objects + assert isinstance(theProject.index, NWIndex) + assert isinstance(theProject.tree, NWTree) + assert isinstance(theProject.options, OptionState) + # Move Novel ROOT to after its files oldOrder = [ "a508bb932959c", # ROOT: Novel @@ -651,17 +670,17 @@ def testCoreProject_AccessItems(nwMinimal, mockGUI): "afb3043c7b2b3", # ROOT: Characters "9d5247ab588e0", # ROOT: World ] - assert theProject.projTree.handles() == oldOrder + assert theProject.tree.handles() == oldOrder assert theProject.setTreeOrder(newOrder) - assert theProject.projTree.handles() == newOrder + assert theProject.tree.handles() == newOrder # Add a non-existing item - theProject.projTree._treeOrder.append("01234567789abc") + theProject.tree._treeOrder.append("01234567789abc") # Add an item with a non-existent parent - nHandle = theProject.newFile("Test File", nwItemClass.NOVEL, "a6d311a93600a") - theProject.projTree[nHandle].setParent("cba9876543210") - assert theProject.projTree[nHandle].itemParent == "cba9876543210" + nHandle = theProject.newFile("Test File", "a6d311a93600a") + theProject.tree[nHandle].setParent("cba9876543210") + assert theProject.tree[nHandle].itemParent == "cba9876543210" retOrder = [] for tItem in theProject.getProjectItems(): @@ -678,19 +697,138 @@ def testCoreProject_AccessItems(nwMinimal, mockGUI): "f5ab3e30151e1", # FILE: New Chapter "8c659a11cd429", # FILE: New Scene ] - assert theProject.projTree[nHandle].itemParent is None + assert theProject.tree[nHandle].itemParent is None # END Test testCoreProject_AccessItems @pytest.mark.core -def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): +def testCoreProject_StatusImport(mockGUI, fncDir, mockRnd): + """Test the status and importance flag handling. + """ + theProject = NWProject(mockGUI) + buildTestProject(theProject, fncDir) + + statusKeys = ["s000008", "s000009", "s00000a", "s00000b"] + importKeys = ["i00000c", "i00000d", "i00000e", "i00000f"] + + # Change Status + # ============= + + theProject.tree["0000000000014"].setStatus("Finished") + theProject.tree["0000000000015"].setStatus("Draft") + theProject.tree["0000000000016"].setStatus("Note") + theProject.tree["0000000000017"].setStatus("Finished") + + assert theProject.tree["0000000000014"].itemStatus == statusKeys[3] + assert theProject.tree["0000000000015"].itemStatus == statusKeys[2] + assert theProject.tree["0000000000016"].itemStatus == statusKeys[1] + assert theProject.tree["0000000000017"].itemStatus == statusKeys[3] + + newList = [ + {"key": statusKeys[0], "name": "New", "cols": (1, 1, 1)}, + {"key": statusKeys[1], "name": "Draft", "cols": (2, 2, 2)}, # These are swapped + {"key": statusKeys[2], "name": "Note", "cols": (3, 3, 3)}, # These are swapped + {"key": statusKeys[3], "name": "Edited", "cols": (4, 4, 4)}, # Renamed + {"key": None, "name": "Finished", "cols": (5, 5, 5)}, # New, reused name + ] + assert theProject.setStatusColours(None, None) is False + assert theProject.setStatusColours([], []) is False + assert theProject.setStatusColours(newList, []) is True + + assert theProject.statusItems.name(statusKeys[0]) == "New" + assert theProject.statusItems.name(statusKeys[1]) == "Draft" + assert theProject.statusItems.name(statusKeys[2]) == "Note" + assert theProject.statusItems.name(statusKeys[3]) == "Edited" + assert theProject.statusItems.cols(statusKeys[0]) == (1, 1, 1) + assert theProject.statusItems.cols(statusKeys[1]) == (2, 2, 2) + assert theProject.statusItems.cols(statusKeys[2]) == (3, 3, 3) + assert theProject.statusItems.cols(statusKeys[3]) == (4, 4, 4) + + # Check the new entry + lastKey = theProject.statusItems.check("Finished") + assert lastKey == "s000018" + assert theProject.statusItems.name(lastKey) == "Finished" + assert theProject.statusItems.cols(lastKey) == (5, 5, 5) + + # Delete last entry + assert theProject.setStatusColours([], [lastKey]) is True + assert theProject.statusItems.name(lastKey) == "New" + + # Change Importance + # ================= + + fHandle = theProject.newFile("Jane Doe", "0000000000012") + theProject.tree[fHandle].setImport("Main") + + assert theProject.tree[fHandle].itemImport == importKeys[3] + newList = [ + {"key": importKeys[0], "name": "New", "cols": (1, 1, 1)}, + {"key": importKeys[1], "name": "Minor", "cols": (2, 2, 2)}, + {"key": importKeys[2], "name": "Major", "cols": (3, 3, 3)}, + {"key": importKeys[3], "name": "Min", "cols": (4, 4, 4)}, + {"key": None, "name": "Max", "cols": (5, 5, 5)}, + ] + assert theProject.setImportColours(None, None) is False + assert theProject.setImportColours([], []) is False + assert theProject.setImportColours(newList, []) is True + + assert theProject.importItems.name(importKeys[0]) == "New" + assert theProject.importItems.name(importKeys[1]) == "Minor" + assert theProject.importItems.name(importKeys[2]) == "Major" + assert theProject.importItems.name(importKeys[3]) == "Min" + assert theProject.importItems.cols(importKeys[0]) == (1, 1, 1) + assert theProject.importItems.cols(importKeys[1]) == (2, 2, 2) + assert theProject.importItems.cols(importKeys[2]) == (3, 3, 3) + assert theProject.importItems.cols(importKeys[3]) == (4, 4, 4) + + # Check the new entry + lastKey = theProject.importItems.check("Max") + assert lastKey == "i00001a" + assert theProject.importItems.name(lastKey) == "Max" + assert theProject.importItems.cols(lastKey) == (5, 5, 5) + + # Delete last entry + assert theProject.setImportColours([], [lastKey]) is True + assert theProject.importItems.name(lastKey) == "New" + + # Delete Status/Import + # ==================== + + theProject.statusItems.resetCounts() + for key in list(theProject.statusItems.keys()): + assert theProject.statusItems.remove(key) is True + + theProject.importItems.resetCounts() + for key in list(theProject.importItems.keys()): + assert theProject.importItems.remove(key) is True + + assert len(theProject.statusItems) == 0 + assert len(theProject.importItems) == 0 + assert theProject.saveProject() is True + assert theProject.closeProject() is True + + # This should restore the default status/import labels + assert theProject.openProject(fncDir) is True + assert theProject.saveProject() is True + assert theProject.statusItems.name("s000023") == "New" + assert theProject.statusItems.name("s000024") == "Note" + assert theProject.statusItems.name("s000025") == "Draft" + assert theProject.statusItems.name("s000026") == "Finished" + assert theProject.importItems.name("i000027") == "New" + assert theProject.importItems.name("i000028") == "Minor" + assert theProject.importItems.name("i000029") == "Major" + assert theProject.importItems.name("i00002a") == "Main" + +# END Test testCoreProject_StatusImport + + +@pytest.mark.core +def testCoreProject_Methods(monkeypatch, mockGUI, tmpDir, fncDir, mockRnd): """Test other project class methods and functions. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) - assert theProject.openProject(nwMinimal) - assert theProject.projPath == nwMinimal + buildTestProject(theProject, fncDir) # Setting project path assert theProject.setProjectPath(None) @@ -701,16 +839,16 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): assert theProject.projPath == os.path.expanduser("~") # Create a new folder and populate it - projPath = os.path.join(nwMinimal, "mock1") + projPath = os.path.join(fncDir, "mock1") assert theProject.setProjectPath(projPath, newProject=True) # Make os.mkdir fail monkeypatch.setattr("os.mkdir", causeOSError) - projPath = os.path.join(nwMinimal, "mock2") + projPath = os.path.join(fncDir, "mock2") assert not theProject.setProjectPath(projPath, newProject=True) # Set back - assert theProject.setProjectPath(nwMinimal) + assert theProject.setProjectPath(fncDir) # Project Name assert theProject.setProjectName(" A Name ") @@ -748,9 +886,10 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): # Trash folder # Should create on first call, and just returned on later calls - assert theProject.projTree["73475cb40a568"] is None - assert theProject.trashFolder() == "73475cb40a568" - assert theProject.trashFolder() == "73475cb40a568" + hTrash = "0000000000018" + assert theProject.tree[hTrash] is None + assert theProject.trashFolder() == hTrash + assert theProject.trashFolder() == hTrash # Project backup assert theProject.doBackup is True @@ -774,9 +913,10 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): # Spell language theProject.projChanged = False - assert theProject.setSpellLang(None) assert theProject.projSpell is None - assert theProject.setSpellLang("None") + assert theProject.setSpellLang(None) is False + assert theProject.projSpell is None + assert theProject.setSpellLang("None") is False # Should be interpreded as None assert theProject.projSpell is None assert theProject.setSpellLang("en_GB") assert theProject.projSpell == "en_GB" @@ -790,11 +930,9 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): assert theProject.setProjectLang("en_GB") is True assert theProject.projLang == "en_GB" - # Automatic outline update - theProject.projChanged = False - assert theProject.setAutoOutline(True) - assert not theProject.setAutoOutline(False) - assert theProject.projChanged + # Language Lookup + assert theProject.localLookup(1) == "One" + assert theProject.localLookup(10) == "Ten" # Last edited theProject.projChanged = False @@ -816,70 +954,20 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): # Change project tree order oldOrder = [ - "a508bb932959c", "a35baf2e93843", "a6d311a93600a", - "f5ab3e30151e1", "8c659a11cd429", "7695ce551d265", - "afb3043c7b2b3", "9d5247ab588e0", "73475cb40a568", + "0000000000010", "0000000000011", "0000000000012", + "0000000000013", "0000000000014", "0000000000015", + "0000000000016", "0000000000017", "0000000000018", ] newOrder = [ - "f5ab3e30151e1", "8c659a11cd429", "7695ce551d265", - "a508bb932959c", "a35baf2e93843", "a6d311a93600a", - "afb3043c7b2b3", "9d5247ab588e0", + "0000000000013", "0000000000014", "0000000000015", + "0000000000010", "0000000000011", "0000000000012", + "0000000000016", "0000000000017", ] - assert theProject.projTree.handles() == oldOrder + assert theProject.tree.handles() == oldOrder assert theProject.setTreeOrder(newOrder) - assert theProject.projTree.handles() == newOrder + assert theProject.tree.handles() == newOrder assert theProject.setTreeOrder(oldOrder) - assert theProject.projTree.handles() == oldOrder - - # Change status - theProject.projTree["a35baf2e93843"].setStatus("Finished") - theProject.projTree["a6d311a93600a"].setStatus("Draft") - theProject.projTree["f5ab3e30151e1"].setStatus("Note") - theProject.projTree["8c659a11cd429"].setStatus("Finished") - newList = [ - ("New", 1, 1, 1, "New"), - ("Draft", 2, 2, 2, "Note"), # These are swapped - ("Note", 3, 3, 3, "Draft"), # These are swapped - ("Edited", 4, 4, 4, "Finished"), # Renamed - ("Finished", 5, 5, 5, None), # New, with reused name - ] - assert theProject.setStatusColours(newList) - assert theProject.statusItems._theLabels == [ - "New", "Draft", "Note", "Edited", "Finished" - ] - assert theProject.statusItems._theColours == [ - (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) - ] - assert theProject.projTree["a35baf2e93843"].itemStatus == "Edited" # Renamed - assert theProject.projTree["a6d311a93600a"].itemStatus == "Note" # Swapped - assert theProject.projTree["f5ab3e30151e1"].itemStatus == "Draft" # Swapped - assert theProject.projTree["8c659a11cd429"].itemStatus == "Edited" # Renamed - - # Change importance - fHandle = theProject.newFile("Jane Doe", nwItemClass.CHARACTER, "afb3043c7b2b3") - theProject.projTree[fHandle].setStatus("Main") - newList = [ - ("New", 1, 1, 1, "New"), - ("Minor", 2, 2, 2, "Minor"), - ("Major", 3, 3, 3, "Major"), - ("Min", 4, 4, 4, "Main"), - ("Max", 5, 5, 5, None), - ] - assert theProject.setImportColours(newList) - assert theProject.importItems._theLabels == [ - "New", "Minor", "Major", "Min", "Max" - ] - assert theProject.importItems._theColours == [ - (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5) - ] - assert theProject.projTree[fHandle].itemStatus == "Min" - - # Check status counts - assert theProject.statusItems._theCounts == [0, 0, 0, 0, 0] - assert theProject.importItems._theCounts == [0, 0, 0, 0, 0] - theProject.countStatus() - assert theProject.statusItems._theCounts == [1, 1, 1, 2, 0] - assert theProject.importItems._theCounts == [3, 0, 0, 1, 0] + assert theProject.tree.handles() == oldOrder # Session stats theProject.currWCount = 200 @@ -894,7 +982,7 @@ def testCoreProject_Methods(monkeypatch, nwMinimal, mockGUI, tmpDir): assert not theProject._appendSessionStats(idleTime=0) # Write entry - assert theProject.projMeta == os.path.join(nwMinimal, "meta") + assert theProject.projMeta == os.path.join(fncDir, "meta") statsFile = os.path.join(theProject.projMeta, nwFiles.SESS_STATS) theProject.projOpened = 1600002000 @@ -948,9 +1036,17 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum): """ theProject = NWProject(mockGUI) - assert theProject.openProject(nwLipsum) - assert theProject.projTree["636b6aa9b697b"] is None - assert theProject.closeProject() + assert theProject.openProject(nwLipsum) is True + assert theProject.tree["636b6aa9b697b"] is None + + # Add a file with non-existent parent + # This file will be renoved from the project on open + oHandle = theProject.newFile("Oops", "b3643d0f92e32") + theProject.tree[oHandle].setParent("1234567890abc") + + # Save and close + assert theProject.saveProject() is True + assert theProject.closeProject() is True # First Item with Meta Data orphPath = os.path.join(nwLipsum, "content", "636b6aa9b697b.nwd") @@ -980,11 +1076,11 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum): assert theProject.openProject(nwLipsum) assert theProject.projPath is not None - assert theProject.projTree["636b6aa9b697bb"] is None - assert theProject.projTree["abcdefghijklm"] is None + assert theProject.tree["636b6aa9b697bb"] is None + assert theProject.tree["abcdefghijklm"] is None # First Item with Meta Data - oItem = theProject.projTree["636b6aa9b697b"] + oItem = theProject.tree["636b6aa9b697b"] assert oItem is not None assert oItem.itemName == "[Recovered] Mars" assert oItem.itemHandle == "636b6aa9b697b" @@ -994,7 +1090,7 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum): assert oItem.itemLayout == nwItemLayout.NOTE # Second Item without Meta Data - oItem = theProject.projTree["736b6aa9b697b"] + oItem = theProject.tree["736b6aa9b697b"] assert oItem is not None assert oItem.itemName == "Recovered File 1" assert oItem.itemHandle == "736b6aa9b697b" @@ -1042,14 +1138,6 @@ def testCoreProject_OldFormat(mockGUI, nwOldProj): os.path.join(nwOldProj, "meta", "sessionLogOptions.json"), ] - # Add some files that shouldn't be there - deleteFiles.append(os.path.join(nwOldProj, "data_f", "whatnow.nwd")) - deleteFiles.append(os.path.join(nwOldProj, "data_f", "whatnow.txt")) - - # Add some folders that shouldn't be there - os.mkdir(os.path.join(nwOldProj, "stuff")) - os.mkdir(os.path.join(nwOldProj, "data_1", "stuff")) - # Create mock files os.mkdir(os.path.join(nwOldProj, "cache")) for aFile in deleteFiles: @@ -1063,7 +1151,6 @@ def testCoreProject_OldFormat(mockGUI, nwOldProj): for aFile in deleteFiles: assert not os.path.isfile(aFile) - assert not os.path.isdir(os.path.join(nwOldProj, "data_1", "stuff")) assert not os.path.isdir(os.path.join(nwOldProj, "data_1")) assert not os.path.isdir(os.path.join(nwOldProj, "data_7")) assert not os.path.isdir(os.path.join(nwOldProj, "data_8")) @@ -1071,12 +1158,6 @@ def testCoreProject_OldFormat(mockGUI, nwOldProj): assert not os.path.isdir(os.path.join(nwOldProj, "data_a")) assert not os.path.isdir(os.path.join(nwOldProj, "data_f")) - # Check stuff that has been moved - assert os.path.isdir(os.path.join(nwOldProj, "junk")) - assert os.path.isdir(os.path.join(nwOldProj, "junk", "stuff")) - assert os.path.isfile(os.path.join(nwOldProj, "junk", "whatnow.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "junk", "whatnow.txt")) - # Check that files we want to keep are in the right place assert os.path.isdir(os.path.join(nwOldProj, "cache")) assert os.path.isdir(os.path.join(nwOldProj, "content")) @@ -1111,10 +1192,6 @@ def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir): theProject = NWProject(mockGUI) theProject.setProjectPath(fncDir) - # assert theProject.newProject({"projPath": fncDir}) - # assert theProject.saveProject() - # assert theProject.closeProject() - # Check behaviour of deprecated files function on OSError tstFile = os.path.join(fncDir, "ToC.json") writeFile(tstFile, "stuff") @@ -1122,7 +1199,7 @@ def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir): with monkeypatch.context() as mp: mp.setattr("os.unlink", causeOSError) - assert not theProject._deprecatedFiles() + assert theProject._deprecatedFiles() is False assert theProject._deprecatedFiles() assert not os.path.isfile(tstFile) @@ -1131,63 +1208,36 @@ def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir): tstFile = os.path.join(fncDir, "data_0") writeFile(tstFile, "stuff") assert os.path.isfile(tstFile) - - errList = [] - errList = theProject._legacyDataFolder(tstFile, errList) - assert len(errList) > 0 - - # Move folder in data folder, shouldn't be there - tstData = os.path.join(fncDir, "data_1") - errItem = os.path.join(fncDir, "data_1", "stuff") - os.mkdir(tstData) - os.mkdir(errItem) - assert os.path.isdir(tstData) - assert os.path.isdir(errItem) - - # This causes a failure to create the 'junk' folder - with monkeypatch.context() as mp: - mp.setattr("os.mkdir", causeOSError) - errList = [] - errList = theProject._legacyDataFolder(tstData, errList) - assert len(errList) > 0 - - # This causes a failure to move 'stuff' to 'junk' - with monkeypatch.context() as mp: - mp.setattr("os.rename", causeOSError) - errList = [] - errList = theProject._legacyDataFolder(tstData, errList) - assert len(errList) > 0 - - # This should be successful - errList = [] - errList = theProject._legacyDataFolder(tstData, errList) - assert len(errList) == 0 - assert os.path.isdir(os.path.join(fncDir, "junk", "stuff")) + assert theProject._legacyDataFolder(tstFile) is False # Check renaming/deleting of old document files - tstData = os.path.join(fncDir, "data_2") - tstDoc1m = os.path.join(tstData, "000000000001_main.nwd") - tstDoc1b = os.path.join(tstData, "000000000001_main.bak") - tstDoc2m = os.path.join(tstData, "000000000002_main.nwd") - tstDoc2b = os.path.join(tstData, "000000000002_main.bak") - tstDoc3m = os.path.join(tstData, "tooshort003_main.nwd") - tstDoc3b = os.path.join(tstData, "tooshort003_main.bak") + tstData2 = os.path.join(fncDir, "data_2") + tstData3 = os.path.join(fncDir, "data_3") + tstDoc1m = os.path.join(tstData2, "000000000001_main.nwd") + tstDoc1b = os.path.join(tstData2, "000000000001_main.bak") + tstDoc2m = os.path.join(tstData2, "000000000002_main.nwd") + tstDoc2b = os.path.join(tstData2, "000000000002_main.bak") + tstDoc3m = os.path.join(tstData3, "tooshort003_main.nwd") + tstDoc3b = os.path.join(tstData3, "tooshort003_main.bak") + tstDir4a = os.path.join(tstData3, "stuff") - os.mkdir(tstData) + os.mkdir(tstData2) + os.mkdir(tstData3) writeFile(tstDoc1m, "stuff") writeFile(tstDoc1b, "stuff") writeFile(tstDoc2m, "stuff") writeFile(tstDoc2b, "stuff") writeFile(tstDoc3m, "stuff") writeFile(tstDoc3b, "stuff") + os.mkdir(tstDir4a) # Make the above fail with monkeypatch.context() as mp: mp.setattr("os.rename", causeOSError) mp.setattr("os.unlink", causeOSError) - errList = [] - errList = theProject._legacyDataFolder(tstData, errList) - assert len(errList) > 0 + with pytest.raises(OSError): + theProject._legacyDataFolder(tstData2) + theProject._legacyDataFolder(tstData3) assert os.path.isfile(tstDoc1m) assert os.path.isfile(tstDoc1b) assert os.path.isfile(tstDoc2m) @@ -1196,15 +1246,16 @@ def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir): assert os.path.isfile(tstDoc3b) # And succeed ... - errList = [] - errList = theProject._legacyDataFolder(tstData, errList) - assert len(errList) == 0 + assert theProject._legacyDataFolder(tstData2) is True + assert theProject._legacyDataFolder(tstData3) is True - assert not os.path.isdir(tstData) + assert not os.path.isdir(tstData2) + assert os.path.isdir(tstData3) assert os.path.isfile(os.path.join(fncDir, "content", "2000000000001.nwd")) assert os.path.isfile(os.path.join(fncDir, "content", "2000000000002.nwd")) - assert os.path.isfile(os.path.join(fncDir, "junk", "tooshort003_main.nwd")) - assert os.path.isfile(os.path.join(fncDir, "junk", "tooshort003_main.bak")) + assert os.path.isfile(os.path.join(fncDir, tstData3, "tooshort003_main.nwd")) + assert os.path.isfile(os.path.join(fncDir, tstData3, "tooshort003_main.bak")) + assert os.path.isdir(tstDir4a) # END Test testCoreProject_LegacyData diff --git a/tests/test_core/test_core_status.py b/tests/test_core/test_core_status.py index ab5af333..868a3034 100644 --- a/tests/test_core/test_core_status.py +++ b/tests/test_core/test_core_status.py @@ -20,101 +20,314 @@ along with this program. If not, see . """ import pytest +import random from lxml import etree +from PyQt5.QtGui import QIcon + from novelwriter.core.status import NWStatus +statusKeys = ["sa3b179", "s1c8031", "s06671a", "sbdd640"] +importKeys = ["i466852", "i3eb13b", "i392456", "i23b8c1"] + + +@pytest.mark.core +def testCoreStatus_Internal(): + """Test all the internal functions of the NWStatus class. + """ + random.seed(42) + theStatus = NWStatus(NWStatus.STATUS) + theImport = NWStatus(NWStatus.IMPORT) + + with pytest.raises(Exception): + NWStatus(999) + + # Generate Key + # ============ + + assert theStatus._newKey() == statusKeys[0] + assert theStatus._newKey() == statusKeys[1] + + # Key collision, should move to key 3 + theStatus.write(statusKeys[2], "Crash", (0, 0, 0)) + assert theStatus._newKey() == statusKeys[3] + + assert theImport._newKey() == importKeys[0] + assert theImport._newKey() == importKeys[1] + + # Key collision, should move to key 3 + theImport.write(importKeys[2], "Crash", (0, 0, 0)) + assert theImport._newKey() == importKeys[3] + + # Check Key + # ========= + + assert theStatus._isKey(None) is False # Not a string + assert theStatus._isKey("s00000") is False # Too short + assert theStatus._isKey("s000000") is True # Correct length + assert theStatus._isKey("s0000000") is False # Too long + assert theStatus._isKey("i000000") is False # Wrong type + assert theStatus._isKey("q000000") is False # Wrong type + assert theStatus._isKey("s12345H") is False # Not a hex value + assert theStatus._isKey("s12345F") is False # Not a lower case hex value + assert theStatus._isKey("s12345f") is True # Valid hex value + + assert theImport._isKey(None) is False # Not a string + assert theImport._isKey("i00000") is False # Too short + assert theImport._isKey("i000000") is True # Correct length + assert theImport._isKey("i0000000") is False # Too long + assert theImport._isKey("s000000") is False # Wrong type + assert theImport._isKey("q000000") is False # Wrong type + assert theImport._isKey("i12345H") is False # Not a hex value + assert theImport._isKey("i12345F") is False # Not a lower case hex value + assert theImport._isKey("i12345f") is True # Valid hex value + +# END Test testCoreStatus_Internal + + +@pytest.mark.core +def testCoreStatus_Iterator(): + """Test the iterator functions of the NWStatus class. + """ + random.seed(42) + theStatus = NWStatus(NWStatus.STATUS) + + theStatus.write(None, "New", (100, 100, 100)) + theStatus.write(None, "Note", (200, 50, 0)) + theStatus.write(None, "Draft", (200, 150, 0)) + theStatus.write(None, "Finished", (50, 200, 0)) + + # Direct access + entry = theStatus[statusKeys[0]] + assert entry["cols"] == (100, 100, 100) + assert entry["name"] == "New" + assert entry["count"] == 0 + assert isinstance(entry["icon"], QIcon) + + # Iterate + entries = list(theStatus) + assert len(entries) == 4 + assert len(theStatus) == 4 + + # Keys + assert list(theStatus.keys()) == statusKeys + + # Items + for index, (key, entry) in enumerate(theStatus.items()): + assert key == statusKeys[index] + assert "cols" in entry + assert "name" in entry + assert "count" in entry + assert "icon" in entry + + # Valuse + for entry in theStatus.values(): + assert "cols" in entry + assert "name" in entry + assert "count" in entry + assert "icon" in entry + +# END Test testCoreStatus_Iterator + @pytest.mark.core def testCoreStatus_Entries(): - """Test all the simple setters for the NWItem class. + """Test all the simple setters for the NWStatus class. """ - theStatus = NWStatus() + random.seed(42) + theStatus = NWStatus(NWStatus.STATUS) - # Add entries - theStatus.addEntry("New", (100, 100, 100)) - theStatus.addEntry("Minor", (200, 50, 0)) - theStatus.addEntry("Major", (200, 150, 0)) - theStatus.addEntry("Main", (50, 200, 0)) + # Write + # ===== - assert theStatus._theLabels == ["New", "Minor", "Major", "Main"] - assert theStatus._theColours == [(100, 100, 100), (200, 50, 0), (200, 150, 0), (50, 200, 0)] - assert theStatus._theCounts == [0, 0, 0, 0] - assert theStatus._theMap["New"] == 0 - assert theStatus._theMap["Minor"] == 1 - assert theStatus._theMap["Major"] == 2 - assert theStatus._theMap["Main"] == 3 - assert theStatus._theLength == 4 + # Have a key + theStatus.write(statusKeys[0], "Entry 1", (200, 100, 50)) + assert theStatus[statusKeys[0]]["name"] == "Entry 1" + assert theStatus[statusKeys[0]]["cols"] == (200, 100, 50) - # Lookups - assert theStatus.lookupEntry(None) is None - assert theStatus.lookupEntry("stuff") is None - assert theStatus.lookupEntry("Main") == 3 + # Don't have a key + theStatus.write(None, "Entry 2", (210, 110, 60)) + assert theStatus[statusKeys[1]]["name"] == "Entry 2" + assert theStatus[statusKeys[1]]["cols"] == (210, 110, 60) - # Checks - assert theStatus.checkEntry(123) == "New" - assert theStatus.checkEntry("Stuff") == "New" - assert theStatus.checkEntry("New ") == "New" - assert theStatus.checkEntry(" Main ") == "Main" + # Wrong colour spec + theStatus.write(None, "Entry 3", "what?") + assert theStatus[statusKeys[2]]["name"] == "Entry 3" + assert theStatus[statusKeys[2]]["cols"] == (100, 100, 100) - # Set new list - newList = [ - ("New", 1, 1, 1, "New"), - ("Minor", 2, 2, 2, "Minor"), - ("Major", 3, 3, 3, "Major"), - ("Min", 4, 4, 4, "Main"), - ("Max", 5, 5, 5, None), - ] - assert theStatus.setNewEntries(None) == {} - assert theStatus.setNewEntries(newList) == {"Main": "Min"} + # Wrong colour count + theStatus.write(None, "Entry 4", (10, 20)) + assert theStatus[statusKeys[3]]["name"] == "Entry 4" + assert theStatus[statusKeys[3]]["cols"] == (100, 100, 100) - assert theStatus._theLabels == ["New", "Minor", "Major", "Min", "Max"] - assert theStatus._theColours == [(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)] - assert theStatus._theCounts == [0, 0, 0, 0, 0] - assert theStatus._theMap["New"] == 0 - assert theStatus._theMap["Minor"] == 1 - assert theStatus._theMap["Major"] == 2 - assert theStatus._theMap["Min"] == 3 - assert theStatus._theMap["Max"] == 4 - assert theStatus._theLength == 5 + # Check reverse map + assert theStatus._reverse == { + "Entry 1": statusKeys[0], + "Entry 2": statusKeys[1], + "Entry 3": statusKeys[2], + "Entry 4": statusKeys[3], + } - # Add counts - countTo = [3, 5, 7, 9, 11] + # Check + # ===== + + # Normal lookup + for key in statusKeys: + assert theStatus.check(key) == key + + # Reverse map lookup + assert theStatus.check("Entry 1") == statusKeys[0] + assert theStatus.check("Entry 2") == statusKeys[1] + assert theStatus.check("Entry 3") == statusKeys[2] + assert theStatus.check("Entry 4") == statusKeys[3] + + # Non-existing name + assert theStatus.check("Entry 5") == statusKeys[0] + + # Name Access + # =========== + + assert theStatus.name(statusKeys[0]) == "Entry 1" + assert theStatus.name(statusKeys[1]) == "Entry 2" + assert theStatus.name(statusKeys[2]) == "Entry 3" + assert theStatus.name(statusKeys[3]) == "Entry 4" + assert theStatus.name("blablabla") == "Entry 1" + + # Colour Access + # ============= + + assert theStatus.cols(statusKeys[0]) == (200, 100, 50) + assert theStatus.cols(statusKeys[1]) == (210, 110, 60) + assert theStatus.cols(statusKeys[2]) == (100, 100, 100) + assert theStatus.cols(statusKeys[3]) == (100, 100, 100) + assert theStatus.cols("blablabla") == (200, 100, 50) + + # Icon Access + # =========== + + assert isinstance(theStatus.icon(statusKeys[0]), QIcon) + assert isinstance(theStatus.icon(statusKeys[1]), QIcon) + assert isinstance(theStatus.icon(statusKeys[2]), QIcon) + assert isinstance(theStatus.icon(statusKeys[3]), QIcon) + assert isinstance(theStatus.icon("blablabla"), QIcon) + + # Increment and Count Access + # ========================== + + countTo = [3, 5, 7, 9] for i, n in enumerate(countTo): for _ in range(n): - theStatus.countEntry(theStatus._theLabels[i]) - assert theStatus._theCounts == countTo + theStatus.increment(statusKeys[i]) - # Iterate - for i, (sA, sB, sC) in enumerate(theStatus): - assert sA == theStatus._theLabels[i] - assert sB == theStatus._theColours[i] - assert sC == theStatus._theCounts[i] + assert theStatus.count(statusKeys[0]) == countTo[0] + assert theStatus.count(statusKeys[1]) == countTo[1] + assert theStatus.count(statusKeys[2]) == countTo[2] + assert theStatus.count(statusKeys[3]) == countTo[3] + assert theStatus.count("blablabla") == countTo[0] - assert theStatus[9] == (None, None, None) - - # Clear counts theStatus.resetCounts() - assert theStatus._theCounts == [0, 0, 0, 0, 0] + + assert theStatus.count(statusKeys[0]) == 0 + assert theStatus.count(statusKeys[1]) == 0 + assert theStatus.count(statusKeys[2]) == 0 + assert theStatus.count(statusKeys[3]) == 0 + + # Reorder + # ======= + + cOrder = list(theStatus.keys()) + assert cOrder == statusKeys + + # Wrong length + assert theStatus.reorder([]) is False + + # No change + assert theStatus.reorder(cOrder) is False + + # Actual reaorder + nOrder = [ + statusKeys[0], + statusKeys[2], + statusKeys[1], + statusKeys[3], + ] + assert theStatus.reorder(nOrder) is True + assert list(theStatus.keys()) == nOrder + + # Add an unknown key + wOrder = nOrder.copy() + wOrder[3] = theStatus._newKey() + assert theStatus.reorder(wOrder) is False + assert list(theStatus.keys()) == nOrder + + # Put it back + assert theStatus.reorder(cOrder) is True + assert list(theStatus.keys()) == cOrder + + # Default + # ======= + + default = theStatus._default + theStatus._default = None + + assert theStatus.check("Entry 5") == "" + assert theStatus.name("blablabla") == "" + assert theStatus.cols("blablabla") == (100, 100, 100) + assert theStatus.count("blablabla") == 0 + assert isinstance(theStatus.icon("blablabla"), QIcon) + + theStatus._default = default + + # Remove + # ====== + + # Non-existing entry + assert theStatus.remove("blablabla") is False + + # Non-zero entry + theStatus.increment(statusKeys[3]) + assert theStatus.remove(statusKeys[3]) is False + + # Delete last entry + theStatus.resetCounts() + lastName = theStatus.name(statusKeys[3]) + assert lastName == "Entry 4" + assert theStatus.remove(statusKeys[3]) is True + assert theStatus.check(statusKeys[3]) == theStatus._default + assert theStatus.check(lastName) == theStatus._default + + # Delete default entry, Entry 2 is new default + firstName = theStatus.name(theStatus._default) + assert firstName == "Entry 1" + assert theStatus.remove(theStatus._default) is True + assert theStatus.name(firstName) == "Entry 2" + + # Remove remaining entries + assert theStatus.remove(statusKeys[1]) is True + assert theStatus.remove(statusKeys[2]) is True + + assert len(theStatus) == 0 + assert theStatus._default is None # END Test testCoreStatus_Entries @pytest.mark.core def testCoreStatus_XMLPackUnpack(): - """Test all the simple setters for the NWItem class. + """Test all the XML pack/unpack of the NWStatus class. """ - theStatus = NWStatus() - theStatus.addEntry("New", (100, 100, 100)) - theStatus.addEntry("Minor", (200, 50, 0)) - theStatus.addEntry("Major", (200, 150, 0)) - theStatus.addEntry("Main", (50, 200, 0)) + random.seed(42) + theStatus = NWStatus(NWStatus.STATUS) + theStatus.write(None, "New", (100, 100, 100)) + theStatus.write(None, "Note", (200, 50, 0)) + theStatus.write(None, "Draft", (200, 150, 0)) + theStatus.write(None, "Finished", (50, 200, 0)) countTo = [3, 5, 7, 9] for i, n in enumerate(countTo): for _ in range(n): - theStatus.countEntry(theStatus._theLabels[i]) + theStatus.increment(statusKeys[i]) nwXML = etree.Element("novelWriterXML") @@ -122,24 +335,30 @@ def testCoreStatus_XMLPackUnpack(): xStatus = etree.SubElement(nwXML, "status") theStatus.packXML(xStatus) assert etree.tostring(xStatus, pretty_print=False, encoding="utf-8") == ( - b"" - b"New" - b"Minor" - b"Major" - b"Main" - b"" + b'' + b'New' + b'Note' + b'Draft' + b'Finished' + b'' ) # Unpack - theStatus = NWStatus() + theStatus = NWStatus(NWStatus.STATUS) assert theStatus.unpackXML(xStatus) - assert theStatus._theLabels == ["New", "Minor", "Major", "Main"] - assert theStatus._theColours == [(100, 100, 100), (200, 50, 0), (200, 150, 0), (50, 200, 0)] - assert theStatus._theCounts == [0, 0, 0, 0] - assert theStatus._theMap["New"] == 0 - assert theStatus._theMap["Minor"] == 1 - assert theStatus._theMap["Major"] == 2 - assert theStatus._theMap["Main"] == 3 - assert theStatus._theLength == 4 + assert len(theStatus._store) == 4 + assert list(theStatus._store.keys()) == statusKeys + assert theStatus._store[statusKeys[0]]["name"] == "New" + assert theStatus._store[statusKeys[1]]["name"] == "Note" + assert theStatus._store[statusKeys[2]]["name"] == "Draft" + assert theStatus._store[statusKeys[3]]["name"] == "Finished" + assert theStatus._store[statusKeys[0]]["cols"] == (100, 100, 100) + assert theStatus._store[statusKeys[1]]["cols"] == (200, 50, 0) + assert theStatus._store[statusKeys[2]]["cols"] == (200, 150, 0) + assert theStatus._store[statusKeys[3]]["cols"] == (50, 200, 0) + assert theStatus._store[statusKeys[0]]["count"] == countTo[0] + assert theStatus._store[statusKeys[1]]["count"] == countTo[1] + assert theStatus._store[statusKeys[2]]["count"] == countTo[2] + assert theStatus._store[statusKeys[3]]["count"] == countTo[3] # END Test testCoreStatus_XMLPackUnpack diff --git a/tests/test_core/test_core_tohtml.py b/tests/test_core/test_core_tohtml.py index 11d89572..f21d5d78 100644 --- a/tests/test_core/test_core_tohtml.py +++ b/tests/test_core/test_core_tohtml.py @@ -24,7 +24,7 @@ import pytest from tools import readFile -from novelwriter.core import NWProject, NWIndex, ToHtml +from novelwriter.core import NWProject, ToHtml @pytest.mark.core @@ -32,7 +32,6 @@ def testCoreToHtml_ConvertFormat(mockGUI): """Test the tokenizer and converter chain using the ToHtml class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theHtml = ToHtml(theProject) # Novel Files Headers @@ -235,7 +234,6 @@ def testCoreToHtml_ConvertDirect(mockGUI): """Test the converter directly using the ToHtml class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theHtml = ToHtml(theProject) theHtml._isNovel = True @@ -606,7 +604,6 @@ def testCoreToHtml_Format(mockGUI): """Test all the formatters for the ToHtml class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theHtml = ToHtml(theProject) # Export Mode diff --git a/tests/test_core/test_core_tokenizer.py b/tests/test_core/test_core_tokenizer.py index 0c57214b..97023201 100644 --- a/tests/test_core/test_core_tokenizer.py +++ b/tests/test_core/test_core_tokenizer.py @@ -28,12 +28,17 @@ from novelwriter.core import NWProject, NWDoc from novelwriter.core.tokenizer import Tokenizer +class BareTokenizer(Tokenizer): + def doConvert(self): + super().doConvert() + + @pytest.mark.core def testCoreToken_Setters(mockGUI): """Test all the setters for the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) # Verify defaults assert theToken._fmtTitle == "%title%" @@ -131,11 +136,10 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): """Test handling files and text in the Tokenizer class. """ theProject = NWProject(mockGUI) - theProject.projTree.setSeed(42) theProject.projLang = "en" theProject._loadProjectLocalisation() - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) assert theProject.openProject(nwMinimal) @@ -214,6 +218,10 @@ def testCoreToken_TextOps(monkeypatch, nwMinimal, mockGUI): "# Notes: Plot\n\n" ) + # Ckeck abstract method + with pytest.raises(NotImplementedError): + theToken.doConvert() + # END Test testCoreToken_TextOps @@ -222,7 +230,7 @@ def testCoreToken_HeaderFormat(mockGUI): """Test the tokenization of header formats in the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) # Title @@ -426,7 +434,7 @@ def testCoreToken_MetaFormat(mockGUI): """Test the tokenization of meta formats in the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) # Comment @@ -495,7 +503,7 @@ def testCoreToken_MarginFormat(mockGUI): """Test the tokenization of margin formats in the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) # Alignment and Indentation @@ -550,7 +558,7 @@ def testCoreToken_TextFormat(mockGUI): """Test the tokenization of text formats in the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken.setKeepMarkdown(True) # Text @@ -672,7 +680,7 @@ def testCoreToken_SpecialFormat(mockGUI): """Test the tokenization of special formats in the Tokenizer class. """ theProject = NWProject(mockGUI) - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) theToken._isNovel = True @@ -877,7 +885,7 @@ def testCoreToken_ProcessHeaders(mockGUI): theProject = NWProject(mockGUI) theProject.projLang = "en" theProject._loadProjectLocalisation() - theToken = Tokenizer(theProject) + theToken = BareTokenizer(theProject) # Nothing theToken._theText = "Some text ...\n" diff --git a/tests/test_core/test_core_tomd.py b/tests/test_core/test_core_tomd.py index 51eea72b..2e49d16b 100644 --- a/tests/test_core/test_core_tomd.py +++ b/tests/test_core/test_core_tomd.py @@ -24,7 +24,7 @@ import pytest from tools import readFile -from novelwriter.core import NWProject, NWIndex, ToMarkdown +from novelwriter.core import NWProject, ToMarkdown @pytest.mark.core @@ -32,7 +32,6 @@ def testCoreToMarkdown_ConvertFormat(mockGUI): """Test the tokenizer and converter chain using the ToMarkdown class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theMD = ToMarkdown(theProject) # Headers @@ -161,7 +160,6 @@ def testCoreToMarkdown_ConvertDirect(mockGUI): """Test the converter directly using the ToMarkdown class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theMD = ToMarkdown(theProject) theMD._isNovel = True @@ -266,7 +264,6 @@ def testCoreToMarkdown_Format(mockGUI): """Test all the formatters for the ToMarkdown class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theMD = ToMarkdown(theProject) assert theMD._formatKeywords("", theMD.A_NONE) == "" diff --git a/tests/test_core/test_core_toodt.py b/tests/test_core/test_core_toodt.py index e2ccb4a5..c714b5f5 100644 --- a/tests/test_core/test_core_toodt.py +++ b/tests/test_core/test_core_toodt.py @@ -28,7 +28,7 @@ from shutil import copyfile from tools import cmpFiles -from novelwriter.core import NWProject, NWIndex, ToOdt +from novelwriter.core import NWProject, ToOdt from novelwriter.core.toodt import ODTParagraphStyle, ODTTextStyle, XMLParagraph, _mkTag XML_NS = [ @@ -55,7 +55,6 @@ def testCoreToOdt_Init(mockGUI): """Test initialisation of the ODT document. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) # Flat Doc # ======== @@ -111,7 +110,6 @@ def testCoreToOdt_TextFormatting(mockGUI): """Test formatting of paragraphs. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=True) theDoc.initDocument() @@ -233,7 +231,6 @@ def testCoreToOdt_Convert(mockGUI): """Test the converter of the ToOdt class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=True) theDoc._isNovel = True @@ -565,7 +562,6 @@ def testCoreToOdt_ConvertDirect(mockGUI): otherwise hard to reach conditions. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=True) theDoc._isNovel = True @@ -620,7 +616,6 @@ def testCoreToOdt_SaveFlat(mockGUI, fncDir, outDir, refDir): """Test the document save functions. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=True) theDoc._isNovel = True @@ -657,7 +652,6 @@ def testCoreToOdt_SaveFull(mockGUI, fncDir, outDir, refDir): """Test the document save functions. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=False) theDoc._isNovel = True @@ -737,7 +731,6 @@ def testCoreToOdt_Format(mockGUI): """Test the formatters for the ToOdt class. """ theProject = NWProject(mockGUI) - mockGUI.theIndex = NWIndex(theProject) theDoc = ToOdt(theProject, isFlat=True) assert theDoc._formatSynopsis("synopsis text") == ( diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index dc49c41a..23eb7f73 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -21,9 +21,9 @@ along with this program. If not, see . import os import pytest +import random from lxml import etree -from hashlib import sha256 from tools import readFile @@ -33,7 +33,7 @@ from novelwriter.constants import nwFiles @pytest.fixture(scope="function") -def mockItems(mockGUI): +def mockItems(mockGUI, mockRnd): """Create a list of mock items. """ theProject = NWProject(mockGUI) @@ -76,7 +76,7 @@ def mockItems(mockGUI): itemF = NWItem(theProject) itemF._name = "Trash" - itemF._type = nwItemType.TRASH + itemF._type = nwItemType.ROOT itemF._class = nwItemClass.TRASH itemF._expanded = False @@ -103,7 +103,7 @@ def mockItems(mockGUI): ("a000000000002", None, itemE), ("a000000000003", None, itemF), ("a000000000004", None, itemG), - ("b000000000002", "a000000000002", itemH), + ("b000000000002", "a000000000004", itemH), ] return theItems @@ -116,26 +116,22 @@ def testCoreTree_BuildTree(mockGUI, mockItems): theProject = NWProject(mockGUI) theTree = NWTree(theProject) - theTree.setSeed(42) - assert theTree._handleSeed == 42 - # Check that tree is empty (calls NWTree.__bool__) - assert not theTree + assert bool(theTree) is False # Check for archive and trash folders assert theTree.trashRoot() is None - assert theTree.archiveRoot() is None - assert not theTree.isTrashRoot("a000000000003") aHandles = [] for tHandle, pHandle, nwItem in mockItems: aHandles.append(tHandle) - assert theTree.append(tHandle, pHandle, nwItem) + assert theTree.append(tHandle, pHandle, nwItem) is True + assert theTree.updateItemData(tHandle) is True - assert theTree._treeChanged + assert theTree._treeChanged is True # Check that tree is not empty (calls __bool__) - assert theTree + assert bool(theTree) is True # Check the number of elements (calls __len__) assert len(theTree) == len(mockItems) @@ -149,17 +145,43 @@ def testCoreTree_BuildTree(mockGUI, mockItems): # Check that we have the correct archive and trash folders assert theTree.trashRoot() == "a000000000003" - assert theTree.archiveRoot() == "a000000000002" - assert theTree.isTrashRoot("a000000000003") + assert theTree.findRoot(nwItemClass.ARCHIVE) == "a000000000002" + assert theTree.isTrash("a000000000003") is True + assert theTree.isRoot("a000000000002") is True + + # Check that we have the root classes + assert theTree.rootClasses() == { + nwItemClass.NOVEL, nwItemClass.CHARACTER, nwItemClass.ARCHIVE, nwItemClass.TRASH + } + + # Check the isTrash function + assert theTree.isTrash("0000000000000") is True # Doesn't exist + assert theTree.isTrash("a000000000003") is True # This the trash folder + + theTree["a000000000003"].setClass(nwItemClass.NO_CLASS) + assert theTree.isTrash("a000000000003") is True # This is still trash + theTree["a000000000003"].setClass(nwItemClass.TRASH) + + assert theTree.isTrash("b000000000002") is False # This is not trash + + value = theTree["b000000000002"].itemParent + theTree["b000000000002"].setParent("a000000000003") + assert theTree.isTrash("b000000000002") is True # This is in trash + theTree["b000000000002"].setParent(value) + + value = theTree["b000000000002"].itemRoot + theTree["b000000000002"].setRoot("a000000000003") + assert theTree.isTrash("b000000000002") is True # This is in trash + theTree["b000000000002"].setRoot(value) # Try to add another trash folder itemT = NWItem(theProject) itemT._name = "Trash" - itemT._type = nwItemType.TRASH + itemT._type = nwItemType.ROOT itemT._class = nwItemClass.TRASH itemT._expanded = False - assert not theTree.append("1234567890abc", None, itemT) + assert theTree.append("1234567890abc", None, itemT) is False assert len(theTree) == len(mockItems) # Generate handle automatically @@ -169,14 +191,16 @@ def testCoreTree_BuildTree(mockGUI, mockItems): itemT._class = nwItemClass.NOVEL itemT._layout = nwItemLayout.DOCUMENT - assert theTree.append(None, None, itemT) + assert theTree.append(None, None, itemT) is True + assert theTree.updateItemData(itemT.itemHandle) is True assert len(theTree) == len(mockItems) + 1 theList = theTree.handles() - assert theList[-1] == "73475cb40a568" + nHandle = "0000000000010" + assert theList[-1] == nHandle # Try to add existing handle - assert not theTree.append("73475cb40a568", None, itemT) + assert theTree.append(nHandle, None, itemT) is False assert len(theTree) == len(mockItems) + 1 # Delete a non-existing item @@ -184,9 +208,9 @@ def testCoreTree_BuildTree(mockGUI, mockItems): assert len(theTree) == len(mockItems) + 1 # Delete the last item - del theTree["73475cb40a568"] + del theTree[nHandle] assert len(theTree) == len(mockItems) - assert "73475cb40a568" not in theTree + assert nHandle not in theTree # Delete the Novel, Archive and Trash folders del theTree["a000000000001"] @@ -196,7 +220,6 @@ def testCoreTree_BuildTree(mockGUI, mockItems): del theTree["a000000000002"] assert len(theTree) == len(mockItems) - 2 assert "a000000000002" not in theTree - assert theTree.archiveRoot() is None del theTree["a000000000003"] assert len(theTree) == len(mockItems) - 3 @@ -215,31 +238,43 @@ def testCoreTree_Methods(mockGUI, mockItems): for tHandle, pHandle, nwItem in mockItems: theTree.append(tHandle, pHandle, nwItem) + theTree.updateItemData(tHandle) assert len(theTree) == len(mockItems) + # Update item data, nonsense handle + assert theTree.updateItemData("stuff") is False + + # Update item data, invalid item parent + corrParent = theTree["b000000000001"].itemParent + theTree["b000000000001"].setParent("0000000000000") + assert theTree.updateItemData("b000000000001") is False + + # Update item data, valid item parent + theTree["b000000000001"].setParent(corrParent) + assert theTree.updateItemData("b000000000001") is True + + # Update item data, root is unreachable + maxDepth = theTree.MAX_DEPTH + theTree.MAX_DEPTH = 0 + with pytest.raises(RecursionError): + theTree.updateItemData("b000000000001") + theTree.MAX_DEPTH = maxDepth + # Chech type assert theTree.checkType("blabla", nwItemType.FILE) is False assert theTree.checkType("b000000000001", nwItemType.FILE) is False assert theTree.checkType("c000000000001", nwItemType.FILE) is True # Root item lookup - theTree._treeRoots.append("stuff") assert theTree.findRoot(nwItemClass.WORLD) is None assert theTree.findRoot(nwItemClass.NOVEL) == "a000000000001" assert theTree.findRoot(nwItemClass.CHARACTER) == "a000000000004" - # Check for root uniqueness - assert theTree.checkRootUnique(nwItemClass.CUSTOM) - assert theTree.checkRootUnique(nwItemClass.WORLD) - assert not theTree.checkRootUnique(nwItemClass.NOVEL) - assert not theTree.checkRootUnique(nwItemClass.CHARACTER) - - # Find root item of child item - assert theTree.getRootItem("b000000000001").itemHandle == "a000000000001" - assert theTree.getRootItem("c000000000001").itemHandle == "a000000000001" - assert theTree.getRootItem("c000000000002").itemHandle == "a000000000001" - assert theTree.getRootItem("stuff") is None + # Add a fake item to root and check that it can handle it + theTree._treeRoots["0000000000000"] = NWItem(theProject) + assert theTree.findRoot(nwItemClass.WORLD) is None + del theTree._treeRoots["0000000000000"] # Get item path assert theTree.getItemPath("stuff") == [] @@ -247,6 +282,13 @@ def testCoreTree_Methods(mockGUI, mockItems): "c000000000001", "b000000000001", "a000000000001" ] + # Cause recursion error + maxDepth = theTree.MAX_DEPTH + theTree.MAX_DEPTH = 0 + with pytest.raises(RecursionError): + theTree.getItemPath("c000000000001") + theTree.MAX_DEPTH = maxDepth + # Break the folder parent handle theTree["b000000000001"]._parent = "stuff" assert theTree.getItemPath("c000000000001") == [ @@ -269,44 +311,31 @@ def testCoreTree_Methods(mockGUI, mockItems): @pytest.mark.core -def testCoreTree_MakeHandles(monkeypatch, mockGUI): +def testCoreTree_MakeHandles(mockGUI): """Test generating item handles. """ + random.seed(42) theProject = NWProject(mockGUI) theTree = NWTree(theProject) - theTree.setSeed(42) + handles = ["1c803a3b1799d", "bdd6406671ad1", "3eb1346685257", "23b8c392456de"] + random.seed(42) tHandle = theTree._makeHandle() - assert tHandle == "73475cb40a568" + assert tHandle == handles[0] + theTree._projTree[handles[0]] = None # Add the next in line to the project to force duplicate - theTree._projTree["44cb730c42048"] = None + theTree._projTree[handles[1]] = None tHandle = theTree._makeHandle() - assert tHandle == "71ee45a3c0db9" - - # Fix the time() function and force a handle collission - theTree.setSeed(None) - theTree._handleCount = 0 - monkeypatch.setattr("novelwriter.core.tree.time", lambda: 123.4) + assert tHandle == handles[2] + theTree._projTree[handles[2]] = None + # Reset the seed to force collissions, which should still end up + # returning the next handle in the sequence + random.seed(42) tHandle = theTree._makeHandle() - theTree._projTree[tHandle] = None - newSeed = "123.4_0_" - assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13] - - tHandle = theTree._makeHandle() - theTree._projTree[tHandle] = None - newSeed = "123.4_1_" - assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13] - - # Reset the count and the handle for 0 and 1 should be duplicates - # which forces the function to add the '!' - theTree._handleCount = 0 - tHandle = theTree._makeHandle() - theTree._projTree[tHandle] = None - newSeed = "123.4_1_!" - assert tHandle == sha256(newSeed.encode()).hexdigest()[0:13] + assert tHandle == handles[3] # END Test testCoreTree_MakeHandles @@ -329,12 +358,6 @@ def testCoreTree_Stats(mockGUI, mockItems): assert novelWords == 550 assert noteWords == 400 - # Count types - nRoot, nFolder, nFile = theTree.countTypes() - assert nRoot == 3 - assert nFolder == 1 - assert nFile == 3 - # END Test testCoreTree_Stats @@ -379,42 +402,44 @@ def testCoreTree_XMLPackUnpack(mockGUI, mockItems): for tHandle, pHandle, nwItem in mockItems: theTree.append(tHandle, pHandle, nwItem) + theTree.updateItemData(tHandle) assert len(theTree) == len(mockItems) nwXML = etree.Element("novelWriterXML") theTree.packXML(nwXML) assert etree.tostring(nwXML, pretty_print=False, encoding="utf-8") == ( - b"" - b"" - b"" - b"NovelROOTNOVELNone" - b"True" - b"" - b"Act OneFOLDERNOVELNone" - b"True" - b"" - b"Chapter OneFILENOVELNone" - b"TrueDOCUMENT300" - b"5020" - b"" - b"Scene OneFILENOVELNone" - b"TrueDOCUMENT3000" - b"500200" - b"" - b"OuttakesROOTARCHIVENone" - b"False" - b"" - b"TrashTRASHTRASHNone" - b"False" - b"" - b"CharactersROOTCHARACTERNone" - b"True" - b"" - b"Jane DoeFILECHARACTERNone" - b"TrueNOTE2000" - b"400160" - b"" + b'' + b'' + b'Novel' + b'Act One' + b'Chapter One' + b'Scene One' + b'Outtakes' + b'Trash' + b'Characters' + b'Jane Doe' + b'' + b'' ) theTree.clear() @@ -435,6 +460,7 @@ def testCoreTree_ToCFile(monkeypatch, mockGUI, mockItems, tmpDir): for tHandle, pHandle, nwItem in mockItems: theTree.append(tHandle, pHandle, nwItem) + theTree.updateItemData(tHandle) assert len(theTree) == len(mockItems) theTree._treeOrder.append("stuff") diff --git a/tests/test_dialogs/test_dlg_about.py b/tests/test_dialogs/test_dlg_about.py index c5ccfe7f..a4623c1f 100644 --- a/tests/test_dialogs/test_dlg_about.py +++ b/tests/test_dialogs/test_dlg_about.py @@ -36,8 +36,8 @@ def testDlgAbout_NWDialog(qtbot, monkeypatch, nwGUI): monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) # NW About - nwGUI.theTheme.themeName = "A Theme" - nwGUI.theTheme.themeAuthor = "An Author" + nwGUI.mainTheme.themeName = "A Theme" + nwGUI.mainTheme.themeAuthor = "An Author" assert nwGUI.showAboutNWDialog(showNotes=True) is True qtbot.waitUntil(lambda: getGuiItem("GuiAbout") is not None, timeout=1000) diff --git a/tests/test_dialogs/test_dlg_dialogs.py b/tests/test_dialogs/test_dlg_dialogs.py index 7ae56d94..3423beb5 100644 --- a/tests/test_dialogs/test_dlg_dialogs.py +++ b/tests/test_dialogs/test_dlg_dialogs.py @@ -24,11 +24,7 @@ import pytest from PyQt5.QtCore import QItemSelectionModel from PyQt5.QtWidgets import QAction, QListWidgetItem, QDialog, QMessageBox -from novelwriter.dialogs import GuiQuoteSelect, GuiUpdates - -keyDelay = 2 -typeDelay = 1 -stepDelay = 20 +from novelwriter.dialogs import GuiQuoteSelect, GuiUpdates, GuiEditLabel @pytest.mark.gui @@ -101,3 +97,24 @@ def testDlgOther_Updates(qtbot, monkeypatch, nwGUI): nwUpdate._doClose() # END Test testDlgOther_Updates + + +@pytest.mark.gui +def testDlgOther_EditLabel(qtbot, monkeypatch): + """Test the label editor dialog. + """ + monkeypatch.setattr(GuiEditLabel, "exec_", lambda *a: None) + + with monkeypatch.context() as mp: + mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Accepted) + newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") + assert dlgOk is True + assert newLabel == "Hello World" + + with monkeypatch.context() as mp: + mp.setattr(GuiEditLabel, "result", lambda *a: QDialog.Rejected) + newLabel, dlgOk = GuiEditLabel.getLabel(None, text="Hello World") + assert dlgOk is False + assert newLabel == "Hello World" + +# END Test testDlgOther_EditLabel diff --git a/tests/test_dialogs/test_dlg_docmerge.py b/tests/test_dialogs/test_dlg_docmerge.py index 6a3825b8..4e3138f6 100644 --- a/tests/test_dialogs/test_dlg_docmerge.py +++ b/tests/test_dialogs/test_dlg_docmerge.py @@ -19,48 +19,48 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest -from tools import getGuiItem, readFile, writeFile from mock import causeOSError +from tools import getGuiItem, readFile, writeFile, buildTestProject -from PyQt5.QtWidgets import QAction, QMessageBox, QDialog +from PyQt5.QtWidgets import QAction, QMessageBox -from novelwriter.dialogs import GuiDocMerge, GuiItemEditor from novelwriter.enum import nwItemType, nwWidget +from novelwriter.dialogs import GuiDocMerge, GuiEditLabel from novelwriter.core.tree import NWTree @pytest.mark.gui -def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj): +def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): """Test the merge documents tool. """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) # Create a new project - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) + buildTestProject(nwGUI, fncProj) # Handles for new objects - hChapterDir = "31489056e0916" - hChapterOne = "98010bd9270f9" - hSceneOne = "0e17daca5f3e1" - hSceneTwo = "1a6562590ef19" - hSceneThree = "031b4af5197ec" - hSceneFour = "41cfc0d1f2d12" - hMergedDoc = "2858dcd1057d3" + hNovelRoot = "0000000000008" + hChapterDir = "000000000000d" + hChapterOne = "000000000000e" + hSceneOne = "000000000000f" + hSceneTwo = "0000000000010" + hSceneThree = "0000000000011" + hSceneFour = "0000000000012" + hMergedDoc = "0000000000023" # Add Project Content - monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: QDialog.Accepted) nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterDir).setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterDir).setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) assert nwGUI.saveProject() is True assert nwGUI.closeProject() is True @@ -82,8 +82,8 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj): # Open the Merge tool nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterDir).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterDir).setSelected(True) monkeypatch.setattr(GuiDocMerge, "exec_", lambda *a: None) nwGUI.mainMenu.aMergeDocs.activate(QAction.Trigger) @@ -101,27 +101,27 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj): assert nwMerge.listBox.count() == 0 # No item selected - nwGUI.treeView.clearSelection() + nwGUI.projView.projTree.clearSelection() assert nwMerge._populateList() is False assert nwMerge.listBox.count() == 0 # Non-existing item with monkeypatch.context() as mp: mp.setattr(NWTree, "__getitem__", lambda *a: None) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterDir).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterDir).setSelected(True) assert nwMerge._populateList() is False assert nwMerge.listBox.count() == 0 # Select a non-folder - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterOne).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterOne).setSelected(True) assert nwMerge._populateList() is False assert nwMerge.listBox.count() == 0 # Select the chapter folder - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterDir).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterDir).setSelected(True) assert nwMerge._populateList() is True assert nwMerge.listBox.count() == 5 @@ -137,7 +137,7 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj): assert os.path.isfile(mergedFile) assert readFile(mergedFile) == ( "%%%%~name: New Chapter\n" - "%%%%~path: 73475cb40a568/2858dcd1057d3\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" "%s\n\n" @@ -145,6 +145,8 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj): "%s\n\n" "%s\n\n" ) % ( + hNovelRoot, + hMergedDoc, tChapterOne.strip(), tSceneOne.strip(), tSceneTwo.strip(), diff --git a/tests/test_dialogs/test_dlg_docsplit.py b/tests/test_dialogs/test_dlg_docsplit.py index d8d4bbac..d0201d6a 100644 --- a/tests/test_dialogs/test_dlg_docsplit.py +++ b/tests/test_dialogs/test_dlg_docsplit.py @@ -19,50 +19,50 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest -from tools import getGuiItem, readFile, writeFile from mock import causeOSError +from tools import getGuiItem, readFile, writeFile, buildTestProject -from PyQt5.QtWidgets import QAction, QMessageBox, QDialog +from PyQt5.QtWidgets import QAction, QMessageBox -from novelwriter.dialogs import GuiDocSplit, GuiItemEditor from novelwriter.enum import nwItemType, nwWidget -from novelwriter.core.document import NWDoc +from novelwriter.dialogs import GuiDocSplit, GuiEditLabel from novelwriter.core.tree import NWTree +from novelwriter.core.document import NWDoc @pytest.mark.gui -def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): +def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): """Test the split document tool. """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) # Create a new project - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) is True + buildTestProject(nwGUI, fncProj) # Handles for new objects - hNovelRoot = "73475cb40a568" - hChapterDir = "31489056e0916" - hToSplit = "1a6562590ef19" - hPartition = "41cfc0d1f2d12" - hChapterOne = "2858dcd1057d3" - hSceneOne = "2fca346db6561" - hSceneTwo = "02d20bbd7e394" - hSceneThree = "7688b6ef52555" - hSceneFour = "c837649cce43f" - hSceneFive = "6208ef0f7750c" + hNovelRoot = "0000000000008" + hChapterDir = "000000000000d" + hToSplit = "0000000000010" + hNewFolder = "0000000000021" + hPartition = "0000000000022" + hChapterOne = "0000000000023" + hSceneOne = "0000000000024" + hSceneTwo = "0000000000025" + hSceneThree = "0000000000026" + hSceneFour = "0000000000027" + hSceneFive = "0000000000028" # Add Project Content - monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: QDialog.Accepted) nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hNovelRoot).setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hNovelRoot).setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) assert nwGUI.saveProject() is True assert nwGUI.closeProject() is True @@ -89,8 +89,8 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): # Open the Split tool nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hToSplit).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hToSplit).setSelected(True) monkeypatch.setattr(GuiDocSplit, "exec_", lambda *a: None) nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger) @@ -109,7 +109,7 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): # No item selected nwSplit.sourceItem = None - nwGUI.treeView.clearSelection() + nwGUI.projView.projTree.clearSelection() assert nwSplit._populateList() is False assert nwSplit.listBox.count() == 0 @@ -117,15 +117,15 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): with monkeypatch.context() as mp: mp.setattr(NWTree, "__getitem__", lambda *a: None) nwSplit.sourceItem = None - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hToSplit).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hToSplit).setSelected(True) assert nwSplit._populateList() is False assert nwSplit.listBox.count() == 0 # Select a non-file nwSplit.sourceItem = None - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem(hChapterDir).setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem(hChapterDir).setSelected(True) assert nwSplit._populateList() is False assert nwSplit.listBox.count() == 0 @@ -173,52 +173,52 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): assert readFile(os.path.join(contentDir, hPartition+".nwd")) == ( "%%%%~name: Nantucket\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hPartition, tPartition) + ) % (hNewFolder, hPartition, tPartition) assert readFile(os.path.join(contentDir, hChapterOne+".nwd")) == ( "%%%%~name: Chapter One\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hChapterOne, tChapterOne) + ) % (hNewFolder, hChapterOne, tChapterOne) assert readFile(os.path.join(contentDir, hSceneOne+".nwd")) == ( "%%%%~name: Scene One\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hSceneOne, tSceneOne) + ) % (hNewFolder, hSceneOne, tSceneOne) assert readFile(os.path.join(contentDir, hSceneTwo+".nwd")) == ( "%%%%~name: Scene Two\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hSceneTwo, tSceneTwo) + ) % (hNewFolder, hSceneTwo, tSceneTwo) assert readFile(os.path.join(contentDir, hSceneThree+".nwd")) == ( "%%%%~name: Scene Three\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hSceneThree, tSceneThree) + ) % (hNewFolder, hSceneThree, tSceneThree) assert readFile(os.path.join(contentDir, hSceneFour+".nwd")) == ( "%%%%~name: Scene Four\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hSceneFour, tSceneFour) + ) % (hNewFolder, hSceneFour, tSceneFour) assert readFile(os.path.join(contentDir, hSceneFive+".nwd")) == ( "%%%%~name: The End\n" - "%%%%~path: 031b4af5197ec/%s\n" + "%%%%~path: %s/%s\n" "%%%%~kind: NOVEL/DOCUMENT\n" "%s\n\n" - ) % (hSceneFive, tSceneFive) + ) % (hNewFolder, hSceneFive, tSceneFive) # OS error with monkeypatch.context() as mp: @@ -230,12 +230,6 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj): mp.setattr(QMessageBox, "question", lambda *a: QMessageBox.No) assert nwSplit._doSplit() is False - # Block folder creation by returning that the folder has a depth - # of 50 items in the tree - with monkeypatch.context() as mp: - mp.setattr(NWTree, "getItemPath", lambda *a: [""]*50) - assert nwSplit._doSplit() is False - # Clear the list nwSplit.listBox.clear() assert nwSplit._doSplit() is False diff --git a/tests/test_dialogs/test_dlg_itemeditor.py b/tests/test_dialogs/test_dlg_itemeditor.py deleted file mode 100644 index 4d183408..00000000 --- a/tests/test_dialogs/test_dlg_itemeditor.py +++ /dev/null @@ -1,232 +0,0 @@ -""" -novelWriter – Item Editor Dialog Class Tester -============================================= - -This file is a part of novelWriter -Copyright 2018–2022, Veronica Berglyd Olsen - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - -import pytest - -from tools import getGuiItem - -from PyQt5.QtWidgets import QAction, QDialog, QMessageBox - -from novelwriter.gui import GuiProjectTree -from novelwriter.enum import nwItemLayout, nwItemType -from novelwriter.dialogs import GuiItemEditor -from novelwriter.core.tree import NWTree - - -@pytest.mark.gui -def testDlgItemEditor_Dialog(qtbot, monkeypatch, nwGUI, fncProj): - """Test launching the item editor dialog from GuiMain. - """ - # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - - # Block Dialog exec_ - monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: None) - - # Open Editor wo/Project - assert nwGUI.editItem() is False - - # Create and Open Project - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) - - # No Selection - nwGUI.treeView.clearSelection() - assert nwGUI.editItem() is False - - # Force opening from editor - assert nwGUI.openDocument("0e17daca5f3e1") - nwGUI.isFocusMode = True - - # Block Tree Lookup - with monkeypatch.context() as mp: - mp.setattr(NWTree, "__getitem__", lambda *a: None) - assert nwGUI.editItem() is False - - # Invalid Type - nwGUI.theProject.projTree["0e17daca5f3e1"]._type = nwItemType.NO_TYPE - assert nwGUI.editItem() is False - nwGUI.theProject.projTree["0e17daca5f3e1"]._type = nwItemType.FILE - - # Open Properly - assert nwGUI.editItem() is True - qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000) - itemEdit = getGuiItem("GuiItemEditor") - assert itemEdit is not None - itemEdit.close() - - # Open Via Menu - with monkeypatch.context() as mp: - mp.setattr(GuiItemEditor, "result", lambda *a: QDialog.Accepted) - nwGUI.mainMenu.aEditItem.activate(QAction.Trigger) - qtbot.waitUntil(lambda: getGuiItem("GuiItemEditor") is not None, timeout=1000) - itemEdit = getGuiItem("GuiItemEditor") - assert itemEdit is not None - itemEdit.close() - - nwGUI.isFocusMode = False - -# END Test testDlgItemEditor_Dialog - - -@pytest.mark.gui -def testDlgItemEditor_Novel(qtbot, monkeypatch, nwGUI, fncProj): - """Test the item editor dialog for a novel document. - """ - # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) - - # Create Project and Open Document - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) - assert nwGUI.openDocument("0e17daca5f3e1") - - # Check that an invalid handle is managed - itemEdit = GuiItemEditor(nwGUI, "whatever") - itemEdit.show() - itemEdit._doClose() - - # Edit a Document - itemEdit = GuiItemEditor(nwGUI, "0e17daca5f3e1") - itemEdit.show() - - # Check Existing Settings - assert itemEdit.editName.text() == "New Scene" - assert itemEdit.editStatus.currentData() == "New" - assert itemEdit.editLayout.currentData() == nwItemLayout.DOCUMENT - assert itemEdit.editExport.isChecked() is True - - # Change Settings - layoutIdx = itemEdit.editLayout.findData(nwItemLayout.NOTE) - itemEdit.editName.setText("Great Scene") - itemEdit.editStatus.setCurrentIndex(1) - itemEdit.editLayout.setCurrentIndex(layoutIdx) - itemEdit.editExport.setChecked(False) - - # Check New Settings - itemEdit._doSave() - assert itemEdit.theItem.itemName == "Great Scene" - assert itemEdit.theItem.itemStatus == "Note" - assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE - assert itemEdit.theItem.isExported is False - - # Check that the editor header is updated - nwGUI.docEditor.updateDocInfo("0e17daca5f3e1") - assert nwGUI.docEditor.docHeader.theTitle.text() == "Novel › New Chapter › Great Scene" - - itemEdit.close() - del itemEdit - # qtbot.stopForInteraction() - -# END Test testDlgItemEditor_Dialog - - -@pytest.mark.gui -def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj): - """Test the item editor dialog for a project note. - """ - # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) - - # Create Project and Open Document - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) - - # Create Note - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem("71ee45a3c0db9").setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) - - # Open Note - assert nwGUI.openDocument("1a6562590ef19") - - # Edit a Document - itemEdit = GuiItemEditor(nwGUI, "1a6562590ef19") - itemEdit.show() - - # Check Existing Settings - assert itemEdit.editName.text() == "New File" - assert itemEdit.editStatus.currentData() == "New" - assert itemEdit.editLayout.currentData() == nwItemLayout.NOTE - assert itemEdit.editExport.isChecked() is True - - # Change Settings - itemEdit.editName.setText("New Character") - itemEdit.editStatus.setCurrentIndex(1) - itemEdit.editExport.setChecked(False) - - # Check New Settings - itemEdit._doSave() - assert itemEdit.theItem.itemName == "New Character" - assert itemEdit.theItem.itemStatus == "Minor" - assert itemEdit.theItem.itemLayout == nwItemLayout.NOTE - assert itemEdit.theItem.isExported is False - - itemEdit.close() - del itemEdit - # qtbot.stopForInteraction() - -# END Test testDlgItemEditor_Note - - -@pytest.mark.gui -def testDlgItemEditor_Folder(qtbot, monkeypatch, nwGUI, fncProj): - """Test the item editor dialog for a folder. - """ - # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) - - # Create Project and Open Document - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) - - # Edit a Folder - itemEdit = GuiItemEditor(nwGUI, "31489056e0916") - itemEdit.show() - - # Check Existing Settings - assert itemEdit.editName.text() == "New Chapter" - assert itemEdit.editStatus.currentData() == "New" - assert itemEdit.editLayout.currentData() == nwItemLayout.NO_LAYOUT - assert itemEdit.editExport.isChecked() is False - - assert itemEdit.editLayout.isEnabled() is False - assert itemEdit.editExport.isEnabled() is False - - # Change Settings - itemEdit.editName.setText("Chapter One") - itemEdit.editStatus.setCurrentIndex(1) - - # Check New Settings - itemEdit._doSave() - assert itemEdit.theItem.itemName == "Chapter One" - assert itemEdit.theItem.itemStatus == "Note" - assert itemEdit.theItem.itemLayout == nwItemLayout.NO_LAYOUT - assert itemEdit.theItem.isExported is False - - itemEdit.close() - del itemEdit - # qtbot.stopForInteraction() - -# END Test testDlgItemEditor_Folder diff --git a/tests/test_dialogs/test_dlg_preferences.py b/tests/test_dialogs/test_dlg_preferences.py index aa33ba82..1507d351 100644 --- a/tests/test_dialogs/test_dlg_preferences.py +++ b/tests/test_dialogs/test_dlg_preferences.py @@ -239,8 +239,8 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir): copyfile(projFile, testFile) ignTuple = ( "timestamp", "guifont", "lastnotes", "guilang", "geometry", - "preferences", "treecols", "novelcols", "projcols", "mainpane", - "docpane", "viewpane", "outlinepane", "textfont", "textsize" + "preferences", "projcols", "mainpane", "docpane", "viewpane", + "outlinepane", "textfont", "textsize" ) assert cmpFiles(testFile, compFile, ignoreStart=ignTuple) diff --git a/tests/test_dialogs/test_dlg_projload.py b/tests/test_dialogs/test_dlg_projload.py index 195ca26b..6edb7a0d 100644 --- a/tests/test_dialogs/test_dlg_projload.py +++ b/tests/test_dialogs/test_dlg_projload.py @@ -42,7 +42,8 @@ def testDlgLoadProject_Main(qtbot, monkeypatch, nwGUI, nwMinimal): """Test the load project wizard. """ # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) assert nwGUI.openProject(nwMinimal) assert nwGUI.closeProject() diff --git a/tests/test_dialogs/test_dlg_projsettings.py b/tests/test_dialogs/test_dlg_projsettings.py index ec316bea..f193194a 100644 --- a/tests/test_dialogs/test_dlg_projsettings.py +++ b/tests/test_dialogs/test_dlg_projsettings.py @@ -19,27 +19,29 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest from shutil import copyfile -from tools import cmpFiles, getGuiItem +from tools import cmpFiles, getGuiItem, buildTestProject from PyQt5.QtGui import QColor from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import ( - QDialog, QAction, QMessageBox, QColorDialog, QTreeWidgetItem -) +from PyQt5.QtWidgets import QDialog, QAction, QMessageBox, QColorDialog from novelwriter.dialogs import GuiProjectSettings keyDelay = 2 typeDelay = 1 stepDelay = 20 +statusKeys = ["s000000", "s000001", "s000002", "s000003"] +importKeys = ["i000004", "i000005", "i000006", "i000007"] @pytest.mark.gui -def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir): +def testDlgProjSettings_Dialog( + qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDir, refDir, mockRnd +): """Test the full project settings dialog. """ projFile = os.path.join(fncProj, "nwProject.nwx") @@ -55,8 +57,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi assert getGuiItem("GuiProjectSettings") is None # Create new project - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) + buildTestProject(nwGUI, fncProj) nwGUI.mainConf.backupPath = fncDir nwGUI.theProject.setSpellLang("en") @@ -80,7 +81,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi # ============ assert projEdit.tabMain.editName.text() == "New Project" - assert projEdit.tabMain.editTitle.text() == "" + assert projEdit.tabMain.editTitle.text() == "New Novel" assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith" assert projEdit.tabMain.spellLang.currentData() == "en" assert projEdit.tabMain.doBackup.isChecked() is False @@ -89,6 +90,7 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi projEdit.tabMain.editName.setText("") for c in "Project Name": qtbot.keyClick(projEdit.tabMain.editName, c, delay=typeDelay) + projEdit.tabMain.editTitle.setText("") for c in "Project Title": qtbot.keyClick(projEdit.tabMain.editTitle, c, delay=typeDelay) @@ -111,19 +113,9 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi projEdit._tabBox.setCurrentWidget(projEdit.tabStatus) assert projEdit.tabStatus.colChanged is False - assert projEdit.tabStatus.getNewList() is None + assert projEdit.tabStatus.getNewList() == ([], []) assert projEdit.tabStatus.listBox.topLevelItemCount() == 4 - # Fake drag'n'drop should change changed status - projEdit.tabStatus._rowsMoved() - assert projEdit.tabStatus.colChanged is True - projEdit.tabStatus.colChanged = False - - projEdit.tabStatus.listBox.clearSelection() - assert projEdit.tabStatus._getSelectedItem() is None - projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True) - assert isinstance(projEdit.tabStatus._getSelectedItem(), QTreeWidgetItem) - # Can't delete the first item (it's in use) projEdit.tabStatus.listBox.clearSelection() projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True) @@ -150,11 +142,53 @@ def testDlgProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi qtbot.wait(stepDelay) assert projEdit.tabStatus.colChanged is True - assert projEdit.tabStatus.getNewList() == [ - ("New", 100, 100, 100, "New"), - ("Note", 200, 50, 0, "Note"), - ("Finished", 50, 200, 0, "Finished"), - ("Final", 20, 30, 40, None) + assert projEdit.tabStatus.getNewList() == ( + [ + { + "key": statusKeys[0], + "name": "New", + "cols": (100, 100, 100) + }, { + "key": statusKeys[1], + "name": "Note", + "cols": (200, 50, 0) + }, { + "key": statusKeys[3], + "name": "Finished", + "cols": (50, 200, 0) + }, { + "key": None, + "name": "Final", + "cols": (20, 30, 40) + } + ], [ + statusKeys[2] # Deleted item + ] + ) + + # Move items + projEdit.tabStatus.listBox.clearSelection() + projEdit.tabStatus._moveItem(1) + assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [ + statusKeys[0], statusKeys[1], statusKeys[3], None + ] + + projEdit.tabStatus.listBox.clearSelection() + projEdit.tabStatus.listBox.topLevelItem(0).setSelected(True) + projEdit.tabStatus._moveItem(-1) + assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [ + statusKeys[0], statusKeys[1], statusKeys[3], None + ] + + projEdit.tabStatus.listBox.clearSelection() + projEdit.tabStatus.listBox.topLevelItem(3).setSelected(True) + projEdit.tabStatus._moveItem(-1) + assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [ + statusKeys[0], statusKeys[1], None, statusKeys[3] + ] + projEdit.tabStatus._moveItem(1) + assert [x["key"] for x in projEdit.tabStatus.getNewList()[0]] == [ + statusKeys[0], statusKeys[1], statusKeys[3], None ] # Importance Tab diff --git a/tests/test_dialogs/test_dlg_wordlist.py b/tests/test_dialogs/test_dlg_wordlist.py index 3ca5a0ee..d9993d4d 100644 --- a/tests/test_dialogs/test_dlg_wordlist.py +++ b/tests/test_dialogs/test_dlg_wordlist.py @@ -40,6 +40,7 @@ stepDelay = 20 def testDlgWordList_Dialog(qtbot, monkeypatch, nwGUI, nwMinimal): """test the word list editor. """ + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(GuiWordList, "exec_", lambda *a: None) diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index f0d40808..572998cb 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -29,7 +29,7 @@ from PyQt5.QtWidgets import QAction, QMessageBox, qApp from novelwriter.gui.doceditor import GuiDocEditor from novelwriter.core import countWords -from novelwriter.enum import nwDocAction, nwDocInsert, nwItemClass, nwItemLayout +from novelwriter.enum import nwDocAction, nwDocInsert, nwItemLayout from novelwriter.constants import nwKeyWords, nwUnicode keyDelay = 2 @@ -43,6 +43,7 @@ def testGuiEditor_Init(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) # Open project assert nwGUI.openProject(nwMinimal) @@ -184,10 +185,10 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, nwMinimal, ipsumTe assert "Could not save document." in caplog.text # Change header level - assert nwGUI.theProject.projTree[sHandle].itemLayout == nwItemLayout.DOCUMENT + assert nwGUI.theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT nwGUI.docEditor.replaceText(longText[1:]) assert nwGUI.docEditor.saveText() is True - assert nwGUI.theProject.projTree[sHandle].itemLayout == nwItemLayout.DOCUMENT + assert nwGUI.theProject.tree[sHandle].itemLayout == nwItemLayout.DOCUMENT # Regular save assert nwGUI.docEditor.saveText() is True @@ -235,9 +236,9 @@ def testGuiEditor_MetaData(qtbot, monkeypatch, nwGUI, nwMinimal): assert nwGUI.docEditor.setCursorPosition(None) is False assert nwGUI.docEditor.setCursorPosition(10) is True assert nwGUI.docEditor.getCursorPosition() == 10 - assert nwGUI.theProject.projTree[sHandle].cursorPos != 10 + assert nwGUI.theProject.tree[sHandle].cursorPos != 10 nwGUI.docEditor.saveCursorPosition() - assert nwGUI.theProject.projTree[sHandle].cursorPos == 10 + assert nwGUI.theProject.tree[sHandle].cursorPos == 10 assert nwGUI.docEditor.setCursorLine(None) is False assert nwGUI.docEditor.setCursorLine(2) is True @@ -1142,11 +1143,11 @@ def testGuiEditor_Tags(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): # Create Character theText = "### Jane Doe\n\n@tag: Jane\n\n" + ipsumText[1] + "\n\n" - cHandle = nwGUI.theProject.newFile("Jane Doe", nwItemClass.CHARACTER, "afb3043c7b2b3") + cHandle = nwGUI.theProject.newFile("Jane Doe", "afb3043c7b2b3") assert nwGUI.openDocument(cHandle) is True assert nwGUI.docEditor.replaceText(theText) is True assert nwGUI.saveDocument() is True - assert nwGUI.treeView.revealNewTreeItem(cHandle) + assert nwGUI.projView.revealNewTreeItem(cHandle) nwGUI.docEditor.updateTagHighLighting() # Follow Tag @@ -1225,8 +1226,8 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): # Open a document and populate it sHandle = "8c659a11cd429" - nwGUI.theProject.projTree[sHandle]._initCount = 0 # Clear item's count - nwGUI.theProject.projTree[sHandle]._wordCount = 0 # Clear item's count + nwGUI.theProject.tree[sHandle]._initCount = 0 # Clear item's count + nwGUI.theProject.tree[sHandle]._wordCount = 0 # Clear item's count assert nwGUI.openDocument(sHandle) is True qtbot.wait(stepDelay) @@ -1252,9 +1253,9 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, nwMinimal, ipsumText): nwGUI.docEditor.wCounterDoc.run() # nwGUI.docEditor._updateDocCounts(cC, wC, pC) qtbot.wait(stepDelay) - assert nwGUI.theProject.projTree[sHandle]._charCount == cC - assert nwGUI.theProject.projTree[sHandle]._wordCount == wC - assert nwGUI.theProject.projTree[sHandle]._paraCount == pC + assert nwGUI.theProject.tree[sHandle]._charCount == cC + assert nwGUI.theProject.tree[sHandle]._wordCount == wC + assert nwGUI.theProject.tree[sHandle]._paraCount == pC assert nwGUI.docEditor.docFooter.wordsText.text() == f"Words: {wC} (+{wC})" # Select all text @@ -1285,7 +1286,6 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, nwLipsum): monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True) - nwGUI.theProject.projTree.setSeed(42) assert nwGUI.openProject(nwLipsum) is True assert nwGUI.openDocument("4c4f28287af27") is True origText = nwGUI.docEditor.getText() diff --git a/tests/test_gui/test_gui_docviewer.py b/tests/test_gui/test_gui_docviewer.py index 4d22b62d..2226a4c3 100644 --- a/tests/test_gui/test_gui_docviewer.py +++ b/tests/test_gui/test_gui_docviewer.py @@ -43,21 +43,20 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) # Open project - nwGUI.theProject.projTree.setSeed(42) assert nwGUI.openProject(nwLipsum) # Rebuild the index nwGUI.mainMenu.aRebuildIndex.activate(QAction.Trigger) - assert nwGUI.theIndex._tagIndex != {} - assert nwGUI.theIndex._refIndex != {} + assert nwGUI.theProject.index._tagsIndex._tags != {} + assert nwGUI.theProject.index._itemIndex._items != {} # Select a document in the project tree - nwGUI.treeView.setSelectedHandle("88243afbe5ed8") + nwGUI.projView.setSelectedHandle("88243afbe5ed8") # Middle-click the selected item - theItem = nwGUI.treeView._getTreeItem("88243afbe5ed8") - theRect = nwGUI.treeView.visualItemRect(theItem) - qtbot.mouseClick(nwGUI.treeView.viewport(), Qt.MidButton, pos=theRect.center()) + theItem = nwGUI.projView.projTree._getTreeItem("88243afbe5ed8") + theRect = nwGUI.projView.projTree.visualItemRect(theItem) + qtbot.mouseClick(nwGUI.projView.projTree.viewport(), Qt.MidButton, pos=theRect.center()) assert nwGUI.docViewer.docHandle() == "88243afbe5ed8" # Reload the text @@ -118,7 +117,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): assert nwGUI.docViewer.docAction(nwDocAction.COPY) is False # Open again via menu - assert nwGUI.treeView.setSelectedHandle("88243afbe5ed8") + assert nwGUI.projView.setSelectedHandle("88243afbe5ed8") nwGUI.mainMenu.aViewDoc.activate(QAction.Trigger) # Select "Bod" link @@ -141,7 +140,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, nwLipsum): nwGUI.docViewer.reloadText() # Change document title - nwItem = nwGUI.theProject.projTree["4c4f28287af27"] + nwItem = nwGUI.theProject.tree["4c4f28287af27"] nwItem.setName("Test Title") assert nwItem.itemName == "Test Title" nwGUI.docViewer.updateDocInfo("4c4f28287af27") diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 4eab5fb0..b2e446bc 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -19,20 +19,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest from shutil import copyfile -from tools import cmpFiles +from tools import cmpFiles, buildTestProject, XML_IGNORE, writeFile from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QMessageBox, QDialog +from PyQt5.QtWidgets import QMessageBox, QInputDialog -from novelwriter.gui import ( - GuiDocEditor, GuiProjectTree, GuiNovelTree, GuiOutline -) -from novelwriter.enum import nwItemType, nwWidget -from novelwriter.dialogs.itemeditor import GuiItemEditor +from novelwriter.gui import GuiDocEditor, GuiNovelView, GuiOutlineView +from novelwriter.enum import nwItemType, nwView, nwWidget +from novelwriter.tools import GuiProjectWizard +from novelwriter.gui.projtree import GuiProjectTree +from novelwriter.dialogs import GuiEditLabel keyDelay = 2 typeDelay = 1 @@ -57,10 +57,9 @@ def testGuiMain_ProjectBlocker(monkeypatch, nwGUI): assert nwGUI.mergeDocuments() is False assert nwGUI.splitDocument() is False assert nwGUI.openSelectedItem() is False - assert nwGUI.editItem() is False + assert nwGUI.editItemLabel() is False assert nwGUI.requestNovelTreeRefresh() is False assert nwGUI.rebuildIndex() is False - assert nwGUI.rebuildOutline() is False assert nwGUI.showProjectSettingsDialog() is False assert nwGUI.showProjectDetailsDialog() is False assert nwGUI.showBuildProjectDialog() is False @@ -71,83 +70,117 @@ def testGuiMain_ProjectBlocker(monkeypatch, nwGUI): @pytest.mark.gui -def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj): +def testGuiMain_NewProject(monkeypatch, nwGUI, fncProj): + """Test creating a new project. + """ + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + + # No data + with monkeypatch.context() as mp: + mp.setattr(GuiProjectWizard, "exec_", lambda *a: None) + assert nwGUI.newProject(projData=None) is False + + # Close project + with monkeypatch.context() as mp: + nwGUI.hasProject = True + mp.setattr(QMessageBox, "question", lambda *a: QMessageBox.No) + assert nwGUI.newProject(projData={"projPath": fncProj}) is False + + # No project path + assert nwGUI.newProject(projData={}) is False + + # Project file already exists + projFile = os.path.join(fncProj, nwGUI.theProject.projFile) + writeFile(projFile, "Stuff") + assert nwGUI.newProject(projData={"projPath": fncProj}) is False + os.unlink(projFile) + + # An unreachable path should also fail + projPath = os.path.join(fncProj, "stuff", "stuff", "stuff") + assert nwGUI.newProject(projData={"projPath": projPath}) is False + + # This one should work just fine + assert nwGUI.newProject(projData={"projPath": fncProj}) is True + assert os.path.isfile(os.path.join(fncProj, nwGUI.theProject.projFile)) + assert os.path.isdir(os.path.join(fncProj, "content")) + +# END Test testGuiMain_NewProject + + +@pytest.mark.gui +def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): """Test handling of project tree items based on GUI focus states. """ monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) is True - assert nwGUI.saveProject() is True + buildTestProject(nwGUI, fncProj) - sHandle = "0e17daca5f3e1" + sHandle = "000000000000f" assert nwGUI.openSelectedItem() is False # Project Tree has focus + nwGUI._changeView(nwView.PROJECT) nwGUI.switchFocus(nwWidget.TREE) - nwGUI.projTabs.setCurrentIndex(0) + nwGUI.projStack.setCurrentIndex(0) with monkeypatch.context() as mp: mp.setattr(GuiProjectTree, "hasFocus", lambda *a: True) assert nwGUI.docEditor.docHandle() is None - nwGUI.treeView._getTreeItem(sHandle).setSelected(True) + nwGUI.projView.projTree._getTreeItem(sHandle).setSelected(True) nwGUI._keyPressReturn() assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.closeDocument() is True # Novel Tree has focus - nwGUI.projTabs.setCurrentIndex(1) - nwGUI.novelView.refreshTree(True) + nwGUI._changeView(nwView.NOVEL) + nwGUI.novelView.novelTree.refreshTree(rootHandle=None, overRide=True) with monkeypatch.context() as mp: - mp.setattr(GuiNovelTree, "hasFocus", lambda *a: True) + mp.setattr(GuiNovelView, "treeHasFocus", lambda *a: True) assert nwGUI.docEditor.docHandle() is None - actItem = nwGUI.novelView.topLevelItem(0) - chpItem = actItem.child(0) - selItem = chpItem.child(0) - nwGUI.novelView.setCurrentItem(selItem) + selItem = nwGUI.novelView.novelTree.topLevelItem(2) + nwGUI.novelView.novelTree.setCurrentItem(selItem) nwGUI._keyPressReturn() assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.closeDocument() is True # Project Outline has focus + nwGUI._changeView(nwView.OUTLINE) nwGUI.switchFocus(nwWidget.OUTLINE) with monkeypatch.context() as mp: - mp.setattr(GuiOutline, "hasFocus", lambda *a: True) + mp.setattr(GuiOutlineView, "treeHasFocus", lambda *a: True) assert nwGUI.docEditor.docHandle() is None - actItem = nwGUI.projView.topLevelItem(0) - chpItem = actItem.child(0) - selItem = chpItem.child(0) - nwGUI.projView.setCurrentItem(selItem) + selItem = nwGUI.outlineView.outlineTree.topLevelItem(2) + nwGUI.outlineView.outlineTree.setCurrentItem(selItem) nwGUI._keyPressReturn() assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.closeDocument() is True - # qtbot.stopForInteraction() + # qtbot.stop() # END Test testGuiMain_ProjectTreeItems @pytest.mark.gui -def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): +def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mockRnd): """Test the document editor. """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiItemEditor, "exec_", lambda *a: None) - monkeypatch.setattr(GuiItemEditor, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) # Create new, save, close project - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) + buildTestProject(nwGUI, fncProj) assert nwGUI.saveProject() assert nwGUI.closeProject() - assert len(nwGUI.theProject.projTree) == 0 - assert len(nwGUI.theProject.projTree._treeOrder) == 0 - assert len(nwGUI.theProject.projTree._treeRoots) == 0 - assert nwGUI.theProject.projTree.trashRoot() is None + assert len(nwGUI.theProject.tree) == 0 + assert len(nwGUI.theProject.tree._treeOrder) == 0 + assert len(nwGUI.theProject.tree._treeRoots) == 0 + assert nwGUI.theProject.tree.trashRoot() is None assert nwGUI.theProject.projPath is None assert nwGUI.theProject.projMeta is None assert nwGUI.theProject.projFile == "nwProject.nwx" @@ -161,7 +194,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): testFile = os.path.join(outDir, "guiEditor_Main_Initial_nwProject.nwx") compFile = os.path.join(refDir, "guiEditor_Main_Initial_nwProject.nwx") copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8]) + assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE) qtbot.wait(stepDelay) # qtbot.stopForInteraction() @@ -171,27 +204,27 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): qtbot.wait(stepDelay) # Check that we loaded the data - assert len(nwGUI.theProject.projTree) == 8 - assert len(nwGUI.theProject.projTree._treeOrder) == 8 - assert len(nwGUI.theProject.projTree._treeRoots) == 4 - assert nwGUI.theProject.projTree.trashRoot() is None + assert len(nwGUI.theProject.tree) == 8 + assert len(nwGUI.theProject.tree._treeOrder) == 8 + assert len(nwGUI.theProject.tree._treeRoots) == 4 + assert nwGUI.theProject.tree.trashRoot() is None assert nwGUI.theProject.projPath == fncProj assert nwGUI.theProject.projMeta == os.path.join(fncProj, "meta") assert nwGUI.theProject.projFile == "nwProject.nwx" assert nwGUI.theProject.projName == "New Project" - assert nwGUI.theProject.bookTitle == "" - assert len(nwGUI.theProject.bookAuthors) == 0 - assert not nwGUI.theProject.spellCheck + assert nwGUI.theProject.bookTitle == "New Novel" + assert len(nwGUI.theProject.bookAuthors) == 1 + assert nwGUI.theProject.spellCheck is False # Check that tree items have been created - assert nwGUI.treeView._getTreeItem("73475cb40a568") is not None - assert nwGUI.treeView._getTreeItem("25fc0e7096fc6") is not None - assert nwGUI.treeView._getTreeItem("31489056e0916") is not None - assert nwGUI.treeView._getTreeItem("98010bd9270f9") is not None - assert nwGUI.treeView._getTreeItem("0e17daca5f3e1") is not None - assert nwGUI.treeView._getTreeItem("44cb730c42048") is not None - assert nwGUI.treeView._getTreeItem("71ee45a3c0db9") is not None - assert nwGUI.treeView._getTreeItem("811786ad1ae74") is not None + assert nwGUI.projView.projTree._getTreeItem("0000000000008") is not None + assert nwGUI.projView.projTree._getTreeItem("0000000000009") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000a") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000b") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000c") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000d") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000e") is not None + assert nwGUI.projView.projTree._getTreeItem("000000000000f") is not None nwGUI.mainMenu.aSpellCheck.setChecked(True) assert nwGUI.mainMenu._toggleSpellCheck() @@ -204,9 +237,9 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): # Add a Character File nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem("71ee45a3c0db9").setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem("000000000000a").setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Type something into the document @@ -226,9 +259,9 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): # Add a Plot File nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem("44cb730c42048").setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem("0000000000009").setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Type something into the document @@ -248,9 +281,9 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): # Add a World File nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem("811786ad1ae74").setSelected(True) - nwGUI.treeView.newTreeItem(nwItemType.FILE, None) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem("000000000000b").setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Add Some Text @@ -279,10 +312,10 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): # Select the 'New Scene' file nwGUI.switchFocus(nwWidget.TREE) - nwGUI.treeView.clearSelection() - nwGUI.treeView._getTreeItem("73475cb40a568").setExpanded(True) - nwGUI.treeView._getTreeItem("31489056e0916").setExpanded(True) - nwGUI.treeView._getTreeItem("0e17daca5f3e1").setSelected(True) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem("0000000000008").setExpanded(True) + nwGUI.projView.projTree._getTreeItem("000000000000d").setExpanded(True) + nwGUI.projView.projTree._getTreeItem("000000000000f").setSelected(True) assert nwGUI.openSelectedItem() # Type something into the document @@ -455,21 +488,21 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): # Open and view the edited document nwGUI.switchFocus(nwWidget.VIEWER) - assert nwGUI.openDocument("0e17daca5f3e1") - assert nwGUI.viewDocument("0e17daca5f3e1") + assert nwGUI.openDocument("000000000000f") + assert nwGUI.viewDocument("000000000000f") qtbot.wait(stepDelay) assert nwGUI.saveProject() assert nwGUI.closeDocViewer() qtbot.wait(stepDelay) # Check a Quick Create and Delete - assert nwGUI.treeView.newTreeItem(nwItemType.FILE, None) - newHandle = nwGUI.treeView.getSelectedHandle() - assert nwGUI.theProject.projTree["2858dcd1057d3"] is not None - assert nwGUI.treeView.deleteItem() - assert nwGUI.treeView.setSelectedHandle(newHandle) - assert nwGUI.treeView.deleteItem() - assert nwGUI.theProject.projTree["2fca346db6561"] is not None # Trash + assert nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None) + newHandle = nwGUI.projView.getSelectedHandle() + assert nwGUI.theProject.tree["0000000000020"] is not None + assert nwGUI.projView.deleteItem() + assert nwGUI.projView.setSelectedHandle(newHandle) + assert nwGUI.projView.deleteItem() + assert nwGUI.theProject.tree["0000000000024"] is not None # Trash assert nwGUI.saveProject() # Check the files @@ -477,32 +510,81 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir): testFile = os.path.join(outDir, "guiEditor_Main_Final_nwProject.nwx") compFile = os.path.join(refDir, "guiEditor_Main_Final_nwProject.nwx") copyfile(projFile, testFile) - assert cmpFiles(testFile, compFile, [2, 6, 7, 8, 13]) + assert cmpFiles(testFile, compFile, ignoreStart=(*XML_IGNORE, "") assert len(theBits) == 2 assert theBits[0] == "The currently open file is saved in:" - assert theBits[1] == os.path.join(fncProj, "content", "0e17daca5f3e1.nwd") + assert theBits[1] == os.path.join(fncProj, "content", "000000000000f.nwd") # qtbot.stopForInteraction() diff --git a/tests/test_gui/test_gui_noveltree.py b/tests/test_gui/test_gui_noveltree.py index 57e6acec..f8f18875 100644 --- a/tests/test_gui/test_gui_noveltree.py +++ b/tests/test_gui/test_gui_noveltree.py @@ -19,74 +19,98 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os +import pytest -from tools import writeFile +from tools import buildTestProject, writeFile -from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QMessageBox +from PyQt5.QtGui import QFocusEvent +from PyQt5.QtCore import Qt, QEvent +from PyQt5.QtWidgets import QMessageBox, QToolTip + +from novelwriter.enum import nwWidget, nwItemType +from novelwriter.dialogs import GuiEditLabel +from novelwriter.gui.noveltree import NovelTreeColumn @pytest.mark.gui -def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): +def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): """Test navigating the novel tree. """ # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) - nwGUI.openProject(nwMinimal) - nwGUI.theProject.projTree.setSeed(42) - nwTree = nwGUI.novelView + buildTestProject(nwGUI, fncProj) - ## - # Show/Hide Scrollbars - ## + nwGUI.switchFocus(nwWidget.TREE) + nwGUI.projView.projTree.clearSelection() + nwGUI.projView.projTree._getTreeItem("000000000000a").setSelected(True) + nwGUI.projView.projTree.newTreeItem(nwItemType.FILE) - nwTree.mainConf.hideVScroll = True - nwTree.mainConf.hideHScroll = True - nwTree.initTree() - assert not nwTree.verticalScrollBar().isVisible() - assert not nwTree.horizontalScrollBar().isVisible() + writeFile( + os.path.join(nwGUI.theProject.projContent, "0000000000010.nwd"), + "# Jane Doe\n\n@tag: Jane\n\n" + ) + writeFile( + os.path.join(nwGUI.theProject.projContent, "000000000000f.nwd"), ( + "### Scene One\n\n" + "@pov: Jane\n" + "@focus: Jane\n\n" + "% Synopsis: This is a scene." + ) + ) - nwTree.mainConf.hideVScroll = False - nwTree.mainConf.hideHScroll = False - nwTree.initTree() - assert nwTree.verticalScrollBar().isEnabled() - assert nwTree.horizontalScrollBar().isEnabled() + novelView = nwGUI.novelView + novelTree = novelView.novelTree + novelBar = novelView.novelBar - ## - # Populate Tree - ## + # Show/Hide Scrollbars + # ==================== - nwGUI.projTabs.setCurrentIndex(nwGUI.idxNovelView) + nwGUI.mainConf.hideVScroll = True + nwGUI.mainConf.hideHScroll = True + novelView.initSettings() + assert not novelTree.verticalScrollBar().isVisible() + assert not novelTree.horizontalScrollBar().isVisible() + + nwGUI.mainConf.hideVScroll = False + nwGUI.mainConf.hideHScroll = False + novelView.initSettings() + assert novelTree.verticalScrollBar().isEnabled() + assert novelTree.horizontalScrollBar().isEnabled() + + # Populate Tree + # ============= + + nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView) nwGUI.rebuildIndex() - nwTree._populateTree() - assert nwTree.topLevelItemCount() == 1 + novelTree._populateTree(rootHandle=None) + assert novelTree.topLevelItemCount() == 3 # Rebuild should preserve selection - topItem = nwTree.topLevelItem(0) + topItem = novelTree.topLevelItem(0) assert not topItem.isSelected() topItem.setSelected(True) - assert nwTree.selectedItems()[0] == topItem - assert nwTree.getSelectedHandle() == ("a35baf2e93843", 0) + assert novelTree.selectedItems()[0] == topItem + assert novelView.getSelectedHandle() == ("000000000000c", 0) - nwTree.refreshTree() - assert nwTree.topLevelItem(0).isSelected() + # Refresh using the slot for the butoom + novelBar._refreshNovelTree() + assert novelTree.topLevelItem(0).isSelected() - ## - # Open Items - ## + # Open Items + # ========== # Clear selection - nwTree.clearSelection() - scItem = nwTree.topLevelItem(0).child(0).child(0) + novelTree.clearSelection() + scItem = novelTree.topLevelItem(2) scItem.setSelected(True) assert scItem.isSelected() # Clear selection with mouse - vPort = nwTree.viewport() + vPort = novelTree.viewport() qtbot.mouseClick(vPort, Qt.LeftButton, pos=vPort.rect().center(), delay=10) assert not scItem.isSelected() @@ -94,8 +118,8 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): scItem.setSelected(True) assert scItem.isSelected() assert nwGUI.docEditor.docHandle() is None - nwTree._treeDoubleClick(scItem, 0) - assert nwGUI.docEditor.docHandle() == "8c659a11cd429" + novelTree._treeDoubleClick(scItem, 0) + assert nwGUI.docEditor.docHandle() == "000000000000f" # Open item with middle mouse button scItem.setSelected(True) @@ -104,58 +128,79 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal): qtbot.mouseClick(vPort, Qt.MiddleButton, pos=vPort.rect().center(), delay=10) assert nwGUI.docViewer.docHandle() is None - scRect = nwTree.visualItemRect(scItem) - oldData = scItem.data(nwTree.C_TITLE, Qt.UserRole) - scItem.setData(nwTree.C_TITLE, Qt.UserRole, (None, "", "")) + scRect = novelTree.visualItemRect(scItem) + oldData = scItem.data(novelTree.C_TITLE, novelTree.D_HANDLE) + scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, None) qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) assert nwGUI.docViewer.docHandle() is None - scItem.setData(nwTree.C_TITLE, Qt.UserRole, oldData) + scItem.setData(novelTree.C_TITLE, novelTree.D_HANDLE, oldData) qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) - assert nwGUI.docViewer.docHandle() == "8c659a11cd429" + assert nwGUI.docViewer.docHandle() == "000000000000f" - ## - # Populate Tree - ## + # Last Column + # =========== - # Add weird titles to first file to check hnadling of non-standard - # order of title levels. - writeFile(os.path.join(nwMinimal, "content", "a35baf2e93843.nwd"), ( - "#### Section wo/Scene\n\n" - "### Scene wo/Chapter\n\n" - "## Chapter wo/Title\n\n" - "# Title\n\n" - "#### Section w/Title, wo/Scene\n\n" - "### Scene w/Title, wo/Chapter\n\n" - "## Chapter\n\n" - "#### Section w/Chapter, wo/Scene\n\n" - "### Scene\n\n" - "#### Section\n\n" - )) - nwGUI.rebuildIndex() - nwTree._populateTree() - assert nwTree.topLevelItem(0).text(nwTree.C_TITLE) == "Section wo/Scene" - assert nwTree.topLevelItem(1).text(nwTree.C_TITLE) == "Scene wo/Chapter" - assert nwTree.topLevelItem(2).text(nwTree.C_TITLE) == "Chapter wo/Title" - assert nwTree.topLevelItem(3).text(nwTree.C_TITLE) == "Title" + novelBar.setLastColType(NovelTreeColumn.HIDDEN) + assert novelTree.isColumnHidden(novelTree.C_EXTRA) is True + assert novelTree.lastColType == NovelTreeColumn.HIDDEN + assert novelTree._getLastColumnText("000000000000f", "T000001") == ("", "") - tTitle = nwTree.topLevelItem(3) - assert tTitle.child(0).text(nwTree.C_TITLE) == "Section w/Title, wo/Scene" - assert tTitle.child(1).text(nwTree.C_TITLE) == "Scene w/Title, wo/Chapter" - assert tTitle.child(2).text(nwTree.C_TITLE) == "Chapter" + novelBar.setLastColType(NovelTreeColumn.POV) + assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False + assert novelTree.lastColType == NovelTreeColumn.POV + assert novelTree._getLastColumnText("000000000000f", "T000001") == ( + "Jane", "Point of View: Jane" + ) - tChap = tTitle.child(2) - assert tChap.child(0).text(nwTree.C_TITLE) == "Section w/Chapter, wo/Scene" - assert tChap.child(1).text(nwTree.C_TITLE) == "Scene" + novelBar.setLastColType(NovelTreeColumn.FOCUS) + assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False + assert novelTree.lastColType == NovelTreeColumn.FOCUS + assert novelTree._getLastColumnText("000000000000f", "T000001") == ( + "Jane", "Focus: Jane" + ) - tScene = tChap.child(1) - assert tScene.child(0).text(nwTree.C_TITLE) == "Section" + novelBar.setLastColType(NovelTreeColumn.PLOT) + assert novelTree.isColumnHidden(novelTree.C_EXTRA) is False + assert novelTree.lastColType == NovelTreeColumn.PLOT + assert novelTree._getLastColumnText("000000000000f", "T000001") == ( + "", "Plot: " + ) - ## - # Close - ## + novelTree._lastCol = None + assert novelTree._getLastColumnText("0000000000000", "T000000") == ("", "") - # qtbot.stopForInteraction() + # Item Meta + # ========= + + ttText = "" + + def showText(pos, text): + nonlocal ttText + ttText = text + + mIndex = novelTree.model().index(2, novelTree.C_MORE) + with monkeypatch.context() as mp: + mp.setattr(QToolTip, "showText", showText) + novelTree._treeItemClicked(mIndex) + assert ttText == ( + "

Point of View: Jane
Focus: Jane

" + "

Synopsis: This is a scene.

" + ) + + # Other Checks + # ============ + + scItem = novelTree.topLevelItem(2) + scItem.setSelected(True) + assert scItem.isSelected() + novelTree.focusOutEvent(QFocusEvent(QEvent.None_, Qt.MouseFocusReason)) + assert not scItem.isSelected() + + # Close + # ===== + + # qtbot.stop() nwGUI.closeProject() # END Test testGuiNovelTree_TreeItems diff --git a/tests/test_gui/test_gui_outline.py b/tests/test_gui/test_gui_outline.py index 972e7456..2f33cf7a 100644 --- a/tests/test_gui/test_gui_outline.py +++ b/tests/test_gui/test_gui_outline.py @@ -19,20 +19,144 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +import os +import time import pytest -from PyQt5.QtCore import Qt, QPoint -from PyQt5.QtWidgets import QAction, QTreeWidgetItem, QMessageBox +from tools import buildTestProject, writeFile -from novelwriter.enum import nwOutline +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import QWidget, QMessageBox, QAction -keyDelay = 2 -typeDelay = 1 -stepDelay = 20 +from novelwriter.enum import nwItemClass, nwOutline, nwView @pytest.mark.gui -def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum): +def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, fncDir): + """Test the outline view. + """ + # Block message box + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) + + # Create a project + prjDir = os.path.join(fncDir, "project") + buildTestProject(nwGUI, prjDir) + + nwGUI.rebuildIndex() + nwGUI._changeView(nwView.OUTLINE) + + outlineView = nwGUI.outlineView + outlineTree = outlineView.outlineTree + outlineData = outlineView.outlineData + outlineMenu = outlineView.outlineBar.mColumns + + # Toggle scrollbars + nwGUI.mainConf.hideVScroll = True + nwGUI.mainConf.hideHScroll = True + outlineView.initSettings() + assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff + assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff + assert outlineData.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff + assert outlineData.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff + + nwGUI.mainConf.hideVScroll = False + nwGUI.mainConf.hideHScroll = False + outlineView.initSettings() + assert outlineTree.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded + assert outlineTree.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded + assert outlineData.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded + assert outlineData.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded + + # Check focus + with monkeypatch.context() as mp: + mp.setattr(QWidget, "hasFocus", lambda *a: True) + assert outlineView.treeHasFocus() is True + + outlineView.setTreeFocus() # Can't check. just ensures that it doesn't error + + # Option State + # ============ + pOptions = nwGUI.theProject.options + colNames = [h.name for h in nwOutline] + colItems = [h for h in nwOutline] + colWidth = {h: outlineTree.DEF_WIDTH[h] for h in nwOutline} + colHidden = {h: outlineTree.DEF_HIDDEN[h] for h in nwOutline} + + assert outlineTree.topLevelItemCount() > 0 + + # Save header state not allowed + outlineTree._lastBuild = 0 + outlineTree._saveHeaderState() + assert pOptions.getValue("GuiOutline", "headerOrder", []) == [] + + # Allow saving header state + outlineTree._lastBuild = time.time() + outlineTree._saveHeaderState() + assert pOptions.getValue("GuiOutline", "headerOrder", []) == colNames + assert outlineTree._treeOrder == colItems + assert outlineTree._colWidth == colWidth + assert outlineTree._colHidden == colHidden + + # Get default values + optItems = pOptions.getValue("GuiOutline", "headerOrder", []) + optWidth = pOptions.getValue("GuiOutline", "columnWidth", {}) + optHidden = pOptions.getValue("GuiOutline", "columnHidden", {}) + + # Add invalid column name + pOptions.setValue("GuiOutline", "headerOrder", optItems + ["blabla"]) + outlineTree._loadHeaderState() + assert outlineTree._treeOrder == colItems + assert outlineTree._colHidden == colHidden + + # Add duplicate column name + pOptions.setValue("GuiOutline", "headerOrder", optItems + [optItems[-1]]) + outlineTree._loadHeaderState() + assert outlineTree._treeOrder == colItems + assert outlineTree._colHidden == colHidden + + # Invalid column width data + pOptions.setValue("GuiOutline", "headerOrder", optItems) + pOptions.setValue("GuiOutline", "columnWidth", {"blabla": None}) + outlineTree._loadHeaderState() + assert outlineTree._treeOrder == colItems + assert outlineTree._colHidden == colHidden + + # Invalid column width data + pOptions.setValue("GuiOutline", "headerOrder", optItems) + pOptions.setValue("GuiOutline", "columnWidth", optWidth) + pOptions.setValue("GuiOutline", "columnHidden", {"bloabla": None}) + outlineTree._loadHeaderState() + assert outlineTree._treeOrder == colItems + assert outlineTree._colHidden == colHidden + + # Valid settings + pOptions.setValue("GuiOutline", "headerOrder", optItems) + pOptions.setValue("GuiOutline", "columnWidth", optWidth) + pOptions.setValue("GuiOutline", "columnHidden", optHidden) + outlineTree._loadHeaderState() + assert outlineTree._treeOrder == colItems + assert outlineTree._colHidden == colHidden + + # Header Menu + # =========== + + # Trigger the menu entry for all hidden columns + for hItem in nwOutline: + if outlineTree.DEF_HIDDEN[hItem]: + outlineMenu.actionMap[hItem].activate(QAction.Trigger) + + # Now no columns should be hidden + outlineTree._saveHeaderState() + assert not any(pOptions.getValue("GuiOutline", "columnHidden", None).values()) + + # qtbot.stop() + +# END Test testGuiOutline_Main + + +@pytest.mark.gui +def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, nwLipsum): """Test the outline view. """ # Block message box @@ -43,73 +167,104 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum): nwGUI.mainConf.lastPath = nwLipsum nwGUI.rebuildIndex() - nwGUI.mainTabs.setCurrentIndex(nwGUI.idxTabProj) + nwGUI._changeView(nwView.OUTLINE) - assert nwGUI.projView.topLevelItemCount() > 0 + outlineView = nwGUI.outlineView + outlineBar = outlineView.outlineBar + outlineTree = outlineView.outlineTree + outlineData = outlineView.outlineData - # Context Menu - nwGUI.projView._headerRightClick(QPoint(1, 1)) - nwGUI.projView.headerMenu.actionMap[nwOutline.CCOUNT].activate(QAction.Trigger) - nwGUI.projView.headerMenu.close() - qtbot.mouseClick(nwGUI.projView, Qt.LeftButton) + lipHandle = "b3643d0f92e32" - nwGUI.projView._loadHeaderState() - assert not nwGUI.projView._colHidden[nwOutline.CCOUNT] + # Check defaults in dropdown list + assert outlineBar.novelValue.itemData(0) == lipHandle + assert outlineBar.novelValue.itemData(1) is None # Separator + assert outlineBar.novelValue.itemData(2) == "" # All novels + + # Add a second novel folder + newHandle = nwGUI.theProject.newRoot(nwItemClass.NOVEL) + nwGUI.projView.revealNewTreeItem(newHandle) + + # Check new values in dropdown list + assert outlineBar.novelValue.itemData(0) == lipHandle + assert outlineBar.novelValue.itemData(1) == newHandle + assert outlineBar.novelValue.itemData(2) is None # Separator + assert outlineBar.novelValue.itemData(3) == "" # All novels + + # Add a bunch of files in a header order that hits all tree combos + docList = [ + ("Section 1", 4), ("Scene 1", 3), ("Chapter 1", 2), ("Part 1", 1), + ("Section 2", 4), ("Scene 2", 3), ("Chapter 2", 2), + ("Section 3", 4), ("Scene 3", 3), + ("Section 4", 4), + ] + for dTitle, hLevel in docList: + aHandle = nwGUI.theProject.newFile(dTitle, newHandle) + hHash = "#"*hLevel + writeFile(os.path.join(nwLipsum, "content", f"{aHandle}.nwd"), f"{hHash} {dTitle}\n\n") + nwGUI.projView.revealNewTreeItem(aHandle) + + nwGUI.rebuildIndex() + + # Build the second novel + outlineBar.novelValue.setCurrentIndex(1) + outlineBar._refreshRequested() + + # Go back to Lipsum + outlineBar.novelValue.setCurrentIndex(0) + outlineBar._refreshRequested() + + # Check Details + # ============= # First Item - nwGUI.rebuildOutline() - selItem = nwGUI.projView.topLevelItem(0) - assert isinstance(selItem, QTreeWidgetItem) + outlineTree.refreshTree() + selItem = outlineTree.topLevelItem(0) - nwGUI.projView.setCurrentItem(selItem) - assert nwGUI.projMeta.titleLabel.text() == "Title" - assert nwGUI.projMeta.titleValue.text() == "Lorem Ipsum" - assert nwGUI.projMeta.fileValue.text() == "Lorem Ipsum" - assert nwGUI.projMeta.itemValue.text() == "Finished" + outlineTree.setCurrentItem(selItem) + assert outlineData.titleLabel.text() == "Title" + assert outlineData.titleValue.text() == "Lorem Ipsum" + assert outlineData.fileValue.text() == "Lorem Ipsum" + assert outlineData.itemValue.text() == "Finished" - assert nwGUI.projMeta.cCValue.text() == "230" - assert nwGUI.projMeta.wCValue.text() == "40" - assert nwGUI.projMeta.pCValue.text() == "3" + assert outlineData.cCValue.text() == "230" + assert outlineData.wCValue.text() == "40" + assert outlineData.pCValue.text() == "3" # Scene One - actItem = nwGUI.projView.topLevelItem(1) - chpItem = actItem.child(0) - selItem = chpItem.child(0) + selItem = outlineTree.topLevelItem(4) - nwGUI.projView.setCurrentItem(selItem) - tHandle, tLine = nwGUI.projView.getSelectedHandle() + outlineTree.setCurrentItem(selItem) + tHandle, tLine = outlineTree.getSelectedHandle() assert tHandle == "88243afbe5ed8" assert tLine == 0 - assert nwGUI.projMeta.titleLabel.text() == "Scene" - assert nwGUI.projMeta.titleValue.text() == "Scene One" - assert nwGUI.projMeta.fileValue.text() == "Scene One" - assert nwGUI.projMeta.itemValue.text() == "Finished" + assert outlineData.titleLabel.text() == "Scene" + assert outlineData.titleValue.text() == "Scene One" + assert outlineData.fileValue.text() == "Scene One" + assert outlineData.itemValue.text() == "Finished" # Click POV Link - assert nwGUI.projMeta.povKeyValue.text() == "
Bod" - nwGUI.projMeta._tagClicked("#pov=Bod") + assert outlineData.povKeyValue.text() == "Bod" + outlineView._tagClicked("Bod") assert nwGUI.docViewer.docHandle() == "4c4f28287af27" # Scene One, Section Two - actItem = nwGUI.projView.topLevelItem(1) - chpItem = actItem.child(0) - scnItem = chpItem.child(0) - selItem = scnItem.child(0) + selItem = outlineTree.topLevelItem(5) - nwGUI.projView.setCurrentItem(selItem) - tHandle, tLine = nwGUI.projView.getSelectedHandle() + outlineTree.setCurrentItem(selItem) + tHandle, tLine = outlineTree.getSelectedHandle() assert tHandle == "88243afbe5ed8" assert tLine == 12 - assert nwGUI.projMeta.titleLabel.text() == "Section" - assert nwGUI.projMeta.titleValue.text() == "Scene One, Section Two" - assert nwGUI.projMeta.fileValue.text() == "Scene One" - assert nwGUI.projMeta.itemValue.text() == "Finished" + assert outlineData.titleLabel.text() == "Section" + assert outlineData.titleValue.text() == "Scene One, Section Two" + assert outlineData.fileValue.text() == "Scene One" + assert outlineData.itemValue.text() == "Finished" - nwGUI.projView._treeDoubleClick(selItem, 0) + outlineTree._treeDoubleClick(selItem, 0) assert nwGUI.docEditor.docHandle() == "88243afbe5ed8" - # qtbot.stopForInteraction() + # qtbot.stop() -# END Test testGuiOutline_Main +# END Test testGuiOutline_Content diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 445bfb9a..feef859d 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -22,218 +22,528 @@ along with this program. If not, see . import pytest import os -from tools import writeFile +from tools import buildTestProject -from PyQt5.QtCore import QItemSelectionModel -from PyQt5.QtWidgets import QAction, QMessageBox +from PyQt5.QtWidgets import QMessageBox, QMenu -from novelwriter.guimain import GuiMain +from novelwriter.enum import nwItemLayout, nwItemType, nwItemClass +from novelwriter.dialogs import GuiEditLabel from novelwriter.gui.projtree import GuiProjectTree -from novelwriter.enum import nwItemType, nwItemClass @pytest.mark.gui -def testGuiProjTree_TreeItems(qtbot, caplog, monkeypatch, nwGUI, nwMinimal): +def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd): """Test adding and removing items from the project tree. """ # Block message box - monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiMain, "editItem", lambda *a: None) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) - nwGUI.theProject.projTree.setSeed(42) - nwTree = nwGUI.treeView + nwTree = nwGUI.projView - ## - # Add New Items - ## + # Try to add item with no project + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is False - # Try to add and move item with no project - assert not nwTree.newTreeItem(nwItemType.FILE, None) - assert not nwTree.moveTreeItem(1) + # Create a project + prjDir = os.path.join(fncDir, "project") + buildTestProject(nwGUI, prjDir) - # Open a project - assert nwGUI.openProject(nwMinimal) + # No itemType set + nwTree.projTree.clearSelection() + assert nwTree.projTree.newTreeItem(None) is False + + # Root Items + # ========== + + # No class set + assert nwTree.projTree.newTreeItem(nwItemType.ROOT) is False + + # Create root item + assert nwTree.projTree.newTreeItem(nwItemType.ROOT, nwItemClass.WORLD) is True + assert "0000000000010" in nwGUI.theProject.tree + + # File/Folder Items + # ================= # No location selected for new item - nwTree.clearSelection() - assert not nwTree.newTreeItem(nwItemType.FILE, None) - assert not nwTree.newTreeItem(nwItemType.FOLDER, None) - assert nwTree.newTreeItem(nwItemType.FILE, nwItemClass.NOVEL) + nwTree.projTree.clearSelection() + caplog.clear() + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is False + assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is False + assert "Did not find anywhere" in caplog.text - # No itemType set or ROOT, but no class - assert not nwTree.newTreeItem(None, None) - assert not nwTree.newTreeItem(nwItemType.ROOT, None) + # Create new folder as child of Novel folder + nwTree.setSelectedHandle("0000000000008") + assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is True + assert nwGUI.theProject.tree["0000000000011"].itemParent == "0000000000008" + assert nwGUI.theProject.tree["0000000000011"].itemRoot == "0000000000008" + assert nwGUI.theProject.tree["0000000000011"].itemClass == nwItemClass.NOVEL - # Select a location - chItem = nwTree._getTreeItem("a6d311a93600a") - nwTree.setCurrentItem(chItem, QItemSelectionModel.Current) - chItem.setExpanded(True) + # Add a new file in the new folder + nwTree.setSelectedHandle("0000000000011") + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwGUI.theProject.tree["0000000000012"].itemParent == "0000000000011" + assert nwGUI.theProject.tree["0000000000012"].itemRoot == "0000000000008" + assert nwGUI.theProject.tree["0000000000012"].itemClass == nwItemClass.NOVEL - # Create new item with no class set (defaults to NOVEL) - assert nwTree.newTreeItem(nwItemType.FILE, None) - assert nwTree.newTreeItem(nwItemType.FOLDER, None) + # Add a new chapter next to the other new file + nwTree.setSelectedHandle("0000000000012") + assert nwTree.projTree.newTreeItem(nwItemType.FILE, hLevel=2) is True + assert nwGUI.theProject.tree["0000000000013"].itemParent == "0000000000011" + assert nwGUI.theProject.tree["0000000000013"].itemRoot == "0000000000008" + assert nwGUI.theProject.tree["0000000000013"].itemClass == nwItemClass.NOVEL + assert nwGUI.openDocument("0000000000013") + assert nwGUI.docEditor.getText() == "## New Chapter\n\n" - # Check that we have the correct tree order - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "8c659a11cd429", "44cb730c42048", "71ee45a3c0db9" - ] + # Add a new scene next to the other new file + nwTree.setSelectedHandle("0000000000012") + assert nwTree.projTree.newTreeItem(nwItemType.FILE, hLevel=3) is True + assert nwGUI.theProject.tree["0000000000014"].itemParent == "0000000000011" + assert nwGUI.theProject.tree["0000000000014"].itemRoot == "0000000000008" + assert nwGUI.theProject.tree["0000000000014"].itemClass == nwItemClass.NOVEL + assert nwGUI.openDocument("0000000000014") + assert nwGUI.docEditor.getText() == "### New Scene\n\n" - # Add roots - assert not nwTree.newTreeItem(nwItemType.ROOT, nwItemClass.WORLD) # Duplicate - assert nwTree.newTreeItem(nwItemType.ROOT, nwItemClass.CUSTOM) # Valid + # Add a new file to the characters folder + nwTree.setSelectedHandle("000000000000a") + assert nwTree.projTree.newTreeItem(nwItemType.FILE, hLevel=1, isNote=True) is True + assert nwGUI.theProject.tree["0000000000015"].itemParent == "000000000000a" + assert nwGUI.theProject.tree["0000000000015"].itemRoot == "000000000000a" + assert nwGUI.theProject.tree["0000000000015"].itemClass == nwItemClass.CHARACTER + assert nwGUI.openDocument("0000000000015") + assert nwGUI.docEditor.getText() == "# New Note\n\n" - # Change max depth and try to add a subfolder that is too deep - monkeypatch.setattr("novelwriter.constants.nwConst.MAX_DEPTH", 2) - chItem = nwTree._getTreeItem("71ee45a3c0db9") - nwTree.setCurrentItem(chItem, QItemSelectionModel.Current) - assert not nwTree.newTreeItem(nwItemType.FOLDER, None) + # Make sure the sibling folder bug trap works + nwTree.setSelectedHandle("0000000000013") + nwGUI.theProject.tree["0000000000013"].setParent(None) # This should not happen + caplog.clear() + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is False + assert "Internal error" in caplog.text + nwGUI.theProject.tree["0000000000013"].setParent("0000000000011") - ## - # Move Items - ## + # Cancel during creation + with monkeypatch.context() as mp: + mp.setattr(GuiEditLabel, "getLabel", lambda *a, **k: ("", False)) + nwTree.setSelectedHandle("0000000000013") + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is False - nwTree.setSelectedHandle("8c659a11cd429") + # Get the trash folder + nwTree.projTree._addTrashRoot() + trashHandle = nwGUI.theProject.trashFolder() + nwTree.setSelectedHandle(trashHandle) + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is False + assert "Cannot add new files or folders to the Trash folder" in caplog.text - # Shift focus and try to move item - monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: False) - assert not nwTree.moveTreeItem(1) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "8c659a11cd429", "44cb730c42048", "71ee45a3c0db9" - ] - monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) + # Other Checks + # ============ - # Move second item up twice (should give same result) - nwGUI.mainMenu.aMoveUp.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "8c659a11cd429", "f5ab3e30151e1", "44cb730c42048", "71ee45a3c0db9" - ] - nwGUI.mainMenu.aMoveUp.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "8c659a11cd429", "f5ab3e30151e1", "44cb730c42048", "71ee45a3c0db9" - ] + # Also check error handling in reveal function + assert nwTree.revealNewTreeItem("abc") is False - # Move it back down four times (last two should be the same) - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "8c659a11cd429", "44cb730c42048", "71ee45a3c0db9" - ] - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "44cb730c42048", "8c659a11cd429", "71ee45a3c0db9" - ] - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "44cb730c42048", "71ee45a3c0db9", "8c659a11cd429" - ] - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "44cb730c42048", "71ee45a3c0db9", "8c659a11cd429" - ] - - # Move up twice, and undo - nwTree._lastMove = {} - nwGUI.mainMenu.aMoveUp.activate(QAction.Trigger) - nwGUI.mainMenu.aMoveUp.activate(QAction.Trigger) - nwGUI.mainMenu.aMoveUndo.activate(QAction.Trigger) - assert nwTree.getTreeFromHandle("a6d311a93600a") == [ - "a6d311a93600a", "f5ab3e30151e1", "44cb730c42048", "71ee45a3c0db9", "8c659a11cd429" - ] - - # Move a root item (top level items are different) twice - nwTree.flushTreeOrder() - assert nwGUI.theProject.projTree._treeOrder.index("9d5247ab588e0") == 10 - nwTree.setSelectedHandle("9d5247ab588e0") - - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - nwTree.flushTreeOrder() - assert nwGUI.theProject.projTree._treeOrder.index("9d5247ab588e0") == 11 - - nwGUI.mainMenu.aMoveDown.activate(QAction.Trigger) - nwTree.flushTreeOrder() - assert nwGUI.theProject.projTree._treeOrder.index("9d5247ab588e0") == 11 - - ## - # Delete and Trash - ## - - # Add some content to the new file - nwGUI.openDocument("73475cb40a568") - nwGUI.docEditor.setText("# Hello World\n") - nwGUI.saveDocument() - nwGUI.saveProject() - assert os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd")) - - # Delete the items we added earlier - nwTree.clearSelection() - assert not nwTree.emptyTrash() # No folder yet - assert not nwTree.deleteItem(None) - assert not nwTree.deleteItem("1111111111111") - assert nwTree.deleteItem("73475cb40a568") # New File - assert nwTree.deleteItem("71ee45a3c0db9") # New Folder - assert nwTree.deleteItem("811786ad1ae74") # Custom Root - assert "73475cb40a568" in nwGUI.theProject.projTree._treeOrder - assert "71ee45a3c0db9" not in nwGUI.theProject.projTree._treeOrder - assert "811786ad1ae74" not in nwGUI.theProject.projTree._treeOrder - - # The file is in trash, empty it - assert os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd")) - assert nwTree.emptyTrash() - assert not nwTree.emptyTrash() # Already empty - assert not os.path.isfile(os.path.join(nwMinimal, "content", "73475cb40a568.nwd")) - assert "73475cb40a568" not in nwGUI.theProject.projTree._treeOrder - - # Should not be allowed to add files and folders to Trash - trashHandle = nwGUI.theProject.projTree.trashRoot() - chItem = nwTree._getTreeItem(trashHandle) - nwTree.setCurrentItem(chItem, QItemSelectionModel.Current) - assert not nwTree.newTreeItem(nwItemType.FILE, None) - assert not nwTree.newTreeItem(nwItemType.FOLDER, None) - - # Close the project - nwGUI.closeProject() - - ## - # Orphaned Files - ## - - # Add an orphaned file - orphFile = os.path.join(nwMinimal, "content", "1234567890abc.nwd") - writeFile(orphFile, "# Hello World\n") - - # Open the project again - nwGUI.openProject(nwMinimal) - - # Check that the orphaned file was found and added to the tree - nwTree.flushTreeOrder() - assert "1234567890abc" in nwGUI.theProject.projTree._treeOrder - orItem = nwTree._getTreeItem("1234567890abc") - assert orItem.text(nwTree.C_NAME) == "Recovered File 1" - - ## - # Unexpected Error Handling - ## - - # Add an item with an invalid type - assert not nwTree.newTreeItem(nwItemType.NO_TYPE, nwItemClass.NOVEL) - assert "Failed to add new item" in caplog.messages[-1] - - # Add new file after one that has no parent handle - chItem = nwTree._getTreeItem("44cb730c42048") - nwTree.setCurrentItem(chItem, QItemSelectionModel.Current) - nwTree.theProject.projTree["44cb730c42048"]._parent = None - assert not nwTree.newTreeItem(nwItemType.FILE, nwItemClass.NOVEL) - nwTree.clearSelection() - - # Add a file with no parent, and fail to find a suitable parent item - monkeypatch.setattr("novelwriter.core.tree.NWTree.findRoot", lambda *a: None) - - assert not nwTree.newTreeItem(nwItemType.FILE, nwItemClass.NOVEL) - assert not nwTree.newTreeItem(nwItemType.FOLDER, nwItemClass.NOVEL) + # Add an item that cannot be displayed in the tree + nHandle = nwGUI.theProject.newFile("Test", None) + assert nwTree.revealNewTreeItem(nHandle) is False + # Clean up # qtbot.stopForInteraction() nwGUI.closeProject() -# END Test testGuiProjTree_TreeItems +# END Test testGuiProjTree_NewItems + + +@pytest.mark.gui +def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, fncDir, mockRnd): + """Test adding and removing items from the project tree. + """ + # Block message box + monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) + + nwTree = nwGUI.projView + + # Try to move item with no project + assert nwTree.projTree.moveTreeItem(1) is False + + # Create a project + prjDir = os.path.join(fncDir, "project") + buildTestProject(nwGUI, prjDir) + + # Move Documents + # ============== + + # Add some files + nwTree.setSelectedHandle("000000000000d") + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Move with no selections + nwTree.projTree.clearSelection() + assert nwTree.projTree.moveTreeItem(1) is False + + # Move second item up twice (should give same result) + nwTree.setSelectedHandle("000000000000f") + assert nwTree.projTree.moveTreeItem(-1) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000f", "000000000000e", + "0000000000010", "0000000000011", "0000000000012", + ] + assert nwTree.projTree.moveTreeItem(-1) is False + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000f", "000000000000e", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Restore + assert nwTree.projTree.moveTreeItem(1) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Move fifth item down twice (should give same result) + nwTree.setSelectedHandle("0000000000011") + assert nwTree.projTree.moveTreeItem(1) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000012", "0000000000011", + ] + assert nwTree.projTree.moveTreeItem(1) is False + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000012", "0000000000011", + ] + + # Restore + assert nwTree.projTree.moveTreeItem(-1) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Move down again, and restore via undo + nwTree.setSelectedHandle("0000000000011") + assert nwTree.projTree.moveTreeItem(1) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000012", "0000000000011", + ] + assert nwTree.projTree.undoLastMove() is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Root Folder + # =========== + + nwTree.setSelectedHandle("0000000000008") + assert nwGUI.theProject.tree._treeOrder.index("0000000000008") == 0 + + # Move novel folder up + assert nwTree.projTree.moveTreeItem(-1) is False + assert nwGUI.theProject.tree._treeOrder.index("0000000000008") == 0 + + # Move novel folder down + assert nwTree.projTree.moveTreeItem(1) is True + assert nwGUI.theProject.tree._treeOrder.index("0000000000008") == 1 + + # Move novel folder up again + assert nwTree.projTree.moveTreeItem(-1) is True + assert nwGUI.theProject.tree._treeOrder.index("0000000000008") == 0 + + # Clean up + # qtbot.stopForInteraction() + nwGUI.closeProject() + +# END Test testGuiProjTree_MoveItems + + +@pytest.mark.gui +def testGuiProjTree_DeleteItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd): + """Test adding and removing items from the project tree. + """ + # Block message box + monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) + + nwTree = nwGUI.projView + + # Try to run with no project + assert nwTree.emptyTrash() is False + assert nwTree.deleteItem() is False + + # Create a project + prjDir = os.path.join(fncDir, "project") + buildTestProject(nwGUI, prjDir) + + # Try emptying the trash already now, when there is no trash folder + assert nwTree.emptyTrash() is False + + # Add some files + nwTree.setSelectedHandle("000000000000d") + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010", "0000000000011", "0000000000012", + ] + + # Delete item without focus -> blocked + monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: False) + nwTree.setSelectedHandle("0000000000012") + assert nwTree.deleteItem() is False + monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) + + # No selection made + nwTree.projTree.clearSelection() + caplog.clear() + assert nwTree.deleteItem() is False + assert "no item to delete" in caplog.text + + # Not a valid handle + nwTree.projTree.clearSelection() + caplog.clear() + assert nwTree.deleteItem("0000000000000") is False + assert "Could not find tree item" in caplog.text + + # Delete Folder/Root + # ================== + + # Deleting non-empty folders is blocked + assert nwTree.deleteItem("0000000000008") is False # Novel Root + assert nwTree.deleteItem("000000000000a") is True # Character Root + + # Delete File + # =========== + + # Block adding trash folder + funcPointer = nwTree.projTree._addTrashRoot + nwTree.projTree._addTrashRoot = lambda *a: None + assert nwTree.deleteItem("0000000000012") is False + nwTree.projTree._addTrashRoot = funcPointer + + # Delete last two documents, which also adds the trash folder + assert nwTree.deleteItem("0000000000012") is True + assert nwTree.deleteItem("0000000000011") is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e", "000000000000f", + "0000000000010" + ] + trashHandle = nwGUI.theProject.tree.trashRoot() + assert nwTree.getTreeFromHandle(trashHandle) == [ + trashHandle, "0000000000012", "0000000000011" + ] + + # Delete the first file again (permanent), and ask for permission + # Also open the document in the editor, which should trigger a close + assert os.path.isfile(os.path.join(prjDir, "content", "0000000000012.nwd")) + assert "0000000000012" in nwGUI.theProject.tree + assert nwGUI.docEditor.docHandle() is None + assert nwGUI.openDocument("0000000000012") is True + assert nwGUI.docEditor.docHandle() == "0000000000012" + assert nwTree.deleteItem("0000000000012") is True + assert nwGUI.docEditor.docHandle() is None + assert not os.path.isfile(os.path.join(prjDir, "content", "0000000000012.nwd")) + assert "0000000000012" not in nwGUI.theProject.tree + assert nwTree.getTreeFromHandle(trashHandle) == [ + trashHandle, "0000000000011" + ] + + # Delete the second file, and skip asking for permission + assert os.path.isfile(os.path.join(prjDir, "content", "0000000000011.nwd")) + assert "0000000000011" in nwGUI.theProject.tree + assert nwTree.deleteItem("0000000000011", alreadyAsked=True) is True + assert not os.path.isfile(os.path.join(prjDir, "content", "0000000000011.nwd")) + assert "0000000000011" not in nwGUI.theProject.tree + assert nwTree.getTreeFromHandle(trashHandle) == [trashHandle] + + # Delete Folder + # ============= + + trashHandle = nwGUI.theProject.tree.trashRoot() + + # Add a folder with two files + nwTree.setSelectedHandle("0000000000009") + assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is True + nwTree.setSelectedHandle("0000000000014") + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.projTree.newTreeItem(nwItemType.FILE) is True + assert os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000015.nwd")) + assert os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000016.nwd")) + + # Delete the folder, which moves everything to Trash + assert nwTree.getTreeFromHandle("0000000000014") == [ + "0000000000014", "0000000000015", "0000000000016" + ] + assert nwTree.deleteItem("0000000000014") is True + assert nwTree.getTreeFromHandle(trashHandle) == [ + trashHandle, "0000000000014", "0000000000015", "0000000000016" + ] + assert os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000015.nwd")) + assert os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000016.nwd")) + + # Delete again, which should delete folder and all files + assert nwTree.deleteItem("0000000000014") is True + assert nwTree.getTreeFromHandle(trashHandle) == [trashHandle] + assert not os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000015.nwd")) + assert not os.path.isfile(os.path.join(fncDir, "project", "content", "0000000000016.nwd")) + + # Add an empty folder, which can be deleted with no further restrictions + nwTree.setSelectedHandle("0000000000009") + assert nwTree.projTree.newTreeItem(nwItemType.FOLDER) is True + assert nwTree.getTreeFromHandle("0000000000009") == ["0000000000009", "0000000000017"] + + nwTree.setSelectedHandle("0000000000017") + assert nwTree.deleteItem("0000000000017") is True + assert nwTree.getTreeFromHandle("0000000000009") == ["0000000000009"] + + # Empty Trash + # =========== + + # Try to empty trash that is already empty + assert nwTree.getTreeFromHandle(trashHandle) == [trashHandle] + assert nwTree.emptyTrash() is False + + # Move the two remaining scene documents to trash + assert nwTree.deleteItem("000000000000f") is True + assert nwTree.deleteItem("0000000000010") is True + assert nwTree.getTreeFromHandle("000000000000d") == [ + "000000000000d", "000000000000e" + ] + assert nwTree.getTreeFromHandle(trashHandle) == [ + trashHandle, "000000000000f", "0000000000010" + ] + + # Empty trash, but select no on question + with monkeypatch.context() as mp: + mp.setattr(QMessageBox, "question", lambda *a: QMessageBox.No) + assert nwTree.emptyTrash() is False + + # Empty the trash proper + assert nwTree.emptyTrash() is True + assert nwTree.getTreeFromHandle(trashHandle) == [trashHandle] + + # Try to delete a file, but block the underlying deletion of the file on disk + assert os.path.isfile(os.path.join(fncDir, "project", "content", "000000000000e.nwd")) + with monkeypatch.context() as mp: + mp.setattr("novelwriter.core.document.NWDoc.deleteDocument", lambda *a: False) + assert nwTree.deleteItem("000000000000e") is True + assert nwTree.deleteItem("000000000000e") is True + assert os.path.isfile(os.path.join(fncDir, "project", "content", "000000000000e.nwd")) + + # Delete proper + assert nwTree.projTree._deleteTreeItem("000000000000e") is True + assert not os.path.isfile(os.path.join(fncDir, "project", "content", "000000000000e.nwd")) + + # Clean up + # qtbot.stopForInteraction() + nwGUI.closeProject() + +# END Test testGuiProjTree_DeleteItems + + +@pytest.mark.gui +def testGuiProjTree_ContextMenu(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd): + """Test the building of the project tree context menu. All this does + is test that the menu builds. It doesn't open the actual menu, + """ + # Block message box + monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True)) + monkeypatch.setattr(QMenu, "exec_", lambda *a: None) + + # Create a project + prjDir = os.path.join(fncDir, "project") + buildTestProject(nwGUI, prjDir) + + # Handles for new objects + hNovelRoot = "0000000000008" + hTitlePage = "000000000000c" + hChapterDir = "000000000000d" + hChapterFile = "000000000000e" + hCharRoot = "000000000000a" + hCharNote = "0000000000011" + hNovelNote = "0000000000012" + + projTree = nwGUI.projView.projTree + projTree._getTreeItem(hNovelRoot).setExpanded(True) + projTree._getTreeItem(hChapterDir).setExpanded(True) + + projTree._addTrashRoot() + hTrashRoot = projTree.theProject.tree.trashRoot() + + projTree.setSelectedHandle(hCharRoot) + projTree.newTreeItem(nwItemType.FILE) + projTree.setSelectedHandle(hNovelRoot) + projTree.newTreeItem(nwItemType.FILE, isNote=True) + + def itemPos(tHandle): + return projTree.visualItemRect(projTree._getTreeItem(tHandle)).center() + + # No item under menu + assert projTree._openContextMenu(projTree.viewport().rect().bottomRight()) is False + + # Generate the possible menu combinarions + assert projTree._openContextMenu(itemPos(hTrashRoot)) is True + assert projTree._openContextMenu(itemPos(hNovelRoot)) is True + assert projTree._openContextMenu(itemPos(hNovelNote)) is True + assert projTree._openContextMenu(itemPos(hTitlePage)) is True + assert projTree._openContextMenu(itemPos(hChapterDir)) is True + assert projTree._openContextMenu(itemPos(hChapterFile)) is True + assert projTree._openContextMenu(itemPos(hCharRoot)) is True + assert projTree._openContextMenu(itemPos(hCharNote)) is True + + # Check the keyboard shortcut handler as well + projTree.setSelectedHandle(hNovelRoot) + assert projTree.openContextOnSelected() is True + projTree.clearSelection() + assert projTree.openContextOnSelected() is False + + # Direct Edit Functions + # ===================== + # Trigger the dedicated functions the menu entries connect to + nwItem = projTree.theProject.tree[hNovelNote] + + # Toggle exported flag + assert nwItem.isExported is True + projTree._toggleItemExported(hNovelNote) + assert nwItem.isExported is False + + # Change item status + assert nwItem.itemStatus == "s000000" + projTree._changeItemStatus(hNovelNote, "s000001") + assert nwItem.itemStatus == "s000001" + + # Change item importance + assert nwItem.itemImport == "i000004" + projTree._changeItemImport(hNovelNote, "i000005") + assert nwItem.itemImport == "i000005" + + # Change item layout + assert nwItem.itemLayout == nwItemLayout.NOTE + projTree._changeItemLayout(hNovelNote, nwItemLayout.DOCUMENT) + assert nwItem.itemLayout == nwItemLayout.DOCUMENT + projTree._changeItemLayout(hNovelNote, nwItemLayout.NOTE) + assert nwItem.itemLayout == nwItemLayout.NOTE + + # qtbot.stop() + +# END Test testGuiProjTree_ContextMenu diff --git a/tests/test_gui/test_gui_statusbar.py b/tests/test_gui/test_gui_statusbar.py index 9d7c4efc..0c6b1e81 100644 --- a/tests/test_gui/test_gui_statusbar.py +++ b/tests/test_gui/test_gui_statusbar.py @@ -22,24 +22,25 @@ along with this program. If not, see . import time import pytest +from tools import buildTestProject + from PyQt5.QtWidgets import QMessageBox from novelwriter.core import NWDoc -from novelwriter.enum import nwItemClass, nwState +from novelwriter.enum import nwState @pytest.mark.gui -def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, fncProj): +def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): """Test the the various features of the status bar. """ monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) - nwGUI.theProject.projTree.setSeed(42) - assert nwGUI.newProject({"projPath": fncProj}) is True - cHandle = nwGUI.theProject.newFile("A Note", nwItemClass.CHARACTER, "71ee45a3c0db9") + buildTestProject(nwGUI, fncProj) + cHandle = nwGUI.theProject.newFile("A Note", "000000000000a") newDoc = NWDoc(nwGUI.theProject, cHandle) newDoc.writeDocument("# A Note\n\n") - nwGUI.treeView.revealNewTreeItem(cHandle) + nwGUI.projView.revealNewTreeItem(cHandle) nwGUI.rebuildIndex(beQuiet=True) # Reference Time @@ -90,10 +91,10 @@ def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, fncProj): # Project Stats nwGUI.statusBar.mainConf.incNotesWCount = False nwGUI._updateStatusWordCount() - assert nwGUI.statusBar.statsText.text() == "Words: 6 (+6)" + assert nwGUI.statusBar.statsText.text() == "Words: 9 (+9)" nwGUI.statusBar.mainConf.incNotesWCount = True nwGUI._updateStatusWordCount() - assert nwGUI.statusBar.statsText.text() == "Words: 8 (+8)" + assert nwGUI.statusBar.statsText.text() == "Words: 11 (+11)" # qtbot.stopForInteraction() diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index 6adac08e..0014a4da 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -35,6 +35,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): """Test the theme and icon classes. """ # Block message box + monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "warning", lambda *a: QMessageBox.Yes) @@ -80,7 +81,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): assert thePalette.window().color() == QColor(54, 54, 54) assert thePalette.windowText().color() == QColor(174, 174, 174) assert thePalette.base().color() == QColor(62, 62, 62) - assert thePalette.alternateBase().color() == QColor(67, 67, 67) + assert thePalette.alternateBase().color() == QColor(78, 78, 78) assert thePalette.text().color() == QColor(174, 174, 174) assert thePalette.toolTipBase().color() == QColor(255, 255, 192) assert thePalette.toolTipText().color() == QColor(21, 21, 13) @@ -92,82 +93,82 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): assert thePalette.link().color() == QColor(44, 152, 247) assert thePalette.linkVisited().color() == QColor(44, 152, 247) - assert nwGUI.theTheme.statNone == [150, 152, 150] - assert nwGUI.theTheme.statSaved == [39, 135, 78] - assert nwGUI.theTheme.statUnsaved == [138, 32, 32] + assert nwGUI.mainTheme.statNone == [150, 152, 150] + assert nwGUI.mainTheme.statSaved == [39, 135, 78] + assert nwGUI.mainTheme.statUnsaved == [138, 32, 32] # Check Syntax Colours - assert nwGUI.theTheme.colBack == [45, 45, 45] - assert nwGUI.theTheme.colText == [204, 204, 204] - assert nwGUI.theTheme.colLink == [102, 153, 204] - assert nwGUI.theTheme.colHead == [102, 153, 204] - assert nwGUI.theTheme.colHeadH == [102, 153, 204] - assert nwGUI.theTheme.colEmph == [249, 145, 57] - assert nwGUI.theTheme.colDialN == [242, 119, 122] - assert nwGUI.theTheme.colDialD == [153, 204, 153] - assert nwGUI.theTheme.colDialS == [255, 204, 102] - assert nwGUI.theTheme.colHidden == [153, 153, 153] - assert nwGUI.theTheme.colKey == [242, 119, 122] - assert nwGUI.theTheme.colVal == [204, 153, 204] - assert nwGUI.theTheme.colSpell == [242, 119, 122] - assert nwGUI.theTheme.colError == [153, 204, 153] - assert nwGUI.theTheme.colRepTag == [102, 204, 204] - assert nwGUI.theTheme.colMod == [249, 145, 57] + assert nwGUI.mainTheme.colBack == [45, 45, 45] + assert nwGUI.mainTheme.colText == [204, 204, 204] + assert nwGUI.mainTheme.colLink == [102, 153, 204] + assert nwGUI.mainTheme.colHead == [102, 153, 204] + assert nwGUI.mainTheme.colHeadH == [102, 153, 204] + assert nwGUI.mainTheme.colEmph == [249, 145, 57] + assert nwGUI.mainTheme.colDialN == [242, 119, 122] + assert nwGUI.mainTheme.colDialD == [153, 204, 153] + assert nwGUI.mainTheme.colDialS == [255, 204, 102] + assert nwGUI.mainTheme.colHidden == [153, 153, 153] + assert nwGUI.mainTheme.colKey == [242, 119, 122] + assert nwGUI.mainTheme.colVal == [204, 153, 204] + assert nwGUI.mainTheme.colSpell == [242, 119, 122] + assert nwGUI.mainTheme.colError == [153, 204, 153] + assert nwGUI.mainTheme.colRepTag == [102, 204, 204] + assert nwGUI.mainTheme.colMod == [249, 145, 57] # Test Icon class - theIcons = nwGUI.theTheme.theIcons + iconCache = nwGUI.mainTheme.iconCache novelwriter.CONFIG.guiIcons = "invalid" - assert theIcons.updateTheme() is True + assert iconCache.updateTheme() is True assert novelwriter.CONFIG.guiIcons == "typicons_light" # Ask for a non-existent key - anImg = theIcons.loadDecoration("nonsense", 20, 20) + anImg = iconCache.loadDecoration("nonsense", 20, 20) assert isinstance(anImg, QPixmap) assert anImg.isNull() # Add a non-existent file and request it - theIcons.DECO_MAP["nonsense"] = "nofile.jpg" - anImg = theIcons.loadDecoration("nonsense", 20, 20) + iconCache.IMAGE_MAP["nonsense"] = "nofile.jpg" + anImg = iconCache.loadDecoration("nonsense", 20, 20) assert isinstance(anImg, QPixmap) assert anImg.isNull() # Get a real image, with different size parameters - anImg = theIcons.loadDecoration("wiz-back", 20, None) + anImg = iconCache.loadDecoration("wiz-back", 20, None) assert isinstance(anImg, QPixmap) assert not anImg.isNull() assert anImg.width() == 20 assert anImg.height() >= 56 - anImg = theIcons.loadDecoration("wiz-back", None, 70) + anImg = iconCache.loadDecoration("wiz-back", None, 70) assert isinstance(anImg, QPixmap) assert not anImg.isNull() assert anImg.height() == 70 assert anImg.width() >= 24 - anImg = theIcons.loadDecoration("wiz-back", 30, 70) + anImg = iconCache.loadDecoration("wiz-back", 30, 70) assert isinstance(anImg, QPixmap) assert not anImg.isNull() assert anImg.height() == 70 assert anImg.width() == 30 - anImg = theIcons.loadDecoration("wiz-back", None, None) + anImg = iconCache.loadDecoration("wiz-back", None, None) assert isinstance(anImg, QPixmap) assert not anImg.isNull() assert anImg.height() >= 1500 assert anImg.width() >= 500 # Load icons - anIcon = theIcons.getIcon("nonsense") + anIcon = iconCache.getIcon("nonsense") assert isinstance(anIcon, QIcon) assert anIcon.isNull() - anIcon = theIcons.getIcon("novelwriter") + anIcon = iconCache.getIcon("novelwriter") assert isinstance(anIcon, QIcon) assert not anIcon.isNull() # Check return empty icon if file not found - theIcons.ICON_KEYS.add("testicon3") - anIcon = theIcons.getIcon("testicon3") + iconCache.ICON_KEYS.add("testicon3") + anIcon = iconCache.getIcon("testicon3") assert isinstance(anIcon, QIcon) assert anIcon.isNull() diff --git a/tests/test_tools/test_tools_lipsum.py b/tests/test_tools/test_tools_lipsum.py new file mode 100644 index 00000000..629deb56 --- /dev/null +++ b/tests/test_tools/test_tools_lipsum.py @@ -0,0 +1,75 @@ +""" +novelWriter – Lorem Ipsum Tool Tester +===================================== + +This file is a part of novelWriter +Copyright 2018–2022, Veronica Berglyd Olsen + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +import pytest + +from tools import getGuiItem, buildTestProject + +from PyQt5.QtWidgets import QAction, QMessageBox + +from novelwriter.tools import GuiLipsum + + +@pytest.mark.gui +def testToolLipsum_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): + """Test the Lorem Ipsum tool. + """ + # Block message box + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + + # Check that we cannot open when there is no project + nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger) + assert getGuiItem("GuiLipsum") is None + + # Create a new project + buildTestProject(nwGUI, fncProj) + assert nwGUI.openDocument("000000000000f") is True + assert len(nwGUI.docEditor.getText()) == 15 + + # Open the tool + nwGUI.mainMenu.aLipsumText.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiLipsum") is not None, timeout=1000) + + nwLipsum = getGuiItem("GuiLipsum") + assert isinstance(nwLipsum, GuiLipsum) + + # Insert paragraphs + nwGUI.docEditor.setCursorPosition(100) # End of document + nwLipsum.paraCount.setValue(2) + nwLipsum._doInsert() + theText = nwGUI.docEditor.getText() + assert "Lorem ipsum" in theText + assert len(theText) == 965 + + # Insert random paragraph + nwGUI.docEditor.setCursorPosition(1000) # End of document + nwLipsum.randSwitch.setChecked(True) + nwLipsum.paraCount.setValue(1) + nwLipsum._doInsert() + theText = nwGUI.docEditor.getText() + assert len(theText) > 965 + + # Close + nwLipsum._doClose() + + # qtbot.stopForInteraction() + +# END Test testToolLipsum_Main diff --git a/tests/test_tools/test_tools_projwizard.py b/tests/test_tools/test_tools_projwizard.py index 53f1cc79..8839964e 100644 --- a/tests/test_tools/test_tools_projwizard.py +++ b/tests/test_tools/test_tools_projwizard.py @@ -19,14 +19,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -import pytest import os import sys +import pytest from tools import getGuiItem from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QFileDialog, QWizard, QMessageBox +from PyQt5.QtWidgets import QFileDialog, QWizard, QMessageBox, QDialog from novelwriter.enum import nwItemClass from novelwriter.tools.projwizard import ( @@ -41,8 +41,8 @@ stepDelay = 20 @pytest.mark.gui @pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin") -def testToolProjectWizard_Main(qtbot, monkeypatch, nwGUI, nwMinimal): - """Test the new project wizard. +def testToolProjectWizard_Handling(qtbot, monkeypatch, nwGUI, nwMinimal): + """Test the launch of the project wizard. Disabled for macOS because the test segfaults on QWizard.show() """ # Block message box @@ -55,173 +55,207 @@ def testToolProjectWizard_Main(qtbot, monkeypatch, nwGUI, nwMinimal): # New with a project open should cause an error assert nwGUI.openProject(nwMinimal) - assert not nwGUI.newProject() + with monkeypatch.context() as mp: + mp.setattr(nwGUI, "closeProject", lambda *a: False) + assert nwGUI.newProject() is False # Close project, but call with invalid path assert nwGUI.closeProject() with monkeypatch.context() as mp: mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: None) - assert not nwGUI.newProject() + assert nwGUI.newProject() is False # Now, with an empty dictionary mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {}) - assert not nwGUI.newProject() + assert nwGUI.newProject() is False # Now, with a non-empty folder mp.setattr(nwGUI, "showNewProjectDialog", lambda *a: {"projPath": nwMinimal}) - assert not nwGUI.newProject() + assert nwGUI.newProject() is False ## - # Test the Wizard + # Test the Wizard Launching ## - monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None) nwGUI.mainConf.lastPath = " " + monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None) - nwGUI.closeProject() - nwGUI.showNewProjectDialog() + result = nwGUI.showNewProjectDialog() qtbot.waitUntil(lambda: getGuiItem("GuiProjectWizard") is not None, timeout=1000) nwWiz = getGuiItem("GuiProjectWizard") assert isinstance(nwWiz, GuiProjectWizard) nwWiz.show() + qtbot.wait(stepDelay) + qtbot.mouseClick(nwWiz.button(QWizard.CancelButton), Qt.LeftButton) + assert result is None - for wStep in range(4): - # This does not actually create the project, it just generates the - # dictionary that defines it. - - # Intro Page - introPage = nwWiz.currentPage() - assert isinstance(introPage, ProjWizardIntroPage) - assert not nwWiz.button(QWizard.NextButton).isEnabled() - - qtbot.wait(stepDelay) - for c in ("Test Minimal %d" % wStep): - qtbot.keyClick(introPage.projName, c, delay=typeDelay) - - qtbot.wait(stepDelay) - for c in "Minimal Novel": - qtbot.keyClick(introPage.projTitle, c, delay=typeDelay) - - qtbot.wait(stepDelay) - for c in "Jane Doe": - qtbot.keyClick(introPage.projAuthors, c, delay=typeDelay) - - # Setting projName should activate the button - assert nwWiz.button(QWizard.NextButton).isEnabled() - - qtbot.wait(stepDelay) - qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) - - # Folder Page - storagePage = nwWiz.currentPage() - assert isinstance(storagePage, ProjWizardFolderPage) - assert not nwWiz.button(QWizard.NextButton).isEnabled() - - if wStep == 0: - # Check invalid path first, the first time we reach here - monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *a, **kw: "") - qtbot.wait(stepDelay) - qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100) - assert storagePage.projPath.text() == "" - - # Then, we always return nwMinimal as path - monkeypatch.setattr(QFileDialog, "getExistingDirectory", lambda *a, **kw: nwMinimal) - - qtbot.wait(stepDelay) - qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100) - projPath = os.path.join(nwMinimal, "Test Minimal %d" % wStep) - assert storagePage.projPath.text() == projPath - - # Setting projPath should activate the button - assert nwWiz.button(QWizard.NextButton).isEnabled() - - qtbot.wait(stepDelay) - qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) - - # Populate Page - popPage = nwWiz.currentPage() - assert isinstance(popPage, ProjWizardPopulatePage) - assert nwWiz.button(QWizard.NextButton).isEnabled() - - qtbot.wait(stepDelay) - if wStep == 0: - popPage.popMinimal.setChecked(True) - elif wStep == 1: - popPage.popCustom.setChecked(True) - elif wStep == 2: - popPage.popCustom.setChecked(True) - elif wStep == 3: - popPage.popSample.setChecked(True) - - qtbot.wait(stepDelay) - qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) - - # Custom Page - if wStep == 1 or wStep == 2: - customPage = nwWiz.currentPage() - assert isinstance(customPage, ProjWizardCustomPage) - assert nwWiz.button(QWizard.NextButton).isEnabled() - - customPage.addPlot.setChecked(True) - customPage.addChar.setChecked(True) - customPage.addWorld.setChecked(True) - customPage.addTime.setChecked(True) - customPage.addObject.setChecked(True) - customPage.addEntity.setChecked(True) - - if wStep == 2: - customPage.numChapters.setValue(0) - customPage.numScenes.setValue(10) - customPage.chFolders.setChecked(False) - - qtbot.wait(stepDelay) - qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) - - # Final Page - finalPage = nwWiz.currentPage() - assert isinstance(finalPage, ProjWizardFinalPage) - assert nwWiz.button(QWizard.FinishButton).isEnabled() # But we don't click it - - # Check Data - projData = nwGUI._assembleProjectWizardData(nwWiz) - assert projData["projName"] == "Test Minimal %d" % wStep - assert projData["projTitle"] == "Minimal Novel" - assert projData["projAuthors"] == "Jane Doe" - assert projData["projPath"] == projPath - assert projData["popMinimal"] == (wStep == 0) - assert projData["popCustom"] == (wStep == 1 or wStep == 2) - assert projData["popSample"] == (wStep == 3) - if wStep == 1 or wStep == 2: - assert projData["addRoots"] == [ - nwItemClass.PLOT, - nwItemClass.CHARACTER, - nwItemClass.WORLD, - nwItemClass.TIMELINE, - nwItemClass.OBJECT, - nwItemClass.ENTITY, - ] - if wStep == 1: - assert projData["numChapters"] == 5 - assert projData["numScenes"] == 5 - assert projData["chFolders"] - else: - assert projData["numChapters"] == 0 - assert projData["numScenes"] == 10 - assert not projData["chFolders"] - else: - assert projData["addRoots"] == [] - assert projData["numChapters"] == 0 - assert projData["numScenes"] == 0 - assert not projData["chFolders"] - - # Restart the wizard for next iteration - nwWiz.restart() + with monkeypatch.context() as mp: + mp.setattr(GuiProjectWizard, "result", lambda *a: QDialog.Accepted) + result = nwGUI.showNewProjectDialog() + nwWiz.button(QWizard.CancelButton).click() + assert isinstance(result, dict) nwWiz.reject() nwWiz.close() # qtbot.stopForInteraction() -# END Test testToolProjectWizard_Main +# END Test testToolProjectWizard_Handling + + +@pytest.mark.gui +@pytest.mark.parametrize("prjType", ["minimal", "custom1", "custom2", "sample"]) +@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Not running on Darwin") +def testToolProjectWizard_Run(qtbot, monkeypatch, nwGUI, fncDir, prjType): + """Test the new project wizard with a set of selection scenarios. + """ + monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) + monkeypatch.setattr(GuiProjectWizard, "exec_", lambda *a: None) + + nwGUI.mainConf.lastPath = " " + nwWiz = GuiProjectWizard(nwGUI) + nwWiz.show() + qtbot.wait(stepDelay) + + # Intro Page + # ========== + + introPage = nwWiz.currentPage() + assert isinstance(introPage, ProjWizardIntroPage) + assert not nwWiz.button(QWizard.NextButton).isEnabled() + + introPage.projName.setText("Test Wizard") + introPage.projTitle.setText("My Novel") + introPage.projAuthors.setPlainText("Jane Doe") + + # Setting projName should activate the button + assert nwWiz.button(QWizard.NextButton).isEnabled() + + qtbot.wait(stepDelay) + qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) + + # Folder Page + # =========== + + storagePage = nwWiz.currentPage() + assert isinstance(storagePage, ProjWizardFolderPage) + assert not nwWiz.button(QWizard.NextButton).isEnabled() + assert storagePage.errLabel.text() == "" + + # Set an invalid path + storagePage.projPath.setText(os.path.join(fncDir, "not", "a", "path")) + assert not nwWiz.button(QWizard.NextButton).isEnabled() + assert storagePage.errLabel.text().startswith("Error") + + # Set an existing path + storagePage.projPath.setText(fncDir) + assert not nwWiz.button(QWizard.NextButton).isEnabled() + assert storagePage.errLabel.text().startswith("Error") + + # Return a non-result from browse + with monkeypatch.context() as mp: + mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: "") + qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100) + assert storagePage.errLabel.text() == "" + + # Let the browse feature handle it + projPath = os.path.join(fncDir, "Test Wizard") + with monkeypatch.context() as mp: + mp.setattr(QFileDialog, "getExistingDirectory", lambda *a, **k: fncDir) + qtbot.mouseClick(storagePage.browseButton, Qt.LeftButton, delay=100) + + assert storagePage.projPath.text() == projPath + assert storagePage.errLabel.text() == "" + + # Setting projPath should activate the button + assert nwWiz.button(QWizard.NextButton).isEnabled() + + qtbot.wait(stepDelay) + qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) + + # Populate Page + # ============= + + popPage = nwWiz.currentPage() + assert isinstance(popPage, ProjWizardPopulatePage) + assert nwWiz.button(QWizard.NextButton).isEnabled() + + qtbot.wait(stepDelay) + if prjType.startswith("minimal"): + popPage.popMinimal.setChecked(True) + elif prjType.startswith("custom"): + popPage.popCustom.setChecked(True) + elif prjType.startswith("sample"): + popPage.popSample.setChecked(True) + + qtbot.wait(stepDelay) + qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) + + # Custom Page + # =========== + if prjType.startswith("custom"): + + customPage = nwWiz.currentPage() + assert isinstance(customPage, ProjWizardCustomPage) + assert nwWiz.button(QWizard.NextButton).isEnabled() + + customPage.addPlot.setChecked(True) + customPage.addChar.setChecked(True) + customPage.addWorld.setChecked(True) + customPage.addNotes.setChecked(True) + + if prjType == "custom2": + customPage.numChapters.setValue(0) + customPage.numScenes.setValue(10) + + qtbot.wait(stepDelay) + qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton) + + # Final Page + # ========== + + finalPage = nwWiz.currentPage() + assert isinstance(finalPage, ProjWizardFinalPage) + assert nwWiz.button(QWizard.FinishButton).isEnabled() # But we don't click it + + # Check Data + # ========== + + projData = nwGUI._assembleProjectWizardData(nwWiz) + assert projData["projName"] == "Test Wizard" + assert projData["projTitle"] == "My Novel" + assert projData["projAuthors"] == "Jane Doe" + assert projData["projPath"] == projPath + assert projData["popMinimal"] == prjType.startswith("minimal") + assert projData["popCustom"] == prjType.startswith("custom") + assert projData["popSample"] == prjType.startswith("sample") + if prjType.startswith("custom"): + assert projData["addRoots"] == [ + nwItemClass.PLOT, + nwItemClass.CHARACTER, + nwItemClass.WORLD, + ] + if prjType == "custom1": + assert projData["numChapters"] == 5 + assert projData["numScenes"] == 5 + assert projData["addNotes"] is True + else: + assert projData["numChapters"] == 0 + assert projData["numScenes"] == 10 + assert projData["addNotes"] is True + else: + assert projData["addRoots"] == [] + assert projData["numChapters"] == 0 + assert projData["numScenes"] == 0 + assert projData["addNotes"] is False + + # Cleanup + nwWiz.reject() + nwWiz.close() + + # qtbot.stopForInteraction() + +# END Test testToolProjectWizard_Run diff --git a/tests/test_tools/test_tools_writingstats.py b/tests/test_tools/test_tools_writingstats.py index cffef9e6..b7358b20 100644 --- a/tests/test_tools/test_tools_writingstats.py +++ b/tests/test_tools/test_tools_writingstats.py @@ -23,8 +23,8 @@ import pytest import json import os -from tools import getGuiItem, writeFile from mock import causeOSError +from tools import getGuiItem, writeFile, buildTestProject from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox @@ -48,7 +48,7 @@ def testToolWritingStats_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj): monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) # Create a project to work on - assert nwGUI.newProject({"projPath": fncProj}) + buildTestProject(nwGUI, fncProj) qtbot.wait(100) assert nwGUI.saveProject() sessFile = os.path.join(fncProj, "meta", nwFiles.SESS_STATS) diff --git a/tests/tools.py b/tests/tools.py index bd417aae..fcdd3817 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -20,10 +20,13 @@ along with this program. If not, see . """ import os +import time import shutil from PyQt5.QtWidgets import qApp +XML_IGNORE = ("> By Jane DOe <<\n") + + aDoc = NWDoc(theProject, xHandle[7]) + aDoc.writeDocument("## %s\n\n" % theProject.tr("New Chapter")) + + aDoc = NWDoc(theProject, xHandle[8]) + aDoc.writeDocument("### %s\n\n" % theProject.tr("New Scene")) + + theProject.projOpened = time.time() + theProject.setProjectChanged(True) + theProject.saveProject(autoSave=True) + + if theGUI is not None: + theGUI.hasProject = True + theGUI.rebuildTrees() + theGUI.rebuildIndex(beQuiet=True) + + return