@@ -21,8 +21,7 @@ public class FileFragment extends BaseFragment {
2121 private SoraEditor editor ;
2222 private FileX file ;
2323 private boolean isModified = false ;
24- private String title ;
25-
24+
2625 private SubscriptionReceipt contentChangeEvent ;
2726
2827 private FileFragment () {}
@@ -41,7 +40,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ex
4140 }
4241 editor .setEditorLanguage (
4342 new SoraTextMateLanguage (requireActivity (), "source" + file .getExtension ()));
44-
43+
4544 if (!file .exists ()) {
4645 ErrorDialog .show (requireActivity (), new FileNotFoundException (file .getPath ()));
4746 return editor ;
@@ -53,16 +52,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle ex
5352 ErrorDialog .show (requireActivity (), err );
5453 }
5554
56- contentChangeEvent = editor .subscribeEvent (
57- ContentChangeEvent .class ,
58- (s , event ) -> {
59- if (!isModified ) {
60- isModified = true ;
61- updateTitle ();
62- }
63- });
64-
65- updateTitle ();
55+ contentChangeEvent =
56+ editor .subscribeEvent (
57+ ContentChangeEvent .class ,
58+ (s , event ) -> {
59+ if (!isModified ) {
60+ isModified = true ;
61+ changeTitle ();
62+ }
63+ });
64+
65+ changeTitle ();
6666 return editor ;
6767 }
6868
@@ -73,15 +73,10 @@ public void onDestroyView() {
7373 }
7474 super .onDestroyView ();
7575 }
76-
76+
7777 @ Override
7878 public String getTitle () {
79- return title ;
80- }
81-
82- private void updateTitle () {
83- title = file .getName () + (isModified ? "*" : "" );
84- changeTitle (title );
79+ return file .getName () + (isModified ? "*" : "" );
8580 }
8681
8782 public static FileFragment newInstance (File file ) {
@@ -112,23 +107,17 @@ public void save() {
112107 try {
113108 file .write (editor .getText ().toString ());
114109 isModified = false ;
115- updateTitle ();
110+ changeTitle ();
116111 } catch (Exception err ) {
117112 ErrorDialog .show (requireActivity (), err );
118113 }
119114 }
120115
121- @ Override
122- public void changeTitle (String title ) {
123- this .title = title ;
124- super .changeTitle (title );
125- }
126-
127116 public void saveAs (File newFile ) {
128117 if (newFile == null ) {
129118 throw new IllegalArgumentException ("New file cannot be null" );
130119 }
131120 this .file = new FileX (newFile );
132121 save ();
133122 }
134- }
123+ }
0 commit comments