Fix not switching to 2nd last used document when the last used

document has been closed (#1945162).
- Code changes:
Move geany_object extern to geany.h.
Remove CallbacksData struct.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3438 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-01-03 12:54:13 +00:00
parent 4428e31d93
commit 9962e8abb8
9 changed files with 65 additions and 34 deletions

View File

@ -1,3 +1,15 @@
2009-01-03 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/interface.c, src/keybindings.c, src/geanyobject.c,
src/geanyobject.h, src/geany.h, src/callbacks.c, src/callbacks.h,
geany.glade:
Fix not switching to 2nd last used document when the last used
document has been closed (#1945162).
- Code changes:
Move geany_object extern to geany.h.
Remove CallbacksData struct.
2009-01-02 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/keybindings.c, src/keybindings.h, src/main.c:

View File

@ -1770,7 +1770,6 @@
<property name="tab_pos">GTK_POS_TOP</property>
<property name="scrollable">True</property>
<property name="enable_popup">True</property>
<signal name="switch_page" handler="on_notebook1_switch_page" last_modification_time="Sat, 23 Apr 2005 15:17:51 GMT"/>
<signal name="switch_page" handler="on_notebook1_switch_page_after" after="yes" last_modification_time="Fri, 26 May 2006 11:47:25 GMT"/>
</widget>
<packing>

View File

@ -89,8 +89,6 @@ static gboolean insert_callback_from_menu = FALSE;
* the selection-changed signal from tv.tree_openfiles */
/*static gboolean switch_tv_notebook_page = FALSE; */
CallbacksData callbacks_data = { NULL };
static gboolean check_no_unsaved(void)
{
@ -703,17 +701,8 @@ on_toolbutton_preferences_clicked (GtkAction *action,
}
void
on_notebook1_switch_page (GtkNotebook *notebook,
GtkNotebookPage *page,
guint page_num,
gpointer user_data)
{
callbacks_data.last_doc = document_get_current();
}
/* changes window-title on switching tabs and lots of other things */
/* Changes window-title after switching tabs and lots of other things.
* note: using 'after' makes Scintilla redraw before the UI, appearing more responsive */
void
on_notebook1_switch_page_after (GtkNotebook *notebook,
GtkNotebookPage *page,

View File

@ -25,14 +25,6 @@
#include "geany.h" /* necessary for interface.c */
typedef struct
{
GeanyDocument *last_doc;
} CallbacksData;
extern CallbacksData callbacks_data;
gboolean
on_exit_clicked (GtkWidget *widget, gpointer gdata);
@ -72,12 +64,6 @@ void
on_toolbutton_close_all_clicked (GtkAction *action,
gpointer user_data);
void
on_notebook1_switch_page (GtkNotebook *notebook,
GtkNotebookPage *page,
guint page_num,
gpointer user_data);
void
on_save_all1_activate (GtkMenuItem *menuitem,
gpointer user_data);

View File

@ -79,6 +79,8 @@ GeanyApp;
extern GeanyApp *app;
extern GObject *geany_object;
extern gboolean ignore_callback;

View File

@ -34,6 +34,7 @@
#include "geany.h"
#include "geanyobject.h"
/* extern in geany.h */
GObject *geany_object;
static guint geany_object_signals[GCB_MAX] = { 0 };

View File

@ -30,8 +30,6 @@
G_BEGIN_DECLS
extern GObject *geany_object;
typedef enum
{
GCB_DOCUMENT_NEW,

View File

@ -1473,9 +1473,6 @@ create_window1 (void)
g_signal_connect ((gpointer) notebook3, "key_press_event",
G_CALLBACK (on_escape_key_press_event),
NULL);
g_signal_connect ((gpointer) notebook1, "switch_page",
G_CALLBACK (on_notebook1_switch_page),
NULL);
g_signal_connect_after ((gpointer) notebook1, "switch_page",
G_CALLBACK (on_notebook1_switch_page_after),
NULL);

View File

@ -58,6 +58,9 @@ static gboolean ignore_keybinding = FALSE;
static GtkAccelGroup *kb_accel_group = NULL;
static const gboolean swap_alt_tab_order = FALSE;
const gsize MAX_MRU_DOCS = 20;
static GQueue *mru_docs = NULL;
static gboolean switch_dialog_cancelled = TRUE;
static GtkWidget *switch_dialog = NULL;
static GtkWidget *switch_dialog_label = NULL;
@ -483,8 +486,51 @@ static void init_default_kb(void)
}
/* before the tab changes, add the current document to the MRU list */
static void on_notebook_switch_page()
{
GeanyDocument *old = document_get_current();
/* when closing current doc, old is NULL */
if (old)
{
g_queue_push_head(mru_docs, old);
if (g_queue_get_length(mru_docs) > MAX_MRU_DOCS)
g_queue_pop_tail(mru_docs);
}
}
/* really this should be just after a document was closed, not idle */
static gboolean on_idle_close(gpointer data)
{
GeanyDocument *current;
current = document_get_current();
while (current && g_queue_peek_head(mru_docs) == current)
g_queue_pop_head(mru_docs);
return FALSE;
}
static void on_document_close(GObject *obj, GeanyDocument *doc)
{
g_queue_remove_all(mru_docs, doc);
g_idle_add(on_idle_close, NULL);
}
void keybindings_init(void)
{
mru_docs = g_queue_new();
g_signal_connect(main_widgets.notebook, "switch-page",
G_CALLBACK(on_notebook_switch_page), NULL);
g_signal_connect(geany_object, "document-close",
G_CALLBACK(on_document_close), NULL);
keybinding_groups = g_ptr_array_sized_new(GEANY_KEY_GROUP_COUNT);
kb_accel_group = gtk_accel_group_new();
@ -671,6 +717,7 @@ void keybindings_write_to_file(void)
void keybindings_free(void)
{
g_ptr_array_free(keybinding_groups, TRUE);
g_queue_free(mru_docs);
}
@ -1428,7 +1475,7 @@ static gboolean on_switch_timeout(G_GNUC_UNUSED gpointer data)
static void cb_func_switch_tablastused(G_GNUC_UNUSED guint key_id)
{
/* TODO: MRU switching order */
GeanyDocument *last_doc = callbacks_data.last_doc;
GeanyDocument *last_doc = g_queue_peek_head(mru_docs);
if (!DOC_VALID(last_doc))
return;