2006-05-04 01:40:54 -05:00
|
|
|
/*
|
2005-09-06 16:21:05 +00:00
|
|
|
* mooedit.c
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2010-12-21 20:15:45 -08:00
|
|
|
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2005-06-22 18:20:32 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-10 01:06:58 -08:00
|
|
|
/**
|
2011-01-09 23:33:47 -08:00
|
|
|
* class:MooEdit: (parent GObject) (moo.doc-object-name doc): document object
|
2010-12-23 16:24:52 -08:00
|
|
|
*
|
|
|
|
* Object which represents a document. It has methods for file operations
|
|
|
|
* and manipulating document text.
|
2010-12-10 01:06:58 -08:00
|
|
|
**/
|
|
|
|
|
2011-01-22 20:56:53 -08:00
|
|
|
/**
|
|
|
|
* flags:MooEditStatus
|
|
|
|
*
|
|
|
|
* @MOO_EDIT_STATUS_NORMAL: none of the below flags, it is equal to <code>0</code>.
|
|
|
|
* @MOO_EDIT_STATUS_MODIFIED_ON_DISK: file has been modified on disk outside the program.
|
|
|
|
* @MOO_EDIT_STATUS_DELETED: file has been deleted from disk.
|
|
|
|
* @MOO_EDIT_STATUS_CHANGED_ON_DISK: file has been modified on disk outside the program or deleted from disk,
|
|
|
|
* it is equal to <code>#MOO_EDIT_STATUS_MODIFIED_ON_DISK | #MOO_EDIT_STATUS_DELETED</code>.
|
|
|
|
* @MOO_EDIT_STATUS_MODIFIED: document content is modifed and not saved yet.
|
|
|
|
* @MOO_EDIT_STATUS_NEW: file doesn't exist on disk yet. This is the state of documents
|
|
|
|
* opened from command line when requested file doesn't exist.
|
|
|
|
* @MOO_EDIT_STATUS_CLEAN: doesn't prompt on close, even if it's modified.
|
|
|
|
**/
|
|
|
|
|
2006-08-19 00:59:53 -05:00
|
|
|
#include "mooedit/mooeditaction-factory.h"
|
2005-06-22 18:20:32 +00:00
|
|
|
#include "mooedit/mooedit-private.h"
|
2010-12-18 23:58:18 -08:00
|
|
|
#include "mooedit/mooeditview-impl.h"
|
2010-11-23 21:54:39 -08:00
|
|
|
#include "mooedit/mooeditbookmark.h"
|
2005-06-22 18:20:32 +00:00
|
|
|
#include "mooedit/mooeditdialogs.h"
|
|
|
|
#include "mooedit/mooeditprefs.h"
|
2010-12-08 01:11:51 -08:00
|
|
|
#include "mooedit/mootextbuffer.h"
|
2006-07-27 14:39:53 -05:00
|
|
|
#include "mooedit/mooeditfiltersettings.h"
|
2010-11-23 21:54:39 -08:00
|
|
|
#include "mooedit/mooeditor-impl.h"
|
2011-01-18 21:15:41 -08:00
|
|
|
#include "mooedit/mooedittab-impl.h"
|
2011-01-18 01:16:25 -08:00
|
|
|
#include "mooedit/mooeditwindow-impl.h"
|
2008-08-26 13:51:05 -05:00
|
|
|
#include "mooedit/moolangmgr.h"
|
2008-02-18 19:42:41 -06:00
|
|
|
#include "marshals.h"
|
2010-09-23 01:20:26 -07:00
|
|
|
#include "mooutils/mooutils-fs.h"
|
2006-08-03 02:29:39 -05:00
|
|
|
#include "mooutils/mooi18n.h"
|
2007-01-19 20:47:59 -06:00
|
|
|
#include "mooutils/mooutils-misc.h"
|
2008-09-07 00:15:07 -05:00
|
|
|
#include "mooutils/mootype-macros.h"
|
2008-09-10 01:33:15 -05:00
|
|
|
#include "mooutils/mooatom.h"
|
2010-11-07 03:32:15 -08:00
|
|
|
#include "mooutils/moocompat.h"
|
2010-12-17 00:46:14 -08:00
|
|
|
#include "mooedit/mooeditprogress-gxml.h"
|
2005-09-06 16:21:05 +00:00
|
|
|
#include <string.h>
|
2008-04-13 18:26:40 -05:00
|
|
|
#include <stdlib.h>
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2008-02-20 06:52:05 -06:00
|
|
|
#define KEY_ENCODING "encoding"
|
|
|
|
#define KEY_LINE "line"
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
MOO_DEFINE_OBJECT_ARRAY (MooEdit, moo_edit)
|
2008-02-20 06:52:05 -06:00
|
|
|
|
2010-02-01 22:44:03 -08:00
|
|
|
MooEditList *_moo_edit_instances = NULL;
|
2010-12-19 02:26:03 -08:00
|
|
|
static guint moo_edit_apply_config_all_idle;
|
2006-04-20 03:57:05 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static GObject *moo_edit_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_param);
|
|
|
|
static void moo_edit_finalize (GObject *object);
|
|
|
|
static void moo_edit_dispose (GObject *object);
|
|
|
|
|
|
|
|
static void moo_edit_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
2006-12-31 04:53:45 -06:00
|
|
|
GParamSpec *pspec);
|
2010-12-19 02:26:03 -08:00
|
|
|
static void moo_edit_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
2006-12-31 04:53:45 -06:00
|
|
|
GParamSpec *pspec);
|
2010-12-19 02:26:03 -08:00
|
|
|
|
2011-01-21 03:12:18 -08:00
|
|
|
static MooSaveResponse moo_edit_before_save (MooEdit *doc,
|
2010-12-19 03:29:16 -08:00
|
|
|
GFile *file);
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static void config_changed (MooEdit *edit);
|
|
|
|
static void update_config_from_mode_lines (MooEdit *doc);
|
|
|
|
static void moo_edit_recheck_config (MooEdit *doc);
|
2005-12-08 08:53:46 +00:00
|
|
|
|
2006-12-31 04:53:45 -06:00
|
|
|
static void modified_changed_cb (GtkTextBuffer *buffer,
|
|
|
|
MooEdit *edit);
|
2005-11-04 01:35:22 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static MooLang *moo_edit_get_lang (MooEdit *doc);
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
static void moo_edit_apply_prefs (MooEdit *doc);
|
|
|
|
static void moo_edit_freeze_notify (MooEdit *doc);
|
|
|
|
static void moo_edit_thaw_notify (MooEdit *doc);
|
|
|
|
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
enum {
|
|
|
|
DOC_STATUS_CHANGED,
|
|
|
|
FILENAME_CHANGED,
|
2011-01-21 03:12:18 -08:00
|
|
|
WILL_CLOSE,
|
2010-12-19 03:29:16 -08:00
|
|
|
BEFORE_SAVE,
|
2011-01-21 03:12:18 -08:00
|
|
|
WILL_SAVE,
|
2010-12-19 03:29:16 -08:00
|
|
|
AFTER_SAVE,
|
2005-06-22 18:20:32 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2005-12-11 04:30:02 +00:00
|
|
|
PROP_EDITOR,
|
2006-04-29 22:54:03 -05:00
|
|
|
PROP_ENABLE_BOOKMARKS,
|
2007-11-29 19:53:33 -06:00
|
|
|
PROP_HAS_COMMENTS,
|
2009-12-06 13:54:27 -08:00
|
|
|
PROP_LINE_END_TYPE,
|
2010-12-19 02:26:03 -08:00
|
|
|
PROP_LANG,
|
2007-11-29 19:53:33 -06:00
|
|
|
PROP_ENCODING
|
2005-06-22 18:20:32 +00:00
|
|
|
};
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
G_DEFINE_TYPE (MooEdit, moo_edit, G_TYPE_OBJECT)
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_class_init (MooEditClass *klass)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = moo_edit_set_property;
|
|
|
|
gobject_class->get_property = moo_edit_get_property;
|
2010-12-08 01:11:51 -08:00
|
|
|
gobject_class->constructor = moo_edit_constructor;
|
2005-06-22 18:20:32 +00:00
|
|
|
gobject_class->finalize = moo_edit_finalize;
|
2010-12-08 01:11:51 -08:00
|
|
|
gobject_class->dispose = moo_edit_dispose;
|
|
|
|
|
2010-12-19 03:29:16 -08:00
|
|
|
klass->before_save = moo_edit_before_save;
|
|
|
|
|
2006-08-19 01:15:42 -05:00
|
|
|
g_type_class_add_private (klass, sizeof (MooEditPrivate));
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
g_object_class_install_property (gobject_class, PROP_EDITOR,
|
|
|
|
g_param_spec_object ("editor", "editor", "editor",
|
|
|
|
MOO_TYPE_EDITOR, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ENABLE_BOOKMARKS,
|
|
|
|
g_param_spec_boolean ("enable-bookmarks", "enable-bookmarks", "enable-bookmarks",
|
|
|
|
TRUE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_HAS_COMMENTS,
|
|
|
|
g_param_spec_boolean ("has-comments", "has-comments", "has-comments",
|
|
|
|
FALSE, G_PARAM_READABLE));
|
2006-04-29 22:54:03 -05:00
|
|
|
|
2009-12-06 13:54:27 -08:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LINE_END_TYPE,
|
2009-12-13 16:16:39 -08:00
|
|
|
g_param_spec_enum ("line-end-type", "line-end-type", "line-end-type",
|
2010-02-01 22:44:03 -08:00
|
|
|
MOO_TYPE_LINE_END_TYPE, MOO_LE_NONE,
|
|
|
|
(GParamFlags) G_PARAM_READWRITE));
|
2009-12-06 13:54:27 -08:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ENCODING,
|
|
|
|
g_param_spec_string ("encoding", "encoding", "encoding",
|
|
|
|
NULL, (GParamFlags) G_PARAM_READWRITE));
|
2007-11-29 19:53:33 -06:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LANG,
|
|
|
|
g_param_spec_object ("lang", "lang", "lang",
|
|
|
|
MOO_TYPE_LANG, G_PARAM_READABLE));
|
2005-11-04 01:35:22 +00:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
signals[DOC_STATUS_CHANGED] =
|
2005-09-03 22:48:05 +00:00
|
|
|
g_signal_new ("doc-status-changed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, doc_status_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
signals[FILENAME_CHANGED] =
|
2005-09-03 22:48:05 +00:00
|
|
|
g_signal_new ("filename-changed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2005-11-04 01:35:22 +00:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
2005-09-03 22:48:05 +00:00
|
|
|
G_STRUCT_OFFSET (MooEditClass, filename_changed),
|
|
|
|
NULL, NULL,
|
2010-12-19 02:26:03 -08:00
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2011-01-21 03:12:18 -08:00
|
|
|
/**
|
|
|
|
* MooEdit::will-close:
|
|
|
|
*
|
|
|
|
* @doc: the object which received the signal
|
|
|
|
*
|
|
|
|
* This signal is emitted before the document is closed.
|
|
|
|
**/
|
|
|
|
signals[WILL_CLOSE] =
|
|
|
|
g_signal_new ("will-close",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, will_close),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MooEdit::before-save:
|
|
|
|
*
|
|
|
|
* @doc: the object which received the signal
|
|
|
|
* @file: the #GFile object which represents saved file
|
|
|
|
*
|
|
|
|
* This signal is emitted when the document is going to be saved on disk.
|
|
|
|
* Callbacks should return #MOO_SAVE_RESPONSE_CANCEL if document
|
|
|
|
* should not be saved, and #MOO_SAVE_RESPONSE_CONTINUE otherwise.
|
|
|
|
*
|
|
|
|
* For example, if before saving the file must be checked out from a version
|
|
|
|
* control system, a callback can do that and return #MOO_SAVE_RESPONSE_CANCEL
|
|
|
|
* if checkout failed.
|
|
|
|
*
|
|
|
|
* Callbacks should not modify document content. If you need to modify
|
|
|
|
* it before saving, use MooEdit::will-save signal instead.
|
|
|
|
*
|
|
|
|
* Returns: #MOO_SAVE_RESPONSE_CANCEL to cancel saving,
|
|
|
|
* #MOO_SAVE_RESPONSE_CONTINUE otherwise.
|
|
|
|
**/
|
2010-12-19 03:29:16 -08:00
|
|
|
signals[BEFORE_SAVE] =
|
|
|
|
g_signal_new ("before-save",
|
2005-11-23 11:10:03 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2010-12-19 03:29:16 -08:00
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, before_save),
|
2011-01-21 03:12:18 -08:00
|
|
|
moo_signal_accumulator_continue_cancel,
|
|
|
|
GINT_TO_POINTER (MOO_SAVE_RESPONSE_CONTINUE),
|
2010-12-19 03:29:16 -08:00
|
|
|
_moo_marshal_ENUM__OBJECT,
|
2011-01-21 03:12:18 -08:00
|
|
|
MOO_TYPE_SAVE_RESPONSE, 1,
|
|
|
|
G_TYPE_FILE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MooEdit::will-save:
|
|
|
|
*
|
|
|
|
* @doc: the object which received the signal
|
|
|
|
* @file: the #GFile object which represents saved file
|
|
|
|
*
|
|
|
|
* This signal is emitted when the document is going to be saved on disk,
|
|
|
|
* after MooEdit::before-save signal. Callbacks may modify document
|
|
|
|
* content at this point.
|
|
|
|
**/
|
|
|
|
signals[WILL_SAVE] =
|
|
|
|
g_signal_new ("will-save",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, will_save),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__OBJECT,
|
|
|
|
G_TYPE_NONE, 1,
|
2010-12-19 03:29:16 -08:00
|
|
|
G_TYPE_FILE);
|
|
|
|
|
2011-01-21 03:12:18 -08:00
|
|
|
/**
|
|
|
|
* MooEdit::after-save:
|
|
|
|
*
|
|
|
|
* @doc: the object which received the signal
|
|
|
|
*
|
|
|
|
* This signal is emitted after the document has been successfully saved on disk.
|
|
|
|
**/
|
2010-12-19 03:29:16 -08:00
|
|
|
signals[AFTER_SAVE] =
|
|
|
|
g_signal_new ("after-save",
|
2005-11-23 11:10:03 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2010-12-19 03:29:16 -08:00
|
|
|
G_STRUCT_OFFSET (MooEditClass, after_save),
|
2005-11-23 11:10:03 +00:00
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2006-07-27 14:39:53 -05:00
|
|
|
_moo_edit_init_config ();
|
|
|
|
_moo_edit_class_init_actions (klass);
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_init (MooEdit *edit)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
edit->priv = G_TYPE_INSTANCE_GET_PRIVATE (edit, MOO_TYPE_EDIT, MooEditPrivate);
|
2010-12-02 23:38:37 -08:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
edit->priv->views = moo_edit_view_array_new ();
|
|
|
|
edit->priv->buffer = g_object_new (MOO_TYPE_TEXT_BUFFER, NULL);
|
|
|
|
|
2005-12-08 08:53:46 +00:00
|
|
|
edit->config = moo_edit_config_new ();
|
|
|
|
g_signal_connect_swapped (edit->config, "notify",
|
2010-12-19 02:26:03 -08:00
|
|
|
G_CALLBACK (config_changed),
|
|
|
|
edit);
|
2005-12-08 08:53:46 +00:00
|
|
|
|
2006-08-15 02:12:41 -05:00
|
|
|
edit->priv->actions = moo_action_collection_new ("MooEdit", "MooEdit");
|
2009-12-06 13:54:27 -08:00
|
|
|
|
2010-12-08 01:11:51 -08:00
|
|
|
edit->priv->line_end_type = MOO_LE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static GObject *
|
2010-12-08 01:11:51 -08:00
|
|
|
moo_edit_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_param)
|
|
|
|
{
|
|
|
|
GObject *object;
|
2011-01-17 03:01:11 -08:00
|
|
|
MooEdit *doc;
|
|
|
|
MooEditView *view;
|
2010-12-08 01:11:51 -08:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (moo_edit_parent_class)->constructor (
|
|
|
|
type, n_construct_properties, construct_param);
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
doc = MOO_EDIT (object);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
view = _moo_edit_view_new (doc);
|
2011-09-28 23:21:32 -07:00
|
|
|
(void) view; g_assert (doc->priv->views->n_elms == 1 && doc->priv->views->elms[0] == view);
|
2010-12-18 23:58:18 -08:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
_moo_edit_add_class_actions (doc);
|
|
|
|
_moo_edit_instances = moo_edit_list_prepend (_moo_edit_instances, doc);
|
2010-12-18 23:58:18 -08:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
doc->priv->modified_changed_handler_id =
|
|
|
|
g_signal_connect (doc->priv->buffer,
|
2005-06-22 18:20:32 +00:00
|
|
|
"modified-changed",
|
|
|
|
G_CALLBACK (modified_changed_cb),
|
2011-01-17 03:01:11 -08:00
|
|
|
doc);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
_moo_edit_set_file (doc, NULL, NULL);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
g_signal_connect_swapped (doc->priv->buffer, "line-mark-moved",
|
2006-11-25 15:03:17 -06:00
|
|
|
G_CALLBACK (_moo_edit_line_mark_moved),
|
2011-01-17 03:01:11 -08:00
|
|
|
doc);
|
|
|
|
g_signal_connect_swapped (doc->priv->buffer, "line-mark-deleted",
|
2006-11-25 15:03:17 -06:00
|
|
|
G_CALLBACK (_moo_edit_line_mark_deleted),
|
2011-01-17 03:01:11 -08:00
|
|
|
doc);
|
2010-12-08 01:11:51 -08:00
|
|
|
|
|
|
|
return object;
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_finalize (GObject *object)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
moo_edit_view_array_free (edit->priv->views);
|
|
|
|
g_object_unref (edit->priv->buffer);
|
2010-11-23 21:54:39 -08:00
|
|
|
moo_file_free (edit->priv->file);
|
2006-04-29 22:36:39 -05:00
|
|
|
g_free (edit->priv->filename);
|
2010-12-12 02:29:20 -08:00
|
|
|
g_free (edit->priv->norm_name);
|
2006-04-29 22:36:39 -05:00
|
|
|
g_free (edit->priv->display_filename);
|
|
|
|
g_free (edit->priv->display_basename);
|
|
|
|
g_free (edit->priv->encoding);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (moo_edit_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
void
|
|
|
|
_moo_edit_closed (MooEdit *doc)
|
2006-04-29 22:36:39 -05:00
|
|
|
{
|
2011-01-14 02:37:04 -08:00
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2011-01-18 01:16:25 -08:00
|
|
|
moo_assert (doc->priv->state == MOO_EDIT_STATE_NORMAL);
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
_moo_edit_remove_untitled (doc);
|
|
|
|
_moo_edit_instances = moo_edit_list_remove (_moo_edit_instances, doc);
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2011-01-19 01:46:13 -08:00
|
|
|
while (!moo_edit_view_array_is_empty (doc->priv->views))
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (doc->priv->views->elms[0]));
|
2006-04-26 23:04:41 -05:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (doc->config)
|
2006-04-29 22:36:39 -05:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
g_signal_handlers_disconnect_by_func (doc->config,
|
|
|
|
(gpointer) config_changed,
|
|
|
|
doc);
|
|
|
|
g_object_unref (doc->config);
|
|
|
|
doc->config = NULL;
|
2006-04-29 22:36:39 -05:00
|
|
|
}
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (doc->priv->apply_config_idle)
|
2006-06-30 00:58:35 -05:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
g_source_remove (doc->priv->apply_config_idle);
|
|
|
|
doc->priv->apply_config_idle = 0;
|
2006-06-30 00:58:35 -05:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (doc->priv->file_monitor_id)
|
2006-06-30 00:58:35 -05:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
_moo_edit_stop_file_watch (doc);
|
|
|
|
doc->priv->file_monitor_id = 0;
|
2006-06-30 00:58:35 -05:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (doc->priv->update_bookmarks_idle)
|
2006-04-30 01:02:19 -05:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
g_source_remove (doc->priv->update_bookmarks_idle);
|
|
|
|
doc->priv->update_bookmarks_idle = 0;
|
2006-04-30 01:02:19 -05:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
_moo_edit_delete_bookmarks (doc, TRUE);
|
2005-12-11 04:30:02 +00:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (doc->priv->actions)
|
2010-12-08 01:11:51 -08:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
g_object_unref (doc->priv->actions);
|
|
|
|
doc->priv->actions = NULL;
|
2010-12-08 01:11:51 -08:00
|
|
|
}
|
2010-12-18 23:58:18 -08:00
|
|
|
}
|
2006-04-20 03:57:05 -05:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
static void
|
|
|
|
moo_edit_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
_moo_edit_closed (MOO_EDIT (object));
|
2010-12-08 01:11:51 -08:00
|
|
|
G_OBJECT_CLASS (moo_edit_parent_class)->dispose (object);
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
void
|
2011-01-18 21:36:06 -08:00
|
|
|
_moo_edit_set_active_view (MooEdit *doc,
|
|
|
|
MooEditView *view)
|
2011-01-17 03:01:11 -08:00
|
|
|
{
|
2011-01-18 22:01:18 -08:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
|
|
|
|
2011-01-18 21:36:06 -08:00
|
|
|
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
|
2011-01-17 03:01:11 -08:00
|
|
|
|
2011-01-18 22:01:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (doc);
|
|
|
|
|
|
|
|
if (doc->priv->active_view != NULL && doc->priv->active_view != view)
|
|
|
|
{
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (doc->priv->active_view);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter, gtk_text_buffer_get_insert (buffer));
|
|
|
|
gtk_text_buffer_move_mark (buffer, mark, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doc->priv->dead_active_view ||
|
|
|
|
(doc->priv->active_view != NULL && doc->priv->active_view != view))
|
|
|
|
{
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextBuffer *buffer = moo_edit_get_buffer (doc);
|
|
|
|
GtkTextMark *mark = _moo_edit_view_get_fake_cursor_mark (view);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
|
|
|
|
gtk_text_buffer_place_cursor (buffer, &iter);
|
|
|
|
}
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
doc->priv->active_view = view;
|
2011-01-18 22:01:18 -08:00
|
|
|
doc->priv->dead_active_view = FALSE;
|
2011-01-17 03:01:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_edit_add_view (MooEdit *doc,
|
|
|
|
MooEditView *view)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
|
|
|
|
|
|
|
g_assert (moo_edit_view_array_find (doc->priv->views, view) < 0);
|
|
|
|
|
|
|
|
g_object_ref_sink (view);
|
|
|
|
moo_edit_view_array_append (doc->priv->views, view);
|
|
|
|
g_object_unref (view);
|
|
|
|
|
|
|
|
_moo_edit_view_apply_prefs (view);
|
|
|
|
_moo_edit_view_apply_config (view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_edit_remove_view (MooEdit *doc,
|
|
|
|
MooEditView *view)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_VIEW (view));
|
|
|
|
|
2011-01-17 23:39:23 -08:00
|
|
|
g_return_if_fail (moo_edit_view_array_find (doc->priv->views, view) >= 0);
|
2011-01-17 03:01:11 -08:00
|
|
|
|
|
|
|
if (view == doc->priv->active_view)
|
2011-01-18 22:01:18 -08:00
|
|
|
{
|
2011-01-17 03:01:11 -08:00
|
|
|
doc->priv->active_view = NULL;
|
2011-01-18 22:01:18 -08:00
|
|
|
doc->priv->dead_active_view = TRUE;
|
|
|
|
}
|
2011-01-17 03:01:11 -08:00
|
|
|
|
2011-01-17 23:39:23 -08:00
|
|
|
g_object_ref (view);
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
moo_edit_view_array_remove (doc->priv->views, view);
|
2011-01-17 23:39:23 -08:00
|
|
|
_moo_edit_view_unset_doc (view);
|
|
|
|
|
|
|
|
g_object_unref (view);
|
2011-01-17 03:01:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
MooActionCollection *
|
|
|
|
_moo_edit_get_actions (MooEdit *doc)
|
|
|
|
{
|
2011-01-14 02:37:04 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2010-12-18 23:58:18 -08:00
|
|
|
return doc->priv->actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
modified_changed_cb (GtkTextBuffer *buffer,
|
|
|
|
MooEdit *edit)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
2014-11-14 23:43:54 +01:00
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
moo_edit_save(edit, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moo_edit_set_modified (edit, gtk_text_buffer_get_modified (buffer));
|
|
|
|
}
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-01 22:44:03 -08:00
|
|
|
static void
|
|
|
|
modify_status (MooEdit *edit,
|
|
|
|
MooEditStatus status,
|
|
|
|
gboolean add)
|
|
|
|
{
|
|
|
|
if (add)
|
|
|
|
edit->priv->status = (MooEditStatus) (edit->priv->status | status);
|
|
|
|
else
|
|
|
|
edit->priv->status = (MooEditStatus) (edit->priv->status & ~status);
|
|
|
|
}
|
|
|
|
|
2010-12-20 23:02:34 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_set_modified:
|
|
|
|
**/
|
2005-09-09 09:54:58 +00:00
|
|
|
void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_set_modified (MooEdit *edit,
|
|
|
|
gboolean modified)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
gboolean buf_modified;
|
2005-09-06 16:21:05 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (edit);
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
buf_modified =
|
2005-09-06 16:21:05 +00:00
|
|
|
gtk_text_buffer_get_modified (buffer);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
if (buf_modified != modified)
|
|
|
|
{
|
2005-09-06 16:21:05 +00:00
|
|
|
g_signal_handler_block (buffer,
|
2005-06-22 18:20:32 +00:00
|
|
|
edit->priv->modified_changed_handler_id);
|
2005-09-06 16:21:05 +00:00
|
|
|
gtk_text_buffer_set_modified (buffer, modified);
|
|
|
|
g_signal_handler_unblock (buffer,
|
2005-06-22 18:20:32 +00:00
|
|
|
edit->priv->modified_changed_handler_id);
|
|
|
|
}
|
|
|
|
|
2011-01-21 03:12:18 -08:00
|
|
|
modify_status (edit, MOO_EDIT_STATUS_MODIFIED, modified);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2010-12-08 01:39:40 -08:00
|
|
|
_moo_edit_status_changed (edit);
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_set_clean:
|
|
|
|
**/
|
2005-09-09 09:54:58 +00:00
|
|
|
void
|
2010-12-08 01:39:40 -08:00
|
|
|
moo_edit_set_clean (MooEdit *edit,
|
|
|
|
gboolean clean)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
2011-01-21 03:12:18 -08:00
|
|
|
modify_status (edit, MOO_EDIT_STATUS_CLEAN, clean);
|
2010-12-08 01:39:40 -08:00
|
|
|
_moo_edit_status_changed (edit);
|
2005-06-22 18:20:32 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_clean:
|
|
|
|
**/
|
2005-11-07 06:56:33 +00:00
|
|
|
gboolean
|
|
|
|
moo_edit_get_clean (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
2011-01-21 03:12:18 -08:00
|
|
|
return (edit->priv->status & MOO_EDIT_STATUS_CLEAN) ? TRUE : FALSE;
|
2005-11-07 06:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
void
|
2010-12-08 01:39:40 -08:00
|
|
|
_moo_edit_status_changed (MooEdit *edit)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_signal_emit (edit, signals[DOC_STATUS_CHANGED], 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-04 02:30:32 -05:00
|
|
|
void
|
|
|
|
_moo_edit_set_status (MooEdit *edit,
|
|
|
|
MooEditStatus status)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
if (edit->priv->status != status)
|
|
|
|
{
|
|
|
|
edit->priv->status = status;
|
2010-12-08 01:39:40 -08:00
|
|
|
_moo_edit_status_changed (edit);
|
2006-05-04 02:30:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-09 00:51:40 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_is_empty:
|
|
|
|
*
|
|
|
|
* This function returns whether the document is "empty", i.e. is not modified,
|
|
|
|
* is untitled, and contains no text.
|
|
|
|
**/
|
2005-09-09 09:54:58 +00:00
|
|
|
gboolean
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_is_empty (MooEdit *edit)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
|
2011-02-05 22:17:19 -08:00
|
|
|
if (MOO_EDIT_IS_BUSY (edit) || moo_edit_is_modified (edit) || !MOO_EDIT_IS_UNTITLED (edit))
|
2005-06-22 18:20:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
gtk_text_buffer_get_bounds (moo_edit_get_buffer (edit), &start, &end);
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
return !gtk_text_iter_compare (&start, &end);
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_is_untitled:
|
|
|
|
**/
|
2007-07-07 07:34:41 -05:00
|
|
|
gboolean
|
|
|
|
moo_edit_is_untitled (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
return MOO_EDIT_IS_UNTITLED (edit);
|
|
|
|
}
|
|
|
|
|
2010-12-20 23:02:34 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_is_modified:
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
moo_edit_is_modified (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
2011-02-05 22:17:19 -08:00
|
|
|
return (moo_edit_get_status (edit) & MOO_EDIT_STATUS_MODIFIED) != 0;
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_status:
|
|
|
|
**/
|
2005-09-09 09:54:58 +00:00
|
|
|
MooEditStatus
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_get_status (MooEdit *edit)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
2010-02-01 22:44:03 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), (MooEditStatus) 0);
|
2005-06-22 18:20:32 +00:00
|
|
|
return edit->priv->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
2005-09-06 16:21:05 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-06-22 18:20:32 +00:00
|
|
|
case PROP_EDITOR:
|
2010-02-01 22:44:03 -08:00
|
|
|
edit->priv->editor = (MooEditor*) g_value_get_object (value);
|
2005-09-06 16:21:05 +00:00
|
|
|
break;
|
|
|
|
|
2005-12-11 04:30:02 +00:00
|
|
|
case PROP_ENABLE_BOOKMARKS:
|
|
|
|
moo_edit_set_enable_bookmarks (edit, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2007-11-29 19:53:33 -06:00
|
|
|
case PROP_ENCODING:
|
2009-12-13 16:16:39 -08:00
|
|
|
moo_edit_set_encoding (edit, g_value_get_string (value));
|
2007-11-29 19:53:33 -06:00
|
|
|
break;
|
|
|
|
|
2009-12-06 13:54:27 -08:00
|
|
|
case PROP_LINE_END_TYPE:
|
2010-02-01 22:44:03 -08:00
|
|
|
moo_edit_set_line_end_type (edit, (MooLineEndType) g_value_get_enum (value));
|
2009-12-06 13:54:27 -08:00
|
|
|
break;
|
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-09 09:40:10 +00:00
|
|
|
|
2005-09-09 09:54:58 +00:00
|
|
|
static void
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
2005-09-06 16:21:05 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-06-22 18:20:32 +00:00
|
|
|
case PROP_EDITOR:
|
|
|
|
g_value_set_object (value, edit->priv->editor);
|
|
|
|
break;
|
|
|
|
|
2005-12-11 04:30:02 +00:00
|
|
|
case PROP_ENABLE_BOOKMARKS:
|
|
|
|
g_value_set_boolean (value, edit->priv->enable_bookmarks);
|
|
|
|
break;
|
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
case PROP_HAS_COMMENTS:
|
|
|
|
g_value_set_boolean (value, _moo_edit_has_comments (edit, NULL, NULL));
|
|
|
|
break;
|
|
|
|
|
2007-11-29 19:53:33 -06:00
|
|
|
case PROP_ENCODING:
|
|
|
|
g_value_set_string (value, edit->priv->encoding);
|
|
|
|
break;
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
case PROP_LANG:
|
|
|
|
g_value_set_object (value, moo_edit_get_lang (edit));
|
|
|
|
break;
|
|
|
|
|
2009-12-06 13:54:27 -08:00
|
|
|
case PROP_LINE_END_TYPE:
|
2009-12-13 16:16:39 -08:00
|
|
|
g_value_set_enum (value, edit->priv->line_end_type);
|
2009-12-06 13:54:27 -08:00
|
|
|
break;
|
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_file:
|
2010-12-21 03:23:59 -08:00
|
|
|
*
|
|
|
|
* Returns: (transfer full)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2008-09-15 03:59:22 -05:00
|
|
|
GFile *
|
2010-11-23 21:54:39 -08:00
|
|
|
moo_edit_get_file (MooEdit *edit)
|
2008-09-15 03:59:22 -05:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->file ? g_file_dup (edit->priv->file) : NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_filename:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* Returns: (type filename)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2007-07-07 07:34:41 -05:00
|
|
|
char *
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_get_filename (MooEdit *edit)
|
2005-07-31 04:28:41 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
2007-07-07 07:34:41 -05:00
|
|
|
return g_strdup (edit->priv->filename);
|
2005-07-31 04:28:41 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 18:49:15 -07:00
|
|
|
char *
|
2010-12-12 02:29:20 -08:00
|
|
|
_moo_edit_get_normalized_name (MooEdit *edit)
|
2010-04-11 18:49:15 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
2010-12-12 02:29:20 -08:00
|
|
|
return g_strdup (edit->priv->norm_name);
|
2010-04-11 18:49:15 -07:00
|
|
|
}
|
|
|
|
|
2010-09-02 18:18:33 -07:00
|
|
|
char *
|
2010-12-12 02:29:20 -08:00
|
|
|
_moo_edit_get_utf8_filename (MooEdit *edit)
|
2010-09-02 18:18:33 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->filename ? g_strdup (edit->priv->display_filename) : NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_display_name:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* Returns: (type const-utf8)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2006-12-17 10:58:17 -06:00
|
|
|
const char *
|
2007-07-07 07:34:41 -05:00
|
|
|
moo_edit_get_display_name (MooEdit *edit)
|
2005-07-31 04:28:41 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->display_filename;
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_display_basename:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* Returns: (type const-utf8)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2006-12-17 10:58:17 -06:00
|
|
|
const char *
|
2005-09-09 09:40:10 +00:00
|
|
|
moo_edit_get_display_basename (MooEdit *edit)
|
2005-07-31 04:28:41 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->display_basename;
|
|
|
|
}
|
2005-09-02 23:27:25 +00:00
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_uri:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* Returns: (type utf8)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2006-12-17 10:58:17 -06:00
|
|
|
char *
|
2005-11-25 20:48:39 +00:00
|
|
|
moo_edit_get_uri (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
2008-09-15 03:59:22 -05:00
|
|
|
return edit->priv->file ? g_file_get_uri (edit->priv->file) : NULL;
|
2005-11-25 20:48:39 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_encoding:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* Returns: (type const-utf8)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2007-07-07 07:34:41 -05:00
|
|
|
const char *
|
|
|
|
moo_edit_get_encoding (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->encoding;
|
|
|
|
}
|
|
|
|
|
2010-12-12 02:29:20 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_set_encoding:
|
2011-01-01 17:14:23 -08:00
|
|
|
*
|
|
|
|
* @edit:
|
|
|
|
* @encoding: (type const-utf8)
|
2010-12-12 02:29:20 -08:00
|
|
|
**/
|
2007-11-26 00:13:17 -06:00
|
|
|
void
|
2009-12-13 16:16:39 -08:00
|
|
|
moo_edit_set_encoding (MooEdit *edit,
|
|
|
|
const char *encoding)
|
2007-11-26 00:13:17 -06:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_return_if_fail (encoding != NULL);
|
2007-11-29 19:53:33 -06:00
|
|
|
|
2011-01-14 01:12:19 -08:00
|
|
|
if (!moo_str_equal (encoding, edit->priv->encoding))
|
2007-11-29 19:53:33 -06:00
|
|
|
{
|
2007-12-19 14:02:42 -06:00
|
|
|
MOO_ASSIGN_STRING (edit->priv->encoding, encoding);
|
2007-11-29 19:53:33 -06:00
|
|
|
g_object_notify (G_OBJECT (edit), "encoding");
|
|
|
|
}
|
2007-11-26 00:13:17 -06:00
|
|
|
}
|
|
|
|
|
2005-11-25 20:48:39 +00:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_editor:
|
|
|
|
**/
|
|
|
|
MooEditor *
|
|
|
|
moo_edit_get_editor (MooEdit *doc)
|
2005-10-13 14:08:18 +00:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
|
|
|
return doc->priv->editor;
|
2005-10-13 14:08:18 +00:00
|
|
|
}
|
|
|
|
|
2011-01-18 01:16:25 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_tab:
|
|
|
|
**/
|
|
|
|
MooEditTab *
|
|
|
|
moo_edit_get_tab (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
|
|
|
return moo_edit_view_get_tab (moo_edit_get_view (doc));
|
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_view:
|
2014-03-20 10:36:27 -07:00
|
|
|
*
|
|
|
|
* Get the active view of this document.
|
2010-12-18 23:58:18 -08:00
|
|
|
**/
|
|
|
|
MooEditView *
|
|
|
|
moo_edit_get_view (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2011-01-17 03:01:11 -08:00
|
|
|
|
|
|
|
if (!doc->priv->active_view)
|
|
|
|
if (!moo_edit_view_array_is_empty (doc->priv->views))
|
|
|
|
doc->priv->active_view = doc->priv->views->elms[doc->priv->views->n_elms - 1];
|
|
|
|
|
|
|
|
return doc->priv->active_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* moo_edit_get_views:
|
2014-03-20 10:36:27 -07:00
|
|
|
*
|
|
|
|
* Get the list of views which belong to this document.
|
2011-01-17 03:01:11 -08:00
|
|
|
**/
|
|
|
|
MooEditViewArray *
|
|
|
|
moo_edit_get_views (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
|
|
|
return moo_edit_view_array_copy (doc->priv->views);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* moo_edit_get_n_views:
|
2014-03-20 10:36:27 -07:00
|
|
|
*
|
|
|
|
* Get the number of views which belong to this document.
|
2011-01-17 03:01:11 -08:00
|
|
|
**/
|
|
|
|
int
|
|
|
|
moo_edit_get_n_views (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), 0);
|
|
|
|
return moo_edit_view_array_get_size (doc->priv->views);
|
2010-12-18 23:58:18 -08:00
|
|
|
}
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_get_window:
|
|
|
|
**/
|
|
|
|
MooEditWindow *
|
|
|
|
moo_edit_get_window (MooEdit *doc)
|
2006-04-08 00:39:13 -05:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2011-01-17 03:01:11 -08:00
|
|
|
return moo_edit_view_get_window (moo_edit_get_view (doc));
|
2010-12-18 23:58:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* moo_edit_get_buffer:
|
|
|
|
**/
|
|
|
|
GtkTextBuffer *
|
|
|
|
moo_edit_get_buffer (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2011-01-17 03:01:11 -08:00
|
|
|
return doc->priv->buffer;
|
2006-04-08 00:39:13 -05:00
|
|
|
}
|
|
|
|
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2006-12-04 22:55:42 -06:00
|
|
|
typedef void (*SetVarFunc) (MooEdit *edit,
|
|
|
|
const char *name,
|
|
|
|
char *val);
|
2005-11-24 17:37:28 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
parse_mode_string (MooEdit *edit,
|
|
|
|
char *string,
|
|
|
|
const char *var_val_separator,
|
|
|
|
SetVarFunc func)
|
|
|
|
{
|
|
|
|
char **vars, **p;
|
|
|
|
|
|
|
|
vars = NULL;
|
|
|
|
|
|
|
|
g_strstrip (string);
|
|
|
|
|
|
|
|
vars = g_strsplit (string, ";", 0);
|
|
|
|
|
|
|
|
if (!vars)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (p = vars; *p != NULL; p++)
|
|
|
|
{
|
|
|
|
char *sep, *var, *value;
|
|
|
|
|
|
|
|
g_strstrip (*p);
|
|
|
|
sep = strstr (*p, var_val_separator);
|
|
|
|
|
|
|
|
if (!sep || sep == *p || !sep[1])
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
var = g_strndup (*p, sep - *p);
|
|
|
|
g_strstrip (var);
|
|
|
|
|
|
|
|
if (!var[0])
|
|
|
|
{
|
|
|
|
g_free (var);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = sep + 1;
|
|
|
|
g_strstrip (value);
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
g_free (var);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
func (edit, var, value);
|
|
|
|
|
|
|
|
g_free (var);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_strfreev (vars);
|
|
|
|
}
|
2005-09-06 16:21:05 +00:00
|
|
|
|
|
|
|
|
2005-10-13 14:08:18 +00:00
|
|
|
static void
|
2005-12-09 00:19:41 +00:00
|
|
|
set_kate_var (MooEdit *edit,
|
|
|
|
const char *name,
|
|
|
|
const char *val)
|
2005-10-13 14:08:18 +00:00
|
|
|
{
|
2005-12-09 00:19:41 +00:00
|
|
|
if (!g_ascii_strcasecmp (name, "space-indent"))
|
|
|
|
{
|
|
|
|
gboolean spaces = FALSE;
|
|
|
|
|
|
|
|
if (moo_edit_config_parse_bool (val, &spaces))
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "indent-use-tabs",
|
|
|
|
spaces ? "false" : "true",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-12-09 00:19:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, name, val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-12-09 00:19:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_kate_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
|
|
|
{
|
|
|
|
parse_mode_string (edit, string, " ", (SetVarFunc) set_kate_var);
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2005-11-24 17:37:28 +00:00
|
|
|
|
|
|
|
static void
|
2006-12-04 22:55:42 -06:00
|
|
|
set_emacs_var (MooEdit *edit,
|
|
|
|
const char *name,
|
|
|
|
char *val)
|
2005-11-24 17:37:28 +00:00
|
|
|
{
|
|
|
|
if (!g_ascii_strcasecmp (name, "mode"))
|
|
|
|
{
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "lang", val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 17:37:28 +00:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "tab-width"))
|
|
|
|
{
|
2006-06-17 04:08:25 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "tab-width", val,
|
2006-05-04 01:40:54 -05:00
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 17:37:28 +00:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "c-basic-offset"))
|
|
|
|
{
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "indent-width", val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 17:37:28 +00:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "indent-tabs-mode"))
|
|
|
|
{
|
|
|
|
if (!g_ascii_strcasecmp (val, "nil"))
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "indent-use-tabs", "false",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 17:37:28 +00:00
|
|
|
else
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse_one (edit->config, "indent-use-tabs", "true",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 17:37:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
static void
|
2005-11-24 17:37:28 +00:00
|
|
|
parse_emacs_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
2005-11-24 14:14:48 +00:00
|
|
|
{
|
2006-12-04 22:55:42 -06:00
|
|
|
MooLangMgr *mgr;
|
|
|
|
|
|
|
|
g_strstrip (string);
|
|
|
|
|
2008-08-26 13:51:05 -05:00
|
|
|
mgr = moo_lang_mgr_default ();
|
2006-12-04 22:55:42 -06:00
|
|
|
|
|
|
|
if (_moo_lang_mgr_find_lang (mgr, string))
|
|
|
|
set_emacs_var (edit, "mode", string);
|
|
|
|
else
|
|
|
|
parse_mode_string (edit, string, ":", set_emacs_var);
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 17:37:28 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
static void
|
2005-11-24 17:37:28 +00:00
|
|
|
parse_moo_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
2005-11-24 14:14:48 +00:00
|
|
|
{
|
2006-05-04 01:40:54 -05:00
|
|
|
moo_edit_config_parse (edit->config, string, MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
#define KATE_MODE_STRING "kate:"
|
|
|
|
#define EMACS_MODE_STRING "-*-"
|
2005-11-24 17:37:28 +00:00
|
|
|
#define MOO_MODE_STRING "-%-"
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
static void
|
|
|
|
try_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
|
|
|
{
|
|
|
|
char *start, *end;
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
if ((start = strstr (string, KATE_MODE_STRING)))
|
2005-09-06 16:21:05 +00:00
|
|
|
{
|
2005-11-24 14:14:48 +00:00
|
|
|
start += strlen (KATE_MODE_STRING);
|
2007-01-11 20:28:22 -06:00
|
|
|
parse_kate_mode_string (edit, start);
|
|
|
|
return;
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
if ((start = strstr (string, EMACS_MODE_STRING)))
|
|
|
|
{
|
|
|
|
start += strlen (EMACS_MODE_STRING);
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2005-11-24 17:37:28 +00:00
|
|
|
if ((end = strstr (start, EMACS_MODE_STRING)) && end > start)
|
2005-09-06 16:21:05 +00:00
|
|
|
{
|
2005-11-24 14:14:48 +00:00
|
|
|
end[0] = 0;
|
2007-01-11 20:28:22 -06:00
|
|
|
parse_emacs_mode_string (edit, start);
|
|
|
|
return;
|
2005-09-06 16:21:05 +00:00
|
|
|
}
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-09-06 16:21:05 +00:00
|
|
|
|
2005-11-24 14:14:48 +00:00
|
|
|
if ((start = strstr (string, MOO_MODE_STRING)))
|
|
|
|
{
|
|
|
|
start += strlen (MOO_MODE_STRING);
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2005-11-24 17:37:28 +00:00
|
|
|
if ((end = strstr (start, MOO_MODE_STRING)) && end > start)
|
2005-09-06 16:21:05 +00:00
|
|
|
{
|
2005-11-24 14:14:48 +00:00
|
|
|
end[0] = 0;
|
2007-01-11 20:28:22 -06:00
|
|
|
parse_moo_mode_string (edit, start);
|
|
|
|
return;
|
2005-09-06 16:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-13 14:08:18 +00:00
|
|
|
static void
|
2010-12-19 02:26:03 -08:00
|
|
|
update_config_from_mode_lines (MooEdit *edit)
|
2005-10-13 14:08:18 +00:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
GtkTextBuffer *buffer = moo_edit_get_buffer (edit);
|
2005-10-13 14:08:18 +00:00
|
|
|
GtkTextIter start, end;
|
2006-09-06 12:25:22 -05:00
|
|
|
char *first = NULL, *second = NULL, *last = NULL;
|
2005-10-13 14:08:18 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &start);
|
2006-09-06 12:25:22 -05:00
|
|
|
|
|
|
|
if (!gtk_text_iter_ends_line (&start))
|
|
|
|
{
|
|
|
|
end = start;
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
first = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gtk_text_iter_forward_line (&start))
|
|
|
|
{
|
|
|
|
if (!gtk_text_iter_ends_line (&start))
|
|
|
|
{
|
|
|
|
end = start;
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
second = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
|
|
|
|
}
|
|
|
|
}
|
2005-10-13 14:08:18 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
2005-11-03 06:47:53 +00:00
|
|
|
|
|
|
|
if (gtk_text_iter_starts_line (&end))
|
|
|
|
{
|
|
|
|
gtk_text_iter_backward_line (&end);
|
|
|
|
start = end;
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = end;
|
|
|
|
gtk_text_iter_set_line_offset (&start, 0);
|
|
|
|
}
|
|
|
|
|
2006-09-06 12:25:22 -05:00
|
|
|
if (gtk_text_iter_get_line (&start) != 1 &&
|
|
|
|
gtk_text_iter_get_line (&start) != 2)
|
|
|
|
last = gtk_text_buffer_get_slice (buffer, &start, &end, TRUE);
|
2005-11-24 14:14:48 +00:00
|
|
|
|
2006-09-06 12:25:22 -05:00
|
|
|
if (first)
|
|
|
|
try_mode_string (edit, first);
|
|
|
|
if (second)
|
|
|
|
try_mode_string (edit, second);
|
|
|
|
if (last)
|
|
|
|
try_mode_string (edit, last);
|
2005-11-24 14:14:48 +00:00
|
|
|
|
|
|
|
g_free (first);
|
2006-09-06 12:25:22 -05:00
|
|
|
g_free (second);
|
2005-11-24 14:14:48 +00:00
|
|
|
g_free (last);
|
2005-10-13 14:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
static MooLang *
|
|
|
|
moo_edit_get_lang (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2010-12-19 02:26:03 -08:00
|
|
|
moo_assert (!doc->priv->in_recheck_config);
|
2011-01-17 03:01:11 -08:00
|
|
|
return moo_text_buffer_get_lang (MOO_TEXT_BUFFER (doc->priv->buffer));
|
2010-12-18 23:58:18 -08:00
|
|
|
}
|
|
|
|
|
2010-12-09 00:51:40 -08:00
|
|
|
/**
|
2010-12-10 01:06:58 -08:00
|
|
|
* moo_edit_get_lang_id:
|
2010-12-09 00:51:40 -08:00
|
|
|
*
|
2011-01-01 17:14:23 -08:00
|
|
|
* Returns: (type utf8): id of language currently used in the document. If no language
|
2010-12-10 01:06:58 -08:00
|
|
|
* is used, then string "none" is returned.
|
2010-12-09 00:51:40 -08:00
|
|
|
*/
|
2010-12-19 02:26:03 -08:00
|
|
|
char *
|
2010-12-10 01:06:58 -08:00
|
|
|
moo_edit_get_lang_id (MooEdit *doc)
|
2010-11-23 21:54:39 -08:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
MooLang *lang = NULL;
|
2010-11-23 21:54:39 -08:00
|
|
|
|
2011-01-14 02:37:04 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
2006-04-26 23:04:41 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
if (!doc->priv->in_recheck_config)
|
2006-05-23 12:59:23 -05:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
lang = moo_edit_get_lang (doc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *lang_id = moo_edit_config_get_string (doc->config, "lang");
|
|
|
|
lang = lang_id ? _moo_lang_mgr_find_lang (moo_lang_mgr_default (), lang_id) : NULL;
|
2006-05-23 12:59:23 -05:00
|
|
|
}
|
2006-04-26 23:04:41 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
return g_strdup (_moo_lang_id (lang));
|
2006-04-26 23:04:41 -05:00
|
|
|
}
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static gboolean
|
|
|
|
moo_edit_apply_config_all_in_idle (void)
|
2006-06-17 02:38:23 -05:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
MooEditList *l;
|
2006-06-17 02:38:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
moo_edit_apply_config_all_idle = 0;
|
|
|
|
|
|
|
|
for (l = _moo_edit_instances; l != NULL; l = l->next)
|
|
|
|
moo_edit_recheck_config (l->data);
|
2006-04-26 23:04:41 -05:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
void
|
|
|
|
_moo_edit_queue_recheck_config_all (void)
|
2006-04-26 23:04:41 -05:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
if (!moo_edit_apply_config_all_idle)
|
|
|
|
moo_edit_apply_config_all_idle =
|
2011-01-13 00:11:32 -08:00
|
|
|
gdk_threads_add_idle ((GSourceFunc) moo_edit_apply_config_all_in_idle, NULL);
|
2006-04-26 23:04:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-08 08:53:46 +00:00
|
|
|
static void
|
2010-12-19 02:26:03 -08:00
|
|
|
update_lang_config_from_lang_globs (MooEdit *doc)
|
2005-12-08 08:53:46 +00:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
const char *lang_id = NULL;
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
if (doc->priv->file)
|
|
|
|
{
|
|
|
|
MooLangMgr *mgr = moo_lang_mgr_default ();
|
|
|
|
MooLang *lang = moo_lang_mgr_get_lang_for_file (mgr, doc->priv->file);
|
|
|
|
lang_id = lang ? _moo_lang_id (lang) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_FILENAME,
|
|
|
|
"lang", lang_id, (char*) NULL);
|
|
|
|
}
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2006-12-31 04:53:45 -06:00
|
|
|
static void
|
2010-12-19 02:26:03 -08:00
|
|
|
update_config_from_filter_settings (MooEdit *doc)
|
2006-07-27 14:39:53 -05:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
char *filter_config = NULL;
|
2006-07-27 14:39:53 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
filter_config = _moo_edit_filter_settings_get_for_doc (doc);
|
2006-07-27 14:39:53 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
if (filter_config)
|
|
|
|
moo_edit_config_parse (doc->config, filter_config,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILENAME);
|
2006-05-04 01:40:54 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
g_free (filter_config);
|
2006-05-04 01:40:54 -05:00
|
|
|
}
|
|
|
|
|
2005-11-04 01:35:22 +00:00
|
|
|
static void
|
2010-12-19 02:26:03 -08:00
|
|
|
update_config_from_lang (MooEdit *doc)
|
2005-10-13 14:08:18 +00:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
char *lang_id = moo_edit_get_lang_id (doc);
|
|
|
|
_moo_lang_mgr_update_config (moo_lang_mgr_default (), doc->config, lang_id);
|
|
|
|
g_free (lang_id);
|
|
|
|
}
|
2006-05-23 12:59:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static void
|
|
|
|
moo_edit_apply_config (MooEdit *doc)
|
|
|
|
{
|
2011-01-17 03:01:11 -08:00
|
|
|
guint i;
|
2010-12-19 02:26:03 -08:00
|
|
|
const char *lang_id = moo_edit_config_get_string (doc->config, "lang");
|
|
|
|
MooLangMgr *mgr = moo_lang_mgr_default ();
|
|
|
|
MooLang *lang = lang_id ? _moo_lang_mgr_find_lang (mgr, lang_id) : NULL;
|
2011-01-17 03:01:11 -08:00
|
|
|
|
|
|
|
moo_text_buffer_set_lang (MOO_TEXT_BUFFER (doc->priv->buffer), lang);
|
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
g_object_notify (G_OBJECT (doc), "has-comments");
|
|
|
|
g_object_notify (G_OBJECT (doc), "lang");
|
2011-01-17 03:01:11 -08:00
|
|
|
|
|
|
|
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
|
|
|
_moo_edit_view_apply_config (doc->priv->views->elms[i]);
|
2010-12-19 02:26:03 -08:00
|
|
|
}
|
2005-11-24 17:37:28 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
static void
|
|
|
|
moo_edit_recheck_config (MooEdit *doc)
|
|
|
|
{
|
2011-01-14 02:37:04 -08:00
|
|
|
g_return_if_fail (!doc->priv->in_recheck_config);
|
2005-11-24 14:14:48 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
if (doc->priv->apply_config_idle)
|
2005-11-24 14:14:48 +00:00
|
|
|
{
|
2010-12-19 02:26:03 -08:00
|
|
|
g_source_remove (doc->priv->apply_config_idle);
|
|
|
|
doc->priv->apply_config_idle = 0;
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-11-04 01:35:22 +00:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
moo_edit_freeze_notify (doc);
|
2010-12-19 02:26:03 -08:00
|
|
|
doc->priv->in_recheck_config = TRUE;
|
2006-07-27 14:39:53 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// this resets settings from global config
|
|
|
|
moo_edit_config_unset_by_source (doc->config, MOO_EDIT_CONFIG_SOURCE_FILE);
|
2010-09-21 23:41:52 -07:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// First global settings
|
2011-01-17 03:01:11 -08:00
|
|
|
moo_edit_apply_prefs (doc);
|
2005-12-08 08:53:46 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// then language from globs
|
|
|
|
update_lang_config_from_lang_globs (doc);
|
2005-11-04 01:35:22 +00:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// then settings from mode lines, these may change lang
|
|
|
|
update_config_from_mode_lines (doc);
|
2006-05-23 12:59:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// then filter settings, these also may change lang
|
|
|
|
update_config_from_filter_settings (doc);
|
2006-05-23 12:59:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// update config for lang
|
|
|
|
update_config_from_lang (doc);
|
2006-05-23 12:59:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
// finally apply config
|
|
|
|
moo_edit_apply_config (doc);
|
2006-05-23 12:59:23 -05:00
|
|
|
|
2010-12-19 02:26:03 -08:00
|
|
|
doc->priv->in_recheck_config = FALSE;
|
2011-01-17 03:01:11 -08:00
|
|
|
moo_edit_thaw_notify (doc);
|
2010-12-19 02:26:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
moo_edit_recheck_config_in_idle (MooEdit *edit)
|
|
|
|
{
|
|
|
|
edit->priv->apply_config_idle = 0;
|
|
|
|
moo_edit_recheck_config (edit);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_edit_queue_recheck_config (MooEdit *doc)
|
|
|
|
{
|
2011-01-14 02:37:04 -08:00
|
|
|
g_return_if_fail (!doc->priv->in_recheck_config);
|
2010-12-19 02:26:03 -08:00
|
|
|
if (!doc->priv->apply_config_idle)
|
|
|
|
doc->priv->apply_config_idle =
|
2011-01-13 00:11:32 -08:00
|
|
|
gdk_threads_add_idle_full (G_PRIORITY_HIGH,
|
|
|
|
(GSourceFunc) moo_edit_recheck_config_in_idle,
|
|
|
|
doc, NULL);
|
2010-12-19 02:26:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
config_changed (MooEdit *doc)
|
|
|
|
{
|
|
|
|
if (!doc->priv->in_recheck_config)
|
|
|
|
_moo_edit_queue_recheck_config (doc);
|
2005-11-04 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
static void
|
|
|
|
moo_edit_apply_prefs (MooEdit *edit)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
moo_edit_freeze_notify (edit);
|
|
|
|
|
|
|
|
for (i = 0; i < edit->priv->views->n_elms; ++i)
|
|
|
|
_moo_edit_view_apply_prefs (edit->priv->views->elms[i]);
|
|
|
|
|
|
|
|
moo_edit_thaw_notify (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_freeze_notify (MooEdit *doc)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (doc));
|
|
|
|
|
|
|
|
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
|
|
|
g_object_freeze_notify (G_OBJECT (doc->priv->views->elms[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_thaw_notify (MooEdit *doc)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
|
|
|
|
for (i = 0; i < doc->priv->views->n_elms; ++i)
|
|
|
|
g_object_thaw_notify (G_OBJECT (doc->priv->views->elms[i]));
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-09 00:51:40 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_reload:
|
|
|
|
*
|
|
|
|
* @edit:
|
2010-12-20 23:02:34 -08:00
|
|
|
* @info: (allow-none) (default NULL):
|
|
|
|
* @error:
|
2010-12-09 00:51:40 -08:00
|
|
|
*
|
|
|
|
* Reload document from disk
|
|
|
|
*
|
|
|
|
* Returns: whether document was successfully reloaded
|
|
|
|
**/
|
|
|
|
gboolean
|
2011-01-10 02:31:07 -08:00
|
|
|
moo_edit_reload (MooEdit *doc,
|
|
|
|
MooReloadInfo *info,
|
|
|
|
GError **error)
|
2010-09-04 04:25:07 -07:00
|
|
|
{
|
2010-12-12 02:29:20 -08:00
|
|
|
moo_return_error_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
return moo_editor_reload (doc->priv->editor, doc, info, error);
|
2010-09-04 04:25:07 -07:00
|
|
|
}
|
|
|
|
|
2010-12-09 00:51:40 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_close:
|
|
|
|
*
|
|
|
|
* Returns: whether document was closed
|
|
|
|
**/
|
2005-11-24 14:14:48 +00:00
|
|
|
gboolean
|
2011-01-21 03:12:18 -08:00
|
|
|
moo_edit_close (MooEdit *edit)
|
2005-11-04 01:35:22 +00:00
|
|
|
{
|
2005-11-24 14:14:48 +00:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
2011-01-21 03:12:18 -08:00
|
|
|
return moo_editor_close_doc (edit->priv->editor, edit);
|
2005-12-04 20:13:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 03:12:18 -08:00
|
|
|
static MooSaveResponse
|
2010-12-19 03:29:16 -08:00
|
|
|
moo_edit_before_save (G_GNUC_UNUSED MooEdit *doc,
|
|
|
|
G_GNUC_UNUSED GFile *file)
|
|
|
|
{
|
2011-01-21 03:12:18 -08:00
|
|
|
return MOO_SAVE_RESPONSE_CONTINUE;
|
2010-12-19 03:29:16 -08:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_save:
|
|
|
|
**/
|
2005-12-04 20:13:58 +00:00
|
|
|
gboolean
|
2010-12-12 02:29:20 -08:00
|
|
|
moo_edit_save (MooEdit *doc,
|
2005-12-04 20:13:58 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2010-12-12 02:29:20 -08:00
|
|
|
moo_return_error_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
return moo_editor_save (doc->priv->editor, doc, error);
|
2005-11-04 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_save_as:
|
2011-05-17 01:49:37 -07:00
|
|
|
*
|
|
|
|
* @doc:
|
|
|
|
* @info: (allow-none):
|
|
|
|
* @error:
|
|
|
|
*
|
|
|
|
* Save document with new filename and/or encoding. If @info is
|
|
|
|
* missing or %NULL then the user is asked for a new filename first.
|
2010-12-18 23:58:18 -08:00
|
|
|
**/
|
2005-11-24 14:14:48 +00:00
|
|
|
gboolean
|
2011-01-10 02:31:07 -08:00
|
|
|
moo_edit_save_as (MooEdit *doc,
|
|
|
|
MooSaveInfo *info,
|
|
|
|
GError **error)
|
2005-11-04 01:35:22 +00:00
|
|
|
{
|
2010-12-12 02:29:20 -08:00
|
|
|
moo_return_error_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
return moo_editor_save_as (doc->priv->editor, doc, info, error);
|
2005-11-04 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
/**
|
|
|
|
* moo_edit_save_copy:
|
|
|
|
**/
|
2005-11-24 14:14:48 +00:00
|
|
|
gboolean
|
2011-01-10 02:31:07 -08:00
|
|
|
moo_edit_save_copy (MooEdit *doc,
|
|
|
|
MooSaveInfo *info,
|
|
|
|
GError **error)
|
2005-11-04 01:35:22 +00:00
|
|
|
{
|
2010-12-12 02:29:20 -08:00
|
|
|
moo_return_error_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
return moo_editor_save_copy (doc->priv->editor, doc, info, error);
|
2005-11-24 14:14:48 +00:00
|
|
|
}
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2005-11-04 01:35:22 +00:00
|
|
|
|
2011-01-17 03:01:11 -08:00
|
|
|
gboolean
|
|
|
|
_moo_edit_is_busy (MooEdit *doc)
|
2011-01-18 01:16:25 -08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
|
|
|
|
return _moo_edit_get_state (doc) != MOO_EDIT_STATE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MooEditState
|
|
|
|
_moo_edit_get_state (MooEdit *doc)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), MOO_EDIT_STATE_NORMAL);
|
|
|
|
return doc->priv->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_edit_set_progress_text (MooEdit *doc,
|
|
|
|
const char *text)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (doc->priv->state != MOO_EDIT_STATE_NORMAL);
|
|
|
|
g_return_if_fail (doc->priv->progress != NULL);
|
|
|
|
_moo_edit_progress_set_text (doc->priv->progress, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_moo_edit_set_state (MooEdit *doc,
|
|
|
|
MooEditState state,
|
|
|
|
const char *text,
|
|
|
|
GDestroyNotify cancel,
|
|
|
|
gpointer data)
|
2011-01-17 03:01:11 -08:00
|
|
|
{
|
|
|
|
guint i;
|
2011-01-18 01:16:25 -08:00
|
|
|
MooEditTab *tab;
|
2011-01-17 03:01:11 -08:00
|
|
|
|
2011-01-18 01:16:25 -08:00
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
g_return_if_fail (state == MOO_EDIT_STATE_NORMAL ||
|
|
|
|
doc->priv->state == MOO_EDIT_STATE_NORMAL);
|
|
|
|
|
|
|
|
if (doc->priv->progress)
|
|
|
|
_moo_edit_progress_set_cancel_func (doc->priv->progress, cancel, data);
|
|
|
|
|
|
|
|
if (state == doc->priv->state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
doc->priv->state = state;
|
2011-01-17 03:01:11 -08:00
|
|
|
|
|
|
|
for (i = 0; i < moo_edit_view_array_get_size (doc->priv->views); ++i)
|
2011-01-18 01:16:25 -08:00
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (doc->priv->views->elms[i]), !state);
|
2011-01-17 03:01:11 -08:00
|
|
|
|
2011-01-18 01:16:25 -08:00
|
|
|
tab = moo_edit_get_tab (doc);
|
|
|
|
|
|
|
|
if (!tab)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
{
|
|
|
|
_moo_edit_tab_destroy_progress (tab);
|
|
|
|
g_object_unref (doc->priv->progress);
|
|
|
|
doc->priv->progress = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doc->priv->progress = _moo_edit_tab_create_progress (tab);
|
|
|
|
_moo_edit_progress_start (doc->priv->progress, text, cancel, data);
|
|
|
|
g_object_ref (doc->priv->progress);
|
|
|
|
}
|
2011-01-17 03:01:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-16 16:51:31 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Comment/uncomment
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: all this stuff, it's pretty lame */
|
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
gboolean
|
|
|
|
_moo_edit_has_comments (MooEdit *edit,
|
|
|
|
gboolean *single_line,
|
|
|
|
gboolean *multi_line)
|
2005-12-16 16:51:31 +00:00
|
|
|
{
|
|
|
|
MooLang *lang;
|
2006-04-29 22:54:03 -05:00
|
|
|
gboolean single, multi;
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
lang = moo_edit_get_lang (edit);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
if (!lang)
|
|
|
|
return FALSE;
|
|
|
|
|
2006-08-26 04:46:29 -05:00
|
|
|
single = _moo_lang_get_line_comment (lang) != NULL;
|
|
|
|
multi = _moo_lang_get_block_comment_start (lang) && _moo_lang_get_block_comment_end (lang);
|
2006-04-29 22:54:03 -05:00
|
|
|
|
|
|
|
if (single_line)
|
|
|
|
*single_line = single;
|
|
|
|
if (multi_line)
|
|
|
|
*multi_line = multi;
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
return single || multi;
|
2005-12-16 16:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_comment (GtkTextBuffer *buffer,
|
|
|
|
const char *comment_string,
|
|
|
|
GtkTextIter *start,
|
|
|
|
GtkTextIter *end)
|
|
|
|
{
|
|
|
|
int first, last, i;
|
|
|
|
GtkTextIter iter;
|
|
|
|
char *comment_and_space;
|
|
|
|
|
|
|
|
g_return_if_fail (comment_string && comment_string[0]);
|
|
|
|
|
|
|
|
first = gtk_text_iter_get_line (start);
|
|
|
|
last = gtk_text_iter_get_line (end);
|
|
|
|
|
|
|
|
if (!gtk_text_iter_equal (start, end) && gtk_text_iter_starts_line (end))
|
|
|
|
last -= 1;
|
|
|
|
|
|
|
|
comment_and_space = g_strdup_printf ("%s ", comment_string);
|
|
|
|
|
|
|
|
for (i = first; i <= last; ++i)
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_iter_at_line (buffer, &iter, i);
|
|
|
|
|
|
|
|
if (gtk_text_iter_ends_line (&iter))
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, comment_string, -1);
|
|
|
|
else
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, comment_and_space, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (comment_and_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_uncomment (GtkTextBuffer *buffer,
|
|
|
|
const char *comment_string,
|
|
|
|
GtkTextIter *start,
|
|
|
|
GtkTextIter *end)
|
|
|
|
{
|
|
|
|
int first, last, i;
|
|
|
|
guint chars;
|
|
|
|
|
|
|
|
g_return_if_fail (comment_string && comment_string[0]);
|
|
|
|
|
|
|
|
first = gtk_text_iter_get_line (start);
|
|
|
|
last = gtk_text_iter_get_line (end);
|
|
|
|
|
|
|
|
if (!gtk_text_iter_equal (start, end) && gtk_text_iter_starts_line (end))
|
|
|
|
last -= 1;
|
|
|
|
|
|
|
|
chars = g_utf8_strlen (comment_string, -1);
|
|
|
|
|
|
|
|
for (i = first; i <= last; ++i)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_line (buffer, start, i);
|
|
|
|
*end = *start;
|
|
|
|
gtk_text_iter_forward_chars (end, chars);
|
|
|
|
text = gtk_text_iter_get_slice (start, end);
|
|
|
|
|
|
|
|
if (!strcmp (comment_string, text))
|
|
|
|
{
|
|
|
|
if (gtk_text_iter_get_char (end) == ' ')
|
|
|
|
gtk_text_iter_forward_char (end);
|
|
|
|
gtk_text_buffer_delete (buffer, start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
iter_to_line_end (GtkTextIter *iter)
|
|
|
|
{
|
|
|
|
if (!gtk_text_iter_ends_line (iter))
|
|
|
|
gtk_text_iter_forward_to_line_end (iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
block_comment (GtkTextBuffer *buffer,
|
|
|
|
const char *comment_start,
|
|
|
|
const char *comment_end,
|
|
|
|
GtkTextIter *start,
|
|
|
|
GtkTextIter *end)
|
|
|
|
{
|
|
|
|
GtkTextMark *end_mark;
|
|
|
|
|
|
|
|
g_return_if_fail (comment_start && comment_start[0]);
|
|
|
|
g_return_if_fail (comment_end && comment_end[0]);
|
|
|
|
|
|
|
|
if (gtk_text_iter_equal (start, end))
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (start, 0);
|
|
|
|
iter_to_line_end (end);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gtk_text_iter_starts_line (end))
|
|
|
|
{
|
|
|
|
gtk_text_iter_backward_line (end);
|
|
|
|
iter_to_line_end (end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end_mark = gtk_text_buffer_create_mark (buffer, NULL, end, FALSE);
|
|
|
|
gtk_text_buffer_insert (buffer, start, comment_start, -1);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, start, end_mark);
|
|
|
|
gtk_text_buffer_insert (buffer, start, comment_end, -1);
|
|
|
|
gtk_text_buffer_delete_mark (buffer, end_mark);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
block_uncomment (GtkTextBuffer *buffer,
|
|
|
|
const char *comment_start,
|
|
|
|
const char *comment_end,
|
|
|
|
GtkTextIter *start,
|
|
|
|
GtkTextIter *end)
|
|
|
|
{
|
|
|
|
GtkTextIter start1, start2, end1, end2;
|
|
|
|
GtkTextMark *mark1, *mark2;
|
|
|
|
GtkTextIter limit;
|
|
|
|
gboolean found;
|
|
|
|
|
|
|
|
g_return_if_fail (comment_start && comment_start[0]);
|
|
|
|
g_return_if_fail (comment_end && comment_end[0]);
|
|
|
|
|
|
|
|
if (!gtk_text_iter_equal (start, end) && gtk_text_iter_starts_line (end))
|
|
|
|
{
|
|
|
|
gtk_text_iter_backward_line (end);
|
|
|
|
iter_to_line_end (end);
|
|
|
|
}
|
|
|
|
|
|
|
|
limit = *end;
|
2010-02-01 22:44:03 -08:00
|
|
|
found = moo_text_search_forward (start, comment_start, (MooTextSearchFlags) 0,
|
2005-12-16 16:51:31 +00:00
|
|
|
&start1, &start2,
|
|
|
|
&limit);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
gtk_text_iter_set_line_offset (&limit, 0);
|
2010-02-01 22:44:03 -08:00
|
|
|
found = gtk_text_iter_backward_search (start, comment_start, (GtkTextSearchFlags) 0,
|
2005-12-16 16:51:31 +00:00
|
|
|
&start1, &start2,
|
|
|
|
&limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
limit = start2;
|
2010-02-01 22:44:03 -08:00
|
|
|
found = gtk_text_iter_backward_search (end, comment_end, (GtkTextSearchFlags) 0,
|
2005-12-16 16:51:31 +00:00
|
|
|
&end1, &end2, &limit);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
limit = *end;
|
|
|
|
iter_to_line_end (&limit);
|
2010-02-01 22:44:03 -08:00
|
|
|
found = moo_text_search_forward (end, comment_end, (MooTextSearchFlags) 0,
|
2005-12-16 16:51:31 +00:00
|
|
|
&end1, &end2, &limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_assert (gtk_text_iter_compare (&start2, &end1) < 0);
|
|
|
|
|
|
|
|
mark1 = gtk_text_buffer_create_mark (buffer, NULL, &end1, FALSE);
|
|
|
|
mark2 = gtk_text_buffer_create_mark (buffer, NULL, &end2, FALSE);
|
|
|
|
gtk_text_buffer_delete (buffer, &start1, &start2);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &end1, mark1);
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &end2, mark2);
|
|
|
|
gtk_text_buffer_delete (buffer, &end1, &end2);
|
|
|
|
gtk_text_buffer_delete_mark (buffer, mark1);
|
|
|
|
gtk_text_buffer_delete_mark (buffer, mark2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-17 01:53:09 -07:00
|
|
|
/**
|
|
|
|
* moo_edit_comment_selection:
|
|
|
|
**/
|
2005-12-16 16:51:31 +00:00
|
|
|
void
|
2011-05-17 01:53:09 -07:00
|
|
|
moo_edit_comment_selection (MooEdit *edit)
|
2005-12-16 16:51:31 +00:00
|
|
|
{
|
|
|
|
MooLang *lang;
|
|
|
|
GtkTextIter start, end;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
gboolean has_selection, single_line, multi_line;
|
|
|
|
gboolean adjust_selection = FALSE, move_insert = FALSE;
|
2005-12-18 00:05:21 +00:00
|
|
|
int sel_start_line = 0, sel_start_offset = 0;
|
2005-12-16 16:51:31 +00:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
lang = moo_edit_get_lang (edit);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
if (!_moo_edit_has_comments (edit, &single_line, &multi_line))
|
2005-12-16 16:51:31 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (edit);
|
2005-12-16 16:51:31 +00:00
|
|
|
has_selection = gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
|
|
|
|
|
2006-05-21 11:18:11 -05:00
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
|
|
|
if (has_selection)
|
|
|
|
{
|
|
|
|
GtkTextIter iter;
|
|
|
|
adjust_selection = TRUE;
|
|
|
|
gtk_text_buffer_get_iter_at_mark (buffer, &iter,
|
|
|
|
gtk_text_buffer_get_insert (buffer));
|
|
|
|
move_insert = gtk_text_iter_equal (&iter, &start);
|
|
|
|
sel_start_line = gtk_text_iter_get_line (&start);
|
|
|
|
sel_start_offset = gtk_text_iter_get_line_offset (&start);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
if (single_line)
|
2006-08-26 04:46:29 -05:00
|
|
|
line_comment (buffer, _moo_lang_get_line_comment (lang), &start, &end);
|
2005-12-16 16:51:31 +00:00
|
|
|
else
|
2006-08-26 04:46:29 -05:00
|
|
|
block_comment (buffer,
|
|
|
|
_moo_lang_get_block_comment_start (lang),
|
|
|
|
_moo_lang_get_block_comment_end (lang),
|
|
|
|
&start, &end);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (adjust_selection)
|
|
|
|
{
|
|
|
|
const char *mark = move_insert ? "insert" : "selection_bound";
|
|
|
|
gtk_text_buffer_get_iter_at_line_offset (buffer, &start,
|
|
|
|
sel_start_line,
|
|
|
|
sel_start_offset);
|
|
|
|
gtk_text_buffer_move_mark_by_name (buffer, mark, &start);
|
|
|
|
}
|
|
|
|
|
2006-05-21 11:18:11 -05:00
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
2005-12-16 16:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-17 01:53:09 -07:00
|
|
|
/**
|
|
|
|
* moo_edit_uncomment_selection:
|
|
|
|
**/
|
2005-12-16 16:51:31 +00:00
|
|
|
void
|
2011-05-17 01:53:09 -07:00
|
|
|
moo_edit_uncomment_selection (MooEdit *edit)
|
2005-12-16 16:51:31 +00:00
|
|
|
{
|
|
|
|
MooLang *lang;
|
|
|
|
GtkTextIter start, end;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
gboolean single_line, multi_line;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
lang = moo_edit_get_lang (edit);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2006-04-29 22:54:03 -05:00
|
|
|
if (!_moo_edit_has_comments (edit, &single_line, &multi_line))
|
2005-12-16 16:51:31 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (edit);
|
2005-12-16 16:51:31 +00:00
|
|
|
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
|
|
|
|
|
2006-05-21 11:18:11 -05:00
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
|
|
|
/* FIXME */
|
|
|
|
if (single_line)
|
2006-08-26 04:46:29 -05:00
|
|
|
line_uncomment (buffer, _moo_lang_get_line_comment (lang), &start, &end);
|
2005-12-16 16:51:31 +00:00
|
|
|
else
|
2006-08-26 04:46:29 -05:00
|
|
|
block_uncomment (buffer,
|
|
|
|
_moo_lang_get_block_comment_start (lang),
|
|
|
|
_moo_lang_get_block_comment_end (lang),
|
|
|
|
&start, &end);
|
2005-12-16 16:51:31 +00:00
|
|
|
|
2006-05-21 11:18:11 -05:00
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
2005-12-16 16:51:31 +00:00
|
|
|
}
|
2006-04-20 03:57:05 -05:00
|
|
|
|
|
|
|
|
2007-12-24 10:24:33 -06:00
|
|
|
void
|
|
|
|
_moo_edit_ensure_newline (MooEdit *edit)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (edit);
|
2007-12-24 10:24:33 -06:00
|
|
|
gtk_text_buffer_get_end_iter (buffer, &iter);
|
|
|
|
|
2008-01-27 00:06:21 -06:00
|
|
|
if (!gtk_text_iter_starts_line (&iter))
|
2007-12-24 10:24:33 -06:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, "\n", -1);
|
|
|
|
}
|
|
|
|
|
2010-12-08 01:11:51 -08:00
|
|
|
void
|
2010-12-18 23:58:18 -08:00
|
|
|
_moo_edit_strip_whitespace (MooEdit *doc)
|
2010-12-08 01:11:51 -08:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter;
|
2010-12-08 01:11:51 -08:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
buffer = moo_edit_get_buffer (doc);
|
|
|
|
gtk_text_buffer_begin_user_action (buffer);
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
for (gtk_text_buffer_get_start_iter (buffer, &iter);
|
|
|
|
!gtk_text_iter_is_end (&iter);
|
|
|
|
gtk_text_iter_forward_line (&iter))
|
|
|
|
{
|
|
|
|
GtkTextIter end;
|
|
|
|
char *slice, *p;
|
|
|
|
int len;
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (gtk_text_iter_ends_line (&iter))
|
|
|
|
continue;
|
2006-06-30 00:58:35 -05:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
end = iter;
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
slice = gtk_text_buffer_get_slice (buffer, &iter, &end, TRUE);
|
|
|
|
len = strlen (slice);
|
|
|
|
g_assert (len > 0);
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
for (p = slice + len; p > slice && (p[-1] == ' ' || p[-1] == '\t'); --p) ;
|
2010-12-08 01:11:51 -08:00
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
if (*p)
|
2010-12-08 01:11:51 -08:00
|
|
|
{
|
2010-12-18 23:58:18 -08:00
|
|
|
gtk_text_iter_forward_chars (&iter, g_utf8_pointer_to_offset (slice, p));
|
|
|
|
gtk_text_buffer_delete (buffer, &iter, &end);
|
2010-12-08 01:11:51 -08:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
g_free (slice);
|
2010-12-08 01:11:51 -08:00
|
|
|
}
|
|
|
|
|
2010-12-18 23:58:18 -08:00
|
|
|
gtk_text_buffer_end_user_action (buffer);
|
2010-12-08 01:11:51 -08:00
|
|
|
}
|