Class: QDA::GUI::WeftClient

Inherits:
Wx::App
  • Object
show all
Includes:
Broadcaster, Subscriber, Wx
Defined in:
lib/weft/wxgui.rb

Constant Summary collapse

SUBSCRIBABLE_EVENTS =
QDA::Application::SUBSCRIBABLE_EVENTS +
[ :focus_category, :focus_document, :text_font_changed ]

Instance Attribute Summary collapse

Attributes included from Broadcaster

#bc__subscribers, #bc__subscriptions

Instance Method Summary collapse

Methods included from Subscriber

#subscribe

Methods included from Broadcaster

#broadcast, #delete_subscriber, #event_types, #reset_subscriptions

Instance Attribute Details

#appObject

Returns the value of attribute app.



21
22
23
# File 'lib/weft/wxgui.rb', line 21

def app
  @app
end

#current_categoryObject

Returns the value of attribute current_category.



22
23
24
# File 'lib/weft/wxgui.rb', line 22

def current_category
  @current_category
end

#current_documentObject

Returns the value of attribute current_document.



22
23
24
# File 'lib/weft/wxgui.rb', line 22

def current_document
  @current_document
end

#display_fontObject

Returns the value of attribute display_font.



21
22
23
# File 'lib/weft/wxgui.rb', line 21

def display_font
  @display_font
end

Returns the value of attribute sidebar.



21
22
23
# File 'lib/weft/wxgui.rb', line 21

def sidebar
  @sidebar
end

#workareaObject (readonly)

Returns the value of attribute workarea.



21
22
23
# File 'lib/weft/wxgui.rb', line 21

def workarea
  @workarea
end

Instance Method Details

#add_icon_dir(dir) ⇒ Object



727
728
729
# File 'lib/weft/wxgui.rb', line 727

def add_icon_dir(dir)
  @icon_dirs.push(dir)
end

#add_subscriber(subscriber, *events) ⇒ Object



480
481
482
483
484
485
486
# File 'lib/weft/wxgui.rb', line 480

def add_subscriber(subscriber, *events)
  super
  subscriber.evt_close do | e | 
    delete_subscriber(subscriber)
    e.skip()
  end
end

#confirm_unsaved_changesObject



686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/weft/wxgui.rb', line 686

def confirm_unsaved_changes()
  unless @app and  @app.dirty?
    # there's no open project or there's no unsaved changes
    return true 
  end

  style = NO_DEFAULT|YES|NO|CANCEL|ICON_EXCLAMATION
  confirm = MessageDialog.new( nil, 
                               Lang::UNSAVED_CHANGES_CONFIRM,
                               Lang::UNSAVED_CHANGES_CONFIRM_TITLE, 
                               style )
  case confirm.show_modal()
  when ID_YES
    @app.dbfile ? save_project() : on_saveas_project(nil)
    return true
  when ID_CANCEL
    return false
  when ID_NO
    return true
  end
end

#create_menusObject

create menus - also only created once, then manipulated as projects open and close.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/weft/wxgui.rb', line 88

def create_menus()
     @menu_file = EasyMenu.new(@workarea)
		@menu_file.add_item("&New Project", "Ctrl-N") do | e |
       on_new_project(e)
     end
		@menu_file.add_item("&Open Project", "Ctrl-O") do | e |
       on_open_project(e)
     end
		@menu_file.add_item("&Close Project") do | e | 
       on_close_project(e)
     end
		@menu_file.append_separator()
		@menu_file.add_item("&Save Project", "Ctrl-S") do | e |
       on_save_project(e)
     end
		@menu_file.add_item("Save Project &As", "Ctrl-Shift-S") do | e |
       on_saveas_project(e)
     end
		@menu_file.add_item("&Revert", "Ctrl-Shift-R") do | e |
       on_revert_project(e)
     end
		@menu_file.append_separator()
		@menu_file.add_item("&Exit", "Alt-F4") do | e | 
       @workarea.close() # this will trigger on_quit
     end

     
     @menu_view = EasyMenu.new(@workarea)
     if WINDOW_MODE == :MDI
       @menu_view.add_item("&Documents and Categories", "",
                            Wx::ITEM_CHECK) { | e | on_toggle_dandc(e) }
     end

		@menu_view.add_item("&Set Display Font") do | e | 
       on_set_display_font(e)
     end
     
		@menu_project = EasyMenu.new(@workarea)
		@menu_project.add_item("&Import Document") do | e | 
       on_import_document(e) 
     end
     @menu_project.add_item("Delete Document") do | e |
       on_delete_document(e)
     end
     @menu_project.append_separator()
		@menu_project.add_item("&Add Category") do | e | 
       on_add_category() 
     end
     @menu_project.add_item("Delete Category") do | e |
       on_delete_category(e)
     end        
     @menu_project.append_separator()
		@menu_project.add_item("&Export") do | e | 
       on_export(e)
     end
     
# 		menu_project.append(MENU_IMPORT_DOCUMENT_CLIPBOARD , 
# 							"&Import Document...\t", 'Import')
# 		@workarea.evt_menu(MENU_IMPORT_DOCUMENT_CLIPBOARD) do | e | 
#           on_paste_import_document(e) 
#         end

		@menu_search = EasyMenu.new(@workarea)
		@menu_search.add_item("&Search") { | e | on_search(e) }

		@menu_search.add_item("&Query") { | e | on_query(e) }
		@menu_search.add_item("&Review Coding") { | e | on_review_coding(e) }
		@menu_search.append_separator()
		@menu_search.add_item("Reindex &Documents") do | e |  
       on_search_reindex(e)
     end

     # hide script in release builds
     if ::WEFT_TESTING
       @menu_script = EasyMenu.new(@workarea)
       @menu_script.add_item("&New") { | e | on_start_script(e) }
     end


@menu_help = EasyMenu.new(@workarea)
@menu_help.add_item("&Help") { | e | on_help(e) }
@menu_help.add_item("&About") { | e | on_help_about(e) }
     menu_state_no_project()
     
		menu_bar = Wx::MenuBar.new()
     menu_bar.append(@menu_file, "&File")
		menu_bar.append(@menu_view, "&View")
		menu_bar.append(@menu_project, "&Project")
		menu_bar.append(@menu_search, "&Search")
		menu_bar.append(@menu_script, "&Script") if ::WEFT_TESTING
     menu_bar.append(@menu_help, "&Help") 

     @workarea.menu_bar = menu_bar
end

#create_workareaObject

create the workarea - would normally only be called once in a whole execution



79
80
81
82
83
84
# File 'lib/weft/wxgui.rb', line 79

def create_workarea()
		@workarea = WorkArea.new(self)
  # TODO - nice windows icon
  @workarea.set_icon( fetch_icon("weft") )
  @workarea.evt_close() { | e | on_quit(e) }
end

#fetch_icon(icon) ⇒ Object

hunt through icon directories to find an icon icon - returns a Wx::Icon constructed from that file, or raise an exception. icon should be the name of an icon file without the extension. This method will search only for icons appropriate to the current platform. Raises a RuntimeError if no icon is found.

Raises:

  • (RuntimeError)


714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/weft/wxgui.rb', line 714

def fetch_icon(icon)
  ICON_EXTS.each do | type |
    maybe_icon_file = "%s.%s" % [ icon, type.extension ]
    @icon_dirs.each do | dir | 
      if File.exist?( f = File.join(dir, maybe_icon_file) )
        return Wx::Icon.new( f, type.constant )
      end
    end
  end
  
  raise RuntimeError, "Could not find icon #{icon}"
end

#finishObject

forcibly closes all the windows - does not check for project saved state - just ends everything



73
74
75
# File 'lib/weft/wxgui.rb', line 73

def finish()
  @workarea.close()
end

#import_documentObject

import a document



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/weft/wxgui.rb', line 275

def import_document()
		file_dialog = ImportFileDialog.new(@workarea, QDA::Document)
  return unless file_dialog.show_modal() == Wx::ID_OK
  file_dialog.each_with_path do | fpath, fname |
       Wx::BusyCursor.busy do
         prog = StageProgressDialog.new(@workarea, "Importing document",
                                        "Reading file #{fname}")
         begin
           doc = Filters.import_file(Document, fpath) do | doc, filter |
             doc.title = fname.gsub(/\.\w+$/, '')
           end
           prog.step('Saving document')
           @app.save_document(doc, true)
           prog.title = "Importing document '#{doc.title}'"
           prog.step("Indexing document '#{doc.title}'")
           indexer = QDA::WordIndexer.new()
           indexer.feed(doc)
           prog.step("Saving word indexes for '#{doc.title}'")
           wordcount = indexer.words.keys.length
           if wordcount > 0
             prog.retarget(wordcount)
             @app.save_reverse_index(doc.dbid, indexer.words, prog)
           end
           prog.finish()
         rescue FilterError, UserAbortedException, 
                IOError, QDA::Backend::BackendError => err
           prog.finish() if prog
           app.delete_document(doc) if doc && doc.dbid
           ErrorDialog.display( "Document not imported", err.to_s() )
           @workarea.cursor = Wx::Cursor.new(Wx::CURSOR_ARROW)
         end
       end
		end
end

#main_loopObject



52
53
54
55
56
57
58
59
60
# File 'lib/weft/wxgui.rb', line 52

def main_loop()
  super()
rescue Exception => err
  if REPORT_CRASHES and not err.kind_of? SystemExit
    workarea.hide_all()
    CrashReportDialog.display(self, err)
  end
  Kernel.raise(err)
end

updates the state of the menu above the main workarea to its initial state with no active project



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/weft/wxgui.rb', line 637

def menu_state_no_project()
  @menu_file.disable_items(:close_project, :save_project,
                           :save_project_as, :revert)
  @menu_project.disable_items(:import_document, :delete_document,
                              :add_category, :delete_category,
                              :export)
		@menu_search.disable_items( :search, :query, :review_coding,
                              :reindex_documents)
		@menu_script.disable_items(:new) if ::WEFT_TESTING
		if WINDOW_MODE == :MDI
		  @menu_view.disable_item(:documents_and_categories, :set_display_font)
  else
    @menu_view.disable_item(:set_display_font)
  end
end

updates the state of the menu above the main workarea to reflect the fact that a project has been opened.



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/weft/wxgui.rb', line 655

def menu_state_open_project()
  # :revert and :save_project are enabled when a change has been made
  @menu_file.enable_items(:close_project, :save_project_as)
  @menu_project.enable_items( :import_document, :delete_document,
                              :add_category, :delete_category,
                              :export)
		@menu_search.enable_items( :search, :query, :review_coding, 
                             :reindex_documents)
		@menu_script.enable_items(:new) if ::WEFT_TESTING
		if WINDOW_MODE == :MDI
    @menu_view.enable_item(:documents_and_categories, :set_display_font)
    @menu_view.check_item(:documents_and_categories)
  else
    @menu_view.enable_item(:set_display_font)        
  end
end

#notify(ev, content = nil) ⇒ Object



488
489
490
491
492
493
494
495
496
# File 'lib/weft/wxgui.rb', line 488

def notify(ev, content = nil)
  if ev == :saved or ev == :started
    @menu_file.disable_items(:save_project, :revert)
  else
    @menu_file.enable_items(:save_project)
    @menu_file.enable_items(:revert) if app.dbfile
  end
  broadcast(ev, content)
end

#on_add_categoryObject



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/weft/wxgui.rb', line 322

def on_add_category()
  dialog = Wx::TextEntryDialog.new(@workarea.d_and_c, "Add Category\n",
                                   "Enter the new category name",
                                   "", Wx::OK | Wx::CANCEL)
  return unless dialog.show_modal() == Wx::ID_OK

  # go ahead and make the new category
  parent = self.current_category || @app.get_root_category('CATEGORIES')  
  name   = dialog.get_value()
  begin
    cat = QDA::Category.new(name, parent )
    @app.save_category(cat)
  rescue QDA::BadNameError
    ErrorDialog.display( Lang::BAD_CATEGORY_NAME_TITLE, 
                         Lang::BAD_CATEGORY_NAME_WARNING )
    return false
  rescue QDA::NotUniqueNameError
    ErrorDialog.display( Lang::DUPLICATE_CATEGORY_NAME_TITLE, 
                         Lang::DUPLICATE_CATEGORY_NAME_WARNING )
    return false
    
  end
end

#on_category_open(cat) ⇒ Object



254
255
256
257
258
259
# File 'lib/weft/wxgui.rb', line 254

def on_category_open(cat)
  if not cat.codes
    cat = @app.get_category(cat.dbid)
  end
     @workarea.launch_window(CategoryWindow, cat)
end

#on_close_project(e) ⇒ Object

Tries to close the current project, checking for unsaved changes. Returns true if the currently open project was closed, or false if it was not. If there was no currently open project, always returns true.



676
677
678
679
680
681
682
683
684
# File 'lib/weft/wxgui.rb', line 676

def on_close_project(e)
  return true unless @app
  if confirm_unsaved_changes()
    unpopulate()
    return true
  else
    return false
  end
end

#on_delete_category(e = nil) ⇒ Object

deletes the currently active category



347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/weft/wxgui.rb', line 347

def on_delete_category(e = nil)
  return false unless current_category
  msg = Lang::DELETE_CATEGORY_WARNING % current_category.name
  confirm = SuppressibleConfirmDialog.display( 'DeleteCategory',
                                          Lang::DELETE_CATEGORY_TITLE,
                                          msg )
  
  return false unless confirm == Wx::ID_YES
  Wx::BusyCursor.busy() do
    @app.delete_category(current_category)
  end
end

#on_delete_document(e = nil) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
# File 'lib/weft/wxgui.rb', line 310

def on_delete_document(e = nil)
  return unless current_document
  msg = Lang::DELETE_DOCUMENT_WARNING % current_document.title
  confirm = SuppressibleConfirmDialog.display('DeleteDocument',
                                          Lang::DELETE_DOCUMENT_TITLE,
                                          msg )
  return unless confirm == Wx::ID_YES
  Wx::BusyCursor.busy do
    @app.delete_document( current_document )
  end
end

#on_document_open(doc, offset = 0) ⇒ Object

opens the document identified by doc_id, and, if offset is supplied, jumps to that point in the document



185
186
187
188
189
190
# File 'lib/weft/wxgui.rb', line 185

def on_document_open(doc, offset = 0)
     dbid = doc.is_a?(Document) ? doc.dbid : doc
		doc = @app.get_document(dbid)
     win = @workarea.launch_window(DocumentWindow, doc)
     win.jump_to(offset)
end

#on_export(e) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/weft/wxgui.rb', line 361

def on_export(e)
  a_win = @workarea.active_child
  return unless a_win.respond_to?(:object)
  obj = a_win.object
  file_dialog = ExportFileDialog.new(@workarea, obj)
  return unless file_dialog.show_modal() == Wx::ID_OK
  Wx::BusyCursor.busy do
    filter = file_dialog.filter.new(app)
    File.open(file_dialog.get_path, 'w') do | outfile |
      filter.write(obj, outfile)
    end
  end
end

#on_help(e) ⇒ Object



246
247
248
# File 'lib/weft/wxgui.rb', line 246

def on_help(e)
  InformationDialog.display('Help', Lang::HELP_HELP_MESSAGE)
end

#on_help_about(e) ⇒ Object



250
251
252
# File 'lib/weft/wxgui.rb', line 250

def on_help_about(e)
  InformationDialog.display('About', Lang::HELP_ABOUT_MESSAGE)
end

#on_import_document(e) ⇒ Object



270
271
272
# File 'lib/weft/wxgui.rb', line 270

def on_import_document(e)
  import_document()
end

#on_import_n6(e) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/weft/wxgui.rb', line 568

def on_import_n6(e)
     wildcard = "N6 Project Files (*.stp)|*.stp"
		file_dialog = Wx::FileDialog.new(@workarea, "Import N6 Project", "",  
                                      "", wildcard )
		if file_dialog.show_modal() == Wx::ID_OK
       Wx::BusyCursor.busy do 
         src = QDA::Application.new()
         src.extend(QDA::Backend::N6)
         src.start( :basedir => file_dialog.get_directory() )
         on_new_project(nil)

         @app.batch() do
           src.get_all_docs.each do | d |
             d.dbid = nil
             @app._save_document(d)
             broadcast(:document_added, d)
           end
         
           save_down = Proc.new do | cat |
             if cat.parent.nil?
               cat.name = "IMPORTED"
             end
             @app._save_category(cat)
             broadcast(:category_added, cat)

             cat.children.each { | c | save_down.call(c) }
           end

           save_down.call(src.get_all_categories)
         end
       end
		end
end

#on_initObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/weft/wxgui.rb', line 30

def on_init()
  self.app_name = 'WeftQDA'
  # retrieve font
  conf = Wx::ConfigBase.get()
  conf.path = '/DisplayFont'
  @display_font = Wx::Font.new( conf.read_int('size', 12), 
                                conf.read_int('family', Wx::DEFAULT),
                                conf.read_int('style', Wx::NORMAL),
                                conf.read_int('weight', Wx::NORMAL),
                                false,
                                conf.read('face', '') )
  # see wxgui/lang.rb
  Lang::set_language('En')
  @icon_dirs = []
  add_icon_dir( File.join( WEFT_SHAREDIR, 'icons') )
  add_icon_dir( File.join( File.dirname( __FILE__ ), 'wxgui') )
  create_workarea()
  create_menus()
		@workarea.show()
end

#on_new_project(e) ⇒ Object

Starts a new project



558
559
560
561
562
563
564
565
566
# File 'lib/weft/wxgui.rb', line 558

def on_new_project(e)
     return unless on_close_project(e)
     # TODO - this process is too protracted
     self.app = QDA::Application.new(QDA::Backend::SQLite)
     app.start(:dbfile => nil)
     app.install_clean()
     app.set_up()
     populate()
end

#on_open_project(e) ⇒ Object

returns true if a new project was started, false if not



456
457
458
459
460
461
462
463
464
# File 'lib/weft/wxgui.rb', line 456

def on_open_project(e)
     return false unless on_close_project(e)
		file_dialog = FileDialog.new( @workarea, "Open Project",
                                   "",  "", 
                                   "Weft QDA Project Files (*.qdp)|*.qdp" )
     return false unless file_dialog.show_modal() == Wx::ID_OK
     
     open_project( file_dialog.get_path() )
end

#on_print(e) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/weft/wxgui.rb', line 375

def on_print(e)
  a_win = @workarea.active_child
  return unless a_win.respond_to?(:object)
  obj = a_win.object
  htmlprint = Wx::HtmlEasyPrinting.new('Weft print', @workarea)
  htmlprint.page_setup()
  file_dialog = ExportFileDialog.new(@workarea, obj)
  return unless file_dialog.show_modal() == Wx::ID_OK
  Wx::BusyCursor.busy do
    filter = file_dialog.filter.new(app)
    File.open(file_dialog.get_path, 'w') do | outfile |
      filter.write(obj, outfile)
    end
  end      
end

#on_query(e) ⇒ Object

run a new query



391
392
393
394
395
396
397
# File 'lib/weft/wxgui.rb', line 391

def on_query(e)
  q_id = app.get_preference('NextQuery') || 1
  app.save_preference('NextQuery', q_id + 1)
  q = Query.new()
  q.dbid = q_id
  @workarea.launch_window(QueryWindow, q)
end

#on_quit(event) ⇒ Object



434
435
436
437
438
439
440
441
442
443
# File 'lib/weft/wxgui.rb', line 434

def on_quit(event)
  if on_close_project(event)
    # remember window position and size
    @workarea.remember_size()
    event.skip()
    exit() # required to exit reliably on Linux
  else
    event.veto()
  end
end

#on_resize(e) ⇒ Object

should resize the toolbar window in proportion to the main window - seems to cause it to go corrupted looking though



510
511
512
513
514
515
# File 'lib/weft/wxgui.rb', line 510

def on_resize(e)
  # if @tools
  #   @tools.set_client_size( proportional_size(0.3, 0.995) )
  # end

end

#on_revert_project(e) ⇒ Object



445
446
447
448
449
450
451
452
453
# File 'lib/weft/wxgui.rb', line 445

def on_revert_project(e)
  result = WarningDialog.display( Lang::REVERT_WARNING_TITLE,
                                  Lang::REVERT_WARNING_MESSAGE )
  return unless result == Wx::ID_OK
  
  the_file = @app.dbfile
  unpopulate()
  open_project(the_file)
end

#on_review_coding(e) ⇒ Object

run a new query



400
401
402
403
404
405
406
# File 'lib/weft/wxgui.rb', line 400

def on_review_coding(e)
  q_id = @app.get_preference('NextReview') || 1
  app.save_preference('NextReview', q_id + 1)
  q = CodeReview.new()
  q.dbid = q_id
  @workarea.launch_window(CodeReviewWindow, q)
end

#on_save_project(e) ⇒ Object

Handles requests to save the project. Do nothing if no project is open, prompt the user to supply a filename if this is a new project, otherwise just save the project.



520
521
522
523
524
# File 'lib/weft/wxgui.rb', line 520

def on_save_project(e)
  return unless app
  return on_saveas_project(e) unless app.dbfile
  save_project()
end

#on_saveas_project(e) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/weft/wxgui.rb', line 531

def on_saveas_project(e)
  wildcard = "Weft QDA Project Files (*.qdp)|*.qdp"
		file_dialog = Wx::FileDialog.new(@workarea, "Save Project As",
				 "",  "", wildcard, Wx::SAVE)

		if file_dialog.show_modal() == Wx::ID_OK
		  new_file = file_dialog.get_path()

		  if FileTest.exists?(new_file)
			confirm = MessageDialog.new(nil, Lang::FILE_ALREADY_EXISTS,
				"File already exists", 
				NO_DEFAULT|OK|CANCEL|ICON_EXCLAMATION)
			case confirm.show_modal()
			when ID_OK
			  # ok
			when ID_CANCEL
			  return()
			else
			  raise "Bad Status"
			end
		  end
    Wx::BusyCursor.busy() { app.save(new_file) }
  end
end

#on_search(e) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/weft/wxgui.rb', line 408

def on_search(e)
		search = SearchDialog.new(@workarea)
		if search.show_modal() == Wx::ID_OK
       Wx::BusyCursor.busy do
         options = { :wrap_both => search.expand,
                     :case_sensitive => search.case_sensitive,
                     :whole_word => search.whole_word }
         
         text_results = app.get_search_fragments(search.term, options)
         title = "'#{search.term}' (#{Lang::SEARCH_RESULTS}) "

         # create a category from the returned fragments
         search_parent = @app.get_root_category('SEARCHES')
         search_cat = Category.new( title, search_parent )
         search_cat.codetable_init() # urgh
         text_results.each do | docid, fragments |
           fragments.each do | f | 
             search_cat.code( f.docid, f.offset, f.length )
           end
         end
         app.save_category(search_cat, true)
         @workarea.launch_window(CategoryWindow, search_cat)
       end
		end		
end

#on_search_reindex(e) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/weft/wxgui.rb', line 217

def on_search_reindex(e)
  confirm = WarningDialog.display( Lang::REINDEX_DOCS_WARNING_TITLE, 
                                   Lang::REINDEX_DOCS_WARNING )
  return true unless confirm == Wx::ID_YES
  
  Wx::BusyCursor.busy do
    begin
      docs = @app.get_all_docs()
      prog =  StageProgressDialog.new(@workarea, 
                                      "Reindexing documents", '')
      
      prog.retarget(docs.length + 2)
      docs.each do | doc |
        prog.step("Indexing document #{doc.title}")
        doc = @app.get_doc(doc.dbid)
        @app.drop_reverse_indexes(doc.dbid)
        indexer = QDA::WordIndexer.new()
        indexer.feed(doc)
        @app.save_reverse_index(doc.dbid, indexer.words)
      end
      prog.finish()
    rescue UserAbortedException => err
      prog.finish() if prog
      ErrorDialog.display("Reindex halted", err.to_s())
      @workarea.cursor = Wx::NORMAL_CURSOR
    end
  end
end

#on_set_display_font(e) ⇒ Object



207
208
209
210
211
212
213
214
215
# File 'lib/weft/wxgui.rb', line 207

def on_set_display_font(e)
  font_data = Wx::FontData.new()
  font_data.initial_font = display_font
  dialog = Wx::FontDialog.new(@workarea, font_data)
  return unless dialog.show_modal() == Wx::ID_OK

  # actually find the newly selected font and communicate new choice
  self.display_font = dialog.font_data.chosen_font()
end

#on_start_script(e) ⇒ Object

run a new query



262
263
264
265
266
267
268
# File 'lib/weft/wxgui.rb', line 262

def on_start_script(e)
  s_id = @app.get_preference('NextScript') || 1
  @app.save_preference('NextScript', s_id + 1)
  s = Script.new()
  s.dbid = s_id
  @workarea.launch_window(ScriptWindow, s)
end

#on_toggle_dandc(e) ⇒ Object



498
499
500
501
502
503
504
505
506
# File 'lib/weft/wxgui.rb', line 498

def on_toggle_dandc(e)
  if @workarea.d_and_c_visible?
    @workarea.hide_d_and_c()
    @menu_view.uncheck_items(:documents_and_categories)
  else
    @workarea.show_d_and_c()
    @menu_view.check_items(:documents_and_categories)
  end
end

#open_project(pfile) ⇒ Object



466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/weft/wxgui.rb', line 466

def open_project(pfile)
  @workarea.set_cursor( Wx::BUSY_CURSOR )
  self.app = QDA::Application.new()
  app.extend( QDA::Backend::SQLite )
  app.start(:dbfile => pfile)
  populate()
rescue ArgumentError, NotImplementedError => err
  ErrorDialog.display(Lang::OPEN_PROJECT_ERROR_TITLE, err.to_s)
  self.app = nil
  return false
ensure
    @workarea.set_cursor( Wx::NORMAL_CURSOR )
end

#populateObject



731
732
733
734
735
736
737
738
739
740
# File 'lib/weft/wxgui.rb', line 731

def populate()
     unless app
       raise "Populate called without an @app set"
     end
     @workarea.show_d_and_c()
     # restore windows
     @workarea.restore_layouts

     menu_state_open_project()
end

#save_projectObject



526
527
528
529
# File 'lib/weft/wxgui.rb', line 526

def save_project()
  @workarea.remember_layouts()
  Wx::BusyCursor.busy() { app.save }
end

#unpopulateObject

unloads the currently loaded Weft instance and tidies up the GUI



624
625
626
627
628
629
630
631
632
633
# File 'lib/weft/wxgui.rb', line 624

def unpopulate()
  return unless app

  @workarea.close_all()
  
  menu_state_no_project()
  self.app = nil
  reset_subscriptions()
  @workarea.subscribe(self, :all)
end