Re: [gedit-list] Determining successfully loaded files



On Sun, Apr 13, 2014 at 6:09 PM, Dustin Oprea <myselfasunder gmail com> wrote:
On Sun, Apr 13, 2014 at 10:35 AM, Sébastien Wilmet <swilmet gnome org> wrote:
Hi,

On Sun, Apr 13, 2014 at 10:24:41AM -0400, Dustin Oprea wrote:
> I'd like to be able to determine if a document is a text-file or a binary
> file. I'd also like to know if there's a way to know whether the file was
> successfully loaded, or it's waiting on some prompt from the user (as in
> the case of a binary file, accidentally loading a path, or having IO
> errors). Are either of these possible?

GeditDocument have signals for that: "load", "loading" and "loaded".
But it is currently not possible to know if the file is a binary file.
Note that this API will probably be deprecated or removed soon, to have
a better API in GtkSourceView.


What about files that were already loaded, and are stopped on an error-prompt in one of the tabs?


windows = self.app.get_windows()
for window in windows:
    for document in window.get_documents():
        location = document.get_location()
        if location is None:
            # This is an untitled file (not loaded from disk).
            continue

        tab = window.get_tab_from_location(location)
        state = tab.get_state()
        if state != state.STATE_NORMAL:
            continue

        # If here, this is a fully-loaded document, successfully.




Dustin

 
The relevant bugs in GtkSourceView:
https://bugzilla.gnome.org/show_bug.cgi?id=721016
https://bugzilla.gnome.org/show_bug.cgi?id=724247

Best regards,
Sébastien




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]