Skip to content

Commit

Permalink
Also auto-sort when document is saved to a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
konsolebox committed Jul 24, 2016
1 parent d8c4f70 commit 646e815
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions doc/geany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,9 @@ Sorting tabs automatically
^^^^^^^^^^^^^^^^^^^^^^^^^^

Tabs can also be automatically sorted everytime a file or a group of
files are opened. This can be enabled in
Preferences->Interface->Notebook tabs. See `Editor tabs`_ section.
files are opened, or when a document is saved to a new file. This can
be enabled in Preferences->Interface->Notebook tabs. See `Editor tabs`_
section.

Cloning documents
^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1993,7 +1994,8 @@ Double-clicking hides all additional widgets

Automatically sort tabs based on filename
Whether to automatically sort editor tabs based on their filenames
everytime files are opened.
everytime files are opened, or when documents are saved to a new
file.

Automatically sort tabs based on pathname
Same as the one above but sort tabs based on pathname. The result
Expand Down
23 changes: 23 additions & 0 deletions src/notebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static GtkWidget *switch_dialog = NULL;
static GtkWidget *switch_dialog_label = NULL;

static gboolean on_idle_auto_sort_hooked = FALSE;
static gboolean doc_saves_to_new_file = FALSE;


static void
Expand All @@ -84,6 +85,8 @@ notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data);
static void setup_tab_dnd(void);

static void on_document_open(GObject *obj, GeanyDocument *doc);
static void on_document_before_save(GObject *obj, GeanyDocument *doc);
static void on_document_save(GObject *obj, GeanyDocument *doc);


static void update_mru_docs_head(GeanyDocument *doc)
Expand Down Expand Up @@ -551,6 +554,8 @@ void notebook_init(void)
g_signal_connect(main_widgets.window, "key-release-event", G_CALLBACK(on_key_release_event), NULL);

g_signal_connect(geany_object, "document-open", G_CALLBACK(on_document_open), NULL);
g_signal_connect(geany_object, "document-before-save", G_CALLBACK(on_document_before_save), NULL);
g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);

setup_tab_dnd();
}
Expand Down Expand Up @@ -1006,6 +1011,24 @@ static void on_document_open(GObject *obj, GeanyDocument *doc)
}


static void on_document_before_save(GObject *obj, GeanyDocument *doc)
{
doc_saves_to_new_file = doc->real_path == NULL;
}


static void on_document_save(GObject *obj, GeanyDocument *doc)
{
if (doc_saves_to_new_file && interface_prefs.show_notebook_tabs)
{
if (interface_prefs.auto_sort_tabs_filename)
notebook_sort_tabs(NOTEBOOK_TAB_SORT_FILENAME);
else if (interface_prefs.auto_sort_tabs_pathname)
notebook_sort_tabs(NOTEBOOK_TAB_SORT_PATHNAME);
}
}


static void
on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
gint x, gint y, GtkSelectionData *data, guint target_type,
Expand Down

0 comments on commit 646e815

Please sign in to comment.