~ubuntu-branches/ubuntu/hardy/gnome-commander/hardy

« back to all changes in this revision

Viewing changes to src/history.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-06-13 15:39:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060613153948-gvrt3mb2ddk5u62o
Tags: 1.2.0-3
added --disable-scrollkeeper on build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    GNOME Commander - A GNOME based file manager 
 
2
    GNOME Commander - A GNOME based file manager
3
3
    Copyright (C) 2001-2006 Marcus Bjurman
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
24
24
 
25
25
History *history_new (gint max)
26
26
{
27
 
        History *history = g_new (History, 1);
28
 
 
29
 
        history->ents = NULL;
30
 
        history->pos = NULL;
31
 
        history->max = max;
32
 
        history->lock = FALSE;
33
 
 
34
 
        return history;
 
27
    History *history = g_new (History, 1);
 
28
 
 
29
    history->ents = NULL;
 
30
    history->pos = NULL;
 
31
    history->max = max;
 
32
    history->lock = FALSE;
 
33
 
 
34
    return history;
35
35
}
36
36
 
37
37
 
38
38
void history_free (History *history)
39
39
{
40
 
        g_return_if_fail (history != NULL);
41
 
 
42
 
        if (history->ents) {
43
 
                g_list_foreach (history->ents, (GFunc)g_free, NULL);
44
 
                g_list_free (history->ents);
45
 
        }
46
 
        
47
 
        g_free (history);
 
40
    g_return_if_fail (history != NULL);
 
41
 
 
42
    if (history->ents) {
 
43
        g_list_foreach (history->ents, (GFunc)g_free, NULL);
 
44
        g_list_free (history->ents);
 
45
    }
 
46
 
 
47
    g_free (history);
48
48
}
49
49
 
50
50
 
51
51
void history_add (History *history, const gchar *text)
52
52
{
53
 
        GList *l, *n;
54
 
        
55
 
        g_return_if_fail (history != NULL);
56
 
 
57
 
        if (history->lock) return;
58
 
 
59
 
        /* If we are in the middle of the history list, lets kill
60
 
           all items that are in front of us */
61
 
        l = history->ents;
62
 
        while (l && l != history->pos) {
63
 
                g_free (l->data);
64
 
                n = g_list_remove_link (l, l);
65
 
                g_list_free (l);
66
 
                l = n;
67
 
        }
68
 
 
69
 
        history->ents = string_history_add (l, text, history->max);
70
 
        history->pos = history->ents;
 
53
    GList *l, *n;
 
54
 
 
55
    g_return_if_fail (history != NULL);
 
56
 
 
57
    if (history->lock) return;
 
58
 
 
59
    /* If we are in the middle of the history list, lets kill
 
60
       all items that are in front of us */
 
61
    l = history->ents;
 
62
    while (l && l != history->pos) {
 
63
        g_free (l->data);
 
64
        n = g_list_remove_link (l, l);
 
65
        g_list_free (l);
 
66
        l = n;
 
67
    }
 
68
 
 
69
    history->ents = string_history_add (l, text, history->max);
 
70
    history->pos = history->ents;
71
71
}
72
72
 
73
73
 
74
74
gboolean history_can_back (History *history)
75
75
{
76
 
        g_return_val_if_fail (history != NULL, FALSE);
77
 
        g_return_val_if_fail (history->pos != NULL, FALSE);
78
 
        
79
 
        return (history->pos->next != NULL);
 
76
    g_return_val_if_fail (history != NULL, FALSE);
 
77
    g_return_val_if_fail (history->pos != NULL, FALSE);
 
78
 
 
79
    return (history->pos->next != NULL);
80
80
}
81
81
 
82
82
 
83
83
gboolean history_can_forward (History *history)
84
84
{
85
 
        g_return_val_if_fail (history != NULL, FALSE);
86
 
        g_return_val_if_fail (history->pos != NULL, FALSE);
87
 
        
88
 
        return (history->pos->prev != NULL);
89
 
 
85
    g_return_val_if_fail (history != NULL, FALSE);
 
86
    g_return_val_if_fail (history->pos != NULL, FALSE);
 
87
 
 
88
    return (history->pos->prev != NULL);
 
89
}
 
90
 
 
91
 
 
92
const gchar *history_first (History *history)
 
93
{
 
94
    g_return_val_if_fail (history != NULL, NULL);
 
95
    g_return_val_if_fail (history->pos != NULL, NULL);
 
96
 
 
97
    if (history->pos->next)
 
98
        history->pos = g_list_last(history->pos);
 
99
 
 
100
    return (const gchar*)history->pos->data;
 
101
}
90
102
 
91
103
 
92
104
const gchar *history_back (History *history)
93
105
{
94
 
        g_return_val_if_fail (history != NULL, NULL);
95
 
        g_return_val_if_fail (history->pos != NULL, NULL);
96
 
 
97
 
        if (history->pos->next)
98
 
                history->pos = history->pos->next;
99
 
        
100
 
        return (const gchar*)history->pos->data;
 
106
    g_return_val_if_fail (history != NULL, NULL);
 
107
    g_return_val_if_fail (history->pos != NULL, NULL);
 
108
 
 
109
    if (history->pos->next)
 
110
        history->pos = history->pos->next;
 
111
 
 
112
    return (const gchar*)history->pos->data;
101
113
}
102
114
 
103
115
 
104
116
const gchar *history_forward (History *history)
105
117
{
106
 
        g_return_val_if_fail (history != NULL, NULL);
107
 
        g_return_val_if_fail (history->pos != NULL, NULL);
108
 
 
109
 
        if (history->pos->prev)
110
 
                history->pos = history->pos->prev;
111
 
        
112
 
        return (const gchar*)history->pos->data;
 
118
    g_return_val_if_fail (history != NULL, NULL);
 
119
    g_return_val_if_fail (history->pos != NULL, NULL);
 
120
 
 
121
    if (history->pos->prev)
 
122
        history->pos = history->pos->prev;
 
123
 
 
124
    return (const gchar*)history->pos->data;
 
125
}
 
126
 
 
127
 
 
128
const gchar *history_last (History *history)
 
129
{
 
130
    g_return_val_if_fail (history != NULL, NULL);
 
131
    g_return_val_if_fail (history->pos != NULL, NULL);
 
132
 
 
133
    if (history->pos->prev)
 
134
        history->pos = g_list_first(history->pos);
 
135
 
 
136
    return (const gchar*)history->pos->data;
113
137
}
114
138
 
115
139