nautilus-history-view.c 6.31 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

/*
 *  Nautilus
 *
Elliot Lee's avatar
Elliot Lee committed
6
 *  Copyright (C) 1999, 2000 Red Hat, Inc.
Elliot Lee's avatar
Elliot Lee committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 *  This library 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.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Author: Elliot Lee <sopwith@redhat.com>
 *
 */
/* ntl-view.c: Implementation of the object representing a data view,
   and its associated CORBA object for proxying requests into this
   object. */
Elliot Lee's avatar
Elliot Lee committed
28
29
30
#include "config.h"

#include <libnautilus/libnautilus.h>
31
32
#include <libgnome/gnome-i18n.h>
#include <libgnorba/gnorba.h>
Elliot Lee's avatar
Elliot Lee committed
33
34

typedef struct {
35
  NautilusViewFrame *view;
Elliot Lee's avatar
Elliot Lee committed
36
37
38
39

  GtkCList *clist;

  gint notify_count, last_row;
40

41
  BonoboUIHandler *uih;
Elliot Lee's avatar
Elliot Lee committed
42
43
44
} HistoryView;

static void
45
hyperbola_navigation_history_notify_location_change (NautilusViewFrame *view,
Elliot Lee's avatar
Elliot Lee committed
46
47
48
49
50
51
52
53
54
55
56
						     Nautilus_NavigationInfo *loci,
						     HistoryView *hview)
{
  char *cols[2];
  int new_rownum;
  GtkCList *clist;

  hview->notify_count++;

  clist = hview->clist;

57
  if(hview->last_row >= 0)
Elliot Lee's avatar
Elliot Lee committed
58
59
    {
      char *uri;
60
      int i, j;
Elliot Lee's avatar
Elliot Lee committed
61

Elliot Lee's avatar
Elliot Lee committed
62
63
64
65
      /* If we are moving 'forward' in history, must either just
	 select a new row that is farther ahead in history, or delete
	 all the history ahead of this point */

66
      for(i = -1; i <= 1; i++)
Elliot Lee's avatar
Elliot Lee committed
67
	{
68
69
70
	  if((hview->last_row + i) < 0)
	    continue;

71
72
73
	  gtk_clist_get_text(clist, hview->last_row + i, 0, &uri);
	  if(!strcmp(uri, loci->requested_uri))
	    {
74
	      hview->last_row = new_rownum = hview->last_row + i;
75
76
	      goto skip_prepend;
	    }
Elliot Lee's avatar
Elliot Lee committed
77
78
	}

79
      for(j = 0; j < hview->last_row; j++)
Elliot Lee's avatar
Elliot Lee committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	gtk_clist_remove(clist, 0);
    }

  gtk_clist_freeze(clist);
  cols[0] = (char *)loci->requested_uri;
  hview->last_row = new_rownum = gtk_clist_prepend(clist, cols);

 skip_prepend:
  gtk_clist_columns_autosize(clist);

  if(gtk_clist_row_is_visible(clist, new_rownum) != GTK_VISIBILITY_FULL)
    gtk_clist_moveto(clist, new_rownum, -1, 0.5, 0.0);

  gtk_clist_select_row(clist, new_rownum, 0);

  gtk_clist_thaw(clist);

  hview->notify_count--;
}

static void
hyperbola_navigation_history_select_row(GtkCList *clist, gint row, gint column, GdkEvent *event,
					HistoryView *hview)
{
  Nautilus_NavigationRequestInfo reqi;

  if(hview->notify_count > 0)
    return;

  gtk_clist_freeze(clist);

  if(hview->last_row == row)
    return;

  hview->last_row = row;

  if(gtk_clist_row_is_visible(clist, row) != GTK_VISIBILITY_FULL)
    gtk_clist_moveto(clist, row, -1, 0.5, 0.0);

  gtk_clist_get_text(clist, row, 0, &reqi.requested_uri);

  reqi.new_window_default = reqi.new_window_suggested = Nautilus_V_FALSE;
  reqi.new_window_enforced = Nautilus_V_FALSE;

124
  nautilus_view_frame_request_location_change(hview->view, &reqi);
Elliot Lee's avatar
Elliot Lee committed
125
126
127
128

  gtk_clist_thaw(clist);
}

129
130
131
132
133
134
135
136
137
static int object_count = 0;

static void
do_destroy(GtkObject *obj)
{
  object_count--;
  if(object_count <= 0)
    gtk_main_quit();
}
Elliot Lee's avatar
Elliot Lee committed
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
static void
menu_setup(BonoboObject *ctl, HistoryView *hview)
{
  Bonobo_UIHandler remote_uih;
  GnomeUIInfo history_menu[] = {
    GNOMEUIINFO_MENU_NEW_ITEM("_Do nothing", "Testing", NULL, NULL),
    GNOMEUIINFO_END
  };

  remote_uih = bonobo_control_get_remote_ui_handler(BONOBO_CONTROL(ctl));
  bonobo_ui_handler_set_container(hview->uih, remote_uih);

  bonobo_ui_handler_menu_new_subtree(hview->uih, "/History", _("H_istory"), NULL, -1, BONOBO_UI_HANDLER_PIXMAP_NONE,
                                     NULL, 0, 0);
  bonobo_ui_handler_menu_add_tree(hview->uih, "/History",
                                  bonobo_ui_handler_menu_parse_uiinfo_tree(history_menu));
}

157
static BonoboObject * make_obj(BonoboGenericFactory *Factory, const char *goad_id, gpointer closure)
Elliot Lee's avatar
Elliot Lee committed
158
{
159
  GtkWidget *frame, *clist, *wtmp;
160
  BonoboObject *ctl;
Elliot Lee's avatar
Elliot Lee committed
161
162
163
164
165
166
  char *col_titles[1];
  HistoryView *hview;

  g_return_val_if_fail(!strcmp(goad_id, "ntl_history_view"), NULL);

  hview = g_new0(HistoryView, 1);
Elliot Lee's avatar
Elliot Lee committed
167
  hview->last_row = -1;
168
169
  frame = gtk_widget_new(nautilus_meta_view_frame_get_type(), NULL);
  gtk_signal_connect(GTK_OBJECT(frame), "destroy", do_destroy, NULL);
170
  object_count++;
Elliot Lee's avatar
Elliot Lee committed
171

172
  ctl = nautilus_view_frame_get_bonobo_object(NAUTILUS_VIEW_FRAME(frame));
173
174
175
176
177
178
179
  hview->uih = bonobo_ui_handler_new();
  bonobo_control_set_ui_handler(BONOBO_CONTROL(ctl), hview->uih);
  gtk_signal_connect(GTK_OBJECT(ctl), "set_frame", menu_setup, hview);

  /* set description */
  nautilus_meta_view_frame_set_label(NAUTILUS_META_VIEW_FRAME(frame),
                                     _("History"));
Elliot Lee's avatar
Elliot Lee committed
180
181
182

  /* create interface */
  col_titles[0] = _("Path");
183
  clist = gtk_clist_new_with_titles(1, col_titles);
Elliot Lee's avatar
Elliot Lee committed
184
185
186
187
  gtk_clist_set_selection_mode(GTK_CLIST(clist), GTK_SELECTION_BROWSE);
  gtk_clist_columns_autosize(GTK_CLIST(clist));
  wtmp = gtk_scrolled_window_new(gtk_clist_get_hadjustment(GTK_CLIST(clist)),
				 gtk_clist_get_vadjustment(GTK_CLIST(clist)));
Elliot Lee's avatar
Elliot Lee committed
188
189
190
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wtmp),
				 GTK_POLICY_AUTOMATIC,
				 GTK_POLICY_AUTOMATIC);
191
  gtk_container_add(GTK_CONTAINER(frame), wtmp);
Elliot Lee's avatar
Elliot Lee committed
192
193
  gtk_container_add(GTK_CONTAINER(wtmp), clist);

194
  gtk_widget_show_all(frame);
Elliot Lee's avatar
Elliot Lee committed
195
196
  
  /* handle events */
197
  gtk_signal_connect(GTK_OBJECT(frame), "notify_location_change", hyperbola_navigation_history_notify_location_change, hview);
Elliot Lee's avatar
Elliot Lee committed
198
  gtk_signal_connect(GTK_OBJECT(clist), "select_row", hyperbola_navigation_history_select_row, hview);
Elliot Lee's avatar
Elliot Lee committed
199

200
  hview->view = (NautilusViewFrame *)frame;
Elliot Lee's avatar
Elliot Lee committed
201
202
203
204
205
206
207
  hview->clist = (GtkCList *)clist;

  return ctl;
}

int main(int argc, char *argv[])
{
208
  BonoboGenericFactory *factory;
Elliot Lee's avatar
Elliot Lee committed
209
210
211
212
213
214
215
216
  CORBA_ORB orb;
  CORBA_Environment ev;

  CORBA_exception_init(&ev);
  orb = gnome_CORBA_init_with_popt_table("ntl-history-view", VERSION, &argc, argv, NULL, 0, NULL,
					 GNORBA_INIT_SERVER_FUNC, &ev);
  bonobo_init(orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);

217
  factory = bonobo_generic_factory_new_multi("ntl_history_view_factory", make_obj, NULL);
Elliot Lee's avatar
Elliot Lee committed
218

219
220
221
  do {
    bonobo_main();
  } while(object_count > 0);
Elliot Lee's avatar
Elliot Lee committed
222
223
224

  return 0;
}