Made moo_edit_get_filename() return duplicated string

This commit is contained in:
Yevgen Muntyan 2007-07-07 07:34:41 -05:00
parent c9336fe3bd
commit 2902ce6aed
16 changed files with 141 additions and 105 deletions

View File

@ -13,8 +13,8 @@
<configure>
<args>--enable-debug=full --enable-all-warnings --enable-project</args>
<vars>
<var name="CFLAGS">-g</var>
<var name="OBJCFLAGS">-g</var>
<var name="CFLAGS">-g</var>
</vars>
</configure>
</debug>
@ -37,8 +37,8 @@
<build_dir>build/optimized</build_dir>
<configure>
<vars>
<var name="CFLAGS">-O2 -g</var>
<var name="OBJCFLAGS">-O2 -g</var>
<var name="CFLAGS">-O2 -g</var>
</vars>
</configure>
</optimized>

View File

@ -241,8 +241,9 @@ run_in_pane (MooCommandExe *cmd,
if (filter)
{
const char *fn = MOO_IS_EDIT (doc) ? moo_edit_get_filename (MOO_EDIT (doc)) : NULL;
char *fn = MOO_IS_EDIT (doc) ? moo_edit_get_filename (MOO_EDIT (doc)) : NULL;
moo_output_filter_set_active_file (filter, fn);
g_free (fn);
}
moo_cmd_view_set_filter (MOO_CMD_VIEW (output), filter);
@ -351,12 +352,15 @@ create_environment (MooCommandContext *ctx,
*envp = NULL;
}
*working_dir = NULL;
doc = moo_command_context_get_doc (ctx);
if (doc && moo_edit_get_filename (doc))
*working_dir = g_path_get_dirname (moo_edit_get_filename (doc));
else
*working_dir = NULL;
if (doc && !moo_edit_is_untitled (doc))
{
char *filename = moo_edit_get_filename (doc);
*working_dir = g_path_get_dirname (filename);
g_free (filename);
}
}

View File

@ -312,7 +312,7 @@ moo_command_check_sensitive_real (MooCommand *cmd,
if ((cmd->options & MOO_COMMAND_NEED_DOC) && !doc)
return FALSE;
if ((cmd->options & MOO_COMMAND_NEED_FILE) && (!MOO_IS_EDIT (doc) || !moo_edit_get_filename (doc)))
if ((cmd->options & MOO_COMMAND_NEED_FILE) && (!MOO_IS_EDIT (doc) || moo_edit_is_untitled (doc)))
return FALSE;
return TRUE;
@ -411,7 +411,7 @@ check_context (MooCommandOptions options,
return FALSE;
if ((options & MOO_COMMAND_NEED_FILE) &&
!(MOO_IS_EDIT (doc) && moo_edit_get_filename (doc) != NULL))
!(MOO_IS_EDIT (doc) && !moo_edit_is_untitled (doc)))
return FALSE;
if ((options & MOO_COMMAND_NEED_SAVE) && !MOO_IS_EDIT (doc))
@ -442,9 +442,7 @@ moo_command_run (MooCommand *cmd,
}
else if (cmd->options & MOO_COMMAND_NEED_SAVE)
{
if (!save_one (doc))
return;
if (!moo_edit_get_filename (doc))
if (!save_one (doc) || moo_edit_is_untitled (doc))
return;
}

View File

@ -98,6 +98,16 @@ void _moo_edit_create_progress_dialog (MooEdit *edit);
void _moo_edit_set_progress_text (MooEdit *edit,
const char *text);
GdkPixbuf *_moo_edit_get_icon (MooEdit *edit,
GtkWidget *widget,
GtkIconSize size);
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->filename)
struct _MooEditFileInfo {
char *filename;
char *encoding;
};
typedef enum {
MOO_EDIT_LINE_END_NONE,
@ -117,7 +127,6 @@ struct _MooEditPrivate {
/* Document
*/
char *filename;
char *basename;
char *display_filename;
char *display_basename;

View File

@ -151,18 +151,23 @@ moo_edit_script_context_set_doc (MooEditScriptContext *ctx,
if (MOO_IS_EDIT (doc))
{
char *filename = NULL, *basename = NULL;
char *dirname = NULL, *base = NULL, *ext = NULL;
if (moo_edit_get_basename (MOO_EDIT (doc)))
get_extension (moo_edit_get_basename (MOO_EDIT (doc)), &base, &ext);
filename = moo_edit_get_filename (MOO_EDIT (doc));
if (moo_edit_get_filename (MOO_EDIT (doc)))
dirname = g_path_get_dirname (moo_edit_get_filename (MOO_EDIT (doc)));
if (filename)
{
basename = g_path_get_basename (filename);
ms_value_dict_set_string (val, MS_VAR_FILE,
moo_edit_get_filename (MOO_EDIT (doc)));
ms_value_dict_set_string (val, MS_VAR_NAME,
moo_edit_get_basename (MOO_EDIT (doc)));
if (basename)
get_extension (basename, &base, &ext);
dirname = g_path_get_dirname (filename);
}
ms_value_dict_set_string (val, MS_VAR_FILE, filename);
ms_value_dict_set_string (val, MS_VAR_NAME, basename);
ms_value_dict_set_string (val, MS_VAR_BASE, base);
ms_value_dict_set_string (val, MS_VAR_DIR, dirname);
ms_value_dict_set_string (val, MS_VAR_EXT, ext);
@ -170,6 +175,8 @@ moo_edit_script_context_set_doc (MooEditScriptContext *ctx,
g_free (base);
g_free (ext);
g_free (dirname);
g_free (basename);
g_free (filename);
}
else
{

View File

@ -298,7 +298,6 @@ moo_edit_finalize (GObject *object)
MooEdit *edit = MOO_EDIT (object);
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);
@ -502,7 +501,7 @@ moo_edit_is_empty (MooEdit *edit)
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
if (MOO_EDIT_IS_BUSY (edit) || MOO_EDIT_IS_MODIFIED (edit) || edit->priv->filename)
if (MOO_EDIT_IS_BUSY (edit) || MOO_EDIT_IS_MODIFIED (edit) || !MOO_EDIT_IS_UNTITLED (edit))
return FALSE;
gtk_text_buffer_get_bounds (get_buffer (edit), &start, &end);
@ -510,6 +509,13 @@ moo_edit_is_empty (MooEdit *edit)
return !gtk_text_iter_compare (&start, &end);
}
gboolean
moo_edit_is_untitled (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
return MOO_EDIT_IS_UNTITLED (edit);
}
MooEditStatus
moo_edit_get_status (MooEdit *edit)
@ -617,22 +623,15 @@ moo_edit_file_info_get_type (void)
}
const char *
char *
moo_edit_get_filename (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->filename;
return g_strdup (edit->priv->filename);
}
const char *
moo_edit_get_basename (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->basename;
}
const char *
moo_edit_get_display_filename (MooEdit *edit)
moo_edit_get_display_name (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->display_filename;
@ -645,14 +644,6 @@ moo_edit_get_display_basename (MooEdit *edit)
return edit->priv->display_basename;
}
const char *
moo_edit_get_encoding (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->encoding;
}
char *
moo_edit_get_uri (MooEdit *edit)
{
@ -664,6 +655,13 @@ moo_edit_get_uri (MooEdit *edit)
return NULL;
}
const char *
moo_edit_get_encoding (MooEdit *edit)
{
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->encoding;
}
static GtkTextBuffer *
get_buffer (MooEdit *edit)

View File

@ -58,11 +58,6 @@ typedef struct _MooEditPrivate MooEditPrivate;
typedef struct _MooEditClass MooEditClass;
struct _MooEditFileInfo {
char *filename;
char *encoding;
};
struct _MooEdit
{
MooTextView parent;
@ -92,19 +87,19 @@ struct _MooEditClass
};
GType moo_edit_get_type (void) G_GNUC_CONST;
GType moo_edit_file_info_get_type (void) G_GNUC_CONST;
GType moo_edit_get_type (void) G_GNUC_CONST;
GType moo_edit_file_info_get_type (void) G_GNUC_CONST;
const char *moo_edit_get_filename (MooEdit *edit);
const char *moo_edit_get_basename (MooEdit *edit);
const char *moo_edit_get_display_filename (MooEdit *edit);
char *moo_edit_get_uri (MooEdit *edit);
char *moo_edit_get_filename (MooEdit *edit);
char *moo_edit_get_basename (MooEdit *edit);
const char *moo_edit_get_display_name (MooEdit *edit);
const char *moo_edit_get_display_basename (MooEdit *edit);
const char *moo_edit_get_encoding (MooEdit *edit);
char *moo_edit_get_uri (MooEdit *edit);
gboolean moo_edit_is_empty (MooEdit *edit);
gboolean moo_edit_is_untitled (MooEdit *edit);
void moo_edit_set_modified (MooEdit *edit,
gboolean modified);
gboolean moo_edit_get_clean (MooEdit *edit);

View File

@ -136,7 +136,7 @@ _moo_edit_save_changes_dialog (MooEdit *edit)
{
GtkDialog *dialog = NULL;
int response;
const char *name = moo_edit_get_display_basename (edit);
const char *name;
g_return_val_if_fail (MOO_IS_EDIT (edit), MOO_EDIT_RESPONSE_CANCEL);
name = moo_edit_get_display_basename (edit);

View File

@ -22,6 +22,7 @@
#include "mooedit/mooeditdialogs.h"
#include "mooedit/mootextbuffer.h"
#include "mooedit/mooeditprefs.h"
#include "moofileview/moofile.h"
#include "mooutils/moofilewatch.h"
#include "mooutils/mooencodings.h"
#include "mooutils/mooi18n.h"
@ -1203,10 +1204,9 @@ _moo_edit_set_filename (MooEdit *edit,
const char *file,
const char *encoding)
{
char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5;
char *tmp1, *tmp3, *tmp4, *tmp5;
tmp1 = edit->priv->filename;
tmp2 = edit->priv->basename;
tmp3 = edit->priv->display_filename;
tmp4 = edit->priv->display_basename;
tmp5 = edit->priv->encoding;
@ -1219,7 +1219,6 @@ _moo_edit_set_filename (MooEdit *edit,
int n = add_untitled (edit);
edit->priv->filename = NULL;
edit->priv->basename = NULL;
if (n == 1)
edit->priv->display_filename = g_strdup (_("Untitled"));
@ -1230,15 +1229,17 @@ _moo_edit_set_filename (MooEdit *edit,
}
else
{
char *basename;
remove_untitled (NULL, edit);
edit->priv->filename = g_strdup (file);
edit->priv->basename = g_path_get_basename (file);
edit->priv->display_filename = _moo_edit_filename_to_utf8 (file);
edit->priv->display_filename =
_moo_edit_filename_to_utf8 (file);
edit->priv->display_basename =
_moo_edit_filename_to_utf8 (edit->priv->basename);
basename = g_path_get_basename (file);
edit->priv->display_basename = _moo_edit_filename_to_utf8 (basename);
g_free (basename);
}
if (!encoding)
@ -1249,7 +1250,6 @@ _moo_edit_set_filename (MooEdit *edit,
moo_edit_status_changed (edit);
g_free (tmp1);
g_free (tmp2);
g_free (tmp3);
g_free (tmp4);
g_free (tmp5);
@ -1282,3 +1282,12 @@ _moo_edit_filename_to_utf8 (const char *filename)
return utf_filename;
}
GdkPixbuf *
_moo_edit_get_icon (MooEdit *doc,
GtkWidget *widget,
GtkIconSize size)
{
return _moo_get_icon_for_path (doc->priv->filename, widget, size);
}

View File

@ -802,11 +802,18 @@ window_info_remove (WindowInfo *win,
static int
edit_and_file_cmp (MooEdit *edit, const char *filename)
{
const char *edit_filename;
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);
{
int result = strcmp (edit_filename, filename);
g_free (edit_filename);
return result;
}
else
return TRUE;
}
@ -1023,9 +1030,9 @@ moo_editor_add_doc (MooEditor *editor,
window_info_add (info, doc);
if (!moo_edit_get_filename (doc) &&
!moo_edit_config_get_string (doc->config, "lang") &&
editor->priv->default_lang)
if (moo_edit_is_untitled (doc) &&
!moo_edit_config_get_string (doc->config, "lang") &&
editor->priv->default_lang)
{
moo_edit_config_set (doc->config, MOO_EDIT_CONFIG_SOURCE_FILENAME,
"lang", editor->priv->default_lang, NULL);
@ -1811,7 +1818,7 @@ static MooMarkupNode *
save_doc_session (MooEdit *doc,
MooMarkupNode *elm)
{
const char *filename;
char *filename;
const char *encoding;
MooMarkupNode *node;
@ -1838,6 +1845,7 @@ save_doc_session (MooEdit *doc,
node = moo_markup_create_element (elm, "document");
}
g_free (filename);
return node;
}
@ -2178,7 +2186,7 @@ _moo_editor_reload (MooEditor *editor,
g_return_if_fail (info != NULL);
/* XXX */
g_return_if_fail (moo_edit_get_filename (doc) != NULL);
g_return_if_fail (!moo_edit_is_untitled (doc));
if (!editor->priv->silent &&
!MOO_EDIT_IS_CLEAN (doc) &&
@ -2262,10 +2270,10 @@ _moo_editor_save (MooEditor *editor,
info = window_list_find_doc (editor, doc);
g_return_val_if_fail (info != NULL, FALSE);
if (!moo_edit_get_filename (doc))
if (moo_edit_is_untitled (doc))
return _moo_editor_save_as (editor, doc, NULL, NULL, error);
filename = g_strdup (moo_edit_get_filename (doc));
filename = moo_edit_get_filename (doc);
encoding = g_strdup (moo_edit_get_encoding (doc));
if (!editor->priv->silent &&

View File

@ -36,7 +36,6 @@
#include "mooutils/mooi18n.h"
#include "mooutils/mooaction-private.h"
#include "mooutils/moofiledialog.h"
#include "moofileview/moofile.h"
#include <string.h>
#include <gtk/gtk.h>
#include <math.h>
@ -973,7 +972,7 @@ static void moo_edit_window_get_property(GObject *object,
case PROP_CAN_RELOAD:
doc = ACTIVE_DOC (window);
g_value_set_boolean (value, doc && moo_edit_get_filename (doc));
g_value_set_boolean (value, doc && !moo_edit_is_untitled (doc));
break;
case PROP_HAS_OPEN_DOCUMENT:
g_value_set_boolean (value, ACTIVE_DOC (window) != NULL);
@ -1095,7 +1094,7 @@ update_window_title (MooEditWindow *window)
}
if (window->priv->use_full_name)
name = moo_edit_get_display_filename (edit);
name = moo_edit_get_display_name (edit);
else
name = moo_edit_get_display_basename (edit);
@ -1144,6 +1143,7 @@ update_window_title (MooEditWindow *window)
g_string_append_printf (title, doc_title_format, name);
gtk_window_set_title (GTK_WINDOW (window), title->str);
g_string_free (title, TRUE);
}
@ -2584,9 +2584,7 @@ update_tab_label (MooEditWindow *window,
moo_edit_get_display_basename (doc));
gtk_label_set_text (GTK_LABEL (label), label_text);
/* XXX */
pixbuf = _moo_get_icon_for_path (moo_edit_get_filename (doc),
icon, GTK_ICON_SIZE_MENU);
pixbuf = _moo_edit_get_icon (doc, icon, GTK_ICON_SIZE_MENU);
set_tab_icon (icon, evbox, pixbuf);
g_free (label_text);
@ -3736,11 +3734,16 @@ compare_doc_list_actions (gpointer a1,
gpointer a2)
{
MooEdit *d1, *d2;
int result;
d1 = g_object_get_data (a1, "moo-edit");
d2 = g_object_get_data (a2, "moo-edit");
g_return_val_if_fail (d1 && d2, -1);
return strcmp (moo_edit_get_display_basename (d1),
moo_edit_get_display_basename (d2));
result = strcmp (moo_edit_get_display_basename (d1),
moo_edit_get_display_basename (d2));
return result;
}
@ -3796,7 +3799,7 @@ do_update_doc_list (MooEditWindow *window)
{
g_object_set (action,
"label", moo_edit_get_display_basename (doc),
"tooltip", moo_edit_get_display_filename (doc),
"tooltip", moo_edit_get_display_name (doc),
NULL);
}
else
@ -3806,7 +3809,7 @@ do_update_doc_list (MooEditWindow *window)
action = g_object_new (MOO_TYPE_RADIO_ACTION ,
"name", name,
"label", moo_edit_get_display_basename (doc),
"tooltip", moo_edit_get_display_filename (doc),
"tooltip", moo_edit_get_display_name (doc),
"use-underline", FALSE,
NULL);
g_object_set_data_full (doc, "moo-doc-list-action", action, g_object_unref);

View File

@ -1622,9 +1622,12 @@ do_print_operation (GtkTextView *view,
op->priv->parent = GTK_WINDOW (parent);
if (MOO_IS_EDIT (view))
moo_print_operation_set_filename (op,
moo_edit_get_display_filename (MOO_EDIT (view)),
moo_edit_get_display_basename (MOO_EDIT (view)));
{
const char *filename, *basename;
filename = moo_edit_get_display_name (MOO_EDIT (view));
basename = moo_edit_get_display_basename (MOO_EDIT (view));
moo_print_operation_set_filename (op, filename, basename);
}
res = gtk_print_operation_run (GTK_PRINT_OPERATION (op),
action, op->priv->parent, &error);

View File

@ -1129,13 +1129,13 @@ create_command_context (gpointer window,
ctx = moo_command_context_new (doc, window);
if (MOO_IS_EDIT (doc) && moo_edit_get_filename (doc))
if (MOO_IS_EDIT (doc) && !moo_edit_is_untitled (doc))
{
const char *filename, *basename;
char *filename, *basename;
char *dirname, *base = NULL, *extension = NULL;
filename = moo_edit_get_filename (doc);
basename = moo_edit_get_basename (doc);
basename = filename ? g_path_get_basename (filename) : NULL;
dirname = g_path_get_dirname (filename);
get_extension (basename, &base, &extension);
@ -1147,6 +1147,8 @@ create_command_context (gpointer window,
g_free (dirname);
g_free (base);
g_free (extension);
g_free (basename);
g_free (filename);
}
if (MOO_IS_EDIT (doc))

View File

@ -337,7 +337,7 @@ static void
goto_current_doc_dir (MooFileSelector *filesel)
{
MooEdit *doc;
const char *filename;
char *filename;
doc = moo_edit_window_get_active_doc (filesel->window);
filename = doc ? moo_edit_get_filename (doc) : NULL;
@ -349,6 +349,8 @@ goto_current_doc_dir (MooFileSelector *filesel)
moo_file_selector_select_file (filesel, filename, dirname);
g_free (dirname);
}
g_free (filename);
}
@ -1092,7 +1094,9 @@ doc_move (MooFileSelector *filesel,
{
char *filename, *old_filename;
old_filename = g_strdup (moo_edit_get_filename (doc));
old_filename = moo_edit_get_filename (doc);
/* XXX non-local */
g_return_if_fail (old_filename != NULL);
filename = save_as_dialog (GTK_WIDGET (filesel), destdir,
moo_edit_get_display_basename (doc),
@ -1304,7 +1308,6 @@ moo_file_selector_drop_doc (MooFileSelector *filesel,
int y,
guint time)
{
const char *filename;
GdkModifierType mods;
DropDocAction action;
@ -1312,9 +1315,7 @@ moo_file_selector_drop_doc (MooFileSelector *filesel,
g_return_if_fail (destdir != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget));
filename = moo_edit_get_filename (doc);
if (!filename)
if (moo_edit_is_untitled (doc))
{
gboolean result = drop_untitled (filesel, doc, destdir,
widget, context, x, y, time);

View File

@ -415,12 +415,15 @@ init_dir_entry (MooHistoryCombo *hist_combo,
if (!gtk_entry_get_text(GTK_ENTRY (entry))[0])
{
MooFileEntryCompletion *completion;
char *filename;
completion = g_object_get_data (G_OBJECT (entry), "find-plugin-file-completion");
if (doc && moo_edit_get_filename (doc))
filename = doc ? moo_edit_get_filename (doc) : NULL;
if (filename)
{
char *dir = g_path_get_dirname (moo_edit_get_filename (doc));
char *dir = g_path_get_dirname (filename);
_moo_file_entry_completion_set_path (completion, dir);
g_free (dir);
}
@ -428,6 +431,8 @@ init_dir_entry (MooHistoryCombo *hist_combo,
{
_moo_file_entry_completion_set_path (completion, g_get_home_dir ());
}
g_free (filename);
}
#if 0

View File

@ -229,18 +229,12 @@
(define-method get_filename
(of-object "MooEdit")
(c-name "moo_edit_get_filename")
(return-type "const-char*")
(return-type "char*")
)
(define-method get_basename
(define-method get_display_name
(of-object "MooEdit")
(c-name "moo_edit_get_basename")
(return-type "const-char*")
)
(define-method get_display_filename
(of-object "MooEdit")
(c-name "moo_edit_get_display_filename")
(c-name "moo_edit_get_display_name")
(return-type "const-char*")
)