/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/__init__.py

  • Committer: Jasper Groenewegen
  • Date: 2008-08-03 08:14:24 UTC
  • mfrom: (560.10.2 redo-files)
  • Revision ID: colbrac@xs4al.nl-20080803081424-dkmh5qjqu3e75zeg
Merge Olive filelist improvements

Adds status messages for folders
Fixes bug 12544 (broken symlink handling)
Moves file list liststore generation to olive/window.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
        
99
99
                # Get the TreeViews
100
100
        self.treeview_left = self.window.treeview_left
101
 
        self.treeview_right = self.window.treeview_right
102
101
        
103
102
        # Get the drive selector
104
103
        self.combobox_drive = gtk.combo_box_new_text()
155
154
        self.remote_revision = None
156
155
        
157
156
        self.set_path(os.getcwd())
158
 
        self._load_right()
 
157
        self.refresh_right()
159
158
        
160
159
        self._just_started = False
161
160
 
212
211
                
213
212
                # We're local
214
213
                try:
215
 
                    self.wt, self.wtpath = WorkingTree.open_containing(path)
 
214
                    self.wt, self.wtpath = WorkingTree.open_containing(os.path.realpath(path))
216
215
                except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
217
216
                    self.notbranch = True
218
217
                
904
903
        
905
904
        # Expand the tree
906
905
        self.treeview_left.expand_all()
907
 
 
908
 
    def _load_right(self):
909
 
        """ Load data into the right panel. (Filelist) """
910
 
        # Create ListStore
911
 
        # Model: [ icon, dir, name, status text, status, size (int), size (human), mtime (int), mtime (local), fileid ]
912
 
        liststore = gtk.ListStore(gobject.TYPE_STRING,
913
 
                                  gobject.TYPE_BOOLEAN,
914
 
                                  gobject.TYPE_STRING,
915
 
                                  gobject.TYPE_STRING,
916
 
                                  gobject.TYPE_STRING,
917
 
                                  gobject.TYPE_STRING,
918
 
                                  gobject.TYPE_STRING,
919
 
                                  gobject.TYPE_INT,
920
 
                                  gobject.TYPE_STRING,
921
 
                                  gobject.TYPE_STRING)
922
 
        
923
 
        dirs = []
924
 
        files = []
925
 
        
926
 
        # Fill the appropriate lists
927
 
        dotted_files = self.pref.get_preference('dotted_files', 'bool')
928
 
        for item in os.listdir(self.path):
929
 
            if not dotted_files and item[0] == '.':
930
 
                continue
931
 
            if os.path.isdir(self.path + os.sep + item):
932
 
                dirs.append(item)
933
 
            else:
934
 
                files.append(item)
935
 
        
936
 
        if not self.notbranch:
937
 
            branch = self.wt.branch
938
 
            tree2 = self.wt.branch.repository.revision_tree(branch.last_revision())
939
 
        
940
 
            delta = self.wt.changes_from(tree2, want_unchanged=True)
941
 
        
942
 
        # Add'em to the ListStore
943
 
        for item in dirs:
944
 
            try:
945
 
                statinfo = os.stat(self.path + os.sep + item)
946
 
            except OSError, e:
947
 
                if e.errno in self.acceptable_errors:
948
 
                    continue
949
 
                else:
950
 
                    raise
951
 
            liststore.append([ gtk.STOCK_DIRECTORY,
952
 
                               True,
953
 
                               item,
954
 
                               '',
955
 
                               '',
956
 
                               "<DIR>",
957
 
                               "<DIR>",
958
 
                               statinfo.st_mtime,
959
 
                               self._format_date(statinfo.st_mtime),
960
 
                               ''])
961
 
        for item in files:
962
 
            status = 'unknown'
963
 
            fileid = ''
964
 
            if not self.notbranch:
965
 
                filename = self.wt.relpath(self.path + os.sep + item)
966
 
                
967
 
                try:
968
 
                    self.wt.lock_read()
969
 
                    
970
 
                    for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
971
 
                        if rpathnew == filename:
972
 
                            status = 'renamed'
973
 
                            fileid = id
974
 
                    for rpath, id, kind in delta.added:
975
 
                        if rpath == filename:
976
 
                            status = 'added'
977
 
                            fileid = id
978
 
                    for rpath, id, kind in delta.removed:
979
 
                        if rpath == filename:
980
 
                            status = 'removed'
981
 
                            fileid = id
982
 
                    for rpath, id, kind, text_modified, meta_modified in delta.modified:
983
 
                        if rpath == filename:
984
 
                            status = 'modified'
985
 
                            fileid = id
986
 
                    for rpath, id, kind in delta.unchanged:
987
 
                        if rpath == filename:
988
 
                            status = 'unchanged'
989
 
                            fileid = id
990
 
                    for rpath, file_class, kind, id, entry in self.wt.list_files():
991
 
                        if rpath == filename and file_class == 'I':
992
 
                            status = 'ignored'
993
 
                finally:
994
 
                    self.wt.unlock()
995
 
            
996
 
            if status == 'renamed':
997
 
                st = _i18n('renamed')
998
 
            elif status == 'removed':
999
 
                st = _i18n('removed')
1000
 
            elif status == 'added':
1001
 
                st = _i18n('added')
1002
 
            elif status == 'modified':
1003
 
                st = _i18n('modified')
1004
 
            elif status == 'unchanged':
1005
 
                st = _i18n('unchanged')
1006
 
            elif status == 'ignored':
1007
 
                st = _i18n('ignored')
1008
 
            else:
1009
 
                st = _i18n('unknown')
1010
 
            
1011
 
            try:
1012
 
                statinfo = os.stat(self.path + os.sep + item)
1013
 
            except OSError, e:
1014
 
                if e.errno in self.acceptable_errors:
1015
 
                    continue
1016
 
                else:
1017
 
                    raise
1018
 
            liststore.append([gtk.STOCK_FILE,
1019
 
                              False,
1020
 
                              item,
1021
 
                              st,
1022
 
                              status,
1023
 
                              str(statinfo.st_size), # NOTE: if int used there it will fail for large files (size expressed as long int)
1024
 
                              self._format_size(statinfo.st_size),
1025
 
                              statinfo.st_mtime,
1026
 
                              self._format_date(statinfo.st_mtime),
1027
 
                              fileid])
1028
 
        
1029
 
        # Create the columns and add them to the TreeView
1030
 
        self.treeview_right.set_model(liststore)
1031
 
        self._tvcolumn_filename = gtk.TreeViewColumn(_i18n('Filename'))
1032
 
        self._tvcolumn_status = gtk.TreeViewColumn(_i18n('Status'))
1033
 
        self._tvcolumn_size = gtk.TreeViewColumn(_i18n('Size'))
1034
 
        self._tvcolumn_mtime = gtk.TreeViewColumn(_i18n('Last modified'))
1035
 
        self.treeview_right.append_column(self._tvcolumn_filename)
1036
 
        self.treeview_right.append_column(self._tvcolumn_status)
1037
 
        self.treeview_right.append_column(self._tvcolumn_size)
1038
 
        self.treeview_right.append_column(self._tvcolumn_mtime)
1039
 
        
1040
 
        # Set up the cells
1041
 
        cellpb = gtk.CellRendererPixbuf()
1042
 
        cell = gtk.CellRendererText()
1043
 
        self._tvcolumn_filename.pack_start(cellpb, False)
1044
 
        self._tvcolumn_filename.pack_start(cell, True)
1045
 
        self._tvcolumn_filename.set_attributes(cellpb, stock_id=0)
1046
 
        self._tvcolumn_filename.add_attribute(cell, 'text', 2)
1047
 
        self._tvcolumn_status.pack_start(cell, True)
1048
 
        self._tvcolumn_status.add_attribute(cell, 'text', 3)
1049
 
        self._tvcolumn_size.pack_start(cell, True)
1050
 
        self._tvcolumn_size.add_attribute(cell, 'text', 6)
1051
 
        self._tvcolumn_mtime.pack_start(cell, True)
1052
 
        self._tvcolumn_mtime.add_attribute(cell, 'text', 8)
1053
 
        
1054
 
        # Set up the properties of the TreeView
1055
 
        self.treeview_right.set_headers_visible(True)
1056
 
        self.treeview_right.set_headers_clickable(True)
1057
 
        self.treeview_right.set_search_column(1)
1058
 
        self._tvcolumn_filename.set_resizable(True)
1059
 
        self._tvcolumn_status.set_resizable(True)
1060
 
        self._tvcolumn_size.set_resizable(True)
1061
 
        self._tvcolumn_mtime.set_resizable(True)
1062
 
        # Set up sorting
1063
 
        liststore.set_sort_func(13, self._sort_filelist_callback, None)
1064
 
        liststore.set_sort_column_id(13, gtk.SORT_ASCENDING)
1065
 
        self._tvcolumn_filename.set_sort_column_id(13)
1066
 
        self._tvcolumn_status.set_sort_column_id(3)
1067
 
        self._tvcolumn_size.set_sort_column_id(5)
1068
 
        self._tvcolumn_mtime.set_sort_column_id(7)
1069
 
        
1070
 
        # Set sensitivity
1071
 
        self.set_sensitivity()
1072
 
        
 
906
       
1073
907
    def get_selected_fileid(self):
1074
908
        """ Get the file_id of the selected file. """
1075
 
        treeselection = self.treeview_right.get_selection()
 
909
        treeselection = self.window.treeview_right.get_selection()
1076
910
        (model, iter) = treeselection.get_selected()
1077
911
        
1078
912
        if iter is None:
1082
916
    
1083
917
    def get_selected_right(self):
1084
918
        """ Get the selected filename. """
1085
 
        treeselection = self.treeview_right.get_selection()
 
919
        treeselection = self.window.treeview_right.get_selection()
1086
920
        (model, iter) = treeselection.get_selected()
1087
921
        
1088
922
        if iter is None:
1157
991
                return
1158
992
    
1159
993
            # Get ListStore and clear it
1160
 
            liststore = self.treeview_right.get_model()
 
994
            liststore = self.window.filelist
1161
995
            liststore.clear()
1162
996
            
1163
997
            # Show Status column
1164
 
            self._tvcolumn_status.set_visible(True)
 
998
            self.window.col_status.set_visible(True)
1165
999
    
1166
1000
            dirs = []
1167
1001
            files = []
1181
1015
            # Try to open the working tree
1182
1016
            notbranch = False
1183
1017
            try:
1184
 
                tree1 = WorkingTree.open_containing(path)[0]
 
1018
                tree1 = WorkingTree.open_containing(os.path.realpath(path))[0]
1185
1019
            except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
1186
1020
                notbranch = True
1187
1021
            
1193
1027
                
1194
1028
            # Add'em to the ListStore
1195
1029
            for item in dirs:
 
1030
                status = ''
 
1031
                st = ''
 
1032
                fileid = ''
 
1033
                if not notbranch:
 
1034
                    filename = tree1.relpath(os.path.join(os.path.realpath(path), item))
 
1035
                    
 
1036
                    st, status = self.statusmapper(filename, delta)
 
1037
                    if not ignored_files and status == 'ignored':
 
1038
                        continue
 
1039
                
1196
1040
                try:
1197
1041
                    statinfo = os.stat(self.path + os.sep + item)
1198
1042
                except OSError, e:
1200
1044
                        continue
1201
1045
                    else:
1202
1046
                        raise
1203
 
                liststore.append([gtk.STOCK_DIRECTORY,
1204
 
                                  True,
1205
 
                                  item,
1206
 
                                  '',
1207
 
                                  '',
1208
 
                                  "<DIR>",
1209
 
                                  "<DIR>",
1210
 
                                  statinfo.st_mtime,
1211
 
                                  self._format_date(statinfo.st_mtime),
1212
 
                                  ''])
 
1047
                liststore.append([ gtk.STOCK_DIRECTORY,
 
1048
                                   True,
 
1049
                                   item,
 
1050
                                   st,
 
1051
                                   status,
 
1052
                                   "<DIR>",
 
1053
                                   "<DIR>",
 
1054
                                   statinfo.st_mtime,
 
1055
                                   self._format_date(statinfo.st_mtime),
 
1056
                                   ''])
1213
1057
            for item in files:
1214
 
                status = 'unknown'
 
1058
                status = ''
 
1059
                st = ''
1215
1060
                fileid = ''
1216
1061
                if not notbranch:
1217
 
                    filename = tree1.relpath(path + os.sep + item)
 
1062
                    filename = tree1.relpath(os.path.join(os.path.realpath(path), item))
1218
1063
                    
1219
 
                    try:
1220
 
                        self.wt.lock_read()
1221
 
                        
1222
 
                        for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
1223
 
                            if rpathnew == filename:
1224
 
                                status = 'renamed'
1225
 
                                fileid = id
1226
 
                        for rpath, id, kind in delta.added:
1227
 
                            if rpath == filename:
1228
 
                                status = 'added'
1229
 
                                fileid = id
1230
 
                        for rpath, id, kind in delta.removed:
1231
 
                            if rpath == filename:
1232
 
                                status = 'removed'
1233
 
                                fileid = id
1234
 
                        for rpath, id, kind, text_modified, meta_modified in delta.modified:
1235
 
                            if rpath == filename:
1236
 
                                status = 'modified'
1237
 
                                fileid = id
1238
 
                        for rpath, id, kind in delta.unchanged:
1239
 
                            if rpath == filename:
1240
 
                                status = 'unchanged'
1241
 
                                fileid = id
1242
 
                        for rpath, file_class, kind, id, entry in self.wt.list_files():
1243
 
                            if rpath == filename and file_class == 'I':
1244
 
                                status = 'ignored'
1245
 
                    finally:
1246
 
                        self.wt.unlock()
1247
 
                
1248
 
                if status == 'renamed':
1249
 
                    st = _i18n('renamed')
1250
 
                elif status == 'removed':
1251
 
                    st = _i18n('removed')
1252
 
                elif status == 'added':
1253
 
                    st = _i18n('added')
1254
 
                elif status == 'modified':
1255
 
                    st = _i18n('modified')
1256
 
                elif status == 'unchanged':
1257
 
                    st = _i18n('unchanged')
1258
 
                elif status == 'ignored':
1259
 
                    st = _i18n('ignored')
1260
 
                    if not ignored_files:
 
1064
                    st, status = self.statusmapper(filename, delta)
 
1065
                    if not ignored_files and status == 'ignored':
1261
1066
                        continue
1262
 
                else:
1263
 
                    st = _i18n('unknown')
1264
1067
                
1265
1068
                try:
1266
1069
                    statinfo = os.stat(self.path + os.sep + item)
1283
1086
            # We're remote
1284
1087
            
1285
1088
            # Get ListStore and clear it
1286
 
            liststore = self.treeview_right.get_model()
 
1089
            liststore = self.window.filelist
1287
1090
            liststore.clear()
1288
1091
            
1289
1092
            # Hide Status column
1290
 
            self._tvcolumn_status.set_visible(False)
 
1093
            self.window.col_status.set_visible(False)
1291
1094
            
1292
1095
            dirs = []
1293
1096
            files = []
1360
1163
            self.image_location_error.destroy()
1361
1164
 
1362
1165
        # Columns should auto-size
1363
 
        self.treeview_right.columns_autosize()
 
1166
        self.window.treeview_right.columns_autosize()
1364
1167
        
1365
1168
        # Set sensitivity
1366
1169
        self.set_sensitivity()
 
1170
    
 
1171
    def statusmapper(self, filename, delta):
 
1172
        status = 'unknown'
 
1173
        try:
 
1174
            self.wt.lock_read()
 
1175
            
 
1176
            for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
 
1177
                if rpathnew == filename:
 
1178
                    status = 'renamed'
 
1179
                    fileid = id
 
1180
            for rpath, id, kind in delta.added:
 
1181
                if rpath == filename:
 
1182
                    status = 'added'
 
1183
                    fileid = id
 
1184
            for rpath, id, kind in delta.removed:
 
1185
                if rpath == filename:
 
1186
                    status = 'removed'
 
1187
                    fileid = id
 
1188
            for rpath, id, kind, text_modified, meta_modified in delta.modified:
 
1189
                if rpath == filename:
 
1190
                    status = 'modified'
 
1191
                    fileid = id
 
1192
            for rpath, id, kind in delta.unchanged:
 
1193
                if rpath == filename:
 
1194
                    status = 'unchanged'
 
1195
                    fileid = id
 
1196
            for rpath, file_class, kind, id, entry in self.wt.list_files():
 
1197
                if rpath == filename and file_class == 'I':
 
1198
                    status = 'ignored'
 
1199
        finally:
 
1200
            self.wt.unlock()
 
1201
    
 
1202
        if status == 'renamed':
 
1203
            st = _i18n('renamed')
 
1204
        elif status == 'removed':
 
1205
            st = _i18n('removed')
 
1206
        elif status == 'added':
 
1207
            st = _i18n('added')
 
1208
        elif status == 'modified':
 
1209
            st = _i18n('modified')
 
1210
        elif status == 'unchanged':
 
1211
            st = _i18n('unchanged')
 
1212
        elif status == 'ignored':
 
1213
            st = _i18n('ignored')
 
1214
        else:
 
1215
            st = _i18n('unknown')
 
1216
        return st, status
1367
1217
 
1368
1218
    def _harddisks(self):
1369
1219
        """ Returns hard drive letters under Win32. """