~gustav-hartvigsson/bzr-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2007-05-19 16:21:10 UTC
  • mfrom: (195.1.7 trunk)
  • Revision ID: jelmer@samba.org-20070519162110-qw0pkevul1iet036
MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
import sys
 
19
import time
19
20
 
20
21
# gettext support
21
22
import gettext
27
28
except:
28
29
    pass
29
30
 
 
31
import gobject
30
32
import gtk
31
33
import gtk.gdk
32
34
import gtk.glade
107
109
        self.combobox_drive = gtk.combo_box_new_text()
108
110
        self.combobox_drive.connect("changed", self._refresh_drives)
109
111
        
 
112
        # Get the navigation widgets
 
113
        self.hbox_location = self.toplevel.get_widget('hbox_location')
 
114
        self.button_location_up = self.toplevel.get_widget('button_location_up')
 
115
        self.button_location_jump = self.toplevel.get_widget('button_location_jump')
 
116
        self.entry_location = self.toplevel.get_widget('entry_location')
 
117
        self.image_location_error = self.toplevel.get_widget('image_location_error')
 
118
        
110
119
        self.vbox_main_right = self.toplevel.get_widget('vbox_main_right')
111
 
 
112
120
        
113
121
        # Dictionary for signal_autoconnect
114
122
        dic = { "on_window_main_destroy": gtk.main_quit,
148
156
                "on_treeview_right_button_press_event": self.on_treeview_right_button_press_event,
149
157
                "on_treeview_right_row_activated": self.on_treeview_right_row_activated,
150
158
                "on_treeview_left_button_press_event": self.on_treeview_left_button_press_event,
151
 
                "on_treeview_left_row_activated": self.on_treeview_left_row_activated }
 
159
                "on_treeview_left_row_activated": self.on_treeview_left_row_activated,
 
160
                "on_button_location_up_clicked": self.on_button_location_up_clicked,
 
161
                "on_button_location_jump_clicked": self.on_button_location_jump_clicked,
 
162
                "on_entry_location_key_press_event": self.on_entry_location_key_press_event
 
163
            }
152
164
        
153
165
        # Connect the signals to the handlers
154
166
        self.toplevel.signal_autoconnect(dic)
175
187
        
176
188
        # Show drive selector if under Win32
177
189
        if sys.platform == 'win32':
178
 
            self.vbox_main_right.pack_start(self.combobox_drive, False, True, 0)
179
 
            self.vbox_main_right.reorder_child(self.combobox_drive, 0)
 
190
            self.hbox_location.pack_start(self.combobox_drive, False, False, 0)
 
191
            self.hbox_location.reorder_child(self.combobox_drive, 1)
180
192
            self.combobox_drive.show()
181
193
            self.gen_hard_selector()
182
194
        
200
212
            self.notbranch = True
201
213
        
202
214
        self.statusbar.push(self.context_id, path)
 
215
        self.entry_location.set_text(path)
 
216
        
 
217
        # If we're in the root, we cannot go up anymore
 
218
        if sys.platform == 'win32':
 
219
            drive, tail = os.path.splitdrive(self.path)
 
220
            if tail in ('', '/', '\\'):
 
221
                self.button_location_up.set_sensitive(False)
 
222
            else:
 
223
                self.button_location_up.set_sensitive(True)
 
224
        else:
 
225
            if self.path == '/':
 
226
                self.button_location_up.set_sensitive(False)
 
227
            else:
 
228
                self.button_location_up.set_sensitive(True)
203
229
 
204
230
    def get_path(self):
205
231
        return self.path
208
234
        from bzrlib.plugins.gtk.dialog import about
209
235
        about()
210
236
        
 
237
    def on_button_location_up_clicked(self, widget):
 
238
        """ Location Up button handler. """
 
239
        self.set_path(os.path.split(self.get_path())[0])
 
240
        self.refresh_right()
 
241
    
 
242
    def on_button_location_jump_clicked(self, widget):
 
243
        """ Location Jump button handler. """
 
244
        location = self.entry_location.get_text()
 
245
        if os.path.isdir(location):
 
246
            self.set_path(location)
 
247
            self.refresh_right()
 
248
            self.image_location_error.hide()
 
249
        else:
 
250
            self.image_location_error.show()
 
251
    
 
252
    def on_entry_location_key_press_event(self, widget, event):
 
253
        """ Key pressed handler for the location entry. """
 
254
        if event.keyval == 65293:
 
255
            # Return was hit, so we have to jump
 
256
            self.on_button_location_jump_clicked(widget)
 
257
    
211
258
    def on_menuitem_add_files_activate(self, widget):
212
259
        """ Add file(s)... menu handler. """
213
260
        from add import OliveAdd
344
391
        """ Branch/Status... menu handler. """
345
392
        from bzrlib.plugins.gtk.status import StatusDialog
346
393
        status = StatusDialog(self.wt, self.wtpath)
347
 
        status.display()
 
394
        response = status.run()
 
395
        if response != gtk.RESPONSE_NONE:
 
396
            status.destroy()
348
397
    
349
398
    def on_menuitem_branch_initialize_activate(self, widget):
350
399
        """ Initialize current directory. """
574
623
        # Expand the tree
575
624
        self.treeview_left.expand_all()
576
625
 
577
 
    def _add_updir_to_dirlist(self, dirlist, curdir):
578
 
        """Add .. to the top of directories list if we not in root directory
579
 
 
580
 
        :param dirlist:     list of directories (modified in place)
581
 
        :param curdir:      current directory
582
 
        :return:            nothing
583
 
        """
584
 
        if curdir is None:
585
 
            curdir = self.path
586
 
 
587
 
        if sys.platform == 'win32':
588
 
            drive, tail = os.path.splitdrive(curdir)
589
 
            if tail in ('', '/', '\\'):
590
 
                return
591
 
        else:
592
 
            if curdir == '/':
593
 
                return
594
 
 
595
 
        # insert always as first element
596
 
        dirlist.insert(0, '..')
597
 
 
598
626
    def _load_right(self):
599
627
        """ Load data into the right panel. (Filelist) """
600
628
        # Create ListStore
601
 
        liststore = gtk.ListStore(str, str, str)
 
629
        # Model: [icon, dir, name, status text, status, size (int), size (human), mtime (int), mtime (local)]
 
630
        liststore = gtk.ListStore(str, gobject.TYPE_BOOLEAN, str, str, str, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING)
602
631
        
603
632
        dirs = []
604
633
        files = []
612
641
                dirs.append(item)
613
642
            else:
614
643
                files.append(item)
615
 
            
616
 
        # Sort'em
617
 
        dirs.sort()
618
 
        files.sort()
619
 
 
620
 
        # add updir link to dirs
621
 
        self._add_updir_to_dirlist(dirs, self.path)
622
644
        
623
645
        if not self.notbranch:
624
646
            branch = self.wt.branch
627
649
            delta = self.wt.changes_from(tree2, want_unchanged=True)
628
650
        
629
651
        # Add'em to the ListStore
630
 
        for item in dirs:    
631
 
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
 
652
        for item in dirs:
 
653
            statinfo = os.stat(self.path + os.sep + item)
 
654
            liststore.append([gtk.STOCK_DIRECTORY, True, item, '', '', statinfo.st_size, self._format_size(statinfo.st_size), statinfo.st_mtime, self._format_date(statinfo.st_mtime)])
632
655
        for item in files:
633
656
            status = 'unknown'
634
657
            if not self.notbranch:
677
700
                st = _('ignored')
678
701
            else:
679
702
                st = _('unknown')
680
 
            liststore.append([gtk.STOCK_FILE, item, st])
 
703
            
 
704
            statinfo = os.stat(self.path + os.sep + item)
 
705
            liststore.append([gtk.STOCK_FILE, False, item, st, status, statinfo.st_size, self._format_size(statinfo.st_size), statinfo.st_mtime, self._format_date(statinfo.st_mtime)])
681
706
        
682
707
        # Create the columns and add them to the TreeView
683
708
        self.treeview_right.set_model(liststore)
684
709
        tvcolumn_filename = gtk.TreeViewColumn(_('Filename'))
685
710
        tvcolumn_status = gtk.TreeViewColumn(_('Status'))
 
711
        tvcolumn_size = gtk.TreeViewColumn(_('Size'))
 
712
        tvcolumn_mtime = gtk.TreeViewColumn(_('Last modified'))
686
713
        self.treeview_right.append_column(tvcolumn_filename)
687
714
        self.treeview_right.append_column(tvcolumn_status)
 
715
        self.treeview_right.append_column(tvcolumn_size)
 
716
        self.treeview_right.append_column(tvcolumn_mtime)
688
717
        
689
718
        # Set up the cells
690
719
        cellpb = gtk.CellRendererPixbuf()
692
721
        tvcolumn_filename.pack_start(cellpb, False)
693
722
        tvcolumn_filename.pack_start(cell, True)
694
723
        tvcolumn_filename.set_attributes(cellpb, stock_id=0)
695
 
        tvcolumn_filename.add_attribute(cell, 'text', 1)
 
724
        tvcolumn_filename.add_attribute(cell, 'text', 2)
696
725
        tvcolumn_status.pack_start(cell, True)
697
 
        tvcolumn_status.add_attribute(cell, 'text', 2)
 
726
        tvcolumn_status.add_attribute(cell, 'text', 3)
 
727
        tvcolumn_size.pack_start(cell, True)
 
728
        tvcolumn_size.add_attribute(cell, 'text', 6)
 
729
        tvcolumn_mtime.pack_start(cell, True)
 
730
        tvcolumn_mtime.add_attribute(cell, 'text', 8)
 
731
        
 
732
        # Set up the properties of the TreeView
 
733
        self.treeview_right.set_headers_visible(True)
 
734
        self.treeview_right.set_headers_clickable(True)
 
735
        self.treeview_right.set_search_column(1)
 
736
        tvcolumn_filename.set_resizable(True)
 
737
        # Set up sorting
 
738
        liststore.set_sort_func(13, self._sort_filelist_callback, None)
 
739
        liststore.set_sort_column_id(13, gtk.SORT_ASCENDING)
 
740
        tvcolumn_filename.set_sort_column_id(13)
 
741
        tvcolumn_status.set_sort_column_id(3)
 
742
        tvcolumn_size.set_sort_column_id(5)
 
743
        tvcolumn_mtime.set_sort_column_id(7)
698
744
        
699
745
        # Set sensitivity
700
746
        self.set_sensitivity()
707
753
        if iter is None:
708
754
            return None
709
755
        else:
710
 
            return model.get_value(iter, 1)
 
756
            return model.get_value(iter, 2)
711
757
    
712
758
    def get_selected_left(self):
713
759
        """ Get the selected bookmark. """
807
853
                dirs.append(item)
808
854
            else:
809
855
                files.append(item)
810
 
 
811
 
        # Sort'em
812
 
        dirs.sort()
813
 
        files.sort()
814
 
 
815
 
        # add updir link to dirs
816
 
        self._add_updir_to_dirlist(dirs, path)
817
 
 
 
856
        
818
857
        # Try to open the working tree
819
858
        notbranch = False
820
859
        try:
830
869
            
831
870
        # Add'em to the ListStore
832
871
        for item in dirs:
833
 
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
 
872
            statinfo = os.stat(self.path + os.sep + item)
 
873
            liststore.append([gtk.STOCK_DIRECTORY, True, item, '', '', statinfo.st_size, self._format_size(statinfo.st_size), statinfo.st_mtime, self._format_date(statinfo.st_mtime)])
834
874
        for item in files:
835
875
            status = 'unknown'
836
876
            if not notbranch:
879
919
                st = _('ignored')
880
920
            else:
881
921
                st = _('unknown')
882
 
            liststore.append([gtk.STOCK_FILE, item, st])
 
922
            
 
923
            statinfo = os.stat(self.path + os.sep + item)
 
924
            liststore.append([gtk.STOCK_FILE, False, item, st, status, statinfo.st_size, self._format_size(statinfo.st_size), statinfo.st_mtime, self._format_date(statinfo.st_mtime)])
883
925
 
884
926
        # Add the ListStore to the TreeView
885
927
        self.treeview_right.set_model(liststore)
 
928
        self.treeview_right.columns_autosize()
886
929
        
887
930
        # Set sensitivity
888
931
        self.set_sensitivity()
933
976
            changes = True
934
977
        
935
978
        return changes
 
979
    
 
980
    def _sort_filelist_callback(self, model, iter1, iter2, data):
 
981
        """ The sort callback for the file list, return values:
 
982
        -1: iter1 < iter2
 
983
        0: iter1 = iter2
 
984
        1: iter1 > iter2
 
985
        """
 
986
        name1 = model.get_value(iter1, 2)
 
987
        name2 = model.get_value(iter2, 2)
 
988
        
 
989
        if model.get_value(iter1, 1):
 
990
            # item1 is a directory
 
991
            if not model.get_value(iter2, 1):
 
992
                # item2 isn't
 
993
                return -1
 
994
            else:
 
995
                # both of them are directories, we compare their names
 
996
                if name1 < name2:
 
997
                    return -1
 
998
                elif name1 == name2:
 
999
                    return 0
 
1000
                else:
 
1001
                    return 1
 
1002
        else:
 
1003
            # item1 is not a directory
 
1004
            if model.get_value(iter2, 1):
 
1005
                # item2 is
 
1006
                return 1
 
1007
            else:
 
1008
                # both of them are files, compare them
 
1009
                if name1 < name2:
 
1010
                    return -1
 
1011
                elif name1 == name2:
 
1012
                    return 0
 
1013
                else:
 
1014
                    return 1
 
1015
    
 
1016
    def _format_size(self, size):
 
1017
        """ Format size to a human readable format. """
 
1018
        return size
 
1019
    
 
1020
    def _format_date(self, timestamp):
 
1021
        """ Format the time (given in secs) to a human readable format. """
 
1022
        return time.ctime(timestamp)
936
1023
 
937
1024
import ConfigParser
938
1025