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-02 16:27:25 -07:00
|
|
|
* mooeditor.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
|
|
|
|
#include "mooedit/mooeditor.h"
|
2005-07-25 10:56:59 -07:00
|
|
|
#include "mooedit/mooeditdialogs.h"
|
2005-09-02 16:27:25 -07:00
|
|
|
#include "mooedit/mooeditfileops.h"
|
2005-09-08 00:46:48 -07:00
|
|
|
#include "mooedit/mooplugin.h"
|
2005-10-13 07:08:18 -07:00
|
|
|
#include "mooutils/moomenuaction.h"
|
2005-06-22 11:20:32 -07:00
|
|
|
#include "mooutils/moocompat.h"
|
|
|
|
#include "mooutils/moomarshals.h"
|
2005-10-31 14:58:01 -08:00
|
|
|
#include "mooutils/mooutils-misc.h"
|
2005-09-15 15:13:44 -07:00
|
|
|
#include "mooutils/mooutils-gobject.h"
|
2005-10-13 07:08:18 -07:00
|
|
|
#include "mooutils/moofilewatch.h"
|
2005-07-31 07:53:10 -07:00
|
|
|
#include <string.h>
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
#define RECENT_ACTION_ID "OpenRecent"
|
|
|
|
|
2005-09-16 10:51:20 -07:00
|
|
|
static MooEditor *editor_instance = NULL;
|
|
|
|
|
|
|
|
|
2005-07-29 08:25:29 -07:00
|
|
|
typedef struct {
|
2005-09-02 16:27:25 -07:00
|
|
|
MooEditWindow *window;
|
2005-07-29 08:25:29 -07:00
|
|
|
GSList *docs;
|
|
|
|
} WindowInfo;
|
|
|
|
|
|
|
|
static WindowInfo *window_info_new (MooEditWindow *win);
|
|
|
|
static void window_info_free (WindowInfo *win);
|
|
|
|
static void window_info_add (WindowInfo *win,
|
|
|
|
MooEdit *doc);
|
|
|
|
static void window_info_remove (WindowInfo *win,
|
|
|
|
MooEdit *doc);
|
2005-07-31 07:53:10 -07:00
|
|
|
static MooEdit *window_info_find (WindowInfo *win,
|
|
|
|
const char *filename);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
|
|
|
static void window_list_free (MooEditor *editor);
|
|
|
|
static void window_list_delete (MooEditor *editor,
|
|
|
|
WindowInfo *win);
|
|
|
|
static WindowInfo *window_list_add (MooEditor *editor,
|
|
|
|
MooEditWindow *win);
|
|
|
|
static WindowInfo *window_list_find (MooEditor *editor,
|
|
|
|
MooEditWindow *win);
|
|
|
|
static WindowInfo *window_list_find_doc (MooEditor *editor,
|
|
|
|
MooEdit *edit);
|
2005-07-31 07:53:10 -07:00
|
|
|
static WindowInfo *window_list_find_filename (MooEditor *editor,
|
|
|
|
const char *filename,
|
|
|
|
MooEdit **edit);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static void set_single_window (MooEditor *editor,
|
|
|
|
gboolean single);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static MooAction *create_recent_action (MooEditWindow *window);
|
2005-07-29 08:25:29 -07:00
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
static MooEditWindow *create_window (MooEditor *editor);
|
2005-09-02 16:27:25 -07:00
|
|
|
static void moo_editor_add_doc (MooEditor *editor,
|
|
|
|
MooEditWindow *window,
|
|
|
|
MooEdit *doc,
|
|
|
|
MooEditLoader *loader,
|
|
|
|
MooEditSaver *saver);
|
|
|
|
static void do_close_window (MooEditor *editor,
|
|
|
|
MooEditWindow *window);
|
|
|
|
static void do_close_doc (MooEditor *editor,
|
|
|
|
MooEdit *doc);
|
|
|
|
static gboolean close_docs_real (MooEditor *editor,
|
|
|
|
GSList *docs);
|
|
|
|
static GSList *find_modified (GSList *docs);
|
|
|
|
static MooEditLoader*get_loader (MooEditor *editor,
|
|
|
|
MooEdit *doc);
|
|
|
|
static MooEditSaver *get_saver (MooEditor *editor,
|
|
|
|
MooEdit *doc);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void activate_history_item (MooEditor *editor,
|
|
|
|
MooHistoryListItem *item,
|
2005-09-03 09:07:59 -07:00
|
|
|
MooEditWindow *window);
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
struct _MooEditorPrivate {
|
2005-09-02 16:27:25 -07:00
|
|
|
GSList *windows; /* WindowInfo* */
|
|
|
|
GHashTable *loaders;
|
|
|
|
GHashTable *savers;
|
2005-06-22 11:20:32 -07:00
|
|
|
char *app_name;
|
|
|
|
MooUIXML *ui_xml;
|
2005-09-02 16:27:25 -07:00
|
|
|
MooFilterMgr *filter_mgr;
|
2005-10-13 07:08:18 -07:00
|
|
|
MooHistoryList *history;
|
2005-10-16 22:23:40 -07:00
|
|
|
MooLangMgr *lang_mgr;
|
2005-10-13 07:08:18 -07:00
|
|
|
MooFileWatch *file_watch;
|
2005-07-31 07:53:10 -07:00
|
|
|
gboolean open_single;
|
2005-09-02 16:27:25 -07:00
|
|
|
gboolean allow_empty_window;
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean single_window;
|
2005-11-11 12:05:33 -08:00
|
|
|
|
2005-11-09 23:15:16 -08:00
|
|
|
gboolean save_backups;
|
2005-11-11 12:05:33 -08:00
|
|
|
gboolean strip_whitespace;
|
2005-11-01 18:32:07 -08:00
|
|
|
|
|
|
|
GType window_type;
|
|
|
|
GType doc_type;
|
2005-11-02 07:49:35 -08:00
|
|
|
|
|
|
|
char *default_lang;
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
static void moo_editor_finalize (GObject *object);
|
|
|
|
static void moo_editor_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void moo_editor_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2005-09-08 10:08:31 -07:00
|
|
|
PROP_OPEN_SINGLE_FILE_INSTANCE,
|
|
|
|
PROP_ALLOW_EMPTY_WINDOW,
|
2005-11-09 23:15:16 -08:00
|
|
|
PROP_SINGLE_WINDOW,
|
2005-11-11 12:05:33 -08:00
|
|
|
PROP_SAVE_BACKUPS,
|
|
|
|
PROP_STRIP_WHITESPACE
|
2005-09-03 09:07:59 -07:00
|
|
|
};
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ALL_WINDOWS_CLOSED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
|
|
|
|
|
|
|
/* MOO_TYPE_EDITOR */
|
|
|
|
G_DEFINE_TYPE (MooEditor, moo_editor, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_editor_class_init (MooEditorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2005-10-13 07:08:18 -07:00
|
|
|
MooWindowClass *edit_window_class;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
gobject_class->finalize = moo_editor_finalize;
|
2005-09-03 09:07:59 -07:00
|
|
|
gobject_class->set_property = moo_editor_set_property;
|
|
|
|
gobject_class->get_property = moo_editor_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2005-09-08 10:08:31 -07:00
|
|
|
PROP_OPEN_SINGLE_FILE_INSTANCE,
|
|
|
|
g_param_spec_boolean ("open-single-file-instance",
|
|
|
|
"open-single-file-instance",
|
|
|
|
"open-single-file-instance",
|
2005-09-03 09:07:59 -07:00
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ALLOW_EMPTY_WINDOW,
|
|
|
|
g_param_spec_boolean ("allow-empty-window",
|
|
|
|
"allow-empty-window",
|
|
|
|
"allow-empty-window",
|
2005-09-08 10:08:31 -07:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SINGLE_WINDOW,
|
|
|
|
g_param_spec_boolean ("single-window",
|
|
|
|
"single-window",
|
|
|
|
"single-window",
|
|
|
|
FALSE,
|
2005-09-03 09:07:59 -07:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-09 23:15:16 -08:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SAVE_BACKUPS,
|
|
|
|
g_param_spec_boolean ("save-backups",
|
|
|
|
"save-backups",
|
|
|
|
"save-backups",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_STRIP_WHITESPACE,
|
|
|
|
g_param_spec_boolean ("strip-whitespace",
|
|
|
|
"strip-whitespace",
|
|
|
|
"strip-whitespace",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
signals[ALL_WINDOWS_CLOSED] =
|
2005-07-31 07:53:10 -07:00
|
|
|
moo_signal_new_cb ("all-windows-closed",
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
_moo_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2005-07-30 15:15:13 -07:00
|
|
|
|
|
|
|
edit_window_class = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_window_class_new_action_custom (edit_window_class, RECENT_ACTION_ID,
|
|
|
|
(MooWindowActionFunc) create_recent_action,
|
2005-11-05 23:33:24 -08:00
|
|
|
NULL, NULL);
|
2005-07-30 15:15:13 -07:00
|
|
|
g_type_class_unref (edit_window_class);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_editor_init (MooEditor *editor)
|
|
|
|
{
|
|
|
|
editor->priv = g_new0 (MooEditorPrivate, 1);
|
2005-07-30 15:15:13 -07:00
|
|
|
|
2005-10-16 22:23:40 -07:00
|
|
|
editor->priv->lang_mgr = moo_lang_mgr_new ();
|
2005-09-02 16:27:25 -07:00
|
|
|
editor->priv->filter_mgr = moo_filter_mgr_new ();
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
editor->priv->history = moo_history_list_new ("Editor");
|
|
|
|
moo_history_list_set_display_func (editor->priv->history,
|
|
|
|
moo_history_list_display_basename,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect_swapped (editor->priv->history, "activate-item",
|
|
|
|
G_CALLBACK (activate_history_item), editor);
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
editor->priv->windows = NULL;
|
|
|
|
|
|
|
|
editor->priv->loaders =
|
|
|
|
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) moo_edit_loader_unref);
|
|
|
|
editor->priv->savers =
|
|
|
|
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) moo_edit_saver_unref);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
static void moo_editor_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MooEditor *editor = MOO_EDITOR (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2005-09-08 10:08:31 -07:00
|
|
|
case PROP_OPEN_SINGLE_FILE_INSTANCE:
|
2005-09-03 09:07:59 -07:00
|
|
|
editor->priv->open_single = g_value_get_boolean (value);
|
2005-09-08 10:08:31 -07:00
|
|
|
g_object_notify (object, "open-single-file-instance");
|
2005-09-03 09:07:59 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ALLOW_EMPTY_WINDOW:
|
|
|
|
editor->priv->allow_empty_window = g_value_get_boolean (value);
|
2005-09-08 10:08:31 -07:00
|
|
|
g_object_notify (object, "allow-empty-window");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_SINGLE_WINDOW:
|
|
|
|
set_single_window (editor, g_value_get_boolean (value));
|
2005-09-03 09:07:59 -07:00
|
|
|
break;
|
|
|
|
|
2005-11-09 23:15:16 -08:00
|
|
|
case PROP_SAVE_BACKUPS:
|
|
|
|
editor->priv->save_backups = g_value_get_boolean (value);
|
|
|
|
g_object_notify (object, "save-backups");
|
|
|
|
break;
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
case PROP_STRIP_WHITESPACE:
|
|
|
|
editor->priv->strip_whitespace = g_value_get_boolean (value);
|
|
|
|
g_object_notify (object, "strip-whitespace");
|
|
|
|
break;
|
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moo_editor_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MooEditor *editor = MOO_EDITOR (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2005-09-08 10:08:31 -07:00
|
|
|
case PROP_OPEN_SINGLE_FILE_INSTANCE:
|
2005-09-03 09:07:59 -07:00
|
|
|
g_value_set_boolean (value, editor->priv->open_single);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ALLOW_EMPTY_WINDOW:
|
|
|
|
g_value_set_boolean (value, editor->priv->allow_empty_window);
|
|
|
|
break;
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
case PROP_SINGLE_WINDOW:
|
|
|
|
g_value_set_boolean (value, editor->priv->single_window);
|
|
|
|
break;
|
|
|
|
|
2005-11-09 23:15:16 -08:00
|
|
|
case PROP_SAVE_BACKUPS:
|
|
|
|
g_value_set_boolean (value, editor->priv->save_backups);
|
|
|
|
break;
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
case PROP_STRIP_WHITESPACE:
|
|
|
|
g_value_set_boolean (value, editor->priv->strip_whitespace);
|
|
|
|
break;
|
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
static void moo_editor_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MooEditor *editor = MOO_EDITOR (object);
|
|
|
|
|
|
|
|
g_free (editor->priv->app_name);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
if (editor->priv->ui_xml)
|
|
|
|
g_object_unref (editor->priv->ui_xml);
|
2005-09-02 16:27:25 -07:00
|
|
|
if (editor->priv->filter_mgr)
|
|
|
|
g_object_unref (editor->priv->filter_mgr);
|
2005-10-13 07:08:18 -07:00
|
|
|
if (editor->priv->history)
|
|
|
|
g_object_unref (editor->priv->history);
|
2005-10-16 22:23:40 -07:00
|
|
|
g_object_unref (editor->priv->lang_mgr);
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
if (editor->priv->file_watch)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
if (!moo_file_watch_close (editor->priv->file_watch, &error))
|
|
|
|
{
|
|
|
|
g_warning ("%s: error in moo_file_watch_close", G_STRLOC);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s: %s", G_STRLOC, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref (editor->priv->file_watch);
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
if (editor->priv->windows)
|
|
|
|
{
|
|
|
|
g_critical ("finalizing editor while some windows are open");
|
|
|
|
window_list_free (editor);
|
|
|
|
}
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
g_hash_table_destroy (editor->priv->loaders);
|
|
|
|
g_hash_table_destroy (editor->priv->savers);
|
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
g_free (editor->priv->default_lang);
|
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
g_free (editor->priv);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (moo_editor_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
gpointer
|
|
|
|
_moo_editor_get_file_watch (MooEditor *editor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
|
|
|
|
if (!editor->priv->file_watch)
|
|
|
|
editor->priv->file_watch = moo_file_watch_new (NULL);
|
|
|
|
|
|
|
|
return editor->priv->file_watch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-16 10:51:20 -07:00
|
|
|
MooEditor*
|
|
|
|
moo_editor_instance (void)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-16 10:51:20 -07:00
|
|
|
if (!editor_instance)
|
|
|
|
{
|
|
|
|
editor_instance = g_object_new (MOO_TYPE_EDITOR, NULL);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (editor_instance),
|
|
|
|
(gpointer*) &editor_instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return editor_instance;
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
static GType
|
|
|
|
get_window_type (MooEditor *editor)
|
|
|
|
{
|
|
|
|
return editor->priv->window_type ?
|
|
|
|
editor->priv->window_type : MOO_TYPE_EDIT_WINDOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GType
|
|
|
|
get_doc_type (MooEditor *editor)
|
|
|
|
{
|
|
|
|
return editor->priv->doc_type ?
|
|
|
|
editor->priv->doc_type : MOO_TYPE_EDIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_single_window (MooEditor *editor,
|
|
|
|
gboolean single)
|
2005-09-08 10:08:31 -07:00
|
|
|
{
|
|
|
|
/* XXX */
|
|
|
|
editor->priv->single_window = single;
|
|
|
|
g_object_notify (G_OBJECT (editor), "single-window");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
static MooEditWindow*
|
|
|
|
get_top_window (MooEditor *editor)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
GSList *list = NULL, *l;
|
|
|
|
GtkWindow *window;
|
2005-07-29 08:25:29 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
if (!editor->priv->windows)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
for (l = editor->priv->windows; l != NULL; l = l->next)
|
2005-07-25 10:56:59 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
WindowInfo *info = l->data;
|
|
|
|
list = g_slist_prepend (list, info->window);
|
2005-07-31 07:53:10 -07:00
|
|
|
}
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
list = g_slist_reverse (list);
|
|
|
|
window = moo_get_top_window (list);
|
2005-07-31 07:53:10 -07:00
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
g_slist_free (list);
|
|
|
|
return MOO_EDIT_WINDOW (window);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
static void file_info_list_free (GSList *list)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
g_slist_foreach (list, (GFunc) moo_edit_file_info_free, NULL);
|
2005-06-22 11:20:32 -07:00
|
|
|
g_slist_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
void
|
|
|
|
moo_editor_set_app_name (MooEditor *editor,
|
|
|
|
const char *name)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
|
|
|
|
g_free (editor->priv->app_name);
|
|
|
|
editor->priv->app_name = g_strdup (name);
|
|
|
|
|
|
|
|
for (l = editor->priv->windows; l != NULL; l = l->next)
|
2005-09-07 04:19:26 -07:00
|
|
|
moo_edit_window_set_title_prefix (MOO_EDIT_WINDOW (l->data), name);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
MooFilterMgr*
|
|
|
|
moo_editor_get_filter_mgr (MooEditor *editor)
|
2005-07-28 12:25:10 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
2005-09-02 16:27:25 -07:00
|
|
|
return editor->priv->filter_mgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
MooHistoryList*
|
|
|
|
moo_editor_get_history (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
return editor->priv->history;
|
2005-07-28 12:25:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
MooUIXML*
|
|
|
|
moo_editor_get_ui_xml (MooEditor *editor)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
|
|
|
|
if (!editor->priv->ui_xml)
|
|
|
|
editor->priv->ui_xml = moo_ui_xml_new ();
|
|
|
|
|
|
|
|
return editor->priv->ui_xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
void
|
|
|
|
moo_editor_set_ui_xml (MooEditor *editor,
|
|
|
|
MooUIXML *xml)
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
|
|
|
|
if (editor->priv->ui_xml == xml)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (editor->priv->ui_xml)
|
|
|
|
g_object_unref (editor->priv->ui_xml);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-06-22 11:20:32 -07:00
|
|
|
editor->priv->ui_xml = xml;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
if (editor->priv->ui_xml)
|
2005-06-22 11:20:32 -07:00
|
|
|
g_object_ref (editor->priv->ui_xml);
|
|
|
|
|
|
|
|
for (l = editor->priv->windows; l != NULL; l = l->next)
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_window_set_ui_xml (l->data, editor->priv->ui_xml);
|
2005-06-22 11:20:32 -07:00
|
|
|
}
|
2005-07-29 08:25:29 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static WindowInfo*
|
|
|
|
window_info_new (MooEditWindow *win)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
WindowInfo *w = g_new0 (WindowInfo, 1);
|
2005-09-02 16:27:25 -07:00
|
|
|
w->window = win;
|
2005-07-29 08:25:29 -07:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
window_info_free (WindowInfo *win)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
if (win)
|
|
|
|
{
|
|
|
|
g_slist_free (win->docs);
|
|
|
|
g_free (win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
window_info_add (WindowInfo *win,
|
|
|
|
MooEdit *edit)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (!g_slist_find (win->docs, edit));
|
2005-09-03 11:02:59 -07:00
|
|
|
win->docs = g_slist_append (win->docs, edit);
|
2005-07-29 08:25:29 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
window_info_remove (WindowInfo *win,
|
|
|
|
MooEdit *edit)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
g_return_if_fail (g_slist_find (win->docs, edit));
|
|
|
|
win->docs = g_slist_remove (win->docs, edit);
|
|
|
|
}
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static int
|
|
|
|
edit_and_file_cmp (MooEdit *edit, const char *filename)
|
2005-07-31 07:53:10 -07:00
|
|
|
{
|
|
|
|
const char *edit_filename;
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (edit) && filename != NULL, TRUE);
|
|
|
|
edit_filename = moo_edit_get_filename (edit);
|
|
|
|
if (edit_filename)
|
|
|
|
return strcmp (edit_filename, filename);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static MooEdit*
|
|
|
|
window_info_find (WindowInfo *win,
|
|
|
|
const char *filename)
|
2005-07-31 07:53:10 -07:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
g_return_val_if_fail (win != NULL && filename != NULL, NULL);
|
|
|
|
l = g_slist_find_custom (win->docs, filename,
|
|
|
|
(GCompareFunc) edit_and_file_cmp);
|
|
|
|
return l ? l->data : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
window_list_free (MooEditor *editor)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
g_slist_foreach (editor->priv->windows,
|
2005-07-29 08:25:29 -07:00
|
|
|
(GFunc) window_info_free, NULL);
|
2005-09-02 16:27:25 -07:00
|
|
|
g_slist_free (editor->priv->windows);
|
|
|
|
editor->priv->windows = NULL;
|
2005-07-29 08:25:29 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
window_list_delete (MooEditor *editor,
|
|
|
|
WindowInfo *win)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
g_return_if_fail (g_slist_find (editor->priv->windows, win));
|
2005-07-29 08:25:29 -07:00
|
|
|
window_info_free (win);
|
2005-09-02 16:27:25 -07:00
|
|
|
editor->priv->windows =
|
|
|
|
g_slist_remove (editor->priv->windows, win);
|
2005-07-29 08:25:29 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static WindowInfo*
|
|
|
|
window_list_add (MooEditor *editor,
|
|
|
|
MooEditWindow *win)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
WindowInfo *w = window_info_new (win);
|
2005-09-02 16:27:25 -07:00
|
|
|
editor->priv->windows =
|
|
|
|
g_slist_prepend (editor->priv->windows, w);
|
2005-07-29 08:25:29 -07:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static int
|
|
|
|
window_cmp (WindowInfo *w, MooEditWindow *e)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
2005-07-31 07:53:10 -07:00
|
|
|
g_return_val_if_fail (w != NULL, TRUE);
|
2005-09-02 16:27:25 -07:00
|
|
|
return !(w->window == e);
|
2005-07-29 08:25:29 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static WindowInfo*
|
|
|
|
window_list_find (MooEditor *editor,
|
|
|
|
MooEditWindow *win)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
GSList *l = g_slist_find_custom (editor->priv->windows, win,
|
2005-07-29 08:25:29 -07:00
|
|
|
(GCompareFunc) window_cmp);
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static int
|
|
|
|
doc_cmp (WindowInfo *w, MooEdit *e)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (w != NULL, 1);
|
|
|
|
return !g_slist_find (w->docs, e);
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static WindowInfo*
|
|
|
|
window_list_find_doc (MooEditor *editor,
|
|
|
|
MooEdit *edit)
|
2005-07-29 08:25:29 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
GSList *l = g_slist_find_custom (editor->priv->windows, edit,
|
2005-07-29 08:25:29 -07:00
|
|
|
(GCompareFunc) doc_cmp);
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-30 15:15:13 -07:00
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static int
|
|
|
|
filename_and_doc_cmp (WindowInfo *w, gpointer user_data)
|
2005-07-31 07:53:10 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
struct {
|
|
|
|
const char *filename;
|
|
|
|
MooEdit *edit;
|
|
|
|
} *data = user_data;
|
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
g_return_val_if_fail (w != NULL, TRUE);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-07-31 07:53:10 -07:00
|
|
|
data->edit = window_info_find (w, data->filename);
|
|
|
|
return data->edit == NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static WindowInfo*
|
|
|
|
window_list_find_filename (MooEditor *editor,
|
|
|
|
const char *filename,
|
|
|
|
MooEdit **edit)
|
2005-07-31 07:53:10 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
struct {
|
|
|
|
const char *filename;
|
|
|
|
MooEdit *edit;
|
|
|
|
} data = {filename, NULL};
|
|
|
|
|
|
|
|
GSList *l = g_slist_find_custom (editor->priv->windows, &data,
|
2005-07-31 07:53:10 -07:00
|
|
|
(GCompareFunc) filename_and_doc_cmp);
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
g_assert (data.edit != NULL);
|
|
|
|
if (edit) *edit = data.edit;
|
|
|
|
return l->data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static MooAction*
|
|
|
|
create_recent_action (MooEditWindow *window)
|
2005-09-03 15:46:44 -07:00
|
|
|
{
|
2005-09-04 11:41:13 -07:00
|
|
|
MooEditor *editor = moo_edit_window_get_editor (window);
|
2005-10-13 07:08:18 -07:00
|
|
|
MooAction *action;
|
|
|
|
MooMenuMgr *mgr;
|
2005-09-03 15:46:44 -07:00
|
|
|
|
2005-07-30 15:15:13 -07:00
|
|
|
g_return_val_if_fail (editor != NULL, NULL);
|
2005-09-03 15:46:44 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
action = moo_menu_action_new (RECENT_ACTION_ID);
|
2005-11-02 12:45:26 -08:00
|
|
|
g_object_set (action, "no-accel", TRUE, NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
mgr = moo_history_list_get_menu_mgr (editor->priv->history);
|
|
|
|
moo_menu_action_set_mgr (MOO_MENU_ACTION (action), mgr);
|
|
|
|
moo_menu_action_set_menu_data (MOO_MENU_ACTION (action), window, TRUE);
|
|
|
|
moo_menu_action_set_menu_label (MOO_MENU_ACTION (action), "Open Recent");
|
2005-09-03 15:46:44 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_bind_bool_property (action, "sensitive",
|
|
|
|
editor->priv->history, "empty", TRUE);
|
|
|
|
|
|
|
|
return action;
|
2005-07-30 15:15:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
static void
|
|
|
|
activate_history_item (MooEditor *editor,
|
|
|
|
MooHistoryListItem *item,
|
|
|
|
MooEditWindow *window)
|
2005-07-30 15:15:13 -07:00
|
|
|
{
|
|
|
|
WindowInfo *win_info;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
2005-10-13 07:08:18 -07:00
|
|
|
g_return_if_fail (item != NULL && item->data != NULL);
|
2005-07-30 15:15:13 -07:00
|
|
|
|
|
|
|
win_info = window_list_find (editor, window);
|
|
|
|
g_return_if_fail (win_info != NULL);
|
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
if (!moo_editor_open_file (editor, window, GTK_WIDGET (window), item->data, NULL))
|
|
|
|
moo_history_list_remove (editor->priv->history, item->data);
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
static MooEditWindow*
|
|
|
|
create_window (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
2005-11-01 18:32:07 -08:00
|
|
|
MooEditWindow *window = g_object_new (get_window_type (editor),
|
2005-09-15 09:37:30 -07:00
|
|
|
"editor", editor,
|
2005-10-13 07:08:18 -07:00
|
|
|
"ui-xml",
|
2005-09-15 09:37:30 -07:00
|
|
|
moo_editor_get_ui_xml (editor),
|
|
|
|
NULL);
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_edit_window_set_title_prefix (window, editor->priv->app_name);
|
2005-09-02 16:27:25 -07:00
|
|
|
window_list_add (editor, window);
|
2005-09-11 23:57:29 -07:00
|
|
|
_moo_window_attach_plugins (window);
|
2005-09-07 04:19:26 -07:00
|
|
|
gtk_widget_show (GTK_WIDGET (window));
|
|
|
|
return window;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
static void
|
|
|
|
moo_editor_add_doc (MooEditor *editor,
|
|
|
|
MooEditWindow *window,
|
|
|
|
MooEdit *doc,
|
|
|
|
MooEditLoader *loader,
|
|
|
|
MooEditSaver *saver)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info = window_list_find (editor, window);
|
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
g_return_if_fail (g_slist_find (info->docs, doc) == NULL);
|
|
|
|
|
|
|
|
window_info_add (info, doc);
|
|
|
|
|
|
|
|
g_hash_table_insert (editor->priv->loaders, doc, moo_edit_loader_ref (loader));
|
|
|
|
g_hash_table_insert (editor->priv->savers, doc, moo_edit_saver_ref (saver));
|
2005-11-02 07:49:35 -08:00
|
|
|
|
2005-11-05 04:34:09 -08:00
|
|
|
if (!moo_edit_get_filename (doc) &&
|
2005-11-24 06:14:48 -08:00
|
|
|
!moo_edit_get_string (doc, MOO_EDIT_VAR_LANG) &&
|
|
|
|
editor->priv->default_lang)
|
|
|
|
{
|
|
|
|
moo_edit_set_string (doc, MOO_EDIT_VAR_LANG,
|
|
|
|
editor->priv->default_lang,
|
|
|
|
MOO_EDIT_VAR_DEP_AUTO);
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
MooEditWindow*
|
|
|
|
moo_editor_new_window (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
MooEditWindow *window;
|
|
|
|
MooEdit *doc;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
window = create_window (editor);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-07 04:19:26 -07:00
|
|
|
if (!editor->priv->allow_empty_window)
|
|
|
|
{
|
2005-11-01 18:32:07 -08:00
|
|
|
doc = g_object_new (get_doc_type (editor), "editor", editor, NULL);
|
2005-09-07 04:19:26 -07:00
|
|
|
_moo_edit_window_insert_doc (window, doc, -1);
|
|
|
|
moo_editor_add_doc (editor, window, doc,
|
|
|
|
moo_edit_loader_get_default (),
|
|
|
|
moo_edit_saver_get_default ());
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
MooEdit*
|
|
|
|
moo_editor_new_doc (MooEditor *editor,
|
|
|
|
MooEditWindow *window)
|
2005-09-02 23:25:43 -07:00
|
|
|
{
|
|
|
|
MooEdit *doc;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
2005-11-11 12:05:33 -08:00
|
|
|
g_return_val_if_fail (!window || MOO_IS_EDIT_WINDOW (window), NULL);
|
|
|
|
g_return_val_if_fail (!window || window_list_find (editor, window) != NULL, NULL);
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
window = get_top_window (editor);
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
window = moo_editor_new_window (editor);
|
|
|
|
|
|
|
|
g_return_val_if_fail (window != NULL, NULL);
|
2005-09-02 23:25:43 -07:00
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
doc = g_object_new (get_doc_type (editor), "editor", editor, NULL);
|
2005-09-02 23:25:43 -07:00
|
|
|
_moo_edit_window_insert_doc (window, doc, -1);
|
|
|
|
moo_editor_add_doc (editor, window, doc,
|
|
|
|
moo_edit_loader_get_default (),
|
|
|
|
moo_edit_saver_get_default ());
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
gboolean
|
|
|
|
moo_editor_open (MooEditor *editor,
|
|
|
|
MooEditWindow *window,
|
|
|
|
GtkWidget *parent,
|
|
|
|
GSList *files)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
MooEditLoader *loader;
|
|
|
|
MooEditSaver *saver;
|
2005-09-03 09:07:59 -07:00
|
|
|
MooEdit *bring_to_front = NULL;
|
2005-11-02 07:49:35 -08:00
|
|
|
gboolean result = TRUE;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
g_return_val_if_fail (!window || MOO_IS_EDIT_WINDOW (window), FALSE);
|
|
|
|
g_return_val_if_fail (!parent || GTK_IS_WIDGET (parent), FALSE);
|
|
|
|
g_return_val_if_fail (!window || window_list_find (editor, window) != NULL, FALSE);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
if (window && !parent)
|
|
|
|
parent = GTK_WIDGET (window);
|
|
|
|
|
|
|
|
if (!files)
|
|
|
|
{
|
|
|
|
files = moo_edit_open_dialog (parent, editor->priv->filter_mgr);
|
|
|
|
|
|
|
|
if (!files)
|
2005-11-02 07:49:35 -08:00
|
|
|
return FALSE;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
result = moo_editor_open (editor, window, parent, files);
|
2005-09-02 16:27:25 -07:00
|
|
|
file_info_list_free (files);
|
2005-11-02 07:49:35 -08:00
|
|
|
|
|
|
|
return result;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
loader = moo_edit_loader_get_default ();
|
|
|
|
saver = moo_edit_saver_get_default ();
|
|
|
|
|
|
|
|
for (l = files; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
MooEditFileInfo *info = l->data;
|
|
|
|
GError *error = NULL;
|
2005-09-03 09:07:59 -07:00
|
|
|
gboolean new_doc = FALSE;
|
|
|
|
MooEdit *doc = NULL;
|
|
|
|
|
|
|
|
if (window_list_find_filename (editor, info->filename, &bring_to_front))
|
|
|
|
{
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_history_list_add_filename (editor->priv->history, info->filename);
|
2005-09-03 09:07:59 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bring_to_front = NULL;
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
doc = moo_edit_window_get_active_doc (window);
|
|
|
|
if (doc && moo_edit_is_empty (doc))
|
|
|
|
g_object_ref (doc);
|
|
|
|
else
|
|
|
|
doc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!doc)
|
|
|
|
{
|
2005-11-01 18:32:07 -08:00
|
|
|
doc = g_object_new (get_doc_type (editor), "editor", editor, NULL);
|
2005-09-03 09:07:59 -07:00
|
|
|
gtk_object_sink (g_object_ref (doc));
|
|
|
|
new_doc = TRUE;
|
|
|
|
}
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
/* XXX open_single */
|
2005-11-11 12:05:33 -08:00
|
|
|
if (!moo_edit_loader_load (loader, doc, info->filename, info->encoding, &error))
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
2005-11-26 07:40:49 -08:00
|
|
|
moo_edit_open_error_dialog (parent, info->filename,
|
|
|
|
error ? error->message : NULL);
|
2005-09-16 16:45:55 -07:00
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2005-11-02 07:49:35 -08:00
|
|
|
result = FALSE;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-08 10:08:31 -07:00
|
|
|
if (!window)
|
|
|
|
window = moo_editor_get_active_window (editor);
|
2005-09-02 16:27:25 -07:00
|
|
|
if (!window)
|
2005-09-07 04:19:26 -07:00
|
|
|
window = create_window (editor);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-03 09:07:59 -07:00
|
|
|
if (new_doc)
|
|
|
|
{
|
|
|
|
_moo_edit_window_insert_doc (window, doc, -1);
|
|
|
|
moo_editor_add_doc (editor, window, doc, loader, saver);
|
|
|
|
}
|
2005-09-04 11:41:13 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bring_to_front = doc;
|
|
|
|
}
|
2005-09-03 09:07:59 -07:00
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_history_list_add_filename (editor->priv->history, info->filename);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
parent = GTK_WIDGET (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (doc);
|
|
|
|
}
|
2005-09-03 09:07:59 -07:00
|
|
|
|
|
|
|
if (bring_to_front)
|
2005-09-04 11:41:13 -07:00
|
|
|
{
|
2005-09-03 09:07:59 -07:00
|
|
|
moo_editor_set_active_doc (editor, bring_to_front);
|
2005-09-04 11:41:13 -07:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (bring_to_front));
|
|
|
|
}
|
2005-11-02 07:49:35 -08:00
|
|
|
|
|
|
|
return result;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
MooEdit*
|
|
|
|
moo_editor_get_active_doc (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
MooEditWindow *window = moo_editor_get_active_window (editor);
|
|
|
|
return window ? moo_edit_window_get_active_doc (window) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
MooEditWindow*
|
|
|
|
moo_editor_get_active_window (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
return get_top_window (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
void
|
|
|
|
moo_editor_present (MooEditor *editor)
|
|
|
|
{
|
|
|
|
MooEditWindow *window;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
|
|
|
|
window = moo_editor_get_active_window (editor);
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
window = moo_editor_new_window (editor);
|
|
|
|
|
|
|
|
g_return_if_fail (window != NULL);
|
|
|
|
moo_window_present (GTK_WINDOW (window));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_editor_set_active_window (MooEditor *editor,
|
|
|
|
MooEditWindow *window)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
|
|
|
|
|
|
|
info = window_list_find (editor, window);
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (info->window));
|
2005-07-30 15:15:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
void
|
|
|
|
moo_editor_set_active_doc (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-07-30 15:15:13 -07:00
|
|
|
{
|
2005-09-02 16:27:25 -07:00
|
|
|
WindowInfo *info;
|
|
|
|
|
2005-07-30 15:15:13 -07:00
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
2005-09-02 16:27:25 -07:00
|
|
|
g_return_if_fail (MOO_IS_EDIT (doc));
|
|
|
|
|
|
|
|
info = window_list_find_doc (editor, doc);
|
2005-07-30 15:15:13 -07:00
|
|
|
g_return_if_fail (info != NULL);
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (info->window));
|
|
|
|
moo_edit_window_set_active_doc (info->window, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
gboolean
|
|
|
|
moo_editor_close_window (MooEditor *editor,
|
|
|
|
MooEditWindow *window)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
MooEditDialogResponse response;
|
|
|
|
GSList *modified;
|
|
|
|
gboolean do_close = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
|
|
|
|
|
|
|
info = window_list_find (editor, window);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
modified = find_modified (info->docs);
|
|
|
|
|
|
|
|
if (!modified)
|
|
|
|
{
|
|
|
|
do_close = TRUE;
|
|
|
|
}
|
|
|
|
else if (!modified->next)
|
|
|
|
{
|
|
|
|
moo_edit_window_set_active_doc (info->window, modified->data);
|
|
|
|
response = moo_edit_save_changes_dialog (modified->data);
|
|
|
|
|
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case MOO_EDIT_RESPONSE_SAVE:
|
|
|
|
if (_moo_editor_save (editor, modified->data))
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOO_EDIT_RESPONSE_CANCEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSList *to_save = NULL, *l;
|
|
|
|
gboolean saved = TRUE;
|
|
|
|
|
|
|
|
response = moo_edit_save_multiple_changes_dialog (modified, &to_save);
|
|
|
|
|
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case MOO_EDIT_RESPONSE_SAVE:
|
|
|
|
for (l = to_save; l != NULL; l = l->next)
|
|
|
|
if (!_moo_editor_save (editor, l->data))
|
|
|
|
{
|
|
|
|
saved = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saved)
|
|
|
|
do_close = TRUE;
|
|
|
|
|
|
|
|
g_slist_free (to_save);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOO_EDIT_RESPONSE_CANCEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_close)
|
|
|
|
do_close_window (editor, window);
|
|
|
|
|
|
|
|
g_slist_free (modified);
|
|
|
|
return do_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 18:32:07 -08:00
|
|
|
static void
|
|
|
|
do_close_window (MooEditor *editor,
|
|
|
|
MooEditWindow *window)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
GSList *l, *list;
|
|
|
|
|
|
|
|
info = window_list_find (editor, window);
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
list = g_slist_copy (info->docs);
|
|
|
|
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
|
|
|
do_close_doc (editor, l->data);
|
|
|
|
|
|
|
|
window_list_delete (editor, info);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
_moo_window_detach_plugins (window);
|
2005-09-07 04:19:26 -07:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (window));
|
2005-09-02 16:27:25 -07:00
|
|
|
|
2005-09-02 23:25:43 -07:00
|
|
|
if (!editor->priv->windows)
|
|
|
|
g_signal_emit (editor, signals[ALL_WINDOWS_CLOSED], 0);
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
g_slist_free (list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static void
|
|
|
|
do_close_doc (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info = window_list_find_doc (editor, doc);
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
window_info_remove (info, doc);
|
|
|
|
_moo_edit_window_remove_doc (info->window, doc);
|
|
|
|
g_hash_table_remove (editor->priv->loaders, doc);
|
|
|
|
g_hash_table_remove (editor->priv->savers, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean
|
|
|
|
moo_editor_close_doc (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
list = g_slist_prepend (NULL, doc);
|
|
|
|
result = moo_editor_close_docs (editor, list);
|
|
|
|
|
|
|
|
g_slist_free (list);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean
|
|
|
|
moo_editor_close_docs (MooEditor *editor,
|
|
|
|
GSList *list)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
g_return_val_if_fail (list != NULL, FALSE);
|
|
|
|
|
|
|
|
for (l = list; l != NULL; l = l->next)
|
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
MooEdit *doc = l->data;
|
|
|
|
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
|
|
|
|
g_return_val_if_fail (window_list_find_doc (editor, doc) != NULL, FALSE);
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do i care? */
|
2005-09-02 23:25:43 -07:00
|
|
|
info = window_list_find_doc (editor, list->data);
|
2005-09-02 16:27:25 -07:00
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
if (close_docs_real (editor, list))
|
|
|
|
{
|
|
|
|
if (!moo_edit_window_num_docs (info->window) &&
|
|
|
|
!editor->priv->allow_empty_window)
|
|
|
|
{
|
2005-11-01 18:32:07 -08:00
|
|
|
MooEdit *doc = g_object_new (get_doc_type (editor),
|
|
|
|
"editor", editor, NULL);
|
2005-09-02 16:27:25 -07:00
|
|
|
_moo_edit_window_insert_doc (info->window, doc, -1);
|
|
|
|
moo_editor_add_doc (editor, info->window, doc,
|
|
|
|
moo_edit_loader_get_default (),
|
|
|
|
moo_edit_saver_get_default ());
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static gboolean
|
|
|
|
close_docs_real (MooEditor *editor,
|
|
|
|
GSList *docs)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
MooEditDialogResponse response;
|
|
|
|
GSList *modified, *l;
|
|
|
|
gboolean do_close = FALSE;
|
|
|
|
|
|
|
|
modified = find_modified (docs);
|
|
|
|
|
|
|
|
if (!modified)
|
|
|
|
{
|
|
|
|
do_close = TRUE;
|
|
|
|
}
|
|
|
|
else if (!modified->next)
|
|
|
|
{
|
2005-09-02 23:25:43 -07:00
|
|
|
WindowInfo *info = window_list_find_doc (editor, modified->data);
|
2005-09-02 16:27:25 -07:00
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
moo_edit_window_set_active_doc (info->window, modified->data);
|
|
|
|
response = moo_edit_save_changes_dialog (modified->data);
|
|
|
|
|
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case MOO_EDIT_RESPONSE_SAVE:
|
|
|
|
if (_moo_editor_save (editor, modified->data))
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOO_EDIT_RESPONSE_CANCEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSList *to_save = NULL;
|
|
|
|
gboolean saved = TRUE;
|
|
|
|
|
|
|
|
response = moo_edit_save_multiple_changes_dialog (modified, &to_save);
|
|
|
|
|
|
|
|
switch (response)
|
|
|
|
{
|
|
|
|
case MOO_EDIT_RESPONSE_SAVE:
|
|
|
|
for (l = to_save; l != NULL; l = l->next)
|
|
|
|
if (!_moo_editor_save (editor, l->data))
|
|
|
|
{
|
|
|
|
saved = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saved)
|
|
|
|
do_close = TRUE;
|
|
|
|
|
|
|
|
g_slist_free (to_save);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOO_EDIT_RESPONSE_CANCEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
do_close = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_close)
|
|
|
|
for (l = docs; l != NULL; l = l->next)
|
|
|
|
do_close_doc (editor, l->data);
|
|
|
|
|
|
|
|
g_slist_free (modified);
|
|
|
|
return do_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static GSList*
|
|
|
|
find_modified (GSList *docs)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
GSList *modified = NULL, *l;
|
|
|
|
for (l = docs; l != NULL; l = l->next)
|
|
|
|
if (MOO_EDIT_IS_MODIFIED (l->data) && !MOO_EDIT_IS_CLEAN (l->data))
|
|
|
|
modified = g_slist_prepend (modified, l->data);
|
|
|
|
return g_slist_reverse (modified);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean
|
|
|
|
moo_editor_close_all (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
GSList *windows, *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
|
|
|
|
windows = moo_editor_list_windows (editor);
|
|
|
|
|
|
|
|
for (l = windows; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
if (!moo_editor_close_window (editor, l->data))
|
|
|
|
{
|
|
|
|
g_slist_free (windows);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (windows);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
GSList*
|
|
|
|
moo_editor_list_windows (MooEditor *editor)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
GSList *windows = NULL, *l;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
|
|
|
|
for (l = editor->priv->windows; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
WindowInfo *info = l->data;
|
|
|
|
windows = g_slist_prepend (windows, info->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_slist_reverse (windows);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-02 07:49:35 -08:00
|
|
|
gboolean
|
2005-09-08 10:08:31 -07:00
|
|
|
moo_editor_open_file (MooEditor *editor,
|
|
|
|
MooEditWindow *window,
|
|
|
|
GtkWidget *parent,
|
|
|
|
const char *filename,
|
|
|
|
const char *encoding)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
MooEditFileInfo *info;
|
|
|
|
GSList *list;
|
2005-11-02 07:49:35 -08:00
|
|
|
gboolean result;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return moo_editor_open (editor, window, parent, NULL);
|
|
|
|
|
|
|
|
info = moo_edit_file_info_new (filename, encoding);
|
|
|
|
list = g_slist_prepend (NULL, info);
|
2005-11-02 07:49:35 -08:00
|
|
|
result = moo_editor_open (editor, window, parent, list);
|
|
|
|
|
2005-09-02 16:27:25 -07:00
|
|
|
moo_edit_file_info_free (info);
|
|
|
|
g_slist_free (list);
|
2005-11-02 07:49:35 -08:00
|
|
|
return result;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
void
|
|
|
|
_moo_editor_reload (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
MooEditLoader *loader;
|
|
|
|
GError *error = NULL;
|
2005-11-09 23:15:16 -08:00
|
|
|
int cursor_line, cursor_offset;
|
|
|
|
GtkTextIter iter;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
|
|
|
|
info = window_list_find_doc (editor, doc);
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
|
|
|
loader = get_loader (editor, doc);
|
|
|
|
g_return_if_fail (loader != NULL);
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
g_return_if_fail (moo_edit_get_filename (doc) != NULL);
|
|
|
|
|
|
|
|
if (!MOO_EDIT_IS_CLEAN (doc) && MOO_EDIT_IS_MODIFIED (doc) &&
|
2005-09-02 23:25:43 -07:00
|
|
|
!moo_edit_reload_modified_dialog (doc))
|
2005-09-02 16:27:25 -07:00
|
|
|
return;
|
|
|
|
|
2005-11-09 23:15:16 -08:00
|
|
|
moo_text_view_get_cursor (MOO_TEXT_VIEW (doc), &iter);
|
|
|
|
cursor_line = gtk_text_iter_get_line (&iter);
|
|
|
|
cursor_offset = gtk_text_iter_get_line_offset (&iter);
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
if (!moo_edit_loader_reload (loader, doc, &error))
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
moo_edit_reload_error_dialog (GTK_WIDGET (doc),
|
|
|
|
error ? error->message : NULL);
|
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2005-11-09 23:15:16 -08:00
|
|
|
g_object_set_data (G_OBJECT (doc), "moo-scroll-to", NULL);
|
|
|
|
return;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
2005-11-09 23:15:16 -08:00
|
|
|
|
|
|
|
moo_text_view_move_cursor (MOO_TEXT_VIEW (doc), cursor_line,
|
|
|
|
cursor_offset, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MooEditSaveFlags
|
|
|
|
moo_editor_get_save_flags (MooEditor *editor)
|
|
|
|
{
|
|
|
|
MooEditSaveFlags flags = 0;
|
|
|
|
|
|
|
|
if (editor->priv->save_backups)
|
|
|
|
flags |= MOO_EDIT_SAVE_BACKUP;
|
|
|
|
|
|
|
|
return flags;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
static gboolean
|
|
|
|
do_save (MooEditor *editor,
|
|
|
|
MooEditSaver *saver,
|
|
|
|
MooEdit *doc,
|
|
|
|
const char *filename,
|
|
|
|
const char *encoding,
|
|
|
|
GError **error)
|
|
|
|
{
|
2005-11-23 03:10:03 -08:00
|
|
|
gboolean result;
|
2005-11-24 06:14:48 -08:00
|
|
|
gboolean strip;
|
2005-11-11 12:05:33 -08:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
strip = moo_edit_get_bool (doc, MOO_EDIT_VAR_STRIP, FALSE);
|
2005-11-11 12:05:33 -08:00
|
|
|
|
2005-11-24 06:14:48 -08:00
|
|
|
if (strip)
|
2005-11-11 12:05:33 -08:00
|
|
|
moo_text_view_strip_whitespace (MOO_TEXT_VIEW (doc));
|
|
|
|
|
2005-11-23 03:10:03 -08:00
|
|
|
g_signal_emit_by_name (doc, "save-before");
|
|
|
|
result = moo_edit_saver_save (saver, doc, filename, encoding,
|
|
|
|
moo_editor_get_save_flags (editor), error);
|
|
|
|
g_signal_emit_by_name (doc, "save-after");
|
|
|
|
|
|
|
|
return result;
|
2005-11-11 12:05:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean
|
|
|
|
_moo_editor_save (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
MooEditSaver *saver;
|
|
|
|
GError *error = NULL;
|
2005-10-13 07:08:18 -07:00
|
|
|
char *filename;
|
|
|
|
char *encoding;
|
2005-09-03 15:46:44 -07:00
|
|
|
gboolean result = FALSE;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
|
|
|
|
info = window_list_find_doc (editor, doc);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
saver = get_saver (editor, doc);
|
|
|
|
g_return_val_if_fail (saver != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!moo_edit_get_filename (doc))
|
|
|
|
return _moo_editor_save_as (editor, doc, NULL, NULL);
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
filename = g_strdup (moo_edit_get_filename (doc));
|
|
|
|
encoding = g_strdup (moo_edit_get_encoding (doc));
|
2005-09-03 11:02:59 -07:00
|
|
|
|
2005-09-03 15:46:44 -07:00
|
|
|
if ((moo_edit_get_status (doc) & MOO_EDIT_MODIFIED_ON_DISK) &&
|
|
|
|
!moo_edit_overwrite_modified_dialog (doc))
|
|
|
|
goto out;
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
if (!do_save (editor, saver, doc, filename, encoding, &error))
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
2005-11-26 07:40:49 -08:00
|
|
|
moo_edit_save_error_dialog (GTK_WIDGET (doc), filename,
|
2005-09-02 16:27:25 -07:00
|
|
|
error ? error->message : NULL);
|
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2005-09-03 15:46:44 -07:00
|
|
|
goto out;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_history_list_add_filename (editor->priv->history, filename);
|
2005-09-03 15:46:44 -07:00
|
|
|
result = TRUE;
|
2005-09-03 09:07:59 -07:00
|
|
|
|
2005-09-03 15:46:44 -07:00
|
|
|
/* fall through */
|
|
|
|
out:
|
2005-10-13 07:08:18 -07:00
|
|
|
g_free (filename);
|
|
|
|
g_free (encoding);
|
2005-09-03 15:46:44 -07:00
|
|
|
return result;
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
gboolean
|
|
|
|
_moo_editor_save_as (MooEditor *editor,
|
|
|
|
MooEdit *doc,
|
|
|
|
const char *filename,
|
|
|
|
const char *encoding)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
MooEditSaver *saver;
|
|
|
|
GError *error = NULL;
|
|
|
|
MooEditFileInfo *file_info = NULL;
|
2005-09-03 11:02:59 -07:00
|
|
|
gboolean result = FALSE;
|
2005-09-02 16:27:25 -07:00
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
|
|
|
|
info = window_list_find_doc (editor, doc);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
saver = get_saver (editor, doc);
|
|
|
|
g_return_val_if_fail (saver != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
file_info = moo_edit_save_as_dialog (doc, editor->priv->filter_mgr);
|
|
|
|
|
|
|
|
if (!file_info)
|
2005-09-03 11:02:59 -07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_info = moo_edit_file_info_new (filename, encoding);
|
2005-09-02 16:27:25 -07:00
|
|
|
}
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
if (!do_save (editor, saver, doc, file_info->filename, file_info->encoding, &error))
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
2005-11-26 07:40:49 -08:00
|
|
|
moo_edit_save_error_dialog (GTK_WIDGET (doc), file_info->filename,
|
2005-09-02 16:27:25 -07:00
|
|
|
error ? error->message : NULL);
|
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-10-13 07:08:18 -07:00
|
|
|
moo_history_list_add_filename (editor->priv->history, file_info->filename);
|
2005-09-02 16:27:25 -07:00
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
out:
|
|
|
|
moo_edit_file_info_free (file_info);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 20:41:09 -08:00
|
|
|
gboolean
|
|
|
|
moo_editor_save_copy (MooEditor *editor,
|
|
|
|
MooEdit *doc,
|
|
|
|
const char *filename,
|
|
|
|
const char *encoding,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
WindowInfo *info;
|
|
|
|
MooEditSaver *saver;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
|
|
|
|
info = window_list_find_doc (editor, doc);
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
saver = get_saver (editor, doc);
|
|
|
|
g_return_val_if_fail (saver != NULL, FALSE);
|
|
|
|
|
2005-11-11 12:05:33 -08:00
|
|
|
return moo_edit_saver_save_copy (saver, doc, filename, encoding, error);
|
2005-11-01 20:41:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static MooEditLoader*
|
|
|
|
get_loader (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
return g_hash_table_lookup (editor->priv->loaders, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 10:08:31 -07:00
|
|
|
static MooEditSaver*
|
|
|
|
get_saver (MooEditor *editor,
|
|
|
|
MooEdit *doc)
|
2005-09-02 16:27:25 -07:00
|
|
|
{
|
|
|
|
return g_hash_table_lookup (editor->priv->savers, doc);
|
2005-07-30 15:15:13 -07:00
|
|
|
}
|
2005-09-08 10:08:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
MooEdit*
|
|
|
|
moo_editor_get_doc (MooEditor *editor,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
MooEdit *doc = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
|
|
|
window_list_find_filename (editor, filename, &doc);
|
|
|
|
return doc;
|
|
|
|
}
|
2005-10-13 07:08:18 -07:00
|
|
|
|
|
|
|
|
2005-10-16 22:23:40 -07:00
|
|
|
MooLangMgr*
|
|
|
|
moo_editor_get_lang_mgr (MooEditor *editor)
|
2005-10-13 07:08:18 -07:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
2005-10-16 22:23:40 -07:00
|
|
|
return editor->priv->lang_mgr;
|
2005-10-13 07:08:18 -07:00
|
|
|
}
|
2005-11-01 18:32:07 -08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_editor_set_window_type (MooEditor *editor,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
g_return_if_fail (g_type_is_a (type, MOO_TYPE_EDIT_WINDOW));
|
|
|
|
editor->priv->window_type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_editor_set_edit_type (MooEditor *editor,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
g_return_if_fail (g_type_is_a (type, MOO_TYPE_EDIT));
|
|
|
|
editor->priv->doc_type = type;
|
|
|
|
}
|
2005-11-02 07:49:35 -08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
moo_editor_set_default_lang (MooEditor *editor,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MOO_IS_EDITOR (editor));
|
|
|
|
g_free (editor->priv->default_lang);
|
|
|
|
editor->priv->default_lang = g_strdup (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char*
|
|
|
|
moo_editor_get_default_lang (MooEditor *editor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
|
|
|
return editor->priv->default_lang;
|
|
|
|
}
|