Ver código fonte

Merge pull request #698 from csmith/master

Avoid raising events before a frame has an ID.
pull/700/head
Greg Holmes 7 anos atrás
pai
commit
b20d26e844

+ 0
- 1
src/main/java/com/dmdirc/Channel.java Ver arquivo

@@ -120,7 +120,6 @@ public class Channel extends FrameContainer implements GroupChat {
120 120
         initBackBuffer();
121 121
         registerCallbacks();
122 122
         updateTitle();
123
-        selfJoin();
124 123
     }
125 124
 
126 125
     public ChannelInfo getChannelInfo() {

+ 1
- 0
src/main/java/com/dmdirc/ChannelFactory.java Ver arquivo

@@ -82,6 +82,7 @@ public class ChannelFactory {
82 82
                 channel::getMaxLineLength));
83 83
         windowManager.addWindow(connection.getWindowModel(), channel);
84 84
         connection.getWindowModel().getEventBus().publish(new ChannelOpenedEvent(channel));
85
+        channel.selfJoin();
85 86
         return channel;
86 87
     }
87 88
 }

+ 27
- 5
src/main/java/com/dmdirc/FrameContainer.java Ver arquivo

@@ -125,6 +125,17 @@ public class FrameContainer implements WindowModel {
125 125
         this.id = id;
126 126
     }
127 127
 
128
+    /**
129
+     * Indicates whether this container has been assigned an ID yet.
130
+     *
131
+     * <p>The container should not post events until it has an ID.
132
+     *
133
+     * @return True if the container has an ID, false otherwise.
134
+     */
135
+    protected boolean hasId() {
136
+        return id != null;
137
+    }
138
+
128 139
     @Override
129 140
     public String getIcon() {
130 141
         return icon;
@@ -154,14 +165,18 @@ public class FrameContainer implements WindowModel {
154 165
     public void setName(final String name) {
155 166
         this.name = name;
156 167
 
157
-        eventBus.publishAsync(new FrameNameChangedEvent(this, name));
168
+        if (hasId()) {
169
+            eventBus.publishAsync(new FrameNameChangedEvent(this, name));
170
+        }
158 171
     }
159 172
 
160 173
     @Override
161 174
     public void setTitle(final String title) {
162 175
         this.title = title;
163 176
 
164
-        eventBus.publishAsync(new FrameTitleChangedEvent(this, title));
177
+        if (hasId()) {
178
+            eventBus.publishAsync(new FrameTitleChangedEvent(this, title));
179
+        }
165 180
     }
166 181
 
167 182
     @Override
@@ -172,14 +187,19 @@ public class FrameContainer implements WindowModel {
172 187
     @Override
173 188
     public void addComponent(final String component) {
174 189
         components.add(component);
175
-        eventBus.publishAsync(new FrameComponentAddedEvent(this, component));
190
+
191
+        if (hasId()) {
192
+            eventBus.publishAsync(new FrameComponentAddedEvent(this, component));
193
+        }
176 194
     }
177 195
 
178 196
     @Override
179 197
     public void removeComponent(final String component) {
180 198
         components.remove(component);
181 199
 
182
-        eventBus.publishAsync(new FrameComponentRemovedEvent(this, component));
200
+        if (hasId()) {
201
+            eventBus.publishAsync(new FrameComponentRemovedEvent(this, component));
202
+        }
183 203
     }
184 204
 
185 205
     @Override
@@ -204,7 +224,9 @@ public class FrameContainer implements WindowModel {
204 224
      * Called when this container's icon is updated.
205 225
      */
206 226
     private void iconUpdated() {
207
-        eventBus.publish(new FrameIconChangedEvent(this, icon));
227
+        if (hasId()) {
228
+            eventBus.publish(new FrameIconChangedEvent(this, icon));
229
+        }
208 230
     }
209 231
 
210 232
     @Override

Carregando…
Cancelar
Salvar