| 1 | |
| 2 | # Syntax and comments |
| 3 | |
| 4 | - Use 2 spaces in `.ui` or `.xml` files. |
| 5 | - Good comments explain *why* the code does what it does. If a comment explains |
| 6 | *what* it does, the comment is useless, or the code is bad. (useless comments |
| 7 | are fine, don't worry) |
| 8 | - Upon translatable strings, comments explaining the context to translators are |
| 9 | welcome. |
| 10 | |
| 11 | **In python code only:** |
| 12 | |
| 13 | - Use actual tabs (4 columns wide). |
| 14 | - Try to not write lines longer than 80 characters. |
| 15 | - Use double quotes for strings the user might see, and single quotes otherwise |
| 16 | (paths, constants, enumerations, dict keys, …) |
| 17 | - Private or protected methods or attributes should start with an underscore. |
| 18 | |
| 19 | ---- |
| 20 | |
| 21 | # Structure of the code |
| 22 | |
| 23 | The `data` directory contains data useful for installation but useless to the |
| 24 | execution (app icons, desktop launcher, settings schemas, appdata, …). |
| 25 | |
| 26 | According to some people, this directory should contain the UI resources, but |
| 27 | here no: resources used by the app (`.ui` files, in-app icons, …) are in `src`, |
| 28 | along with the python code. |
| 29 | |
| 30 | >See [here](./design-general.md) for explanations about the architecture and |
| 31 | class diagrams |
| 32 | |
| 33 | ---- |
| 34 | |
| 35 | # UI design |
| 36 | |
| 37 | If you want to change something to the user interface: |
| 38 | |
| 39 | ### About Glade |
| 40 | |
| 41 | People sometimes like to design their apps in Glade, or in the "GUI designer" |
| 42 | extension integrated in GNOME Builder. |
| 43 | |
| 44 | But in Drawing, the UI is modular, and the `.ui` files are mere templates filled |
| 45 | algorithmically according to the user's actions and settings. So you have to: |
| 46 | |
| 47 | - edit them with a text editor, since the point of a given file is hard to |
| 48 | understand by just looking at the Glade preview; |
| 49 | - run the app to be sure of how your changes to these files actually look like |
| 50 | once filled with the accurate widgets. |
| 51 | |
| 52 | If you **ever** even try to use Glade or a similar software, the auto-generated |
| 53 | code will re-order all the lines, and add dozens of useless properties. Such a |
| 54 | commit diff would be unreadable. |
| 55 | |
| 56 | Glade also removes all comments, which are essential to the understanding of the |
| 57 | code, to the generation of the translation files, or which may be disabled code |
| 58 | for future features. It also removes some of the empty containers meant to be |
| 59 | filled by the python code, thus breaking the app. |
| 60 | |
| 61 | Please do not use Glade here. Merge requests with such changes will be rejected. |
| 62 | |
| 63 | ### Guidelines |
| 64 | |
| 65 | Try to respect [GNOME Human Interface Guidelines](https://developer.gnome.org/hig/stable/) |
| 66 | as much as possible, while making your feature available from the menubar |
| 67 | (in `app-menus.ui`). The menubar is hidden in most cases, but it should contains |
| 68 | as many `GAction`s as possible for testing purposes (and also because searchable |
| 69 | menus still exist). |
| 70 | |
| 71 | If you're contributing to an alternative layout ("elementary OS", "Cinnamon", or |
| 72 | any other), please be sure to not hurt the UX of the GNOME layout (since it's |
| 73 | the one used on smartphone, be careful: it has to stay very resizable). |
| 74 | |
| 75 | ---- |
| 76 | |
| 77 | # Other remarks |
| 78 | |
| 79 | I like `GAction`s and i've added wrapper methods for using them, try to use that |
| 80 | instead of directly connecting buttons/menu-items to a method. |
| 81 | |
| 82 | In my opinion, the difficulties with the code can come mainly from 3 points: |
| 83 | |
| 84 | - tools are window-wide, while [the operations they produce](./design-tools.md#command-pattern), |
| 85 | which are stored in the history, are image-wide. |
| 86 | - the interactions between the tools and the selection manager are ridiculously |
| 87 | complex and numerous _(defining, explicit applying, explicit canceling, import, |
| 88 | clipboard methods, use by the transformation tools (whose operation can be |
| 89 | cancelled or confirmed), deletion, implicit applying, implicit canceling, …)_ |
| 90 | which can easily create small bugs or regressions. |
| 91 | - the horizontal and vertical scrollings (and their scrollbars) are managed |
| 92 | "manually" and quite poorly. |
| 93 | |
| 94 | These 3 points sometimes can lead to object-oriented spaghetti code. |
| 95 | |
| 96 | If you change anything regarding the selection and/or the transformation tools |
| 97 | (which can edit the selection content), make sure to test various scenarios like |
| 98 | this one: |
| 99 | |
| 100 | 1. several images edited in different tabs of the same window; |
| 101 | 2. zoom and/or scroll; |
| 102 | 3. select things, or import/paste things (in both tabs); |
| 103 | 4. edit the selection (in both tabs, don't forget to click "apply" before |
| 104 | switching to the other tab); |
| 105 | 5. unselect it (in both tabs); |
| 106 | 6. undo/redo. |
| 107 |