2005-09-06 09:21:05 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
|
2005-09-09 02:54:58 -07:00
|
|
|
*
|
2005-09-06 09:21:05 -07:00
|
|
|
* mooedit.c
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mooedit/mooedit-private.h"
|
2005-11-11 12:04:17 -08:00
|
|
|
#include "mooedit/mootextview-private.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooedit/mooeditdialogs.h"
|
|
|
|
#include "mooedit/mooeditprefs.h"
|
2005-09-09 02:40:10 -07:00
|
|
|
#include "mooedit/mootextbuffer.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooutils/moomarshals.h"
|
|
|
|
#include "mooutils/moocompat.h"
|
2005-09-15 15:13:44 -07:00
|
|
|
#include "mooutils/mooutils-gobject.h"
|
2005-09-06 09:21:05 -07:00
|
|
|
#include <string.h>
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static GObject *moo_edit_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_param);
|
|
|
|
static void moo_edit_finalize (GObject *object);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static void moo_edit_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void moo_edit_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void moo_edit_filename_changed (MooEdit *edit,
|
|
|
|
const char *new_filename);
|
2005-12-10 20:30:02 -08:00
|
|
|
static gboolean moo_edit_line_mark_clicked (MooTextView *view,
|
|
|
|
int line);
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
static void config_changed (MooEdit *edit,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void moo_edit_config_notify (MooEdit *edit,
|
|
|
|
guint var_id,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static GtkTextBuffer *get_buffer (MooEdit *edit);
|
2005-12-10 20:30:02 -08:00
|
|
|
static MooTextBuffer *get_moo_buffer (MooEdit *edit);
|
2005-11-03 17:35:22 -08:00
|
|
|
|
|
|
|
static void modified_changed_cb (GtkTextBuffer *buffer,
|
|
|
|
MooEdit *edit);
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
static void disconnect_bookmark (MooEditBookmark *bk);
|
|
|
|
static void line_mark_moved (MooEdit *edit,
|
|
|
|
MooLineMark *mark);
|
|
|
|
static void line_mark_deleted (MooEdit *edit,
|
|
|
|
MooLineMark *mark);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
DOC_STATUS_CHANGED,
|
|
|
|
FILENAME_CHANGED,
|
2005-10-13 07:08:18 -07:00
|
|
|
COMMENT,
|
|
|
|
UNCOMMENT,
|
2005-12-08 00:53:46 -08:00
|
|
|
CONFIG_NOTIFY,
|
2005-11-23 03:10:03 -08:00
|
|
|
SAVE_BEFORE,
|
|
|
|
SAVE_AFTER,
|
2005-12-10 20:30:02 -08:00
|
|
|
BOOKMARKS_CHANGED,
|
2005-06-22 11:20:32 -07:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2005-12-10 20:30:02 -08:00
|
|
|
PROP_EDITOR,
|
|
|
|
PROP_ENABLE_BOOKMARKS
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
2005-12-08 14:46:03 -08:00
|
|
|
enum {
|
|
|
|
SETTING_LANG,
|
|
|
|
SETTING_INDENT,
|
|
|
|
SETTING_STRIP,
|
|
|
|
LAST_SETTING
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint settings[LAST_SETTING];
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
/* MOO_TYPE_EDIT */
|
2005-09-09 02:40:10 -07:00
|
|
|
G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW)
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_class_init (MooEditClass *klass)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2005-12-10 20:30:02 -08:00
|
|
|
MooTextViewClass *view_class = MOO_TEXT_VIEW_CLASS (klass);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
gobject_class->set_property = moo_edit_set_property;
|
|
|
|
gobject_class->get_property = moo_edit_get_property;
|
|
|
|
gobject_class->constructor = moo_edit_constructor;
|
|
|
|
gobject_class->finalize = moo_edit_finalize;
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
view_class->line_mark_clicked = moo_edit_line_mark_clicked;
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
klass->filename_changed = moo_edit_filename_changed;
|
2005-12-08 00:53:46 -08:00
|
|
|
klass->config_notify = moo_edit_config_notify;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EDITOR,
|
|
|
|
g_param_spec_object ("editor",
|
|
|
|
"editor",
|
|
|
|
"editor",
|
|
|
|
MOO_TYPE_EDITOR,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ENABLE_BOOKMARKS,
|
|
|
|
g_param_spec_boolean ("enable-bookmarks",
|
|
|
|
"enable-bookmarks",
|
|
|
|
"enable-bookmarks",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
2005-12-08 14:46:03 -08:00
|
|
|
settings[SETTING_LANG] = moo_edit_config_install_setting (
|
|
|
|
g_param_spec_string ("lang", "lang", "lang",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
settings[SETTING_INDENT] = moo_edit_config_install_setting (
|
|
|
|
g_param_spec_string ("indent", "indent", "indent",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
settings[SETTING_STRIP] = moo_edit_config_install_setting (
|
|
|
|
g_param_spec_boolean ("strip", "strip", "strip",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
signals[CONFIG_NOTIFY] =
|
|
|
|
g_signal_new ("config-notify",
|
2005-11-03 17:35:22 -08:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2005-12-08 00:53:46 -08:00
|
|
|
G_STRUCT_OFFSET (MooEditClass, config_notify),
|
2005-11-03 17:35:22 -08:00
|
|
|
NULL, NULL,
|
2005-12-08 00:53:46 -08:00
|
|
|
_moo_marshal_VOID__UINT_POINTER,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_UINT, G_TYPE_POINTER);
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
signals[DOC_STATUS_CHANGED] =
|
2005-09-03 15:48:05 -07: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 11:20:32 -07:00
|
|
|
|
|
|
|
signals[FILENAME_CHANGED] =
|
2005-09-03 15:48:05 -07:00
|
|
|
g_signal_new ("filename-changed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2005-11-03 17:35:22 -08:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
2005-09-03 15:48:05 -07:00
|
|
|
G_STRUCT_OFFSET (MooEditClass, filename_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__STRING,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
signals[COMMENT] =
|
|
|
|
moo_signal_new_cb ("comment",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2005-11-24 06:14:48 -08:00
|
|
|
NULL, /* G_CALLBACK (moo_edit_comment), */
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[UNCOMMENT] =
|
|
|
|
moo_signal_new_cb ("uncomment",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
2005-11-24 06:14:48 -08:00
|
|
|
NULL, /* G_CALLBACK (moo_edit_uncomment), */
|
2005-10-13 07:08:18 -07:00
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
signals[SAVE_BEFORE] =
|
|
|
|
g_signal_new ("save-before",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, save_before),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[SAVE_AFTER] =
|
|
|
|
g_signal_new ("save-after",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, save_after),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
signals[BOOKMARKS_CHANGED] =
|
|
|
|
g_signal_new ("bookmarks-changed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (MooEditClass, bookmarks_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2005-12-08 14:46:03 -08:00
|
|
|
_moo_edit_init_settings ();
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_init (MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
MooIndenter *indent;
|
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
edit->config = moo_edit_config_new ();
|
|
|
|
g_signal_connect_swapped (edit->config, "notify",
|
|
|
|
G_CALLBACK (config_changed), edit);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
edit->priv = g_new0 (MooEditPrivate, 1);
|
|
|
|
|
|
|
|
edit->priv->file_watch_policy = MOO_EDIT_RELOAD_IF_SAFE;
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
indent = moo_indenter_new (edit, NULL);
|
|
|
|
moo_text_view_set_indenter (MOO_TEXT_VIEW (edit), indent);
|
|
|
|
g_object_unref (indent);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
/* XXX this is stupid */
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
edit->priv->line_end_type = MOO_EDIT_LINE_END_WIN32;
|
|
|
|
#elif defined(MOO_OS_DARWIN)
|
|
|
|
edit->priv->line_end_type = MOO_EDIT_LINE_END_MAC;
|
|
|
|
#else
|
|
|
|
edit->priv->line_end_type = MOO_EDIT_LINE_END_UNIX;
|
|
|
|
#endif
|
|
|
|
|
2005-11-20 23:58:01 -08:00
|
|
|
g_object_set (edit, "draw-tabs", TRUE, "draw-trailing-spaces", TRUE, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
static GObject*
|
|
|
|
moo_edit_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_param)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
GObject *object;
|
|
|
|
MooEdit *edit;
|
2005-12-10 20:30:02 -08:00
|
|
|
GtkTextBuffer *buffer;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (moo_edit_parent_class)->constructor (
|
|
|
|
type, n_construct_properties, construct_param);
|
|
|
|
|
|
|
|
edit = MOO_EDIT (object);
|
|
|
|
|
|
|
|
edit->priv->modified_changed_handler_id =
|
2005-09-09 02:40:10 -07:00
|
|
|
g_signal_connect (get_buffer (edit),
|
2005-06-22 11:20:32 -07:00
|
|
|
"modified-changed",
|
|
|
|
G_CALLBACK (modified_changed_cb),
|
|
|
|
edit);
|
|
|
|
|
|
|
|
_moo_edit_apply_settings (edit);
|
2005-12-08 14:46:03 -08:00
|
|
|
g_signal_connect_after (edit, "realize", G_CALLBACK (_moo_edit_apply_style_settings), NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
_moo_edit_set_filename (edit, NULL, NULL);
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
buffer = get_buffer (edit);
|
|
|
|
g_signal_connect_swapped (buffer, "line-mark-moved",
|
|
|
|
G_CALLBACK (line_mark_moved),
|
|
|
|
edit);
|
|
|
|
g_signal_connect_swapped (buffer, "line-mark-deleted",
|
|
|
|
G_CALLBACK (line_mark_deleted),
|
|
|
|
edit);
|
|
|
|
|
2005-12-12 02:58:25 -08:00
|
|
|
// g_object_set (edit, "enable-folding", TRUE, NULL);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_finalize (GObject *object)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
|
|
|
|
2005-12-08 14:46:03 -08:00
|
|
|
g_signal_handlers_disconnect_by_func (edit->config,
|
|
|
|
(gpointer) config_changed,
|
|
|
|
edit);
|
2005-12-08 00:53:46 -08:00
|
|
|
g_object_unref (edit->config);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
edit->priv->focus_in_handler_id = 0;
|
|
|
|
if (edit->priv->file_monitor_id)
|
|
|
|
_moo_edit_stop_file_watch (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
g_free (edit->priv->filename);
|
|
|
|
g_free (edit->priv->basename);
|
|
|
|
g_free (edit->priv->display_filename);
|
|
|
|
g_free (edit->priv->display_basename);
|
|
|
|
g_free (edit->priv->encoding);
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
if (edit->priv->update_bookmarks_idle)
|
|
|
|
g_source_remove (edit->priv->update_bookmarks_idle);
|
|
|
|
g_slist_foreach (edit->priv->bookmarks, (GFunc) disconnect_bookmark, NULL);
|
|
|
|
g_slist_foreach (edit->priv->bookmarks, (GFunc) g_object_unref, NULL);
|
|
|
|
g_slist_free (edit->priv->bookmarks);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
g_free (edit->priv);
|
|
|
|
edit->priv = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (moo_edit_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
MooEdit*
|
|
|
|
_moo_edit_new (MooEditor *editor)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (g_object_new (MOO_TYPE_EDIT,
|
|
|
|
"editor", editor,
|
|
|
|
NULL));
|
|
|
|
return edit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
modified_changed_cb (GtkTextBuffer *buffer,
|
|
|
|
MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
moo_edit_set_modified (edit, gtk_text_buffer_get_modified (buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_set_modified (MooEdit *edit,
|
|
|
|
gboolean modified)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
gboolean buf_modified;
|
2005-09-06 09:21:05 -07:00
|
|
|
GtkTextBuffer *buffer;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
buffer = get_buffer (edit);
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
buf_modified =
|
2005-09-06 09:21:05 -07:00
|
|
|
gtk_text_buffer_get_modified (buffer);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
if (buf_modified != modified)
|
|
|
|
{
|
2005-09-06 09:21:05 -07:00
|
|
|
g_signal_handler_block (buffer,
|
2005-06-22 11:20:32 -07:00
|
|
|
edit->priv->modified_changed_handler_id);
|
2005-09-06 09:21:05 -07:00
|
|
|
gtk_text_buffer_set_modified (buffer, modified);
|
|
|
|
g_signal_handler_unblock (buffer,
|
2005-06-22 11:20:32 -07:00
|
|
|
edit->priv->modified_changed_handler_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modified)
|
2005-09-02 16:27:25 -07:00
|
|
|
edit->priv->status |= MOO_EDIT_MODIFIED;
|
2005-06-22 11:20:32 -07:00
|
|
|
else
|
2005-09-02 16:27:25 -07:00
|
|
|
edit->priv->status &= ~MOO_EDIT_MODIFIED;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
moo_edit_status_changed (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_set_clean (MooEdit *edit,
|
|
|
|
gboolean clean)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
if (clean)
|
2005-09-02 16:27:25 -07:00
|
|
|
edit->priv->status |= MOO_EDIT_CLEAN;
|
2005-06-22 11:20:32 -07:00
|
|
|
else
|
2005-09-02 16:27:25 -07:00
|
|
|
edit->priv->status &= ~MOO_EDIT_CLEAN;
|
|
|
|
moo_edit_status_changed (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-06 22:56:33 -08:00
|
|
|
gboolean
|
|
|
|
moo_edit_get_clean (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
return (edit->priv->status & MOO_EDIT_CLEAN) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_status_changed (MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_signal_emit (edit, signals[DOC_STATUS_CHANGED], 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
MooEditFileInfo*
|
|
|
|
moo_edit_file_info_new (const char *filename,
|
|
|
|
const char *encoding)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-07-30 21:28:41 -07:00
|
|
|
MooEditFileInfo *info = g_new0 (MooEditFileInfo, 1);
|
2005-06-22 11:20:32 -07:00
|
|
|
info->filename = g_strdup (filename);
|
|
|
|
info->encoding = g_strdup (encoding);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
|
|
|
|
MooEditFileInfo*
|
|
|
|
moo_edit_file_info_copy (const MooEditFileInfo *info)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEditFileInfo *copy;
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
copy = g_new (MooEditFileInfo, 1);
|
|
|
|
copy->encoding = g_strdup (info->encoding);
|
2005-07-30 21:28:41 -07:00
|
|
|
copy->filename = g_strdup (info->filename);
|
2005-06-22 11:20:32 -07:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_file_info_free (MooEditFileInfo *info)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-07-30 21:28:41 -07:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
g_free (info->encoding);
|
|
|
|
g_free (info->filename);
|
|
|
|
g_free (info);
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
gboolean
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_get_readonly (MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), TRUE);
|
|
|
|
return edit->priv->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_set_readonly (MooEdit *edit,
|
|
|
|
gboolean readonly)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
edit->priv->readonly = readonly;
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (edit), !readonly);
|
2005-09-02 16:27:25 -07:00
|
|
|
moo_edit_status_changed (edit);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
gboolean
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_is_empty (MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
if (MOO_EDIT_IS_MODIFIED (edit) || edit->priv->filename)
|
2005-06-22 11:20:32 -07:00
|
|
|
return FALSE;
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gtk_text_buffer_get_bounds (get_buffer (edit), &start, &end);
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
return !gtk_text_iter_compare (&start, &end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
MooEditStatus
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_get_status (MooEdit *edit)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), 0);
|
|
|
|
return edit->priv->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
2005-09-06 09:21:05 -07:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
case PROP_EDITOR:
|
2005-09-06 09:21:05 -07:00
|
|
|
edit->priv->editor = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
case PROP_ENABLE_BOOKMARKS:
|
|
|
|
moo_edit_set_enable_bookmarks (edit, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
static void
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
MooEdit *edit = MOO_EDIT (object);
|
2005-09-06 09:21:05 -07:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2005-06-22 11:20:32 -07:00
|
|
|
case PROP_EDITOR:
|
|
|
|
g_value_set_object (value, edit->priv->editor);
|
|
|
|
break;
|
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
case PROP_ENABLE_BOOKMARKS:
|
|
|
|
g_value_set_boolean (value, edit->priv->enable_bookmarks);
|
|
|
|
break;
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
GType
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_edit_status_get_type (void)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
static const GFlagsValue values[] = {
|
2005-09-02 16:27:25 -07:00
|
|
|
{ MOO_EDIT_MODIFIED_ON_DISK, (char*)"MOO_EDIT_MODIFIED_ON_DISK", (char*)"modified-on-disk" },
|
|
|
|
{ MOO_EDIT_DELETED, (char*)"MOO_EDIT_DELETED", (char*)"deleted" },
|
|
|
|
{ MOO_EDIT_CHANGED_ON_DISK, (char*)"MOO_EDIT_CHANGED_ON_DISK", (char*)"changed-on-disk" },
|
|
|
|
{ MOO_EDIT_MODIFIED, (char*)"MOO_EDIT_MODIFIED", (char*)"modified" },
|
|
|
|
{ MOO_EDIT_CLEAN, (char*)"MOO_EDIT_CLEAN", (char*)"clean" },
|
2005-06-22 11:20:32 -07:00
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
2005-09-02 16:27:25 -07:00
|
|
|
type = g_flags_register_static ("MooEditStatus", values);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
GType
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_on_external_changes_get_type (void)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{ MOO_EDIT_DONT_WATCH_FILE, (char*)"MOO_EDIT_DONT_WATCH_FILE", (char*)"dont-watch-file" },
|
|
|
|
{ MOO_EDIT_ALWAYS_ALERT, (char*)"MOO_EDIT_ALWAYS_ALERT", (char*)"always-alert" },
|
|
|
|
{ MOO_EDIT_ALWAYS_RELOAD, (char*)"MOO_EDIT_ALWAYS_RELOAD", (char*)"always-reload" },
|
|
|
|
{ MOO_EDIT_RELOAD_IF_SAFE, (char*)"MOO_EDIT_RELOAD_IF_SAFE", (char*)"reload-if-safe" },
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
type = g_enum_register_static ("MooEditOnExternalChanges", values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
|
2005-09-09 02:54:58 -07:00
|
|
|
GType
|
2005-09-09 02:40:10 -07:00
|
|
|
moo_edit_file_info_get_type (void)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
if (!type)
|
|
|
|
type = g_boxed_type_register_static ("MooEditFileInfo",
|
|
|
|
(GBoxedCopyFunc) moo_edit_file_info_copy,
|
2005-12-08 00:53:46 -08:00
|
|
|
(GBoxedFreeFunc) moo_edit_file_info_free);
|
2005-06-22 11:20:32 -07:00
|
|
|
return type;
|
|
|
|
}
|
2005-07-25 11:49:06 -07:00
|
|
|
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
const char*
|
|
|
|
moo_edit_get_filename (MooEdit *edit)
|
2005-07-30 21:28:41 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->filename;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
const char*
|
|
|
|
moo_edit_get_basename (MooEdit *edit)
|
2005-07-30 21:28:41 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->basename;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
const char*
|
|
|
|
moo_edit_get_display_filename (MooEdit *edit)
|
2005-07-30 21:28:41 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->display_filename;
|
|
|
|
}
|
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
const char*
|
|
|
|
moo_edit_get_display_basename (MooEdit *edit)
|
2005-07-30 21:28:41 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->display_basename;
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-09 02:40:10 -07:00
|
|
|
const char*
|
|
|
|
moo_edit_get_encoding (MooEdit *edit)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
return edit->priv->encoding;
|
|
|
|
}
|
2005-09-06 09:21:05 -07:00
|
|
|
|
|
|
|
|
2005-11-25 12:48:39 -08:00
|
|
|
char*
|
|
|
|
moo_edit_get_uri (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
|
|
|
|
if (edit->priv->filename)
|
|
|
|
return g_filename_to_uri (edit->priv->filename, NULL, NULL);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static GtkTextBuffer*
|
|
|
|
get_buffer (MooEdit *edit)
|
|
|
|
{
|
|
|
|
return gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
|
|
|
|
}
|
|
|
|
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-12-10 20:30:02 -08:00
|
|
|
static MooTextBuffer *
|
|
|
|
get_moo_buffer (MooEdit *edit)
|
|
|
|
{
|
|
|
|
return MOO_TEXT_BUFFER (get_buffer (edit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static void
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_edit_set_lang (MooEdit *edit,
|
|
|
|
MooLang *lang)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
2005-10-16 22:23:40 -07:00
|
|
|
moo_text_view_set_lang (MOO_TEXT_VIEW (edit), lang);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 09:37:28 -08:00
|
|
|
typedef void (*SetVarFunc) (MooEdit *edit,
|
|
|
|
char *name,
|
|
|
|
char *val);
|
|
|
|
|
|
|
|
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 09:21:05 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
2005-12-08 16:19:41 -08:00
|
|
|
set_kate_var (MooEdit *edit,
|
|
|
|
const char *name,
|
|
|
|
const char *val)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2005-12-08 16:19:41 -08:00
|
|
|
if (!g_ascii_strcasecmp (name, "space-indent"))
|
|
|
|
{
|
|
|
|
gboolean spaces = FALSE;
|
|
|
|
|
|
|
|
if (moo_edit_config_parse_bool (val, &spaces))
|
|
|
|
moo_edit_config_parse (edit->config, "indent-use-tabs",
|
|
|
|
spaces ? "false" : "true",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moo_edit_config_parse (edit->config, name, val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_kate_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
|
|
|
{
|
|
|
|
parse_mode_string (edit, string, " ", (SetVarFunc) set_kate_var);
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-24 09:37:28 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_emacs_var (MooEdit *edit,
|
|
|
|
char *name,
|
|
|
|
char *val)
|
|
|
|
{
|
|
|
|
if (!g_ascii_strcasecmp (name, "mode"))
|
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_parse (edit->config, "lang", val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 09:37:28 -08:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "tab-width"))
|
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_parse (edit->config, "indent-tab-width", val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 09:37:28 -08:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "c-basic-offset"))
|
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_parse (edit->config, "indent-width", val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 09:37:28 -08:00
|
|
|
}
|
|
|
|
else if (!g_ascii_strcasecmp (name, "indent-tabs-mode"))
|
|
|
|
{
|
|
|
|
if (!g_ascii_strcasecmp (val, "nil"))
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_parse (edit->config, "indent-use-tabs", "false",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 09:37:28 -08:00
|
|
|
else
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_parse (edit->config, "indent-use-tabs", "true",
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 09:37:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
static void
|
2005-11-24 09:37:28 -08:00
|
|
|
parse_emacs_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
2005-11-24 06:14:48 -08:00
|
|
|
{
|
2005-11-24 09:37:28 -08:00
|
|
|
parse_mode_string (edit, string, ":", set_emacs_var);
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 09:37:28 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
static void
|
|
|
|
set_moo_var (MooEdit *edit,
|
|
|
|
char *name,
|
|
|
|
char *val)
|
|
|
|
{
|
|
|
|
moo_edit_config_parse (edit->config, name, val,
|
|
|
|
MOO_EDIT_CONFIG_SOURCE_FILE);
|
|
|
|
}
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
static void
|
2005-11-24 09:37:28 -08:00
|
|
|
parse_moo_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
2005-11-24 06:14:48 -08:00
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
parse_mode_string (edit, string, " ", (SetVarFunc) set_moo_var);
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
#define KATE_MODE_STRING "kate:"
|
|
|
|
#define EMACS_MODE_STRING "-*-"
|
2005-11-24 09:37:28 -08:00
|
|
|
#define MOO_MODE_STRING "-%-"
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
static void
|
|
|
|
try_mode_string (MooEdit *edit,
|
|
|
|
char *string)
|
|
|
|
{
|
|
|
|
char *start, *end;
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
if ((start = strstr (string, KATE_MODE_STRING)))
|
2005-09-06 09:21:05 -07:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
start += strlen (KATE_MODE_STRING);
|
|
|
|
return parse_kate_mode_string (edit, start);
|
|
|
|
}
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
if ((start = strstr (string, EMACS_MODE_STRING)))
|
|
|
|
{
|
|
|
|
start += strlen (EMACS_MODE_STRING);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-24 09:37:28 -08:00
|
|
|
if ((end = strstr (start, EMACS_MODE_STRING)) && end > start)
|
2005-09-06 09:21:05 -07:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
end[0] = 0;
|
|
|
|
return parse_emacs_mode_string (edit, start);
|
2005-09-06 09:21:05 -07:00
|
|
|
}
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-09-06 09:21:05 -07:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
if ((start = strstr (string, MOO_MODE_STRING)))
|
|
|
|
{
|
|
|
|
start += strlen (MOO_MODE_STRING);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-24 09:37:28 -08:00
|
|
|
if ((end = strstr (start, MOO_MODE_STRING)) && end > start)
|
2005-09-06 09:21:05 -07:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
end[0] = 0;
|
|
|
|
return parse_moo_mode_string (edit, start);
|
2005-09-06 09:21:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
2005-11-24 06:14:48 -08:00
|
|
|
try_mode_strings (MooEdit *edit)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer = get_buffer (edit);
|
|
|
|
GtkTextIter start, end;
|
2005-11-24 06:14:48 -08:00
|
|
|
char *first, *last;
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &start);
|
|
|
|
end = start;
|
|
|
|
gtk_text_iter_forward_to_line_end (&end);
|
2005-11-24 06:14:48 -08:00
|
|
|
first = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
2005-11-02 22:47:53 -08: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);
|
|
|
|
}
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
last = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
|
|
|
|
|
|
|
try_mode_string (edit, first);
|
|
|
|
try_mode_string (edit, last);
|
|
|
|
|
|
|
|
g_free (first);
|
|
|
|
g_free (last);
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static void
|
2005-12-08 00:53:46 -08:00
|
|
|
config_changed (MooEdit *edit,
|
|
|
|
GParamSpec *pspec)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
guint id = moo_edit_config_get_setting_id (pspec);
|
|
|
|
g_return_if_fail (id != 0);
|
|
|
|
g_signal_emit (edit, signals[CONFIG_NOTIFY], 0, id, pspec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_config_notify (MooEdit *edit,
|
2005-12-08 14:46:03 -08:00
|
|
|
guint var_id,
|
|
|
|
G_GNUC_UNUSED GParamSpec *pspec)
|
2005-12-08 00:53:46 -08:00
|
|
|
{
|
2005-12-08 14:46:03 -08:00
|
|
|
if (var_id == settings[SETTING_LANG])
|
2005-11-24 06:14:48 -08:00
|
|
|
{
|
2005-12-08 00:53:46 -08:00
|
|
|
const char *value = moo_edit_config_get_string (edit->config, "lang");
|
2005-11-24 06:14:48 -08:00
|
|
|
MooLangMgr *mgr = moo_editor_get_lang_mgr (edit->priv->editor);
|
|
|
|
MooLang *lang = value ? moo_lang_mgr_get_lang (mgr, value) : NULL;
|
|
|
|
moo_edit_set_lang (edit, lang);
|
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
static void
|
2005-11-24 06:14:48 -08:00
|
|
|
moo_edit_filename_changed (MooEdit *edit,
|
|
|
|
const char *filename)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
MooLang *lang = NULL;
|
2005-12-08 00:53:46 -08:00
|
|
|
const char *lang_id = NULL;
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
_moo_edit_freeze_config_notify (edit);
|
2005-11-24 09:37:28 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_unset_by_source (edit->config, MOO_EDIT_CONFIG_SOURCE_FILE);
|
2005-11-24 06:14:48 -08:00
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
MooLangMgr *mgr = moo_editor_get_lang_mgr (edit->priv->editor);
|
|
|
|
lang = moo_lang_mgr_get_lang_for_file (mgr, filename);
|
2005-12-08 16:24:28 -08:00
|
|
|
lang_id = lang ? lang->id : NULL;
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
moo_edit_config_set (edit->config, "lang", MOO_EDIT_CONFIG_SOURCE_FILENAME, lang_id, NULL);
|
|
|
|
moo_edit_config_set (edit->config, "indent", MOO_EDIT_CONFIG_SOURCE_FILENAME, NULL, NULL);
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
try_mode_strings (edit);
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-12-08 00:53:46 -08:00
|
|
|
_moo_edit_thaw_config_notify (edit);
|
2005-11-03 17:35:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
gboolean
|
2005-12-04 12:13:58 -08:00
|
|
|
moo_edit_close (MooEdit *edit,
|
|
|
|
gboolean ask_confirm)
|
2005-11-03 17:35:22 -08:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
2005-12-04 12:13:58 -08:00
|
|
|
return moo_editor_close_doc (edit->priv->editor, edit, ask_confirm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
moo_edit_save (MooEdit *edit,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
return _moo_editor_save (edit->priv->editor, edit, error);
|
2005-11-03 17:35:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
gboolean
|
|
|
|
moo_edit_save_as (MooEdit *edit,
|
|
|
|
const char *filename,
|
2005-12-04 12:13:58 -08:00
|
|
|
const char *encoding,
|
|
|
|
GError **error)
|
2005-11-03 17:35:22 -08:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
2005-12-04 12:13:58 -08:00
|
|
|
return _moo_editor_save_as (edit->priv->editor, edit, filename, encoding, error);
|
2005-11-03 17:35:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
gboolean
|
|
|
|
moo_edit_save_copy (MooEdit *edit,
|
|
|
|
const char *filename,
|
|
|
|
const char *encoding,
|
|
|
|
GError **error)
|
2005-11-03 17:35:22 -08:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
return moo_editor_save_copy (edit->priv->editor, edit,
|
|
|
|
filename, encoding, error);
|
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
void
|
2005-12-08 00:53:46 -08:00
|
|
|
_moo_edit_freeze_config_notify (MooEdit *edit)
|
2005-11-24 06:14:48 -08:00
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
2005-12-08 00:53:46 -08:00
|
|
|
g_object_freeze_notify (G_OBJECT (edit->config));
|
2005-11-03 17:35:22 -08:00
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
2005-11-03 17:35:22 -08:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
void
|
2005-12-08 00:53:46 -08:00
|
|
|
_moo_edit_thaw_config_notify (MooEdit *edit)
|
2005-11-03 17:35:22 -08:00
|
|
|
{
|
2005-11-24 06:14:48 -08:00
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
2005-12-08 00:53:46 -08:00
|
|
|
g_object_thaw_notify (G_OBJECT (edit->config));
|
2005-11-24 06:14:48 -08:00
|
|
|
}
|
2005-12-10 20:30:02 -08:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Bookmarks
|
|
|
|
*/
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(MooEditBookmark, moo_edit_bookmark, MOO_TYPE_LINE_MARK)
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_bookmark_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MooEditBookmark *bk = MOO_EDIT_BOOKMARK (object);
|
|
|
|
g_free (bk->text);
|
|
|
|
G_OBJECT_CLASS(moo_edit_bookmark_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_bookmark_class_init (MooEditBookmarkClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
object_class->finalize = moo_edit_bookmark_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
moo_edit_bookmark_init (MooEditBookmark *bk)
|
|
|
|
{
|
|
|
|
g_object_set (bk,
|
|
|
|
"visible", TRUE,
|
|
|
|
"background", "#E5E5FF",
|
|
|
|
"stock-id", GTK_STOCK_ABOUT,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static guint
|
|
|
|
get_line_count (MooEdit *edit)
|
|
|
|
{
|
|
|
|
return gtk_text_buffer_get_line_count (get_buffer (edit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
bookmarks_changed (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_signal_emit (edit, signals[BOOKMARKS_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_set_enable_bookmarks (MooEdit *edit,
|
|
|
|
gboolean enable)
|
|
|
|
{
|
|
|
|
MooTextBuffer *buffer;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
|
|
|
|
enable = enable != 0;
|
|
|
|
|
|
|
|
if (enable == edit->priv->enable_bookmarks)
|
|
|
|
return;
|
|
|
|
|
|
|
|
edit->priv->enable_bookmarks = enable;
|
|
|
|
moo_text_view_set_show_line_marks (MOO_TEXT_VIEW (edit), enable);
|
|
|
|
buffer = get_moo_buffer (edit);
|
|
|
|
|
|
|
|
if (!enable && edit->priv->bookmarks)
|
|
|
|
{
|
|
|
|
GSList *tmp = edit->priv->bookmarks;
|
|
|
|
edit->priv->bookmarks = NULL;
|
|
|
|
g_slist_foreach (tmp, (GFunc) disconnect_bookmark, NULL);
|
|
|
|
|
|
|
|
while (tmp)
|
|
|
|
{
|
2005-12-12 02:58:25 -08:00
|
|
|
moo_text_buffer_delete_line_mark (buffer, tmp->data);
|
2005-12-10 20:30:02 -08:00
|
|
|
g_object_unref (tmp->data);
|
|
|
|
tmp = g_slist_delete_link (tmp, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bookmarks_changed (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (edit), "enable-bookmarks");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
moo_edit_get_enable_bookmarks (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
|
|
|
return edit->priv->enable_bookmarks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int cmp_bookmarks (MooLineMark *a,
|
|
|
|
MooLineMark *b)
|
|
|
|
{
|
|
|
|
int line_a = moo_line_mark_get_line (a);
|
|
|
|
int line_b = moo_line_mark_get_line (b);
|
|
|
|
return line_a < line_b ? -1 : (line_a > line_b ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
update_bookmarks (MooEdit *edit)
|
|
|
|
{
|
|
|
|
GSList *deleted, *dup, *old, *new, *l;
|
|
|
|
|
|
|
|
edit->priv->update_bookmarks_idle = 0;
|
|
|
|
old = edit->priv->bookmarks;
|
|
|
|
edit->priv->bookmarks = NULL;
|
|
|
|
|
|
|
|
for (deleted = NULL, new = NULL, l = old; l != NULL; l = l->next)
|
|
|
|
if (moo_line_mark_get_deleted (MOO_LINE_MARK (l->data)))
|
|
|
|
deleted = g_slist_prepend (deleted, l->data);
|
|
|
|
else
|
|
|
|
new = g_slist_prepend (new, l->data);
|
|
|
|
|
|
|
|
g_slist_foreach (deleted, (GFunc) disconnect_bookmark, NULL);
|
|
|
|
g_slist_foreach (deleted, (GFunc) g_object_unref, NULL);
|
|
|
|
g_slist_free (deleted);
|
|
|
|
|
|
|
|
new = g_slist_sort (new, (GCompareFunc) cmp_bookmarks);
|
|
|
|
old = new;
|
|
|
|
new = NULL;
|
|
|
|
dup = NULL;
|
|
|
|
|
|
|
|
for (l = old; l != NULL; l = l->next)
|
|
|
|
if (new && moo_line_mark_get_line (new->data) == moo_line_mark_get_line (l->data))
|
|
|
|
dup = g_slist_prepend (dup, l->data);
|
|
|
|
else
|
|
|
|
new = g_slist_prepend (new, l->data);
|
|
|
|
|
|
|
|
while (dup)
|
|
|
|
{
|
|
|
|
disconnect_bookmark (dup->data);
|
2005-12-12 02:58:25 -08:00
|
|
|
moo_text_buffer_delete_line_mark (get_moo_buffer (edit), dup->data);
|
2005-12-10 20:30:02 -08:00
|
|
|
g_object_unref (dup->data);
|
|
|
|
dup = g_slist_delete_link (dup, dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
edit->priv->bookmarks = g_slist_reverse (new);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_bookmarks_now (MooEdit *edit)
|
|
|
|
{
|
|
|
|
if (edit->priv->update_bookmarks_idle)
|
|
|
|
{
|
|
|
|
g_source_remove (edit->priv->update_bookmarks_idle);
|
|
|
|
edit->priv->update_bookmarks_idle = 0;
|
|
|
|
update_bookmarks (edit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const GSList *
|
|
|
|
moo_edit_list_bookmarks (MooEdit *edit)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
update_bookmarks_now (edit);
|
|
|
|
return edit->priv->bookmarks;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_toggle_bookmark (MooEdit *edit,
|
|
|
|
guint line)
|
|
|
|
{
|
|
|
|
MooEditBookmark *bk;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_return_if_fail (line < get_line_count (edit));
|
|
|
|
|
|
|
|
bk = moo_edit_get_bookmark_at_line (edit, line);
|
|
|
|
|
|
|
|
if (bk)
|
|
|
|
moo_edit_remove_bookmark (edit, bk);
|
|
|
|
else
|
|
|
|
moo_edit_add_bookmark (edit, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MooEditBookmark *
|
|
|
|
moo_edit_get_bookmark_at_line (MooEdit *edit,
|
|
|
|
guint line)
|
|
|
|
{
|
|
|
|
GSList *list, *l;
|
|
|
|
MooEditBookmark *bk;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
g_return_val_if_fail (line < get_line_count (edit), NULL);
|
|
|
|
|
|
|
|
bk = NULL;
|
|
|
|
list = moo_text_buffer_get_line_marks_at_line (get_moo_buffer (edit), line);
|
|
|
|
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
if (MOO_IS_EDIT_BOOKMARK (l->data) && g_slist_find (edit->priv->bookmarks, l->data))
|
|
|
|
{
|
|
|
|
bk = l->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (list);
|
|
|
|
return bk;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_remove_bookmark (MooEdit *edit,
|
|
|
|
MooEditBookmark *bookmark)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_BOOKMARK (bookmark));
|
|
|
|
g_return_if_fail (g_slist_find (edit->priv->bookmarks, bookmark));
|
|
|
|
|
|
|
|
disconnect_bookmark (bookmark);
|
|
|
|
edit->priv->bookmarks = g_slist_remove (edit->priv->bookmarks, bookmark);
|
2005-12-12 02:58:25 -08:00
|
|
|
moo_text_buffer_delete_line_mark (get_moo_buffer (edit), MOO_LINE_MARK (bookmark));
|
2005-12-10 20:30:02 -08:00
|
|
|
|
|
|
|
g_object_unref (bookmark);
|
|
|
|
bookmarks_changed (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_edit_add_bookmark (MooEdit *edit,
|
|
|
|
guint line)
|
|
|
|
{
|
|
|
|
MooEditBookmark *bk;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDIT (edit));
|
|
|
|
g_return_if_fail (line < get_line_count (edit));
|
|
|
|
g_return_if_fail (moo_edit_get_bookmark_at_line (edit, line) == NULL);
|
|
|
|
|
|
|
|
bk = g_object_new (MOO_TYPE_EDIT_BOOKMARK, NULL);
|
|
|
|
moo_text_buffer_add_line_mark (get_moo_buffer (edit), MOO_LINE_MARK (bk), line);
|
|
|
|
g_object_set_data (G_OBJECT (bk), "moo-edit-bookmark", GINT_TO_POINTER (TRUE));
|
|
|
|
|
|
|
|
// bk->text = ???
|
|
|
|
// background
|
|
|
|
|
|
|
|
if (!edit->priv->update_bookmarks_idle)
|
|
|
|
edit->priv->bookmarks =
|
|
|
|
g_slist_insert_sorted (edit->priv->bookmarks, bk,
|
|
|
|
(GCompareFunc) cmp_bookmarks);
|
|
|
|
else
|
|
|
|
edit->priv->bookmarks = g_slist_prepend (edit->priv->bookmarks, bk);
|
|
|
|
|
|
|
|
bookmarks_changed (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
disconnect_bookmark (MooEditBookmark *bk)
|
|
|
|
{
|
|
|
|
g_object_set_data (G_OBJECT (bk), "moo-edit-bookmark", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_mark_moved (MooEdit *edit,
|
|
|
|
MooLineMark *mark)
|
|
|
|
{
|
|
|
|
if (MOO_IS_EDIT_BOOKMARK (mark) &&
|
|
|
|
g_object_get_data (G_OBJECT (mark), "moo-edit-bookmark") &&
|
|
|
|
!edit->priv->update_bookmarks_idle)
|
|
|
|
{
|
|
|
|
edit->priv->update_bookmarks_idle =
|
|
|
|
g_idle_add ((GSourceFunc) update_bookmarks, edit);
|
|
|
|
bookmarks_changed (edit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
line_mark_deleted (MooEdit *edit,
|
|
|
|
MooLineMark *mark)
|
|
|
|
{
|
|
|
|
if (MOO_IS_EDIT_BOOKMARK (mark) &&
|
|
|
|
g_object_get_data (G_OBJECT (mark), "moo-edit-bookmark") &&
|
|
|
|
g_slist_find (edit->priv->bookmarks, mark))
|
|
|
|
{
|
|
|
|
disconnect_bookmark (MOO_EDIT_BOOKMARK (mark));
|
|
|
|
edit->priv->bookmarks = g_slist_remove (edit->priv->bookmarks, mark);
|
|
|
|
g_object_unref (mark);
|
|
|
|
bookmarks_changed (edit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
moo_edit_line_mark_clicked (MooTextView *view,
|
|
|
|
int line)
|
|
|
|
{
|
|
|
|
moo_edit_toggle_bookmark (MOO_EDIT (view), line);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-12-10 23:23:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
GSList*
|
|
|
|
moo_edit_get_bookmarks_in_range (MooEdit *edit,
|
|
|
|
int first_line,
|
|
|
|
int last_line)
|
|
|
|
{
|
|
|
|
GSList *all, *range, *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
|
|
|
g_return_val_if_fail (first_line >= 0, NULL);
|
|
|
|
|
|
|
|
if (last_line < 0 || last_line >= (int) get_line_count (edit))
|
|
|
|
last_line = get_line_count (edit) - 1;
|
|
|
|
|
|
|
|
if (first_line > last_line)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
all = (GSList*) moo_edit_list_bookmarks (edit);
|
|
|
|
|
|
|
|
for (l = all, range = NULL; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
int line = moo_line_mark_get_line (l->data);
|
|
|
|
|
|
|
|
if (line < first_line)
|
|
|
|
continue;
|
|
|
|
else if (line > last_line)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
range = g_slist_prepend (range, l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_slist_reverse (range);
|
|
|
|
}
|