2005-11-17 19:06:47 -08:00
|
|
|
/*
|
2005-09-02 23:25:43 -07:00
|
|
|
* mooeditwindow.c
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
2006-02-23 06:03:17 -08:00
|
|
|
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
2006-05-05 11:35:25 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
#define MOOEDIT_COMPILATION
|
2006-04-05 00:54:33 -07:00
|
|
|
#include "mooedit/statusbar-glade.h"
|
|
|
|
#include "mooedit/mooedit-private.h"
|
2006-12-06 21:02:08 -08:00
|
|
|
#include "mooedit/mooeditor-private.h"
|
2006-08-26 02:46:29 -07:00
|
|
|
#include "mooedit/moolang.h"
|
2005-10-13 07:08:18 -07:00
|
|
|
#include "mooedit/mootextbuffer.h"
|
|
|
|
#include "mooedit/mooeditprefs.h"
|
|
|
|
#include "mooedit/mooplugin.h"
|
2006-04-16 20:05:51 -07:00
|
|
|
#include "mooedit/moocmdview.h"
|
2006-08-18 22:59:53 -07:00
|
|
|
#include "mooedit/mooeditaction.h"
|
2006-11-25 13:03:17 -08:00
|
|
|
#include "mooedit/mooedit-bookmarks.h"
|
2005-10-13 07:08:18 -07:00
|
|
|
#include "mooutils/moonotebook.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooutils/moostock.h"
|
2005-09-04 21:24:21 -07:00
|
|
|
#include "mooutils/moomarshals.h"
|
2005-10-13 07:08:18 -07:00
|
|
|
#include "mooutils/moomenuaction.h"
|
2005-11-27 06:03:12 -08:00
|
|
|
#include "mooutils/mooutils-misc.h"
|
2005-11-30 08:46:02 -08:00
|
|
|
#include "mooutils/moocompat.h"
|
2006-04-05 00:54:33 -07:00
|
|
|
#include "mooutils/mooglade.h"
|
2006-08-03 00:29:39 -07:00
|
|
|
#include "mooutils/mooi18n.h"
|
2006-08-15 00:12:41 -07:00
|
|
|
#include "mooutils/mooaction-private.h"
|
2006-11-18 23:12:56 -08:00
|
|
|
#include "mooutils/moofiledialog.h"
|
2006-08-13 02:00:15 -07:00
|
|
|
#include "moofileview/moofile.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include <string.h>
|
2005-10-13 07:08:18 -07:00
|
|
|
#include <gtk/gtk.h>
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-07-05 12:14:02 -07:00
|
|
|
#if GTK_CHECK_VERSION(2,10,0)
|
|
|
|
#define ENABLE_PRINTING
|
|
|
|
#include "mooedit/mootextprint.h"
|
|
|
|
#endif
|
|
|
|
|
2006-11-23 18:09:41 -08:00
|
|
|
#define ENABLE_BOOKMARKS
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
#define ACTIVE_DOC moo_edit_window_get_active_doc
|
2005-09-03 15:48:05 -07:00
|
|
|
#define ACTIVE_PAGE(window) (moo_notebook_get_current_page (window->priv->notebook))
|
2005-08-07 19:16:23 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
#define LANG_ACTION_ID "LanguageMenu"
|
2005-11-18 05:02:42 -08:00
|
|
|
#define STOP_ACTION_ID "StopJob"
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
typedef struct {
|
2006-08-15 22:18:16 -07:00
|
|
|
MooActionCheckFunc func;
|
2006-04-16 15:02:19 -07:00
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify notify;
|
2006-08-15 22:18:16 -07:00
|
|
|
} OnePropCheck;
|
|
|
|
|
|
|
|
#define N_ACTION_CHECKS 3
|
|
|
|
typedef struct {
|
|
|
|
OnePropCheck checks[N_ACTION_CHECKS];
|
2006-04-16 15:02:19 -07:00
|
|
|
} ActionCheck;
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
static GHashTable *action_checks; /* char* -> ActionCheck* */
|
2006-04-16 15:02:19 -07:00
|
|
|
static GSList *windows;
|
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
typedef struct {
|
|
|
|
MooPaneParams *params;
|
|
|
|
int position;
|
|
|
|
} PaneParams;
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
struct _MooEditWindowPrivate {
|
2005-09-02 23:25:43 -07:00
|
|
|
MooEditor *editor;
|
2006-04-05 00:54:33 -07:00
|
|
|
|
2006-04-05 03:01:27 -07:00
|
|
|
GtkStatusbar *statusbar;
|
|
|
|
guint last_msg_id;
|
2006-04-05 00:54:33 -07:00
|
|
|
GtkLabel *cursor_label;
|
|
|
|
GtkLabel *insert_label;
|
|
|
|
GtkWidget *info;
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
MooNotebook *notebook;
|
2005-09-07 04:19:26 -07:00
|
|
|
char *prefix;
|
2006-05-26 22:37:32 -07:00
|
|
|
gboolean use_full_name;
|
2005-09-08 00:46:48 -07:00
|
|
|
GHashTable *panes;
|
2005-10-13 07:08:18 -07:00
|
|
|
GHashTable *panes_to_save; /* char* */
|
|
|
|
guint save_params_idle;
|
2005-11-18 05:02:42 -08:00
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
MooUIXML *xml;
|
|
|
|
guint doc_list_merge_id;
|
|
|
|
guint doc_list_update_idle;
|
|
|
|
|
2005-11-18 05:02:42 -08:00
|
|
|
GSList *stop_clients;
|
|
|
|
GSList *jobs; /* Job* */
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
enum {
|
|
|
|
TARGET_MOO_EDIT_TAB = 1,
|
|
|
|
TARGET_URI_LIST = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
static GdkAtom moo_edit_tab_atom;
|
2006-06-23 00:48:32 -07:00
|
|
|
static GdkAtom text_uri_atom;
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
static GtkTargetEntry dest_targets[] = {
|
|
|
|
{(char*) "MOO_EDIT_TAB", GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB},
|
|
|
|
{(char*) "text/uri-list", 0, TARGET_URI_LIST}
|
|
|
|
};
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
static void action_checks_init (void);
|
|
|
|
static void moo_edit_window_check_actions (MooEditWindow *window);
|
|
|
|
|
|
|
|
GObject *moo_edit_window_constructor (GType type,
|
|
|
|
guint n_props,
|
|
|
|
GObjectConstructParam *props);
|
|
|
|
static void moo_edit_window_finalize (GObject *object);
|
|
|
|
static void moo_edit_window_destroy (GtkObject *object);
|
|
|
|
|
|
|
|
static void moo_edit_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void moo_edit_window_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean moo_edit_window_close (MooEditWindow *window);
|
|
|
|
|
|
|
|
static void setup_notebook (MooEditWindow *window);
|
|
|
|
static void update_window_title (MooEditWindow *window);
|
|
|
|
|
|
|
|
static void proxy_boolean_property (MooEditWindow *window,
|
|
|
|
GParamSpec *prop,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void edit_changed (MooEditWindow *window,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void edit_filename_changed (MooEditWindow *window,
|
|
|
|
const char *filename,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void edit_lang_changed (MooEditWindow *window,
|
|
|
|
guint var_id,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
MooEdit *doc);
|
2006-05-02 19:40:18 -07:00
|
|
|
static void edit_overwrite_changed (MooEditWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
MooEdit *doc);
|
2006-06-17 00:38:23 -07:00
|
|
|
static void edit_wrap_mode_changed (MooEditWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void edit_show_line_numbers_changed (MooEditWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
MooEdit *doc);
|
2006-04-16 15:02:19 -07:00
|
|
|
static GtkWidget *create_tab_label (MooEditWindow *window,
|
|
|
|
MooEdit *edit);
|
|
|
|
static void update_tab_label (MooEditWindow *window,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void edit_cursor_moved (MooEditWindow *window,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
MooEdit *edit);
|
|
|
|
static void update_lang_menu (MooEditWindow *window);
|
2006-06-17 00:38:23 -07:00
|
|
|
static void update_doc_view_actions (MooEditWindow *window);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
|
|
|
static void create_statusbar (MooEditWindow *window);
|
|
|
|
static void update_statusbar (MooEditWindow *window);
|
|
|
|
static MooEdit *get_nth_tab (MooEditWindow *window,
|
|
|
|
guint n);
|
|
|
|
static int get_page_num (MooEditWindow *window,
|
|
|
|
MooEdit *doc);
|
|
|
|
|
2006-05-08 21:57:16 -07:00
|
|
|
static GtkAction *create_lang_action (MooEditWindow *window);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
|
|
|
static void create_paned (MooEditWindow *window);
|
2006-05-04 20:41:23 -07:00
|
|
|
static PaneParams *load_pane_params (const char *pane_id);
|
2006-04-16 15:02:19 -07:00
|
|
|
static gboolean save_pane_params (const char *pane_id,
|
2006-05-04 20:41:23 -07:00
|
|
|
PaneParams *params);
|
2006-04-16 15:02:19 -07:00
|
|
|
static void pane_params_changed (MooEditWindow *window,
|
|
|
|
MooPanePosition position,
|
|
|
|
guint index);
|
|
|
|
static void pane_size_changed (MooEditWindow *window,
|
|
|
|
MooPanePosition position);
|
2006-05-04 20:41:23 -07:00
|
|
|
static PaneParams *pane_params_new (void);
|
|
|
|
static void pane_params_free (PaneParams *params);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
static void moo_edit_window_update_doc_list (MooEditWindow *window);
|
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
static void notebook_drag_data_recv (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static gboolean notebook_drag_drop (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
guint time,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static gboolean notebook_drag_motion (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
guint time,
|
|
|
|
MooEditWindow *window);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
/* actions */
|
2006-06-25 01:15:19 -07:00
|
|
|
static void action_new_doc (MooEditWindow *window);
|
|
|
|
static void action_open (MooEditWindow *window);
|
|
|
|
static void action_reload (MooEditWindow *window);
|
|
|
|
static void action_save (MooEditWindow *window);
|
|
|
|
static void action_save_as (MooEditWindow *window);
|
|
|
|
static void action_close_tab (MooEditWindow *window);
|
|
|
|
static void action_close_all (MooEditWindow *window);
|
|
|
|
static void action_previous_tab (MooEditWindow *window);
|
|
|
|
static void action_next_tab (MooEditWindow *window);
|
2006-11-23 18:09:41 -08:00
|
|
|
#ifdef ENABLE_BOOKMARKS
|
|
|
|
static void action_toggle_bookmark (MooEditWindow *window);
|
|
|
|
static void action_next_bookmark (MooEditWindow *window);
|
|
|
|
static void action_prev_bookmark (MooEditWindow *window);
|
2006-11-25 13:03:17 -08:00
|
|
|
static GtkAction *create_goto_bookmark_action (MooWindow *window,
|
|
|
|
gpointer data);
|
|
|
|
static GtkAction *create_bookmarks_menu_action (MooWindow *window,
|
|
|
|
gpointer data);
|
2006-10-17 22:24:35 -07:00
|
|
|
#endif
|
2006-06-25 01:15:19 -07:00
|
|
|
static void action_next_ph (MooEditWindow *window);
|
|
|
|
static void action_prev_ph (MooEditWindow *window);
|
|
|
|
static void action_find_now_f (MooEditWindow *window);
|
|
|
|
static void action_find_now_b (MooEditWindow *window);
|
|
|
|
static void action_abort_jobs (MooEditWindow *window);
|
|
|
|
|
|
|
|
static void wrap_text_toggled (MooEditWindow *window,
|
|
|
|
gboolean active);
|
|
|
|
static void line_numbers_toggled (MooEditWindow *window,
|
|
|
|
gboolean active);
|
2006-06-17 00:38:23 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-07-05 12:14:02 -07:00
|
|
|
#ifdef ENABLE_PRINTING
|
2006-06-25 01:15:19 -07:00
|
|
|
static void action_page_setup (MooEditWindow *window);
|
|
|
|
static void action_print (MooEditWindow *window);
|
2006-11-13 23:12:57 -08:00
|
|
|
static void action_print_preview (MooEditWindow *window);
|
2006-11-18 23:12:56 -08:00
|
|
|
static void action_print_pdf (MooEditWindow *window);
|
2006-03-25 01:40:54 -08:00
|
|
|
#endif
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
/* MOO_TYPE_EDIT_WINDOW */
|
|
|
|
G_DEFINE_TYPE (MooEditWindow, moo_edit_window, MOO_TYPE_WINDOW)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2005-09-02 23:25:43 -07:00
|
|
|
PROP_EDITOR,
|
2005-09-16 20:53:25 -07:00
|
|
|
PROP_ACTIVE_DOC,
|
2006-05-26 22:37:32 -07:00
|
|
|
PROP_USE_FULL_NAME_IN_TITLE,
|
2005-09-16 20:53:25 -07:00
|
|
|
|
|
|
|
/* aux properties */
|
|
|
|
PROP_CAN_RELOAD,
|
|
|
|
PROP_HAS_OPEN_DOCUMENT,
|
|
|
|
PROP_CAN_UNDO,
|
|
|
|
PROP_CAN_REDO,
|
|
|
|
PROP_HAS_SELECTION,
|
2006-04-29 20:54:03 -07:00
|
|
|
PROP_HAS_COMMENTS,
|
2005-11-18 05:02:42 -08:00
|
|
|
PROP_HAS_TEXT,
|
|
|
|
PROP_HAS_JOBS_RUNNING,
|
|
|
|
PROP_HAS_STOP_CLIENTS
|
2005-07-29 08:25:29 -07:00
|
|
|
};
|
|
|
|
|
2005-09-04 21:24:21 -07:00
|
|
|
enum {
|
|
|
|
NEW_DOC,
|
|
|
|
CLOSE_DOC,
|
2005-09-07 04:19:26 -07:00
|
|
|
CLOSE_DOC_AFTER,
|
2005-09-04 21:24:21 -07:00
|
|
|
NUM_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[NUM_SIGNALS];
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
#define INSTALL_PROP(prop_id,name) \
|
|
|
|
g_object_class_install_property (gobject_class, prop_id, \
|
|
|
|
g_param_spec_boolean (name, name, name, FALSE, G_PARAM_READABLE))
|
|
|
|
|
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
static void
|
|
|
|
moo_edit_window_class_init (MooEditWindowClass *klass)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2006-11-25 13:03:17 -08:00
|
|
|
guint i;
|
2005-06-22 11:20:32 -07:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2005-11-18 05:02:42 -08:00
|
|
|
GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
|
2005-06-22 11:20:32 -07:00
|
|
|
MooWindowClass *window_class = MOO_WINDOW_CLASS (klass);
|
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
action_checks_init ();
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
gobject_class->constructor = moo_edit_window_constructor;
|
|
|
|
gobject_class->finalize = moo_edit_window_finalize;
|
|
|
|
gobject_class->set_property = moo_edit_window_set_property;
|
|
|
|
gobject_class->get_property = moo_edit_window_get_property;
|
2005-11-18 05:02:42 -08:00
|
|
|
gtkobject_class->destroy = moo_edit_window_destroy;
|
2006-06-25 01:15:19 -07:00
|
|
|
window_class->close = (gboolean (*) (MooWindow*)) moo_edit_window_close;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
moo_edit_tab_atom = gdk_atom_intern ("MOO_EDIT_TAB", FALSE);
|
2006-06-23 00:48:32 -07:00
|
|
|
text_uri_atom = gdk_atom_intern ("text/uri-list", FALSE);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
2006-08-18 23:15:42 -07:00
|
|
|
g_type_class_add_private (klass, sizeof (MooEditWindowPrivate));
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EDITOR,
|
|
|
|
g_param_spec_object ("editor",
|
|
|
|
"editor",
|
|
|
|
"editor",
|
|
|
|
MOO_TYPE_EDITOR,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ACTIVE_DOC,
|
|
|
|
g_param_spec_object ("active-doc",
|
|
|
|
"active-doc",
|
|
|
|
"active-doc",
|
|
|
|
MOO_TYPE_EDIT,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USE_FULL_NAME_IN_TITLE,
|
|
|
|
g_param_spec_boolean ("use-full-name-in-title",
|
|
|
|
"use-full-name-in-title",
|
|
|
|
"use-full-name-in-title",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-09-04 21:24:21 -07:00
|
|
|
signals[NEW_DOC] =
|
|
|
|
g_signal_new ("new-doc",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditWindowClass, new_doc),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT);
|
|
|
|
|
|
|
|
signals[CLOSE_DOC] =
|
|
|
|
g_signal_new ("close-doc",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditWindowClass, close_doc),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT);
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
signals[CLOSE_DOC_AFTER] =
|
|
|
|
g_signal_new ("close-doc-after",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditWindowClass, close_doc_after),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
INSTALL_PROP (PROP_CAN_RELOAD, "can-reload");
|
|
|
|
INSTALL_PROP (PROP_HAS_OPEN_DOCUMENT, "has-open-document");
|
|
|
|
INSTALL_PROP (PROP_CAN_UNDO, "can-undo");
|
|
|
|
INSTALL_PROP (PROP_CAN_REDO, "can-redo");
|
|
|
|
INSTALL_PROP (PROP_HAS_SELECTION, "has-selection");
|
2006-04-29 20:54:03 -07:00
|
|
|
INSTALL_PROP (PROP_HAS_COMMENTS, "has-comments");
|
2005-09-16 20:53:25 -07:00
|
|
|
INSTALL_PROP (PROP_HAS_TEXT, "has-text");
|
2005-11-18 05:02:42 -08:00
|
|
|
INSTALL_PROP (PROP_HAS_JOBS_RUNNING, "has-jobs-running");
|
|
|
|
INSTALL_PROP (PROP_HAS_STOP_CLIENTS, "has-stop-clients");
|
2005-09-16 20:53:25 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_window_class_set_id (window_class, "Editor", "Editor");
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "NewDoc", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", Q_("New document|New"),
|
|
|
|
"label", Q_("New document|New"),
|
|
|
|
"tooltip", _("Create new document"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_NEW,
|
2006-04-04 02:21:07 -07:00
|
|
|
"accel", "<ctrl>N",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_new_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Open", NULL,
|
|
|
|
"display-name", GTK_STOCK_OPEN,
|
2006-08-10 02:24:12 -07:00
|
|
|
"label", _("_Open..."),
|
|
|
|
"tooltip", _("Open..."),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_OPEN,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>O",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_open,
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Reload", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Reload"),
|
|
|
|
"label", _("_Reload"),
|
|
|
|
"tooltip", _("Reload document"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_REFRESH,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "F5",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_reload,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "can-reload",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Save", NULL,
|
|
|
|
"display-name", GTK_STOCK_SAVE,
|
|
|
|
"label", GTK_STOCK_SAVE,
|
|
|
|
"tooltip", GTK_STOCK_SAVE,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_SAVE,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>S",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_save,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "SaveAs", NULL,
|
|
|
|
"display-name", GTK_STOCK_SAVE_AS,
|
2006-08-10 02:24:12 -07:00
|
|
|
"label", _("Save _As..."),
|
|
|
|
"tooltip", _("Save as..."),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_SAVE_AS,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl><shift>S",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_save_as,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Close", NULL,
|
|
|
|
"display-name", GTK_STOCK_CLOSE,
|
|
|
|
"label", GTK_STOCK_CLOSE,
|
2006-08-10 02:24:12 -07:00
|
|
|
"tooltip", _("Close document"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_CLOSE,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>W",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_close_tab,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "CloseAll", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Close All"),
|
|
|
|
"label", _("Close _All"),
|
|
|
|
"tooltip", _("Close all documents"),
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<shift><ctrl>W",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_close_all,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Undo", NULL,
|
|
|
|
"display-name", GTK_STOCK_UNDO,
|
|
|
|
"label", GTK_STOCK_UNDO,
|
|
|
|
"tooltip", GTK_STOCK_UNDO,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_UNDO,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>Z",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "undo",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "can-undo",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Redo", NULL,
|
|
|
|
"display-name", GTK_STOCK_REDO,
|
|
|
|
"label", GTK_STOCK_REDO,
|
|
|
|
"tooltip", GTK_STOCK_REDO,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_REDO,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<shift><ctrl>Z",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "redo",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "can-redo",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Cut", NULL,
|
|
|
|
"display-name", GTK_STOCK_CUT,
|
|
|
|
"label", GTK_STOCK_CUT,
|
|
|
|
"tooltip", GTK_STOCK_CUT,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_CUT,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>X",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "cut-clipboard",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-selection",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Copy", NULL,
|
|
|
|
"display-name", GTK_STOCK_COPY,
|
|
|
|
"label", GTK_STOCK_COPY,
|
|
|
|
"tooltip", GTK_STOCK_COPY,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_COPY,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>C",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "copy-clipboard",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-selection",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Paste", NULL,
|
|
|
|
"display-name", GTK_STOCK_PASTE,
|
|
|
|
"label", GTK_STOCK_PASTE,
|
|
|
|
"tooltip", GTK_STOCK_PASTE,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_PASTE,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>V",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "paste-clipboard",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Delete", NULL,
|
|
|
|
"display-name", GTK_STOCK_DELETE,
|
|
|
|
"label", GTK_STOCK_DELETE,
|
|
|
|
"tooltip", GTK_STOCK_DELETE,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_DELETE,
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "delete-selection",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-selection",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "SelectAll", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Select All"),
|
|
|
|
"label", _("Select _All"),
|
|
|
|
"tooltip", _("Select all"),
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>A",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-callback", moo_text_view_select_all,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-text",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "PreviousTab", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Previous Tab"),
|
|
|
|
"label", _("_Previous Tab"),
|
|
|
|
"tooltip", _("Previous tab"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_BACK,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<alt>Left",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_previous_tab,
|
2005-11-24 00:34:02 -08:00
|
|
|
"condition::sensitive", "has-open-document",
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "NextTab", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Next Tab"),
|
|
|
|
"label", _("_Next Tab"),
|
|
|
|
"tooltip", _("Next tab"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_FORWARD,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<alt>Right",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_next_tab,
|
2005-11-24 00:34:02 -08:00
|
|
|
"condition::sensitive", "has-open-document",
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Find", NULL,
|
|
|
|
"display-name", GTK_STOCK_FIND,
|
|
|
|
"label", GTK_STOCK_FIND,
|
|
|
|
"tooltip", GTK_STOCK_FIND,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_FIND,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>F",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "find-interactive",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "FindNext", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Find Next"),
|
|
|
|
"label", ("Find _Next"),
|
|
|
|
"tooltip", _("Find next"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_FORWARD,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "F3",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "find-next-interactive",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "FindPrevious", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Find Previous"),
|
|
|
|
"label", _("Find _Previous"),
|
|
|
|
"tooltip", _("Find previous"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_BACK,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<shift>F3",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "find-prev-interactive",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Replace", NULL,
|
|
|
|
"display-name", GTK_STOCK_FIND_AND_REPLACE,
|
|
|
|
"label", GTK_STOCK_FIND_AND_REPLACE,
|
|
|
|
"tooltip", GTK_STOCK_FIND_AND_REPLACE,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_FIND_AND_REPLACE,
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>R",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "replace-interactive",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "FindCurrent", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Find Current Word"),
|
|
|
|
"label", _("Find Current _Word"),
|
2006-06-10 02:10:43 -07:00
|
|
|
"stock-id", GTK_STOCK_FIND,
|
2006-11-23 20:47:06 -08:00
|
|
|
"accel", "F4",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_find_now_f,
|
2006-06-10 02:10:43 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "FindCurrentBack", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Find Current Word Backwards"),
|
|
|
|
"label", _("Find Current Word _Backwards"),
|
2006-06-10 02:10:43 -07:00
|
|
|
"stock-id", GTK_STOCK_FIND,
|
2006-11-23 20:47:06 -08:00
|
|
|
"accel", "<shift>F4",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_find_now_b,
|
2006-06-10 02:10:43 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "GoToLine", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Go to Line"),
|
|
|
|
"label", _("_Go to Line"),
|
|
|
|
"tooltip", _("Go to line"),
|
2005-10-13 07:08:18 -07:00
|
|
|
"accel", "<ctrl>G",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-signal", "goto-line-interactive",
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-10-13 07:08:18 -07:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-11-25 23:09:47 -08:00
|
|
|
moo_window_class_new_action (window_class, "DocumentSubmenu", NULL,
|
|
|
|
"label", _("_Document"),
|
|
|
|
"no-accel", TRUE,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "WrapText", NULL,
|
|
|
|
"action-type::", MOO_TYPE_TOGGLE_ACTION,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Toggle Text Wrapping"),
|
|
|
|
"label", _("_Wrap Text"),
|
2006-06-17 00:38:23 -07:00
|
|
|
"toggled-callback", wrap_text_toggled,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "LineNumbers", NULL,
|
|
|
|
"action-type::", MOO_TYPE_TOGGLE_ACTION,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Toggle Line Numbers Display"),
|
|
|
|
"label", _("_Show Line Numbers"),
|
2006-06-17 00:38:23 -07:00
|
|
|
"toggled-callback", line_numbers_toggled,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "FocusDoc", NULL,
|
2006-11-23 20:47:06 -08:00
|
|
|
"display-name", _("Focus Document"),
|
|
|
|
"label", _("Focus Document"),
|
|
|
|
"tooltip", _("Focus Document"),
|
2005-11-09 08:40:51 -08:00
|
|
|
"accel", "<alt>C",
|
2005-11-19 19:59:01 -08:00
|
|
|
"closure-callback", gtk_widget_grab_focus,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2005-11-09 08:40:51 -08:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, STOP_ACTION_ID, NULL,
|
|
|
|
"display-name", GTK_STOCK_STOP,
|
|
|
|
"label", GTK_STOCK_STOP,
|
|
|
|
"tooltip", GTK_STOCK_STOP,
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_STOP,
|
2005-11-18 05:02:42 -08:00
|
|
|
"accel", "Escape",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_abort_jobs,
|
2005-11-18 05:02:42 -08:00
|
|
|
"condition::sensitive", "has-jobs-running",
|
|
|
|
"condition::visible", "has-stop-clients",
|
|
|
|
NULL);
|
|
|
|
|
2006-11-23 18:09:41 -08:00
|
|
|
#ifdef ENABLE_BOOKMARKS
|
2006-11-25 13:03:17 -08:00
|
|
|
for (i = 1; i < 10; ++i)
|
|
|
|
{
|
2006-12-02 23:49:14 -08:00
|
|
|
char *action_id = g_strdup_printf (MOO_EDIT_GOTO_BOOKMARK_ACTION "%u", i);
|
2006-11-25 13:03:17 -08:00
|
|
|
moo_window_class_new_action_custom (window_class, action_id, NULL,
|
|
|
|
create_goto_bookmark_action,
|
|
|
|
GUINT_TO_POINTER (i),
|
|
|
|
NULL);
|
|
|
|
g_free (action_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
moo_window_class_new_action_custom (window_class, "BookmarksMenu", NULL,
|
|
|
|
create_bookmarks_menu_action,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2006-10-17 22:24:35 -07:00
|
|
|
moo_window_class_new_action (window_class, "ToggleBookmark", NULL,
|
|
|
|
"display-name", "Toggle Bookmark",
|
|
|
|
"label", "Toggle Bookmark",
|
|
|
|
"tooltip", "Toggle bookmark",
|
|
|
|
"stock-id", MOO_STOCK_EDIT_BOOKMARK,
|
|
|
|
"accel", "<ctrl>B",
|
|
|
|
"closure-callback", action_toggle_bookmark,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_window_class_new_action (window_class, "NextBookmark", NULL,
|
|
|
|
"display-name", "Next Bookmark",
|
|
|
|
"label", "Next Bookmark",
|
|
|
|
"tooltip", "Next bookmark",
|
|
|
|
"accel", "<alt>Down",
|
2006-11-25 13:30:19 -08:00
|
|
|
"connect-accel", TRUE,
|
2006-10-17 22:24:35 -07:00
|
|
|
"closure-callback", action_next_bookmark,
|
|
|
|
"condition::visible", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_window_class_new_action (window_class, "PreviousBookmark", NULL,
|
|
|
|
"display-name", "Previous Bookmark",
|
|
|
|
"label", "Previous Bookmark",
|
|
|
|
"tooltip", "Previous bookmark",
|
|
|
|
"accel", "<alt>Up",
|
2006-11-25 13:30:19 -08:00
|
|
|
"connect-accel", TRUE,
|
2006-10-17 22:24:35 -07:00
|
|
|
"closure-callback", action_prev_bookmark,
|
|
|
|
"condition::visible", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
#endif
|
2005-12-10 23:25:20 -08:00
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "NextPlaceholder", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Next Placeholder"),
|
|
|
|
"label", _("Next Placeholder"),
|
|
|
|
"tooltip", _("Go to next placeholder"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_FORWARD,
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_next_ph,
|
2006-04-24 12:27:34 -07:00
|
|
|
"condition::visible", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "PrevPlaceholder", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Previous Placeholder"),
|
|
|
|
"label", _("Previous Placeholder"),
|
|
|
|
"tooltip", _("Go to previous placeholder"),
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_GO_BACK,
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_prev_ph,
|
2006-04-24 12:27:34 -07:00
|
|
|
"condition::visible", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Comment", NULL,
|
2006-12-08 15:54:44 -08:00
|
|
|
/* action */
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Comment"),
|
|
|
|
"label", _("Comment"),
|
|
|
|
"tooltip", _("Comment"),
|
2005-12-16 08:51:31 -08:00
|
|
|
"closure-callback", moo_edit_comment,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2006-04-29 20:54:03 -07:00
|
|
|
"condition::sensitive", "has-comments",
|
2005-12-16 08:51:31 -08:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Uncomment", NULL,
|
2006-12-08 15:54:44 -08:00
|
|
|
/* action */
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Uncomment"),
|
|
|
|
"label", _("Uncomment"),
|
|
|
|
"tooltip", _("Uncomment"),
|
2005-12-16 08:51:31 -08:00
|
|
|
"closure-callback", moo_edit_uncomment,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
2006-04-29 20:54:03 -07:00
|
|
|
"condition::sensitive", "has-comments",
|
2005-12-16 08:51:31 -08:00
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Indent", NULL,
|
|
|
|
"display-name", GTK_STOCK_INDENT,
|
|
|
|
"label", GTK_STOCK_INDENT,
|
|
|
|
"tooltip", GTK_STOCK_INDENT,
|
2006-08-03 01:45:39 -07:00
|
|
|
"stock-id", GTK_STOCK_INDENT,
|
2006-04-25 00:29:39 -07:00
|
|
|
"closure-callback", moo_text_view_indent,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Unindent", NULL,
|
|
|
|
"display-name", GTK_STOCK_UNINDENT,
|
|
|
|
"label", GTK_STOCK_UNINDENT,
|
|
|
|
"tooltip", GTK_STOCK_UNINDENT,
|
2006-08-03 01:45:39 -07:00
|
|
|
"stock-id", GTK_STOCK_UNINDENT,
|
2006-04-25 00:29:39 -07:00
|
|
|
"closure-callback", moo_text_view_unindent,
|
|
|
|
"closure-proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "NoDocuments", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"label", _("No Documents"),
|
2006-05-23 13:09:45 -07:00
|
|
|
"no-accel", TRUE,
|
2006-11-25 13:03:17 -08:00
|
|
|
"sensitive", FALSE,
|
|
|
|
"condition::visible", "!has-open-document",
|
2006-05-23 13:09:45 -07:00
|
|
|
NULL);
|
|
|
|
|
2006-07-05 12:14:02 -07:00
|
|
|
#ifdef ENABLE_PRINTING
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "PageSetup", NULL,
|
2006-08-10 02:24:12 -07:00
|
|
|
"display-name", _("Page Setup"),
|
|
|
|
"label", _("Page Setup"),
|
|
|
|
"tooltip", _("Page Setup"),
|
2006-03-25 01:40:54 -08:00
|
|
|
"accel", "<ctrl><shift>P",
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_page_setup,
|
2006-03-25 01:40:54 -08:00
|
|
|
NULL);
|
|
|
|
|
2006-11-13 23:12:57 -08:00
|
|
|
moo_window_class_new_action (window_class, "PrintPreview", NULL,
|
|
|
|
"display-name", GTK_STOCK_PRINT_PREVIEW,
|
|
|
|
"label", GTK_STOCK_PRINT_PREVIEW,
|
|
|
|
"tooltip", GTK_STOCK_PRINT_PREVIEW,
|
|
|
|
"stock-id", GTK_STOCK_PRINT_PREVIEW,
|
|
|
|
"closure-callback", action_print_preview,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action (window_class, "Print", NULL,
|
|
|
|
"display-name", GTK_STOCK_PRINT,
|
|
|
|
"label", GTK_STOCK_PRINT,
|
|
|
|
"tooltip", GTK_STOCK_PRINT,
|
2006-03-25 01:40:54 -08:00
|
|
|
"accel", "<ctrl>P",
|
2006-05-08 21:57:16 -07:00
|
|
|
"stock-id", GTK_STOCK_PRINT,
|
2006-06-25 01:15:19 -07:00
|
|
|
"closure-callback", action_print,
|
2006-03-25 01:40:54 -08:00
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
2006-11-18 23:12:56 -08:00
|
|
|
|
|
|
|
moo_window_class_new_action (window_class, "PrintPdf", NULL,
|
|
|
|
"display-name", _("Export as PDF"),
|
|
|
|
"label", _("Export as PDF..."),
|
|
|
|
"tooltip", _("Export as PDF"),
|
|
|
|
"stock-id", GTK_STOCK_PRINT,
|
|
|
|
"closure-callback", action_print_pdf,
|
|
|
|
"condition::sensitive", "has-open-document",
|
|
|
|
NULL);
|
2006-03-25 01:40:54 -08:00
|
|
|
#endif
|
|
|
|
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_window_class_new_action_custom (window_class, LANG_ACTION_ID, NULL,
|
2005-10-13 07:08:18 -07:00
|
|
|
(MooWindowActionFunc) create_lang_action,
|
2005-11-05 23:33:24 -08:00
|
|
|
NULL, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-17 21:13:25 -08:00
|
|
|
static void
|
|
|
|
moo_edit_window_init (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2006-08-18 23:15:42 -07:00
|
|
|
window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, MOO_TYPE_EDIT_WINDOW, MooEditWindowPrivate);
|
2005-09-07 04:19:26 -07:00
|
|
|
window->priv->prefix = g_strdup ("medit");
|
2005-09-08 00:46:48 -07:00
|
|
|
window->priv->panes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
window->priv->panes_to_save = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
|
2006-05-04 20:41:23 -07:00
|
|
|
(GDestroyNotify) pane_params_free);
|
2005-06-22 11:20:32 -07:00
|
|
|
g_object_set (G_OBJECT (window),
|
2005-07-25 10:56:59 -07:00
|
|
|
"menubar-ui-name", "Editor/Menubar",
|
|
|
|
"toolbar-ui-name", "Editor/Toolbar",
|
2005-06-22 11:20:32 -07:00
|
|
|
NULL);
|
2005-11-03 14:55:48 -08:00
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
window->priv->use_full_name = TRUE;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
|
|
|
windows = g_slist_prepend (windows, window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
MooEditor *
|
|
|
|
moo_edit_window_get_editor (MooEditWindow *window)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
return window->priv->editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-18 05:02:42 -08:00
|
|
|
static void
|
|
|
|
moo_edit_window_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
if (window->priv->doc_list_merge_id)
|
|
|
|
{
|
|
|
|
moo_ui_xml_remove_ui (window->priv->xml,
|
|
|
|
window->priv->doc_list_merge_id);
|
|
|
|
window->priv->doc_list_merge_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->priv->doc_list_update_idle)
|
|
|
|
{
|
|
|
|
g_source_remove (window->priv->doc_list_update_idle);
|
|
|
|
window->priv->doc_list_update_idle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->priv->xml)
|
|
|
|
{
|
|
|
|
g_object_unref (window->priv->xml);
|
|
|
|
window->priv->xml = NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-18 05:02:42 -08:00
|
|
|
if (window->priv->stop_clients || window->priv->jobs)
|
|
|
|
{
|
|
|
|
GSList *list, *l;
|
|
|
|
|
|
|
|
moo_edit_window_abort_jobs (window);
|
|
|
|
g_slist_foreach (window->priv->jobs, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (window->priv->jobs);
|
|
|
|
window->priv->jobs = NULL;
|
|
|
|
|
|
|
|
list = g_slist_copy (window->priv->stop_clients);
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
|
|
|
moo_edit_window_remove_stop_client (window, l->data);
|
|
|
|
g_assert (window->priv->stop_clients == NULL);
|
|
|
|
g_slist_free (list);
|
|
|
|
}
|
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
windows = g_slist_remove (windows, window);
|
|
|
|
|
2005-11-18 05:02:42 -08:00
|
|
|
GTK_OBJECT_CLASS(moo_edit_window_parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
static void
|
|
|
|
moo_edit_window_finalize (GObject *object)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
2005-09-04 11:41:13 -07:00
|
|
|
/* XXX */
|
2005-10-13 07:08:18 -07:00
|
|
|
g_hash_table_destroy (window->priv->panes);
|
|
|
|
|
|
|
|
if (window->priv->panes_to_save)
|
|
|
|
g_hash_table_destroy (window->priv->panes_to_save);
|
|
|
|
|
|
|
|
if (window->priv->save_params_idle)
|
|
|
|
{
|
|
|
|
g_warning ("%s: oops", G_STRLOC);
|
|
|
|
g_source_remove (window->priv->save_params_idle);
|
|
|
|
}
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
g_free (window->priv->prefix);
|
2006-08-18 23:15:42 -07:00
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
G_OBJECT_CLASS (moo_edit_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
static void
|
|
|
|
moo_edit_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
case PROP_EDITOR:
|
|
|
|
window->priv->editor = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTIVE_DOC:
|
|
|
|
moo_edit_window_set_active_doc (window, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
case PROP_USE_FULL_NAME_IN_TITLE:
|
|
|
|
if (window->priv->use_full_name != g_value_get_boolean (value))
|
|
|
|
{
|
|
|
|
window->priv->use_full_name = g_value_get_boolean (value);
|
|
|
|
update_window_title (window);
|
|
|
|
g_object_notify (object, "use-full-name-in-title");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moo_edit_window_get_property(GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
2005-09-16 20:53:25 -07:00
|
|
|
MooEdit *doc;
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
case PROP_EDITOR:
|
|
|
|
g_value_set_object (value, window->priv->editor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTIVE_DOC:
|
|
|
|
g_value_set_object (value, moo_edit_window_get_active_doc (window));
|
|
|
|
break;
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
case PROP_USE_FULL_NAME_IN_TITLE:
|
|
|
|
g_value_set_boolean (value, window->priv->use_full_name != 0);
|
|
|
|
break;
|
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
case PROP_CAN_RELOAD:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && moo_edit_get_filename (doc));
|
|
|
|
break;
|
|
|
|
case PROP_HAS_OPEN_DOCUMENT:
|
|
|
|
g_value_set_boolean (value, ACTIVE_DOC (window) != NULL);
|
|
|
|
break;
|
|
|
|
case PROP_CAN_UNDO:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && moo_text_view_can_undo (MOO_TEXT_VIEW (doc)));
|
|
|
|
break;
|
|
|
|
case PROP_CAN_REDO:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && moo_text_view_can_redo (MOO_TEXT_VIEW (doc)));
|
|
|
|
break;
|
|
|
|
case PROP_HAS_SELECTION:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && moo_text_view_has_selection (MOO_TEXT_VIEW (doc)));
|
|
|
|
break;
|
2006-04-29 20:54:03 -07:00
|
|
|
case PROP_HAS_COMMENTS:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && _moo_edit_has_comments (doc, NULL, NULL));
|
|
|
|
break;
|
2005-09-16 20:53:25 -07:00
|
|
|
case PROP_HAS_TEXT:
|
|
|
|
doc = ACTIVE_DOC (window);
|
|
|
|
g_value_set_boolean (value, doc && moo_text_view_has_text (MOO_TEXT_VIEW (doc)));
|
|
|
|
break;
|
2005-11-18 05:02:42 -08:00
|
|
|
case PROP_HAS_JOBS_RUNNING:
|
|
|
|
g_value_set_boolean (value, window->priv->jobs != NULL);
|
|
|
|
break;
|
|
|
|
case PROP_HAS_STOP_CLIENTS:
|
|
|
|
g_value_set_boolean (value, window->priv->stop_clients != NULL);
|
|
|
|
break;
|
2005-09-16 20:53:25 -07:00
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2005-08-07 19:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
void
|
|
|
|
moo_edit_window_set_title_prefix (MooEditWindow *window,
|
|
|
|
const char *prefix)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
g_free (window->priv->prefix);
|
|
|
|
window->priv->prefix = g_strdup (prefix);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
if (GTK_WIDGET_REALIZED (GTK_WIDGET (window)))
|
|
|
|
update_window_title (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Constructing
|
|
|
|
*/
|
|
|
|
|
2006-05-04 00:30:32 -07:00
|
|
|
GObject *
|
|
|
|
moo_edit_window_constructor (GType type,
|
|
|
|
guint n_props,
|
|
|
|
GObjectConstructParam *props)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
GtkWidget *notebook;
|
2005-06-22 11:20:32 -07:00
|
|
|
MooEditWindow *window;
|
2006-04-09 15:16:48 -07:00
|
|
|
GtkWindowGroup *group;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
GObject *object =
|
|
|
|
G_OBJECT_CLASS(moo_edit_window_parent_class)->constructor (type, n_props, props);
|
|
|
|
|
|
|
|
window = MOO_EDIT_WINDOW (object);
|
2005-09-02 23:25:43 -07:00
|
|
|
g_return_val_if_fail (window->priv->editor != NULL, object);
|
|
|
|
|
2006-04-09 15:16:48 -07:00
|
|
|
group = gtk_window_group_new ();
|
|
|
|
gtk_window_group_add_window (group, GTK_WINDOW (window));
|
|
|
|
g_object_unref (group);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
create_paned (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
notebook = g_object_new (MOO_TYPE_NOTEBOOK,
|
|
|
|
"show-tabs", TRUE,
|
|
|
|
"enable-popup", TRUE,
|
|
|
|
"enable-reordering", TRUE,
|
|
|
|
NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_widget_show (notebook);
|
2005-09-04 15:32:08 -07:00
|
|
|
moo_big_paned_add_child (window->paned, notebook);
|
2005-08-31 09:55:02 -07:00
|
|
|
window->priv->notebook = MOO_NOTEBOOK (notebook);
|
2005-09-02 23:25:43 -07:00
|
|
|
setup_notebook (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-04-05 00:54:33 -07:00
|
|
|
create_statusbar (window);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
g_signal_connect (window, "realize", G_CALLBACK (update_window_title), NULL);
|
2006-05-21 16:10:48 -07:00
|
|
|
g_signal_connect (window, "notify::ui-xml",
|
|
|
|
G_CALLBACK (moo_edit_window_update_doc_list), NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
edit_changed (window, NULL);
|
2006-05-26 22:37:32 -07:00
|
|
|
moo_edit_window_check_actions (window);
|
2005-09-08 00:46:48 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
/* XXX */
|
2006-05-04 00:30:32 -07:00
|
|
|
static void
|
|
|
|
update_window_title (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
const char *name;
|
2005-09-02 16:27:25 -07:00
|
|
|
MooEditStatus status;
|
2005-06-22 11:20:32 -07:00
|
|
|
GString *title;
|
2006-05-04 00:30:32 -07:00
|
|
|
gboolean modified;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
if (!edit)
|
|
|
|
{
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window),
|
2005-09-07 04:19:26 -07:00
|
|
|
window->priv->prefix ? window->priv->prefix : "");
|
2005-09-02 23:25:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-26 22:37:32 -07:00
|
|
|
if (window->priv->use_full_name)
|
2005-06-22 11:20:32 -07:00
|
|
|
name = moo_edit_get_display_filename (edit);
|
|
|
|
else
|
|
|
|
name = moo_edit_get_display_basename (edit);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
if (!name)
|
|
|
|
name = "<\?\?\?\?\?>";
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
status = moo_edit_get_status (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
title = g_string_new ("");
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
if (window->priv->prefix)
|
|
|
|
g_string_append_printf (title, "%s - ", window->priv->prefix);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-09-03 15:48:05 -07:00
|
|
|
g_string_append_printf (title, "%s", name);
|
|
|
|
|
2006-05-04 00:30:32 -07:00
|
|
|
modified = (status & MOO_EDIT_MODIFIED) && !(status & MOO_EDIT_CLEAN);
|
|
|
|
|
|
|
|
if ((status & MOO_EDIT_NEW) && !modified)
|
|
|
|
g_string_append (title, " [new file]");
|
|
|
|
|
2005-09-03 15:48:05 -07:00
|
|
|
if (status & MOO_EDIT_MODIFIED_ON_DISK)
|
|
|
|
g_string_append (title, " [modified on disk]");
|
|
|
|
else if (status & MOO_EDIT_DELETED)
|
|
|
|
g_string_append (title, " [deleted]");
|
|
|
|
|
2006-05-04 00:30:32 -07:00
|
|
|
if (modified)
|
2005-09-03 15:48:05 -07:00
|
|
|
g_string_append (title, " [modified]");
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), title->str);
|
|
|
|
g_string_free (title, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 01:57:05 -07:00
|
|
|
MooEditWindow *
|
|
|
|
moo_edit_get_window (MooEdit *edit)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (edit));
|
|
|
|
|
|
|
|
if (MOO_IS_EDIT_WINDOW (toplevel))
|
|
|
|
return MOO_EDIT_WINDOW (toplevel);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 01:15:19 -07:00
|
|
|
gboolean
|
|
|
|
moo_edit_window_close_all (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GSList *docs;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
|
|
|
|
|
|
|
docs = moo_edit_window_list_docs (window);
|
|
|
|
result = moo_editor_close_docs (window->priv->editor, docs, TRUE);
|
|
|
|
|
|
|
|
g_slist_free (docs);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static gboolean
|
|
|
|
moo_edit_window_close (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-12-04 12:13:58 -08:00
|
|
|
moo_editor_close_window (window->priv->editor, window, TRUE);
|
2005-09-02 23:25:43 -07:00
|
|
|
return TRUE;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 01:15:19 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Actions
|
|
|
|
*/
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_new_doc (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
moo_editor_new_doc (window->priv->editor, window);
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
2005-07-31 07:53:10 -07:00
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_open (MooEditWindow *window)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
moo_editor_open (window->priv->editor, window, GTK_WIDGET (window), NULL);
|
|
|
|
}
|
2005-07-31 07:53:10 -07:00
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_reload (MooEditWindow *window)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (edit != NULL);
|
2005-12-04 12:13:58 -08:00
|
|
|
_moo_editor_reload (window->priv->editor, edit, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_save (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
MooEdit *edit = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (edit != NULL);
|
2005-12-04 12:13:58 -08:00
|
|
|
_moo_editor_save (window->priv->editor, edit, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_save_as (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
MooEdit *edit = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (edit != NULL);
|
2005-12-04 12:13:58 -08:00
|
|
|
_moo_editor_save_as (window->priv->editor, edit, NULL, NULL, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_close_tab (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
MooEdit *edit = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (edit != NULL);
|
2005-12-04 12:13:58 -08:00
|
|
|
moo_editor_close_doc (window->priv->editor, edit, TRUE);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_close_all (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2006-06-25 01:15:19 -07:00
|
|
|
moo_edit_window_close_all (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_previous_tab (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-11-16 23:04:35 -08:00
|
|
|
MooEdit *doc;
|
2005-08-31 09:55:02 -07:00
|
|
|
int n = moo_notebook_get_current_page (window->priv->notebook);
|
2005-11-16 23:04:35 -08:00
|
|
|
if (n > 0)
|
2005-08-31 09:55:02 -07:00
|
|
|
moo_notebook_set_current_page (window->priv->notebook, n - 1);
|
2005-11-16 23:04:35 -08:00
|
|
|
else
|
|
|
|
moo_notebook_set_current_page (window->priv->notebook, -1);
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
if (doc)
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (doc));
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-09 18:49:00 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_next_tab (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-11-16 23:04:35 -08:00
|
|
|
MooEdit *doc;
|
2005-08-31 09:55:02 -07:00
|
|
|
int n = moo_notebook_get_current_page (window->priv->notebook);
|
2005-11-16 23:04:35 -08:00
|
|
|
if (n < moo_notebook_get_n_pages (window->priv->notebook) - 1)
|
2005-08-31 09:55:02 -07:00
|
|
|
moo_notebook_set_current_page (window->priv->notebook, n + 1);
|
2005-11-16 23:04:35 -08:00
|
|
|
else
|
|
|
|
moo_notebook_set_current_page (window->priv->notebook, 0);
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
if (doc)
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (doc));
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-10 02:10:43 -07:00
|
|
|
static void
|
|
|
|
moo_edit_window_find_now (MooEditWindow *window,
|
|
|
|
gboolean forward)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (doc, "find-word-at-cursor", forward);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_find_now_f (MooEditWindow *window)
|
2006-06-10 02:10:43 -07:00
|
|
|
{
|
|
|
|
moo_edit_window_find_now (window, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_find_now_b (MooEditWindow *window)
|
2006-06-10 02:10:43 -07:00
|
|
|
{
|
|
|
|
moo_edit_window_find_now (window, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 01:15:19 -07:00
|
|
|
static void
|
|
|
|
action_abort_jobs (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
moo_edit_window_abort_jobs (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-23 18:09:41 -08:00
|
|
|
#ifdef ENABLE_BOOKMARKS
|
2006-10-17 22:24:35 -07:00
|
|
|
static void
|
|
|
|
action_toggle_bookmark (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
moo_edit_toggle_bookmark (doc, moo_text_view_get_cursor_line (MOO_TEXT_VIEW (doc)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_next_bookmark (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
int cursor;
|
|
|
|
GSList *bookmarks;
|
|
|
|
MooEdit *doc = moo_edit_window_get_active_doc (window);
|
|
|
|
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
cursor = moo_text_view_get_cursor_line (MOO_TEXT_VIEW (doc));
|
|
|
|
bookmarks = moo_edit_get_bookmarks_in_range (doc, cursor + 1, -1);
|
|
|
|
|
|
|
|
if (bookmarks)
|
|
|
|
{
|
2006-11-25 13:03:17 -08:00
|
|
|
moo_edit_goto_bookmark (doc, bookmarks->data);
|
2006-10-17 22:24:35 -07:00
|
|
|
g_slist_free (bookmarks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_prev_bookmark (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
int cursor;
|
|
|
|
GSList *bookmarks = NULL;
|
|
|
|
MooEdit *doc = moo_edit_window_get_active_doc (window);
|
|
|
|
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
cursor = moo_text_view_get_cursor_line (MOO_TEXT_VIEW (doc));
|
|
|
|
|
|
|
|
if (cursor > 0)
|
|
|
|
bookmarks = moo_edit_get_bookmarks_in_range (doc, 0, cursor - 1);
|
|
|
|
|
|
|
|
if (bookmarks)
|
|
|
|
{
|
|
|
|
GSList *last = g_slist_last (bookmarks);
|
2006-11-25 13:03:17 -08:00
|
|
|
moo_edit_goto_bookmark (doc, last->data);
|
2006-10-17 22:24:35 -07:00
|
|
|
g_slist_free (bookmarks);
|
|
|
|
}
|
|
|
|
}
|
2006-11-25 13:03:17 -08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
goto_bookmark_activated (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
MooEditWindow *window;
|
|
|
|
MooEditBookmark *bk;
|
|
|
|
guint n = GPOINTER_TO_UINT (data);
|
|
|
|
|
|
|
|
window = _moo_action_get_window (action);
|
|
|
|
g_return_if_fail (window != NULL);
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
if ((bk = moo_edit_get_bookmark (doc, n)))
|
|
|
|
moo_edit_goto_bookmark (doc, bk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkAction *
|
|
|
|
create_goto_bookmark_action (MooWindow *window,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
guint n = GPOINTER_TO_UINT (data);
|
|
|
|
char *accel;
|
|
|
|
char *name;
|
|
|
|
|
2006-12-02 23:49:14 -08:00
|
|
|
name = g_strdup_printf (MOO_EDIT_GOTO_BOOKMARK_ACTION "%u", n);
|
|
|
|
accel = g_strdup_printf ("<ctrl>%u", n);
|
2006-11-25 13:03:17 -08:00
|
|
|
|
|
|
|
action = g_object_new (MOO_TYPE_ACTION, "name", name, "accel", accel,
|
|
|
|
"connect-accel", TRUE, "accel-editable", FALSE, NULL);
|
|
|
|
g_signal_connect (action, "activate", G_CALLBACK (goto_bookmark_activated), data);
|
|
|
|
moo_bind_bool_property (action, "sensitive", window, "has-open-document", FALSE);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_free (accel);
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bookmark_item_activated (GtkWidget *item)
|
|
|
|
{
|
|
|
|
moo_edit_goto_bookmark (g_object_get_data (G_OBJECT (item), "moo-edit"),
|
|
|
|
g_object_get_data (G_OBJECT (item), "moo-bookmark"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_bookmark_item (MooEditWindow *window,
|
|
|
|
MooEdit *doc,
|
|
|
|
MooEditBookmark *bk)
|
|
|
|
{
|
|
|
|
char *label, *bk_text;
|
|
|
|
GtkWidget *item = NULL;
|
|
|
|
|
|
|
|
bk_text = _moo_edit_bookmark_get_text (bk);
|
|
|
|
label = g_strdup_printf ("%d - \"%s\"", 1 + moo_line_mark_get_line (MOO_LINE_MARK (bk)),
|
|
|
|
bk_text ? bk_text : "");
|
|
|
|
g_free (bk_text);
|
|
|
|
|
|
|
|
if (bk->no)
|
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
char *action_name;
|
|
|
|
|
2006-12-02 23:49:14 -08:00
|
|
|
action_name = g_strdup_printf (MOO_EDIT_GOTO_BOOKMARK_ACTION "%u", bk->no);
|
2006-11-25 13:03:17 -08:00
|
|
|
action = moo_window_get_action (MOO_WINDOW (window), action_name);
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
g_object_set (action, "label", label, NULL);
|
|
|
|
item = gtk_action_create_menu_item (action);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical ("%s: oops", G_STRLOC);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
item = gtk_menu_item_new_with_label (label);
|
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (bookmark_item_activated), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (item), "moo-bookmark", g_object_ref (bk), g_object_unref);
|
|
|
|
g_object_set_data_full (G_OBJECT (item), "moo-edit", g_object_ref (doc), g_object_unref);
|
|
|
|
|
|
|
|
g_free (label);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate_bookmarks (MooEditWindow *window,
|
|
|
|
GtkWidget *menu)
|
|
|
|
{
|
|
|
|
GtkAction *pn;
|
|
|
|
MooEdit *doc;
|
|
|
|
GtkWidget *item;
|
|
|
|
const GSList *bookmarks;
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
bookmarks = moo_edit_list_bookmarks (doc);
|
|
|
|
|
|
|
|
pn = moo_window_get_action (MOO_WINDOW (window), "PreviousBookmark");
|
|
|
|
item = gtk_action_create_menu_item (pn);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
g_object_set (pn, "sensitive", bookmarks != NULL, NULL);
|
|
|
|
|
|
|
|
pn = moo_window_get_action (MOO_WINDOW (window), "NextBookmark");
|
|
|
|
item = gtk_action_create_menu_item (pn);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
g_object_set (pn, "sensitive", bookmarks != NULL, NULL);
|
|
|
|
|
|
|
|
if (bookmarks)
|
|
|
|
{
|
|
|
|
item = gtk_separator_menu_item_new ();
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (bookmarks)
|
|
|
|
{
|
|
|
|
item = create_bookmark_item (window, doc, bookmarks->data);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
bookmarks = bookmarks->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show_all (menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
erase_bookmarks_menu (GtkMenuItem *bk_item)
|
|
|
|
{
|
|
|
|
if (g_object_get_data (G_OBJECT (bk_item), "moo-bookmarks-populated"))
|
|
|
|
{
|
|
|
|
GtkWidget *menu = gtk_menu_item_get_submenu (bk_item);
|
|
|
|
|
|
|
|
if (menu)
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (menu),
|
|
|
|
(GtkCallback) gtk_widget_destroy,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (bk_item),
|
|
|
|
"moo-bookmarks-populated",
|
|
|
|
GINT_TO_POINTER (FALSE));
|
|
|
|
g_object_unref (bk_item);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bookmarks_toplevel_hide (GtkWidget *toplevel,
|
|
|
|
GtkMenuItem *bk_item)
|
|
|
|
{
|
|
|
|
g_idle_add ((GSourceFunc) erase_bookmarks_menu, g_object_ref (bk_item));
|
|
|
|
g_signal_handlers_disconnect_by_func (toplevel,
|
|
|
|
(gpointer) bookmarks_toplevel_hide,
|
|
|
|
bk_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bookmarks_item_selected (GtkMenuItem *bk_item,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
if (!g_object_get_data (G_OBJECT (bk_item), "moo-bookmarks-populated"))
|
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
menu = gtk_menu_item_get_submenu (bk_item);
|
|
|
|
g_return_if_fail (menu != NULL);
|
|
|
|
|
|
|
|
populate_bookmarks (window, menu);
|
|
|
|
g_object_set_data (G_OBJECT (bk_item), "moo-bookmarks-populated",
|
|
|
|
GINT_TO_POINTER (TRUE));
|
|
|
|
|
|
|
|
menu = gtk_widget_get_parent (GTK_WIDGET (bk_item));
|
|
|
|
|
|
|
|
if (GTK_IS_MENU (menu))
|
|
|
|
g_signal_connect (GTK_MENU (menu)->toplevel, "hide",
|
|
|
|
G_CALLBACK (bookmarks_toplevel_hide), bk_item);
|
|
|
|
else
|
|
|
|
g_critical ("%s: oops", G_STRLOC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_bookmarks_item (GtkAction *action,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
MooEditWindow *window;
|
|
|
|
GtkWidget *menu;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_ITEM (widget));
|
|
|
|
|
|
|
|
window = _moo_action_get_window (action);
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), menu);
|
|
|
|
g_signal_connect (widget, "select", G_CALLBACK (bookmarks_item_selected), window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkAction *
|
|
|
|
create_bookmarks_menu_action (MooWindow *window,
|
|
|
|
G_GNUC_UNUSED gpointer data)
|
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
|
|
|
|
action = g_object_new (MOO_TYPE_ACTION,
|
|
|
|
"name", "BookmarksMenu",
|
|
|
|
"label", _("Bookmarks"),
|
|
|
|
"no-accel", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (action, "connect-proxy", G_CALLBACK (connect_bookmarks_item), NULL);
|
|
|
|
moo_bind_bool_property (action, "sensitive", window, "has-open-document", FALSE);
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
2006-10-17 22:24:35 -07:00
|
|
|
#endif
|
2005-12-10 23:25:20 -08:00
|
|
|
|
|
|
|
|
2006-04-24 12:27:34 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_next_ph (MooEditWindow *window)
|
2006-04-24 12:27:34 -07:00
|
|
|
{
|
|
|
|
MooEdit *doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
moo_text_view_next_placeholder (MOO_TEXT_VIEW (doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_prev_ph (MooEditWindow *window)
|
2006-04-24 12:27:34 -07:00
|
|
|
{
|
|
|
|
MooEdit *doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
moo_text_view_prev_placeholder (MOO_TEXT_VIEW (doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-05 12:14:02 -07:00
|
|
|
#ifdef ENABLE_PRINTING
|
2006-05-07 21:48:37 -07:00
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_page_setup (MooEditWindow *window)
|
2006-03-25 01:40:54 -08:00
|
|
|
{
|
2006-11-13 23:12:57 -08:00
|
|
|
_moo_edit_page_setup (GTK_WIDGET (window));
|
2006-03-25 01:40:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-25 01:15:19 -07:00
|
|
|
action_print (MooEditWindow *window)
|
2006-03-25 01:40:54 -08:00
|
|
|
{
|
|
|
|
gpointer doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
2006-05-07 11:15:58 -07:00
|
|
|
_moo_edit_print (doc, GTK_WIDGET (window));
|
2006-03-25 01:40:54 -08:00
|
|
|
}
|
2006-11-13 23:12:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_print_preview (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
gpointer doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
_moo_edit_print_preview (doc, GTK_WIDGET (window));
|
|
|
|
}
|
2006-11-18 23:12:56 -08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_print_pdf (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
const char *filename;
|
|
|
|
gpointer doc = moo_edit_window_get_active_doc (window);
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
filename = moo_file_dialogp (GTK_WIDGET (window),
|
|
|
|
MOO_FILE_DIALOG_SAVE,
|
|
|
|
"Export as PDF",
|
|
|
|
moo_edit_setting (MOO_EDIT_PREFS_PDF_LAST_DIR),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
_moo_edit_export_pdf (doc, filename);
|
|
|
|
}
|
2006-03-25 01:40:54 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-06-17 00:38:23 -07:00
|
|
|
static void
|
|
|
|
wrap_text_toggled (MooEditWindow *window,
|
|
|
|
gboolean active)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
GtkWrapMode mode;
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
g_object_get (doc, "wrap-mode", &mode, NULL);
|
|
|
|
|
|
|
|
if ((active && mode != GTK_WRAP_NONE) || (!active && mode == GTK_WRAP_NONE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
{
|
|
|
|
mode = GTK_WRAP_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_WRAP_WORDS)))
|
|
|
|
mode = GTK_WRAP_WORD;
|
|
|
|
else
|
|
|
|
mode = GTK_WRAP_CHAR;
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:39:53 -07:00
|
|
|
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER, "wrap-mode", mode, NULL);
|
2006-06-17 00:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_numbers_toggled (MooEditWindow *window,
|
|
|
|
gboolean active)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
gboolean show;
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
|
|
|
|
g_object_get (doc, "show-line-numbers", &show, NULL);
|
|
|
|
|
|
|
|
if ((active && show) || (!active && !show))
|
|
|
|
return;
|
|
|
|
|
2006-07-27 12:39:53 -07:00
|
|
|
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER,
|
|
|
|
"show-line-numbers", active,
|
2006-06-17 00:38:23 -07:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-14 09:28:41 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Notebook popup menu
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void close_activated (GtkWidget *item,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit = g_object_get_data (G_OBJECT (item), "moo-edit");
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
moo_editor_close_doc (window->priv->editor, edit, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void close_others_activated (GtkWidget *item,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
MooEdit *edit = g_object_get_data (G_OBJECT (item), "moo-edit");
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
list = moo_edit_window_list_docs (window);
|
|
|
|
list = g_slist_remove (list, edit);
|
|
|
|
|
2006-06-29 22:53:11 -07:00
|
|
|
if (list)
|
|
|
|
moo_editor_close_docs (window->priv->editor, list, TRUE);
|
2006-06-14 09:28:41 -07:00
|
|
|
|
|
|
|
g_slist_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Documents
|
|
|
|
*/
|
|
|
|
|
2006-06-14 09:28:41 -07:00
|
|
|
static void
|
|
|
|
notebook_switch_page (G_GNUC_UNUSED MooNotebook *notebook,
|
|
|
|
guint page_num,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
edit_changed (window, get_nth_tab (window, page_num));
|
|
|
|
moo_edit_window_check_actions (window);
|
2006-06-29 22:53:11 -07:00
|
|
|
moo_edit_window_update_doc_list (window);
|
2006-06-14 09:28:41 -07:00
|
|
|
g_object_notify (G_OBJECT (window), "active-doc");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
notebook_populate_popup (MooNotebook *notebook,
|
|
|
|
GtkWidget *child,
|
|
|
|
GtkMenu *menu,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), TRUE);
|
|
|
|
g_return_val_if_fail (window->priv->notebook == notebook, TRUE);
|
|
|
|
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (child), TRUE);
|
|
|
|
|
|
|
|
edit = MOO_EDIT (gtk_bin_get_child (GTK_BIN (child)));
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), TRUE);
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label ("Close");
|
|
|
|
gtk_widget_show (item);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
g_object_set_data (G_OBJECT (item), "moo-edit", edit);
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
G_CALLBACK (close_activated),
|
|
|
|
window);
|
|
|
|
|
|
|
|
if (moo_edit_window_num_docs (window) > 1)
|
|
|
|
{
|
|
|
|
item = gtk_menu_item_new_with_label ("Close All Others");
|
|
|
|
gtk_widget_show (item);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
g_object_set_data (G_OBJECT (item), "moo-edit", edit);
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
G_CALLBACK (close_others_activated),
|
|
|
|
window);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
notebook_button_press (MooNotebook *notebook,
|
|
|
|
GdkEventButton *event,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (event->button != 2 || event->type != GDK_BUTTON_PRESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
n = moo_notebook_get_event_tab (notebook, (GdkEvent*) event);
|
|
|
|
|
|
|
|
if (n < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
moo_editor_close_doc (window->priv->editor,
|
|
|
|
get_nth_tab (window, n),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
static void
|
|
|
|
setup_notebook (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-04 15:50:27 -07:00
|
|
|
GtkWidget *button, *icon, *frame;
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2006-11-03 23:03:25 -08:00
|
|
|
g_signal_connect_after (window->priv->notebook, "moo-switch-page",
|
2005-09-02 23:25:43 -07:00
|
|
|
G_CALLBACK (notebook_switch_page), window);
|
|
|
|
g_signal_connect (window->priv->notebook, "populate-popup",
|
|
|
|
G_CALLBACK (notebook_populate_popup), window);
|
2006-06-14 09:28:41 -07:00
|
|
|
g_signal_connect (window->priv->notebook, "button-press-event",
|
|
|
|
G_CALLBACK (notebook_button_press), window);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-09-04 15:50:27 -07:00
|
|
|
frame = gtk_aspect_frame_new (NULL, 0.5, 0.5, 1.0, FALSE);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
button = gtk_button_new ();
|
|
|
|
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
2006-06-25 01:15:19 -07:00
|
|
|
G_CALLBACK (action_close_tab), window);
|
2005-11-19 19:59:01 -08:00
|
|
|
moo_bind_bool_property (button, "sensitive", window, "has-open-document", FALSE);
|
2005-09-04 15:50:27 -07:00
|
|
|
|
|
|
|
icon = gtk_image_new_from_stock (MOO_STOCK_CLOSE, MOO_ICON_SIZE_REAL_SMALL);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), icon);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), button);
|
|
|
|
gtk_widget_show_all (frame);
|
|
|
|
moo_notebook_set_action_widget (window->priv->notebook, frame, TRUE);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (window->priv->notebook), 0,
|
|
|
|
dest_targets, G_N_ELEMENTS (dest_targets),
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2005-11-28 05:50:17 -08:00
|
|
|
gtk_drag_dest_add_text_targets (GTK_WIDGET (window->priv->notebook));
|
2005-11-28 05:49:21 -08:00
|
|
|
g_signal_connect (window->priv->notebook, "drag-motion",
|
|
|
|
G_CALLBACK (notebook_drag_motion), window);
|
|
|
|
g_signal_connect (window->priv->notebook, "drag-drop",
|
|
|
|
G_CALLBACK (notebook_drag_drop), window);
|
|
|
|
g_signal_connect (window->priv->notebook, "drag-data-received",
|
|
|
|
G_CALLBACK (notebook_drag_data_recv), window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static void
|
|
|
|
edit_changed (MooEditWindow *window,
|
|
|
|
MooEdit *doc)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
if (doc == ACTIVE_DOC (window))
|
|
|
|
{
|
2005-09-16 20:53:25 -07:00
|
|
|
g_object_freeze_notify (G_OBJECT (window));
|
|
|
|
g_object_notify (G_OBJECT (window), "can-reload");
|
|
|
|
g_object_notify (G_OBJECT (window), "has-open-document");
|
|
|
|
g_object_notify (G_OBJECT (window), "can-undo");
|
|
|
|
g_object_notify (G_OBJECT (window), "can-redo");
|
|
|
|
g_object_notify (G_OBJECT (window), "has-selection");
|
2006-04-29 20:54:03 -07:00
|
|
|
g_object_notify (G_OBJECT (window), "has-comments");
|
2005-09-16 20:53:25 -07:00
|
|
|
g_object_notify (G_OBJECT (window), "has-text");
|
|
|
|
g_object_thaw_notify (G_OBJECT (window));
|
|
|
|
|
|
|
|
update_window_title (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
update_statusbar (window);
|
2005-10-13 07:08:18 -07:00
|
|
|
update_lang_menu (window);
|
2006-06-17 00:38:23 -07:00
|
|
|
update_doc_view_actions (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doc)
|
|
|
|
update_tab_label (window, doc);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static void
|
|
|
|
edit_overwrite_changed (MooEditWindow *window,
|
|
|
|
G_GNUC_UNUSED GParamSpec *pspec,
|
|
|
|
MooEdit *doc)
|
|
|
|
{
|
|
|
|
if (doc == ACTIVE_DOC (window))
|
|
|
|
update_statusbar (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-17 00:38:23 -07:00
|
|
|
static void
|
|
|
|
edit_wrap_mode_changed (MooEditWindow *window,
|
|
|
|
G_GNUC_UNUSED GParamSpec *pspec,
|
|
|
|
MooEdit *doc)
|
|
|
|
{
|
|
|
|
gpointer action;
|
|
|
|
GtkWrapMode mode;
|
|
|
|
|
|
|
|
if (doc != ACTIVE_DOC (window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
action = moo_window_get_action (MOO_WINDOW (window), "WrapText");
|
|
|
|
g_return_if_fail (action != NULL);
|
|
|
|
|
|
|
|
g_object_get (doc, "wrap-mode", &mode, NULL);
|
|
|
|
gtk_toggle_action_set_active (action, mode != GTK_WRAP_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
edit_show_line_numbers_changed (MooEditWindow *window,
|
|
|
|
G_GNUC_UNUSED GParamSpec *pspec,
|
|
|
|
MooEdit *doc)
|
|
|
|
{
|
|
|
|
gpointer action;
|
|
|
|
gboolean show;
|
|
|
|
|
|
|
|
if (doc != ACTIVE_DOC (window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
action = moo_window_get_action (MOO_WINDOW (window), "LineNumbers");
|
|
|
|
g_return_if_fail (action != NULL);
|
|
|
|
|
|
|
|
g_object_get (doc, "show-line-numbers", &show, NULL);
|
|
|
|
gtk_toggle_action_set_active (action, show);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_doc_view_actions (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
edit_wrap_mode_changed (window, NULL, doc);
|
|
|
|
edit_show_line_numbers_changed (window, NULL, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static void
|
|
|
|
edit_filename_changed (MooEditWindow *window,
|
|
|
|
G_GNUC_UNUSED const char *filename,
|
|
|
|
MooEdit *doc)
|
2005-09-03 15:48:05 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
edit_changed (window, doc);
|
2006-05-21 16:10:48 -07:00
|
|
|
moo_edit_window_update_doc_list (window);
|
2005-09-03 15:48:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static void
|
|
|
|
proxy_boolean_property (MooEditWindow *window,
|
|
|
|
GParamSpec *prop,
|
|
|
|
MooEdit *doc)
|
2005-09-03 15:48:05 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
if (doc == ACTIVE_DOC (window))
|
|
|
|
g_object_notify (G_OBJECT (window), prop->name);
|
2005-09-03 15:48:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
MooEdit *
|
|
|
|
moo_edit_window_get_active_doc (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
GtkWidget *swin;
|
|
|
|
int page;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
|
2005-09-16 20:53:25 -07:00
|
|
|
if (!window->priv->notebook)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
page = moo_notebook_get_current_page (window->priv->notebook);
|
|
|
|
|
|
|
|
if (page < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
swin = moo_notebook_get_nth_page (window->priv->notebook, page);
|
|
|
|
return MOO_EDIT (gtk_bin_get_child (GTK_BIN (swin)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
void
|
|
|
|
moo_edit_window_set_active_doc (MooEditWindow *window,
|
|
|
|
MooEdit *edit)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
GtkWidget *swin;
|
|
|
|
int page;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
swin = GTK_WIDGET(edit)->parent;
|
|
|
|
page = moo_notebook_page_num (window->priv->notebook, swin);
|
|
|
|
g_return_if_fail (page >= 0);
|
|
|
|
|
|
|
|
moo_notebook_set_current_page (window->priv->notebook, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
GSList *
|
|
|
|
moo_edit_window_list_docs (MooEditWindow *window)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
GSList *list = NULL;
|
|
|
|
int num, i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
|
|
|
|
num = moo_notebook_get_n_pages (window->priv->notebook);
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
list = g_slist_prepend (list, get_nth_tab (window, i));
|
|
|
|
|
|
|
|
return g_slist_reverse (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
guint
|
|
|
|
moo_edit_window_num_docs (MooEditWindow *window)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), 0);
|
2005-09-16 20:53:25 -07:00
|
|
|
|
|
|
|
if (!window->priv->notebook)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return moo_notebook_get_n_pages (window->priv->notebook);
|
2005-09-02 23:25:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-01 00:07:33 -07:00
|
|
|
MooEdit *
|
|
|
|
moo_edit_window_get_nth_doc (MooEditWindow *window,
|
|
|
|
guint n)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
|
|
|
|
if (!window->priv->notebook || n >= (guint) moo_notebook_get_n_pages (window->priv->notebook))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return get_nth_tab (window, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static MooEdit *
|
|
|
|
get_nth_tab (MooEditWindow *window,
|
|
|
|
guint n)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
GtkWidget *swin;
|
|
|
|
|
|
|
|
swin = moo_notebook_get_nth_page (window->priv->notebook, n);
|
|
|
|
|
|
|
|
if (swin)
|
|
|
|
return MOO_EDIT (gtk_bin_get_child (GTK_BIN (swin)));
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
static int
|
|
|
|
get_page_num (MooEditWindow *window,
|
|
|
|
MooEdit *doc)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
GtkWidget *swin;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), -1);
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), -1);
|
|
|
|
|
|
|
|
swin = GTK_WIDGET(doc)->parent;
|
|
|
|
return moo_notebook_page_num (window->priv->notebook, swin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
void
|
|
|
|
_moo_edit_window_insert_doc (MooEditWindow *window,
|
|
|
|
MooEdit *edit,
|
|
|
|
int position)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scrolledwindow;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
label = create_tab_label (window, edit);
|
2005-09-02 23:25:43 -07:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
|
|
|
|
GTK_SHADOW_ETCHED_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET (edit));
|
|
|
|
gtk_widget_show_all (scrolledwindow);
|
|
|
|
|
|
|
|
moo_notebook_insert_page (window->priv->notebook, scrolledwindow, label, position);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (edit, "doc_status_changed",
|
|
|
|
G_CALLBACK (edit_changed), window);
|
2006-04-05 00:54:33 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::overwrite",
|
2006-05-02 19:40:18 -07:00
|
|
|
G_CALLBACK (edit_overwrite_changed), window);
|
2006-06-17 00:38:23 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::wrap-mode",
|
|
|
|
G_CALLBACK (edit_wrap_mode_changed), window);
|
|
|
|
g_signal_connect_swapped (edit, "notify::show-line-numbers",
|
|
|
|
G_CALLBACK (edit_show_line_numbers_changed), window);
|
2005-09-03 15:48:05 -07:00
|
|
|
g_signal_connect_swapped (edit, "filename_changed",
|
2005-10-13 07:08:18 -07:00
|
|
|
G_CALLBACK (edit_filename_changed), window);
|
2005-09-16 20:53:25 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::can-undo",
|
|
|
|
G_CALLBACK (proxy_boolean_property), window);
|
|
|
|
g_signal_connect_swapped (edit, "notify::can-redo",
|
|
|
|
G_CALLBACK (proxy_boolean_property), window);
|
2005-09-09 02:40:10 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::has-selection",
|
2005-09-16 20:53:25 -07:00
|
|
|
G_CALLBACK (proxy_boolean_property), window);
|
2006-04-29 20:54:03 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::has-comments",
|
|
|
|
G_CALLBACK (proxy_boolean_property), window);
|
2005-09-09 02:40:10 -07:00
|
|
|
g_signal_connect_swapped (edit, "notify::has-text",
|
2005-09-16 20:53:25 -07:00
|
|
|
G_CALLBACK (proxy_boolean_property), window);
|
2006-04-15 21:29:08 -07:00
|
|
|
g_signal_connect_swapped (edit, "config-notify::lang",
|
2005-09-02 23:25:43 -07:00
|
|
|
G_CALLBACK (edit_lang_changed), window);
|
|
|
|
g_signal_connect_swapped (edit, "cursor-moved",
|
|
|
|
G_CALLBACK (edit_cursor_moved), window);
|
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
moo_edit_window_update_doc_list (window);
|
2005-09-04 21:24:21 -07:00
|
|
|
g_signal_emit (window, signals[NEW_DOC], 0, edit);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
_moo_doc_attach_plugins (window, edit);
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
moo_edit_window_set_active_doc (window, edit);
|
|
|
|
edit_changed (window, edit);
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (edit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 01:57:05 -07:00
|
|
|
void
|
|
|
|
_moo_edit_window_remove_doc (MooEditWindow *window,
|
|
|
|
MooEdit *doc)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
int page;
|
2006-05-21 16:10:48 -07:00
|
|
|
GtkAction *action;
|
2006-07-08 07:57:01 -07:00
|
|
|
MooEdit *new_doc;
|
|
|
|
gboolean had_focus;
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
|
|
|
|
page = get_page_num (window, doc);
|
|
|
|
g_return_if_fail (page >= 0);
|
|
|
|
|
2006-07-08 07:57:01 -07:00
|
|
|
had_focus = GTK_WIDGET_HAS_FOCUS (doc);
|
|
|
|
|
2005-09-04 21:24:21 -07:00
|
|
|
g_signal_emit (window, signals[CLOSE_DOC], 0, doc);
|
|
|
|
|
2006-06-17 00:38:23 -07:00
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_changed, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_filename_changed, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) proxy_boolean_property, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_cursor_moved, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_lang_changed, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_overwrite_changed, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_wrap_mode_changed, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (doc, (gpointer) edit_show_line_numbers_changed, window);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
_moo_doc_detach_plugins (window, doc);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
action = g_object_get_data (G_OBJECT (doc), "moo-doc-list-action");
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
{
|
2006-08-15 00:12:41 -07:00
|
|
|
moo_action_collection_remove_action (moo_window_get_actions (MOO_WINDOW (window)), action);
|
2006-05-21 16:10:48 -07:00
|
|
|
g_object_set_data (G_OBJECT (doc), "moo-doc-list-action", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
moo_edit_window_update_doc_list (window);
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
moo_notebook_remove_page (window->priv->notebook, page);
|
|
|
|
edit_changed (window, NULL);
|
2005-09-07 04:19:26 -07:00
|
|
|
|
|
|
|
g_signal_emit (window, signals[CLOSE_DOC_AFTER], 0);
|
2005-09-02 23:25:43 -07:00
|
|
|
g_object_notify (G_OBJECT (window), "active-doc");
|
2006-05-26 22:37:32 -07:00
|
|
|
|
2006-07-08 07:57:01 -07:00
|
|
|
new_doc = ACTIVE_DOC (window);
|
|
|
|
|
|
|
|
if (!new_doc)
|
2006-05-26 22:37:32 -07:00
|
|
|
moo_edit_window_check_actions (window);
|
2006-07-08 07:57:01 -07:00
|
|
|
else if (had_focus)
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (new_doc));
|
2005-09-02 23:25:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
typedef struct {
|
|
|
|
int x;
|
|
|
|
int y;
|
2006-08-20 13:41:14 -07:00
|
|
|
gboolean drag_started;
|
2005-11-25 12:49:15 -08:00
|
|
|
} DragInfo;
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean tab_icon_button_press (GtkWidget *evbox,
|
|
|
|
GdkEventButton *event,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static gboolean tab_icon_button_release (GtkWidget *evbox,
|
|
|
|
GdkEventButton *event,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static gboolean tab_icon_motion_notify (GtkWidget *evbox,
|
|
|
|
GdkEventMotion *event,
|
|
|
|
MooEditWindow *window);
|
2006-06-23 03:29:54 -07:00
|
|
|
|
|
|
|
static void tab_icon_drag_begin (GtkWidget *evbox,
|
|
|
|
GdkDragContext *context,
|
|
|
|
MooEditWindow *window);
|
2005-11-25 12:49:15 -08:00
|
|
|
static void tab_icon_drag_data_delete (GtkWidget *evbox,
|
|
|
|
GdkDragContext *context,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void tab_icon_drag_data_get (GtkWidget *evbox,
|
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void tab_icon_drag_end (GtkWidget *evbox,
|
|
|
|
GdkDragContext *context,
|
|
|
|
MooEditWindow *window);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
tab_icon_button_release (GtkWidget *evbox,
|
|
|
|
G_GNUC_UNUSED GdkEventButton *event,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (evbox), "moo-drag-info", NULL);
|
2006-06-23 03:29:54 -07:00
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_button_release, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_motion_notify, window);
|
2005-11-25 12:49:15 -08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-23 00:48:32 -07:00
|
|
|
static void
|
|
|
|
tab_icon_start_drag (GtkWidget *evbox,
|
|
|
|
GdkEvent *event,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GtkTargetList *targets;
|
|
|
|
GdkDragContext *context;
|
|
|
|
MooEdit *edit;
|
|
|
|
|
|
|
|
edit = g_object_get_data (G_OBJECT (evbox), "moo-edit");
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2006-06-23 03:29:54 -07:00
|
|
|
g_signal_connect (evbox, "drag-begin", G_CALLBACK (tab_icon_drag_begin), window);
|
|
|
|
g_signal_connect (evbox, "drag-data-delete", G_CALLBACK (tab_icon_drag_data_delete), window);
|
|
|
|
g_signal_connect (evbox, "drag-data-get", G_CALLBACK (tab_icon_drag_data_get), window);
|
|
|
|
g_signal_connect (evbox, "drag-end", G_CALLBACK (tab_icon_drag_end), window);
|
|
|
|
|
2006-06-23 00:48:32 -07:00
|
|
|
targets = gtk_target_list_new (NULL, 0);
|
|
|
|
|
|
|
|
gtk_target_list_add (targets,
|
|
|
|
gdk_atom_intern ("text/uri-list", FALSE),
|
|
|
|
0, TARGET_URI_LIST);
|
|
|
|
gtk_target_list_add (targets,
|
|
|
|
gdk_atom_intern ("MOO_EDIT_TAB", FALSE),
|
|
|
|
GTK_TARGET_SAME_APP,
|
|
|
|
TARGET_MOO_EDIT_TAB);
|
|
|
|
|
|
|
|
context = gtk_drag_begin (evbox, targets,
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK,
|
|
|
|
1, (GdkEvent*) event);
|
|
|
|
|
|
|
|
gtk_target_list_unref (targets);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
static gboolean
|
|
|
|
tab_icon_motion_notify (GtkWidget *evbox,
|
|
|
|
GdkEventMotion *event,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
DragInfo *info;
|
|
|
|
|
|
|
|
info = g_object_get_data (G_OBJECT (evbox), "moo-drag-info");
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
2006-08-20 13:41:14 -07:00
|
|
|
if (info->drag_started)
|
|
|
|
return TRUE;
|
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
if (gtk_drag_check_threshold (evbox, info->x, info->y, event->x, event->y))
|
|
|
|
{
|
2006-08-20 13:41:14 -07:00
|
|
|
info->drag_started = TRUE;
|
2006-06-23 00:48:32 -07:00
|
|
|
tab_icon_start_drag (evbox, (GdkEvent*) event, window);
|
2005-11-25 12:49:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
static gboolean
|
|
|
|
tab_icon_button_press (GtkWidget *evbox,
|
|
|
|
GdkEventButton *event,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
2005-11-25 12:49:15 -08:00
|
|
|
DragInfo *info;
|
|
|
|
|
|
|
|
if (event->window != evbox->window || event->button != 1 || event->type != GDK_BUTTON_PRESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
info = g_new0 (DragInfo, 1);
|
|
|
|
info->x = event->x;
|
|
|
|
info->y = event->y;
|
|
|
|
g_object_set_data_full (G_OBJECT (evbox), "moo-drag-info", info, g_free);
|
2006-06-23 00:48:32 -07:00
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
g_signal_connect (evbox, "motion-notify-event", G_CALLBACK (tab_icon_motion_notify), window);
|
|
|
|
g_signal_connect (evbox, "button-release-event", G_CALLBACK (tab_icon_button_release), window);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-23 03:29:54 -07:00
|
|
|
static void
|
|
|
|
tab_icon_drag_begin (GtkWidget *evbox,
|
|
|
|
GdkDragContext *context,
|
|
|
|
G_GNUC_UNUSED MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GtkImage *icon;
|
|
|
|
icon = g_object_get_data (G_OBJECT (evbox), "moo-edit-icon");
|
|
|
|
pixbuf = gtk_image_get_pixbuf (icon);
|
|
|
|
gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
static void
|
|
|
|
tab_icon_drag_data_delete (G_GNUC_UNUSED GtkWidget *evbox,
|
|
|
|
G_GNUC_UNUSED GdkDragContext *context,
|
|
|
|
G_GNUC_UNUSED MooEditWindow *window)
|
|
|
|
{
|
|
|
|
g_print ("delete!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
tab_icon_drag_data_get (GtkWidget *evbox,
|
|
|
|
G_GNUC_UNUSED GdkDragContext *context,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
G_GNUC_UNUSED guint time,
|
|
|
|
G_GNUC_UNUSED MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit = g_object_get_data (G_OBJECT (evbox), "moo-edit");
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
if (info == TARGET_MOO_EDIT_TAB)
|
|
|
|
{
|
2006-08-15 01:52:38 -07:00
|
|
|
_moo_selection_data_set_pointer (data,
|
|
|
|
gdk_atom_intern ("MOO_EDIT_TAB", FALSE),
|
|
|
|
edit);
|
2005-11-25 12:49:15 -08:00
|
|
|
}
|
|
|
|
else if (info == TARGET_URI_LIST)
|
|
|
|
{
|
|
|
|
char *uris[] = {NULL, NULL};
|
|
|
|
uris[0] = moo_edit_get_uri (edit);
|
2005-11-26 01:31:54 -08:00
|
|
|
gtk_selection_data_set_uris (data, uris);
|
2005-11-25 12:49:15 -08:00
|
|
|
g_free (uris[0]);
|
|
|
|
}
|
2005-11-26 01:31:54 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_print ("drag-data-get WTF?\n");
|
2006-06-23 00:48:32 -07:00
|
|
|
gtk_selection_data_set_text (data, "", -1);
|
2005-11-26 01:31:54 -08:00
|
|
|
}
|
2005-11-25 12:49:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
tab_icon_drag_end (GtkWidget *evbox,
|
|
|
|
G_GNUC_UNUSED GdkDragContext *context,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
2005-11-26 01:31:54 -08:00
|
|
|
g_object_set_data (G_OBJECT (evbox), "moo-drag-info", NULL);
|
2006-06-23 03:29:54 -07:00
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_drag_begin, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_drag_data_delete, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_drag_data_get, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (evbox, (gpointer) tab_icon_drag_end, window);
|
2005-11-24 22:11:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_tab_label (MooEditWindow *window,
|
|
|
|
MooEdit *edit)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
2005-11-24 22:11:19 -08:00
|
|
|
GtkWidget *hbox, *icon, *label, *evbox;
|
2005-09-03 15:48:05 -07:00
|
|
|
GtkSizeGroup *group;
|
|
|
|
|
|
|
|
group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
|
2005-09-03 09:07:59 -07:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new (FALSE, 3);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
evbox = gtk_event_box_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), evbox, FALSE, FALSE, 0);
|
|
|
|
icon = gtk_image_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (evbox), icon);
|
|
|
|
gtk_widget_show_all (evbox);
|
2005-09-03 09:07:59 -07:00
|
|
|
|
|
|
|
label = gtk_label_new (moo_edit_get_display_basename (edit));
|
2006-05-19 22:09:09 -07:00
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
|
2005-09-03 09:07:59 -07:00
|
|
|
gtk_widget_show (label);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
gtk_size_group_add_widget (group, evbox);
|
2005-09-03 15:48:05 -07:00
|
|
|
gtk_size_group_add_widget (group, label);
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
g_object_set_data (G_OBJECT (hbox), "moo-edit-icon", icon);
|
|
|
|
g_object_set_data (G_OBJECT (hbox), "moo-edit-icon-evbox", evbox);
|
2005-09-03 09:07:59 -07:00
|
|
|
g_object_set_data (G_OBJECT (hbox), "moo-edit-label", label);
|
2005-11-24 22:11:19 -08:00
|
|
|
g_object_set_data (G_OBJECT (evbox), "moo-edit-icon", icon);
|
|
|
|
g_object_set_data (G_OBJECT (evbox), "moo-edit", edit);
|
|
|
|
g_object_set_data (G_OBJECT (icon), "moo-edit", edit);
|
|
|
|
|
2005-11-25 12:49:15 -08:00
|
|
|
g_signal_connect (evbox, "button-press-event",
|
|
|
|
G_CALLBACK (tab_icon_button_press),
|
|
|
|
window);
|
2005-09-03 09:07:59 -07:00
|
|
|
|
|
|
|
return hbox;
|
2005-09-02 23:25:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
static void
|
|
|
|
update_tab_label (MooEditWindow *window,
|
|
|
|
MooEdit *doc)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
2005-11-25 12:49:15 -08:00
|
|
|
GtkWidget *hbox, *icon, *label, *evbox;
|
2005-09-03 09:07:59 -07:00
|
|
|
MooEditStatus status;
|
2005-11-24 22:11:19 -08:00
|
|
|
char *label_text;
|
|
|
|
gboolean modified, deleted;
|
|
|
|
GdkPixbuf *pixbuf;
|
2006-05-02 19:40:18 -07:00
|
|
|
int page;
|
2005-09-03 09:07:59 -07:00
|
|
|
|
2006-05-02 19:40:18 -07:00
|
|
|
page = get_page_num (window, doc);
|
2005-09-03 09:07:59 -07:00
|
|
|
g_return_if_fail (page >= 0);
|
|
|
|
|
|
|
|
hbox = moo_notebook_get_tab_label (window->priv->notebook,
|
|
|
|
GTK_WIDGET(doc)->parent);
|
2005-11-24 22:11:19 -08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (hbox));
|
2005-09-03 15:48:05 -07:00
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
icon = g_object_get_data (G_OBJECT (hbox), "moo-edit-icon");
|
|
|
|
label = g_object_get_data (G_OBJECT (hbox), "moo-edit-label");
|
2005-11-25 12:49:15 -08:00
|
|
|
evbox = g_object_get_data (G_OBJECT (hbox), "moo-edit-icon-evbox");
|
2005-11-24 22:11:19 -08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (icon) && GTK_IS_WIDGET (label));
|
2005-11-25 12:49:15 -08:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (evbox));
|
2005-09-03 09:07:59 -07:00
|
|
|
|
|
|
|
status = moo_edit_get_status (doc);
|
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
deleted = status & (MOO_EDIT_DELETED | MOO_EDIT_MODIFIED_ON_DISK);
|
|
|
|
modified = (status & MOO_EDIT_MODIFIED) && !(status & MOO_EDIT_CLEAN);
|
2005-09-03 09:07:59 -07:00
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
label_text = g_strdup_printf ("%s%s%s",
|
|
|
|
deleted ? "!" : "",
|
|
|
|
modified ? "*" : "",
|
|
|
|
moo_edit_get_display_basename (doc));
|
|
|
|
gtk_label_set_text (GTK_LABEL (label), label_text);
|
|
|
|
|
2005-12-02 09:48:10 -08:00
|
|
|
/* XXX */
|
2006-05-13 14:09:46 -07:00
|
|
|
pixbuf = _moo_get_icon_for_path (moo_edit_get_filename (doc),
|
|
|
|
icon, GTK_ICON_SIZE_MENU);
|
2005-11-24 22:11:19 -08:00
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (icon), pixbuf);
|
2005-09-03 15:48:05 -07:00
|
|
|
|
2005-11-24 22:11:19 -08:00
|
|
|
g_free (label_text);
|
2005-09-02 23:25:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Panes
|
|
|
|
*/
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static const char *PANE_POSITIONS[4] = {
|
|
|
|
"left",
|
|
|
|
"right",
|
|
|
|
"top",
|
|
|
|
"bottom"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_paned (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooBigPaned *paned;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
paned = g_object_new (MOO_TYPE_BIG_PANED,
|
|
|
|
"handle-cursor-type", GDK_FLEUR,
|
|
|
|
"enable-detaching", TRUE,
|
|
|
|
NULL);
|
|
|
|
gtk_widget_show (GTK_WIDGET (paned));
|
|
|
|
gtk_box_pack_start (GTK_BOX (MOO_WINDOW(window)->vbox),
|
|
|
|
GTK_WIDGET (paned), TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
window->paned = paned;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
char *key = g_strdup_printf (MOO_EDIT_PREFS_PREFIX "/window/panes/%s",
|
|
|
|
PANE_POSITIONS[i]);
|
|
|
|
|
2006-11-19 10:35:32 -08:00
|
|
|
moo_prefs_create_key (key, MOO_PREFS_STATE, G_TYPE_INT, -1);
|
2005-10-13 07:08:18 -07:00
|
|
|
size = moo_prefs_get_int (key);
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
moo_paned_set_pane_size (MOO_PANED (paned->paned[i]), size);
|
|
|
|
|
|
|
|
g_free (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect_swapped (paned, "pane-params-changed",
|
|
|
|
G_CALLBACK (pane_params_changed),
|
|
|
|
window);
|
|
|
|
g_signal_connect_swapped (paned, "set-pane-size",
|
|
|
|
G_CALLBACK (pane_size_changed),
|
|
|
|
window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
gboolean
|
|
|
|
moo_edit_window_add_pane (MooEditWindow *window,
|
|
|
|
const char *user_id,
|
|
|
|
GtkWidget *widget,
|
|
|
|
MooPaneLabel *label,
|
|
|
|
MooPanePosition position)
|
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
int result;
|
2006-05-04 20:41:23 -07:00
|
|
|
PaneParams *params;
|
2005-09-08 00:46:48 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
|
|
|
g_return_val_if_fail (user_id != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
|
|
|
|
g_return_val_if_fail (moo_edit_window_get_pane (window, user_id) == NULL, FALSE);
|
|
|
|
|
2005-11-06 22:56:33 -08:00
|
|
|
gtk_object_sink (g_object_ref (widget));
|
2005-09-08 00:46:48 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
params = load_pane_params (user_id);
|
|
|
|
position = (params && params->position >= 0) ?
|
|
|
|
(MooPanePosition) params->position : position;
|
|
|
|
|
2005-09-08 00:46:48 -07:00
|
|
|
result = moo_big_paned_insert_pane (window->paned, widget, label,
|
|
|
|
position, -1);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (result >= 0)
|
|
|
|
{
|
2005-09-08 00:46:48 -07:00
|
|
|
g_hash_table_insert (window->priv->panes,
|
|
|
|
g_strdup (user_id), widget);
|
2005-10-13 07:08:18 -07:00
|
|
|
g_object_set_data_full (G_OBJECT (widget), "moo-edit-window-pane-user-id",
|
|
|
|
g_strdup (user_id), g_free);
|
|
|
|
|
|
|
|
if (params)
|
2006-05-04 20:41:23 -07:00
|
|
|
moo_big_paned_set_pane_params (window->paned, position, result, params->params);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2005-09-08 00:46:48 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
pane_params_free (params);
|
2005-09-08 00:46:48 -07:00
|
|
|
g_object_unref (widget);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
return result >= 0;
|
2005-09-08 00:46:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
moo_edit_window_remove_pane (MooEditWindow *window,
|
|
|
|
const char *user_id)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
|
|
|
g_return_val_if_fail (user_id != NULL, FALSE);
|
|
|
|
|
|
|
|
widget = g_hash_table_lookup (window->priv->panes, user_id);
|
|
|
|
|
|
|
|
if (!widget)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_hash_table_remove (window->priv->panes, user_id);
|
|
|
|
|
|
|
|
result = moo_big_paned_remove_pane (window->paned, widget);
|
|
|
|
g_return_val_if_fail (result, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
moo_edit_window_get_pane (MooEditWindow *window,
|
|
|
|
const char *user_id)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
g_return_val_if_fail (user_id != NULL, NULL);
|
|
|
|
return g_hash_table_lookup (window->priv->panes, user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
#define PANE_PREFS_ROOT MOO_EDIT_PREFS_PREFIX "/panes"
|
|
|
|
#define ELEMENT_PANE "pane"
|
|
|
|
#define PROP_PANE_ID "id"
|
2006-05-04 20:41:23 -07:00
|
|
|
#define PROP_PANE_POSITION "position"
|
2005-10-13 07:08:18 -07:00
|
|
|
#define PROP_PANE_WINDOW_X "x"
|
|
|
|
#define PROP_PANE_WINDOW_Y "y"
|
|
|
|
#define PROP_PANE_WINDOW_WIDTH "width"
|
|
|
|
#define PROP_PANE_WINDOW_HEIGHT "height"
|
|
|
|
#define PROP_PANE_WINDOW_DETACHED "detached"
|
|
|
|
#define PROP_PANE_WINDOW_MAXIMIZED "maximized"
|
|
|
|
#define PROP_PANE_WINDOW_KEEP_ON_TOP "keep-on-top"
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static MooMarkupNode*
|
|
|
|
get_pane_element (const char *pane_id,
|
|
|
|
gboolean create)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
MooMarkupDoc *xml;
|
|
|
|
MooMarkupNode *root, *node;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2006-11-14 23:29:32 -08:00
|
|
|
xml = moo_prefs_get_markup (MOO_PREFS_STATE);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
root = moo_markup_get_element (MOO_MARKUP_NODE (xml), PANE_PREFS_ROOT);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!root)
|
|
|
|
{
|
|
|
|
if (create)
|
|
|
|
{
|
|
|
|
node = moo_markup_create_element (MOO_MARKUP_NODE (xml),
|
|
|
|
PANE_PREFS_ROOT "/" ELEMENT_PANE);
|
|
|
|
moo_markup_set_prop (node, PROP_PANE_ID, pane_id);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node = root->children; node != NULL; node = node->next)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
const char *id;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!MOO_MARKUP_IS_ELEMENT (node))
|
|
|
|
continue;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (strcmp (node->name, ELEMENT_PANE))
|
|
|
|
{
|
|
|
|
g_warning ("%s: invalid element '%s'", G_STRLOC, node->name);
|
|
|
|
continue;
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
id = moo_markup_get_prop (node, PROP_PANE_ID);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!id || !id[0])
|
|
|
|
{
|
|
|
|
g_warning ("%s: id missing", G_STRLOC);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (id, pane_id))
|
|
|
|
continue;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
return node;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (create)
|
|
|
|
{
|
|
|
|
node = moo_markup_create_element (MOO_MARKUP_NODE (xml),
|
|
|
|
PANE_PREFS_ROOT "/" ELEMENT_PANE);
|
|
|
|
moo_markup_set_prop (node, PROP_PANE_ID, pane_id);
|
|
|
|
return node;
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
static PaneParams *
|
2006-06-29 22:53:11 -07:00
|
|
|
load_pane_params (const char *pane_id)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
|
|
|
MooMarkupNode *node;
|
2006-05-04 20:41:23 -07:00
|
|
|
PaneParams *params;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
node = get_pane_element (pane_id, FALSE);
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NULL;
|
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
params = pane_params_new ();
|
|
|
|
params->params = moo_pane_params_new ();
|
|
|
|
|
|
|
|
params->params->window_position.x = moo_markup_get_int_prop (node, PROP_PANE_WINDOW_X, 0);
|
|
|
|
params->params->window_position.y = moo_markup_get_int_prop (node, PROP_PANE_WINDOW_Y, 0);
|
|
|
|
params->params->window_position.width = moo_markup_get_int_prop (node, PROP_PANE_WINDOW_WIDTH, 0);
|
|
|
|
params->params->window_position.height = moo_markup_get_int_prop (node, PROP_PANE_WINDOW_HEIGHT, 0);
|
|
|
|
params->params->detached = moo_markup_get_bool_prop (node, PROP_PANE_WINDOW_DETACHED, FALSE);
|
|
|
|
params->params->maximized = moo_markup_get_bool_prop (node, PROP_PANE_WINDOW_MAXIMIZED, FALSE);
|
|
|
|
params->params->keep_on_top = moo_markup_get_bool_prop (node, PROP_PANE_WINDOW_KEEP_ON_TOP, FALSE);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
params->position = moo_markup_get_int_prop (node, PROP_PANE_POSITION, -1);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
return params;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
set_if_not_zero (MooMarkupNode *node,
|
|
|
|
const char *attr,
|
|
|
|
int val)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
if (val)
|
|
|
|
moo_markup_set_int_prop (node, attr, val);
|
|
|
|
else
|
|
|
|
moo_markup_set_prop (node, attr, NULL);
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
set_if_not_false (MooMarkupNode *node,
|
|
|
|
const char *attr,
|
|
|
|
gboolean val)
|
|
|
|
{
|
|
|
|
if (val)
|
|
|
|
moo_markup_set_bool_prop (node, attr, val);
|
|
|
|
else
|
|
|
|
moo_markup_set_prop (node, attr, NULL);
|
|
|
|
}
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static gboolean
|
2006-05-04 20:41:23 -07:00
|
|
|
save_pane_params (const char *pane_id,
|
|
|
|
PaneParams *params)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
|
|
|
MooMarkupNode *node;
|
|
|
|
|
|
|
|
if (!params)
|
|
|
|
{
|
|
|
|
node = get_pane_element (pane_id, FALSE);
|
|
|
|
if (node)
|
|
|
|
moo_markup_delete_node (node);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = get_pane_element (pane_id, TRUE);
|
|
|
|
g_return_val_if_fail (node != NULL, TRUE);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
set_if_not_zero (node, PROP_PANE_WINDOW_X, params->params->window_position.x);
|
|
|
|
set_if_not_zero (node, PROP_PANE_WINDOW_Y, params->params->window_position.y);
|
|
|
|
set_if_not_zero (node, PROP_PANE_WINDOW_WIDTH, params->params->window_position.width);
|
|
|
|
set_if_not_zero (node, PROP_PANE_WINDOW_HEIGHT, params->params->window_position.height);
|
|
|
|
set_if_not_false (node, PROP_PANE_WINDOW_DETACHED, params->params->detached);
|
|
|
|
set_if_not_false (node, PROP_PANE_WINDOW_MAXIMIZED, params->params->maximized);
|
|
|
|
set_if_not_false (node, PROP_PANE_WINDOW_KEEP_ON_TOP, params->params->keep_on_top);
|
|
|
|
|
|
|
|
if (params->position >= 0)
|
|
|
|
moo_markup_set_prop (node, PROP_PANE_POSITION,
|
2006-08-15 01:21:44 -07:00
|
|
|
_moo_convert_int_to_string (params->position));
|
2006-05-04 20:41:23 -07:00
|
|
|
else
|
|
|
|
moo_markup_set_prop (node, PROP_PANE_POSITION, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
return TRUE;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static gboolean
|
|
|
|
do_save_panes (MooEditWindow *window)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
g_hash_table_foreach_remove (window->priv->panes_to_save,
|
|
|
|
(GHRFunc) save_pane_params, NULL);
|
|
|
|
window->priv->save_params_idle = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2006-05-04 20:41:23 -07:00
|
|
|
static PaneParams *
|
|
|
|
pane_params_new (void)
|
|
|
|
{
|
|
|
|
PaneParams *params = g_new0 (PaneParams, 1);
|
|
|
|
params->position = -1;
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
pane_params_free (PaneParams *params)
|
|
|
|
{
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
moo_pane_params_free (params->params);
|
|
|
|
g_free (params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
pane_params_changed (MooEditWindow *window,
|
|
|
|
MooPanePosition position,
|
|
|
|
guint index)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
const char *id;
|
2006-05-04 20:41:23 -07:00
|
|
|
PaneParams *params;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
widget = moo_big_paned_get_pane (window->paned, position, index);
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
id = g_object_get_data (G_OBJECT (widget), "moo-edit-window-pane-user-id");
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (id)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2006-05-04 20:41:23 -07:00
|
|
|
params = pane_params_new ();
|
|
|
|
params->params = moo_big_paned_get_pane_params (window->paned, position, index);
|
|
|
|
params->position = position;
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
g_hash_table_insert (window->priv->panes_to_save,
|
|
|
|
g_strdup (id), params);
|
2006-05-04 20:41:23 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!window->priv->save_params_idle)
|
|
|
|
window->priv->save_params_idle =
|
|
|
|
g_idle_add ((GSourceFunc) do_save_panes, window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
pane_size_changed (MooEditWindow *window,
|
|
|
|
MooPanePosition pos)
|
|
|
|
{
|
|
|
|
GtkWidget *paned = window->paned->paned[pos];
|
|
|
|
char *key;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_PANED (paned));
|
|
|
|
g_return_if_fail (pos < 4);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
key = g_strdup_printf (MOO_EDIT_PREFS_PREFIX "/window/panes/%s",
|
|
|
|
PANE_POSITIONS[pos]);
|
|
|
|
moo_prefs_set_int (key, moo_paned_get_pane_size (MOO_PANED (paned)));
|
|
|
|
g_free (key);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
2005-07-26 09:13:40 -07:00
|
|
|
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Statusbar
|
|
|
|
*/
|
|
|
|
|
2006-04-05 03:01:27 -07:00
|
|
|
static void
|
2006-06-29 22:53:11 -07:00
|
|
|
clear_statusbar (MooEditWindow *window)
|
2006-04-05 03:01:27 -07:00
|
|
|
{
|
2006-06-29 22:53:11 -07:00
|
|
|
gtk_statusbar_pop (window->priv->statusbar, 0);
|
2006-04-05 03:01:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
set_statusbar_numbers (MooEditWindow *window,
|
|
|
|
int line,
|
|
|
|
int column)
|
2005-07-26 09:13:40 -07:00
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
char *text = g_strdup_printf ("Line: %d Col: %d", line, column);
|
2006-04-05 00:54:33 -07:00
|
|
|
gtk_label_set_text (window->priv->cursor_label, text);
|
2006-06-29 22:53:11 -07:00
|
|
|
clear_statusbar (window);
|
2005-07-26 09:13:40 -07:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
/* XXX */
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
update_statusbar (MooEditWindow *window)
|
2005-07-26 09:13:40 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
int line, column;
|
|
|
|
GtkTextIter iter;
|
2005-09-06 09:21:05 -07:00
|
|
|
GtkTextBuffer *buffer;
|
2006-04-05 00:54:33 -07:00
|
|
|
gboolean ovr;
|
2005-07-26 09:13:40 -07:00
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
|
|
|
if (!edit)
|
|
|
|
{
|
2006-04-05 00:54:33 -07:00
|
|
|
gtk_widget_set_sensitive (window->priv->info, FALSE);
|
2006-06-29 22:53:11 -07:00
|
|
|
clear_statusbar (window);
|
2005-09-02 23:25:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-05 00:54:33 -07:00
|
|
|
gtk_widget_set_sensitive (window->priv->info, TRUE);
|
|
|
|
|
2005-09-06 09:21:05 -07:00
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
2005-07-26 09:13:40 -07:00
|
|
|
line = gtk_text_iter_get_line (&iter) + 1;
|
2006-04-22 06:42:02 -07:00
|
|
|
column = moo_text_iter_get_visual_line_offset (&iter, 8) + 1;
|
2005-07-26 09:13:40 -07:00
|
|
|
|
|
|
|
set_statusbar_numbers (window, line, column);
|
2006-04-05 00:54:33 -07:00
|
|
|
|
|
|
|
ovr = gtk_text_view_get_overwrite (GTK_TEXT_VIEW (edit));
|
|
|
|
gtk_label_set_text (window->priv->insert_label, ovr ? "OVR" : "INS");
|
2005-07-26 09:13:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
/* XXX */
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
edit_cursor_moved (MooEditWindow *window,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
MooEdit *edit)
|
2005-07-26 09:13:40 -07:00
|
|
|
{
|
2005-08-07 19:16:23 -07:00
|
|
|
if (edit == ACTIVE_DOC (window))
|
2005-07-26 09:13:40 -07:00
|
|
|
{
|
|
|
|
int line = gtk_text_iter_get_line (iter) + 1;
|
2006-04-22 06:42:02 -07:00
|
|
|
int column = moo_text_iter_get_visual_line_offset (iter, 8) + 1;
|
2005-07-26 09:13:40 -07:00
|
|
|
set_statusbar_numbers (window, line, column);
|
|
|
|
}
|
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
|
2006-04-05 00:54:33 -07:00
|
|
|
static void
|
|
|
|
create_statusbar (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooGladeXML *xml;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
|
2006-08-08 17:32:47 -07:00
|
|
|
xml = moo_glade_xml_new_from_buf (STATUSBAR_GLADE_XML, -1,
|
|
|
|
"hbox", GETTEXT_PACKAGE, NULL);
|
2006-04-05 00:54:33 -07:00
|
|
|
hbox = moo_glade_xml_get_widget (xml, "hbox");
|
|
|
|
g_return_if_fail (hbox != NULL);
|
|
|
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (MOO_WINDOW (window)->vbox),
|
|
|
|
hbox, FALSE, FALSE, 0);
|
|
|
|
|
2006-04-05 03:01:27 -07:00
|
|
|
window->priv->statusbar = moo_glade_xml_get_widget (xml, "statusbar");
|
2006-04-05 00:54:33 -07:00
|
|
|
|
|
|
|
window->priv->cursor_label = moo_glade_xml_get_widget (xml, "cursor");
|
|
|
|
window->priv->insert_label = moo_glade_xml_get_widget (xml, "insert");
|
|
|
|
window->priv->info = moo_glade_xml_get_widget (xml, "info");
|
2006-05-19 23:57:50 -07:00
|
|
|
|
|
|
|
g_object_unref (xml);
|
2006-04-05 00:54:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-05 03:01:27 -07:00
|
|
|
void
|
|
|
|
moo_edit_window_message (MooEditWindow *window,
|
|
|
|
const char *message)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
2006-06-29 22:53:11 -07:00
|
|
|
|
|
|
|
gtk_statusbar_pop (window->priv->statusbar, 0);
|
|
|
|
|
|
|
|
if (message)
|
|
|
|
gtk_statusbar_push (window->priv->statusbar, 0, message);
|
2006-04-05 03:01:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Language menu
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
cmp_langs (MooLang *lang1,
|
|
|
|
MooLang *lang2)
|
|
|
|
{
|
2006-09-07 00:04:31 -07:00
|
|
|
return g_utf8_collate (_moo_lang_display_name (lang1),
|
|
|
|
_moo_lang_display_name (lang2));
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
lang_item_activated (MooEditWindow *window,
|
|
|
|
const char *lang_name)
|
|
|
|
{
|
|
|
|
MooEdit *doc = ACTIVE_DOC (window);
|
2005-11-03 17:35:22 -08:00
|
|
|
const char *old_val;
|
|
|
|
gboolean do_set = FALSE;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
g_return_if_fail (doc != NULL);
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
old_val = moo_edit_config_get_string (doc->config, "lang");
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
if (old_val)
|
|
|
|
do_set = !lang_name || strcmp (old_val, lang_name);
|
|
|
|
else
|
|
|
|
do_set = !!lang_name;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
if (do_set)
|
2006-07-27 12:39:53 -07:00
|
|
|
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_USER,
|
|
|
|
"lang", lang_name, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-08 21:57:16 -07:00
|
|
|
static GtkAction*
|
2005-10-13 07:08:18 -07:00
|
|
|
create_lang_action (MooEditWindow *window)
|
|
|
|
{
|
2006-05-08 21:57:16 -07:00
|
|
|
GtkAction *action;
|
2005-10-13 07:08:18 -07:00
|
|
|
MooMenuMgr *menu_mgr;
|
2005-10-16 22:23:40 -07:00
|
|
|
MooLangMgr *lang_mgr;
|
2005-10-13 07:08:18 -07:00
|
|
|
GSList *langs, *sections, *l;
|
|
|
|
|
2005-10-16 22:23:40 -07:00
|
|
|
lang_mgr = moo_editor_get_lang_mgr (window->priv->editor);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
/* TODO display names, etc. */
|
2005-10-16 22:23:40 -07:00
|
|
|
sections = moo_lang_mgr_get_sections (lang_mgr);
|
2005-10-13 07:08:18 -07:00
|
|
|
sections = g_slist_sort (sections, (GCompareFunc) strcmp);
|
|
|
|
|
2005-10-16 22:23:40 -07:00
|
|
|
langs = moo_lang_mgr_get_available_langs (lang_mgr);
|
2005-10-13 07:08:18 -07:00
|
|
|
langs = g_slist_sort (langs, (GCompareFunc) cmp_langs);
|
|
|
|
|
2006-05-08 21:57:16 -07:00
|
|
|
action = moo_menu_action_new (LANG_ACTION_ID, "Language");
|
2005-10-13 07:08:18 -07:00
|
|
|
menu_mgr = moo_menu_action_get_mgr (MOO_MENU_ACTION (action));
|
|
|
|
|
2006-05-08 21:57:16 -07:00
|
|
|
moo_menu_mgr_append (menu_mgr, NULL,
|
2006-08-19 10:09:05 -07:00
|
|
|
MOO_LANG_NONE, "None", NULL,
|
2005-10-13 07:08:18 -07:00
|
|
|
MOO_MENU_ITEM_RADIO, NULL, NULL);
|
|
|
|
|
|
|
|
for (l = sections; l != NULL; l = l->next)
|
2006-05-08 21:57:16 -07:00
|
|
|
moo_menu_mgr_append (menu_mgr, NULL,
|
2006-08-19 10:09:05 -07:00
|
|
|
l->data, l->data, NULL,
|
|
|
|
0, NULL, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
for (l = langs; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
MooLang *lang = l->data;
|
2006-08-26 02:46:29 -07:00
|
|
|
if (!_moo_lang_get_hidden (lang))
|
|
|
|
moo_menu_mgr_append (menu_mgr, _moo_lang_get_section (lang),
|
|
|
|
_moo_lang_id (lang),
|
|
|
|
_moo_lang_display_name (lang),
|
|
|
|
NULL, MOO_MENU_ITEM_RADIO,
|
|
|
|
g_strdup (_moo_lang_id (lang)),
|
|
|
|
g_free);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect_swapped (menu_mgr, "radio-set-active",
|
|
|
|
G_CALLBACK (lang_item_activated), window);
|
|
|
|
|
2006-08-26 02:46:29 -07:00
|
|
|
g_slist_foreach (langs, (GFunc) g_object_unref, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
g_slist_free (langs);
|
|
|
|
g_slist_foreach (sections, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (sections);
|
|
|
|
|
|
|
|
moo_bind_bool_property (action, "sensitive", window, "has-open-document", FALSE);
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_lang_menu (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
2006-05-08 21:57:16 -07:00
|
|
|
GtkAction *action;
|
2005-11-16 23:04:35 -08:00
|
|
|
MooLang *lang;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
doc = ACTIVE_DOC (window);
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2005-11-16 23:04:35 -08:00
|
|
|
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
2006-05-08 21:57:16 -07:00
|
|
|
action = moo_window_get_action (MOO_WINDOW (window), LANG_ACTION_ID);
|
2005-10-13 07:08:18 -07:00
|
|
|
g_return_if_fail (action != NULL);
|
|
|
|
|
|
|
|
moo_menu_mgr_set_active (moo_menu_action_get_mgr (MOO_MENU_ACTION (action)),
|
2006-08-26 02:46:29 -07:00
|
|
|
_moo_lang_id (lang), TRUE);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
edit_lang_changed (MooEditWindow *window,
|
2006-04-15 21:29:08 -07:00
|
|
|
G_GNUC_UNUSED guint var_id,
|
2005-10-13 07:08:18 -07:00
|
|
|
G_GNUC_UNUSED GParamSpec *pspec,
|
|
|
|
MooEdit *doc)
|
|
|
|
{
|
|
|
|
if (doc == ACTIVE_DOC (window))
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
update_lang_menu (window);
|
2006-04-16 15:02:19 -07:00
|
|
|
moo_edit_window_check_actions (window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Action properties checks
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2006-08-15 22:18:16 -07:00
|
|
|
window_check_one_action (const char *action_id,
|
|
|
|
ActionCheck *set,
|
|
|
|
MooEditWindow *window,
|
|
|
|
MooEdit *doc)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
MooActionCheckFunc func;
|
2006-05-08 21:57:16 -07:00
|
|
|
GtkAction *action;
|
2006-08-15 22:18:16 -07:00
|
|
|
gboolean visible = TRUE, sensitive = TRUE;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-05-08 21:57:16 -07:00
|
|
|
action = moo_window_get_action (MOO_WINDOW (window), action_id);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
|
|
|
if (!action)
|
|
|
|
return;
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if ((func = set->checks[MOO_ACTION_CHECK_ACTIVE].func))
|
|
|
|
{
|
|
|
|
if (!func (action, window, doc,
|
|
|
|
set->checks[MOO_ACTION_CHECK_ACTIVE].data))
|
|
|
|
{
|
|
|
|
visible = FALSE;
|
|
|
|
sensitive = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (visible && (func = set->checks[MOO_ACTION_CHECK_VISIBLE].func))
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
gpointer data = set->checks[MOO_ACTION_CHECK_VISIBLE].data;
|
|
|
|
visible = func (action, window, doc, data);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (sensitive && (func = set->checks[MOO_ACTION_CHECK_SENSITIVE].func))
|
|
|
|
{
|
|
|
|
gpointer data = set->checks[MOO_ACTION_CHECK_SENSITIVE].data;
|
|
|
|
sensitive = func (action, window, doc, data);
|
|
|
|
}
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
g_object_set (action, "visible", visible, "sensitive", sensitive, NULL);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-08-15 22:18:16 -07:00
|
|
|
check_action_hash_cb (const char *action_id,
|
|
|
|
ActionCheck *check,
|
|
|
|
gpointer user_data)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
struct {
|
|
|
|
MooEdit *doc;
|
|
|
|
MooEditWindow *window;
|
|
|
|
} *data = user_data;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
window_check_one_action (action_id, check, data->window, data->doc);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
static void
|
|
|
|
moo_edit_window_check_actions (MooEditWindow *window)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
struct {
|
|
|
|
MooEdit *doc;
|
|
|
|
MooEditWindow *window;
|
|
|
|
} data;
|
|
|
|
|
|
|
|
data.window = window;
|
|
|
|
data.doc = ACTIVE_DOC (window);
|
|
|
|
|
|
|
|
g_hash_table_foreach (action_checks,
|
|
|
|
(GHFunc) check_action_hash_cb,
|
|
|
|
&data);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
|
2006-04-16 15:02:19 -07:00
|
|
|
void
|
2006-08-15 22:18:16 -07:00
|
|
|
moo_edit_window_set_action_check (const char *action_id,
|
|
|
|
MooActionCheckType type,
|
|
|
|
MooActionCheckFunc func,
|
2006-04-16 15:02:19 -07:00
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
ActionCheck *check;
|
2006-08-15 22:18:16 -07:00
|
|
|
GSList *l;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
|
|
|
g_return_if_fail (action_id != NULL);
|
2006-08-15 22:18:16 -07:00
|
|
|
g_return_if_fail (type < N_ACTION_CHECKS);
|
2006-04-16 15:02:19 -07:00
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
action_checks_init ();
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
check = g_hash_table_lookup (action_checks, action_id);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (!check)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
check = g_new0 (ActionCheck, 1);
|
|
|
|
g_hash_table_insert (action_checks, g_strdup (action_id), check);
|
|
|
|
}
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (check->checks[type].func)
|
|
|
|
{
|
|
|
|
check->checks[type].func = NULL;
|
|
|
|
|
|
|
|
if (check->checks[type].notify)
|
|
|
|
check->checks[type].notify (check->checks[type].data);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
check->checks[type].func = func;
|
|
|
|
check->checks[type].data = data;
|
|
|
|
check->checks[type].notify = notify;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
for (l = windows; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
MooEditWindow *window = l->data;
|
|
|
|
MooEdit *doc = ACTIVE_DOC (window);
|
|
|
|
window_check_one_action (action_id, check, window, doc);
|
|
|
|
}
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-05 14:17:32 -07:00
|
|
|
static void
|
2006-08-15 22:18:16 -07:00
|
|
|
moo_edit_window_remove_action_check (const char *action_id,
|
|
|
|
MooActionCheckType type)
|
2006-05-05 14:17:32 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
ActionCheck *check;
|
|
|
|
gboolean remove = TRUE;
|
|
|
|
guint i;
|
2006-05-05 14:17:32 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
g_return_if_fail (action_id != NULL);
|
|
|
|
g_return_if_fail (type <= N_ACTION_CHECKS);
|
|
|
|
|
|
|
|
if (!action_checks)
|
|
|
|
return;
|
|
|
|
|
|
|
|
check = g_hash_table_lookup (action_checks, action_id);
|
|
|
|
|
|
|
|
if (!check)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type < N_ACTION_CHECKS)
|
2006-05-26 22:37:32 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
for (i = 0; i < N_ACTION_CHECKS; ++i)
|
|
|
|
{
|
|
|
|
if (check->checks[i].func && i != type)
|
|
|
|
{
|
|
|
|
remove = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-05-05 14:17:32 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (!remove && check->checks[type].func && check->checks[type].notify)
|
|
|
|
{
|
|
|
|
check->checks[type].func = NULL;
|
|
|
|
check->checks[type].notify (check->checks[type].data);
|
|
|
|
}
|
2006-05-26 22:37:32 -07:00
|
|
|
}
|
2006-05-05 14:17:32 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (remove)
|
|
|
|
{
|
|
|
|
g_hash_table_remove (action_checks, action_id);
|
|
|
|
|
|
|
|
for (i = 0; i < N_ACTION_CHECKS; ++i)
|
|
|
|
if (check->checks[i].func && check->checks[i].notify)
|
|
|
|
check->checks[i].notify (check->checks[i].data);
|
|
|
|
|
|
|
|
g_free (check);
|
|
|
|
}
|
2006-05-05 14:17:32 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_action_langs (G_GNUC_UNUSED GtkAction *action,
|
|
|
|
G_GNUC_UNUSED MooEditWindow *window,
|
|
|
|
MooEdit *doc,
|
|
|
|
gpointer langs_list)
|
2006-05-05 14:17:32 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
gboolean value = FALSE;
|
2006-05-05 14:17:32 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (doc)
|
2006-05-05 14:17:32 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
2006-08-26 02:46:29 -07:00
|
|
|
value = NULL != g_slist_find_custom (langs_list, _moo_lang_id (lang),
|
2006-08-15 22:18:16 -07:00
|
|
|
(GCompareFunc) strcmp);
|
2006-05-05 14:17:32 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
return value;
|
2006-05-05 14:17:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
string_list_free (gpointer list)
|
|
|
|
{
|
|
|
|
g_slist_foreach (list, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
GSList *
|
|
|
|
_moo_edit_parse_langs (const char *string)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
char **pieces, **p;
|
|
|
|
GSList *list = NULL;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (!string)
|
|
|
|
return NULL;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
pieces = g_strsplit_set (string, " \t\r\n;,", 0);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (!pieces)
|
|
|
|
return NULL;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
for (p = pieces; *p != NULL; ++p)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
g_strstrip (*p);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
if (**p)
|
2006-08-26 02:46:29 -07:00
|
|
|
list = g_slist_prepend (list, _moo_lang_id_from_name (*p));
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
g_strfreev (pieces);
|
|
|
|
return g_slist_reverse (list);
|
|
|
|
}
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
void
|
|
|
|
moo_edit_window_set_action_langs (const char *action_id,
|
|
|
|
MooActionCheckType type,
|
|
|
|
const char *langs)
|
2006-04-16 15:02:19 -07:00
|
|
|
{
|
2006-08-15 22:18:16 -07:00
|
|
|
GSList *langs_list;
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
g_return_if_fail (action_id != NULL);
|
|
|
|
g_return_if_fail (type < N_ACTION_CHECKS);
|
2006-04-16 15:02:19 -07:00
|
|
|
|
2006-08-15 22:18:16 -07:00
|
|
|
langs_list = _moo_edit_parse_langs (langs);
|
|
|
|
|
|
|
|
if (langs_list)
|
|
|
|
moo_edit_window_set_action_check (action_id, type,
|
|
|
|
check_action_langs,
|
|
|
|
langs_list,
|
|
|
|
string_list_free);
|
|
|
|
else
|
|
|
|
moo_edit_window_remove_action_check (action_id, type);
|
2006-04-16 15:02:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
action_checks_init (void)
|
|
|
|
{
|
|
|
|
if (!action_checks)
|
|
|
|
action_checks =
|
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2005-11-17 19:06:47 -08:00
|
|
|
|
|
|
|
|
2005-11-18 05:02:42 -08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Stop button
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
gpointer job;
|
|
|
|
MooAbortJobFunc abort;
|
|
|
|
} Job;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_died (MooEditWindow *window,
|
|
|
|
gpointer client)
|
|
|
|
{
|
|
|
|
window->priv->stop_clients = g_slist_remove (window->priv->stop_clients, client);
|
|
|
|
moo_edit_window_job_finished (window, client);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
abort_client_job (gpointer client)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
g_signal_emit_by_name (client, "abort", &ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_job_started (gpointer client,
|
|
|
|
const char *job_name,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
moo_edit_window_job_started (window, job_name, abort_client_job, client);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
client_job_finished (gpointer client,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
moo_edit_window_job_finished (window, client);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_window_add_stop_client (MooEditWindow *window,
|
|
|
|
gpointer client)
|
|
|
|
{
|
|
|
|
GType type, return_type;
|
|
|
|
guint signal_abort, signal_started, signal_finished;
|
|
|
|
GSignalQuery query;
|
|
|
|
gboolean had_clients;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (G_IS_OBJECT (client));
|
|
|
|
|
|
|
|
g_return_if_fail (!g_slist_find (window->priv->stop_clients, client));
|
|
|
|
|
|
|
|
type = G_OBJECT_TYPE (client);
|
|
|
|
signal_abort = g_signal_lookup ("abort", type);
|
|
|
|
signal_started = g_signal_lookup ("job-started", type);
|
|
|
|
signal_finished = g_signal_lookup ("job-finished", type);
|
|
|
|
g_return_if_fail (signal_abort && signal_started && signal_finished);
|
|
|
|
|
|
|
|
#define REAL_TYPE(t__) ((t__) & ~(G_SIGNAL_TYPE_STATIC_SCOPE))
|
|
|
|
g_signal_query (signal_abort, &query);
|
|
|
|
return_type = REAL_TYPE (query.return_type);
|
|
|
|
g_return_if_fail (return_type == G_TYPE_NONE || return_type == G_TYPE_BOOLEAN);
|
|
|
|
g_return_if_fail (query.n_params == 0);
|
|
|
|
|
|
|
|
g_signal_query (signal_started, &query);
|
|
|
|
g_return_if_fail (REAL_TYPE (query.return_type) == G_TYPE_NONE);
|
|
|
|
g_return_if_fail (query.n_params == 1);
|
|
|
|
g_return_if_fail (REAL_TYPE (query.param_types[0]) == G_TYPE_STRING);
|
|
|
|
|
|
|
|
g_signal_query (signal_finished, &query);
|
|
|
|
g_return_if_fail (REAL_TYPE (query.return_type) == G_TYPE_NONE);
|
|
|
|
g_return_if_fail (query.n_params == 0);
|
|
|
|
#undef REAL_TYPE
|
|
|
|
|
|
|
|
had_clients = window->priv->stop_clients != NULL;
|
|
|
|
window->priv->stop_clients = g_slist_prepend (window->priv->stop_clients, client);
|
|
|
|
g_object_weak_ref (client, (GWeakNotify) client_died, window);
|
|
|
|
g_signal_connect (client, "job-started", G_CALLBACK (client_job_started), window);
|
|
|
|
g_signal_connect (client, "job-finished", G_CALLBACK (client_job_finished), window);
|
|
|
|
|
|
|
|
if (!had_clients)
|
|
|
|
g_object_notify (G_OBJECT (window), "has-stop-clients");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_window_remove_stop_client (MooEditWindow *window,
|
|
|
|
gpointer client)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (g_slist_find (window->priv->stop_clients, client));
|
|
|
|
|
|
|
|
window->priv->stop_clients = g_slist_remove (window->priv->stop_clients, client);
|
|
|
|
|
|
|
|
if (G_IS_OBJECT (client))
|
|
|
|
{
|
|
|
|
g_object_weak_unref (client, (GWeakNotify) client_died, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (client, (gpointer)client_job_started, window);
|
|
|
|
g_signal_handlers_disconnect_by_func (client, (gpointer)client_job_finished, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window->priv->stop_clients)
|
|
|
|
g_object_notify (G_OBJECT (window), "has-stop-clients");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_window_abort_jobs (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GSList *l, *jobs;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
|
|
|
jobs = g_slist_copy (window->priv->jobs);
|
|
|
|
|
|
|
|
for (l = jobs; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
Job *j = l->data;
|
|
|
|
j->abort (j->job);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (jobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_window_job_started (MooEditWindow *window,
|
|
|
|
G_GNUC_UNUSED const char *name,
|
|
|
|
MooAbortJobFunc func,
|
|
|
|
gpointer job)
|
|
|
|
{
|
|
|
|
Job *j;
|
|
|
|
gboolean had_jobs;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
g_return_if_fail (job != NULL);
|
|
|
|
|
|
|
|
j = g_new0 (Job, 1);
|
|
|
|
j->abort = func;
|
|
|
|
j->job = job;
|
|
|
|
|
|
|
|
had_jobs = window->priv->jobs != NULL;
|
|
|
|
window->priv->jobs = g_slist_prepend (window->priv->jobs, j);
|
|
|
|
|
|
|
|
if (!had_jobs)
|
|
|
|
g_object_notify (G_OBJECT (window), "has-jobs-running");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_window_job_finished (MooEditWindow *window,
|
|
|
|
gpointer job)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
Job *j = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_return_if_fail (job != NULL);
|
|
|
|
|
|
|
|
for (l = window->priv->jobs; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
j = l->data;
|
|
|
|
|
|
|
|
if (j->job == job)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
j = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j)
|
|
|
|
{
|
|
|
|
window->priv->jobs = g_slist_remove (window->priv->jobs, j);
|
|
|
|
|
|
|
|
if (!window->priv->jobs)
|
|
|
|
g_object_notify (G_OBJECT (window), "has-jobs-running");
|
|
|
|
|
|
|
|
g_free (j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-16 20:05:51 -07:00
|
|
|
GtkWidget *
|
|
|
|
moo_edit_window_get_output (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooPaneLabel *label;
|
|
|
|
GtkWidget *cmd_view;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
|
|
|
|
scrolled_window = moo_edit_window_get_pane (window, "moo-edit-window-output");
|
|
|
|
|
|
|
|
if (!scrolled_window)
|
|
|
|
{
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
|
|
|
|
|
|
cmd_view = moo_cmd_view_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), cmd_view);
|
|
|
|
gtk_widget_show_all (scrolled_window);
|
|
|
|
g_object_set_data (G_OBJECT (scrolled_window), "moo-output", cmd_view);
|
|
|
|
|
|
|
|
label = moo_pane_label_new (MOO_STOCK_TERMINAL, NULL, NULL, "Output", "Output");
|
|
|
|
|
|
|
|
if (!moo_edit_window_add_pane (window, "moo-edit-window-output",
|
|
|
|
scrolled_window, label, MOO_PANE_POS_BOTTOM))
|
|
|
|
{
|
|
|
|
g_critical ("%s: oops", G_STRLOC);
|
|
|
|
moo_pane_label_free (label);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
moo_edit_window_add_stop_client (window, cmd_view);
|
|
|
|
|
|
|
|
moo_pane_label_free (label);
|
|
|
|
return cmd_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_object_get_data (G_OBJECT (scrolled_window), "moo-output");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
moo_edit_window_get_output_pane (MooEditWindow *window)
|
|
|
|
{
|
2006-05-25 23:44:27 -07:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
2006-04-16 20:05:51 -07:00
|
|
|
return moo_edit_window_get_pane (window, "moo-edit-window-output");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-25 23:44:27 -07:00
|
|
|
void
|
|
|
|
moo_edit_window_present_output (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
moo_edit_window_get_output (window);
|
|
|
|
moo_big_paned_present_pane (window->paned,
|
|
|
|
moo_edit_window_get_output_pane (window));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-21 16:10:48 -07:00
|
|
|
/************************************************************************/
|
|
|
|
/* Doc list
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
doc_list_action_toggled (gpointer action,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
|
|
|
|
if (window->priv->doc_list_update_idle ||
|
|
|
|
!gtk_toggle_action_get_active (action))
|
|
|
|
return;
|
|
|
|
|
|
|
|
doc = g_object_get_data (action, "moo-edit");
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
|
|
|
if (doc != ACTIVE_DOC (window))
|
|
|
|
moo_edit_window_set_active_doc (window, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_doc_list_actions (gpointer a1,
|
|
|
|
gpointer a2)
|
|
|
|
{
|
|
|
|
MooEdit *d1, *d2;
|
|
|
|
d1 = g_object_get_data (a1, "moo-edit");
|
|
|
|
d2 = g_object_get_data (a2, "moo-edit");
|
|
|
|
g_return_val_if_fail (d1 && d2, -1);
|
|
|
|
return strcmp (moo_edit_get_display_basename (d1),
|
|
|
|
moo_edit_get_display_basename (d2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
do_update_doc_list (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooUIXML *xml;
|
|
|
|
GSList *actions = NULL, *docs;
|
|
|
|
GSList *group = NULL;
|
|
|
|
MooUINode *ph;
|
|
|
|
gpointer active_doc;
|
|
|
|
|
|
|
|
active_doc = ACTIVE_DOC (window);
|
|
|
|
|
|
|
|
xml = moo_window_get_ui_xml (MOO_WINDOW (window));
|
|
|
|
g_return_val_if_fail (xml != NULL, FALSE);
|
|
|
|
|
|
|
|
if (xml != window->priv->xml)
|
|
|
|
{
|
|
|
|
if (window->priv->xml)
|
|
|
|
{
|
|
|
|
if (window->priv->doc_list_merge_id)
|
|
|
|
moo_ui_xml_remove_ui (window->priv->xml,
|
|
|
|
window->priv->doc_list_merge_id);
|
|
|
|
g_object_unref (window->priv->xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->priv->xml = g_object_ref (xml);
|
|
|
|
}
|
|
|
|
else if (window->priv->doc_list_merge_id)
|
|
|
|
{
|
|
|
|
moo_ui_xml_remove_ui (xml, window->priv->doc_list_merge_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->priv->doc_list_merge_id = 0;
|
|
|
|
|
|
|
|
ph = moo_ui_xml_find_placeholder (xml, "DocList");
|
|
|
|
g_return_val_if_fail (ph != NULL, FALSE);
|
|
|
|
|
|
|
|
docs = moo_edit_window_list_docs (window);
|
|
|
|
|
|
|
|
if (!docs)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
while (docs)
|
|
|
|
{
|
|
|
|
GtkRadioAction *action;
|
|
|
|
gpointer doc = docs->data;
|
|
|
|
|
|
|
|
action = g_object_get_data (doc, "moo-doc-list-action");
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
g_object_set (action,
|
|
|
|
"label", moo_edit_get_display_basename (doc),
|
|
|
|
"tooltip", moo_edit_get_display_filename (doc),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-04 02:54:12 -08:00
|
|
|
GtkActionGroup *action_group;
|
2006-05-21 16:10:48 -07:00
|
|
|
char *name = g_strdup_printf ("MooEdit-%p", doc);
|
2006-08-15 00:12:41 -07:00
|
|
|
action = g_object_new (MOO_TYPE_RADIO_ACTION ,
|
|
|
|
"name", name,
|
|
|
|
"label", moo_edit_get_display_basename (doc),
|
|
|
|
"tooltip", moo_edit_get_display_filename (doc),
|
|
|
|
NULL);
|
2006-05-21 16:10:48 -07:00
|
|
|
g_object_set_data_full (doc, "moo-doc-list-action", action, g_object_unref);
|
|
|
|
g_object_set_data (G_OBJECT (action), "moo-edit", doc);
|
2006-08-15 00:12:41 -07:00
|
|
|
_moo_action_set_no_accel (action, TRUE);
|
2006-05-21 16:10:48 -07:00
|
|
|
g_signal_connect (action, "toggled", G_CALLBACK (doc_list_action_toggled), window);
|
2006-12-04 02:54:12 -08:00
|
|
|
action_group = moo_action_collection_get_group (moo_window_get_actions (MOO_WINDOW (window)), NULL);
|
|
|
|
gtk_action_group_add_action (action_group, GTK_ACTION (action));
|
2006-05-21 16:10:48 -07:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_radio_action_set_group (action, group);
|
|
|
|
group = gtk_radio_action_get_group (action);
|
|
|
|
actions = g_slist_prepend (actions, action);
|
|
|
|
|
|
|
|
docs = g_slist_delete_link (docs, docs);
|
|
|
|
}
|
|
|
|
|
|
|
|
window->priv->doc_list_merge_id = moo_ui_xml_new_merge_id (xml);
|
|
|
|
actions = g_slist_sort (actions, (GCompareFunc) compare_doc_list_actions);
|
|
|
|
|
|
|
|
while (actions)
|
|
|
|
{
|
|
|
|
gpointer action = actions->data;
|
|
|
|
gpointer doc = g_object_get_data (G_OBJECT (action), "moo-edit");
|
|
|
|
char *markup = g_markup_printf_escaped ("<item action=\"%s\"/>",
|
|
|
|
gtk_action_get_name (action));
|
|
|
|
|
|
|
|
moo_ui_xml_insert (xml, window->priv->doc_list_merge_id, ph, -1, markup);
|
|
|
|
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
|
|
|
|
doc == active_doc);
|
|
|
|
|
|
|
|
g_free (markup);
|
|
|
|
actions = g_slist_delete_link (actions, actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
window->priv->doc_list_update_idle = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_window_update_doc_list (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
if (!window->priv->doc_list_update_idle)
|
|
|
|
window->priv->doc_list_update_idle =
|
|
|
|
g_idle_add ((GSourceFunc) do_update_doc_list,
|
|
|
|
window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
/************************************************************************/
|
|
|
|
/* Drag into the window
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
notebook_drag_motion (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
2005-11-30 07:02:07 -08:00
|
|
|
G_GNUC_UNUSED int x,
|
|
|
|
G_GNUC_UNUSED int y,
|
2005-11-28 05:49:21 -08:00
|
|
|
guint time,
|
2005-11-30 07:02:07 -08:00
|
|
|
G_GNUC_UNUSED MooEditWindow *window)
|
2005-11-28 05:49:21 -08:00
|
|
|
{
|
|
|
|
GdkAtom target;
|
|
|
|
|
|
|
|
target = gtk_drag_dest_find_target (widget, context, NULL);
|
|
|
|
|
|
|
|
if (target == GDK_NONE)
|
2006-06-23 00:48:32 -07:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (target == moo_edit_tab_atom)
|
2005-11-28 05:49:21 -08:00
|
|
|
gtk_drag_get_data (widget, context, moo_edit_tab_atom, time);
|
2005-11-28 05:50:17 -08:00
|
|
|
else
|
|
|
|
gdk_drag_status (context, context->suggested_action, time);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
notebook_drag_drop (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
2005-11-30 07:02:07 -08:00
|
|
|
G_GNUC_UNUSED int x,
|
|
|
|
G_GNUC_UNUSED int y,
|
2005-11-28 05:49:21 -08:00
|
|
|
guint time,
|
2005-11-30 07:02:07 -08:00
|
|
|
G_GNUC_UNUSED MooEditWindow *window)
|
2005-11-28 05:49:21 -08:00
|
|
|
{
|
|
|
|
GdkAtom target;
|
|
|
|
|
|
|
|
target = gtk_drag_dest_find_target (widget, context, NULL);
|
|
|
|
|
|
|
|
if (target == GDK_NONE)
|
|
|
|
{
|
|
|
|
gtk_drag_finish (context, FALSE, FALSE, time);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (widget), "moo-edit-window-drop",
|
|
|
|
GINT_TO_POINTER (TRUE));
|
|
|
|
gtk_drag_get_data (widget, context, target, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
notebook_drag_data_recv (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
2005-11-30 07:02:07 -08:00
|
|
|
G_GNUC_UNUSED int x,
|
|
|
|
G_GNUC_UNUSED int y,
|
2005-11-28 05:49:21 -08:00
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
2006-06-23 00:48:32 -07:00
|
|
|
gboolean finished = FALSE;
|
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
if (g_object_get_data (G_OBJECT (widget), "moo-edit-window-drop"))
|
|
|
|
{
|
2005-11-28 05:50:17 -08:00
|
|
|
char **uris;
|
|
|
|
|
2005-11-28 05:49:21 -08:00
|
|
|
g_object_set_data (G_OBJECT (widget), "moo-edit-window-drop", NULL);
|
|
|
|
|
|
|
|
if (data->target == moo_edit_tab_atom)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
2006-08-15 01:52:38 -07:00
|
|
|
MooEdit *doc = _moo_selection_data_get_pointer (data, moo_edit_tab_atom);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (doc));
|
|
|
|
|
|
|
|
if (toplevel == GTK_WIDGET (window))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
g_print ("%s: implement me\n", G_STRLOC);
|
|
|
|
goto out;
|
|
|
|
}
|
2005-11-28 05:50:17 -08:00
|
|
|
else if ((uris = gtk_selection_data_get_uris (data)))
|
2005-11-28 05:49:21 -08:00
|
|
|
{
|
|
|
|
char **u;
|
|
|
|
|
|
|
|
if (!uris)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (u = uris; *u; ++u)
|
|
|
|
moo_editor_open_uri (window->priv->editor, window,
|
|
|
|
NULL, *u, NULL);
|
|
|
|
|
|
|
|
g_strfreev (uris);
|
|
|
|
gtk_drag_finish (context, TRUE, FALSE, time);
|
2006-06-23 00:48:32 -07:00
|
|
|
finished = TRUE;
|
2005-11-28 05:49:21 -08:00
|
|
|
}
|
2005-11-28 05:50:17 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
GtkTextBuffer *buf;
|
2006-02-18 18:54:44 -08:00
|
|
|
char *text = (char *) gtk_selection_data_get_text (data);
|
2005-11-28 05:50:17 -08:00
|
|
|
|
|
|
|
if (!text)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
doc = moo_editor_new_doc (window->priv->editor, window);
|
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
{
|
|
|
|
g_free (text);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (doc));
|
|
|
|
gtk_text_buffer_set_text (buf, text, -1);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
gtk_drag_finish (context, TRUE,
|
|
|
|
context->suggested_action == GDK_ACTION_MOVE,
|
|
|
|
time);
|
2006-06-23 00:48:32 -07:00
|
|
|
finished = TRUE;
|
2005-11-28 05:50:17 -08:00
|
|
|
}
|
2005-11-28 05:49:21 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (info == TARGET_MOO_EDIT_TAB)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
2006-08-15 01:52:38 -07:00
|
|
|
MooEdit *doc = _moo_selection_data_get_pointer (data, moo_edit_tab_atom);
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
if (!doc)
|
2006-06-23 00:48:32 -07:00
|
|
|
{
|
|
|
|
g_critical ("%s: oops", G_STRLOC);
|
2006-10-20 00:02:13 -07:00
|
|
|
gdk_drag_status (context, 0, time);
|
|
|
|
return;
|
2006-06-23 00:48:32 -07:00
|
|
|
}
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (doc));
|
|
|
|
|
|
|
|
if (toplevel == GTK_WIDGET (window))
|
2006-10-20 00:02:13 -07:00
|
|
|
{
|
|
|
|
gdk_drag_status (context, 0, time);
|
|
|
|
return;
|
|
|
|
}
|
2005-11-28 05:49:21 -08:00
|
|
|
|
|
|
|
gdk_drag_status (context, GDK_ACTION_MOVE, time);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdk_drag_status (context, 0, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2006-06-23 00:48:32 -07:00
|
|
|
if (!finished)
|
|
|
|
gtk_drag_finish (context, FALSE, FALSE, time);
|
2005-11-28 05:49:21 -08:00
|
|
|
}
|