2626import webbrowser
2727
2828from gettext import gettext as _
29+ from typing import Optional
2930from urllib .parse import urlparse
3031
3132from diffuse import constants
3233from diffuse import utils
3334from diffuse .dialogs import AboutDialog , FileChooserDialog , NumericDialog , SearchDialog
3435from diffuse .preferences import Preferences
3536from diffuse .resources import theResources
37+ from diffuse .utils import LineEnding
3638from diffuse .vcs .vcs_registry import VcsRegistry
3739from diffuse .widgets import FileDiffViewerBase
3840from diffuse .widgets import createMenu , LINE_MODE , CHAR_MODE , ALIGN_MODE
@@ -118,7 +120,7 @@ class Diffuse(Gtk.Window):
118120 class FileDiffViewer (FileDiffViewerBase ):
119121 # pane header
120122 class PaneHeader (Gtk .Box ):
121- def __init__ (self ):
123+ def __init__ (self ) -> None :
122124 Gtk .Box .__init__ (self , orientation = Gtk .Orientation .HORIZONTAL , spacing = 0 )
123125 _append_buttons (self , Gtk .IconSize .MENU , [
124126 [Gtk .STOCK_OPEN , self .button_cb , 'open' , _ ('Open File...' )],
@@ -171,7 +173,7 @@ def setEdits(self, has_edits):
171173
172174 # pane footer
173175 class PaneFooter (Gtk .Box ):
174- def __init__ (self ):
176+ def __init__ (self ) -> None :
175177 Gtk .Box .__init__ (self , orientation = Gtk .Orientation .HORIZONTAL , spacing = 0 )
176178 self .cursor = label = Gtk .Label .new ()
177179 self .cursor .set_size_request (- 1 , - 1 )
@@ -212,11 +214,11 @@ def updateCursor(self, viewer, f):
212214 # set the format label
213215 def setFormat (self , s ):
214216 v = []
215- if s & utils .DOS_FORMAT :
217+ if s & LineEnding .DOS_FORMAT :
216218 v .append ('DOS' )
217- if s & utils .MAC_FORMAT :
219+ if s & LineEnding .MAC_FORMAT :
218220 v .append ('Mac' )
219- if s & utils .UNIX_FORMAT :
221+ if s & LineEnding .UNIX_FORMAT :
220222 v .append ('Unix' )
221223 self .format .set_text ('/' .join (v ))
222224
@@ -1108,7 +1110,7 @@ def remove_tab_cb(self, widget, data):
11081110 self .quit_cb (widget , data )
11091111
11101112 # convenience method to request confirmation when closing the last tab
1111- def _confirm_tab_close (self ):
1113+ def _confirm_tab_close (self ) -> bool :
11121114 dialog = utils .MessageDialog (
11131115 self .get_toplevel (),
11141116 Gtk .MessageType .WARNING ,
@@ -1193,7 +1195,7 @@ def syntax_changed_cb(self, widget, s):
11931195 self .setSyntax (s )
11941196
11951197 # create an empty viewer with 'n' panes
1196- def newFileDiffViewer (self , n ) :
1198+ def newFileDiffViewer (self , n : int ) -> FileDiffViewer :
11971199 self .viewer_count += 1
11981200 tabname = _ ('File Merge %d' ) % (self .viewer_count , )
11991201 tab = NotebookTab (tabname , Gtk .STOCK_FILE )
@@ -1338,13 +1340,13 @@ def createModifiedFileTabs(self, items, labels, options):
13381340 )
13391341
13401342 # close all tabs without differences
1341- def closeOnSame (self ):
1343+ def closeOnSame (self ) -> None :
13421344 for i in range (self .notebook .get_n_pages () - 1 , - 1 , - 1 ):
13431345 if not self .notebook .get_nth_page (i ).hasDifferences ():
13441346 self .notebook .remove_page (i )
13451347
13461348 # returns True if the application can safely quit
1347- def confirmQuit (self ):
1349+ def confirmQuit (self ) -> bool :
13481350 nb = self .notebook
13491351 return self .confirmCloseViewers ([nb .get_nth_page (i ) for i in range (nb .get_n_pages ())])
13501352
@@ -1356,7 +1358,7 @@ def delete_cb(self, widget, event):
13561358 return True
13571359
13581360 # returns the currently focused viewer
1359- def getCurrentViewer (self ):
1361+ def getCurrentViewer (self ) -> Optional [ Gtk . Widget ] :
13601362 return self .notebook .get_nth_page (self .notebook .get_current_page ())
13611363
13621364 # callback for the open file menu item
@@ -1570,7 +1572,7 @@ def go_to_line_cb(self, widget, data):
15701572 self .getCurrentViewer ().go_to_line_cb (widget , data )
15711573
15721574 # notify all viewers of changes to the preferences
1573- def preferences_updated (self ):
1575+ def preferences_updated (self ) -> None :
15741576 n = self .notebook .get_n_pages ()
15751577 self .notebook .set_show_tabs (self .prefs .getBool ('tabs_always_show' ) or n > 1 )
15761578 for i in range (n ):
@@ -1712,7 +1714,7 @@ def _append_buttons(box, size, specs):
17121714
17131715
17141716# constructs a full URL for the named file
1715- def _path2url (path , proto = 'file' ):
1717+ def _path2url (path : str , proto : str = 'file' ) -> str :
17161718 r = [proto , ':///' ]
17171719 s = os .path .abspath (path )
17181720 i = 0
0 commit comments