The ::document-activate signal was not emitted when opening the first
tab of the notebook, e.g. when the tab count changed from 0 to 1.
This is because the ::document-activate signal is emitted in response
to the GtkNotebook::switch-page signal, which is emitted whenever the
currently displayed page changes. When there already is a current page
(when there is one or more pages), adding a new page does not trigger
the signal, as this new page doesn't become the current one (we will
switch to it later). However, when there are none, the newly added one
becomes current, and so the signal is emitted right away.
This is problematic because when we add the page to the notebook, the
document associated with it is not yet ready (only partly initialized),
and so we can't emit the signal on a valid document, and we discard it.
Not emitting this signal leads to inconsistent behavior introducing
subtle bugs in plugins relying on it.
To work this around, only show the page widget (the child added to the
notebook) after we finished initializing everything. This is the
simplest fix, because a lot of the code around document creation and
opening depend on the fact the page is already added, so while delaying
the page addition sounds like the more sensible fix, it has non-trivial
consequences that would require a large amount of work to overcome.
Note that interestingly, in addition to our problem, GtkNotebook seems
to have a bug as it emits the ::switch-page right when adding the first
page even if that page is not visible. However, it properly emits it
again when the child becomes visible, so we just still discard the
first emission like we used to.
Since document_compare_by_tab_order_reverse does the exact reverse of
document_compare_by_tab_order the code need not to be duplicated. Instead
document_compare_by_tab_order can be called and the return value be reversed.
The issue was introduced in b646424ddb715382a937d233a75bc684c22e18ec as
it removed the default handler that used to destroy the infobar.
Now, the infobar is properly closed, but only if the action succeeded.
Closes#375.
With the previous TMWorkspace API it was possible to make the workspace
inconsistent by e.g. removing source files and forgetting to update
workspace. This could lead to non-obvious and not immediately visible
crashes.
The new set of the public (but also Geany private) API calls always
updates the workspace accordingly and neither of the calls can lead
to an inconsistent state of the workspace.
In addition, perform some minor cleanups and simplifications - unify
parsing from buffer and from file, support "parsing" of 0-sized buffers
and improve documentation.
Manage the list the same way as workspace tags_array by the fast tag removal
and merge. Thanks to this, typename tags don't have to be extracted from
tags_array periodically, which speeds up editing.
Lazy initializing various member pointers doesn't bring any real performance
improvement but it requires lots of additional NULL checks - get rid of
this.
Make some more cleanups on the way.
In addition, remove success/failure return values from tm_workspace_add_source_file()
and tm_workspace_remove_source_file() which have no real use.
Avoid "utility" parameters like do_free for which we already have API calls
and which actually don't perform any free if the source file isn't
in TM. Clarify when to set the update_workspace parameter.
The placement of this function in tm_source_file is not right - by moving
it to the workspace we can make the source file unaware of the existence
of the workspace (no inclusion of tm_workspace.h in tm_source_file any
more). Also change tm_source_file_new() so it doesn't offer the source file
update.
After this change
* TMWorkspace knows TMSourceFile and TMTag
* TMSourceFile knows TMTag
* TMTag knows TMSourceFile
In addition, rename all functions, parameters, comments etc. mentioning
work_object and remove unnecessary parameters of various functions.
Delete dead code paths.
Also move common functions like tm_get_real_path() from tm_work_object to
tm_source_file.
Updating the workspace is useless as the application will be shut down,
and not doing it can save a lot of time (almost 50% speedup quitting an
instance with all Geany source from `src/` open).
Setting the document text as changed makes it too easy to accidentally
overwrite the file - e.g. when closing you're reminded to save it.
It also makes it slower to close documents you no longer want open.
Setting text as changed is still done if the user cancels the warning.
Add GeanyDocument::id, document_find_by_id() to plugin API.
This also fixes clicking on a Messages item whose document has been
closed and reused. Now the click will be ignored instead of jumping to
an unexpected line in the new document.
Passed-in flags was always 0, so the argument is not useful.
Also, this function expected Scintilla search flags rather than Geany
ones, making the API confusing for no good reason.
Apparently the ::unrealize symbol is sent too late, after we destroyed
the widget and freed the GeanyDocument, and some signals like
::focus-in-event can still be fired on the widget after that.
So, properly use the ::destroy signal that is supposed to be fired when
others should release references to that instance.
When quitting we avoid doing some unnecessary actions, and used to
simply destroy the Scintilla widget (and thus the notebook page)
instead of the elaborate UI updates.
Unfortunately, when the infobars landed they changed what is packed as
a notebook page, and now destroying the Scintilla widget alone is not
enough to close the page. Fix this by properly removing the whole page
no matter what it contains.
This issue was visible when quitting Geany with a project open.
Before infobar it didn't matter because the dialog was modal and interaction
with the doc was impossible. Now that you can interact it the doc should
be marked changed immediately.
Since cbf9813632d7ee921ffa1fda0d1f69128b2bc755 we have a proper
solution for maintaining line number consistent with the editor zoom,
so drop the old hack.
This also allows to remove the now useless third argument of
sci_set_line_numbers().
The callback wasn't used from glade but is useful for some other places so
it's worth moving into document.c. This also fixes a bug where reload via sidebar
always reloads the current document instead of the actually clicked one.