2005-06-22 11:20:32 -07:00
|
|
|
/*
|
|
|
|
* mooedit/mooeditwindow.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOEDIT_COMPILATION
|
|
|
|
#include "mooedit/mooedit-private.h"
|
|
|
|
#include "mooedit/mooeditdialogs.h"
|
2005-08-26 01:37:34 -07:00
|
|
|
#include "mooedit/moobigpaned.h"
|
2005-08-25 02:29:01 -07:00
|
|
|
#include "moofileview/moofileview.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooui/moouiobject-impl.h"
|
|
|
|
#include "mooui/moomenuaction.h"
|
2005-08-07 19:16:23 -07:00
|
|
|
#include "mooui/mootoggleaction.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooutils/moocompat.h"
|
|
|
|
#include "mooutils/moostock.h"
|
|
|
|
#include "mooutils/moomarshals.h"
|
2005-07-29 08:25:29 -07:00
|
|
|
#include "mooutils/moosignal.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
#define ACTIVE_DOC moo_edit_window_get_active_doc
|
|
|
|
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
struct _MooEditWindowPrivate {
|
2005-08-26 01:37:34 -07:00
|
|
|
MooBigPaned *paned;
|
2005-06-22 11:20:32 -07:00
|
|
|
GtkNotebook *notebook;
|
2005-08-05 07:44:07 -07:00
|
|
|
MooFileView *fileview;
|
2005-06-22 11:20:32 -07:00
|
|
|
gboolean use_fullname;
|
|
|
|
char *app_name;
|
|
|
|
MooEditor *editor;
|
|
|
|
GSList *lang_actions;
|
2005-07-26 09:13:40 -07:00
|
|
|
GtkStatusbar *statusbar;
|
|
|
|
guint statusbar_context_id;
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_class_init (MooEditWindowClass *klass);
|
|
|
|
|
|
|
|
static void moo_edit_window_init (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_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 add_tab (MooEditWindow *window,
|
|
|
|
MooEdit *edit);
|
|
|
|
static gboolean close_current_tab (MooEditWindow *window);
|
|
|
|
static gboolean close_tab (MooEditWindow *window,
|
|
|
|
MooEdit *edit);
|
|
|
|
static MooEdit *get_nth_tab (MooEditWindow *window,
|
|
|
|
int n);
|
|
|
|
static void notebook_switch_page (GtkNotebook *notebook,
|
|
|
|
GtkNotebookPage *page,
|
|
|
|
guint page_num,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void update_window_title (MooEditWindow *window);
|
|
|
|
static void edit_changed (MooEdit *edit,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void edit_can_undo_redo (MooEditWindow *window);
|
|
|
|
static GtkWidget *create_tab_label (MooEdit *edit);
|
|
|
|
static void update_tab_label (GtkWidget *label,
|
|
|
|
MooEdit *edit);
|
|
|
|
|
|
|
|
static GtkMenuItem *create_lang_menu (MooEditWindow *window,
|
|
|
|
MooMenuAction *action);
|
|
|
|
static void lang_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void active_tab_lang_changed (MooEditWindow *window);
|
2005-07-26 09:13:40 -07:00
|
|
|
static void update_statusbar (MooEditWindow *window);
|
|
|
|
static void cursor_moved (MooEditWindow *window,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
MooEdit *edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-07-30 15:15:13 -07:00
|
|
|
static void file_saved (MooEditWindow *window,
|
|
|
|
MooEditFileInfo *info);
|
|
|
|
|
2005-08-05 07:14:04 -07:00
|
|
|
static void fileview_activate (MooEditWindow *window,
|
2005-08-10 10:33:57 -07:00
|
|
|
const char *path);
|
2005-08-05 07:44:07 -07:00
|
|
|
static void current_doc_dir_clicked (MooEditWindow *window);
|
2005-08-05 07:14:04 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
/* actions */
|
|
|
|
static void moo_edit_window_new_cb (MooEditWindow *window);
|
|
|
|
static void moo_edit_window_new_tab (MooEditWindow *window);
|
|
|
|
static void moo_edit_window_open_cb (MooEditWindow *window);
|
|
|
|
static void moo_edit_window_close_tab (MooEditWindow *window);
|
|
|
|
static void moo_edit_window_previous_tab (MooEditWindow *window);
|
|
|
|
static void moo_edit_window_next_tab (MooEditWindow *window);
|
2005-08-07 19:16:23 -07:00
|
|
|
static void show_file_selector_toggled_cb (MooEditWindow *window,
|
|
|
|
gboolean show);
|
2005-08-26 01:37:34 -07:00
|
|
|
static void pane_opened (MooBigPaned *paned,
|
|
|
|
MooPanePosition position,
|
2005-08-07 19:16:23 -07:00
|
|
|
guint index,
|
|
|
|
MooEditWindow *window);
|
2005-08-26 01:37:34 -07:00
|
|
|
static void pane_hidden (MooBigPaned *paned,
|
|
|
|
MooPanePosition position,
|
2005-08-07 19:16:23 -07:00
|
|
|
MooEditWindow *window);
|
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,
|
|
|
|
PROP_EDITOR
|
|
|
|
};
|
|
|
|
|
2005-07-29 08:25:29 -07:00
|
|
|
enum {
|
2005-07-31 07:53:10 -07:00
|
|
|
DOCUMENT_NEW,
|
|
|
|
DOCUMENT_CLOSED,
|
2005-07-30 15:15:13 -07:00
|
|
|
FILE_OPENED,
|
|
|
|
FILE_SAVED,
|
2005-07-29 08:25:29 -07:00
|
|
|
NUM_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[NUM_SIGNALS];
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
static void moo_edit_window_class_init (MooEditWindowClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
MooWindowClass *window_class = MOO_WINDOW_CLASS (klass);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
window_class->close = (gboolean (*) (MooWindow*))moo_edit_window_close;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
moo_ui_object_class_init (gobject_class, "Editor", "Editor");
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "NewWindow",
|
|
|
|
"name", "New Window",
|
|
|
|
"label", "_New Window",
|
|
|
|
"tooltip", "Open new editor window",
|
|
|
|
"icon-stock-id", GTK_STOCK_NEW,
|
|
|
|
"accel", "<ctrl>N",
|
|
|
|
"closure::callback", moo_edit_window_new_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "NewTab",
|
|
|
|
"name", "New Tab",
|
|
|
|
"label", "New _Tab",
|
|
|
|
"tooltip", "Create new document tab",
|
|
|
|
"icon-stock-id", GTK_STOCK_NEW,
|
|
|
|
"accel", "<ctrl>T",
|
|
|
|
"closure::callback", moo_edit_window_new_tab,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Open",
|
|
|
|
"name", "Open",
|
|
|
|
"label", "_Open...",
|
|
|
|
"tooltip", "Open...",
|
|
|
|
"icon-stock-id", GTK_STOCK_OPEN,
|
|
|
|
"accel", "<ctrl>O",
|
|
|
|
"closure::callback", moo_edit_window_open_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Reload",
|
|
|
|
"name", "Reload",
|
|
|
|
"label", "_Reload",
|
|
|
|
"tooltip", "Reload document",
|
|
|
|
"icon-stock-id", GTK_STOCK_REFRESH,
|
|
|
|
"accel", "F5",
|
|
|
|
"closure::signal", "reload-interactive",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Save",
|
|
|
|
"name", "Save",
|
|
|
|
"label", "_Save",
|
|
|
|
"tooltip", "Save document",
|
|
|
|
"icon-stock-id", GTK_STOCK_SAVE,
|
|
|
|
"accel", "<ctrl>S",
|
|
|
|
"closure::callback", moo_edit_save,
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "SaveAs",
|
|
|
|
"name", "Save As",
|
|
|
|
"label", "Save _As...",
|
|
|
|
"tooltip", "Save as...",
|
|
|
|
"icon-stock-id", GTK_STOCK_SAVE_AS,
|
|
|
|
"accel", "<ctrl><shift>S",
|
|
|
|
"closure::signal", "save-as-interactive",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "CloseTab",
|
|
|
|
"name", "Close Tab",
|
|
|
|
"label", "_Close Tab",
|
|
|
|
"tooltip", "Close current document tab",
|
|
|
|
"icon-stock-id", GTK_STOCK_CLOSE,
|
|
|
|
"accel", "<ctrl>W",
|
|
|
|
"closure::callback", moo_edit_window_close_tab,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Undo",
|
|
|
|
"name", "Undo",
|
|
|
|
"label", "_Undo",
|
|
|
|
"tooltip", "Undo",
|
|
|
|
"icon-stock-id", GTK_STOCK_UNDO,
|
|
|
|
"accel", "<ctrl>Z",
|
|
|
|
"closure::signal", "undo",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Redo",
|
|
|
|
"name", "Redo",
|
|
|
|
"label", "_Redo",
|
|
|
|
"tooltip", "Redo",
|
|
|
|
"icon-stock-id", GTK_STOCK_REDO,
|
|
|
|
"accel", "<shift><ctrl>Z",
|
|
|
|
"closure::signal", "redo",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Cut",
|
|
|
|
"name", "Cut",
|
|
|
|
"label", "Cu_t",
|
|
|
|
"tooltip", "Cut",
|
|
|
|
"icon-stock-id", GTK_STOCK_CUT,
|
|
|
|
"accel", "<ctrl>X",
|
|
|
|
"closure::signal", "cut-clipboard",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Copy",
|
|
|
|
"name", "Copy",
|
|
|
|
"label", "_Copy",
|
|
|
|
"tooltip", "Copy",
|
|
|
|
"icon-stock-id", GTK_STOCK_COPY,
|
|
|
|
"accel", "<ctrl>C",
|
|
|
|
"closure::signal", "copy-clipboard",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Paste",
|
|
|
|
"name", "Paste",
|
|
|
|
"label", "_Paste",
|
|
|
|
"tooltip", "Paste",
|
|
|
|
"icon-stock-id", GTK_STOCK_PASTE,
|
|
|
|
"accel", "<ctrl>V",
|
|
|
|
"closure::signal", "paste-clipboard",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Delete",
|
|
|
|
"name", "Delete",
|
|
|
|
"label", "_Delete",
|
|
|
|
"tooltip", "Delete",
|
|
|
|
"icon-stock-id", GTK_STOCK_DELETE,
|
|
|
|
"closure::signal", "delete-selection",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "SelectAll",
|
|
|
|
"name", "Select All",
|
|
|
|
"label", "Select _All",
|
|
|
|
"tooltip", "Select all",
|
|
|
|
"accel", "<ctrl>A",
|
|
|
|
"closure::callback", moo_edit_select_all,
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "PreviousTab",
|
|
|
|
"name", "Previous Tab",
|
|
|
|
"label", "_Previous Tab",
|
|
|
|
"tooltip", "Previous tab",
|
|
|
|
"icon-stock-id", GTK_STOCK_GO_BACK,
|
|
|
|
"accel", "<alt>Left",
|
|
|
|
"closure::callback", moo_edit_window_previous_tab,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "NextTab",
|
|
|
|
"name", "Next Tab",
|
|
|
|
"label", "_Next Tab",
|
|
|
|
"tooltip", "Next tab",
|
|
|
|
"icon-stock-id", GTK_STOCK_GO_FORWARD,
|
|
|
|
"accel", "<alt>Right",
|
|
|
|
"closure::callback", moo_edit_window_next_tab,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Find",
|
|
|
|
"name", "Find",
|
|
|
|
"label", "_Find",
|
|
|
|
"tooltip", "Find",
|
|
|
|
"icon-stock-id", GTK_STOCK_FIND,
|
|
|
|
"accel", "<ctrl>F",
|
|
|
|
"closure::signal", "find",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "FindNext",
|
|
|
|
"name", "Find Next",
|
|
|
|
"label", "Find _Next",
|
|
|
|
"tooltip", "Find next",
|
|
|
|
"icon-stock-id", GTK_STOCK_GO_FORWARD,
|
|
|
|
"accel", "F3",
|
|
|
|
"closure::signal", "find-next",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "FindPrevious",
|
|
|
|
"name", "Find Previous",
|
|
|
|
"label", "Find _Previous",
|
|
|
|
"tooltip", "Find previous",
|
|
|
|
"icon-stock-id", GTK_STOCK_GO_BACK,
|
|
|
|
"accel", "<shift>F3",
|
|
|
|
"closure::signal", "find-previous",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "Replace",
|
|
|
|
"name", "Replace",
|
|
|
|
"label", "_Replace",
|
|
|
|
"tooltip", "Replace",
|
|
|
|
"icon-stock-id", GTK_STOCK_FIND_AND_REPLACE,
|
|
|
|
"accel", "<ctrl>R",
|
|
|
|
"closure::signal", "replace",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"id", "GoToLine",
|
|
|
|
"name", "Go to Line",
|
|
|
|
"label", "_Go to Line",
|
|
|
|
"tooltip", "Go to line",
|
|
|
|
"accel", "<ctrl>G",
|
|
|
|
"closure::signal", "goto-line",
|
|
|
|
"closure::proxy-func", moo_edit_window_get_active_doc,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"action-type::", MOO_TYPE_MENU_ACTION,
|
|
|
|
"id", "SyntaxMenu",
|
|
|
|
"create-menu-func", create_lang_menu,
|
|
|
|
NULL);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
moo_ui_object_class_new_action (gobject_class,
|
|
|
|
"action-type::", MOO_TYPE_TOGGLE_ACTION,
|
|
|
|
"id", "ShowFileSelector",
|
|
|
|
"name", "Show File Selector",
|
|
|
|
"label", "Show File Selector",
|
|
|
|
"tooltip", "Show File Selector",
|
|
|
|
"toggled-callback", show_file_selector_toggled_cb,
|
|
|
|
NULL);
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
signals[DOCUMENT_NEW] =
|
|
|
|
moo_signal_new_cb ("document-new",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
_moo_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT);
|
|
|
|
|
|
|
|
signals[DOCUMENT_CLOSED] =
|
|
|
|
moo_signal_new_cb ("document-closed",
|
2005-07-29 08:25:29 -07:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
_moo_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT);
|
2005-07-30 15:15:13 -07:00
|
|
|
|
|
|
|
signals[FILE_OPENED] =
|
|
|
|
moo_signal_new_cb ("file-opened",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
_moo_marshal_VOID__BOXED,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT_FILE_INFO | G_SIGNAL_TYPE_STATIC_SCOPE);
|
|
|
|
|
|
|
|
signals[FILE_SAVED] =
|
|
|
|
moo_signal_new_cb ("file-saved",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
_moo_marshal_VOID__BOXED,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
MOO_TYPE_EDIT_FILE_INFO | G_SIGNAL_TYPE_STATIC_SCOPE);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_init (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
window->priv = g_new0 (MooEditWindowPrivate, 1);
|
|
|
|
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-08-07 19:16:23 -07:00
|
|
|
static gboolean set_home_dir (MooFileView *fileview)
|
|
|
|
{
|
|
|
|
moo_file_view_chdir (fileview, g_get_home_dir (), NULL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
GObject *moo_edit_window_constructor (GType type,
|
|
|
|
guint n_props,
|
|
|
|
GObjectConstructParam *props)
|
|
|
|
{
|
2005-08-05 07:44:07 -07:00
|
|
|
GtkWidget *notebook, *paned, *fileview, *button, *icon;
|
2005-06-22 11:20:32 -07:00
|
|
|
MooEdit *edit;
|
2005-08-05 07:14:04 -07:00
|
|
|
MooEditFileMgr *mgr = NULL;
|
2005-06-22 11:20:32 -07:00
|
|
|
MooEditWindow *window;
|
|
|
|
|
|
|
|
GObject *object =
|
|
|
|
G_OBJECT_CLASS(moo_edit_window_parent_class)->constructor (type, n_props, props);
|
|
|
|
|
|
|
|
window = MOO_EDIT_WINDOW (object);
|
|
|
|
|
2005-07-26 09:13:40 -07:00
|
|
|
window->priv->statusbar = GTK_STATUSBAR (MOO_WINDOW(window)->statusbar);
|
|
|
|
gtk_widget_show (MOO_WINDOW(window)->statusbar);
|
|
|
|
window->priv->statusbar_context_id =
|
|
|
|
gtk_statusbar_get_context_id (window->priv->statusbar,
|
2005-07-31 07:53:10 -07:00
|
|
|
"MooEditWindow");
|
2005-07-26 09:13:40 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_widget_show (MOO_WINDOW(window)->vbox);
|
2005-08-05 07:14:04 -07:00
|
|
|
|
2005-08-26 01:37:34 -07:00
|
|
|
paned = moo_big_paned_new ();
|
2005-08-05 07:14:04 -07:00
|
|
|
gtk_widget_show (paned);
|
|
|
|
gtk_box_pack_start (GTK_BOX (MOO_WINDOW(window)->vbox), paned, TRUE, TRUE, 0);
|
2005-08-26 01:37:34 -07:00
|
|
|
window->priv->paned = MOO_BIG_PANED (paned);
|
2005-08-07 19:16:23 -07:00
|
|
|
g_signal_connect (window->priv->paned, "open-pane",
|
|
|
|
G_CALLBACK (pane_opened), window);
|
|
|
|
g_signal_connect (window->priv->paned, "hide-pane",
|
|
|
|
G_CALLBACK (pane_hidden), window);
|
2005-08-05 07:14:04 -07:00
|
|
|
|
|
|
|
if (window->priv->editor)
|
|
|
|
mgr = moo_editor_get_file_mgr (window->priv->editor);
|
|
|
|
|
|
|
|
fileview = GTK_WIDGET (g_object_new (MOO_TYPE_FILE_VIEW,
|
2005-08-26 01:37:34 -07:00
|
|
|
// "file-mgr", mgr,
|
2005-08-05 07:44:07 -07:00
|
|
|
NULL));
|
2005-08-05 07:14:04 -07:00
|
|
|
g_signal_connect_swapped (fileview, "activate",
|
|
|
|
G_CALLBACK (fileview_activate),
|
|
|
|
window);
|
2005-08-05 07:44:07 -07:00
|
|
|
window->priv->fileview = MOO_FILE_VIEW (fileview);
|
2005-08-07 19:16:23 -07:00
|
|
|
g_idle_add ((GSourceFunc) set_home_dir, fileview);
|
2005-08-05 07:44:07 -07:00
|
|
|
|
|
|
|
icon = gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_widget_show (GTK_WIDGET (icon));
|
|
|
|
button = gtk_button_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), icon);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
|
|
|
|
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
|
|
|
|
gtk_tooltips_set_tip (MOO_WINDOW(window)->tooltips, button,
|
|
|
|
"Current Document Directory",
|
|
|
|
"Current Document Directory");
|
|
|
|
gtk_box_pack_end (GTK_BOX (MOO_FILE_VIEW (fileview)->toolbar),
|
|
|
|
button, FALSE, FALSE, 0);
|
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (current_doc_dir_clicked),
|
|
|
|
window);
|
2005-08-05 07:14:04 -07:00
|
|
|
|
2005-08-26 01:37:34 -07:00
|
|
|
moo_big_paned_add_pane (MOO_BIG_PANED (paned),
|
|
|
|
fileview, MOO_PANE_POS_LEFT,
|
2005-08-26 22:45:09 -07:00
|
|
|
"File Selector", GTK_STOCK_OPEN, -1);
|
2005-08-05 07:14:04 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
notebook = gtk_notebook_new ();
|
2005-07-31 07:53:10 -07:00
|
|
|
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_widget_show (notebook);
|
2005-08-26 01:37:34 -07:00
|
|
|
moo_big_paned_add_child (window->priv->paned, notebook);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
window->priv->notebook = GTK_NOTEBOOK (notebook);
|
|
|
|
g_signal_connect_after (window->priv->notebook, "switch-page",
|
|
|
|
G_CALLBACK (notebook_switch_page), window);
|
|
|
|
|
|
|
|
window = MOO_EDIT_WINDOW (object);
|
|
|
|
edit = MOO_EDIT (_moo_edit_new (window->priv->editor));
|
|
|
|
add_tab (window, edit);
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (edit));
|
|
|
|
GTK_WIDGET_SET_FLAGS (edit, GTK_CAN_DEFAULT);
|
|
|
|
gtk_widget_grab_default (GTK_WIDGET (edit));
|
|
|
|
|
|
|
|
g_signal_connect (window, "realize", G_CALLBACK (update_window_title), NULL);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
|
|
|
g_free (window->priv->app_name);
|
|
|
|
g_free (window->priv);
|
|
|
|
G_OBJECT_CLASS (moo_edit_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define SCROLLED_WINDOW_QUARK (scrolled_window_quark())
|
|
|
|
static GQuark scrolled_window_quark (void)
|
|
|
|
{
|
|
|
|
static GQuark q = 0;
|
|
|
|
if (!q)
|
|
|
|
q = g_quark_from_static_string ("moo_edit_window_edit_scrolled_window");
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void add_tab (MooEditWindow *window,
|
|
|
|
MooEdit *edit)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scrolledwindow;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_WINDOW (window) && MOO_EDIT (edit));
|
|
|
|
|
|
|
|
label = create_tab_label (edit);
|
|
|
|
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);
|
2005-08-26 01:37:34 -07:00
|
|
|
// gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
|
|
|
|
// GTK_SHADOW_ETCHED_IN);
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET (edit));
|
|
|
|
gtk_widget_show_all (scrolledwindow);
|
|
|
|
g_object_set_qdata (G_OBJECT (edit), SCROLLED_WINDOW_QUARK, scrolledwindow);
|
|
|
|
|
|
|
|
if (!gtk_notebook_get_n_pages (window->priv->notebook))
|
|
|
|
gtk_notebook_set_show_tabs (window->priv->notebook, FALSE);
|
|
|
|
else
|
|
|
|
gtk_notebook_set_show_tabs (window->priv->notebook, TRUE);
|
|
|
|
|
|
|
|
#if GTK_MINOR_VERSION >= 4
|
|
|
|
n = gtk_notebook_append_page (window->priv->notebook, scrolledwindow, label);
|
|
|
|
#else /* GTK_MINOR_VERSION < 4 */
|
|
|
|
gtk_notebook_append_page (window->priv->notebook, scrolledwindow, label);
|
|
|
|
n = gtk_notebook_page_num (window->priv->notebook, scrolledwindow);
|
|
|
|
#endif /* GTK_MINOR_VERSION < 4 */
|
|
|
|
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, n);
|
|
|
|
g_signal_connect (edit, "doc_status_changed",
|
|
|
|
G_CALLBACK (edit_changed), window);
|
|
|
|
g_signal_connect_swapped (edit, "can-undo",
|
|
|
|
G_CALLBACK (edit_can_undo_redo), window);
|
|
|
|
g_signal_connect_swapped (edit, "can-redo",
|
|
|
|
G_CALLBACK (edit_can_undo_redo), window);
|
|
|
|
g_signal_connect_swapped (edit, "lang-changed",
|
|
|
|
G_CALLBACK (active_tab_lang_changed), window);
|
2005-07-26 09:13:40 -07:00
|
|
|
g_signal_connect_swapped (edit, "cursor-moved",
|
|
|
|
G_CALLBACK (cursor_moved), window);
|
2005-07-30 15:15:13 -07:00
|
|
|
g_signal_connect_swapped (edit, "file-saved",
|
|
|
|
G_CALLBACK (file_saved), window);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-07-26 09:13:40 -07:00
|
|
|
edit_changed (edit, window);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
g_signal_emit (window, signals[DOCUMENT_NEW], 0, edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void notebook_switch_page (G_GNUC_UNUSED GtkNotebook *notebook,
|
|
|
|
G_GNUC_UNUSED GtkNotebookPage *page,
|
|
|
|
guint page_num,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
edit_changed (get_nth_tab (window, page_num), window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MooEdit *get_nth_tab (MooEditWindow *window,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
GtkWidget *swin = gtk_notebook_get_nth_page (window->priv->notebook, n);
|
|
|
|
g_return_val_if_fail (swin != NULL, NULL);
|
|
|
|
return MOO_EDIT (gtk_bin_get_child (GTK_BIN (swin)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
void moo_edit_window_set_active_doc (MooEditWindow *window,
|
|
|
|
MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-07-31 07:53:10 -07:00
|
|
|
int index;
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window) && MOO_IS_EDIT (edit));
|
|
|
|
index = gtk_notebook_page_num (window->priv->notebook,
|
|
|
|
g_object_get_qdata (G_OBJECT (edit),
|
|
|
|
SCROLLED_WINDOW_QUARK));
|
|
|
|
g_return_if_fail (index >= 0);
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, index);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_window_title (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
const char *name;
|
|
|
|
MooEditDocStatus status;
|
|
|
|
gboolean modified, deleted, modified_on_disk, clean;
|
|
|
|
GString *title;
|
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
g_return_if_fail (edit != NULL);
|
|
|
|
if (window->priv->use_fullname)
|
|
|
|
name = moo_edit_get_display_filename (edit);
|
|
|
|
else
|
|
|
|
name = moo_edit_get_display_basename (edit);
|
|
|
|
if (!name) name = "<\?\?\?\?\?>";
|
|
|
|
|
|
|
|
status = moo_edit_get_doc_status (edit);
|
|
|
|
clean = status & MOO_EDIT_DOC_CLEAN;
|
|
|
|
modified = status & MOO_EDIT_DOC_MODIFIED;
|
|
|
|
deleted = status & MOO_EDIT_DOC_DELETED;
|
|
|
|
modified_on_disk = status & MOO_EDIT_DOC_MODIFIED_ON_DISK;
|
|
|
|
|
|
|
|
title = g_string_new ("");
|
|
|
|
if (window->priv->app_name)
|
|
|
|
g_string_append_printf (title, "%s - ", window->priv->app_name);
|
|
|
|
g_string_append_printf (title, "%s%s%s",
|
|
|
|
(modified && !clean) ? "* " : "",
|
|
|
|
name,
|
|
|
|
deleted ? " [deleted]" :
|
|
|
|
(modified_on_disk ? " [modified on disk]" : ""));
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), title->str);
|
|
|
|
g_string_free (title, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void edit_changed (G_GNUC_UNUSED MooEdit *edit,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
update_window_title (window);
|
|
|
|
edit_can_undo_redo (window);
|
|
|
|
active_tab_lang_changed (window);
|
2005-07-26 09:13:40 -07:00
|
|
|
update_statusbar (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void edit_can_undo_redo (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
gboolean can_redo, can_undo;
|
|
|
|
MooActionGroup *actions;
|
|
|
|
MooAction *undo, *redo;
|
|
|
|
|
|
|
|
g_return_if_fail (window != NULL);
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
g_return_if_fail (edit != NULL);
|
|
|
|
|
|
|
|
can_redo = moo_edit_can_redo (edit);
|
|
|
|
can_undo = moo_edit_can_undo (edit);
|
|
|
|
|
|
|
|
actions = moo_ui_object_get_actions (MOO_UI_OBJECT (window));
|
|
|
|
undo = moo_action_group_get_action (actions, "Undo");
|
|
|
|
redo = moo_action_group_get_action (actions, "Redo");
|
|
|
|
g_return_if_fail (undo != NULL && redo != NULL);
|
|
|
|
|
|
|
|
moo_action_set_sensitive (undo, can_undo);
|
|
|
|
moo_action_set_sensitive (redo, can_redo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkWidget *create_tab_label (MooEdit *edit)
|
|
|
|
{
|
2005-07-31 07:53:10 -07:00
|
|
|
GtkWidget *eventbox, *hbox, *filename, *icon;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
eventbox = gtk_event_box_new ();
|
2005-06-22 11:20:32 -07:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
2005-07-31 07:53:10 -07:00
|
|
|
gtk_widget_show (hbox);
|
2005-06-22 11:20:32 -07:00
|
|
|
icon = gtk_image_new ();
|
|
|
|
filename = gtk_label_new (moo_edit_get_display_basename (edit));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), filename, TRUE, TRUE, 3);
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
g_object_set_data (G_OBJECT (eventbox), "filename", filename);
|
|
|
|
g_object_set_data (G_OBJECT (eventbox), "icon", icon);
|
2005-06-22 11:20:32 -07:00
|
|
|
gtk_widget_show (filename);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (edit, "doc-status-changed",
|
2005-07-31 07:53:10 -07:00
|
|
|
G_CALLBACK (update_tab_label), eventbox);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_tab_label (GtkWidget *label,
|
|
|
|
MooEdit *edit)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
MooEditDocStatus status;
|
|
|
|
gboolean clean, modified, deleted, modified_on_disk;
|
|
|
|
GString *title;
|
|
|
|
GtkWidget *filename, *icon;
|
|
|
|
|
|
|
|
filename = g_object_get_data (G_OBJECT (label), "filename");
|
|
|
|
icon = g_object_get_data (G_OBJECT (label), "icon");
|
|
|
|
|
|
|
|
name = moo_edit_get_display_basename (edit);
|
|
|
|
if (!name) name = "<\?\?\?\?\?>";
|
|
|
|
|
|
|
|
status = moo_edit_get_doc_status (edit);
|
|
|
|
clean = status & MOO_EDIT_DOC_CLEAN;
|
|
|
|
modified = status & MOO_EDIT_DOC_MODIFIED;
|
|
|
|
deleted = status & MOO_EDIT_DOC_DELETED;
|
|
|
|
modified_on_disk = status & MOO_EDIT_DOC_MODIFIED_ON_DISK;
|
|
|
|
|
|
|
|
title = g_string_new ("");
|
|
|
|
g_string_append_printf (title, "%s%s",
|
|
|
|
(modified && !clean) ? "* " : "",
|
|
|
|
name);
|
|
|
|
gtk_label_set_text (GTK_LABEL (filename), title->str);
|
|
|
|
g_string_free (title, TRUE);
|
|
|
|
|
|
|
|
if (deleted || modified_on_disk)
|
|
|
|
gtk_widget_show (icon);
|
|
|
|
else
|
|
|
|
gtk_widget_hide (icon);
|
|
|
|
|
|
|
|
if (deleted)
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (icon),
|
|
|
|
MOO_STOCK_DOC_DELETED,
|
|
|
|
GTK_ICON_SIZE_MENU);
|
|
|
|
else if (modified_on_disk)
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (icon),
|
|
|
|
MOO_STOCK_DOC_MODIFIED_ON_DISK,
|
|
|
|
GTK_ICON_SIZE_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean moo_edit_window_close (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
|
|
|
|
while (gtk_notebook_get_n_pages (window->priv->notebook) &&
|
|
|
|
close_current_tab (window)) ;
|
|
|
|
|
|
|
|
if (gtk_notebook_get_n_pages (window->priv->notebook))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean close_current_tab (MooEditWindow *window)
|
|
|
|
{
|
2005-08-07 19:16:23 -07:00
|
|
|
MooEdit *edit = ACTIVE_DOC (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
g_return_val_if_fail (edit != NULL, FALSE);
|
|
|
|
return close_tab (window, edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean close_tab (MooEditWindow *window,
|
|
|
|
MooEdit *edit)
|
|
|
|
{
|
2005-07-31 07:53:10 -07:00
|
|
|
if (moo_edit_close (edit))
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
g_object_ref (edit);
|
|
|
|
|
|
|
|
label = gtk_notebook_get_tab_label (window->priv->notebook,
|
2005-06-22 11:20:32 -07:00
|
|
|
g_object_get_qdata (G_OBJECT (edit),
|
|
|
|
SCROLLED_WINDOW_QUARK));
|
|
|
|
g_signal_handlers_disconnect_by_func(edit, update_tab_label, label);
|
|
|
|
gtk_notebook_remove_page (window->priv->notebook,
|
|
|
|
gtk_notebook_get_current_page (window->priv->notebook));
|
2005-07-31 07:53:10 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
if (gtk_notebook_get_n_pages (window->priv->notebook) <= 1)
|
|
|
|
gtk_notebook_set_show_tabs (window->priv->notebook, FALSE);
|
2005-07-31 07:53:10 -07:00
|
|
|
|
|
|
|
g_signal_emit (window, signals[DOCUMENT_CLOSED], 0, edit);
|
|
|
|
g_object_unref (edit);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_new_cb (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
if (window->priv->editor)
|
|
|
|
moo_editor_new_window (window->priv->editor);
|
|
|
|
else
|
|
|
|
gtk_widget_show (_moo_edit_window_new (NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_new_tab (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit = _moo_edit_new (window->priv->editor);
|
|
|
|
add_tab (window, edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_open_cb (MooEditWindow *window)
|
|
|
|
{
|
2005-07-31 07:53:10 -07:00
|
|
|
_moo_edit_window_open (window, NULL, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_close_tab (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
close_current_tab (window);
|
|
|
|
if (!gtk_notebook_get_n_pages (window->priv->notebook))
|
|
|
|
moo_edit_window_new_tab (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_previous_tab (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
int n = gtk_notebook_get_current_page (window->priv->notebook);
|
|
|
|
if (n <= 0)
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, -1);
|
|
|
|
else
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, n - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_next_tab (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
int n = gtk_notebook_get_current_page (window->priv->notebook);
|
|
|
|
if (n == gtk_notebook_get_n_pages (window->priv->notebook) - 1)
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, 0);
|
|
|
|
else
|
|
|
|
gtk_notebook_set_current_page (window->priv->notebook, n + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *_moo_edit_window_new (MooEditor *editor)
|
|
|
|
{
|
|
|
|
MooEditWindow *window =
|
|
|
|
MOO_EDIT_WINDOW (g_object_new (MOO_TYPE_EDIT_WINDOW,
|
|
|
|
"editor", editor,
|
|
|
|
NULL));
|
|
|
|
return GTK_WIDGET (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
gboolean _moo_edit_window_open (MooEditWindow *window,
|
2005-06-22 11:20:32 -07:00
|
|
|
const char *filename,
|
|
|
|
const char *encoding)
|
|
|
|
{
|
2005-07-29 08:25:29 -07:00
|
|
|
MooEdit *edit;
|
2005-06-22 11:20:32 -07:00
|
|
|
MooEditFileInfo *info = NULL;
|
|
|
|
gboolean result;
|
2005-07-29 08:25:29 -07:00
|
|
|
gboolean add = FALSE;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
if (!filename)
|
2005-07-31 07:53:10 -07:00
|
|
|
return moo_editor_open (window->priv->editor, window,
|
|
|
|
GTK_WIDGET (window), NULL, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-07-28 12:25:10 -07:00
|
|
|
|
|
|
|
if (!edit)
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
moo_edit_file_info_free (info);
|
2005-07-30 15:15:13 -07:00
|
|
|
g_return_val_if_reached (FALSE);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
2005-07-28 12:25:10 -07:00
|
|
|
if (!moo_edit_is_empty (edit))
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
edit = _moo_edit_new (window->priv->editor);
|
2005-08-05 07:14:04 -07:00
|
|
|
gtk_object_sink (GTK_OBJECT (g_object_ref (edit)));
|
2005-07-29 08:25:29 -07:00
|
|
|
add = TRUE;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
result = moo_edit_open (edit, filename, encoding);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
|
|
|
if (add)
|
2005-07-28 12:25:10 -07:00
|
|
|
{
|
2005-07-29 08:25:29 -07:00
|
|
|
if (result)
|
|
|
|
add_tab (window, edit);
|
|
|
|
else
|
|
|
|
g_object_unref (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
2005-07-28 12:25:10 -07:00
|
|
|
|
2005-07-30 15:15:13 -07:00
|
|
|
if (!info)
|
|
|
|
info = moo_edit_file_info_new (filename, encoding);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
g_signal_emit (window, signals[FILE_OPENED], 0, info);
|
|
|
|
|
|
|
|
moo_edit_file_info_free (info);
|
2005-06-22 11:20:32 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
g_return_val_if_fail (gtk_notebook_get_n_pages (window->priv->notebook) > 0,
|
|
|
|
NULL);
|
|
|
|
return get_nth_tab (window,
|
|
|
|
gtk_notebook_get_current_page (window->priv->notebook));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _moo_edit_window_set_app_name (MooEditWindow *window,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
g_free (window->priv->app_name);
|
|
|
|
window->priv->app_name = g_strdup (name);
|
|
|
|
if (GTK_WIDGET_REALIZED (GTK_WIDGET (window)))
|
|
|
|
update_window_title (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_edit_window_set_property(GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MooEditWindow *window = MOO_EDIT_WINDOW (object);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_EDITOR:
|
|
|
|
window->priv->editor = MOO_EDITOR (g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
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);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_EDITOR:
|
|
|
|
g_value_set_object (value, window->priv->editor);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GtkMenuItem *create_lang_menu (MooEditWindow *window,
|
|
|
|
MooMenuAction *action)
|
|
|
|
{
|
|
|
|
GSList *sections;
|
|
|
|
GSList *section_items = NULL, *section_menus = NULL;
|
|
|
|
GSList *l;
|
|
|
|
MooEditLangMgr *mgr;
|
|
|
|
const GSList *langs, *cl;
|
|
|
|
GtkWidget *main_item, *main_menu, *none;
|
|
|
|
GSList *group = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
g_return_val_if_fail (window->priv->editor != NULL, NULL);
|
|
|
|
|
|
|
|
main_item = gtk_menu_item_new_with_label ("Language");
|
|
|
|
main_menu = gtk_menu_new ();
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (main_item), main_menu);
|
|
|
|
none = gtk_radio_menu_item_new_with_label (group, "None");
|
|
|
|
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (none));
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (main_menu), none);
|
|
|
|
g_signal_connect (none, "toggled",
|
|
|
|
G_CALLBACK (lang_menu_item_toggled),
|
|
|
|
window);
|
|
|
|
/* TODO TODO TODO crash */
|
|
|
|
g_object_set_qdata (G_OBJECT (action),
|
|
|
|
g_quark_from_string ("moo_edit_window_null_lang"),
|
|
|
|
none);
|
|
|
|
|
|
|
|
mgr = moo_editor_get_lang_mgr (window->priv->editor);
|
|
|
|
sections = moo_edit_lang_mgr_get_sections (mgr);
|
|
|
|
|
|
|
|
for (l = sections; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
GtkWidget *item, *menu;
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label (l->data);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (main_menu), item);
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
|
|
|
|
|
|
|
|
section_items = g_slist_append (section_items, item);
|
|
|
|
section_menus = g_slist_append (section_menus, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
langs = moo_edit_lang_mgr_get_available_languages (mgr);
|
|
|
|
for (cl = langs; cl != NULL; cl = cl->next)
|
|
|
|
{
|
|
|
|
MooEditLang *lang;
|
|
|
|
const char *section, *name;
|
|
|
|
GtkWidget *item;
|
|
|
|
GSList *link;
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
lang = MOO_EDIT_LANG (cl->data);
|
|
|
|
section = moo_edit_lang_get_section (lang);
|
|
|
|
name = moo_edit_lang_get_name (lang);
|
|
|
|
|
|
|
|
link = g_slist_find_custom (sections, section, (GCompareFunc) strcmp);
|
|
|
|
pos = g_slist_position (sections, link);
|
|
|
|
g_assert (pos >= 0);
|
|
|
|
|
|
|
|
item = gtk_radio_menu_item_new_with_label (group, name);
|
|
|
|
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
|
|
|
|
g_object_set_data_full (G_OBJECT (item), "moo_edit_window_lang_id",
|
|
|
|
g_strdup (moo_edit_lang_get_id (lang)),
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
g_signal_connect (item, "toggled",
|
|
|
|
G_CALLBACK (lang_menu_item_toggled),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_object_set_qdata (G_OBJECT (action),
|
|
|
|
g_quark_from_string (moo_edit_lang_get_id (lang)),
|
|
|
|
item);
|
|
|
|
|
|
|
|
link = g_slist_nth (section_menus, pos);
|
|
|
|
g_assert (link != NULL);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (link->data), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO TODO TODO crash */
|
|
|
|
window->priv->lang_actions =
|
|
|
|
g_slist_append (window->priv->lang_actions, action);
|
|
|
|
gtk_widget_show_all (main_item);
|
|
|
|
active_tab_lang_changed (window);
|
|
|
|
|
|
|
|
g_slist_foreach (sections, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (sections);
|
|
|
|
g_slist_free (section_items);
|
|
|
|
g_slist_free (section_menus);
|
|
|
|
|
|
|
|
return GTK_MENU_ITEM (main_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void lang_menu_item_toggled (GtkCheckMenuItem *item,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
const char *lang_id;
|
|
|
|
MooEditLang *lang = NULL;
|
|
|
|
MooEdit *edit;
|
|
|
|
MooEditor *editor;
|
|
|
|
|
|
|
|
if (!gtk_check_menu_item_get_active (item))
|
|
|
|
return;
|
|
|
|
|
|
|
|
editor = window->priv->editor;
|
|
|
|
g_return_if_fail (editor != NULL);
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
if (!edit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lang_id = g_object_get_data (G_OBJECT (item), "moo_edit_window_lang_id");
|
|
|
|
if (lang_id)
|
|
|
|
lang = moo_edit_lang_mgr_get_language_by_id (moo_editor_get_lang_mgr (editor),
|
|
|
|
lang_id);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (edit, active_tab_lang_changed, window);
|
|
|
|
moo_edit_set_lang (edit, lang);
|
|
|
|
edit->priv->lang_custom = TRUE;
|
|
|
|
g_signal_handlers_unblock_by_func (edit, active_tab_lang_changed, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void active_tab_lang_changed (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
const char *lang_id = NULL;
|
|
|
|
MooEditLang *lang = NULL;
|
|
|
|
MooEdit *edit;
|
|
|
|
GSList *l;
|
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
if (!edit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lang = moo_edit_get_lang (edit);
|
|
|
|
if (lang)
|
|
|
|
lang_id = moo_edit_lang_get_id (lang);
|
|
|
|
else
|
|
|
|
lang_id = "moo_edit_window_null_lang";
|
|
|
|
|
|
|
|
for (l = window->priv->lang_actions; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
GtkCheckMenuItem *item =
|
|
|
|
g_object_get_qdata (G_OBJECT (l->data),
|
|
|
|
g_quark_try_string (lang_id));
|
|
|
|
g_assert (item != NULL);
|
|
|
|
g_signal_handlers_block_by_func (item, lang_menu_item_toggled, window);
|
|
|
|
gtk_check_menu_item_set_active (item, TRUE);
|
|
|
|
g_signal_handlers_unblock_by_func (item, lang_menu_item_toggled, window);
|
|
|
|
}
|
|
|
|
}
|
2005-07-26 09:13:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
static void set_statusbar_numbers (MooEditWindow *window,
|
|
|
|
int line,
|
|
|
|
int column)
|
|
|
|
{
|
|
|
|
char *text;
|
2005-07-29 09:21:04 -07:00
|
|
|
gtk_statusbar_pop (window->priv->statusbar,
|
|
|
|
window->priv->statusbar_context_id);
|
2005-07-26 09:13:40 -07:00
|
|
|
text = g_strdup_printf ("Line: %d Col: %d", line, column);
|
|
|
|
gtk_statusbar_push (window->priv->statusbar,
|
|
|
|
window->priv->statusbar_context_id,
|
|
|
|
text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_statusbar (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooEdit *edit;
|
|
|
|
int line, column;
|
|
|
|
GtkTextIter iter;
|
|
|
|
|
2005-08-07 19:16:23 -07:00
|
|
|
edit = ACTIVE_DOC (window);
|
2005-07-26 09:13:40 -07:00
|
|
|
gtk_text_buffer_get_iter_at_mark (edit->priv->text_buffer, &iter,
|
|
|
|
gtk_text_buffer_get_insert (edit->priv->text_buffer));
|
|
|
|
line = gtk_text_iter_get_line (&iter) + 1;
|
|
|
|
column = gtk_text_iter_get_line_offset (&iter) + 1;
|
|
|
|
|
|
|
|
set_statusbar_numbers (window, line, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void cursor_moved (MooEditWindow *window,
|
|
|
|
GtkTextIter *iter,
|
|
|
|
MooEdit *edit)
|
|
|
|
{
|
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;
|
|
|
|
int column = gtk_text_iter_get_line_offset (iter) + 1;
|
|
|
|
set_statusbar_numbers (window, line, column);
|
|
|
|
}
|
|
|
|
}
|
2005-07-29 08:25:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
GSList *moo_edit_window_list_docs (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
GSList *list = NULL;
|
|
|
|
int num, i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
|
|
|
|
num = gtk_notebook_get_n_pages (window->priv->notebook);
|
|
|
|
|
|
|
|
for (i = num - 1; i >= 0; i--)
|
|
|
|
list = g_slist_prepend (list, get_nth_tab (window, i));
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2005-07-30 15:15:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
MooEditor *_moo_edit_window_get_editor (MooEditWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
return window->priv->editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void file_saved (MooEditWindow *window,
|
|
|
|
MooEditFileInfo *info)
|
|
|
|
{
|
|
|
|
g_signal_emit (window, signals[FILE_SAVED], 0, info);
|
|
|
|
}
|
2005-08-05 07:14:04 -07:00
|
|
|
|
|
|
|
|
|
|
|
static void fileview_activate (MooEditWindow *window,
|
2005-08-10 10:33:57 -07:00
|
|
|
const char *path)
|
2005-08-05 07:14:04 -07:00
|
|
|
{
|
|
|
|
if (_moo_edit_window_open (window, path, NULL))
|
|
|
|
{
|
2005-08-07 19:16:23 -07:00
|
|
|
MooEdit *edit = ACTIVE_DOC (window);
|
2005-08-05 07:14:04 -07:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (edit));
|
|
|
|
}
|
|
|
|
}
|
2005-08-05 07:44:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
static void current_doc_dir_clicked (MooEditWindow *window)
|
|
|
|
{
|
2005-08-07 19:16:23 -07:00
|
|
|
MooEdit *edit = ACTIVE_DOC (window);
|
2005-08-05 07:44:07 -07:00
|
|
|
const char *filename = moo_edit_get_filename (edit);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
char *dirname = g_path_get_dirname (filename);
|
|
|
|
moo_file_view_chdir (window->priv->fileview, dirname, NULL);
|
|
|
|
g_free (dirname);
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 19:16:23 -07:00
|
|
|
|
|
|
|
|
|
|
|
#define BOOL_EQUAL(a,b) ((a && b) || (!a && !b))
|
|
|
|
|
|
|
|
static void show_file_selector_toggled_cb (MooEditWindow *window,
|
|
|
|
gboolean show)
|
|
|
|
{
|
2005-08-26 01:37:34 -07:00
|
|
|
/* gboolean open = moo_paned_is_open (window->priv->paned);
|
2005-08-07 19:16:23 -07:00
|
|
|
|
|
|
|
if (BOOL_EQUAL (show, open))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
{
|
|
|
|
moo_paned_open_pane (window->priv->paned, 0);
|
|
|
|
g_signal_emit_by_name (window->priv->fileview,
|
|
|
|
"focus-to-file-view");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MooEdit *edit = ACTIVE_DOC (window);
|
|
|
|
moo_paned_hide_pane (window->priv->paned);
|
|
|
|
if (edit) gtk_widget_grab_focus (GTK_WIDGET (edit));
|
2005-08-26 01:37:34 -07:00
|
|
|
}*/
|
2005-08-07 19:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-26 01:37:34 -07:00
|
|
|
static void pane_opened (G_GNUC_UNUSED MooBigPaned *paned,
|
|
|
|
G_GNUC_UNUSED MooPanePosition position,
|
2005-08-07 19:16:23 -07:00
|
|
|
G_GNUC_UNUSED guint index,
|
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooActionGroup *actions;
|
|
|
|
MooAction *show;
|
|
|
|
|
|
|
|
actions = moo_ui_object_get_actions (MOO_UI_OBJECT (window));
|
|
|
|
show = moo_action_group_get_action (actions, "ShowFileSelector");
|
|
|
|
g_return_if_fail (show != NULL);
|
|
|
|
|
|
|
|
moo_toggle_action_set_active (MOO_TOGGLE_ACTION (show), TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-26 01:37:34 -07:00
|
|
|
static void pane_hidden (G_GNUC_UNUSED MooBigPaned *paned,
|
|
|
|
G_GNUC_UNUSED MooPanePosition position,
|
2005-08-07 19:16:23 -07:00
|
|
|
MooEditWindow *window)
|
|
|
|
{
|
|
|
|
MooActionGroup *actions;
|
|
|
|
MooAction *show;
|
|
|
|
|
|
|
|
actions = moo_ui_object_get_actions (MOO_UI_OBJECT (window));
|
|
|
|
show = moo_action_group_get_action (actions, "ShowFileSelector");
|
|
|
|
g_return_if_fail (show != NULL);
|
|
|
|
|
|
|
|
moo_toggle_action_set_active (MOO_TOGGLE_ACTION (show), FALSE);
|
|
|
|
}
|