Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features for sorting editor tabs #1144

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a64749e
Allow document_get_notebook_child() to be used globally
konsolebox Jul 19, 2016
803d6a6
Add capability to sort editor tabs
konsolebox Jul 19, 2016
138dd09
Add keybindings for sorting editor tabs
konsolebox Jul 19, 2016
04eb16b
Add capability to automatically sort editor tabs
konsolebox Jul 20, 2016
e943a3d
Fix syntax error on win32.c
konsolebox Jul 20, 2016
764ff76
Fix and enhance sorting of editor tabs based on pathnames
konsolebox Jul 21, 2016
11bfad0
Revert "Fix syntax error on win32.c"
konsolebox Jul 23, 2016
5bd8b52
Revert "Add capability to automatically sort editor tabs"
konsolebox Jul 23, 2016
474c0a5
Add capability to automatically sort editor tabs (v2)
konsolebox Jul 23, 2016
defc554
Add documentation
konsolebox Jul 23, 2016
4f219bd
Use GEANY_STRING_UNTITLED as directory if file is untitled.
konsolebox Jul 23, 2016
72894fe
Place declaration of document_get_notebook_child() inside GEANY_PRIVATE
konsolebox Jul 24, 2016
7e7d375
Move GEANY_KEYS_NOTEBOOK_SORTTABS_* closest to GEANY_KEYS_COUNT
konsolebox Jul 24, 2016
db8d823
Use the Stash for the auto-sort settings
konsolebox Jul 24, 2016
d8c4f70
Fix wrong definition of callback function
konsolebox Jul 24, 2016
646e815
Also auto-sort when document is saved to a new file
konsolebox Jul 24, 2016
dc07e0c
Simplify stuff, and make automatic sorting gradual
konsolebox Jul 27, 2016
85d5b31
Rename npages to n_pages
konsolebox Jul 27, 2016
c064984
Rename gradually_sort_doc_* to gradually_sort_tab_*
konsolebox Jul 29, 2016
ed809af
Say "sort by", not "sort based on"
konsolebox Jul 30, 2016
6d99001
Share get_doc_folder as sidebar_get_doc_folder and use it.
konsolebox Jul 31, 2016
bf3d1df
Use GPtrArray instead of GArray
konsolebox Jul 31, 2016
bb54fc1
Apply function simplifications by @b4n
konsolebox Jul 31, 2016
b7ba772
Do not skip automatic sorting even when editor tabs are disabled
konsolebox Jul 31, 2016
a6b84e2
Use radio buttons for the auto-sort options, and use a single paramet…
konsolebox Aug 1, 2016
aaeab39
Convert an if-else block to a simple one-line
konsolebox Aug 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 75 additions & 0 deletions data/geany.glade
Expand Up @@ -2179,6 +2179,81 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox_notebook_auto_sort_tabs">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label_notebook_auto_sort_tabs">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Automatically sort tabs:</property>
</object>
<packing>
<property name="position">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radio_notebook_auto_sort_tabs_disabled">
<property name="label" translatable="yes">Disabled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Disable auto-sorting of tabs</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radio_notebook_auto_sort_tabs_by_filename">
<property name="label" translatable="yes">By Filename</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Automatically sort tabs everytime a file is opened or when a document is saved to a new file. The sorting order will be based on the filename or basename.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio_notebook_auto_sort_tabs_disabled</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radio_notebook_auto_sort_tabs_by_pathname">
<property name="label" translatable="yes">By Pathname</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Automatically sort tabs everytime a file is opened or when a document is saved to a new file. The sorting order will be based on the full path of the file.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio_notebook_auto_sort_tabs_disabled</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
41 changes: 41 additions & 0 deletions doc/geany.txt
Expand Up @@ -509,6 +509,31 @@ order. It is not alphabetical as shown in the documents list
See the `Notebook tab keybindings`_ section for useful
shortcuts including for Most-Recently-Used document switching.

Sorting tabs
^^^^^^^^^^^^

You can sort tabs based on the names of the opened files they represent,
or based on the pathnames of those files. This can be done by
activating the sort command item in the popup menu that's shown by
right-clicking an editor tab. You can also activate the commands by
using shortcut keys. See `Notebook tab keybindings`_ section.

Sorting by filename means sorting the tabs based on the alphabetical
order of the basic names of the files, which excludes the directory
parts. For example: "name.ext".

Sorting by pathname on the other hand includes the directory parts.
This makes the resulting arrangement similar to the one in the documents
list when Show Paths is enabled.

Sorting tabs automatically
^^^^^^^^^^^^^^^^^^^^^^^^^^

Tabs can also be automatically sorted everytime a file or a group of
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
^^^^^^^^^^^^^^^^^
The `Document->Clone` menu item copies the current document's text,
Expand Down Expand Up @@ -1967,6 +1992,16 @@ Double-clicking hides all additional widgets
Whether to call the View->Toggle All Additional Widgets command
when double-clicking on a notebook tab.

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

Sorting by filename means sorting it based on the basic name of the
file and it excludes the directory parts, while sorting by pathname
means sorting it based on the full path, in which the resulting
arrangement would be the same as the one in the documents list when
Show Paths is enabled.

Tab positions
`````````````

Expand Down Expand Up @@ -3707,6 +3742,12 @@ Move document right Ctrl-Shift-PageDown Changes the current do
Move document first Moves the current document to the first position.

Move document last Moves the current document to the last position.

Sort tabs by filename Sorts tabs based on filenames or basenames.

Sort tabs by pathname Sorts tabs based on full path names. The tabs get
sorted similar to how files are arranged in the
documents list when Show Paths is enabled.
=============================== ========================= ==================================================


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which one is more correct: to say "sort based on filename", or to say "sort by filename". I find the former more technically correct, even though the latter is more common.

Expand Down
2 changes: 1 addition & 1 deletion src/document.c
Expand Up @@ -263,7 +263,7 @@ GeanyDocument *document_find_by_id(guint id)


/* gets the widget the main_widgets.notebook consider is its child for this document */
static GtkWidget *document_get_notebook_child(GeanyDocument *doc)
GtkWidget *document_get_notebook_child(GeanyDocument *doc)
{
GtkWidget *parent;
GtkWidget *child;
Expand Down
2 changes: 2 additions & 0 deletions src/document.h
Expand Up @@ -316,6 +316,8 @@ void document_grab_focus(GeanyDocument *doc);

GeanyDocument *document_clone(GeanyDocument *old_doc);

GtkWidget *document_get_notebook_child(GeanyDocument *doc);

#endif /* GEANY_PRIVATE */

G_END_DECLS
Expand Down
19 changes: 19 additions & 0 deletions src/keybindings.c
Expand Up @@ -106,6 +106,7 @@ static void cb_func_switch_tableft(guint key_id);
static void cb_func_switch_tabright(guint key_id);
static void cb_func_switch_tablastused(guint key_id);
static void cb_func_move_tab(guint key_id);
static void cb_func_sort_tabs(guint key_id);

static void add_popup_menu_accels(void);

Expand Down Expand Up @@ -653,6 +654,10 @@ static void init_default_kb(void)
0, 0, "move_tabfirst", _("Move document first"), NULL);
add_kb(group, GEANY_KEYS_NOTEBOOK_MOVETABLAST, cb_func_move_tab,
0, 0, "move_tablast", _("Move document last"), NULL);
add_kb(group, GEANY_KEYS_NOTEBOOK_SORTTABSBYFILENAME, cb_func_sort_tabs,
0, 0, "sort_tabs_by_filename", _("Sort tabs by filename"), NULL);
add_kb(group, GEANY_KEYS_NOTEBOOK_SORTTABSBYPATHNAME, cb_func_sort_tabs,
0, 0, "sort_tabs_by_filepath", _("Sort tabs by pathname"), NULL);

group = keybindings_get_core_group(GEANY_KEY_GROUP_DOCUMENT);

Expand Down Expand Up @@ -1914,6 +1919,20 @@ static void cb_func_move_tab(guint key_id)
}


static void cb_func_sort_tabs(guint key_id)
{
switch (key_id)
{
case GEANY_KEYS_NOTEBOOK_SORTTABSBYFILENAME:
notebook_sort_tabs(NOTEBOOK_TAB_SORT_BY_FILENAME);
break;
case GEANY_KEYS_NOTEBOOK_SORTTABSBYPATHNAME:
notebook_sort_tabs(NOTEBOOK_TAB_SORT_BY_PATHNAME);
break;
}
}


static void goto_matching_brace(GeanyDocument *doc)
{
gint pos, new_pos;
Expand Down
2 changes: 2 additions & 0 deletions src/keybindings.h
Expand Up @@ -274,6 +274,8 @@ enum GeanyKeyBindingID
GEANY_KEYS_FORMAT_SENDTOCMD8, /**< Keybinding. */
GEANY_KEYS_FORMAT_SENDTOCMD9, /**< Keybinding. */
GEANY_KEYS_EDITOR_DELETELINETOBEGINNING, /**< Keybinding. */
GEANY_KEYS_NOTEBOOK_SORTTABSBYFILENAME, /**< Keybinding. */
GEANY_KEYS_NOTEBOOK_SORTTABSBYPATHNAME, /**< Keybinding. */
GEANY_KEYS_COUNT /* must not be used by plugins */
};

Expand Down
7 changes: 7 additions & 0 deletions src/keyfile.c
Expand Up @@ -43,6 +43,7 @@
#include "geanyobject.h"
#include "main.h"
#include "msgwindow.h"
#include "notebook.h"
#include "prefs.h"
#include "printing.h"
#include "project.h"
Expand Down Expand Up @@ -173,6 +174,12 @@ static void init_pref_groups(void)
"radio_msgwin_vertical", GTK_ORIENTATION_VERTICAL,
"radio_msgwin_horizontal", GTK_ORIENTATION_HORIZONTAL,
NULL);
stash_group_add_radio_buttons(group, &interface_prefs.notebook_auto_sort_tabs,
"notebook_auto_sort_tabs", NOTEBOOK_TAB_AUTO_SORT_DISABLED,
"radio_notebook_auto_sort_tabs_disabled", NOTEBOOK_TAB_AUTO_SORT_DISABLED,
"radio_notebook_auto_sort_tabs_by_filename", NOTEBOOK_TAB_AUTO_SORT_BY_FILENAME,
"radio_notebook_auto_sort_tabs_by_pathname", NOTEBOOK_TAB_AUTO_SORT_BY_PATHNAME,
NULL);

/* editor display */
stash_group_add_toggle_button(group, &interface_prefs.highlighting_invert_all,
Expand Down