Add a new GeditNotebookPopupMenu class.

This class will take care of creating the menu that is popup with right
click in a notebook tab.
parent 0f7da0aa
......@@ -120,6 +120,7 @@ NOINST_H_FILES = \
gedit-language-manager.h \
gedit-multi-notebook.h \
gedit-notebook.h \
gedit-notebook-popup-menu.h \
gedit-plugins-engine.h \
gedit-print-job.h \
gedit-print-preview.h \
......@@ -201,6 +202,7 @@ libgedit_c_files = \
gedit-message.c \
gedit-multi-notebook.c \
gedit-notebook.c \
gedit-notebook-popup-menu.c \
gedit-panel.c \
gedit-plugins-engine.c \
gedit-print-job.c \
......
......@@ -498,8 +498,6 @@ _gedit_cmd_file_open (GtkAction *action,
}
/* File saving */
static void file_save_as (GeditTab *tab,
GeditWindow *window);
static gboolean
is_read_only (GFile *location)
......@@ -791,7 +789,7 @@ save_next_tab:
}
gedit_window_set_active_tab (window, tab);
file_save_as (tab, window);
_gedit_cmd_file_save_as_tab (tab, window);
}
}
......@@ -827,9 +825,9 @@ confirm_overwrite_callback (GtkFileChooser *dialog,
return res;
}
static void
file_save_as (GeditTab *tab,
GeditWindow *window)
void
_gedit_cmd_file_save_as_tab (GeditTab *tab,
GeditWindow *window)
{
GtkWidget *save_dialog;
GtkWindowGroup *wg;
......@@ -928,9 +926,9 @@ file_save_as (GeditTab *tab,
gtk_widget_show (save_dialog);
}
static void
file_save (GeditTab *tab,
GeditWindow *window)
void
_gedit_cmd_file_save_tab (GeditTab *tab,
GeditWindow *window)
{
GeditDocument *doc;
gchar *uri_for_display;
......@@ -948,8 +946,8 @@ file_save (GeditTab *tab,
{
gedit_debug_message (DEBUG_COMMANDS, "Untitled or Readonly");
file_save_as (tab, window);
_gedit_cmd_file_save_as_tab (tab, window);
return;
}
......@@ -966,7 +964,7 @@ file_save (GeditTab *tab,
void
_gedit_cmd_file_save (GtkAction *action,
GeditWindow *window)
GeditWindow *window)
{
GeditTab *tab;
......@@ -976,12 +974,12 @@ _gedit_cmd_file_save (GtkAction *action,
if (tab == NULL)
return;
file_save (tab, window);
_gedit_cmd_file_save_tab (tab, window);
}
void
_gedit_cmd_file_save_as (GtkAction *action,
GeditWindow *window)
GeditWindow *window)
{
GeditTab *tab;
......@@ -991,7 +989,7 @@ _gedit_cmd_file_save_as (GtkAction *action,
if (tab == NULL)
return;
file_save_as (tab, window);
_gedit_cmd_file_save_as_tab (tab, window);
}
static gboolean
......@@ -1058,7 +1056,7 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
}
else
{
file_save (t, window);
_gedit_cmd_file_save_tab (t, window);
}
}
else
......@@ -1113,7 +1111,7 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
tab = GEDIT_TAB (tabs_to_save_as->data);
gedit_window_set_active_tab (window, tab);
file_save_as (tab, window);
_gedit_cmd_file_save_as_tab (tab, window);
}
}
......@@ -1152,7 +1150,7 @@ gedit_commands_save_document (GeditWindow *window,
gedit_debug (DEBUG_COMMANDS);
tab = gedit_tab_get_from_document (document);
file_save (tab, window);
_gedit_cmd_file_save_tab (tab, window);
}
/* File revert */
......@@ -1452,7 +1450,7 @@ save_and_close (GeditTab *tab,
G_CALLBACK (tab_state_changed_while_saving),
window);
file_save (tab, window);
_gedit_cmd_file_save_tab (tab, window);
}
static void
......@@ -1472,7 +1470,7 @@ save_as_and_close (GeditTab *tab,
window);
gedit_window_set_active_tab (window, tab);
file_save_as (tab, window);
_gedit_cmd_file_save_as_tab (tab, window);
}
static void
......
......@@ -73,6 +73,10 @@ void _gedit_cmd_file_new (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_file_open (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_file_save_tab (GeditTab *tab,
GeditWindow *window);
void _gedit_cmd_file_save_as_tab (GeditTab *tab,
GeditWindow *window);
void _gedit_cmd_file_save (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_file_save_as (GtkAction *action,
......@@ -137,8 +141,8 @@ void _gedit_cmd_search_clear_highlight (GtkAction *action,
void _gedit_cmd_search_goto_line (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_search_incremental_search (GtkAction *action,
GeditWindow *window);
GeditWindow *window);
void _gedit_cmd_documents_previous_document (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_documents_next_document (GtkAction *action,
......
......@@ -3,6 +3,7 @@ BOOLEAN:OBJECT
VOID:BOOLEAN
VOID:BOOLEAN,POINTER
VOID:BOXED,BOXED
VOID:BOXED,OBJECT
VOID:OBJECT
VOID:OBJECT,OBJECT
VOID:OBJECT,OBJECT,OBJECT,OBJECT
......
......@@ -205,10 +205,11 @@ gedit_multi_notebook_class_init (GeditMultiNotebookClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GeditMultiNotebookClass, show_popup_menu),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
gedit_marshal_VOID__BOXED_OBJECT,
G_TYPE_NONE,
1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
GEDIT_TYPE_TAB);
g_object_class_install_property (object_class,
PROP_ACTIVE_NOTEBOOK,
......@@ -231,9 +232,10 @@ gedit_multi_notebook_class_init (GeditMultiNotebookClass *klass)
static void
notebook_show_popup_menu (GtkNotebook *notebook,
GdkEvent *event,
GeditTab *tab,
GeditMultiNotebook *mnb)
{
g_signal_emit (G_OBJECT (mnb), signals[SHOW_POPUP_MENU], 0, event);
g_signal_emit (G_OBJECT (mnb), signals[SHOW_POPUP_MENU], 0, event, tab);
}
static void
......
......@@ -80,7 +80,8 @@ struct _GeditMultiNotebookClass
gint y);
void (* page_reordered) (GeditMultiNotebook *mnb);
void (* show_popup_menu) (GeditMultiNotebook *mnb,
GdkEvent *event);
GdkEvent *event,
GeditTab *tab);
};
GType gedit_multi_notebook_get_type (void) G_GNUC_CONST;
......
/*
* gedit-notebook-popup-menu.c
* This file is part of gedit
*
* Copyright (C) 2011 - Ignacio Casal Quinteiro
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gedit-notebook-popup-menu.h"
#include "gedit-commands.h"
#include <glib/gi18n.h>
struct _GeditNotebookPopupMenuPrivate
{
GeditWindow *window;
GeditTab *tab;
};
enum
{
PROP_0,
PROP_WINDOW,
PROP_TAB
};
G_DEFINE_TYPE (GeditNotebookPopupMenu, gedit_notebook_popup_menu, GTK_TYPE_MENU)
static void
gedit_notebook_popup_menu_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GeditNotebookPopupMenu *menu = GEDIT_NOTEBOOK_POPUP_MENU (object);
switch (prop_id)
{
case PROP_WINDOW:
menu->priv->window = GEDIT_WINDOW (g_value_get_object (value));
break;
case PROP_TAB:
menu->priv->tab = GEDIT_TAB (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gedit_notebook_popup_menu_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GeditNotebookPopupMenu *menu = GEDIT_NOTEBOOK_POPUP_MENU (object);
switch (prop_id)
{
case PROP_WINDOW:
g_value_set_object (value, menu->priv->window);
break;
case PROP_TAB:
g_value_set_object (value, menu->priv->tab);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gedit_notebook_popup_menu_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_notebook_popup_menu_parent_class)->finalize (object);
}
static void
gedit_notebook_popup_menu_class_init (GeditNotebookPopupMenuClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gedit_notebook_popup_menu_get_property;
object_class->set_property = gedit_notebook_popup_menu_set_property;
object_class->finalize = gedit_notebook_popup_menu_finalize;
g_object_class_install_property (object_class,
PROP_WINDOW,
g_param_spec_object ("window",
"Window",
"The GeditWindow",
GEDIT_TYPE_WINDOW,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_TAB,
g_param_spec_object ("tab",
"Tab",
"The GeditTab",
GEDIT_TYPE_TAB,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (GeditNotebookPopupMenuPrivate));
}
static void
on_move_to_new_window_menuitem_activate (GtkMenuItem *menuitem,
GeditNotebookPopupMenu *menu)
{
_gedit_window_move_tab_to_new_window (menu->priv->window,
menu->priv->tab);
}
static void
on_file_save_menuitem_activate (GtkMenuItem *menuitem,
GeditNotebookPopupMenu *menu)
{
_gedit_cmd_file_save (menu->priv->tab, menu->priv->window);
}
static void
on_file_save_as_menuitem_activate (GtkMenuItem *menuitem,
GeditNotebookPopupMenu *menu)
{
_gedit_cmd_file_save_as (menu->priv->tab, menu->priv->window);
}
static void
on_file_print_menuitem_activate (GtkMenuItem *menuitem,
GeditNotebookPopupMenu *menu)
{
_gedit_tab_print (menu->priv->tab);
}
static void
on_file_close_menuitem_activate (GtkMenuItem *menuitem,
GeditNotebookPopupMenu *menu)
{
_gedit_cmd_file_close_tab (menu->priv->tab, menu->priv->window);
}
static void
gedit_notebook_popup_menu_init (GeditNotebookPopupMenu *menu)
{
GtkWidget *menu_item;
GtkWidget *image;
menu->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu,
GEDIT_TYPE_NOTEBOOK_POPUP_MENU,
GeditNotebookPopupMenuPrivate);
/* Keep in sync with the respective GtkActions */
menu_item = gtk_menu_item_new_with_mnemonic (_("_Move to New Window"));
g_signal_connect (menu_item, "activate",
G_CALLBACK (on_move_to_new_window_menuitem_activate),
menu);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_separator_menu_item_new ();
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE, NULL);
g_signal_connect (menu_item, "activate",
G_CALLBACK (on_file_save_menuitem_activate),
menu);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_image_menu_item_new_with_mnemonic (_("Save _As..."));
image = gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
g_signal_connect (menu_item, "activate",
G_CALLBACK (on_file_save_as_menuitem_activate),
menu);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_separator_menu_item_new ();
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_image_menu_item_new_with_mnemonic (_("_Print..."));
image = gtk_image_new_from_stock (GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
g_signal_connect (menu_item, "activate",
G_CALLBACK (on_file_print_menuitem_activate),
menu);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_separator_menu_item_new ();
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL);
g_signal_connect (menu_item, "activate",
G_CALLBACK (on_file_close_menuitem_activate),
menu);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
gtk_widget_show (menu_item);
}
GtkWidget *
gedit_notebook_popup_menu_new (GeditWindow *window,
GeditTab *tab)
{
return g_object_new (GEDIT_TYPE_NOTEBOOK_POPUP_MENU,
"window", window,
"tab", tab,
NULL);
}
/*
* gedit-notebook-popup-menu.h
* This file is part of gedit
*
* Copyright (C) 2011 - Ignacio Casal Quinteiro
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GEDIT_NOTEBOOK_POPUP_MENU_H__
#define __GEDIT_NOTEBOOK_POPUP_MENU_H__
#include <gtk/gtk.h>
#include "gedit-window.h"
#include "gedit-tab.h"
G_BEGIN_DECLS
#define GEDIT_TYPE_NOTEBOOK_POPUP_MENU (gedit_notebook_popup_menu_get_type ())
#define GEDIT_NOTEBOOK_POPUP_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_NOTEBOOK_POPUP_MENU, GeditNotebookPopupMenu))
#define GEDIT_NOTEBOOK_POPUP_MENU_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_NOTEBOOK_POPUP_MENU, GeditNotebookPopupMenu const))
#define GEDIT_NOTEBOOK_POPUP_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_NOTEBOOK_POPUP_MENU, GeditNotebookPopupMenuClass))
#define GEDIT_IS_NOTEBOOK_POPUP_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_NOTEBOOK_POPUP_MENU))
#define GEDIT_IS_NOTEBOOK_POPUP_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_NOTEBOOK_POPUP_MENU))
#define GEDIT_NOTEBOOK_POPUP_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_NOTEBOOK_POPUP_MENU, GeditNotebookPopupMenuClass))
typedef struct _GeditNotebookPopupMenu GeditNotebookPopupMenu;
typedef struct _GeditNotebookPopupMenuClass GeditNotebookPopupMenuClass;
typedef struct _GeditNotebookPopupMenuPrivate GeditNotebookPopupMenuPrivate;
struct _GeditNotebookPopupMenu
{
GtkMenu parent;
GeditNotebookPopupMenuPrivate *priv;
};
struct _GeditNotebookPopupMenuClass
{
GtkMenuClass parent_class;
};
GType gedit_notebook_popup_menu_get_type (void) G_GNUC_CONST;
GtkWidget *gedit_notebook_popup_menu_new (GeditWindow *window,
GeditTab *tab);
G_END_DECLS
#endif /* __GEDIT_NOTEBOOK_POPUP_MENU_H__ */
......@@ -49,6 +49,7 @@
#include "gedit-window.h"
#include "gedit-enum-types.h"
#include "gedit-settings.h"
#include "gedit-marshal.h"
#define GEDIT_NOTEBOOK_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_NOTEBOOK, GeditNotebookPrivate))
......@@ -266,10 +267,11 @@ gedit_notebook_button_press (GtkWidget *widget,
tab_clicked = find_tab_num_at_pos (nb, event->x_root, event->y_root);
if (tab_clicked >= 0)
{
/* switch to the page the mouse is over */
gtk_notebook_set_current_page (nb, tab_clicked);
GtkWidget *tab;
g_signal_emit (G_OBJECT (widget), signals[SHOW_POPUP_MENU], 0, event);
tab = gtk_notebook_get_nth_page (nb, tab_clicked);
g_signal_emit (G_OBJECT (widget), signals[SHOW_POPUP_MENU], 0, event, tab);
return TRUE;
}
......@@ -535,10 +537,11 @@ gedit_notebook_class_init (GeditNotebookClass *klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GeditNotebookClass, show_popup_menu),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
gedit_marshal_VOID__BOXED_OBJECT,
G_TYPE_NONE,
1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
GEDIT_TYPE_TAB);
g_type_class_add_private (object_class, sizeof (GeditNotebookPrivate));
}
......
......@@ -90,7 +90,8 @@ struct _GeditNotebookClass
void (* tab_close_request) (GeditNotebook *notebook,
GeditTab *tab);
void (* show_popup_menu) (GeditNotebook *notebook,
GdkEvent *event);
GdkEvent *event,
GeditTab *tab);
};
/*
......
......@@ -191,17 +191,4 @@
<toolitem action="LeaveFullscreen"/>
</toolbar>
<popup name="NotebookPopup" action="NotebookPopupAction">
<menuitem action="DocumentsMoveToNewWindow"/>
<separator/>
<menuitem action="FileSave"/>
<menuitem action="FileSaveAs"/>
<separator/>
<menuitem action="FilePrint"/>
<separator/>
<placeholder name="NotebookPupupOps_1"/>
<separator/>
<menuitem name="FileCloseMenu" action="FileClose"/>
</popup>
</ui>
......@@ -45,6 +45,7 @@
#include "gedit-window-private.h"
#include "gedit-app.h"
#include "gedit-notebook.h"
#include "gedit-notebook-popup-menu.h"
#include "gedit-multi-notebook.h"
#include "gedit-statusbar.h"
#include "gedit-utils.h"
......@@ -3782,16 +3783,17 @@ on_tab_close_request (GeditMultiNotebook *multi,
static void
on_show_popup_menu (GeditMultiNotebook *multi,
GdkEventButton *event,
GeditWindow *window)
GdkEventButton *event,
GeditTab *tab,
GeditWindow *window)
{
GtkWidget *menu;
if (event == NULL)
return;
menu = gtk_ui_manager_get_widget (window->priv->manager, "/NotebookPopup");
g_return_if_fail (menu != NULL);
menu = gedit_notebook_popup_menu_new (window, tab);
gtk_widget_show (menu);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment