nautilus-history-view.c 4.02 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "config.h"

#include <libnautilus/libnautilus.h>

typedef struct {
  NautilusViewClient *view;

  GtkCList *clist;

  gint notify_count, last_row;
} HistoryView;

static void
hyperbola_navigation_history_notify_location_change (NautilusViewClient *view,
						     Nautilus_NavigationInfo *loci,
						     HistoryView *hview)
{
  char *cols[2];
  int new_rownum;
  GtkCList *clist;

  hview->notify_count++;

  clist = hview->clist;

26
  if(hview->last_row >= 0)
Elliot Lee's avatar
Elliot Lee committed
27
28
29
30
    {
      char *uri;
      int i;

Elliot Lee's avatar
Elliot Lee committed
31
32
33
34
      /* 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 */

35
      for(i = -1; i <= 1; i++)
Elliot Lee's avatar
Elliot Lee committed
36
	{
37
38
39
40
41
42
	  gtk_clist_get_text(clist, hview->last_row + i, 0, &uri);
	  if(!strcmp(uri, loci->requested_uri))
	    {
	      new_rownum = hview->last_row + i;
	      goto skip_prepend;
	    }
Elliot Lee's avatar
Elliot Lee committed
43
44
	}

45
      for(i = 0; i < hview->last_row; i++)
Elliot Lee's avatar
Elliot Lee committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	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;

  nautilus_view_client_request_location_change(hview->view, &reqi);

  gtk_clist_thaw(clist);
}


96
static GnomeObject * make_obj(GnomeGenericFactory *Factory, const char *goad_id, gpointer closure)
Elliot Lee's avatar
Elliot Lee committed
97
98
99
100
101
102
103
104
105
{
  GtkWidget *client, *clist, *wtmp;
  GnomeObject *ctl;
  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
106
  hview->last_row = -1;
Elliot Lee's avatar
Elliot Lee committed
107
108
109
110
111
112
  client = gtk_widget_new(nautilus_meta_view_client_get_type(), NULL);

  ctl = nautilus_view_client_get_gnome_object(NAUTILUS_VIEW_CLIENT(client));

  /* create interface */
  col_titles[0] = _("Path");
113
  clist = gtk_clist_new_with_titles(1, col_titles);
Elliot Lee's avatar
Elliot Lee committed
114
115
116
117
  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
118
119
120
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wtmp),
				 GTK_POLICY_AUTOMATIC,
				 GTK_POLICY_AUTOMATIC);
Elliot Lee's avatar
Elliot Lee committed
121
122
123
124
125
126
  gtk_container_add(GTK_CONTAINER(client), wtmp);
  gtk_container_add(GTK_CONTAINER(wtmp), clist);

  gtk_widget_show_all(client);
  
  /* handle events */
Elliot Lee's avatar
Elliot Lee committed
127
128
  gtk_signal_connect(GTK_OBJECT(client), "notify_location_change", hyperbola_navigation_history_notify_location_change, hview);
  gtk_signal_connect(GTK_OBJECT(clist), "select_row", hyperbola_navigation_history_select_row, hview);
Elliot Lee's avatar
Elliot Lee committed
129
130

  /* set description */
Elliot Lee's avatar
Elliot Lee committed
131
132
  nautilus_meta_view_client_set_label(NAUTILUS_META_VIEW_CLIENT(client),
				      _("History"));
Elliot Lee's avatar
Elliot Lee committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

  hview->view = (NautilusViewClient *)client;
  hview->clist = (GtkCList *)clist;

  return ctl;
}

int main(int argc, char *argv[])
{
  GnomeGenericFactory *factory;
  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);

151
  factory = gnome_generic_factory_new_multi("ntl_history_view_factory", make_obj, NULL);
Elliot Lee's avatar
Elliot Lee committed
152

Elliot Lee's avatar
Elliot Lee committed
153
  bonobo_main();
Elliot Lee's avatar
Elliot Lee committed
154
155
156

  return 0;
}