C# Class SIL.FieldWorks.Common.Framework.FwApp

Base application for .net FieldWorks apps (i.e., replacement for AfApp)
Inheritance: IApp, ISettings, IFWDisposable, IHelpTopicProvider, IMessageFilter, IFeedbackInfoProvider, IProjectSpecificSettingsKeyProvider
Mostrar archivo Open project: sillsdev/FieldWorks Class Usage Examples

Protected Properties

Property Type Description
m_activeMainWindow System.Windows.Forms.Form
m_debugProcs DebugProcs
m_findPattern IVwPattern
m_findReplaceDlg SIL.FieldWorks.FwCoreDlgs.FwFindReplaceDlg
m_fwManager IFieldWorksManager
m_rgMainWindows List

Private Properties

Property Type Description
Application_EnterThreadModal void
Application_LeaveThreadModal void
BeginUpdate void
CalcTileSizeAndSpacing void
CloseRootBoxes void
CollectMovableFilesFromFolder void
EndUpdate void
ExpandToFullPath void
IApp string
OnWindowClosed void
RestartSpellChecking void
UpdateAppRuntimeCounter void
fwMainWindow_Activated void
fwMainWindow_HandleDestroyed void

Public Methods

Method Description
ActivateWindow ( int iMainWnd ) : void

Activate the given window.

CalcTileSizeAndSpacing ( Screen scrn, int screenDimension, int minWindowDimension, int &desiredWindowDimension, int &windowSpacing ) : void

This method can be used to do the size and spacing calculations when tiling either side-by-side or stacked. It calculates two things: 1) The desired width or height of tiled windows. 2) how many pixels between the left or top edges of tiled windows. If the calculated width or height of a window is less than the allowable minimum, then tiled windows will be overlapped.

CascadeSize ( int screenSize, int minSize ) : int

Calculate a size (width or height) which is 2/3 of the screen area or the minimum allowable size.

CascadeWindows ( Form wndCurr ) : void

Cascade the windows from top left and resize them to fill 2/3 of the screen area (or the minimum allowable size).

CheckDisposed ( ) : void

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.

Dispose ( ) : void

Must not be virtual.

DoApplicationInitialization ( IProgress progressDlg ) : void

Use this for slow operations that should happen during the splash screen instead of during app construction

EnableMainWindows ( bool fEnable ) : void

Enable or disable all top-level windows. This allows nesting. In other words, calling EnableMainWindows(false) twice requires 2 calls to EnableMainWindows(true) before the top level windows are actually enabled. An example of where not allowing nesting was a problem was the Tools/Options dialog, which could open a PossListChooser dialog. Before, when you closed the PossListChooser, you could select the main window.

ExitAppplication ( ) : void

Close all windows (which will shut down the application)

GetAppFeatures ( ) : SIL.FieldWorks.FDO.Feature[]

Returns the features available for the application

GetHelpString ( string stid ) : string

Gets a URL identifying a Help topic.

GetResourceString ( string stid ) : string

Return a string from a resource ID.

HandleIncomingLink ( SIL.FieldWorks.Common.FwUtils.FwLinkArgs link ) : void

Applications should override this method to handle incoming links. This method is called from FieldWorks when a link is requested. It is guaranteed to be on the correct thread (the thread this application is on) so invoking should not be needed. Overridden in FwXApp. See the class comment on FwLinkArgs for details on how all the parts of hyperlinking work.

HandleOutgoingLink ( SIL.FieldWorks.Common.FwUtils.FwAppArgs link ) : void

Handles an outgoing link request from this application.

InitAndShowMainWindow ( Form fwMainWindow, Form wndCopyFrom ) : void

Registers events for the main window and adds the main window to the list of windows. Then shows the window.

InitCacheForApp ( IThreadedProgress progressDlg ) : bool

Provides a hook for initializing the cache in application-specific ways.

LoadSettings ( ) : void

Called just after DoApplicationInitialization(). Allows a separate overide of loading settings. If you override this you probably also want to override SaveSettings.

NewMainAppWnd ( IProgress progressDlg, bool fNewCache, Form wndCopyFrom, bool fOpeningNewProject ) : Form

Creates a new instance of the main window

PreFilterMessage ( Message &m ) : bool

Filters out a message before it is dispatched.

RefreshAllViews ( ) : void

Refreshes all the views in all of the Main Windows of the app.

RemoveFindReplaceDialog ( ) : void

Close and remove the Find/Replace modeless dialog (result of LT-5702)

RemoveWindow ( IFwMainWnd fwMainWindow ) : void

Removes the specified IFwMainWnd from the list of windows. If it is ok to close down the application and the count of main windows is zero, then this method will also shut down the application.

RestartSpellChecking ( ) : void

Restart the spell-checking process (e.g. when dictionary changed)

ResumePaint ( ) : void

Resumes painting in every view and every main window.

ResumeSynchronize ( ) : void

Resume execution of synchronize messages. If there are any messages in the queue execute them now.

SaveSettings ( ) : void

Triggered by shutting down the app, this is a possible override point for saving any settings to be loaded by LoadSettings. This is the real place to save settings, as opposed to SaveSettingsNow, which is a dummy implementation required because (for the sake of the SettingsKey method) we implement ISettings.

SaveSettingsNow ( ) : void

For now, app has no settings to save. This method is required as part of ISettings implementation. Note that the SaveSettings() method is the appropriate one to modify or override if you really want to save settings. This one is NEVER called!

ShowFindReplaceDialog ( bool fReplace, SIL.FieldWorks.Common.RootSites.RootSite rootsite ) : bool

Display the Find/Replace modeless dialog

ShowFirstTimeMessageDlg ( string suggestedProject ) : string

Displays a message box asking the user whether or not he wants to open a sample DB.

SuppressPaint ( ) : void

Suppresses painting in every view and every main window.

SuppressSynchronize ( ) : void

Suppress execution of all synchronize messages and store them in a queue instead.

Synchronize ( SyncMsg sync ) : bool

Cycle through the applications main windows and synchronize them with database changes.

TileWindows ( Form wndCurr, List windowsToTile, WindowTiling orientation ) : void

Arrange the windows top to bottom or left to right.

TileWindows ( Form wndCurr, WindowTiling orientation ) : void

Arrange the windows top to bottom or left to right.

UpdateExternalLinks ( string sOldLinkedFilesRootDir ) : bool

Handle changes to the LinkedFiles root directory for a language project.

This may not be the best place for this method, but I'm not sure there is a "best place".

Protected Methods

Method Description
AdjustNewWindowPosition ( Form wndNew, Form wndCopyFrom ) : void

Adjust the new window position - offset right and down from the original. Also copy the window size, state, and set the StartPosition mode to manual.

ConfigureFindReplacedialog ( ) : void

This provides a hook for any kind of app that wants to configure the dialog in some special way. TE wants to disable regular expressions for replace.

Dispose ( bool disposing ) : void

Executes in two distinct scenarios. 1. If disposing is true, the method has been called directly or indirectly by a user's code via the Dispose method. Both managed and unmanaged resources can be disposed. 2. If disposing is false, the method has been called by the runtime from inside the finalizer and you should not reference (access) other managed objects, as they already have been garbage collected. Only unmanaged resources can be disposed.

If any exceptions are thrown, that is fine. If the method is being done in a finalizer, it will be ignored. If it is thrown by client code calling Dispose, it needs to be handled by fixing the bug. If subclasses override this method, they should call the base implementation.

FwApp ( IFieldWorksManager fwManager, IHelpTopicProvider helpTopicProvider ) : System

Constructor for FwApp

OnClosingWindow ( object sender, CancelEventArgs e ) : void

The active main window is closing, so try to find some other main window that can "own" the find/replace dialog, so it can stay alive. If we can't find one, then all main windows are going away and we're going to have to close, too.

Private Methods

Method Description
Application_EnterThreadModal ( object sender, EventArgs e ) : void

Handles the EnterThreadModal event of the Application control.

Application_LeaveThreadModal ( object sender, EventArgs e ) : void

Handles the LeaveThreadModal event of the Application control.

BeginUpdate ( ) : void

Suppress all calls to T:RefreshAllViews() until T:EndUpdate is called.

Used by T:ResumeSynchronize to do only one refresh of the view.

CalcTileSizeAndSpacing ( Screen scrn, List windowsToTile, int screenDimension, int minWindowDimension, int &desiredWindowDimension, int &windowSpacing ) : void

This method can be used to do the size and spacing calculations when tiling either side-by-side or stacked. It calculates two things: 1) The desired width or height of tiled windows. 2) how many pixels between the left or top edges of tiled windows. If the calculated width or height of a window is less than the allowable minimum, then tiled windows will be overlapped.

CloseRootBoxes ( Control ctrl ) : void

Recursively look at all the controls belonging to the specified control and save the settings for each root box for controls of type ISettings. Then close the root box for controls of type IRootSite. Ideally IRootSite controls should close their root boxes in the OnHandleDestroyed event, but since sometimes IRootSite controls are created but never shown (which means their handle is never created), we have to close the rootboxes here instead.

CollectMovableFilesFromFolder ( ICmFolder folder, List rgFilesToMove, string sOldRootDir, string sNewRootDir ) : void

Build a list of files that can be moved (or copied) to the new LinkedFiles root directory.

EndUpdate ( ) : void

Do a T:RefreshAllViews() if it was called at least once after T:BeginUpdate

ExpandToFullPath ( ICmFolder folder, string sOldRootDir, string sNewRootDir ) : void

Expand the internal paths from relative to absolute as needed, since the user doesn't want to move (or copy) them.

IApp ( string stid ) : string

Return a string from a resource ID. This should normally not be called directly. Use FwApp.GetResourceString() instead.

OnWindowClosed ( object sender, EventArgs e ) : void

When a window is closed, we need to make sure we close any root boxes that may be on the window.

RestartSpellChecking ( Control root ) : void
UpdateAppRuntimeCounter ( ) : void
fwMainWindow_Activated ( object sender, EventArgs e ) : void

Note the most recent of our main windows to become active.

fwMainWindow_HandleDestroyed ( object sender, EventArgs e ) : void

Make sure a window that's no longer valid isn't considered active.

Method Details

ActivateWindow() public method

Activate the given window.
public ActivateWindow ( int iMainWnd ) : void
iMainWnd int Index (in the internal list of main windows) of the window to /// activate
return void

AdjustNewWindowPosition() protected method

Adjust the new window position - offset right and down from the original. Also copy the window size, state, and set the StartPosition mode to manual.
protected AdjustNewWindowPosition ( Form wndNew, Form wndCopyFrom ) : void
wndNew System.Windows.Forms.Form
wndCopyFrom System.Windows.Forms.Form
return void

CalcTileSizeAndSpacing() public method

This method can be used to do the size and spacing calculations when tiling either side-by-side or stacked. It calculates two things: 1) The desired width or height of tiled windows. 2) how many pixels between the left or top edges of tiled windows. If the calculated width or height of a window is less than the allowable minimum, then tiled windows will be overlapped.
public CalcTileSizeAndSpacing ( Screen scrn, int screenDimension, int minWindowDimension, int &desiredWindowDimension, int &windowSpacing ) : void
scrn System.Windows.Forms.Screen The screen where the tiling will take place (only windows on this /// screen will actually get tiled).
screenDimension int The width or height, in pixels, of the display on /// which tiling will be performed.
minWindowDimension int The minimum allowable width or height, in pixels, /// of tiled windows.
desiredWindowDimension int The desired width or height, in pixels, of /// tiled windows.
windowSpacing int The distance, in pixels, between the left or top edge /// of each tiled window. If there is only one window, this is undefined.
return void

CascadeSize() public method

Calculate a size (width or height) which is 2/3 of the screen area or the minimum allowable size.
public CascadeSize ( int screenSize, int minSize ) : int
screenSize int Total available width or height (for the screen)
minSize int Minimum width or height for the window
return int

CascadeWindows() public method

Cascade the windows from top left and resize them to fill 2/3 of the screen area (or the minimum allowable size).
public CascadeWindows ( Form wndCurr ) : void
wndCurr System.Windows.Forms.Form Current Window (i.e. window whose menu was used to issue the /// Cascaede command.
return void

CheckDisposed() public method

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.
public CheckDisposed ( ) : void
return void

ConfigureFindReplacedialog() protected method

This provides a hook for any kind of app that wants to configure the dialog in some special way. TE wants to disable regular expressions for replace.
protected ConfigureFindReplacedialog ( ) : void
return void

Dispose() public method

Must not be virtual.
public Dispose ( ) : void
return void

Dispose() protected method

Executes in two distinct scenarios. 1. If disposing is true, the method has been called directly or indirectly by a user's code via the Dispose method. Both managed and unmanaged resources can be disposed. 2. If disposing is false, the method has been called by the runtime from inside the finalizer and you should not reference (access) other managed objects, as they already have been garbage collected. Only unmanaged resources can be disposed.
If any exceptions are thrown, that is fine. If the method is being done in a finalizer, it will be ignored. If it is thrown by client code calling Dispose, it needs to be handled by fixing the bug. If subclasses override this method, they should call the base implementation.
protected Dispose ( bool disposing ) : void
disposing bool
return void

DoApplicationInitialization() public method

Use this for slow operations that should happen during the splash screen instead of during app construction
public DoApplicationInitialization ( IProgress progressDlg ) : void
progressDlg IProgress The progress dialog to use.
return void

EnableMainWindows() public method

Enable or disable all top-level windows. This allows nesting. In other words, calling EnableMainWindows(false) twice requires 2 calls to EnableMainWindows(true) before the top level windows are actually enabled. An example of where not allowing nesting was a problem was the Tools/Options dialog, which could open a PossListChooser dialog. Before, when you closed the PossListChooser, you could select the main window.
public EnableMainWindows ( bool fEnable ) : void
fEnable bool Enable (true) or disable (false).
return void

ExitAppplication() public method

Close all windows (which will shut down the application)
public ExitAppplication ( ) : void
return void

FwApp() protected method

Constructor for FwApp
protected FwApp ( IFieldWorksManager fwManager, IHelpTopicProvider helpTopicProvider ) : System
fwManager IFieldWorksManager The FieldWorks manager for dealing with FieldWorks-level /// stuff.
helpTopicProvider IHelpTopicProvider An application-specific help topic provider.
return System

GetAppFeatures() public method

Returns the features available for the application
public GetAppFeatures ( ) : SIL.FieldWorks.FDO.Feature[]
return SIL.FieldWorks.FDO.Feature[]

GetHelpString() public method

Gets a URL identifying a Help topic.
public GetHelpString ( string stid ) : string
stid string An identifier for the desired Help topic
return string

GetResourceString() public method

Return a string from a resource ID.
public GetResourceString ( string stid ) : string
stid string String resource id
return string

HandleIncomingLink() public method

Applications should override this method to handle incoming links. This method is called from FieldWorks when a link is requested. It is guaranteed to be on the correct thread (the thread this application is on) so invoking should not be needed. Overridden in FwXApp. See the class comment on FwLinkArgs for details on how all the parts of hyperlinking work.
public HandleIncomingLink ( SIL.FieldWorks.Common.FwUtils.FwLinkArgs link ) : void
link SIL.FieldWorks.Common.FwUtils.FwLinkArgs The link to handle.
return void

HandleOutgoingLink() public method

Handles an outgoing link request from this application.
public HandleOutgoingLink ( SIL.FieldWorks.Common.FwUtils.FwAppArgs link ) : void
link SIL.FieldWorks.Common.FwUtils.FwAppArgs The link.
return void

InitAndShowMainWindow() public method

Registers events for the main window and adds the main window to the list of windows. Then shows the window.
public InitAndShowMainWindow ( Form fwMainWindow, Form wndCopyFrom ) : void
fwMainWindow System.Windows.Forms.Form The new main window.
wndCopyFrom System.Windows.Forms.Form Form to copy from, or null
return void

InitCacheForApp() public abstract method

Provides a hook for initializing the cache in application-specific ways.
public abstract InitCacheForApp ( IThreadedProgress progressDlg ) : bool
progressDlg IThreadedProgress The progress dialog.
return bool

LoadSettings() public method

Called just after DoApplicationInitialization(). Allows a separate overide of loading settings. If you override this you probably also want to override SaveSettings.
public LoadSettings ( ) : void
return void

NewMainAppWnd() public abstract method

Creates a new instance of the main window
public abstract NewMainAppWnd ( IProgress progressDlg, bool fNewCache, Form wndCopyFrom, bool fOpeningNewProject ) : Form
progressDlg IProgress The progress dialog to use, if needed (can be null).
fNewCache bool Flag indicating whether one-time, application-specific /// initialization should be done for this cache.
wndCopyFrom System.Windows.Forms.Form Must be null for creating the original app window. /// Otherwise, a reference to the main window whose settings we are copying.
fOpeningNewProject bool true if opening a brand spankin' new /// project
return System.Windows.Forms.Form

OnClosingWindow() protected method

The active main window is closing, so try to find some other main window that can "own" the find/replace dialog, so it can stay alive. If we can't find one, then all main windows are going away and we're going to have to close, too.
protected OnClosingWindow ( object sender, CancelEventArgs e ) : void
sender object
e CancelEventArgs
return void

PreFilterMessage() public method

Filters out a message before it is dispatched.
public PreFilterMessage ( Message &m ) : bool
m System.Windows.Forms.Message The message to be dispatched. You cannot modify this message.
return bool

RefreshAllViews() public method

Refreshes all the views in all of the Main Windows of the app.
public RefreshAllViews ( ) : void
return void

RemoveFindReplaceDialog() public method

Close and remove the Find/Replace modeless dialog (result of LT-5702)
public RemoveFindReplaceDialog ( ) : void
return void

RemoveWindow() public method

Removes the specified IFwMainWnd from the list of windows. If it is ok to close down the application and the count of main windows is zero, then this method will also shut down the application.
public RemoveWindow ( IFwMainWnd fwMainWindow ) : void
fwMainWindow IFwMainWnd The IFwMainWnd to remove
return void

RestartSpellChecking() public method

Restart the spell-checking process (e.g. when dictionary changed)
public RestartSpellChecking ( ) : void
return void

ResumePaint() public method

Resumes painting in every view and every main window.
public ResumePaint ( ) : void
return void

ResumeSynchronize() public method

Resume execution of synchronize messages. If there are any messages in the queue execute them now.
public ResumeSynchronize ( ) : void
return void

SaveSettings() public method

Triggered by shutting down the app, this is a possible override point for saving any settings to be loaded by LoadSettings. This is the real place to save settings, as opposed to SaveSettingsNow, which is a dummy implementation required because (for the sake of the SettingsKey method) we implement ISettings.
public SaveSettings ( ) : void
return void

SaveSettingsNow() public method

For now, app has no settings to save. This method is required as part of ISettings implementation. Note that the SaveSettings() method is the appropriate one to modify or override if you really want to save settings. This one is NEVER called!
public SaveSettingsNow ( ) : void
return void

ShowFindReplaceDialog() public method

Display the Find/Replace modeless dialog
public ShowFindReplaceDialog ( bool fReplace, SIL.FieldWorks.Common.RootSites.RootSite rootsite ) : bool
fReplace bool true to make the replace tab active
rootsite SIL.FieldWorks.Common.RootSites.RootSite The view where the find will be conducted
return bool

ShowFirstTimeMessageDlg() public method

Displays a message box asking the user whether or not he wants to open a sample DB.
public ShowFirstTimeMessageDlg ( string suggestedProject ) : string
suggestedProject string
return string

SuppressPaint() public method

Suppresses painting in every view and every main window.
public SuppressPaint ( ) : void
return void

SuppressSynchronize() public method

Suppress execution of all synchronize messages and store them in a queue instead.
public SuppressSynchronize ( ) : void
return void

Synchronize() public method

Cycle through the applications main windows and synchronize them with database changes.
public Synchronize ( SyncMsg sync ) : bool
sync SyncMsg synchronization information record
return bool

TileWindows() public method

Arrange the windows top to bottom or left to right.
public TileWindows ( Form wndCurr, List windowsToTile, WindowTiling orientation ) : void
wndCurr System.Windows.Forms.Form Current Window (i.e. window whose menu was used to issue a /// tile vertical or horizontal command.
windowsToTile List A list of all the windows to tile (including the /// current window)
orientation WindowTiling The value indicating whether to tile side by side or /// stacked.
return void

TileWindows() public method

Arrange the windows top to bottom or left to right.
public TileWindows ( Form wndCurr, WindowTiling orientation ) : void
wndCurr System.Windows.Forms.Form Current Window (i.e. window whose menu was used to issue a /// tile vertical or horizontal command.
orientation WindowTiling The value indicating whether to tile side by side or /// stacked.
return void

UpdateExternalLinks() public method

Handle changes to the LinkedFiles root directory for a language project.
This may not be the best place for this method, but I'm not sure there is a "best place".
public UpdateExternalLinks ( string sOldLinkedFilesRootDir ) : bool
sOldLinkedFilesRootDir string The old LinkedFiles root directory.
return bool

Property Details

m_activeMainWindow protected_oe property

One of m_rgMainWindows, the one most recently activated.
protected Form,System.Windows.Forms m_activeMainWindow
return System.Windows.Forms.Form

m_debugProcs protected_oe property

protected DebugProcs m_debugProcs
return DebugProcs

m_findPattern protected_oe property

The find patterns for the find/replace dialog, one for each database.
We need one pattern per database (cache). Otherwise it'll crash when we try to load the previous search term because the new database has different writing system hvos (TE-5598).
protected IVwPattern m_findPattern
return IVwPattern

m_findReplaceDlg protected_oe property

protected FwFindReplaceDlg,SIL.FieldWorks.FwCoreDlgs m_findReplaceDlg
return SIL.FieldWorks.FwCoreDlgs.FwFindReplaceDlg

m_fwManager protected_oe property

The FieldWorks manager for dealing with FieldWorks-level stuff.
protected IFieldWorksManager m_fwManager
return IFieldWorksManager

m_rgMainWindows protected_oe property

protected List m_rgMainWindows
return List